ddraw/tests: Recognise E_NOTIMPL returned from UpdateOverlay() on VMware as broken.
[wine.git] / dlls / ddraw / tests / ddraw7.c
blobfdfac696cfc39f6601aa0de2ca4aec3cac4ae571
1 /*
2 * Copyright 2005 Antoine Chavasse (a.chavasse@gmail.com)
3 * Copyright 2006, 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
20 #define COBJMACROS
22 #include "wine/test.h"
23 #include <limits.h>
24 #include <math.h>
25 #include "d3d.h"
27 HRESULT WINAPI GetSurfaceFromDC(HDC dc, struct IDirectDrawSurface **surface, HDC *device_dc);
29 static HRESULT (WINAPI *pDirectDrawCreateEx)(GUID *guid, void **ddraw, REFIID iid, IUnknown *outer_unknown);
30 static BOOL is_ddraw64 = sizeof(DWORD) != sizeof(DWORD *);
31 static DEVMODEW registry_mode;
33 static HRESULT (WINAPI *pDwmIsCompositionEnabled)(BOOL *);
35 #ifndef ARRAY_SIZE
36 #define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
37 #endif
39 struct vec2
41 float x, y;
44 struct vec3
46 float x, y, z;
49 struct vec4
51 float x, y, z, w;
54 struct create_window_thread_param
56 HWND window;
57 HANDLE window_created;
58 HANDLE destroy_window;
59 HANDLE thread;
62 static BOOL compare_float(float f, float g, unsigned int ulps)
64 int x = *(int *)&f;
65 int y = *(int *)&g;
67 if (x < 0)
68 x = INT_MIN - x;
69 if (y < 0)
70 y = INT_MIN - y;
72 if (abs(x - y) > ulps)
73 return FALSE;
75 return TRUE;
78 static BOOL compare_vec3(struct vec3 *vec, float x, float y, float z, unsigned int ulps)
80 return compare_float(vec->x, x, ulps)
81 && compare_float(vec->y, y, ulps)
82 && compare_float(vec->z, z, ulps);
85 static BOOL compare_vec4(const struct vec4 *vec, float x, float y, float z, float w, unsigned int ulps)
87 return compare_float(vec->x, x, ulps)
88 && compare_float(vec->y, y, ulps)
89 && compare_float(vec->z, z, ulps)
90 && compare_float(vec->w, w, ulps);
93 static BOOL compare_color(D3DCOLOR c1, D3DCOLOR c2, BYTE max_diff)
95 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
96 c1 >>= 8; c2 >>= 8;
97 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
98 c1 >>= 8; c2 >>= 8;
99 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
100 c1 >>= 8; c2 >>= 8;
101 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
102 return TRUE;
105 static ULONG get_refcount(IUnknown *iface)
107 IUnknown_AddRef(iface);
108 return IUnknown_Release(iface);
111 static BOOL ddraw_get_identifier(IDirectDraw7 *ddraw, DDDEVICEIDENTIFIER2 *identifier)
113 HRESULT hr;
115 hr = IDirectDraw7_GetDeviceIdentifier(ddraw, identifier, 0);
116 ok(SUCCEEDED(hr), "Failed to get device identifier, hr %#x.\n", hr);
118 return SUCCEEDED(hr);
121 static BOOL ddraw_is_warp(IDirectDraw7 *ddraw)
123 DDDEVICEIDENTIFIER2 identifier;
125 return strcmp(winetest_platform, "wine")
126 && ddraw_get_identifier(ddraw, &identifier)
127 && strstr(identifier.szDriver, "warp");
130 static BOOL ddraw_is_nvidia(IDirectDraw7 *ddraw)
132 DDDEVICEIDENTIFIER2 identifier;
134 return strcmp(winetest_platform, "wine")
135 && ddraw_get_identifier(ddraw, &identifier)
136 && identifier.dwVendorId == 0x10de;
139 static BOOL ddraw_is_intel(IDirectDraw7 *ddraw)
141 DDDEVICEIDENTIFIER2 identifier;
143 return strcmp(winetest_platform, "wine")
144 && ddraw_get_identifier(ddraw, &identifier)
145 && identifier.dwVendorId == 0x8086;
148 static BOOL ddraw_is_vmware(IDirectDraw7 *ddraw)
150 DDDEVICEIDENTIFIER2 identifier;
152 return strcmp(winetest_platform, "wine")
153 && ddraw_get_identifier(ddraw, &identifier)
154 && identifier.dwVendorId == 0x15ad;
157 static IDirectDrawSurface7 *create_overlay(IDirectDraw7 *ddraw,
158 unsigned int width, unsigned int height, DWORD format)
160 IDirectDrawSurface7 *surface;
161 DDSURFACEDESC2 desc;
163 memset(&desc, 0, sizeof(desc));
164 desc.dwSize = sizeof(desc);
165 desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
166 desc.dwWidth = width;
167 desc.dwHeight = height;
168 desc.ddsCaps.dwCaps = DDSCAPS_OVERLAY;
169 U4(desc).ddpfPixelFormat.dwSize = sizeof(U4(desc).ddpfPixelFormat);
170 U4(desc).ddpfPixelFormat.dwFlags = DDPF_FOURCC;
171 U4(desc).ddpfPixelFormat.dwFourCC = format;
173 if (FAILED(IDirectDraw7_CreateSurface(ddraw, &desc, &surface, NULL)))
174 return NULL;
175 return surface;
178 static HWND create_window(void)
180 RECT r = {0, 0, 640, 480};
182 AdjustWindowRect(&r, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
184 return CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
185 CW_USEDEFAULT, CW_USEDEFAULT, r.right - r.left, r.bottom - r.top, NULL, NULL, NULL, NULL);
188 static DWORD WINAPI create_window_thread_proc(void *param)
190 struct create_window_thread_param *p = param;
191 DWORD res;
192 BOOL ret;
194 p->window = create_window();
195 ret = SetEvent(p->window_created);
196 ok(ret, "SetEvent failed, last error %#x.\n", GetLastError());
198 for (;;)
200 MSG msg;
202 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
203 DispatchMessageA(&msg);
204 res = WaitForSingleObject(p->destroy_window, 100);
205 if (res == WAIT_OBJECT_0)
206 break;
207 if (res != WAIT_TIMEOUT)
209 ok(0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
210 break;
214 DestroyWindow(p->window);
216 return 0;
219 static void create_window_thread(struct create_window_thread_param *p)
221 DWORD res, tid;
223 p->window_created = CreateEventA(NULL, FALSE, FALSE, NULL);
224 ok(!!p->window_created, "CreateEvent failed, last error %#x.\n", GetLastError());
225 p->destroy_window = CreateEventA(NULL, FALSE, FALSE, NULL);
226 ok(!!p->destroy_window, "CreateEvent failed, last error %#x.\n", GetLastError());
227 p->thread = CreateThread(NULL, 0, create_window_thread_proc, p, 0, &tid);
228 ok(!!p->thread, "Failed to create thread, last error %#x.\n", GetLastError());
229 res = WaitForSingleObject(p->window_created, INFINITE);
230 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
233 static void destroy_window_thread(struct create_window_thread_param *p)
235 SetEvent(p->destroy_window);
236 WaitForSingleObject(p->thread, INFINITE);
237 CloseHandle(p->destroy_window);
238 CloseHandle(p->window_created);
239 CloseHandle(p->thread);
242 static IDirectDrawSurface7 *get_depth_stencil(IDirect3DDevice7 *device)
244 IDirectDrawSurface7 *rt, *ret;
245 DDSCAPS2 caps = {DDSCAPS_ZBUFFER, 0, 0, {0}};
246 HRESULT hr;
248 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
249 ok(SUCCEEDED(hr), "Failed to get the render target, hr %#x.\n", hr);
250 hr = IDirectDrawSurface7_GetAttachedSurface(rt, &caps, &ret);
251 ok(SUCCEEDED(hr) || hr == DDERR_NOTFOUND, "Failed to get the z buffer, hr %#x.\n", hr);
252 IDirectDrawSurface7_Release(rt);
253 return ret;
256 static HRESULT set_display_mode(IDirectDraw7 *ddraw, DWORD width, DWORD height)
258 if (SUCCEEDED(IDirectDraw7_SetDisplayMode(ddraw, width, height, 32, 0, 0)))
259 return DD_OK;
260 return IDirectDraw7_SetDisplayMode(ddraw, width, height, 24, 0, 0);
263 static D3DCOLOR get_surface_color(IDirectDrawSurface7 *surface, UINT x, UINT y)
265 RECT rect = {x, y, x + 1, y + 1};
266 DDSURFACEDESC2 surface_desc;
267 D3DCOLOR color;
268 HRESULT hr;
270 memset(&surface_desc, 0, sizeof(surface_desc));
271 surface_desc.dwSize = sizeof(surface_desc);
273 hr = IDirectDrawSurface7_Lock(surface, &rect, &surface_desc, DDLOCK_READONLY, NULL);
274 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
275 if (FAILED(hr))
276 return 0xdeadbeef;
278 color = *((DWORD *)surface_desc.lpSurface) & 0x00ffffff;
280 hr = IDirectDrawSurface7_Unlock(surface, &rect);
281 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
283 return color;
286 static HRESULT CALLBACK enum_z_fmt(DDPIXELFORMAT *format, void *ctx)
288 DDPIXELFORMAT *z_fmt = ctx;
290 if (U1(*format).dwZBufferBitDepth > U1(*z_fmt).dwZBufferBitDepth)
291 *z_fmt = *format;
293 return DDENUMRET_OK;
296 static IDirectDraw7 *create_ddraw(void)
298 IDirectDraw7 *ddraw;
300 if (FAILED(pDirectDrawCreateEx(NULL, (void **)&ddraw, &IID_IDirectDraw7, NULL)))
301 return NULL;
303 return ddraw;
306 static HRESULT WINAPI enum_devtype_cb(char *desc_str, char *name, D3DDEVICEDESC7 *desc, void *ctx)
308 BOOL *hal_ok = ctx;
309 if (IsEqualGUID(&desc->deviceGUID, &IID_IDirect3DTnLHalDevice))
311 *hal_ok = TRUE;
312 return DDENUMRET_CANCEL;
314 return DDENUMRET_OK;
317 static IDirect3DDevice7 *create_device(HWND window, DWORD coop_level)
319 IDirectDrawSurface7 *surface, *ds;
320 IDirect3DDevice7 *device = NULL;
321 DDSURFACEDESC2 surface_desc;
322 DDPIXELFORMAT z_fmt;
323 IDirectDraw7 *ddraw;
324 IDirect3D7 *d3d7;
325 HRESULT hr;
326 BOOL hal_ok = FALSE;
327 const GUID *devtype = &IID_IDirect3DHALDevice;
329 if (!(ddraw = create_ddraw()))
330 return NULL;
332 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, coop_level);
333 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
335 memset(&surface_desc, 0, sizeof(surface_desc));
336 surface_desc.dwSize = sizeof(surface_desc);
337 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
338 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
339 surface_desc.dwWidth = 640;
340 surface_desc.dwHeight = 480;
342 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
343 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
345 if (coop_level & DDSCL_NORMAL)
347 IDirectDrawClipper *clipper;
349 hr = IDirectDraw7_CreateClipper(ddraw, 0, &clipper, NULL);
350 ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr);
351 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
352 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
353 hr = IDirectDrawSurface7_SetClipper(surface, clipper);
354 ok(SUCCEEDED(hr), "Failed to set surface clipper, hr %#x.\n", hr);
355 IDirectDrawClipper_Release(clipper);
358 hr = IDirectDraw7_QueryInterface(ddraw, &IID_IDirect3D7, (void **)&d3d7);
359 IDirectDraw7_Release(ddraw);
360 if (FAILED(hr))
362 IDirectDrawSurface7_Release(surface);
363 return NULL;
366 hr = IDirect3D7_EnumDevices(d3d7, enum_devtype_cb, &hal_ok);
367 ok(SUCCEEDED(hr), "Failed to enumerate devices, hr %#x.\n", hr);
368 if (hal_ok) devtype = &IID_IDirect3DTnLHalDevice;
370 memset(&z_fmt, 0, sizeof(z_fmt));
371 hr = IDirect3D7_EnumZBufferFormats(d3d7, devtype, enum_z_fmt, &z_fmt);
372 if (FAILED(hr) || !z_fmt.dwSize)
374 IDirect3D7_Release(d3d7);
375 IDirectDrawSurface7_Release(surface);
376 return NULL;
379 memset(&surface_desc, 0, sizeof(surface_desc));
380 surface_desc.dwSize = sizeof(surface_desc);
381 surface_desc.dwFlags = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT;
382 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
383 U4(surface_desc).ddpfPixelFormat = z_fmt;
384 surface_desc.dwWidth = 640;
385 surface_desc.dwHeight = 480;
386 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &ds, NULL);
387 ok(SUCCEEDED(hr), "Failed to create depth buffer, hr %#x.\n", hr);
388 if (FAILED(hr))
390 IDirect3D7_Release(d3d7);
391 IDirectDrawSurface7_Release(surface);
392 return NULL;
395 hr = IDirectDrawSurface_AddAttachedSurface(surface, ds);
396 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
397 IDirectDrawSurface7_Release(ds);
398 if (FAILED(hr))
400 IDirect3D7_Release(d3d7);
401 IDirectDrawSurface7_Release(surface);
402 return NULL;
405 hr = IDirect3D7_CreateDevice(d3d7, devtype, surface, &device);
406 IDirect3D7_Release(d3d7);
407 IDirectDrawSurface7_Release(surface);
408 if (FAILED(hr))
409 return NULL;
411 return device;
414 struct message
416 UINT message;
417 BOOL check_wparam;
418 WPARAM expect_wparam;
421 static const struct message *expect_messages;
423 static LRESULT CALLBACK test_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
425 if (expect_messages && message == expect_messages->message)
427 if (expect_messages->check_wparam)
428 ok (wparam == expect_messages->expect_wparam,
429 "Got unexpected wparam %lx for message %x, expected %lx.\n",
430 wparam, message, expect_messages->expect_wparam);
432 ++expect_messages;
435 return DefWindowProcA(hwnd, message, wparam, lparam);
438 /* Set the wndproc back to what ddraw expects it to be, and release the ddraw
439 * interface. This prevents subsequent SetCooperativeLevel() calls on a
440 * different window from failing with DDERR_HWNDALREADYSET. */
441 static void fix_wndproc(HWND window, LONG_PTR proc)
443 IDirectDraw7 *ddraw;
444 HRESULT hr;
446 if (!(ddraw = create_ddraw()))
447 return;
449 SetWindowLongPtrA(window, GWLP_WNDPROC, proc);
450 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
451 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
452 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
453 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
455 IDirectDraw7_Release(ddraw);
458 static void test_process_vertices(void)
460 IDirect3DVertexBuffer7 *src_vb, *dst_vb1, *dst_vb2;
461 D3DVERTEXBUFFERDESC vb_desc;
462 IDirect3DDevice7 *device;
463 struct vec4 *dst_data;
464 struct vec3 *dst_data2;
465 struct vec3 *src_data;
466 IDirect3D7 *d3d7;
467 D3DVIEWPORT7 vp;
468 HWND window;
469 HRESULT hr;
471 static D3DMATRIX world =
473 0.0f, 1.0f, 0.0f, 0.0f,
474 1.0f, 0.0f, 0.0f, 0.0f,
475 0.0f, 0.0f, 0.0f, 1.0f,
476 0.0f, 1.0f, 1.0f, 1.0f,
478 static D3DMATRIX view =
480 2.0f, 0.0f, 0.0f, 0.0f,
481 0.0f, -1.0f, 0.0f, 0.0f,
482 0.0f, 0.0f, 1.0f, 0.0f,
483 0.0f, 0.0f, 0.0f, 3.0f,
485 static D3DMATRIX proj =
487 1.0f, 0.0f, 0.0f, 1.0f,
488 0.0f, 1.0f, 1.0f, 0.0f,
489 0.0f, 1.0f, 1.0f, 0.0f,
490 1.0f, 0.0f, 0.0f, 1.0f,
493 window = create_window();
494 if (!(device = create_device(window, DDSCL_NORMAL)))
496 skip("Failed to create a 3D device, skipping test.\n");
497 DestroyWindow(window);
498 return;
501 hr = IDirect3DDevice7_GetDirect3D(device, &d3d7);
502 ok(SUCCEEDED(hr), "Failed to get Direct3D7 interface, hr %#x.\n", hr);
504 memset(&vb_desc, 0, sizeof(vb_desc));
505 vb_desc.dwSize = sizeof(vb_desc);
506 vb_desc.dwFVF = D3DFVF_XYZ;
507 vb_desc.dwNumVertices = 4;
508 hr = IDirect3D7_CreateVertexBuffer(d3d7, &vb_desc, &src_vb, 0);
509 ok(SUCCEEDED(hr), "Failed to create source vertex buffer, hr %#x.\n", hr);
511 hr = IDirect3DVertexBuffer7_Lock(src_vb, 0, (void **)&src_data, NULL);
512 ok(SUCCEEDED(hr), "Failed to lock source vertex buffer, hr %#x.\n", hr);
513 src_data[0].x = 0.0f;
514 src_data[0].y = 0.0f;
515 src_data[0].z = 0.0f;
516 src_data[1].x = 1.0f;
517 src_data[1].y = 1.0f;
518 src_data[1].z = 1.0f;
519 src_data[2].x = -1.0f;
520 src_data[2].y = -1.0f;
521 src_data[2].z = 0.5f;
522 src_data[3].x = 0.5f;
523 src_data[3].y = -0.5f;
524 src_data[3].z = 0.25f;
525 hr = IDirect3DVertexBuffer7_Unlock(src_vb);
526 ok(SUCCEEDED(hr), "Failed to unlock source vertex buffer, hr %#x.\n", hr);
528 memset(&vb_desc, 0, sizeof(vb_desc));
529 vb_desc.dwSize = sizeof(vb_desc);
530 vb_desc.dwFVF = D3DFVF_XYZRHW;
531 vb_desc.dwNumVertices = 4;
532 /* MSDN says that the last parameter must be 0 - check that. */
533 hr = IDirect3D7_CreateVertexBuffer(d3d7, &vb_desc, &dst_vb1, 4);
534 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
536 memset(&vb_desc, 0, sizeof(vb_desc));
537 vb_desc.dwSize = sizeof(vb_desc);
538 vb_desc.dwFVF = D3DFVF_XYZ;
539 vb_desc.dwNumVertices = 5;
540 /* MSDN says that the last parameter must be 0 - check that. */
541 hr = IDirect3D7_CreateVertexBuffer(d3d7, &vb_desc, &dst_vb2, 12345678);
542 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
544 memset(&vp, 0, sizeof(vp));
545 vp.dwX = 64;
546 vp.dwY = 64;
547 vp.dwWidth = 128;
548 vp.dwHeight = 128;
549 vp.dvMinZ = 0.0f;
550 vp.dvMaxZ = 1.0f;
551 hr = IDirect3DDevice7_SetViewport(device, &vp);
552 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#x.\n", hr);
554 hr = IDirect3DVertexBuffer7_ProcessVertices(dst_vb1, D3DVOP_TRANSFORM, 0, 4, src_vb, 0, device, 0);
555 ok(SUCCEEDED(hr), "Failed to process vertices, hr %#x.\n", hr);
556 hr = IDirect3DVertexBuffer7_ProcessVertices(dst_vb2, D3DVOP_TRANSFORM, 0, 4, src_vb, 0, device, 0);
557 ok(SUCCEEDED(hr), "Failed to process vertices, hr %#x.\n", hr);
559 hr = IDirect3DVertexBuffer7_Lock(dst_vb1, 0, (void **)&dst_data, NULL);
560 ok(SUCCEEDED(hr), "Failed to lock destination vertex buffer, hr %#x.\n", hr);
561 ok(compare_vec4(&dst_data[0], +1.280e+2f, +1.280e+2f, +0.000e+0f, +1.000e+0f, 4096),
562 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
563 dst_data[0].x, dst_data[0].y, dst_data[0].z, dst_data[0].w);
564 ok(compare_vec4(&dst_data[1], +1.920e+2f, +6.400e+1f, +1.000e+0f, +1.000e+0f, 4096),
565 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
566 dst_data[1].x, dst_data[1].y, dst_data[1].z, dst_data[1].w);
567 ok(compare_vec4(&dst_data[2], +6.400e+1f, +1.920e+2f, +5.000e-1f, +1.000e+0f, 4096),
568 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
569 dst_data[2].x, dst_data[2].y, dst_data[2].z, dst_data[2].w);
570 ok(compare_vec4(&dst_data[3], +1.600e+2f, +1.600e+2f, +2.500e-1f, +1.000e+0f, 4096),
571 "Got unexpected vertex 3 {%.8e, %.8e, %.8e, %.8e}.\n",
572 dst_data[3].x, dst_data[3].y, dst_data[3].z, dst_data[3].w);
573 hr = IDirect3DVertexBuffer7_Unlock(dst_vb1);
574 ok(SUCCEEDED(hr), "Failed to unlock destination vertex buffer, hr %#x.\n", hr);
576 hr = IDirect3DVertexBuffer7_Lock(dst_vb2, 0, (void **)&dst_data2, NULL);
577 ok(SUCCEEDED(hr), "Failed to lock destination vertex buffer, hr %#x.\n", hr);
578 /* Small thing without much practical meaning, but I stumbled upon it,
579 * so let's check for it: If the output vertex buffer has no RHW value,
580 * the RHW value of the last vertex is written into the next vertex. */
581 ok(compare_vec3(&dst_data2[4], +1.000e+0f, +0.000e+0f, +0.000e+0f, 4096),
582 "Got unexpected vertex 4 {%.8e, %.8e, %.8e}.\n",
583 dst_data2[4].x, dst_data2[4].y, dst_data2[4].z);
584 hr = IDirect3DVertexBuffer7_Unlock(dst_vb2);
585 ok(SUCCEEDED(hr), "Failed to unlock destination vertex buffer, hr %#x.\n", hr);
587 /* Try a more complicated viewport, same vertices. */
588 memset(&vp, 0, sizeof(vp));
589 vp.dwX = 10;
590 vp.dwY = 5;
591 vp.dwWidth = 246;
592 vp.dwHeight = 130;
593 vp.dvMinZ = -2.0f;
594 vp.dvMaxZ = 4.0f;
595 hr = IDirect3DDevice7_SetViewport(device, &vp);
596 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#x.\n", hr);
598 hr = IDirect3DVertexBuffer7_ProcessVertices(dst_vb1, D3DVOP_TRANSFORM, 0, 4, src_vb, 0, device, 0);
599 ok(SUCCEEDED(hr), "Failed to process vertices, hr %#x.\n", hr);
601 hr = IDirect3DVertexBuffer7_Lock(dst_vb1, 0, (void **)&dst_data, NULL);
602 ok(SUCCEEDED(hr), "Failed to lock destination vertex buffer, hr %#x.\n", hr);
603 ok(compare_vec4(&dst_data[0], +1.330e+2f, +7.000e+1f, -2.000e+0f, +1.000e+0f, 4096),
604 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
605 dst_data[0].x, dst_data[0].y, dst_data[0].z, dst_data[0].w);
606 ok(compare_vec4(&dst_data[1], +2.560e+2f, +5.000e+0f, +4.000e+0f, +1.000e+0f, 4096),
607 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
608 dst_data[1].x, dst_data[1].y, dst_data[1].z, dst_data[1].w);
609 ok(compare_vec4(&dst_data[2], +1.000e+1f, +1.350e+2f, +1.000e+0f, +1.000e+0f, 4096),
610 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
611 dst_data[2].x, dst_data[2].y, dst_data[2].z, dst_data[2].w);
612 ok(compare_vec4(&dst_data[3], +1.945e+2f, +1.025e+2f, -5.000e-1f, +1.000e+0f, 4096),
613 "Got unexpected vertex 3 {%.8e, %.8e, %.8e, %.8e}.\n",
614 dst_data[3].x, dst_data[3].y, dst_data[3].z, dst_data[3].w);
615 hr = IDirect3DVertexBuffer7_Unlock(dst_vb1);
616 ok(SUCCEEDED(hr), "Failed to unlock destination vertex buffer, hr %#x.\n", hr);
618 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &world);
619 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#x.\n", hr);
620 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_VIEW, &view);
621 ok(SUCCEEDED(hr), "Failed to set view transform, hr %#x.\n", hr);
622 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &proj);
623 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
625 hr = IDirect3DVertexBuffer7_ProcessVertices(dst_vb1, D3DVOP_TRANSFORM, 0, 4, src_vb, 0, device, 0);
626 ok(SUCCEEDED(hr), "Failed to process vertices, hr %#x.\n", hr);
628 hr = IDirect3DVertexBuffer7_Lock(dst_vb1, 0, (void **)&dst_data, NULL);
629 ok(SUCCEEDED(hr), "Failed to lock destination vertex buffer, hr %#x.\n", hr);
630 ok(compare_vec4(&dst_data[0], +2.560e+2f, +7.000e+1f, -2.000e+0f, +3.333e-1f, 4096),
631 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
632 dst_data[0].x, dst_data[0].y, dst_data[0].z, dst_data[0].w);
633 ok(compare_vec4(&dst_data[1], +2.560e+2f, +7.813e+1f, -2.750e+0f, +1.250e-1f, 4096),
634 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
635 dst_data[1].x, dst_data[1].y, dst_data[1].z, dst_data[1].w);
636 ok(compare_vec4(&dst_data[2], +2.560e+2f, +4.400e+1f, +4.000e-1f, +4.000e-1f, 4096),
637 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
638 dst_data[2].x, dst_data[2].y, dst_data[2].z, dst_data[2].w);
639 ok(compare_vec4(&dst_data[3], +2.560e+2f, +8.182e+1f, -3.091e+0f, +3.636e-1f, 4096),
640 "Got unexpected vertex 3 {%.8e, %.8e, %.8e, %.8e}.\n",
641 dst_data[3].x, dst_data[3].y, dst_data[3].z, dst_data[3].w);
642 hr = IDirect3DVertexBuffer7_Unlock(dst_vb1);
643 ok(SUCCEEDED(hr), "Failed to unlock destination vertex buffer, hr %#x.\n", hr);
645 IDirect3DVertexBuffer7_Release(dst_vb2);
646 IDirect3DVertexBuffer7_Release(dst_vb1);
647 IDirect3DVertexBuffer7_Release(src_vb);
648 IDirect3D7_Release(d3d7);
649 IDirect3DDevice7_Release(device);
650 DestroyWindow(window);
653 static void test_coop_level_create_device_window(void)
655 HWND focus_window, device_window;
656 IDirectDraw7 *ddraw;
657 HRESULT hr;
659 focus_window = create_window();
660 ddraw = create_ddraw();
661 ok(!!ddraw, "Failed to create a ddraw object.\n");
663 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
664 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
665 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
666 ok(!device_window, "Unexpected device window found.\n");
667 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW);
668 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
669 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
670 ok(!device_window, "Unexpected device window found.\n");
671 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_NORMAL);
672 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
673 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
674 ok(!device_window, "Unexpected device window found.\n");
675 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_NORMAL | DDSCL_FULLSCREEN);
676 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
677 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
678 ok(!device_window, "Unexpected device window found.\n");
679 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
680 ok(hr == DDERR_NOFOCUSWINDOW || broken(hr == DDERR_INVALIDPARAMS), "Got unexpected hr %#x.\n", hr);
681 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
682 ok(!device_window, "Unexpected device window found.\n");
684 /* Windows versions before 98 / NT5 don't support DDSCL_CREATEDEVICEWINDOW. */
685 if (broken(hr == DDERR_INVALIDPARAMS))
687 win_skip("DDSCL_CREATEDEVICEWINDOW not supported, skipping test.\n");
688 IDirectDraw7_Release(ddraw);
689 DestroyWindow(focus_window);
690 return;
693 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
694 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
695 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
696 ok(!device_window, "Unexpected device window found.\n");
697 hr = IDirectDraw7_SetCooperativeLevel(ddraw, focus_window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
698 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
699 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
700 ok(!device_window, "Unexpected device window found.\n");
702 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
703 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
704 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
705 ok(!device_window, "Unexpected device window found.\n");
706 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_SETFOCUSWINDOW
707 | DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
708 ok(hr == DDERR_NOHWND, "Got unexpected hr %#x.\n", hr);
709 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
710 ok(!!device_window, "Device window not found.\n");
712 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
713 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
714 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
715 ok(!device_window, "Unexpected device window found.\n");
716 hr = IDirectDraw7_SetCooperativeLevel(ddraw, focus_window, DDSCL_SETFOCUSWINDOW
717 | DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
718 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
719 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
720 ok(!!device_window, "Device window not found.\n");
722 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
723 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
724 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
725 ok(!device_window, "Unexpected device window found.\n");
726 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
727 ok(hr == DDERR_NOFOCUSWINDOW, "Got unexpected hr %#x.\n", hr);
728 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
729 ok(!device_window, "Unexpected device window found.\n");
730 hr = IDirectDraw7_SetCooperativeLevel(ddraw, focus_window, DDSCL_SETFOCUSWINDOW);
731 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
732 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
733 ok(!device_window, "Unexpected device window found.\n");
734 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
735 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
736 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
737 ok(!!device_window, "Device window not found.\n");
739 IDirectDraw7_Release(ddraw);
740 DestroyWindow(focus_window);
743 static void test_clipper_blt(void)
745 IDirectDrawSurface7 *src_surface, *dst_surface;
746 RECT client_rect, src_rect;
747 IDirectDrawClipper *clipper;
748 DDSURFACEDESC2 surface_desc;
749 unsigned int i, j, x, y;
750 IDirectDraw7 *ddraw;
751 RGNDATA *rgn_data;
752 D3DCOLOR color;
753 ULONG refcount;
754 HRGN r1, r2;
755 HWND window;
756 DDBLTFX fx;
757 HRESULT hr;
758 DWORD *ptr;
759 DWORD ret;
761 static const DWORD src_data[] =
763 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
764 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
765 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
767 static const D3DCOLOR expected1[] =
769 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
770 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
771 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
772 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
774 /* Nvidia on Windows seems to have an off-by-one error
775 * when processing source rectangles. Our left = 1 and
776 * right = 5 input reads from x = {1, 2, 3}. x = 4 is
777 * read as well, but only for the edge pixels on the
778 * output image. The bug happens on the y axis as well,
779 * but we only read one row there, and all source rows
780 * contain the same data. This bug is not dependent on
781 * the presence of a clipper. */
782 static const D3DCOLOR expected1_broken[] =
784 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
785 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
786 0x00000000, 0x00000000, 0x00ff0000, 0x00ff0000,
787 0x00000000, 0x00000000, 0x0000ff00, 0x00ff0000,
789 static const D3DCOLOR expected2[] =
791 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
792 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
793 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
794 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
797 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
798 10, 10, 640, 480, 0, 0, 0, 0);
799 ShowWindow(window, SW_SHOW);
800 ddraw = create_ddraw();
801 ok(!!ddraw, "Failed to create a ddraw object.\n");
803 ret = GetClientRect(window, &client_rect);
804 ok(ret, "Failed to get client rect.\n");
805 ret = MapWindowPoints(window, NULL, (POINT *)&client_rect, 2);
806 ok(ret, "Failed to map client rect.\n");
808 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
809 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
811 hr = IDirectDraw7_CreateClipper(ddraw, 0, &clipper, NULL);
812 ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr);
813 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
814 ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr);
815 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
816 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
817 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
818 ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr);
819 rgn_data = HeapAlloc(GetProcessHeap(), 0, ret);
820 hr = IDirectDrawClipper_GetClipList(clipper, NULL, rgn_data, &ret);
821 ok(SUCCEEDED(hr), "Failed to get clip list, hr %#x.\n", hr);
822 ok(rgn_data->rdh.dwSize == sizeof(rgn_data->rdh), "Got unexpected structure size %#x.\n", rgn_data->rdh.dwSize);
823 ok(rgn_data->rdh.iType == RDH_RECTANGLES, "Got unexpected type %#x.\n", rgn_data->rdh.iType);
824 ok(rgn_data->rdh.nCount >= 1, "Got unexpected count %u.\n", rgn_data->rdh.nCount);
825 ok(EqualRect(&rgn_data->rdh.rcBound, &client_rect),
826 "Got unexpected bounding rect %s, expected %s.\n",
827 wine_dbgstr_rect(&rgn_data->rdh.rcBound), wine_dbgstr_rect(&client_rect));
828 HeapFree(GetProcessHeap(), 0, rgn_data);
830 r1 = CreateRectRgn(0, 0, 320, 240);
831 ok(!!r1, "Failed to create region.\n");
832 r2 = CreateRectRgn(320, 240, 640, 480);
833 ok(!!r2, "Failed to create region.\n");
834 CombineRgn(r1, r1, r2, RGN_OR);
835 ret = GetRegionData(r1, 0, NULL);
836 rgn_data = HeapAlloc(GetProcessHeap(), 0, ret);
837 ret = GetRegionData(r1, ret, rgn_data);
838 ok(!!ret, "Failed to get region data.\n");
840 DeleteObject(r2);
841 DeleteObject(r1);
843 hr = IDirectDrawClipper_SetClipList(clipper, rgn_data, 0);
844 ok(hr == DDERR_CLIPPERISUSINGHWND, "Got unexpected hr %#x.\n", hr);
845 hr = IDirectDrawClipper_SetHWnd(clipper, 0, NULL);
846 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
847 hr = IDirectDrawClipper_SetClipList(clipper, rgn_data, 0);
848 ok(SUCCEEDED(hr), "Failed to set clip list, hr %#x.\n", hr);
850 HeapFree(GetProcessHeap(), 0, rgn_data);
852 memset(&surface_desc, 0, sizeof(surface_desc));
853 surface_desc.dwSize = sizeof(surface_desc);
854 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
855 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
856 surface_desc.dwWidth = 640;
857 surface_desc.dwHeight = 480;
858 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
859 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
860 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
861 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
862 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
863 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
865 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &src_surface, NULL);
866 ok(SUCCEEDED(hr), "Failed to create source surface, hr %#x.\n", hr);
867 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &dst_surface, NULL);
868 ok(SUCCEEDED(hr), "Failed to create destination surface, hr %#x.\n", hr);
870 memset(&fx, 0, sizeof(fx));
871 fx.dwSize = sizeof(fx);
872 hr = IDirectDrawSurface7_Blt(src_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
873 ok(SUCCEEDED(hr), "Failed to clear source surface, hr %#x.\n", hr);
874 hr = IDirectDrawSurface7_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
875 ok(SUCCEEDED(hr), "Failed to clear destination surface, hr %#x.\n", hr);
877 hr = IDirectDrawSurface7_Lock(src_surface, NULL, &surface_desc, 0, NULL);
878 ok(SUCCEEDED(hr), "Failed to lock source surface, hr %#x.\n", hr);
879 ok(U1(surface_desc).lPitch == 2560, "Got unexpected surface pitch %u.\n", U1(surface_desc).lPitch);
880 ptr = surface_desc.lpSurface;
881 memcpy(&ptr[ 0], &src_data[ 0], 6 * sizeof(DWORD));
882 memcpy(&ptr[ 640], &src_data[ 6], 6 * sizeof(DWORD));
883 memcpy(&ptr[1280], &src_data[12], 6 * sizeof(DWORD));
884 hr = IDirectDrawSurface7_Unlock(src_surface, NULL);
885 ok(SUCCEEDED(hr), "Failed to unlock source surface, hr %#x.\n", hr);
887 hr = IDirectDrawSurface7_SetClipper(dst_surface, clipper);
888 ok(SUCCEEDED(hr), "Failed to set clipper, hr %#x.\n", hr);
890 SetRect(&src_rect, 1, 1, 5, 2);
891 hr = IDirectDrawSurface7_Blt(dst_surface, NULL, src_surface, &src_rect, DDBLT_WAIT, NULL);
892 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
893 for (i = 0; i < 4; ++i)
895 for (j = 0; j < 4; ++j)
897 x = 80 * ((2 * j) + 1);
898 y = 60 * ((2 * i) + 1);
899 color = get_surface_color(dst_surface, x, y);
900 ok(compare_color(color, expected1[i * 4 + j], 1)
901 || broken(compare_color(color, expected1_broken[i * 4 + j], 1)),
902 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected1[i * 4 + j], x, y, color);
906 U5(fx).dwFillColor = 0xff0000ff;
907 hr = IDirectDrawSurface7_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
908 ok(SUCCEEDED(hr), "Failed to clear destination surface, hr %#x.\n", hr);
909 for (i = 0; i < 4; ++i)
911 for (j = 0; j < 4; ++j)
913 x = 80 * ((2 * j) + 1);
914 y = 60 * ((2 * i) + 1);
915 color = get_surface_color(dst_surface, x, y);
916 ok(compare_color(color, expected2[i * 4 + j], 1),
917 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected2[i * 4 + j], x, y, color);
921 hr = IDirectDrawSurface7_BltFast(dst_surface, 0, 0, src_surface, NULL, DDBLTFAST_WAIT);
922 ok(hr == DDERR_BLTFASTCANTCLIP, "Got unexpected hr %#x.\n", hr);
924 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
925 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
926 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
927 ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr);
928 DestroyWindow(window);
929 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
930 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
931 hr = IDirectDrawClipper_SetHWnd(clipper, 0, NULL);
932 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
933 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
934 ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr);
935 hr = IDirectDrawClipper_SetClipList(clipper, NULL, 0);
936 ok(SUCCEEDED(hr), "Failed to set clip list, hr %#x.\n", hr);
937 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
938 ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr);
939 hr = IDirectDrawSurface7_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
940 ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr);
942 IDirectDrawSurface7_Release(dst_surface);
943 IDirectDrawSurface7_Release(src_surface);
944 refcount = IDirectDrawClipper_Release(clipper);
945 ok(!refcount, "Clipper has %u references left.\n", refcount);
946 IDirectDraw7_Release(ddraw);
949 static void test_coop_level_d3d_state(void)
951 IDirectDrawSurface7 *rt, *surface;
952 IDirect3DDevice7 *device;
953 IDirectDraw7 *ddraw;
954 IDirect3D7 *d3d;
955 D3DCOLOR color;
956 DWORD value;
957 HWND window;
958 HRESULT hr;
960 window = create_window();
961 if (!(device = create_device(window, DDSCL_NORMAL)))
963 skip("Failed to create a 3D device, skipping test.\n");
964 DestroyWindow(window);
965 return;
968 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
969 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
970 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_ZENABLE, &value);
971 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
972 ok(!!value, "Got unexpected z-enable state %#x.\n", value);
973 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, &value);
974 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
975 ok(!value, "Got unexpected alpha blend enable state %#x.\n", value);
976 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);
977 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
978 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff0000, 0.0f, 0);
979 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
980 color = get_surface_color(rt, 320, 240);
981 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
983 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
984 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
985 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
986 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
987 IDirect3D7_Release(d3d);
988 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
989 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
990 hr = IDirectDrawSurface7_IsLost(rt);
991 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
992 hr = IDirectDraw7_RestoreAllSurfaces(ddraw);
993 ok(SUCCEEDED(hr), "Failed to restore surfaces, hr %#x.\n", hr);
994 IDirectDraw7_Release(ddraw);
996 hr = IDirect3DDevice7_GetRenderTarget(device, &surface);
997 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
998 ok(surface == rt, "Got unexpected surface %p.\n", surface);
999 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_ZENABLE, &value);
1000 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
1001 ok(!!value, "Got unexpected z-enable state %#x.\n", value);
1002 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, &value);
1003 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
1004 ok(!!value, "Got unexpected alpha blend enable state %#x.\n", value);
1005 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff00ff00, 0.0f, 0);
1006 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
1007 color = get_surface_color(rt, 320, 240);
1008 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
1010 IDirectDrawSurface7_Release(surface);
1011 IDirectDrawSurface7_Release(rt);
1012 IDirect3DDevice7_Release(device);
1013 DestroyWindow(window);
1016 static void test_surface_interface_mismatch(void)
1018 IDirectDraw7 *ddraw = NULL;
1019 IDirect3D7 *d3d = NULL;
1020 IDirectDrawSurface7 *surface = NULL, *ds;
1021 IDirectDrawSurface3 *surface3 = NULL;
1022 IDirect3DDevice7 *device = NULL;
1023 DDSURFACEDESC2 surface_desc;
1024 DDPIXELFORMAT z_fmt;
1025 ULONG refcount;
1026 HRESULT hr;
1027 D3DCOLOR color;
1028 HWND window;
1030 window = create_window();
1031 ddraw = create_ddraw();
1032 ok(!!ddraw, "Failed to create a ddraw object.\n");
1033 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
1034 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
1036 memset(&surface_desc, 0, sizeof(surface_desc));
1037 surface_desc.dwSize = sizeof(surface_desc);
1038 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1039 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
1040 surface_desc.dwWidth = 640;
1041 surface_desc.dwHeight = 480;
1043 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1044 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1046 hr = IDirectDrawSurface7_QueryInterface(surface, &IID_IDirectDrawSurface3, (void **)&surface3);
1047 ok(SUCCEEDED(hr), "Failed to QI IDirectDrawSurface3, hr %#x.\n", hr);
1049 if (FAILED(IDirectDraw7_QueryInterface(ddraw, &IID_IDirect3D7, (void **)&d3d)))
1051 skip("D3D interface is not available, skipping test.\n");
1052 goto cleanup;
1055 memset(&z_fmt, 0, sizeof(z_fmt));
1056 hr = IDirect3D7_EnumZBufferFormats(d3d, &IID_IDirect3DHALDevice, enum_z_fmt, &z_fmt);
1057 if (FAILED(hr) || !z_fmt.dwSize)
1059 skip("No depth buffer formats available, skipping test.\n");
1060 goto cleanup;
1063 memset(&surface_desc, 0, sizeof(surface_desc));
1064 surface_desc.dwSize = sizeof(surface_desc);
1065 surface_desc.dwFlags = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT;
1066 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
1067 U4(surface_desc).ddpfPixelFormat = z_fmt;
1068 surface_desc.dwWidth = 640;
1069 surface_desc.dwHeight = 480;
1070 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &ds, NULL);
1071 ok(SUCCEEDED(hr), "Failed to create depth buffer, hr %#x.\n", hr);
1072 if (FAILED(hr))
1073 goto cleanup;
1075 /* Using a different surface interface version still works */
1076 hr = IDirectDrawSurface3_AddAttachedSurface(surface3, (IDirectDrawSurface3 *)ds);
1077 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
1078 refcount = IDirectDrawSurface7_Release(ds);
1079 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
1080 if (FAILED(hr))
1081 goto cleanup;
1083 /* Here too */
1084 hr = IDirect3D7_CreateDevice(d3d, &IID_IDirect3DHALDevice, (IDirectDrawSurface7 *)surface3, &device);
1085 ok(SUCCEEDED(hr), "Failed to create d3d device.\n");
1086 if (FAILED(hr))
1087 goto cleanup;
1089 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff0000, 0.0f, 0);
1090 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
1091 color = get_surface_color(surface, 320, 240);
1092 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
1094 cleanup:
1095 if (surface3) IDirectDrawSurface3_Release(surface3);
1096 if (surface) IDirectDrawSurface7_Release(surface);
1097 if (device) IDirect3DDevice7_Release(device);
1098 if (d3d) IDirect3D7_Release(d3d);
1099 if (ddraw) IDirectDraw7_Release(ddraw);
1100 DestroyWindow(window);
1103 static void test_coop_level_threaded(void)
1105 struct create_window_thread_param p;
1106 IDirectDraw7 *ddraw;
1107 HRESULT hr;
1109 ddraw = create_ddraw();
1110 ok(!!ddraw, "Failed to create a ddraw object.\n");
1111 create_window_thread(&p);
1113 hr = IDirectDraw7_SetCooperativeLevel(ddraw, p.window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
1114 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
1116 IDirectDraw7_Release(ddraw);
1117 destroy_window_thread(&p);
1120 static void test_depth_blit(void)
1122 IDirect3DDevice7 *device;
1123 static struct
1125 float x, y, z;
1126 DWORD color;
1128 quad1[] =
1130 { -1.0, 1.0, 0.50f, 0xff00ff00},
1131 { 1.0, 1.0, 0.50f, 0xff00ff00},
1132 { -1.0, -1.0, 0.50f, 0xff00ff00},
1133 { 1.0, -1.0, 0.50f, 0xff00ff00},
1135 static const D3DCOLOR expected_colors[4][4] =
1137 {0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00},
1138 {0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00},
1139 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1140 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1142 DDSURFACEDESC2 ddsd_new, ddsd_existing;
1144 IDirectDrawSurface7 *ds1, *ds2, *ds3, *rt;
1145 RECT src_rect, dst_rect;
1146 unsigned int i, j;
1147 D3DCOLOR color;
1148 HRESULT hr;
1149 IDirect3D7 *d3d;
1150 IDirectDraw7 *ddraw;
1151 DDBLTFX fx;
1152 HWND window;
1154 window = create_window();
1155 if (!(device = create_device(window, DDSCL_NORMAL)))
1157 skip("Failed to create a 3D device, skipping test.\n");
1158 DestroyWindow(window);
1159 return;
1162 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
1163 ok(SUCCEEDED(hr), "Failed to get Direct3D7 interface, hr %#x.\n", hr);
1164 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
1165 ok(SUCCEEDED(hr), "Failed to get DirectDraw7 interface, hr %#x.\n", hr);
1166 IDirect3D7_Release(d3d);
1168 ds1 = get_depth_stencil(device);
1170 memset(&ddsd_new, 0, sizeof(ddsd_new));
1171 ddsd_new.dwSize = sizeof(ddsd_new);
1172 memset(&ddsd_existing, 0, sizeof(ddsd_existing));
1173 ddsd_existing.dwSize = sizeof(ddsd_existing);
1174 hr = IDirectDrawSurface7_GetSurfaceDesc(ds1, &ddsd_existing);
1175 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
1176 ddsd_new.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
1177 ddsd_new.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
1178 ddsd_new.dwWidth = ddsd_existing.dwWidth;
1179 ddsd_new.dwHeight = ddsd_existing.dwHeight;
1180 U4(ddsd_new).ddpfPixelFormat = U4(ddsd_existing).ddpfPixelFormat;
1181 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd_new, &ds2, NULL);
1182 ok(SUCCEEDED(hr), "Failed to create a z buffer, hr %#x.\n", hr);
1183 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd_new, &ds3, NULL);
1184 ok(SUCCEEDED(hr), "Failed to create a z buffer, hr %#x.\n", hr);
1185 IDirectDraw7_Release(ddraw);
1187 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_TRUE);
1188 ok(SUCCEEDED(hr), "Failed to enable z testing, hr %#x.\n", hr);
1189 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZFUNC, D3DCMP_LESSEQUAL);
1190 ok(SUCCEEDED(hr), "Failed to set the z function, hr %#x.\n", hr);
1191 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
1192 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
1194 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER, 0, 0.0f, 0);
1195 ok(SUCCEEDED(hr), "Failed to clear the z buffer, hr %#x.\n", hr);
1197 /* Partial blit. */
1198 SetRect(&src_rect, 0, 0, 320, 240);
1199 SetRect(&dst_rect, 0, 0, 320, 240);
1200 hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1201 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1202 /* Different locations. */
1203 SetRect(&src_rect, 0, 0, 320, 240);
1204 SetRect(&dst_rect, 320, 240, 640, 480);
1205 hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1206 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1207 /* Stretched. */
1208 SetRect(&src_rect, 0, 0, 320, 240);
1209 SetRect(&dst_rect, 0, 0, 640, 480);
1210 hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1211 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1212 /* Flipped. */
1213 SetRect(&src_rect, 0, 480, 640, 0);
1214 SetRect(&dst_rect, 0, 0, 640, 480);
1215 hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1216 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
1217 SetRect(&src_rect, 0, 0, 640, 480);
1218 SetRect(&dst_rect, 0, 480, 640, 0);
1219 hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1220 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
1221 /* Full, explicit. */
1222 SetRect(&src_rect, 0, 0, 640, 480);
1223 SetRect(&dst_rect, 0, 0, 640, 480);
1224 hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1225 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1226 /* Depth -> color blit: Succeeds on Win7 + Radeon HD 5700, fails on WinXP + Radeon X1600 */
1228 /* Depth blit inside a BeginScene / EndScene pair */
1229 hr = IDirect3DDevice7_BeginScene(device);
1230 ok(SUCCEEDED(hr), "Failed to start scene, hr %#x.\n", hr);
1231 /* From the current depth stencil */
1232 hr = IDirectDrawSurface7_Blt(ds2, NULL, ds1, NULL, DDBLT_WAIT, NULL);
1233 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1234 /* To the current depth stencil */
1235 hr = IDirectDrawSurface7_Blt(ds1, NULL, ds2, NULL, DDBLT_WAIT, NULL);
1236 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1237 /* Between unbound surfaces */
1238 hr = IDirectDrawSurface7_Blt(ds3, NULL, ds2, NULL, DDBLT_WAIT, NULL);
1239 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1240 hr = IDirect3DDevice7_EndScene(device);
1241 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1243 /* Avoid changing the depth stencil, it doesn't work properly on Windows.
1244 * Instead use DDBLT_DEPTHFILL to clear the depth stencil. Unfortunately
1245 * drivers disagree on the meaning of dwFillDepth. Only 0 seems to produce
1246 * a reliable result(z = 0.0) */
1247 memset(&fx, 0, sizeof(fx));
1248 fx.dwSize = sizeof(fx);
1249 hr = IDirectDrawSurface7_Blt(ds2, NULL, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
1250 ok(SUCCEEDED(hr), "Failed to clear the source z buffer, hr %#x.\n", hr);
1252 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER | D3DCLEAR_TARGET, 0xffff0000, 1.0f, 0);
1253 ok(SUCCEEDED(hr), "Failed to clear the color and z buffers, hr %#x.\n", hr);
1254 SetRect(&dst_rect, 0, 0, 320, 240);
1255 hr = IDirectDrawSurface7_Blt(ds1, &dst_rect, ds2, NULL, DDBLT_WAIT, NULL);
1256 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1257 IDirectDrawSurface7_Release(ds3);
1258 IDirectDrawSurface7_Release(ds2);
1259 IDirectDrawSurface7_Release(ds1);
1261 hr = IDirect3DDevice7_BeginScene(device);
1262 ok(SUCCEEDED(hr), "Failed to start scene, hr %#x.\n", hr);
1263 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE,
1264 quad1, 4, 0);
1265 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1266 hr = IDirect3DDevice7_EndScene(device);
1267 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1269 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
1270 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1271 for (i = 0; i < 4; ++i)
1273 for (j = 0; j < 4; ++j)
1275 unsigned int x = 80 * ((2 * j) + 1);
1276 unsigned int y = 60 * ((2 * i) + 1);
1277 color = get_surface_color(rt, x, y);
1278 ok(compare_color(color, expected_colors[i][j], 1),
1279 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected_colors[i][j], x, y, color);
1283 IDirectDrawSurface7_Release(rt);
1284 IDirect3DDevice7_Release(device);
1285 DestroyWindow(window);
1288 static void test_texture_load_ckey(void)
1290 HWND window;
1291 IDirect3DDevice7 *device;
1292 IDirectDraw7 *ddraw;
1293 IDirectDrawSurface7 *src;
1294 IDirectDrawSurface7 *dst;
1295 DDSURFACEDESC2 ddsd;
1296 HRESULT hr;
1297 DDCOLORKEY ckey;
1298 IDirect3D7 *d3d;
1300 window = create_window();
1301 if (!(device = create_device(window, DDSCL_NORMAL)))
1303 skip("Failed to create a 3D device, skipping test.\n");
1304 DestroyWindow(window);
1305 return;
1308 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
1309 ok(SUCCEEDED(hr), "Failed to get Direct3D7 interface, hr %#x.\n", hr);
1310 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
1311 ok(SUCCEEDED(hr), "Failed to get DirectDraw7 interface, hr %#x.\n", hr);
1312 IDirect3D7_Release(d3d);
1314 memset(&ddsd, 0, sizeof(ddsd));
1315 ddsd.dwSize = sizeof(ddsd);
1316 ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
1317 ddsd.dwHeight = 128;
1318 ddsd.dwWidth = 128;
1319 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY;
1320 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &src, NULL);
1321 ok(SUCCEEDED(hr), "Failed to create source texture, hr %#x.\n", hr);
1322 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1323 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &dst, NULL);
1324 ok(SUCCEEDED(hr), "Failed to create destination texture, hr %#x.\n", hr);
1326 /* No surface has a color key */
1327 hr = IDirect3DDevice7_Load(device, dst, NULL, src, NULL, 0);
1328 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1329 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0xdeadbeef;
1330 hr = IDirectDrawSurface7_GetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1331 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1332 ok(ckey.dwColorSpaceLowValue == 0xdeadbeef, "dwColorSpaceLowValue is %#x.\n", ckey.dwColorSpaceLowValue);
1333 ok(ckey.dwColorSpaceHighValue == 0xdeadbeef, "dwColorSpaceHighValue is %#x.\n", ckey.dwColorSpaceHighValue);
1335 /* Source surface has a color key */
1336 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0x0000ff00;
1337 hr = IDirectDrawSurface7_SetColorKey(src, DDCKEY_SRCBLT, &ckey);
1338 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1339 hr = IDirect3DDevice7_Load(device, dst, NULL, src, NULL, 0);
1340 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1341 hr = IDirectDrawSurface7_GetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1342 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1343 ok(ckey.dwColorSpaceLowValue == 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey.dwColorSpaceLowValue);
1344 ok(ckey.dwColorSpaceHighValue == 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey.dwColorSpaceHighValue);
1346 /* Both surfaces have a color key: Dest ckey is overwritten */
1347 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0x000000ff;
1348 hr = IDirectDrawSurface7_SetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1349 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1350 hr = IDirect3DDevice7_Load(device, dst, NULL, src, NULL, 0);
1351 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1352 hr = IDirectDrawSurface7_GetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1353 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1354 ok(ckey.dwColorSpaceLowValue == 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey.dwColorSpaceLowValue);
1355 ok(ckey.dwColorSpaceHighValue == 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey.dwColorSpaceHighValue);
1357 /* Only the destination has a color key: It is deleted. This behavior differs from
1358 * IDirect3DTexture(2)::Load */
1359 hr = IDirectDrawSurface7_SetColorKey(src, DDCKEY_SRCBLT, NULL);
1360 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1361 hr = IDirectDrawSurface7_GetColorKey(src, DDCKEY_SRCBLT, &ckey);
1362 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1363 hr = IDirect3DDevice7_Load(device, dst, NULL, src, NULL, 0);
1364 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1365 hr = IDirectDrawSurface7_GetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1366 todo_wine ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1368 IDirectDrawSurface7_Release(dst);
1369 IDirectDrawSurface7_Release(src);
1370 IDirectDraw7_Release(ddraw);
1371 IDirect3DDevice7_Release(device);
1372 DestroyWindow(window);
1375 static void test_zenable(void)
1377 static struct
1379 struct vec4 position;
1380 D3DCOLOR diffuse;
1382 tquad[] =
1384 {{ 0.0f, 480.0f, -0.5f, 1.0f}, 0xff00ff00},
1385 {{ 0.0f, 0.0f, -0.5f, 1.0f}, 0xff00ff00},
1386 {{640.0f, 480.0f, 1.5f, 1.0f}, 0xff00ff00},
1387 {{640.0f, 0.0f, 1.5f, 1.0f}, 0xff00ff00},
1389 IDirect3DDevice7 *device;
1390 IDirectDrawSurface7 *rt;
1391 D3DCOLOR color;
1392 HWND window;
1393 HRESULT hr;
1394 UINT x, y;
1395 UINT i, j;
1397 window = create_window();
1398 if (!(device = create_device(window, DDSCL_NORMAL)))
1400 skip("Failed to create a 3D device, skipping test.\n");
1401 DestroyWindow(window);
1402 return;
1405 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
1406 ok(SUCCEEDED(hr), "Failed to disable z-buffering, hr %#x.\n", hr);
1408 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffff0000, 0.0f, 0);
1409 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
1410 hr = IDirect3DDevice7_BeginScene(device);
1411 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1412 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_DIFFUSE, tquad, 4, 0);
1413 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1414 hr = IDirect3DDevice7_EndScene(device);
1415 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1417 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
1418 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1419 for (i = 0; i < 4; ++i)
1421 for (j = 0; j < 4; ++j)
1423 x = 80 * ((2 * j) + 1);
1424 y = 60 * ((2 * i) + 1);
1425 color = get_surface_color(rt, x, y);
1426 ok(compare_color(color, 0x0000ff00, 1),
1427 "Expected color 0x0000ff00 at %u, %u, got 0x%08x.\n", x, y, color);
1430 IDirectDrawSurface7_Release(rt);
1432 IDirect3DDevice7_Release(device);
1433 DestroyWindow(window);
1436 static void test_ck_rgba(void)
1438 static struct
1440 struct vec4 position;
1441 struct vec2 texcoord;
1443 tquad[] =
1445 {{ 0.0f, 480.0f, 0.25f, 1.0f}, {0.0f, 0.0f}},
1446 {{ 0.0f, 0.0f, 0.25f, 1.0f}, {0.0f, 1.0f}},
1447 {{640.0f, 480.0f, 0.25f, 1.0f}, {1.0f, 0.0f}},
1448 {{640.0f, 0.0f, 0.25f, 1.0f}, {1.0f, 1.0f}},
1449 {{ 0.0f, 480.0f, 0.75f, 1.0f}, {0.0f, 0.0f}},
1450 {{ 0.0f, 0.0f, 0.75f, 1.0f}, {0.0f, 1.0f}},
1451 {{640.0f, 480.0f, 0.75f, 1.0f}, {1.0f, 0.0f}},
1452 {{640.0f, 0.0f, 0.75f, 1.0f}, {1.0f, 1.0f}},
1454 static const struct
1456 D3DCOLOR fill_color;
1457 BOOL color_key;
1458 BOOL blend;
1459 D3DCOLOR result1, result1_broken;
1460 D3DCOLOR result2, result2_broken;
1462 tests[] =
1464 /* r200 on Windows doesn't check the alpha component when applying the color
1465 * key, so the key matches on every texel. */
1466 {0xff00ff00, TRUE, TRUE, 0x00ff0000, 0x00ff0000, 0x000000ff, 0x000000ff},
1467 {0xff00ff00, TRUE, FALSE, 0x00ff0000, 0x00ff0000, 0x000000ff, 0x000000ff},
1468 {0xff00ff00, FALSE, TRUE, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1469 {0xff00ff00, FALSE, FALSE, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1470 {0x7f00ff00, TRUE, TRUE, 0x00807f00, 0x00ff0000, 0x00807f00, 0x000000ff},
1471 {0x7f00ff00, TRUE, FALSE, 0x0000ff00, 0x00ff0000, 0x0000ff00, 0x000000ff},
1472 {0x7f00ff00, FALSE, TRUE, 0x00807f00, 0x00807f00, 0x00807f00, 0x00807f00},
1473 {0x7f00ff00, FALSE, FALSE, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1476 IDirectDrawSurface7 *texture;
1477 DDSURFACEDESC2 surface_desc;
1478 IDirect3DDevice7 *device;
1479 IDirectDrawSurface7 *rt;
1480 IDirectDraw7 *ddraw;
1481 IDirect3D7 *d3d;
1482 D3DCOLOR color;
1483 HWND window;
1484 DDBLTFX fx;
1485 HRESULT hr;
1486 UINT i;
1488 window = create_window();
1489 if (!(device = create_device(window, DDSCL_NORMAL)))
1491 skip("Failed to create a 3D device, skipping test.\n");
1492 DestroyWindow(window);
1493 return;
1496 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
1497 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
1498 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
1499 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
1500 IDirect3D7_Release(d3d);
1502 memset(&surface_desc, 0, sizeof(surface_desc));
1503 surface_desc.dwSize = sizeof(surface_desc);
1504 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CKSRCBLT;
1505 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1506 surface_desc.dwWidth = 256;
1507 surface_desc.dwHeight = 256;
1508 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
1509 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
1510 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
1511 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
1512 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
1513 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
1514 U5(U4(surface_desc).ddpfPixelFormat).dwRGBAlphaBitMask = 0xff000000;
1515 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0xff00ff00;
1516 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0xff00ff00;
1517 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &texture, NULL);
1518 ok(SUCCEEDED(hr), "Failed to create destination surface, hr %#x.\n", hr);
1520 hr = IDirect3DDevice7_SetTexture(device, 0, texture);
1521 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
1522 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);
1523 ok(SUCCEEDED(hr), "Failed to enable alpha blending, hr %#x.\n", hr);
1524 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA);
1525 ok(SUCCEEDED(hr), "Failed to enable alpha blending, hr %#x.\n", hr);
1527 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
1528 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1530 for (i = 0; i < ARRAY_SIZE(tests); ++i)
1532 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, tests[i].color_key);
1533 ok(SUCCEEDED(hr), "Failed to enable color keying, hr %#x.\n", hr);
1534 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, tests[i].blend);
1535 ok(SUCCEEDED(hr), "Failed to enable alpha blending, hr %#x.\n", hr);
1537 memset(&fx, 0, sizeof(fx));
1538 fx.dwSize = sizeof(fx);
1539 U5(fx).dwFillColor = tests[i].fill_color;
1540 hr = IDirectDrawSurface7_Blt(texture, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
1541 ok(SUCCEEDED(hr), "Failed to fill texture, hr %#x.\n", hr);
1543 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffff0000, 1.0f, 0);
1544 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
1545 hr = IDirect3DDevice7_BeginScene(device);
1546 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1547 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_TEX1, &tquad[0], 4, 0);
1548 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1549 hr = IDirect3DDevice7_EndScene(device);
1550 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1552 color = get_surface_color(rt, 320, 240);
1553 ok(compare_color(color, tests[i].result1, 1) || compare_color(color, tests[i].result1_broken, 1),
1554 "Expected color 0x%08x for test %u, got 0x%08x.\n",
1555 tests[i].result1, i, color);
1557 U5(fx).dwFillColor = 0xff0000ff;
1558 hr = IDirectDrawSurface7_Blt(texture, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
1559 ok(SUCCEEDED(hr), "Failed to fill texture, hr %#x.\n", hr);
1561 hr = IDirect3DDevice7_BeginScene(device);
1562 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1563 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_TEX1, &tquad[4], 4, 0);
1564 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1565 hr = IDirect3DDevice7_EndScene(device);
1566 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1568 /* This tests that fragments that are masked out by the color key are
1569 * discarded, instead of just fully transparent. */
1570 color = get_surface_color(rt, 320, 240);
1571 ok(compare_color(color, tests[i].result2, 1) || compare_color(color, tests[i].result2_broken, 1),
1572 "Expected color 0x%08x for test %u, got 0x%08x.\n",
1573 tests[i].result2, i, color);
1576 IDirectDrawSurface7_Release(rt);
1577 IDirectDrawSurface7_Release(texture);
1578 IDirectDraw7_Release(ddraw);
1579 IDirect3DDevice7_Release(device);
1580 DestroyWindow(window);
1583 static void test_ck_default(void)
1585 static struct
1587 struct vec4 position;
1588 struct vec2 texcoord;
1590 tquad[] =
1592 {{ 0.0f, 480.0f, 0.0f, 1.0f}, {0.0f, 0.0f}},
1593 {{ 0.0f, 0.0f, 0.0f, 1.0f}, {0.0f, 1.0f}},
1594 {{640.0f, 480.0f, 0.0f, 1.0f}, {1.0f, 0.0f}},
1595 {{640.0f, 0.0f, 0.0f, 1.0f}, {1.0f, 1.0f}},
1597 IDirectDrawSurface7 *surface, *rt;
1598 DDSURFACEDESC2 surface_desc;
1599 IDirect3DDevice7 *device;
1600 IDirectDraw7 *ddraw;
1601 IDirect3D7 *d3d;
1602 D3DCOLOR color;
1603 DWORD value;
1604 HWND window;
1605 DDBLTFX fx;
1606 HRESULT hr;
1608 window = create_window();
1609 if (!(device = create_device(window, DDSCL_NORMAL)))
1611 skip("Failed to create a 3D device, skipping test.\n");
1612 DestroyWindow(window);
1613 return;
1616 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
1617 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
1618 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
1619 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
1620 IDirect3D7_Release(d3d);
1622 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
1623 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1625 memset(&surface_desc, 0, sizeof(surface_desc));
1626 surface_desc.dwSize = sizeof(surface_desc);
1627 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CKSRCBLT;
1628 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1629 surface_desc.dwWidth = 256;
1630 surface_desc.dwHeight = 256;
1631 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
1632 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
1633 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
1634 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
1635 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
1636 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
1637 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x000000ff;
1638 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x000000ff;
1639 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1640 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1641 hr = IDirect3DDevice7_SetTexture(device, 0, surface);
1642 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
1644 memset(&fx, 0, sizeof(fx));
1645 fx.dwSize = sizeof(fx);
1646 U5(fx).dwFillColor = 0x000000ff;
1647 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
1648 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
1650 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff00ff00, 1.0f, 0);
1651 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
1652 hr = IDirect3DDevice7_BeginScene(device);
1653 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1654 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, &value);
1655 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
1656 ok(!value, "Got unexpected color keying state %#x.\n", value);
1657 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_TEX1, &tquad[0], 4, 0);
1658 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1659 hr = IDirect3DDevice7_EndScene(device);
1660 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1661 color = get_surface_color(rt, 320, 240);
1662 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
1664 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff00ff00, 1.0f, 0);
1665 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
1666 hr = IDirect3DDevice7_BeginScene(device);
1667 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1668 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, TRUE);
1669 ok(SUCCEEDED(hr), "Failed to enable color keying, hr %#x.\n", hr);
1670 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_TEX1, &tquad[0], 4, 0);
1671 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1672 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, &value);
1673 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
1674 ok(!!value, "Got unexpected color keying state %#x.\n", value);
1675 hr = IDirect3DDevice7_EndScene(device);
1676 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1677 color = get_surface_color(rt, 320, 240);
1678 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
1680 IDirectDrawSurface7_Release(surface);
1681 IDirectDrawSurface7_Release(rt);
1682 IDirect3DDevice7_Release(device);
1683 IDirectDraw7_Release(ddraw);
1684 DestroyWindow(window);
1687 static void test_ck_complex(void)
1689 IDirectDrawSurface7 *surface, *mipmap, *tmp;
1690 D3DDEVICEDESC7 device_desc;
1691 DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, {0}};
1692 DDSURFACEDESC2 surface_desc;
1693 IDirect3DDevice7 *device;
1694 DDCOLORKEY color_key;
1695 IDirectDraw7 *ddraw;
1696 IDirect3D7 *d3d;
1697 unsigned int i;
1698 ULONG refcount;
1699 HWND window;
1700 HRESULT hr;
1702 window = create_window();
1703 if (!(device = create_device(window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN)))
1705 skip("Failed to create a 3D device, skipping test.\n");
1706 DestroyWindow(window);
1707 return;
1709 hr = IDirect3DDevice7_GetCaps(device, &device_desc);
1710 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
1711 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
1712 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
1713 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
1714 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
1715 IDirect3D7_Release(d3d);
1717 memset(&surface_desc, 0, sizeof(surface_desc));
1718 surface_desc.dwSize = sizeof(surface_desc);
1719 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1720 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
1721 surface_desc.dwWidth = 128;
1722 surface_desc.dwHeight = 128;
1723 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1724 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1726 hr = IDirectDrawSurface7_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1727 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1728 color_key.dwColorSpaceLowValue = 0x0000ff00;
1729 color_key.dwColorSpaceHighValue = 0x0000ff00;
1730 hr = IDirectDrawSurface7_SetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1731 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1732 memset(&color_key, 0, sizeof(color_key));
1733 hr = IDirectDrawSurface7_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1734 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
1735 ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1736 color_key.dwColorSpaceLowValue);
1737 ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1738 color_key.dwColorSpaceHighValue);
1740 mipmap = surface;
1741 IDirectDrawSurface_AddRef(mipmap);
1742 for (i = 0; i < 7; ++i)
1744 hr = IDirectDrawSurface7_GetAttachedSurface(mipmap, &caps, &tmp);
1745 ok(SUCCEEDED(hr), "Failed to get attached surface, i %u, hr %#x.\n", i, hr);
1746 hr = IDirectDrawSurface7_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1747 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x, i %u.\n", hr, i);
1749 color_key.dwColorSpaceLowValue = 0x000000ff;
1750 color_key.dwColorSpaceHighValue = 0x000000ff;
1751 hr = IDirectDrawSurface7_SetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1752 ok(hr == DDERR_NOTONMIPMAPSUBLEVEL, "Got unexpected hr %#x, i %u.\n", hr, i);
1754 IDirectDrawSurface_Release(mipmap);
1755 mipmap = tmp;
1758 hr = IDirectDrawSurface7_GetAttachedSurface(mipmap, &caps, &tmp);
1759 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
1760 IDirectDrawSurface_Release(mipmap);
1761 refcount = IDirectDrawSurface7_Release(surface);
1762 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1764 memset(&surface_desc, 0, sizeof(surface_desc));
1765 surface_desc.dwSize = sizeof(surface_desc);
1766 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
1767 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
1768 U5(surface_desc).dwBackBufferCount = 1;
1769 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1770 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1772 hr = IDirectDrawSurface7_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1773 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1774 color_key.dwColorSpaceLowValue = 0x0000ff00;
1775 color_key.dwColorSpaceHighValue = 0x0000ff00;
1776 hr = IDirectDrawSurface7_SetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1777 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1778 memset(&color_key, 0, sizeof(color_key));
1779 hr = IDirectDrawSurface7_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1780 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
1781 ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1782 color_key.dwColorSpaceLowValue);
1783 ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1784 color_key.dwColorSpaceHighValue);
1786 hr = IDirectDrawSurface7_GetAttachedSurface(surface, &caps, &tmp);
1787 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
1789 hr = IDirectDrawSurface7_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1790 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x, i %u.\n", hr, i);
1791 color_key.dwColorSpaceLowValue = 0x0000ff00;
1792 color_key.dwColorSpaceHighValue = 0x0000ff00;
1793 hr = IDirectDrawSurface7_SetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1794 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1795 memset(&color_key, 0, sizeof(color_key));
1796 hr = IDirectDrawSurface7_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1797 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
1798 ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1799 color_key.dwColorSpaceLowValue);
1800 ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1801 color_key.dwColorSpaceHighValue);
1803 IDirectDrawSurface_Release(tmp);
1805 refcount = IDirectDrawSurface7_Release(surface);
1806 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1808 if (!(device_desc.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_CUBEMAP))
1810 skip("Device does not support cubemaps.\n");
1811 goto cleanup;
1813 memset(&surface_desc, 0, sizeof(surface_desc));
1814 surface_desc.dwSize = sizeof(surface_desc);
1815 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1816 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
1817 surface_desc.ddsCaps.dwCaps2 = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES;
1818 surface_desc.dwWidth = 128;
1819 surface_desc.dwHeight = 128;
1820 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1821 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1823 hr = IDirectDrawSurface7_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1824 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1825 color_key.dwColorSpaceLowValue = 0x0000ff00;
1826 color_key.dwColorSpaceHighValue = 0x0000ff00;
1827 hr = IDirectDrawSurface7_SetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1828 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1830 caps.dwCaps2 = DDSCAPS2_CUBEMAP_NEGATIVEZ;
1831 hr = IDirectDrawSurface7_GetAttachedSurface(surface, &caps, &mipmap);
1832 ok(SUCCEEDED(hr), "Failed to get attached surface, i %u, hr %#x.\n", i, hr);
1834 hr = IDirectDrawSurface7_GetColorKey(mipmap, DDCKEY_SRCBLT, &color_key);
1835 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1836 color_key.dwColorSpaceLowValue = 0x000000ff;
1837 color_key.dwColorSpaceHighValue = 0x000000ff;
1838 hr = IDirectDrawSurface7_SetColorKey(mipmap, DDCKEY_SRCBLT, &color_key);
1839 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1841 color_key.dwColorSpaceLowValue = 0;
1842 color_key.dwColorSpaceHighValue = 0;
1843 hr = IDirectDrawSurface7_GetColorKey(mipmap, DDCKEY_SRCBLT, &color_key);
1844 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
1845 ok(color_key.dwColorSpaceLowValue == 0x000000ff, "Got unexpected value 0x%08x.\n",
1846 color_key.dwColorSpaceLowValue);
1847 ok(color_key.dwColorSpaceHighValue == 0x000000ff, "Got unexpected value 0x%08x.\n",
1848 color_key.dwColorSpaceHighValue);
1850 IDirectDrawSurface_AddRef(mipmap);
1851 for (i = 0; i < 7; ++i)
1853 hr = IDirectDrawSurface7_GetAttachedSurface(mipmap, &caps, &tmp);
1854 ok(SUCCEEDED(hr), "Failed to get attached surface, i %u, hr %#x.\n", i, hr);
1855 hr = IDirectDrawSurface7_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1856 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x, i %u.\n", hr, i);
1858 color_key.dwColorSpaceLowValue = 0x000000ff;
1859 color_key.dwColorSpaceHighValue = 0x000000ff;
1860 hr = IDirectDrawSurface7_SetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1861 ok(hr == DDERR_NOTONMIPMAPSUBLEVEL, "Got unexpected hr %#x, i %u.\n", hr, i);
1863 IDirectDrawSurface_Release(mipmap);
1864 mipmap = tmp;
1867 IDirectDrawSurface7_Release(mipmap);
1869 refcount = IDirectDrawSurface7_Release(surface);
1870 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1872 cleanup:
1873 IDirectDraw7_Release(ddraw);
1874 refcount = IDirect3DDevice7_Release(device);
1875 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1876 DestroyWindow(window);
1879 struct qi_test
1881 REFIID iid;
1882 REFIID refcount_iid;
1883 HRESULT hr;
1886 static void test_qi(const char *test_name, IUnknown *base_iface,
1887 REFIID refcount_iid, const struct qi_test *tests, UINT entry_count)
1889 ULONG refcount, expected_refcount;
1890 IUnknown *iface1, *iface2;
1891 HRESULT hr;
1892 UINT i, j;
1894 for (i = 0; i < entry_count; ++i)
1896 hr = IUnknown_QueryInterface(base_iface, tests[i].iid, (void **)&iface1);
1897 ok(hr == tests[i].hr, "Got hr %#x for test \"%s\" %u.\n", hr, test_name, i);
1898 if (SUCCEEDED(hr))
1900 for (j = 0; j < entry_count; ++j)
1902 hr = IUnknown_QueryInterface(iface1, tests[j].iid, (void **)&iface2);
1903 ok(hr == tests[j].hr, "Got hr %#x for test \"%s\" %u, %u.\n", hr, test_name, i, j);
1904 if (SUCCEEDED(hr))
1906 expected_refcount = 0;
1907 if (IsEqualGUID(refcount_iid, tests[j].refcount_iid))
1908 ++expected_refcount;
1909 if (IsEqualGUID(tests[i].refcount_iid, tests[j].refcount_iid))
1910 ++expected_refcount;
1911 refcount = IUnknown_Release(iface2);
1912 ok(refcount == expected_refcount, "Got refcount %u for test \"%s\" %u, %u, expected %u.\n",
1913 refcount, test_name, i, j, expected_refcount);
1917 expected_refcount = 0;
1918 if (IsEqualGUID(refcount_iid, tests[i].refcount_iid))
1919 ++expected_refcount;
1920 refcount = IUnknown_Release(iface1);
1921 ok(refcount == expected_refcount, "Got refcount %u for test \"%s\" %u, expected %u.\n",
1922 refcount, test_name, i, expected_refcount);
1927 static void test_surface_qi(void)
1929 static const struct qi_test tests[] =
1931 {&IID_IDirect3DTexture2, NULL, E_NOINTERFACE},
1932 {&IID_IDirect3DTexture, NULL, E_NOINTERFACE},
1933 {&IID_IDirectDrawGammaControl, &IID_IDirectDrawGammaControl, S_OK },
1934 {&IID_IDirectDrawColorControl, NULL, E_NOINTERFACE},
1935 {&IID_IDirectDrawSurface7, &IID_IDirectDrawSurface7, S_OK },
1936 {&IID_IDirectDrawSurface4, &IID_IDirectDrawSurface4, S_OK },
1937 {&IID_IDirectDrawSurface3, &IID_IDirectDrawSurface3, S_OK },
1938 {&IID_IDirectDrawSurface2, &IID_IDirectDrawSurface2, S_OK },
1939 {&IID_IDirectDrawSurface, &IID_IDirectDrawSurface, S_OK },
1940 {&IID_IDirect3DDevice7, NULL, E_NOINTERFACE},
1941 {&IID_IDirect3DDevice3, NULL, E_NOINTERFACE},
1942 {&IID_IDirect3DDevice2, NULL, E_NOINTERFACE},
1943 {&IID_IDirect3DDevice, NULL, E_NOINTERFACE},
1944 {&IID_IDirect3DRampDevice, NULL, E_NOINTERFACE},
1945 {&IID_IDirect3DRGBDevice, NULL, E_NOINTERFACE},
1946 {&IID_IDirect3DHALDevice, NULL, E_NOINTERFACE},
1947 {&IID_IDirect3DMMXDevice, NULL, E_NOINTERFACE},
1948 {&IID_IDirect3DRefDevice, NULL, E_NOINTERFACE},
1949 {&IID_IDirect3DTnLHalDevice, NULL, E_NOINTERFACE},
1950 {&IID_IDirect3DNullDevice, NULL, E_NOINTERFACE},
1951 {&IID_IDirect3D7, NULL, E_NOINTERFACE},
1952 {&IID_IDirect3D3, NULL, E_NOINTERFACE},
1953 {&IID_IDirect3D2, NULL, E_NOINTERFACE},
1954 {&IID_IDirect3D, NULL, E_NOINTERFACE},
1955 {&IID_IDirectDraw7, NULL, E_NOINTERFACE},
1956 {&IID_IDirectDraw4, NULL, E_NOINTERFACE},
1957 {&IID_IDirectDraw3, NULL, E_NOINTERFACE},
1958 {&IID_IDirectDraw2, NULL, E_NOINTERFACE},
1959 {&IID_IDirectDraw, NULL, E_NOINTERFACE},
1960 {&IID_IDirect3DLight, NULL, E_NOINTERFACE},
1961 {&IID_IDirect3DMaterial, NULL, E_NOINTERFACE},
1962 {&IID_IDirect3DMaterial2, NULL, E_NOINTERFACE},
1963 {&IID_IDirect3DMaterial3, NULL, E_NOINTERFACE},
1964 {&IID_IDirect3DExecuteBuffer, NULL, E_NOINTERFACE},
1965 {&IID_IDirect3DViewport, NULL, E_NOINTERFACE},
1966 {&IID_IDirect3DViewport2, NULL, E_NOINTERFACE},
1967 {&IID_IDirect3DViewport3, NULL, E_NOINTERFACE},
1968 {&IID_IDirect3DVertexBuffer, NULL, E_NOINTERFACE},
1969 {&IID_IDirect3DVertexBuffer7, NULL, E_NOINTERFACE},
1970 {&IID_IDirectDrawPalette, NULL, E_NOINTERFACE},
1971 {&IID_IDirectDrawClipper, NULL, E_NOINTERFACE},
1972 {&IID_IUnknown, &IID_IDirectDrawSurface, S_OK },
1975 IDirectDrawSurface7 *surface;
1976 DDSURFACEDESC2 surface_desc;
1977 IDirect3DDevice7 *device;
1978 IDirectDraw7 *ddraw;
1979 HWND window;
1980 HRESULT hr;
1982 window = create_window();
1983 /* Try to create a D3D device to see if the ddraw implementation supports
1984 * D3D. 64-bit ddraw in particular doesn't seem to support D3D, and
1985 * doesn't support e.g. the IDirect3DTexture interfaces. */
1986 if (!(device = create_device(window, DDSCL_NORMAL)))
1988 skip("Failed to create a 3D device, skipping test.\n");
1989 DestroyWindow(window);
1990 return;
1992 IDirect3DDevice_Release(device);
1993 ddraw = create_ddraw();
1994 ok(!!ddraw, "Failed to create a ddraw object.\n");
1995 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
1996 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
1998 memset(&surface_desc, 0, sizeof(surface_desc));
1999 surface_desc.dwSize = sizeof(surface_desc);
2000 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
2001 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
2002 surface_desc.dwWidth = 512;
2003 surface_desc.dwHeight = 512;
2004 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, (IDirectDrawSurface7 **)0xdeadbeef, NULL);
2005 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2006 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
2007 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
2009 test_qi("surface_qi", (IUnknown *)surface, &IID_IDirectDrawSurface7, tests, ARRAY_SIZE(tests));
2011 IDirectDrawSurface7_Release(surface);
2012 IDirectDraw7_Release(ddraw);
2013 DestroyWindow(window);
2016 static void test_device_qi(void)
2018 static const struct qi_test tests[] =
2020 {&IID_IDirect3DTexture2, NULL, E_NOINTERFACE},
2021 {&IID_IDirect3DTexture, NULL, E_NOINTERFACE},
2022 {&IID_IDirectDrawGammaControl, NULL, E_NOINTERFACE},
2023 {&IID_IDirectDrawColorControl, NULL, E_NOINTERFACE},
2024 {&IID_IDirectDrawSurface7, NULL, E_NOINTERFACE},
2025 {&IID_IDirectDrawSurface4, NULL, E_NOINTERFACE},
2026 {&IID_IDirectDrawSurface3, NULL, E_NOINTERFACE},
2027 {&IID_IDirectDrawSurface2, NULL, E_NOINTERFACE},
2028 {&IID_IDirectDrawSurface, NULL, E_NOINTERFACE},
2029 {&IID_IDirect3DDevice7, &IID_IDirect3DDevice7, S_OK },
2030 {&IID_IDirect3DDevice3, NULL, E_NOINTERFACE},
2031 {&IID_IDirect3DDevice2, NULL, E_NOINTERFACE},
2032 {&IID_IDirect3DDevice, NULL, E_NOINTERFACE},
2033 {&IID_IDirect3DRampDevice, NULL, E_NOINTERFACE},
2034 {&IID_IDirect3DRGBDevice, NULL, E_NOINTERFACE},
2035 {&IID_IDirect3DHALDevice, NULL, E_NOINTERFACE},
2036 {&IID_IDirect3DMMXDevice, NULL, E_NOINTERFACE},
2037 {&IID_IDirect3DRefDevice, NULL, E_NOINTERFACE},
2038 {&IID_IDirect3DTnLHalDevice, NULL, E_NOINTERFACE},
2039 {&IID_IDirect3DNullDevice, NULL, E_NOINTERFACE},
2040 {&IID_IDirect3D7, NULL, E_NOINTERFACE},
2041 {&IID_IDirect3D3, NULL, E_NOINTERFACE},
2042 {&IID_IDirect3D2, NULL, E_NOINTERFACE},
2043 {&IID_IDirect3D, NULL, E_NOINTERFACE},
2044 {&IID_IDirectDraw7, NULL, E_NOINTERFACE},
2045 {&IID_IDirectDraw4, NULL, E_NOINTERFACE},
2046 {&IID_IDirectDraw3, NULL, E_NOINTERFACE},
2047 {&IID_IDirectDraw2, NULL, E_NOINTERFACE},
2048 {&IID_IDirectDraw, NULL, E_NOINTERFACE},
2049 {&IID_IDirect3DLight, NULL, E_NOINTERFACE},
2050 {&IID_IDirect3DMaterial, NULL, E_NOINTERFACE},
2051 {&IID_IDirect3DMaterial2, NULL, E_NOINTERFACE},
2052 {&IID_IDirect3DMaterial3, NULL, E_NOINTERFACE},
2053 {&IID_IDirect3DExecuteBuffer, NULL, E_NOINTERFACE},
2054 {&IID_IDirect3DViewport, NULL, E_NOINTERFACE},
2055 {&IID_IDirect3DViewport2, NULL, E_NOINTERFACE},
2056 {&IID_IDirect3DViewport3, NULL, E_NOINTERFACE},
2057 {&IID_IDirect3DVertexBuffer, NULL, E_NOINTERFACE},
2058 {&IID_IDirect3DVertexBuffer7, NULL, E_NOINTERFACE},
2059 {&IID_IDirectDrawPalette, NULL, E_NOINTERFACE},
2060 {&IID_IDirectDrawClipper, NULL, E_NOINTERFACE},
2061 {&IID_IUnknown, &IID_IDirect3DDevice7, S_OK },
2064 IDirect3DDevice7 *device;
2065 HWND window;
2067 window = create_window();
2068 if (!(device = create_device(window, DDSCL_NORMAL)))
2070 skip("Failed to create a 3D device, skipping test.\n");
2071 DestroyWindow(window);
2072 return;
2075 test_qi("device_qi", (IUnknown *)device, &IID_IDirect3DDevice7, tests, ARRAY_SIZE(tests));
2077 IDirect3DDevice7_Release(device);
2078 DestroyWindow(window);
2081 static void test_wndproc(void)
2083 LONG_PTR proc, ddraw_proc;
2084 IDirectDraw7 *ddraw;
2085 WNDCLASSA wc = {0};
2086 HWND window;
2087 HRESULT hr;
2088 ULONG ref;
2090 static struct message messages[] =
2092 {WM_WINDOWPOSCHANGING, FALSE, 0},
2093 {WM_MOVE, FALSE, 0},
2094 {WM_SIZE, FALSE, 0},
2095 {WM_WINDOWPOSCHANGING, FALSE, 0},
2096 {WM_ACTIVATE, FALSE, 0},
2097 {WM_SETFOCUS, FALSE, 0},
2098 {0, FALSE, 0},
2101 /* DDSCL_EXCLUSIVE replaces the window's window proc. */
2102 ddraw = create_ddraw();
2103 ok(!!ddraw, "Failed to create a ddraw object.\n");
2105 wc.lpfnWndProc = test_proc;
2106 wc.lpszClassName = "ddraw_test_wndproc_wc";
2107 ok(RegisterClassA(&wc), "Failed to register window class.\n");
2109 window = CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
2110 WS_MAXIMIZE | WS_CAPTION , 0, 0, 640, 480, 0, 0, 0, 0);
2112 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2113 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2114 (LONG_PTR)test_proc, proc);
2115 expect_messages = messages;
2116 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2117 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2118 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2119 expect_messages = NULL;
2120 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2121 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
2122 (LONG_PTR)test_proc, proc);
2123 ref = IDirectDraw7_Release(ddraw);
2124 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2125 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2126 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2127 (LONG_PTR)test_proc, proc);
2129 /* DDSCL_NORMAL doesn't. */
2130 ddraw = create_ddraw();
2131 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2132 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2133 (LONG_PTR)test_proc, proc);
2134 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL | DDSCL_FULLSCREEN);
2135 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2136 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2137 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2138 (LONG_PTR)test_proc, proc);
2139 ref = IDirectDraw7_Release(ddraw);
2140 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2141 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2142 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2143 (LONG_PTR)test_proc, proc);
2145 /* The original window proc is only restored by ddraw if the current
2146 * window proc matches the one ddraw set. This also affects switching
2147 * from DDSCL_NORMAL to DDSCL_EXCLUSIVE. */
2148 ddraw = create_ddraw();
2149 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2150 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2151 (LONG_PTR)test_proc, proc);
2152 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2153 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2154 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2155 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
2156 (LONG_PTR)test_proc, proc);
2157 ddraw_proc = proc;
2158 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2159 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2160 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2161 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2162 (LONG_PTR)test_proc, proc);
2163 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2164 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2165 proc = SetWindowLongPtrA(window, GWLP_WNDPROC, (LONG_PTR)DefWindowProcA);
2166 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
2167 (LONG_PTR)test_proc, proc);
2168 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2169 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2170 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2171 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#lx, got %#lx.\n",
2172 (LONG_PTR)DefWindowProcA, proc);
2173 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2174 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2175 proc = SetWindowLongPtrA(window, GWLP_WNDPROC, (LONG_PTR)ddraw_proc);
2176 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#lx, got %#lx.\n",
2177 (LONG_PTR)DefWindowProcA, proc);
2178 ref = IDirectDraw7_Release(ddraw);
2179 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2180 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2181 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2182 (LONG_PTR)test_proc, proc);
2184 ddraw = create_ddraw();
2185 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2186 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2187 (LONG_PTR)test_proc, proc);
2188 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2189 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2190 proc = SetWindowLongPtrA(window, GWLP_WNDPROC, (LONG_PTR)DefWindowProcA);
2191 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
2192 (LONG_PTR)test_proc, proc);
2193 ref = IDirectDraw7_Release(ddraw);
2194 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2195 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2196 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#lx, got %#lx.\n",
2197 (LONG_PTR)DefWindowProcA, proc);
2199 fix_wndproc(window, (LONG_PTR)test_proc);
2200 expect_messages = NULL;
2201 DestroyWindow(window);
2202 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL));
2205 static void test_window_style(void)
2207 LONG style, exstyle, tmp, expected_style;
2208 RECT fullscreen_rect, r;
2209 IDirectDraw7 *ddraw;
2210 HWND window;
2211 HRESULT hr;
2212 ULONG ref;
2213 BOOL ret;
2215 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
2216 0, 0, 100, 100, 0, 0, 0, 0);
2217 ddraw = create_ddraw();
2218 ok(!!ddraw, "Failed to create a ddraw object.\n");
2220 style = GetWindowLongA(window, GWL_STYLE);
2221 exstyle = GetWindowLongA(window, GWL_EXSTYLE);
2222 SetRect(&fullscreen_rect, 0, 0, registry_mode.dmPelsWidth, registry_mode.dmPelsHeight);
2224 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2225 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2227 tmp = GetWindowLongA(window, GWL_STYLE);
2228 todo_wine ok(tmp == style, "Expected window style %#x, got %#x.\n", style, tmp);
2229 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2230 todo_wine ok(tmp == exstyle, "Expected window extended style %#x, got %#x.\n", exstyle, tmp);
2232 GetWindowRect(window, &r);
2233 ok(EqualRect(&r, &fullscreen_rect), "Expected %s, got %s.\n",
2234 wine_dbgstr_rect(&fullscreen_rect), wine_dbgstr_rect(&r));
2235 GetClientRect(window, &r);
2236 todo_wine ok(!EqualRect(&r, &fullscreen_rect), "Client rect and window rect are equal.\n");
2238 ret = SetForegroundWindow(GetDesktopWindow());
2239 ok(ret, "Failed to set foreground window.\n");
2241 tmp = GetWindowLongA(window, GWL_STYLE);
2242 todo_wine ok(tmp == style, "Expected window style %#x, got %#x.\n", style, tmp);
2243 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2244 todo_wine ok(tmp == exstyle, "Expected window extended style %#x, got %#x.\n", exstyle, tmp);
2246 ret = SetForegroundWindow(window);
2247 ok(ret, "Failed to set foreground window.\n");
2248 /* Windows 7 (but not Vista and XP) shows the window when it receives focus. Hide it again,
2249 * the next tests expect this. */
2250 ShowWindow(window, SW_HIDE);
2252 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2253 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2255 tmp = GetWindowLongA(window, GWL_STYLE);
2256 todo_wine ok(tmp == style, "Expected window style %#x, got %#x.\n", style, tmp);
2257 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2258 todo_wine ok(tmp == exstyle, "Expected window extended style %#x, got %#x.\n", exstyle, tmp);
2260 ShowWindow(window, SW_SHOW);
2261 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2262 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2264 tmp = GetWindowLongA(window, GWL_STYLE);
2265 expected_style = style | WS_VISIBLE;
2266 todo_wine ok(tmp == expected_style, "Expected window style %#x, got %#x.\n", expected_style, tmp);
2267 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2268 expected_style = exstyle | WS_EX_TOPMOST;
2269 todo_wine ok(tmp == expected_style, "Expected window extended style %#x, got %#x.\n", expected_style, tmp);
2271 ret = SetForegroundWindow(GetDesktopWindow());
2272 ok(ret, "Failed to set foreground window.\n");
2273 tmp = GetWindowLongA(window, GWL_STYLE);
2274 expected_style = style | WS_VISIBLE | WS_MINIMIZE;
2275 todo_wine ok(tmp == expected_style, "Expected window style %#x, got %#x.\n", expected_style, tmp);
2276 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2277 expected_style = exstyle | WS_EX_TOPMOST;
2278 todo_wine ok(tmp == expected_style, "Expected window extended style %#x, got %#x.\n", expected_style, tmp);
2280 ref = IDirectDraw7_Release(ddraw);
2281 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2283 DestroyWindow(window);
2286 static void test_redundant_mode_set(void)
2288 DDSURFACEDESC2 surface_desc = {0};
2289 IDirectDraw7 *ddraw;
2290 RECT q, r, s;
2291 HWND window;
2292 HRESULT hr;
2293 ULONG ref;
2295 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
2296 0, 0, 100, 100, 0, 0, 0, 0);
2297 ddraw = create_ddraw();
2298 ok(!!ddraw, "Failed to create a ddraw object.\n");
2299 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2300 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2302 surface_desc.dwSize = sizeof(surface_desc);
2303 hr = IDirectDraw7_GetDisplayMode(ddraw, &surface_desc);
2304 ok(SUCCEEDED(hr), "GetDisplayMode failed, hr %#x.\n", hr);
2306 hr = IDirectDraw7_SetDisplayMode(ddraw, surface_desc.dwWidth, surface_desc.dwHeight,
2307 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount, 0, 0);
2308 ok(SUCCEEDED(hr), "SetDisplayMode failed, hr %#x.\n", hr);
2310 GetWindowRect(window, &q);
2311 r = q;
2312 r.right /= 2;
2313 r.bottom /= 2;
2314 SetWindowPos(window, HWND_TOP, r.left, r.top, r.right, r.bottom, 0);
2315 GetWindowRect(window, &s);
2316 ok(EqualRect(&r, &s), "Expected %s, got %s.\n", wine_dbgstr_rect(&r), wine_dbgstr_rect(&s));
2318 hr = IDirectDraw7_SetDisplayMode(ddraw, surface_desc.dwWidth, surface_desc.dwHeight,
2319 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount, 0, 0);
2320 ok(SUCCEEDED(hr), "SetDisplayMode failed, hr %#x.\n", hr);
2322 GetWindowRect(window, &s);
2323 ok(EqualRect(&r, &s) || broken(EqualRect(&q, &s) /* Windows 10 */),
2324 "Expected %s, got %s.\n", wine_dbgstr_rect(&r), wine_dbgstr_rect(&s));
2326 ref = IDirectDraw7_Release(ddraw);
2327 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2329 DestroyWindow(window);
2332 static SIZE screen_size, screen_size2;
2334 static LRESULT CALLBACK mode_set_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
2336 if (message == WM_SIZE)
2338 screen_size.cx = GetSystemMetrics(SM_CXSCREEN);
2339 screen_size.cy = GetSystemMetrics(SM_CYSCREEN);
2342 return test_proc(hwnd, message, wparam, lparam);
2345 static LRESULT CALLBACK mode_set_proc2(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
2347 if (message == WM_SIZE)
2349 screen_size2.cx = GetSystemMetrics(SM_CXSCREEN);
2350 screen_size2.cy = GetSystemMetrics(SM_CYSCREEN);
2353 return test_proc(hwnd, message, wparam, lparam);
2356 struct test_coop_level_mode_set_enum_param
2358 DWORD ddraw_width, ddraw_height, user32_width, user32_height;
2361 static HRESULT CALLBACK test_coop_level_mode_set_enum_cb(DDSURFACEDESC2 *surface_desc, void *context)
2363 struct test_coop_level_mode_set_enum_param *param = context;
2365 if (U1(U4(*surface_desc).ddpfPixelFormat).dwRGBBitCount != registry_mode.dmBitsPerPel)
2366 return DDENUMRET_OK;
2367 if (surface_desc->dwWidth == registry_mode.dmPelsWidth
2368 && surface_desc->dwHeight == registry_mode.dmPelsHeight)
2369 return DDENUMRET_OK;
2371 if (!param->ddraw_width)
2373 param->ddraw_width = surface_desc->dwWidth;
2374 param->ddraw_height = surface_desc->dwHeight;
2375 return DDENUMRET_OK;
2377 if (surface_desc->dwWidth == param->ddraw_width && surface_desc->dwHeight == param->ddraw_height)
2378 return DDENUMRET_OK;
2380 param->user32_width = surface_desc->dwWidth;
2381 param->user32_height = surface_desc->dwHeight;
2382 return DDENUMRET_CANCEL;
2385 static void test_coop_level_mode_set(void)
2387 IDirectDrawSurface7 *primary;
2388 RECT registry_rect, ddraw_rect, user32_rect, r;
2389 IDirectDraw7 *ddraw;
2390 DDSURFACEDESC2 ddsd;
2391 WNDCLASSA wc = {0};
2392 HWND window, window2;
2393 HRESULT hr;
2394 ULONG ref;
2395 MSG msg;
2396 struct test_coop_level_mode_set_enum_param param;
2397 DEVMODEW devmode;
2398 BOOL ret;
2399 LONG change_ret;
2401 static const struct message exclusive_messages[] =
2403 {WM_WINDOWPOSCHANGING, FALSE, 0},
2404 {WM_WINDOWPOSCHANGED, FALSE, 0},
2405 {WM_SIZE, FALSE, 0},
2406 {WM_DISPLAYCHANGE, FALSE, 0},
2407 {0, FALSE, 0},
2409 static const struct message exclusive_focus_loss_messages[] =
2411 {WM_ACTIVATE, TRUE, WA_INACTIVE},
2412 {WM_DISPLAYCHANGE, FALSE, 0},
2413 {WM_WINDOWPOSCHANGING, FALSE, 0},
2414 /* Like d3d8 and d3d9 ddraw seems to use SW_SHOWMINIMIZED instead of
2415 * SW_MINIMIZED, causing a recursive window activation that does not
2416 * produce the same result in Wine yet. Ignore the difference for now.
2417 * {WM_ACTIVATE, TRUE, 0x200000 | WA_ACTIVE}, */
2418 {WM_WINDOWPOSCHANGED, FALSE, 0},
2419 {WM_MOVE, FALSE, 0},
2420 {WM_SIZE, TRUE, SIZE_MINIMIZED},
2421 {WM_ACTIVATEAPP, TRUE, FALSE},
2422 {0, FALSE, 0},
2424 static const struct message exclusive_focus_restore_messages[] =
2426 {WM_WINDOWPOSCHANGING, FALSE, 0}, /* From the ShowWindow(SW_RESTORE). */
2427 {WM_WINDOWPOSCHANGING, FALSE, 0}, /* Generated by ddraw, matches d3d9 behavior. */
2428 {WM_WINDOWPOSCHANGED, FALSE, 0}, /* Matching previous message. */
2429 {WM_SIZE, FALSE, 0}, /* DefWindowProc. */
2430 {WM_DISPLAYCHANGE, FALSE, 0}, /* Ddraw restores mode. */
2431 /* Native redundantly sets the window size here. */
2432 {WM_ACTIVATEAPP, TRUE, TRUE}, /* End of ddraw's hooks. */
2433 {WM_WINDOWPOSCHANGED, FALSE, 0}, /* Matching the one from ShowWindow. */
2434 {WM_MOVE, FALSE, 0}, /* DefWindowProc. */
2435 {WM_SIZE, TRUE, SIZE_RESTORED}, /* DefWindowProc. */
2436 {0, FALSE, 0},
2438 static const struct message sc_restore_messages[] =
2440 {WM_SYSCOMMAND, TRUE, SC_RESTORE},
2441 {WM_WINDOWPOSCHANGING, FALSE, 0},
2442 {WM_WINDOWPOSCHANGED, FALSE, 0},
2443 {WM_SIZE, TRUE, SIZE_RESTORED},
2444 {0, FALSE, 0},
2446 static const struct message sc_minimize_messages[] =
2448 {WM_SYSCOMMAND, TRUE, SC_MINIMIZE},
2449 {WM_WINDOWPOSCHANGING, FALSE, 0},
2450 {WM_WINDOWPOSCHANGED, FALSE, 0},
2451 {WM_SIZE, TRUE, SIZE_MINIMIZED},
2452 {0, FALSE, 0},
2454 static const struct message sc_maximize_messages[] =
2456 {WM_SYSCOMMAND, TRUE, SC_MAXIMIZE},
2457 {WM_WINDOWPOSCHANGING, FALSE, 0},
2458 {WM_WINDOWPOSCHANGED, FALSE, 0},
2459 {WM_SIZE, TRUE, SIZE_MAXIMIZED},
2460 {0, FALSE, 0},
2463 static const struct message normal_messages[] =
2465 {WM_DISPLAYCHANGE, FALSE, 0},
2466 {0, FALSE, 0},
2469 ddraw = create_ddraw();
2470 ok(!!ddraw, "Failed to create a ddraw object.\n");
2472 memset(&param, 0, sizeof(param));
2473 hr = IDirectDraw7_EnumDisplayModes(ddraw, 0, NULL, &param, test_coop_level_mode_set_enum_cb);
2474 ok(SUCCEEDED(hr), "Failed to enumerate display mode, hr %#x.\n", hr);
2475 ref = IDirectDraw7_Release(ddraw);
2476 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2478 if (!param.user32_height)
2480 skip("Fewer than 3 different modes supported, skipping mode restore test.\n");
2481 return;
2484 SetRect(&registry_rect, 0, 0, registry_mode.dmPelsWidth, registry_mode.dmPelsHeight);
2485 SetRect(&ddraw_rect, 0, 0, param.ddraw_width, param.ddraw_height);
2486 SetRect(&user32_rect, 0, 0, param.user32_width, param.user32_height);
2488 memset(&devmode, 0, sizeof(devmode));
2489 devmode.dmSize = sizeof(devmode);
2490 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
2491 devmode.dmPelsWidth = param.user32_width;
2492 devmode.dmPelsHeight = param.user32_height;
2493 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
2494 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2496 ddraw = create_ddraw();
2497 ok(!!ddraw, "Failed to create a ddraw object.\n");
2499 wc.lpfnWndProc = mode_set_proc;
2500 wc.lpszClassName = "ddraw_test_wndproc_wc";
2501 ok(RegisterClassA(&wc), "Failed to register window class.\n");
2502 wc.lpfnWndProc = mode_set_proc2;
2503 wc.lpszClassName = "ddraw_test_wndproc_wc2";
2504 ok(RegisterClassA(&wc), "Failed to register window class.\n");
2506 window = CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test", WS_OVERLAPPEDWINDOW,
2507 0, 0, 100, 100, 0, 0, 0, 0);
2508 window2 = CreateWindowA("ddraw_test_wndproc_wc2", "ddraw_test", WS_OVERLAPPEDWINDOW,
2509 0, 0, 100, 100, 0, 0, 0, 0);
2511 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2512 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2514 GetWindowRect(window, &r);
2515 ok(EqualRect(&r, &user32_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&user32_rect),
2516 wine_dbgstr_rect(&r));
2518 memset(&ddsd, 0, sizeof(ddsd));
2519 ddsd.dwSize = sizeof(ddsd);
2520 ddsd.dwFlags = DDSD_CAPS;
2521 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2523 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2524 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2525 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2526 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2527 ok(ddsd.dwWidth == param.user32_width, "Expected surface width %u, got %u.\n",
2528 param.user32_width, ddsd.dwWidth);
2529 ok(ddsd.dwHeight == param.user32_height, "Expected surface height %u, got %u.\n",
2530 param.user32_height, ddsd.dwHeight);
2532 GetWindowRect(window, &r);
2533 ok(EqualRect(&r, &user32_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&user32_rect),
2534 wine_dbgstr_rect(&r));
2536 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2537 expect_messages = exclusive_messages;
2538 screen_size.cx = 0;
2539 screen_size.cy = 0;
2541 hr = IDirectDrawSurface7_IsLost(primary);
2542 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
2543 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
2544 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2545 hr = IDirectDrawSurface7_IsLost(primary);
2546 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2548 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2549 expect_messages = NULL;
2550 ok(screen_size.cx == param.ddraw_width && screen_size.cy == param.ddraw_height,
2551 "Expected screen size %ux%u, got %ux%u.\n",
2552 param.ddraw_width, param.ddraw_height, screen_size.cx, screen_size.cy);
2554 GetWindowRect(window, &r);
2555 ok(EqualRect(&r, &ddraw_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect),
2556 wine_dbgstr_rect(&r));
2558 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2559 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2560 ok(ddsd.dwWidth == param.user32_width, "Expected surface width %u, got %u.\n",
2561 param.user32_width, ddsd.dwWidth);
2562 ok(ddsd.dwHeight == param.user32_height, "Expected surface height %u, got %u.\n",
2563 param.user32_height, ddsd.dwHeight);
2564 IDirectDrawSurface7_Release(primary);
2566 memset(&ddsd, 0, sizeof(ddsd));
2567 ddsd.dwSize = sizeof(ddsd);
2568 ddsd.dwFlags = DDSD_CAPS;
2569 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2571 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2572 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2573 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2574 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2575 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2576 param.ddraw_width, ddsd.dwWidth);
2577 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2578 param.ddraw_height, ddsd.dwHeight);
2580 GetWindowRect(window, &r);
2581 ok(EqualRect(&r, &ddraw_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect),
2582 wine_dbgstr_rect(&r));
2584 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2585 expect_messages = exclusive_messages;
2586 screen_size.cx = 0;
2587 screen_size.cy = 0;
2589 hr = IDirectDrawSurface7_IsLost(primary);
2590 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
2591 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
2592 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2593 hr = IDirectDrawSurface7_IsLost(primary);
2594 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2596 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2597 expect_messages = NULL;
2598 ok(screen_size.cx == param.user32_width && screen_size.cy == param.user32_height,
2599 "Expected screen size %ux%u, got %ux%u.\n",
2600 param.user32_width, param.user32_height, screen_size.cx, screen_size.cy);
2602 GetWindowRect(window, &r);
2603 ok(EqualRect(&r, &user32_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&user32_rect),
2604 wine_dbgstr_rect(&r));
2606 expect_messages = exclusive_focus_loss_messages;
2607 ret = SetForegroundWindow(GetDesktopWindow());
2608 ok(ret, "Failed to set foreground window.\n");
2609 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2610 memset(&devmode, 0, sizeof(devmode));
2611 devmode.dmSize = sizeof(devmode);
2612 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
2613 ok(ret, "Failed to get display mode.\n");
2614 ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth
2615 && devmode.dmPelsHeight == registry_mode.dmPelsHeight, "Got unexpect screen size %ux%u.\n",
2616 devmode.dmPelsWidth, devmode.dmPelsHeight);
2618 expect_messages = exclusive_focus_restore_messages;
2619 ShowWindow(window, SW_RESTORE);
2620 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2622 GetWindowRect(window, &r);
2623 ok(EqualRect(&r, &ddraw_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect),
2624 wine_dbgstr_rect(&r));
2625 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
2626 ok(ret, "Failed to get display mode.\n");
2627 ok(devmode.dmPelsWidth == param.ddraw_width
2628 && devmode.dmPelsHeight == param.ddraw_height, "Got unexpect screen size %ux%u.\n",
2629 devmode.dmPelsWidth, devmode.dmPelsHeight);
2631 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2632 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2633 /* Normally the primary should be restored here. Unfortunately this causes the
2634 * GetSurfaceDesc call after the next display mode change to crash on the Windows 8
2635 * testbot. Another Restore call would presumably avoid the crash, but it also moots
2636 * the point of the GetSurfaceDesc call. */
2638 expect_messages = sc_minimize_messages;
2639 SendMessageA(window, WM_SYSCOMMAND, SC_MINIMIZE, 0);
2640 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2641 expect_messages = NULL;
2643 expect_messages = sc_restore_messages;
2644 SendMessageA(window, WM_SYSCOMMAND, SC_RESTORE, 0);
2645 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2646 expect_messages = NULL;
2648 expect_messages = sc_maximize_messages;
2649 SendMessageA(window, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
2650 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2651 expect_messages = NULL;
2653 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2654 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2656 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2657 expect_messages = exclusive_messages;
2658 screen_size.cx = 0;
2659 screen_size.cy = 0;
2661 hr = IDirectDrawSurface7_IsLost(primary);
2662 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2663 hr = IDirectDraw7_RestoreDisplayMode(ddraw);
2664 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
2665 hr = IDirectDrawSurface7_IsLost(primary);
2666 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2668 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2669 expect_messages = NULL;
2670 ok(screen_size.cx == registry_mode.dmPelsWidth
2671 && screen_size.cy == registry_mode.dmPelsHeight,
2672 "Expected screen size %ux%u, got %ux%u.\n",
2673 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight, screen_size.cx, screen_size.cy);
2675 GetWindowRect(window, &r);
2676 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2677 wine_dbgstr_rect(&r));
2679 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2680 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2681 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2682 param.ddraw_width, ddsd.dwWidth);
2683 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2684 param.ddraw_height, ddsd.dwHeight);
2685 IDirectDrawSurface7_Release(primary);
2687 /* For Wine. */
2688 change_ret = ChangeDisplaySettingsW(NULL, CDS_FULLSCREEN);
2689 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2691 memset(&ddsd, 0, sizeof(ddsd));
2692 ddsd.dwSize = sizeof(ddsd);
2693 ddsd.dwFlags = DDSD_CAPS;
2694 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2696 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2697 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2698 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2699 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2700 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2701 registry_mode.dmPelsWidth, ddsd.dwWidth);
2702 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2703 registry_mode.dmPelsHeight, ddsd.dwHeight);
2705 GetWindowRect(window, &r);
2706 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2707 wine_dbgstr_rect(&r));
2709 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2710 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2712 GetWindowRect(window, &r);
2713 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2714 wine_dbgstr_rect(&r));
2716 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2717 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2718 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2719 registry_mode.dmPelsWidth, ddsd.dwWidth);
2720 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2721 registry_mode.dmPelsHeight, ddsd.dwHeight);
2722 IDirectDrawSurface7_Release(primary);
2724 memset(&ddsd, 0, sizeof(ddsd));
2725 ddsd.dwSize = sizeof(ddsd);
2726 ddsd.dwFlags = DDSD_CAPS;
2727 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2729 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2730 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2731 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2732 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2733 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2734 registry_mode.dmPelsWidth, ddsd.dwWidth);
2735 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2736 registry_mode.dmPelsHeight, ddsd.dwHeight);
2738 GetWindowRect(window, &r);
2739 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2740 wine_dbgstr_rect(&r));
2742 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2743 expect_messages = normal_messages;
2744 screen_size.cx = 0;
2745 screen_size.cy = 0;
2747 hr = IDirectDrawSurface7_IsLost(primary);
2748 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
2749 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
2750 devmode.dmPelsWidth = param.user32_width;
2751 devmode.dmPelsHeight = param.user32_height;
2752 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
2753 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2754 hr = IDirectDrawSurface7_IsLost(primary);
2755 todo_wine ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2757 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2758 expect_messages = NULL;
2759 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2761 GetWindowRect(window, &r);
2762 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2763 wine_dbgstr_rect(&r));
2765 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2766 expect_messages = normal_messages;
2767 screen_size.cx = 0;
2768 screen_size.cy = 0;
2770 hr = IDirectDrawSurface7_Restore(primary);
2771 ok(hr == DDERR_WRONGMODE, "Got unexpected hr %#x.\n", hr);
2772 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
2773 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2774 hr = IDirectDrawSurface7_Restore(primary);
2775 ok(hr == DDERR_WRONGMODE, "Got unexpected hr %#x.\n", hr);
2776 hr = IDirectDrawSurface7_IsLost(primary);
2777 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2779 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2780 expect_messages = NULL;
2781 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2783 GetWindowRect(window, &r);
2784 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2785 wine_dbgstr_rect(&r));
2787 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2788 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2789 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2790 registry_mode.dmPelsWidth, ddsd.dwWidth);
2791 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2792 registry_mode.dmPelsHeight, ddsd.dwHeight);
2793 IDirectDrawSurface7_Release(primary);
2795 memset(&ddsd, 0, sizeof(ddsd));
2796 ddsd.dwSize = sizeof(ddsd);
2797 ddsd.dwFlags = DDSD_CAPS;
2798 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2800 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2801 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2802 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2803 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2804 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2805 param.ddraw_width, ddsd.dwWidth);
2806 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2807 param.ddraw_height, ddsd.dwHeight);
2809 GetWindowRect(window, &r);
2810 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2811 wine_dbgstr_rect(&r));
2813 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2814 expect_messages = normal_messages;
2815 screen_size.cx = 0;
2816 screen_size.cy = 0;
2818 hr = IDirectDrawSurface7_IsLost(primary);
2819 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
2820 hr = IDirectDraw7_RestoreDisplayMode(ddraw);
2821 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
2822 hr = IDirectDrawSurface7_IsLost(primary);
2823 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2825 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2826 expect_messages = NULL;
2827 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2829 GetWindowRect(window, &r);
2830 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2831 wine_dbgstr_rect(&r));
2833 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2834 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2835 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2836 param.ddraw_width, ddsd.dwWidth);
2837 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2838 param.ddraw_height, ddsd.dwHeight);
2839 IDirectDrawSurface7_Release(primary);
2841 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
2842 ok(ret, "Failed to get display mode.\n");
2843 ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth
2844 && devmode.dmPelsHeight == registry_mode.dmPelsHeight,
2845 "Expected resolution %ux%u, got %ux%u.\n",
2846 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight,
2847 devmode.dmPelsWidth, devmode.dmPelsHeight);
2848 change_ret = ChangeDisplaySettingsW(NULL, CDS_FULLSCREEN);
2849 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2851 memset(&ddsd, 0, sizeof(ddsd));
2852 ddsd.dwSize = sizeof(ddsd);
2853 ddsd.dwFlags = DDSD_CAPS;
2854 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2856 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2857 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2858 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2859 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2860 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2861 registry_mode.dmPelsWidth, ddsd.dwWidth);
2862 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2863 registry_mode.dmPelsHeight, ddsd.dwHeight);
2865 GetWindowRect(window, &r);
2866 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2867 wine_dbgstr_rect(&r));
2869 /* DDSCL_NORMAL | DDSCL_FULLSCREEN behaves the same as just DDSCL_NORMAL.
2870 * Resizing the window on mode changes is a property of DDSCL_EXCLUSIVE,
2871 * not DDSCL_FULLSCREEN. */
2872 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL | DDSCL_FULLSCREEN);
2873 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2875 GetWindowRect(window, &r);
2876 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2877 wine_dbgstr_rect(&r));
2879 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2880 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2881 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2882 registry_mode.dmPelsWidth, ddsd.dwWidth);
2883 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2884 registry_mode.dmPelsHeight, ddsd.dwHeight);
2885 IDirectDrawSurface7_Release(primary);
2887 memset(&ddsd, 0, sizeof(ddsd));
2888 ddsd.dwSize = sizeof(ddsd);
2889 ddsd.dwFlags = DDSD_CAPS;
2890 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2892 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2893 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2894 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2895 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2896 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2897 registry_mode.dmPelsWidth, ddsd.dwWidth);
2898 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2899 registry_mode.dmPelsHeight, ddsd.dwHeight);
2901 GetWindowRect(window, &r);
2902 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2903 wine_dbgstr_rect(&r));
2905 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2906 expect_messages = normal_messages;
2907 screen_size.cx = 0;
2908 screen_size.cy = 0;
2910 hr = IDirectDrawSurface7_IsLost(primary);
2911 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
2912 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
2913 devmode.dmPelsWidth = param.user32_width;
2914 devmode.dmPelsHeight = param.user32_height;
2915 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
2916 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2917 hr = IDirectDrawSurface7_IsLost(primary);
2918 todo_wine ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2920 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2921 expect_messages = NULL;
2922 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2924 GetWindowRect(window, &r);
2925 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2926 wine_dbgstr_rect(&r));
2928 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2929 expect_messages = normal_messages;
2930 screen_size.cx = 0;
2931 screen_size.cy = 0;
2933 hr = IDirectDrawSurface7_Restore(primary);
2934 ok(hr == DDERR_WRONGMODE, "Got unexpected hr %#x.\n", hr);
2935 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
2936 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2937 hr = IDirectDrawSurface7_Restore(primary);
2938 ok(hr == DDERR_WRONGMODE, "Got unexpected hr %#x.\n", hr);
2939 hr = IDirectDrawSurface7_IsLost(primary);
2940 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2942 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2943 expect_messages = NULL;
2944 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2946 GetWindowRect(window, &r);
2947 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2948 wine_dbgstr_rect(&r));
2950 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2951 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2952 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2953 registry_mode.dmPelsWidth, ddsd.dwWidth);
2954 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2955 registry_mode.dmPelsHeight, ddsd.dwHeight);
2956 IDirectDrawSurface7_Release(primary);
2958 memset(&ddsd, 0, sizeof(ddsd));
2959 ddsd.dwSize = sizeof(ddsd);
2960 ddsd.dwFlags = DDSD_CAPS;
2961 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2963 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2964 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2965 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2966 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2967 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2968 param.ddraw_width, ddsd.dwWidth);
2969 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2970 param.ddraw_height, ddsd.dwHeight);
2972 GetWindowRect(window, &r);
2973 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2974 wine_dbgstr_rect(&r));
2976 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2977 expect_messages = normal_messages;
2978 screen_size.cx = 0;
2979 screen_size.cy = 0;
2981 hr = IDirectDrawSurface7_IsLost(primary);
2982 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
2983 hr = IDirectDraw7_RestoreDisplayMode(ddraw);
2984 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
2985 hr = IDirectDrawSurface7_IsLost(primary);
2986 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2988 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2989 expect_messages = NULL;
2990 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2992 GetWindowRect(window, &r);
2993 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2994 wine_dbgstr_rect(&r));
2996 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2997 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2998 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2999 param.ddraw_width, ddsd.dwWidth);
3000 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
3001 param.ddraw_height, ddsd.dwHeight);
3002 IDirectDrawSurface7_Release(primary);
3004 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
3005 ok(ret, "Failed to get display mode.\n");
3006 ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth
3007 && devmode.dmPelsHeight == registry_mode.dmPelsHeight,
3008 "Expected resolution %ux%u, got %ux%u.\n",
3009 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight,
3010 devmode.dmPelsWidth, devmode.dmPelsHeight);
3011 change_ret = ChangeDisplaySettingsW(NULL, CDS_FULLSCREEN);
3012 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
3014 memset(&ddsd, 0, sizeof(ddsd));
3015 ddsd.dwSize = sizeof(ddsd);
3016 ddsd.dwFlags = DDSD_CAPS;
3017 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3019 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
3020 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
3021 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
3022 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
3023 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
3024 registry_mode.dmPelsWidth, ddsd.dwWidth);
3025 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
3026 registry_mode.dmPelsHeight, ddsd.dwHeight);
3027 IDirectDrawSurface7_Release(primary);
3029 GetWindowRect(window, &r);
3030 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
3031 wine_dbgstr_rect(&r));
3033 /* Changing the coop level from EXCLUSIVE to NORMAL restores the screen resolution */
3034 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3035 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3036 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
3037 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3039 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
3040 expect_messages = exclusive_messages;
3041 screen_size.cx = 0;
3042 screen_size.cy = 0;
3044 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
3045 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3047 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
3048 expect_messages = NULL;
3049 ok(screen_size.cx == registry_mode.dmPelsWidth
3050 && screen_size.cy == registry_mode.dmPelsHeight,
3051 "Expected screen size %ux%u, got %ux%u.\n",
3052 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight,
3053 screen_size.cx, screen_size.cy);
3055 GetWindowRect(window, &r);
3056 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
3057 wine_dbgstr_rect(&r));
3059 memset(&ddsd, 0, sizeof(ddsd));
3060 ddsd.dwSize = sizeof(ddsd);
3061 ddsd.dwFlags = DDSD_CAPS;
3062 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3064 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
3065 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
3066 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
3067 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
3068 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
3069 registry_mode.dmPelsWidth, ddsd.dwWidth);
3070 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
3071 registry_mode.dmPelsHeight, ddsd.dwHeight);
3072 IDirectDrawSurface7_Release(primary);
3074 /* The screen restore is a property of DDSCL_EXCLUSIVE */
3075 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL | DDSCL_FULLSCREEN);
3076 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3077 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
3078 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3080 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
3081 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3083 memset(&ddsd, 0, sizeof(ddsd));
3084 ddsd.dwSize = sizeof(ddsd);
3085 ddsd.dwFlags = DDSD_CAPS;
3086 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3088 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
3089 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
3090 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
3091 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
3092 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
3093 param.ddraw_width, ddsd.dwWidth);
3094 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
3095 param.ddraw_height, ddsd.dwHeight);
3096 IDirectDrawSurface7_Release(primary);
3098 hr = IDirectDraw7_RestoreDisplayMode(ddraw);
3099 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
3101 /* If the window is changed at the same time, messages are sent to the new window. */
3102 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3103 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3104 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
3105 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3107 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
3108 expect_messages = exclusive_messages;
3109 screen_size.cx = 0;
3110 screen_size.cy = 0;
3111 screen_size2.cx = 0;
3112 screen_size2.cy = 0;
3114 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window2, DDSCL_NORMAL);
3115 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, 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",
3120 screen_size.cx, screen_size.cy);
3121 ok(screen_size2.cx == registry_mode.dmPelsWidth && screen_size2.cy == registry_mode.dmPelsHeight,
3122 "Expected screen size 2 %ux%u, got %ux%u.\n",
3123 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight, screen_size2.cx, screen_size2.cy);
3125 GetWindowRect(window, &r);
3126 ok(EqualRect(&r, &ddraw_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect),
3127 wine_dbgstr_rect(&r));
3128 GetWindowRect(window2, &r);
3129 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
3130 wine_dbgstr_rect(&r));
3132 memset(&ddsd, 0, sizeof(ddsd));
3133 ddsd.dwSize = sizeof(ddsd);
3134 ddsd.dwFlags = DDSD_CAPS;
3135 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3137 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
3138 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
3139 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
3140 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
3141 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
3142 registry_mode.dmPelsWidth, ddsd.dwWidth);
3143 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
3144 registry_mode.dmPelsHeight, ddsd.dwHeight);
3145 IDirectDrawSurface7_Release(primary);
3147 ref = IDirectDraw7_Release(ddraw);
3148 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3150 GetWindowRect(window, &r);
3151 ok(EqualRect(&r, &ddraw_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect),
3152 wine_dbgstr_rect(&r));
3154 expect_messages = NULL;
3155 DestroyWindow(window);
3156 DestroyWindow(window2);
3157 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL));
3158 UnregisterClassA("ddraw_test_wndproc_wc2", GetModuleHandleA(NULL));
3161 static void test_coop_level_mode_set_multi(void)
3163 IDirectDraw7 *ddraw1, *ddraw2;
3164 UINT w, h;
3165 HWND window;
3166 HRESULT hr;
3167 ULONG ref;
3169 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
3170 0, 0, 100, 100, 0, 0, 0, 0);
3171 ddraw1 = create_ddraw();
3172 ok(!!ddraw1, "Failed to create a ddraw object.\n");
3174 /* With just a single ddraw object, the display mode is restored on
3175 * release. */
3176 hr = set_display_mode(ddraw1, 800, 600);
3177 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3178 w = GetSystemMetrics(SM_CXSCREEN);
3179 ok(w == 800, "Got unexpected screen width %u.\n", w);
3180 h = GetSystemMetrics(SM_CYSCREEN);
3181 ok(h == 600, "Got unexpected screen height %u.\n", h);
3183 ref = IDirectDraw7_Release(ddraw1);
3184 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3185 w = GetSystemMetrics(SM_CXSCREEN);
3186 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3187 h = GetSystemMetrics(SM_CYSCREEN);
3188 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3190 /* When there are multiple ddraw objects, the display mode is restored to
3191 * the initial mode, before the first SetDisplayMode() call. */
3192 ddraw1 = create_ddraw();
3193 hr = set_display_mode(ddraw1, 800, 600);
3194 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3195 w = GetSystemMetrics(SM_CXSCREEN);
3196 ok(w == 800, "Got unexpected screen width %u.\n", w);
3197 h = GetSystemMetrics(SM_CYSCREEN);
3198 ok(h == 600, "Got unexpected screen height %u.\n", h);
3200 ddraw2 = create_ddraw();
3201 hr = set_display_mode(ddraw2, 640, 480);
3202 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3203 w = GetSystemMetrics(SM_CXSCREEN);
3204 ok(w == 640, "Got unexpected screen width %u.\n", w);
3205 h = GetSystemMetrics(SM_CYSCREEN);
3206 ok(h == 480, "Got unexpected screen height %u.\n", h);
3208 ref = IDirectDraw7_Release(ddraw2);
3209 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3210 w = GetSystemMetrics(SM_CXSCREEN);
3211 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3212 h = GetSystemMetrics(SM_CYSCREEN);
3213 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3215 ref = IDirectDraw7_Release(ddraw1);
3216 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3217 w = GetSystemMetrics(SM_CXSCREEN);
3218 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3219 h = GetSystemMetrics(SM_CYSCREEN);
3220 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3222 /* Regardless of release ordering. */
3223 ddraw1 = create_ddraw();
3224 hr = set_display_mode(ddraw1, 800, 600);
3225 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3226 w = GetSystemMetrics(SM_CXSCREEN);
3227 ok(w == 800, "Got unexpected screen width %u.\n", w);
3228 h = GetSystemMetrics(SM_CYSCREEN);
3229 ok(h == 600, "Got unexpected screen height %u.\n", h);
3231 ddraw2 = create_ddraw();
3232 hr = set_display_mode(ddraw2, 640, 480);
3233 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3234 w = GetSystemMetrics(SM_CXSCREEN);
3235 ok(w == 640, "Got unexpected screen width %u.\n", w);
3236 h = GetSystemMetrics(SM_CYSCREEN);
3237 ok(h == 480, "Got unexpected screen height %u.\n", h);
3239 ref = IDirectDraw7_Release(ddraw1);
3240 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3241 w = GetSystemMetrics(SM_CXSCREEN);
3242 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3243 h = GetSystemMetrics(SM_CYSCREEN);
3244 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3246 ref = IDirectDraw7_Release(ddraw2);
3247 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3248 w = GetSystemMetrics(SM_CXSCREEN);
3249 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3250 h = GetSystemMetrics(SM_CYSCREEN);
3251 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3253 /* But only for ddraw objects that called SetDisplayMode(). */
3254 ddraw1 = create_ddraw();
3255 ddraw2 = create_ddraw();
3256 hr = set_display_mode(ddraw2, 640, 480);
3257 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3258 w = GetSystemMetrics(SM_CXSCREEN);
3259 ok(w == 640, "Got unexpected screen width %u.\n", w);
3260 h = GetSystemMetrics(SM_CYSCREEN);
3261 ok(h == 480, "Got unexpected screen height %u.\n", h);
3263 ref = IDirectDraw7_Release(ddraw1);
3264 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3265 w = GetSystemMetrics(SM_CXSCREEN);
3266 ok(w == 640, "Got unexpected screen width %u.\n", w);
3267 h = GetSystemMetrics(SM_CYSCREEN);
3268 ok(h == 480, "Got unexpected screen height %u.\n", h);
3270 ref = IDirectDraw7_Release(ddraw2);
3271 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3272 w = GetSystemMetrics(SM_CXSCREEN);
3273 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3274 h = GetSystemMetrics(SM_CYSCREEN);
3275 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3277 /* If there's a ddraw object that's currently in exclusive mode, it blocks
3278 * restoring the display mode. */
3279 ddraw1 = create_ddraw();
3280 hr = set_display_mode(ddraw1, 800, 600);
3281 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3282 w = GetSystemMetrics(SM_CXSCREEN);
3283 ok(w == 800, "Got unexpected screen width %u.\n", w);
3284 h = GetSystemMetrics(SM_CYSCREEN);
3285 ok(h == 600, "Got unexpected screen height %u.\n", h);
3287 ddraw2 = create_ddraw();
3288 hr = set_display_mode(ddraw2, 640, 480);
3289 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3290 w = GetSystemMetrics(SM_CXSCREEN);
3291 ok(w == 640, "Got unexpected screen width %u.\n", w);
3292 h = GetSystemMetrics(SM_CYSCREEN);
3293 ok(h == 480, "Got unexpected screen height %u.\n", h);
3295 hr = IDirectDraw7_SetCooperativeLevel(ddraw2, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3296 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3298 ref = IDirectDraw7_Release(ddraw1);
3299 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3300 w = GetSystemMetrics(SM_CXSCREEN);
3301 ok(w == 640, "Got unexpected screen width %u.\n", w);
3302 h = GetSystemMetrics(SM_CYSCREEN);
3303 ok(h == 480, "Got unexpected screen height %u.\n", h);
3305 ref = IDirectDraw7_Release(ddraw2);
3306 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3307 w = GetSystemMetrics(SM_CXSCREEN);
3308 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3309 h = GetSystemMetrics(SM_CYSCREEN);
3310 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3312 /* Exclusive mode blocks mode setting on other ddraw objects in general. */
3313 ddraw1 = create_ddraw();
3314 hr = set_display_mode(ddraw1, 800, 600);
3315 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3316 w = GetSystemMetrics(SM_CXSCREEN);
3317 ok(w == 800, "Got unexpected screen width %u.\n", w);
3318 h = GetSystemMetrics(SM_CYSCREEN);
3319 ok(h == 600, "Got unexpected screen height %u.\n", h);
3321 hr = IDirectDraw7_SetCooperativeLevel(ddraw1, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3322 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3324 ddraw2 = create_ddraw();
3325 hr = set_display_mode(ddraw2, 640, 480);
3326 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
3328 ref = IDirectDraw7_Release(ddraw1);
3329 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3330 w = GetSystemMetrics(SM_CXSCREEN);
3331 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3332 h = GetSystemMetrics(SM_CYSCREEN);
3333 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3335 ref = IDirectDraw7_Release(ddraw2);
3336 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3337 w = GetSystemMetrics(SM_CXSCREEN);
3338 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3339 h = GetSystemMetrics(SM_CYSCREEN);
3340 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3342 DestroyWindow(window);
3345 static void test_initialize(void)
3347 IDirectDraw7 *ddraw;
3348 HRESULT hr;
3350 ddraw = create_ddraw();
3351 ok(!!ddraw, "Failed to create a ddraw object.\n");
3353 hr = IDirectDraw7_Initialize(ddraw, NULL);
3354 ok(hr == DDERR_ALREADYINITIALIZED, "Initialize returned hr %#x.\n", hr);
3355 IDirectDraw7_Release(ddraw);
3357 CoInitialize(NULL);
3358 hr = CoCreateInstance(&CLSID_DirectDraw, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectDraw7, (void **)&ddraw);
3359 ok(SUCCEEDED(hr), "Failed to create IDirectDraw7 instance, hr %#x.\n", hr);
3360 hr = IDirectDraw7_Initialize(ddraw, NULL);
3361 ok(hr == DD_OK, "Initialize returned hr %#x, expected DD_OK.\n", hr);
3362 hr = IDirectDraw7_Initialize(ddraw, NULL);
3363 ok(hr == DDERR_ALREADYINITIALIZED, "Initialize returned hr %#x, expected DDERR_ALREADYINITIALIZED.\n", hr);
3364 IDirectDraw7_Release(ddraw);
3365 CoUninitialize();
3368 static void test_coop_level_surf_create(void)
3370 IDirectDrawSurface7 *surface;
3371 IDirectDraw7 *ddraw;
3372 DDSURFACEDESC2 ddsd;
3373 HRESULT hr;
3375 ddraw = create_ddraw();
3376 ok(!!ddraw, "Failed to create a ddraw object.\n");
3378 memset(&ddsd, 0, sizeof(ddsd));
3379 ddsd.dwSize = sizeof(ddsd);
3380 ddsd.dwFlags = DDSD_CAPS;
3381 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3382 surface = (void *)0xdeadbeef;
3383 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
3384 ok(hr == DDERR_NOCOOPERATIVELEVELSET, "Surface creation returned hr %#x.\n", hr);
3385 ok(surface == (void *)0xdeadbeef, "Got unexpected surface %p.\n", surface);
3387 IDirectDraw7_Release(ddraw);
3390 static void test_vb_discard(void)
3392 static const struct vec4 quad[] =
3394 { 0.0f, 480.0f, 0.0f, 1.0f},
3395 { 0.0f, 0.0f, 0.0f, 1.0f},
3396 {640.0f, 480.0f, 0.0f, 1.0f},
3397 {640.0f, 0.0f, 0.0f, 1.0f},
3400 IDirect3DDevice7 *device;
3401 IDirect3D7 *d3d;
3402 IDirect3DVertexBuffer7 *buffer;
3403 HWND window;
3404 HRESULT hr;
3405 D3DVERTEXBUFFERDESC desc;
3406 BYTE *data;
3407 static const unsigned int vbsize = 16;
3408 unsigned int i;
3410 window = create_window();
3411 if (!(device = create_device(window, DDSCL_NORMAL)))
3413 skip("Failed to create a 3D device, skipping test.\n");
3414 DestroyWindow(window);
3415 return;
3418 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
3419 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
3421 memset(&desc, 0, sizeof(desc));
3422 desc.dwSize = sizeof(desc);
3423 desc.dwCaps = D3DVBCAPS_WRITEONLY;
3424 desc.dwFVF = D3DFVF_XYZRHW;
3425 desc.dwNumVertices = vbsize;
3426 hr = IDirect3D7_CreateVertexBuffer(d3d, &desc, &buffer, 0);
3427 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
3429 hr = IDirect3DVertexBuffer7_Lock(buffer, DDLOCK_DISCARDCONTENTS, (void **)&data, NULL);
3430 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
3431 memcpy(data, quad, sizeof(quad));
3432 hr = IDirect3DVertexBuffer7_Unlock(buffer);
3433 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
3435 hr = IDirect3DDevice7_BeginScene(device);
3436 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
3437 hr = IDirect3DDevice7_DrawPrimitiveVB(device, D3DPT_TRIANGLESTRIP, buffer, 0, 4, 0);
3438 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3439 hr = IDirect3DDevice7_EndScene(device);
3440 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
3442 hr = IDirect3DVertexBuffer7_Lock(buffer, DDLOCK_DISCARDCONTENTS, (void **)&data, NULL);
3443 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
3444 memset(data, 0xaa, sizeof(struct vec4) * vbsize);
3445 hr = IDirect3DVertexBuffer7_Unlock(buffer);
3446 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
3448 hr = IDirect3DVertexBuffer7_Lock(buffer, DDLOCK_DISCARDCONTENTS, (void **)&data, NULL);
3449 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
3450 for (i = 0; i < sizeof(struct vec4) * vbsize; i++)
3452 if (data[i] != 0xaa)
3454 ok(FALSE, "Vertex buffer data byte %u is 0x%02x, expected 0xaa\n", i, data[i]);
3455 break;
3458 hr = IDirect3DVertexBuffer7_Unlock(buffer);
3459 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
3461 IDirect3DVertexBuffer7_Release(buffer);
3462 IDirect3D7_Release(d3d);
3463 IDirect3DDevice7_Release(device);
3464 DestroyWindow(window);
3467 static void test_coop_level_multi_window(void)
3469 HWND window1, window2;
3470 IDirectDraw7 *ddraw;
3471 HRESULT hr;
3473 window1 = create_window();
3474 window2 = create_window();
3475 ddraw = create_ddraw();
3476 ok(!!ddraw, "Failed to create a ddraw object.\n");
3478 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window1, DDSCL_NORMAL);
3479 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3480 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window2, DDSCL_NORMAL);
3481 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3482 ok(IsWindow(window1), "Window 1 was destroyed.\n");
3483 ok(IsWindow(window2), "Window 2 was destroyed.\n");
3485 IDirectDraw7_Release(ddraw);
3486 DestroyWindow(window2);
3487 DestroyWindow(window1);
3490 static void test_draw_strided(void)
3492 static struct vec3 position[] =
3494 {-1.0, -1.0, 0.0},
3495 {-1.0, 1.0, 0.0},
3496 { 1.0, 1.0, 0.0},
3497 { 1.0, -1.0, 0.0},
3499 static DWORD diffuse[] =
3501 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00,
3503 static WORD indices[] =
3505 0, 1, 2, 2, 3, 0
3508 IDirectDrawSurface7 *rt;
3509 IDirect3DDevice7 *device;
3510 D3DCOLOR color;
3511 HWND window;
3512 HRESULT hr;
3513 D3DDRAWPRIMITIVESTRIDEDDATA strided;
3515 window = create_window();
3516 if (!(device = create_device(window, DDSCL_NORMAL)))
3518 skip("Failed to create a 3D device, skipping test.\n");
3519 DestroyWindow(window);
3520 return;
3523 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
3524 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
3526 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
3527 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
3528 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00000000, 1.0f, 0);
3529 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
3530 hr = IDirect3DDevice7_BeginScene(device);
3531 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
3533 memset(&strided, 0x55, sizeof(strided));
3534 strided.position.lpvData = position;
3535 strided.position.dwStride = sizeof(*position);
3536 strided.diffuse.lpvData = diffuse;
3537 strided.diffuse.dwStride = sizeof(*diffuse);
3538 hr = IDirect3DDevice7_DrawIndexedPrimitiveStrided(device, D3DPT_TRIANGLELIST, D3DFVF_XYZ | D3DFVF_DIFFUSE,
3539 &strided, 4, indices, 6, 0);
3540 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3542 hr = IDirect3DDevice7_EndScene(device);
3543 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
3545 color = get_surface_color(rt, 320, 240);
3546 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
3548 IDirectDrawSurface7_Release(rt);
3549 IDirect3DDevice7_Release(device);
3550 DestroyWindow(window);
3553 static void test_lighting(void)
3555 static D3DMATRIX mat =
3557 1.0f, 0.0f, 0.0f, 0.0f,
3558 0.0f, 1.0f, 0.0f, 0.0f,
3559 0.0f, 0.0f, 1.0f, 0.0f,
3560 0.0f, 0.0f, 0.0f, 1.0f,
3562 mat_singular =
3564 1.0f, 0.0f, 1.0f, 0.0f,
3565 0.0f, 1.0f, 0.0f, 0.0f,
3566 1.0f, 0.0f, 1.0f, 0.0f,
3567 0.0f, 0.0f, 0.5f, 1.0f,
3569 mat_transf =
3571 0.0f, 0.0f, 1.0f, 0.0f,
3572 0.0f, 1.0f, 0.0f, 0.0f,
3573 -1.0f, 0.0f, 0.0f, 0.0f,
3574 10.f, 10.0f, 10.0f, 1.0f,
3576 mat_nonaffine =
3578 1.0f, 0.0f, 0.0f, 0.0f,
3579 0.0f, 1.0f, 0.0f, 0.0f,
3580 0.0f, 0.0f, 1.0f, -1.0f,
3581 10.f, 10.0f, 10.0f, 0.0f,
3583 static struct
3585 struct vec3 position;
3586 DWORD diffuse;
3588 unlitquad[] =
3590 {{-1.0f, -1.0f, 0.1f}, 0xffff0000},
3591 {{-1.0f, 0.0f, 0.1f}, 0xffff0000},
3592 {{ 0.0f, 0.0f, 0.1f}, 0xffff0000},
3593 {{ 0.0f, -1.0f, 0.1f}, 0xffff0000},
3595 litquad[] =
3597 {{-1.0f, 0.0f, 0.1f}, 0xff00ff00},
3598 {{-1.0f, 1.0f, 0.1f}, 0xff00ff00},
3599 {{ 0.0f, 1.0f, 0.1f}, 0xff00ff00},
3600 {{ 0.0f, 0.0f, 0.1f}, 0xff00ff00},
3602 static struct
3604 struct vec3 position;
3605 struct vec3 normal;
3606 DWORD diffuse;
3608 unlitnquad[] =
3610 {{0.0f, -1.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xff0000ff},
3611 {{0.0f, 0.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xff0000ff},
3612 {{1.0f, 0.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xff0000ff},
3613 {{1.0f, -1.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xff0000ff},
3615 litnquad[] =
3617 {{0.0f, 0.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xffffff00},
3618 {{0.0f, 1.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xffffff00},
3619 {{1.0f, 1.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xffffff00},
3620 {{1.0f, 0.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xffffff00},
3622 nquad[] =
3624 {{-1.0f, -1.0f, 0.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
3625 {{-1.0f, 1.0f, 0.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
3626 {{ 1.0f, 1.0f, 0.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
3627 {{ 1.0f, -1.0f, 0.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
3629 rotatedquad[] =
3631 {{-10.0f, -11.0f, 11.0f}, {-1.0f, 0.0f, 0.0f}, 0xff0000ff},
3632 {{-10.0f, -9.0f, 11.0f}, {-1.0f, 0.0f, 0.0f}, 0xff0000ff},
3633 {{-10.0f, -9.0f, 9.0f}, {-1.0f, 0.0f, 0.0f}, 0xff0000ff},
3634 {{-10.0f, -11.0f, 9.0f}, {-1.0f, 0.0f, 0.0f}, 0xff0000ff},
3636 translatedquad[] =
3638 {{-11.0f, -11.0f, -10.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
3639 {{-11.0f, -9.0f, -10.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
3640 {{ -9.0f, -9.0f, -10.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
3641 {{ -9.0f, -11.0f, -10.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
3643 static WORD indices[] = {0, 1, 2, 2, 3, 0};
3644 static const struct
3646 D3DMATRIX *world_matrix;
3647 void *quad;
3648 DWORD expected;
3649 const char *message;
3651 tests[] =
3653 {&mat, nquad, 0x000000ff, "Lit quad with light"},
3654 {&mat_singular, nquad, 0x000000ff, "Lit quad with singular world matrix"},
3655 {&mat_transf, rotatedquad, 0x000000ff, "Lit quad with transformation matrix"},
3656 {&mat_nonaffine, translatedquad, 0x00000000, "Lit quad with non-affine matrix"},
3659 HWND window;
3660 IDirect3DDevice7 *device;
3661 IDirectDrawSurface7 *rt;
3662 HRESULT hr;
3663 DWORD fvf = D3DFVF_XYZ | D3DFVF_DIFFUSE;
3664 DWORD nfvf = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_NORMAL;
3665 D3DCOLOR color;
3666 ULONG refcount;
3667 unsigned int i;
3669 window = create_window();
3670 if (!(device = create_device(window, DDSCL_NORMAL)))
3672 skip("Failed to create a 3D device, skipping test.\n");
3673 DestroyWindow(window);
3674 return;
3677 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
3678 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
3680 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
3681 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
3683 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &mat);
3684 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#x.\n", hr);
3685 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_VIEW, &mat);
3686 ok(SUCCEEDED(hr), "Failed to set view transform, hr %#x.\n", hr);
3687 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &mat);
3688 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
3689 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CLIPPING, FALSE);
3690 ok(SUCCEEDED(hr), "Failed to disable clipping, hr %#x.\n", hr);
3691 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, FALSE);
3692 ok(SUCCEEDED(hr), "Failed to disable z-buffering, hr %#x.\n", hr);
3693 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, FALSE);
3694 ok(SUCCEEDED(hr), "Failed to disable fog, hr %#x.\n", hr);
3695 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_STENCILENABLE, FALSE);
3696 ok(SUCCEEDED(hr), "Failed to disable stencil buffering, hr %#x.\n", hr);
3697 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CULLMODE, D3DCULL_NONE);
3698 ok(SUCCEEDED(hr), "Failed to disable culling, hr %#x.\n", hr);
3700 hr = IDirect3DDevice7_BeginScene(device);
3701 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
3703 /* No lights are defined... That means, lit vertices should be entirely black. */
3704 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
3705 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
3706 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, fvf, unlitquad, 4,
3707 indices, 6, 0);
3708 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3710 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, TRUE);
3711 ok(SUCCEEDED(hr), "Failed to enable lighting, hr %#x.\n", hr);
3712 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, fvf, litquad, 4,
3713 indices, 6, 0);
3714 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3716 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
3717 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
3718 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, nfvf, unlitnquad, 4,
3719 indices, 6, 0);
3720 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3722 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, TRUE);
3723 ok(SUCCEEDED(hr), "Failed to enable lighting, hr %#x.\n", hr);
3724 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, nfvf, litnquad, 4,
3725 indices, 6, 0);
3726 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3728 hr = IDirect3DDevice7_EndScene(device);
3729 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
3731 color = get_surface_color(rt, 160, 360);
3732 ok(color == 0x00ff0000, "Unlit quad without normals has color 0x%08x, expected 0x00ff0000.\n", color);
3733 color = get_surface_color(rt, 160, 120);
3734 ok(color == 0x00000000, "Lit quad without normals has color 0x%08x, expected 0x00000000.\n", color);
3735 color = get_surface_color(rt, 480, 360);
3736 ok(color == 0x000000ff, "Unlit quad with normals has color 0x%08x, expected 0x000000ff.\n", color);
3737 color = get_surface_color(rt, 480, 120);
3738 ok(color == 0x00000000, "Lit quad with normals has color 0x%08x, expected 0x00000000.\n", color);
3740 hr = IDirect3DDevice7_LightEnable(device, 0, TRUE);
3741 ok(SUCCEEDED(hr), "Failed to enable light 0, hr %#x.\n", hr);
3743 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3745 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_WORLD, tests[i].world_matrix);
3746 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#x.\n", hr);
3748 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
3749 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
3751 hr = IDirect3DDevice7_BeginScene(device);
3752 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
3754 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, nfvf, tests[i].quad,
3755 4, indices, 6, 0);
3756 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3758 hr = IDirect3DDevice7_EndScene(device);
3759 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
3761 color = get_surface_color(rt, 320, 240);
3762 ok(color == tests[i].expected, "%s has color 0x%08x.\n", tests[i].message, color);
3765 IDirectDrawSurface7_Release(rt);
3767 refcount = IDirect3DDevice7_Release(device);
3768 ok(!refcount, "Device has %u references left.\n", refcount);
3769 DestroyWindow(window);
3772 static void test_specular_lighting(void)
3774 static const unsigned int vertices_side = 5;
3775 const unsigned int indices_count = (vertices_side - 1) * (vertices_side - 1) * 2 * 3;
3776 static const DWORD fvf = D3DFVF_XYZ | D3DFVF_NORMAL;
3777 static D3DMATRIX mat =
3779 1.0f, 0.0f, 0.0f, 0.0f,
3780 0.0f, 1.0f, 0.0f, 0.0f,
3781 0.0f, 0.0f, 1.0f, 0.0f,
3782 0.0f, 0.0f, 0.0f, 1.0f,
3784 static D3DLIGHT7 directional =
3786 D3DLIGHT_DIRECTIONAL,
3787 {{0.0f}, {0.0f}, {0.0f}, {0.0f}},
3788 {{1.0f}, {1.0f}, {1.0f}, {0.0f}},
3789 {{0.0f}, {0.0f}, {0.0f}, {0.0f}},
3790 {{0.0f}, {0.0f}, {0.0f}},
3791 {{0.0f}, {0.0f}, {1.0f}},
3793 point =
3795 D3DLIGHT_POINT,
3796 {{0.0f}, {0.0f}, {0.0f}, {0.0f}},
3797 {{1.0f}, {1.0f}, {1.0f}, {0.0f}},
3798 {{0.0f}, {0.0f}, {0.0f}, {0.0f}},
3799 {{0.0f}, {0.0f}, {0.0f}},
3800 {{0.0f}, {0.0f}, {0.0f}},
3801 100.0f,
3802 0.0f,
3803 0.0f, 0.0f, 1.0f,
3805 spot =
3807 D3DLIGHT_SPOT,
3808 {{0.0f}, {0.0f}, {0.0f}, {0.0f}},
3809 {{1.0f}, {1.0f}, {1.0f}, {0.0f}},
3810 {{0.0f}, {0.0f}, {0.0f}, {0.0f}},
3811 {{0.0f}, {0.0f}, {0.0f}},
3812 {{0.0f}, {0.0f}, {1.0f}},
3813 100.0f,
3814 1.0f,
3815 0.0f, 0.0f, 1.0f,
3816 M_PI / 12.0f, M_PI / 3.0f
3818 /* The chosen range value makes the test fail when using a manhattan
3819 * distance metric vs the correct euclidean distance. */
3820 point_range =
3822 D3DLIGHT_POINT,
3823 {{0.0f}, {0.0f}, {0.0f}, {0.0f}},
3824 {{1.0f}, {1.0f}, {1.0f}, {0.0f}},
3825 {{0.0f}, {0.0f}, {0.0f}, {0.0f}},
3826 {{0.0f}, {0.0f}, {0.0f}},
3827 {{0.0f}, {0.0f}, {0.0f}},
3828 1.2f,
3829 0.0f,
3830 0.0f, 0.0f, 1.0f,
3832 point_side =
3834 D3DLIGHT_POINT,
3835 {{0.0f}, {0.0f}, {0.0f}, {0.0f}},
3836 {{1.0f}, {1.0f}, {1.0f}, {0.0f}},
3837 {{0.0f}, {0.0f}, {0.0f}, {0.0f}},
3838 {{-1.1f}, {0.0f}, {1.1f}},
3839 {{0.0f}, {0.0f}, {0.0f}},
3840 100.0f,
3841 0.0f,
3842 1.0f, 0.0f, 0.0f,
3844 static const struct expected_color
3846 unsigned int x, y;
3847 D3DCOLOR color;
3849 expected_directional[] =
3851 {160, 120, 0x00ffffff},
3852 {320, 120, 0x00ffffff},
3853 {480, 120, 0x00ffffff},
3854 {160, 240, 0x00ffffff},
3855 {320, 240, 0x00ffffff},
3856 {480, 240, 0x00ffffff},
3857 {160, 360, 0x00ffffff},
3858 {320, 360, 0x00ffffff},
3859 {480, 360, 0x00ffffff},
3861 expected_directional_local[] =
3863 {160, 120, 0x003c3c3c},
3864 {320, 120, 0x00717171},
3865 {480, 120, 0x003c3c3c},
3866 {160, 240, 0x00717171},
3867 {320, 240, 0x00ffffff},
3868 {480, 240, 0x00717171},
3869 {160, 360, 0x003c3c3c},
3870 {320, 360, 0x00717171},
3871 {480, 360, 0x003c3c3c},
3873 expected_point[] =
3875 {160, 120, 0x00282828},
3876 {320, 120, 0x005a5a5a},
3877 {480, 120, 0x00282828},
3878 {160, 240, 0x005a5a5a},
3879 {320, 240, 0x00ffffff},
3880 {480, 240, 0x005a5a5a},
3881 {160, 360, 0x00282828},
3882 {320, 360, 0x005a5a5a},
3883 {480, 360, 0x00282828},
3885 expected_point_local[] =
3887 {160, 120, 0x00000000},
3888 {320, 120, 0x00070707},
3889 {480, 120, 0x00000000},
3890 {160, 240, 0x00070707},
3891 {320, 240, 0x00ffffff},
3892 {480, 240, 0x00070707},
3893 {160, 360, 0x00000000},
3894 {320, 360, 0x00070707},
3895 {480, 360, 0x00000000},
3897 expected_spot[] =
3899 {160, 120, 0x00000000},
3900 {320, 120, 0x00141414},
3901 {480, 120, 0x00000000},
3902 {160, 240, 0x00141414},
3903 {320, 240, 0x00ffffff},
3904 {480, 240, 0x00141414},
3905 {160, 360, 0x00000000},
3906 {320, 360, 0x00141414},
3907 {480, 360, 0x00000000},
3909 expected_spot_local[] =
3911 {160, 120, 0x00000000},
3912 {320, 120, 0x00020202},
3913 {480, 120, 0x00000000},
3914 {160, 240, 0x00020202},
3915 {320, 240, 0x00ffffff},
3916 {480, 240, 0x00020202},
3917 {160, 360, 0x00000000},
3918 {320, 360, 0x00020202},
3919 {480, 360, 0x00000000},
3921 expected_point_range[] =
3923 {160, 120, 0x00000000},
3924 {320, 120, 0x005a5a5a},
3925 {480, 120, 0x00000000},
3926 {160, 240, 0x005a5a5a},
3927 {320, 240, 0x00ffffff},
3928 {480, 240, 0x005a5a5a},
3929 {160, 360, 0x00000000},
3930 {320, 360, 0x005a5a5a},
3931 {480, 360, 0x00000000},
3933 expected_point_side[] =
3935 {160, 120, 0x00000000},
3936 {320, 120, 0x00000000},
3937 {480, 120, 0x00000000},
3938 {160, 240, 0x00000000},
3939 {320, 240, 0x00000000},
3940 {480, 240, 0x00000000},
3941 {160, 360, 0x00000000},
3942 {320, 360, 0x00000000},
3943 {480, 360, 0x00000000},
3945 static const struct
3947 D3DLIGHT7 *light;
3948 BOOL local_viewer;
3949 float specular_power;
3950 const struct expected_color *expected;
3951 unsigned int expected_count;
3953 tests[] =
3955 {&directional, FALSE, 30.0f, expected_directional, ARRAY_SIZE(expected_directional)},
3956 {&directional, TRUE, 30.0f, expected_directional_local, ARRAY_SIZE(expected_directional_local)},
3957 {&point, FALSE, 30.0f, expected_point, ARRAY_SIZE(expected_point)},
3958 {&point, TRUE, 30.0f, expected_point_local, ARRAY_SIZE(expected_point_local)},
3959 {&spot, FALSE, 30.0f, expected_spot, ARRAY_SIZE(expected_spot)},
3960 {&spot, TRUE, 30.0f, expected_spot_local, ARRAY_SIZE(expected_spot_local)},
3961 {&point_range, FALSE, 30.0f, expected_point_range, ARRAY_SIZE(expected_point_range)},
3962 {&point_side, TRUE, 0.0f, expected_point_side, ARRAY_SIZE(expected_point_side)},
3964 IDirect3DDevice7 *device;
3965 IDirectDrawSurface7 *rt;
3966 D3DMATERIAL7 material;
3967 D3DCOLOR color;
3968 ULONG refcount;
3969 HWND window;
3970 HRESULT hr;
3971 unsigned int i, j, x, y;
3972 struct
3974 struct vec3 position;
3975 struct vec3 normal;
3976 } *quad;
3977 WORD *indices;
3979 window = create_window();
3980 if (!(device = create_device(window, DDSCL_NORMAL)))
3982 skip("Failed to create a 3D device, skipping test.\n");
3983 DestroyWindow(window);
3984 return;
3987 quad = HeapAlloc(GetProcessHeap(), 0, vertices_side * vertices_side * sizeof(*quad));
3988 indices = HeapAlloc(GetProcessHeap(), 0, indices_count * sizeof(*indices));
3989 for (i = 0, y = 0; y < vertices_side; ++y)
3991 for (x = 0; x < vertices_side; ++x)
3993 quad[i].position.x = x * 2.0f / (vertices_side - 1) - 1.0f;
3994 quad[i].position.y = y * 2.0f / (vertices_side - 1) - 1.0f;
3995 quad[i].position.z = 1.0f;
3996 quad[i].normal.x = 0.0f;
3997 quad[i].normal.y = 0.0f;
3998 quad[i++].normal.z = -1.0f;
4001 for (i = 0, y = 0; y < (vertices_side - 1); ++y)
4003 for (x = 0; x < (vertices_side - 1); ++x)
4005 indices[i++] = y * vertices_side + x + 1;
4006 indices[i++] = y * vertices_side + x;
4007 indices[i++] = (y + 1) * vertices_side + x;
4008 indices[i++] = y * vertices_side + x + 1;
4009 indices[i++] = (y + 1) * vertices_side + x;
4010 indices[i++] = (y + 1) * vertices_side + x + 1;
4014 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
4015 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
4017 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &mat);
4018 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#x.\n", hr);
4019 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_VIEW, &mat);
4020 ok(SUCCEEDED(hr), "Failed to set view transform, hr %#x.\n", hr);
4021 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &mat);
4022 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
4023 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CLIPPING, FALSE);
4024 ok(SUCCEEDED(hr), "Failed to disable clipping, hr %#x.\n", hr);
4025 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, FALSE);
4026 ok(SUCCEEDED(hr), "Failed to disable z-buffering, hr %#x.\n", hr);
4027 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, FALSE);
4028 ok(SUCCEEDED(hr), "Failed to disable fog, hr %#x.\n", hr);
4030 hr = IDirect3DDevice7_LightEnable(device, 0, TRUE);
4031 ok(SUCCEEDED(hr), "Failed to enable light 0, hr %#x.\n", hr);
4032 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_SPECULARENABLE, TRUE);
4033 ok(SUCCEEDED(hr), "Failed to enable specular lighting, hr %#x.\n", hr);
4035 for (i = 0; i < ARRAY_SIZE(tests); ++i)
4037 hr = IDirect3DDevice7_SetLight(device, 0, tests[i].light);
4038 ok(SUCCEEDED(hr), "Failed to set light parameters, hr %#x.\n", hr);
4040 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LOCALVIEWER, tests[i].local_viewer);
4041 ok(SUCCEEDED(hr), "Failed to set local viewer state, hr %#x.\n", hr);
4043 memset(&material, 0, sizeof(material));
4044 U1(U2(material).specular).r = 1.0f;
4045 U2(U2(material).specular).g = 1.0f;
4046 U3(U2(material).specular).b = 1.0f;
4047 U4(U2(material).specular).a = 1.0f;
4048 U4(material).power = tests[i].specular_power;
4049 hr = IDirect3DDevice7_SetMaterial(device, &material);
4050 ok(SUCCEEDED(hr), "Failed to set material, hr %#x.\n", hr);
4052 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
4053 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
4055 hr = IDirect3DDevice7_BeginScene(device);
4056 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
4058 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, fvf, quad,
4059 vertices_side * vertices_side, indices, indices_count, 0);
4060 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
4062 hr = IDirect3DDevice7_EndScene(device);
4063 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
4065 for (j = 0; j < tests[i].expected_count; ++j)
4067 color = get_surface_color(rt, tests[i].expected[j].x, tests[i].expected[j].y);
4068 ok(compare_color(color, tests[i].expected[j].color, 1),
4069 "Expected color 0x%08x at location (%u, %u), got 0x%08x, case %u.\n",
4070 tests[i].expected[j].color, tests[i].expected[j].x,
4071 tests[i].expected[j].y, color, i);
4075 IDirectDrawSurface7_Release(rt);
4077 refcount = IDirect3DDevice7_Release(device);
4078 ok(!refcount, "Device has %u references left.\n", refcount);
4079 DestroyWindow(window);
4080 HeapFree(GetProcessHeap(), 0, indices);
4081 HeapFree(GetProcessHeap(), 0, quad);
4084 static void test_clear_rect_count(void)
4086 IDirectDrawSurface7 *rt;
4087 IDirect3DDevice7 *device;
4088 D3DCOLOR color;
4089 HWND window;
4090 HRESULT hr;
4091 D3DRECT rect = {{0}, {0}, {640}, {480}};
4093 window = create_window();
4094 if (!(device = create_device(window, DDSCL_NORMAL)))
4096 skip("Failed to create a 3D device, skipping test.\n");
4097 DestroyWindow(window);
4098 return;
4101 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
4102 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
4104 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00ffffff, 1.0f, 0);
4105 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
4106 hr = IDirect3DDevice7_Clear(device, 0, &rect, D3DCLEAR_TARGET, 0x00ff0000, 1.0f, 0);
4107 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
4109 color = get_surface_color(rt, 320, 240);
4110 ok(compare_color(color, 0x00ffffff, 1) || broken(compare_color(color, 0x00ff0000, 1)),
4111 "Clear with count = 0, rect != NULL has color %#08x.\n", color);
4113 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00ffffff, 1.0f, 0);
4114 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
4115 hr = IDirect3DDevice7_Clear(device, 1, NULL, D3DCLEAR_TARGET, 0x0000ff00, 1.0f, 0);
4116 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
4118 color = get_surface_color(rt, 320, 240);
4119 ok(compare_color(color, 0x0000ff00, 1),
4120 "Clear with count = 1, rect = NULL has color %#08x.\n", color);
4122 IDirectDrawSurface7_Release(rt);
4123 IDirect3DDevice7_Release(device);
4124 DestroyWindow(window);
4127 static BOOL test_mode_restored(IDirectDraw7 *ddraw, HWND window)
4129 DDSURFACEDESC2 ddsd1, ddsd2;
4130 HRESULT hr;
4132 memset(&ddsd1, 0, sizeof(ddsd1));
4133 ddsd1.dwSize = sizeof(ddsd1);
4134 hr = IDirectDraw7_GetDisplayMode(ddraw, &ddsd1);
4135 ok(SUCCEEDED(hr), "GetDisplayMode failed, hr %#x.\n", hr);
4137 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
4138 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
4139 hr = set_display_mode(ddraw, 640, 480);
4140 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
4141 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
4142 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
4144 memset(&ddsd2, 0, sizeof(ddsd2));
4145 ddsd2.dwSize = sizeof(ddsd2);
4146 hr = IDirectDraw7_GetDisplayMode(ddraw, &ddsd2);
4147 ok(SUCCEEDED(hr), "GetDisplayMode failed, hr %#x.\n", hr);
4148 hr = IDirectDraw7_RestoreDisplayMode(ddraw);
4149 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
4151 return ddsd1.dwWidth == ddsd2.dwWidth && ddsd1.dwHeight == ddsd2.dwHeight;
4154 static void test_coop_level_versions(void)
4156 HWND window;
4157 IDirectDraw *ddraw;
4158 HRESULT hr;
4159 BOOL restored;
4160 IDirectDrawSurface *surface;
4161 IDirectDraw7 *ddraw7;
4162 DDSURFACEDESC ddsd;
4164 window = create_window();
4165 ddraw7 = create_ddraw();
4166 ok(!!ddraw7, "Failed to create a ddraw object.\n");
4167 /* Newly created ddraw objects restore the mode on ddraw2+::SetCooperativeLevel(NORMAL) */
4168 restored = test_mode_restored(ddraw7, window);
4169 ok(restored, "Display mode not restored in new ddraw object\n");
4171 /* A failing ddraw1::SetCooperativeLevel call does not have an effect */
4172 hr = IDirectDraw7_QueryInterface(ddraw7, &IID_IDirectDraw, (void **)&ddraw);
4173 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#x.\n", hr);
4175 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
4176 ok(FAILED(hr), "SetCooperativeLevel returned %#x, expected failure.\n", hr);
4177 restored = test_mode_restored(ddraw7, window);
4178 ok(restored, "Display mode not restored after bad ddraw1::SetCooperativeLevel call\n");
4180 /* A successful one does */
4181 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
4182 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
4183 restored = test_mode_restored(ddraw7, window);
4184 ok(!restored, "Display mode restored after good ddraw1::SetCooperativeLevel call\n");
4186 IDirectDraw_Release(ddraw);
4187 IDirectDraw7_Release(ddraw7);
4189 ddraw7 = create_ddraw();
4190 ok(!!ddraw7, "Failed to create a ddraw object.\n");
4191 hr = IDirectDraw7_QueryInterface(ddraw7, &IID_IDirectDraw, (void **)&ddraw);
4192 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#x.\n", hr);
4194 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_SETFOCUSWINDOW);
4195 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
4196 restored = test_mode_restored(ddraw7, window);
4197 ok(!restored, "Display mode restored after ddraw1::SetCooperativeLevel(SETFOCUSWINDOW) call\n");
4199 IDirectDraw_Release(ddraw);
4200 IDirectDraw7_Release(ddraw7);
4202 /* A failing call does not restore the ddraw2+ behavior */
4203 ddraw7 = create_ddraw();
4204 ok(!!ddraw7, "Failed to create a ddraw object.\n");
4205 hr = IDirectDraw7_QueryInterface(ddraw7, &IID_IDirectDraw, (void **)&ddraw);
4206 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#x.\n", hr);
4208 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
4209 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
4210 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
4211 ok(FAILED(hr), "SetCooperativeLevel returned %#x, expected failure.\n", hr);
4212 restored = test_mode_restored(ddraw7, window);
4213 ok(!restored, "Display mode restored after good-bad ddraw1::SetCooperativeLevel() call sequence\n");
4215 IDirectDraw_Release(ddraw);
4216 IDirectDraw7_Release(ddraw7);
4218 /* Neither does a sequence of successful calls with the new interface */
4219 ddraw7 = create_ddraw();
4220 ok(!!ddraw7, "Failed to create a ddraw object.\n");
4221 hr = IDirectDraw7_QueryInterface(ddraw7, &IID_IDirectDraw, (void **)&ddraw);
4222 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#x.\n", hr);
4224 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
4225 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
4226 hr = IDirectDraw7_SetCooperativeLevel(ddraw7, window, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
4227 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
4228 hr = IDirectDraw7_SetCooperativeLevel(ddraw7, window, DDSCL_NORMAL);
4229 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
4231 restored = test_mode_restored(ddraw7, window);
4232 ok(!restored, "Display mode restored after ddraw1-ddraw7 SetCooperativeLevel() call sequence\n");
4233 IDirectDraw_Release(ddraw);
4234 IDirectDraw7_Release(ddraw7);
4236 /* ddraw1::CreateSurface does not triger the ddraw1 behavior */
4237 ddraw7 = create_ddraw();
4238 ok(!!ddraw7, "Failed to create a ddraw object.\n");
4239 hr = IDirectDraw7_QueryInterface(ddraw7, &IID_IDirectDraw, (void **)&ddraw);
4240 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#x.\n", hr);
4242 hr = IDirectDraw7_SetCooperativeLevel(ddraw7, window, DDSCL_NORMAL);
4243 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
4245 memset(&ddsd, 0, sizeof(ddsd));
4246 ddsd.dwSize = sizeof(ddsd);
4247 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
4248 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
4249 ddsd.dwWidth = ddsd.dwHeight = 8;
4250 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &surface, NULL);
4251 ok(SUCCEEDED(hr), "CreateSurface failed, hr %#x.\n", hr);
4252 IDirectDrawSurface_Release(surface);
4253 restored = test_mode_restored(ddraw7, window);
4254 ok(restored, "Display mode not restored after ddraw1::CreateSurface() call\n");
4256 IDirectDraw_Release(ddraw);
4257 IDirectDraw7_Release(ddraw7);
4258 DestroyWindow(window);
4261 static void test_fog_special(void)
4263 static struct
4265 struct vec3 position;
4266 D3DCOLOR diffuse;
4268 quad[] =
4270 {{ -1.0f, 1.0f, 0.0f}, 0xff00ff00},
4271 {{ 1.0f, 1.0f, 1.0f}, 0xff00ff00},
4272 {{ -1.0f, -1.0f, 0.0f}, 0xff00ff00},
4273 {{ 1.0f, -1.0f, 1.0f}, 0xff00ff00},
4275 static const struct
4277 DWORD vertexmode, tablemode;
4278 D3DCOLOR color_left, color_right;
4280 tests[] =
4282 {D3DFOG_LINEAR, D3DFOG_NONE, 0x00ff0000, 0x00ff0000},
4283 {D3DFOG_NONE, D3DFOG_LINEAR, 0x0000ff00, 0x00ff0000},
4285 union
4287 float f;
4288 DWORD d;
4289 } conv;
4290 D3DCOLOR color;
4291 HRESULT hr;
4292 unsigned int i;
4293 HWND window;
4294 IDirect3DDevice7 *device;
4295 IDirectDrawSurface7 *rt;
4297 window = create_window();
4298 if (!(device = create_device(window, DDSCL_NORMAL)))
4300 skip("Failed to create a 3D device, skipping test.\n");
4301 DestroyWindow(window);
4302 return;
4305 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
4306 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
4308 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, TRUE);
4309 ok(SUCCEEDED(hr), "Failed to enable fog, hr %#x.\n", hr);
4310 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGCOLOR, 0xffff0000);
4311 ok(SUCCEEDED(hr), "Failed to set fog color, hr %#x.\n", hr);
4312 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
4313 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
4314 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
4315 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
4317 conv.f = 0.5f;
4318 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGSTART, conv.d);
4319 ok(SUCCEEDED(hr), "Failed to set fog start, hr %#x.\n", hr);
4320 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGEND, conv.d);
4321 ok(SUCCEEDED(hr), "Failed to set fog end, hr %#x.\n", hr);
4323 for (i = 0; i < ARRAY_SIZE(tests); ++i)
4325 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x000000ff, 1.0f, 0);
4326 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
4328 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGVERTEXMODE, tests[i].vertexmode);
4329 ok(SUCCEEDED(hr), "Failed to set fogvertexmode, hr %#x.\n", hr);
4330 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGTABLEMODE, tests[i].tablemode);
4331 ok(SUCCEEDED(hr), "Failed to set fogtablemode, hr %#x.\n", hr);
4333 hr = IDirect3DDevice7_BeginScene(device);
4334 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
4335 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE, quad, 4, 0);
4336 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
4337 hr = IDirect3DDevice7_EndScene(device);
4338 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
4340 color = get_surface_color(rt, 310, 240);
4341 ok(compare_color(color, tests[i].color_left, 1),
4342 "Expected left color 0x%08x, got 0x%08x, case %u.\n", tests[i].color_left, color, i);
4343 color = get_surface_color(rt, 330, 240);
4344 ok(compare_color(color, tests[i].color_right, 1),
4345 "Expected right color 0x%08x, got 0x%08x, case %u.\n", tests[i].color_right, color, i);
4348 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, FALSE);
4349 ok(SUCCEEDED(hr), "Failed to disable fog, hr %#x.\n", hr);
4351 IDirectDrawSurface7_Release(rt);
4352 IDirect3DDevice7_Release(device);
4353 DestroyWindow(window);
4356 static void test_lighting_interface_versions(void)
4358 IDirect3DDevice7 *device;
4359 IDirectDrawSurface7 *rt;
4360 D3DCOLOR color;
4361 HWND window;
4362 HRESULT hr;
4363 DWORD rs;
4364 unsigned int i;
4365 ULONG ref;
4366 D3DMATERIAL7 material;
4367 static D3DVERTEX quad[] =
4369 {{-1.0f}, { 1.0f}, {0.0f}, {1.0f}, {0.0f}, {0.0f}},
4370 {{ 1.0f}, { 1.0f}, {0.0f}, {1.0f}, {0.0f}, {0.0f}},
4371 {{-1.0f}, {-1.0f}, {0.0f}, {1.0f}, {0.0f}, {0.0f}},
4372 {{ 1.0f}, {-1.0f}, {0.0f}, {1.0f}, {0.0f}, {0.0f}},
4375 #define FVF_COLORVERTEX (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE | D3DFVF_SPECULAR)
4376 static struct
4378 struct vec3 position;
4379 struct vec3 normal;
4380 DWORD diffuse, specular;
4382 quad2[] =
4384 {{-1.0f, 1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000, 0xff808080},
4385 {{ 1.0f, 1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000, 0xff808080},
4386 {{-1.0f, -1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000, 0xff808080},
4387 {{ 1.0f, -1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000, 0xff808080},
4390 static D3DLVERTEX lquad[] =
4392 {{-1.0f}, { 1.0f}, {0.0f}, 0, {0xffff0000}, {0xff808080}},
4393 {{ 1.0f}, { 1.0f}, {0.0f}, 0, {0xffff0000}, {0xff808080}},
4394 {{-1.0f}, {-1.0f}, {0.0f}, 0, {0xffff0000}, {0xff808080}},
4395 {{ 1.0f}, {-1.0f}, {0.0f}, 0, {0xffff0000}, {0xff808080}},
4398 #define FVF_LVERTEX2 (D3DFVF_LVERTEX & ~D3DFVF_RESERVED1)
4399 static struct
4401 struct vec3 position;
4402 DWORD diffuse, specular;
4403 struct vec2 texcoord;
4405 lquad2[] =
4407 {{-1.0f, 1.0f, 0.0f}, 0xffff0000, 0xff808080},
4408 {{ 1.0f, 1.0f, 0.0f}, 0xffff0000, 0xff808080},
4409 {{-1.0f, -1.0f, 0.0f}, 0xffff0000, 0xff808080},
4410 {{ 1.0f, -1.0f, 0.0f}, 0xffff0000, 0xff808080},
4413 static D3DTLVERTEX tlquad[] =
4415 {{ 0.0f}, { 480.0f}, {0.0f}, {1.0f}, {0xff0000ff}, {0xff808080}},
4416 {{ 0.0f}, { 0.0f}, {0.0f}, {1.0f}, {0xff0000ff}, {0xff808080}},
4417 {{ 640.0f}, { 480.0f}, {0.0f}, {1.0f}, {0xff0000ff}, {0xff808080}},
4418 {{ 640.0f}, { 0.0f}, {0.0f}, {1.0f}, {0xff0000ff}, {0xff808080}},
4421 static const struct
4423 DWORD vertextype;
4424 void *data;
4425 DWORD d3drs_lighting, d3drs_specular;
4426 DWORD draw_flags;
4427 D3DCOLOR color;
4429 tests[] =
4431 /* Lighting is enabled when D3DFVF_XYZ is used and D3DRENDERSTATE_LIGHTING is
4432 * enabled. D3DDP_DONOTLIGHT is ignored. Lighting is also enabled when normals
4433 * are not available
4435 * Note that the specular result is 0x00000000 when lighting is on even if the
4436 * input vertex has specular color because D3DRENDERSTATE_COLORVERTEX is not
4437 * enabled */
4439 /* 0 */
4440 { D3DFVF_VERTEX, quad, FALSE, FALSE, 0, 0x00ffffff},
4441 { D3DFVF_VERTEX, quad, TRUE, FALSE, 0, 0x0000ff00},
4442 { D3DFVF_VERTEX, quad, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x00ffffff},
4443 { D3DFVF_VERTEX, quad, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x0000ff00},
4444 { D3DFVF_VERTEX, quad, FALSE, TRUE, 0, 0x00ffffff},
4445 { D3DFVF_VERTEX, quad, TRUE, TRUE, 0, 0x0000ff00},
4446 { D3DFVF_VERTEX, quad, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x00ffffff},
4447 { D3DFVF_VERTEX, quad, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x0000ff00},
4449 /* 8 */
4450 { FVF_COLORVERTEX, quad2, FALSE, FALSE, 0, 0x00ff0000},
4451 { FVF_COLORVERTEX, quad2, TRUE, FALSE, 0, 0x0000ff00},
4452 { FVF_COLORVERTEX, quad2, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x00ff0000},
4453 { FVF_COLORVERTEX, quad2, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x0000ff00},
4454 { FVF_COLORVERTEX, quad2, FALSE, TRUE, 0, 0x00ff8080},
4455 { FVF_COLORVERTEX, quad2, TRUE, TRUE, 0, 0x0000ff00},
4456 { FVF_COLORVERTEX, quad2, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x00ff8080},
4457 { FVF_COLORVERTEX, quad2, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x0000ff00},
4459 /* 16 */
4460 { D3DFVF_LVERTEX, lquad, FALSE, FALSE, 0, 0x00ff0000},
4461 { D3DFVF_LVERTEX, lquad, TRUE, FALSE, 0, 0x0000ff00},
4462 { D3DFVF_LVERTEX, lquad, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x00ff0000},
4463 { D3DFVF_LVERTEX, lquad, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x0000ff00},
4464 { D3DFVF_LVERTEX, lquad, FALSE, TRUE, 0, 0x00ff8080},
4465 { D3DFVF_LVERTEX, lquad, TRUE, TRUE, 0, 0x0000ff00},
4466 { D3DFVF_LVERTEX, lquad, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x00ff8080},
4467 { D3DFVF_LVERTEX, lquad, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x0000ff00},
4469 /* 24 */
4470 { FVF_LVERTEX2, lquad2, FALSE, FALSE, 0, 0x00ff0000},
4471 { FVF_LVERTEX2, lquad2, TRUE, FALSE, 0, 0x0000ff00},
4472 { FVF_LVERTEX2, lquad2, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x00ff0000},
4473 { FVF_LVERTEX2, lquad2, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x0000ff00},
4474 { FVF_LVERTEX2, lquad2, FALSE, TRUE, 0, 0x00ff8080},
4475 { FVF_LVERTEX2, lquad2, TRUE, TRUE, 0, 0x0000ff00},
4476 { FVF_LVERTEX2, lquad2, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x00ff8080},
4477 { FVF_LVERTEX2, lquad2, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x0000ff00},
4479 /* 32 */
4480 { D3DFVF_TLVERTEX, tlquad, FALSE, FALSE, 0, 0x000000ff},
4481 { D3DFVF_TLVERTEX, tlquad, TRUE, FALSE, 0, 0x000000ff},
4482 { D3DFVF_TLVERTEX, tlquad, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x000000ff},
4483 { D3DFVF_TLVERTEX, tlquad, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x000000ff},
4484 { D3DFVF_TLVERTEX, tlquad, FALSE, TRUE, 0, 0x008080ff},
4485 { D3DFVF_TLVERTEX, tlquad, TRUE, TRUE, 0, 0x008080ff},
4486 { D3DFVF_TLVERTEX, tlquad, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x008080ff},
4487 { D3DFVF_TLVERTEX, tlquad, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x008080ff},
4490 window = create_window();
4491 if (!(device = create_device(window, DDSCL_NORMAL)))
4493 skip("Failed to create a 3D device, skipping test.\n");
4494 DestroyWindow(window);
4495 return;
4498 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
4499 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
4501 memset(&material, 0, sizeof(material));
4502 U2(U3(material).emissive).g = 1.0f;
4503 hr = IDirect3DDevice7_SetMaterial(device, &material);
4504 ok(SUCCEEDED(hr), "Failed set material, hr %#x.\n", hr);
4505 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
4506 ok(SUCCEEDED(hr), "Failed to disable z test, hr %#x.\n", hr);
4508 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_LIGHTING, &rs);
4509 ok(SUCCEEDED(hr), "Failed to get lighting render state, hr %#x.\n", hr);
4510 ok(rs == TRUE, "Initial D3DRENDERSTATE_LIGHTING is %#x, expected TRUE.\n", rs);
4511 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_SPECULARENABLE, &rs);
4512 ok(SUCCEEDED(hr), "Failed to get specularenable render state, hr %#x.\n", hr);
4513 ok(rs == FALSE, "Initial D3DRENDERSTATE_SPECULARENABLE is %#x, expected FALSE.\n", rs);
4515 for (i = 0; i < ARRAY_SIZE(tests); ++i)
4517 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff202020, 0.0f, 0);
4518 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
4520 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, tests[i].d3drs_lighting);
4521 ok(SUCCEEDED(hr), "Failed to set lighting render state, hr %#x.\n", hr);
4522 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_SPECULARENABLE,
4523 tests[i].d3drs_specular);
4524 ok(SUCCEEDED(hr), "Failed to set specularenable render state, hr %#x.\n", hr);
4526 hr = IDirect3DDevice7_BeginScene(device);
4527 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
4528 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
4529 tests[i].vertextype, tests[i].data, 4, tests[i].draw_flags | D3DDP_WAIT);
4530 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
4531 hr = IDirect3DDevice7_EndScene(device);
4532 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
4534 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_LIGHTING, &rs);
4535 ok(SUCCEEDED(hr), "Failed to get lighting render state, hr %#x.\n", hr);
4536 ok(rs == tests[i].d3drs_lighting, "D3DRENDERSTATE_LIGHTING is %#x, expected %#x.\n",
4537 rs, tests[i].d3drs_lighting);
4539 color = get_surface_color(rt, 320, 240);
4540 ok(compare_color(color, tests[i].color, 1),
4541 "Got unexpected color 0x%08x, expected 0x%08x, test %u.\n",
4542 color, tests[i].color, i);
4545 IDirectDrawSurface7_Release(rt);
4546 ref = IDirect3DDevice7_Release(device);
4547 ok(ref == 0, "Device not properly released, refcount %u.\n", ref);
4548 DestroyWindow(window);
4551 static struct
4553 BOOL received;
4554 IDirectDraw7 *ddraw;
4555 HWND window;
4556 DWORD coop_level;
4557 } activateapp_testdata;
4559 static LRESULT CALLBACK activateapp_test_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
4561 if (message == WM_ACTIVATEAPP)
4563 if (activateapp_testdata.ddraw)
4565 HRESULT hr;
4566 activateapp_testdata.received = FALSE;
4567 hr = IDirectDraw7_SetCooperativeLevel(activateapp_testdata.ddraw,
4568 activateapp_testdata.window, activateapp_testdata.coop_level);
4569 ok(SUCCEEDED(hr), "Recursive SetCooperativeLevel call failed, hr %#x.\n", hr);
4570 ok(!activateapp_testdata.received, "Received WM_ACTIVATEAPP during recursive SetCooperativeLevel call.\n");
4572 activateapp_testdata.received = TRUE;
4575 return DefWindowProcA(hwnd, message, wparam, lparam);
4578 static void test_coop_level_activateapp(void)
4580 IDirectDraw7 *ddraw;
4581 HRESULT hr;
4582 HWND window;
4583 WNDCLASSA wc = {0};
4584 DDSURFACEDESC2 ddsd;
4585 IDirectDrawSurface7 *surface;
4587 ddraw = create_ddraw();
4588 ok(!!ddraw, "Failed to create a ddraw object.\n");
4590 wc.lpfnWndProc = activateapp_test_proc;
4591 wc.lpszClassName = "ddraw_test_wndproc_wc";
4592 ok(RegisterClassA(&wc), "Failed to register window class.\n");
4594 window = CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
4595 WS_MAXIMIZE | WS_CAPTION , 0, 0, 640, 480, 0, 0, 0, 0);
4597 /* Exclusive with window already active. */
4598 SetForegroundWindow(window);
4599 activateapp_testdata.received = FALSE;
4600 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
4601 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4602 ok(!activateapp_testdata.received, "Received WM_ACTIVATEAPP although window was already active.\n");
4603 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
4604 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4606 /* Exclusive with window not active. */
4607 SetForegroundWindow(GetDesktopWindow());
4608 activateapp_testdata.received = FALSE;
4609 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
4610 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4611 ok(activateapp_testdata.received, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
4612 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
4613 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4615 /* Normal with window not active, then exclusive with the same window. */
4616 SetForegroundWindow(GetDesktopWindow());
4617 activateapp_testdata.received = FALSE;
4618 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
4619 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4620 ok(!activateapp_testdata.received, "Received WM_ACTIVATEAPP when setting DDSCL_NORMAL.\n");
4621 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
4622 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4623 ok(activateapp_testdata.received, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
4624 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
4625 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4627 /* Recursive set of DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN. */
4628 SetForegroundWindow(GetDesktopWindow());
4629 activateapp_testdata.received = FALSE;
4630 activateapp_testdata.ddraw = ddraw;
4631 activateapp_testdata.window = window;
4632 activateapp_testdata.coop_level = DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN;
4633 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
4634 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4635 ok(activateapp_testdata.received, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
4636 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
4637 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4639 /* The recursive call seems to have some bad effect on native ddraw, despite (apparently)
4640 * succeeding. Another switch to exclusive and back to normal is needed to release the
4641 * window properly. Without doing this, SetCooperativeLevel(EXCLUSIVE) will not send
4642 * WM_ACTIVATEAPP messages. */
4643 activateapp_testdata.ddraw = NULL;
4644 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
4645 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4646 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
4647 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4649 /* Setting DDSCL_NORMAL with recursive invocation. */
4650 SetForegroundWindow(GetDesktopWindow());
4651 activateapp_testdata.received = FALSE;
4652 activateapp_testdata.ddraw = ddraw;
4653 activateapp_testdata.window = window;
4654 activateapp_testdata.coop_level = DDSCL_NORMAL;
4655 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
4656 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4657 ok(activateapp_testdata.received, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
4659 /* DDraw is in exclusive mode now. */
4660 memset(&ddsd, 0, sizeof(ddsd));
4661 ddsd.dwSize = sizeof(ddsd);
4662 ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
4663 U5(ddsd).dwBackBufferCount = 1;
4664 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
4665 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
4666 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4667 IDirectDrawSurface7_Release(surface);
4669 /* Recover again, just to be sure. */
4670 activateapp_testdata.ddraw = NULL;
4671 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
4672 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4673 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
4674 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4676 DestroyWindow(window);
4677 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL));
4678 IDirectDraw7_Release(ddraw);
4681 static void test_texturemanage(void)
4683 IDirectDraw7 *ddraw;
4684 HRESULT hr;
4685 DDSURFACEDESC2 ddsd;
4686 IDirectDrawSurface7 *surface;
4687 unsigned int i;
4688 DDCAPS hal_caps, hel_caps;
4689 DWORD needed_caps = DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY;
4690 static const struct
4692 DWORD caps_in, caps2_in;
4693 HRESULT hr;
4694 DWORD caps_out, caps2_out;
4696 tests[] =
4698 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
4699 ~0U, ~0U},
4700 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, DDERR_INVALIDCAPS,
4701 ~0U, ~0U},
4702 {DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
4703 ~0U, ~0U},
4704 {DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, DDERR_INVALIDCAPS,
4705 ~0U, ~0U},
4706 {DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, DD_OK,
4707 DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE},
4708 {DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, DD_OK,
4709 DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE},
4710 {DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE, 0, DD_OK,
4711 DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE | DDSCAPS_LOCALVIDMEM, 0},
4712 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, 0, DD_OK,
4713 DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, 0},
4715 {0, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
4716 ~0U, ~0U},
4717 {0, DDSCAPS2_D3DTEXTUREMANAGE, DDERR_INVALIDCAPS,
4718 ~0U, ~0U},
4719 {DDSCAPS_SYSTEMMEMORY, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
4720 ~0U, ~0U},
4721 {DDSCAPS_SYSTEMMEMORY, DDSCAPS2_D3DTEXTUREMANAGE, DDERR_INVALIDCAPS,
4722 ~0U, ~0U},
4723 {DDSCAPS_VIDEOMEMORY, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
4724 ~0U, ~0U},
4725 {DDSCAPS_VIDEOMEMORY, DDSCAPS2_D3DTEXTUREMANAGE, DDERR_INVALIDCAPS,
4726 ~0U, ~0U},
4727 {DDSCAPS_VIDEOMEMORY, 0, DD_OK,
4728 DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY, 0},
4729 {DDSCAPS_SYSTEMMEMORY, 0, DD_OK,
4730 DDSCAPS_SYSTEMMEMORY, 0},
4733 ddraw = create_ddraw();
4734 ok(!!ddraw, "Failed to create a ddraw object.\n");
4735 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
4736 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4738 memset(&hal_caps, 0, sizeof(hal_caps));
4739 hal_caps.dwSize = sizeof(hal_caps);
4740 memset(&hel_caps, 0, sizeof(hel_caps));
4741 hel_caps.dwSize = sizeof(hel_caps);
4742 hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, &hel_caps);
4743 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
4744 if ((hal_caps.ddsCaps.dwCaps & needed_caps) != needed_caps)
4746 skip("Managed textures not supported, skipping managed texture test.\n");
4747 IDirectDraw7_Release(ddraw);
4748 return;
4751 for (i = 0; i < ARRAY_SIZE(tests); ++i)
4753 memset(&ddsd, 0, sizeof(ddsd));
4754 ddsd.dwSize = sizeof(ddsd);
4755 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
4756 ddsd.ddsCaps.dwCaps = tests[i].caps_in;
4757 ddsd.ddsCaps.dwCaps2 = tests[i].caps2_in;
4758 ddsd.dwWidth = 4;
4759 ddsd.dwHeight = 4;
4761 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
4762 if (tests[i].hr == DD_OK && is_ddraw64 && (tests[i].caps_in & DDSCAPS_TEXTURE))
4763 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Got unexpected hr %#x.\n", i, hr);
4764 else
4765 ok(hr == tests[i].hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, tests[i].hr);
4766 if (FAILED(hr))
4767 continue;
4769 memset(&ddsd, 0, sizeof(ddsd));
4770 ddsd.dwSize = sizeof(ddsd);
4771 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd);
4772 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
4774 ok(ddsd.ddsCaps.dwCaps == tests[i].caps_out,
4775 "Input caps %#x, %#x, expected output caps %#x, got %#x, case %u.\n",
4776 tests[i].caps_in, tests[i].caps2_in, tests[i].caps_out, ddsd.ddsCaps.dwCaps, i);
4777 ok(ddsd.ddsCaps.dwCaps2 == tests[i].caps2_out,
4778 "Input caps %#x, %#x, expected output caps %#x, got %#x, case %u.\n",
4779 tests[i].caps_in, tests[i].caps2_in, tests[i].caps2_out, ddsd.ddsCaps.dwCaps2, i);
4781 IDirectDrawSurface7_Release(surface);
4784 IDirectDraw7_Release(ddraw);
4787 #define SUPPORT_DXT1 0x01
4788 #define SUPPORT_DXT2 0x02
4789 #define SUPPORT_DXT3 0x04
4790 #define SUPPORT_DXT4 0x08
4791 #define SUPPORT_DXT5 0x10
4792 #define SUPPORT_YUY2 0x20
4793 #define SUPPORT_UYVY 0x40
4795 static HRESULT WINAPI test_block_formats_creation_cb(DDPIXELFORMAT *fmt, void *ctx)
4797 DWORD *supported_fmts = ctx;
4799 if (!(fmt->dwFlags & DDPF_FOURCC))
4800 return DDENUMRET_OK;
4802 switch (fmt->dwFourCC)
4804 case MAKEFOURCC('D','X','T','1'):
4805 *supported_fmts |= SUPPORT_DXT1;
4806 break;
4807 case MAKEFOURCC('D','X','T','2'):
4808 *supported_fmts |= SUPPORT_DXT2;
4809 break;
4810 case MAKEFOURCC('D','X','T','3'):
4811 *supported_fmts |= SUPPORT_DXT3;
4812 break;
4813 case MAKEFOURCC('D','X','T','4'):
4814 *supported_fmts |= SUPPORT_DXT4;
4815 break;
4816 case MAKEFOURCC('D','X','T','5'):
4817 *supported_fmts |= SUPPORT_DXT5;
4818 break;
4819 case MAKEFOURCC('Y','U','Y','2'):
4820 *supported_fmts |= SUPPORT_YUY2;
4821 break;
4822 case MAKEFOURCC('U','Y','V','Y'):
4823 *supported_fmts |= SUPPORT_UYVY;
4824 break;
4825 default:
4826 break;
4829 return DDENUMRET_OK;
4832 static void test_block_formats_creation(void)
4834 HRESULT hr, expect_hr;
4835 unsigned int i, j, w, h;
4836 HWND window;
4837 IDirectDraw7 *ddraw;
4838 IDirect3D7 *d3d;
4839 IDirect3DDevice7 *device;
4840 IDirectDrawSurface7 *surface;
4841 DWORD supported_fmts = 0, supported_overlay_fmts = 0;
4842 DWORD num_fourcc_codes = 0, *fourcc_codes;
4843 DDSURFACEDESC2 ddsd;
4844 DDCAPS hal_caps;
4845 void *mem;
4847 static const struct
4849 DWORD fourcc;
4850 const char *name;
4851 DWORD support_flag;
4852 unsigned int block_width;
4853 unsigned int block_height;
4854 unsigned int block_size;
4855 BOOL create_size_checked, overlay;
4857 formats[] =
4859 {MAKEFOURCC('D','X','T','1'), "D3DFMT_DXT1", SUPPORT_DXT1, 4, 4, 8, TRUE, FALSE},
4860 {MAKEFOURCC('D','X','T','2'), "D3DFMT_DXT2", SUPPORT_DXT2, 4, 4, 16, TRUE, FALSE},
4861 {MAKEFOURCC('D','X','T','3'), "D3DFMT_DXT3", SUPPORT_DXT3, 4, 4, 16, TRUE, FALSE},
4862 {MAKEFOURCC('D','X','T','4'), "D3DFMT_DXT4", SUPPORT_DXT4, 4, 4, 16, TRUE, FALSE},
4863 {MAKEFOURCC('D','X','T','5'), "D3DFMT_DXT5", SUPPORT_DXT5, 4, 4, 16, TRUE, FALSE},
4864 {MAKEFOURCC('Y','U','Y','2'), "D3DFMT_YUY2", SUPPORT_YUY2, 2, 1, 4, FALSE, TRUE },
4865 {MAKEFOURCC('U','Y','V','Y'), "D3DFMT_UYVY", SUPPORT_UYVY, 2, 1, 4, FALSE, TRUE },
4867 static const struct
4869 DWORD caps, caps2;
4870 const char *name;
4871 BOOL overlay;
4873 types[] =
4875 /* DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY fails to create any fourcc
4876 * surface with DDERR_INVALIDPIXELFORMAT. Don't care about it for now.
4878 * Nvidia returns E_FAIL on DXTN DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY.
4879 * Other hw / drivers successfully create those surfaces. Ignore them, this
4880 * suggests that no game uses this, otherwise Nvidia would support it. */
4882 DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE, 0,
4883 "videomemory texture", FALSE
4886 DDSCAPS_VIDEOMEMORY | DDSCAPS_OVERLAY, 0,
4887 "videomemory overlay", TRUE
4890 DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, 0,
4891 "systemmemory texture", FALSE
4894 DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE,
4895 "managed texture", FALSE
4898 enum size_type
4900 SIZE_TYPE_ZERO,
4901 SIZE_TYPE_PITCH,
4902 SIZE_TYPE_SIZE,
4904 static const struct
4906 DWORD flags;
4907 enum size_type size_type;
4908 int rel_size;
4909 HRESULT hr;
4911 user_mem_tests[] =
4913 {DDSD_LINEARSIZE, SIZE_TYPE_ZERO, 0, DD_OK},
4914 {DDSD_LINEARSIZE, SIZE_TYPE_SIZE, 0, DD_OK},
4915 {DDSD_PITCH, SIZE_TYPE_ZERO, 0, DD_OK},
4916 {DDSD_PITCH, SIZE_TYPE_PITCH, 0, DD_OK},
4917 {DDSD_LPSURFACE, SIZE_TYPE_ZERO, 0, DDERR_INVALIDPARAMS},
4918 {DDSD_LPSURFACE | DDSD_LINEARSIZE, SIZE_TYPE_ZERO, 0, DDERR_INVALIDPARAMS},
4919 {DDSD_LPSURFACE | DDSD_LINEARSIZE, SIZE_TYPE_PITCH, 0, DDERR_INVALIDPARAMS},
4920 {DDSD_LPSURFACE | DDSD_LINEARSIZE, SIZE_TYPE_SIZE, 0, DD_OK},
4921 {DDSD_LPSURFACE | DDSD_LINEARSIZE, SIZE_TYPE_SIZE, 1, DD_OK},
4922 {DDSD_LPSURFACE | DDSD_LINEARSIZE, SIZE_TYPE_SIZE, -1, DDERR_INVALIDPARAMS},
4923 {DDSD_LPSURFACE | DDSD_PITCH, SIZE_TYPE_ZERO, 0, DDERR_INVALIDPARAMS},
4924 {DDSD_LPSURFACE | DDSD_PITCH, SIZE_TYPE_PITCH, 0, DDERR_INVALIDPARAMS},
4925 {DDSD_LPSURFACE | DDSD_PITCH, SIZE_TYPE_SIZE, 0, DDERR_INVALIDPARAMS},
4926 {DDSD_LPSURFACE | DDSD_PITCH | DDSD_LINEARSIZE, SIZE_TYPE_SIZE, 0, DDERR_INVALIDPARAMS},
4929 window = create_window();
4930 if (!(device = create_device(window, DDSCL_NORMAL)))
4932 skip("Failed to create a 3D device, skipping test.\n");
4933 DestroyWindow(window);
4934 return;
4937 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
4938 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
4939 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **) &ddraw);
4940 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
4941 IDirect3D7_Release(d3d);
4943 hr = IDirect3DDevice7_EnumTextureFormats(device, test_block_formats_creation_cb,
4944 &supported_fmts);
4945 ok(SUCCEEDED(hr), "Failed to enumerate texture formats %#x.\n", hr);
4947 hr = IDirectDraw7_GetFourCCCodes(ddraw, &num_fourcc_codes, NULL);
4948 ok(SUCCEEDED(hr), "Failed to get fourcc codes %#x.\n", hr);
4949 fourcc_codes = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
4950 num_fourcc_codes * sizeof(*fourcc_codes));
4951 if (!fourcc_codes)
4952 goto cleanup;
4953 hr = IDirectDraw7_GetFourCCCodes(ddraw, &num_fourcc_codes, fourcc_codes);
4954 ok(SUCCEEDED(hr), "Failed to get fourcc codes %#x.\n", hr);
4955 for (i = 0; i < num_fourcc_codes; i++)
4957 for (j = 0; j < ARRAY_SIZE(formats); ++j)
4959 if (fourcc_codes[i] == formats[j].fourcc)
4960 supported_overlay_fmts |= formats[j].support_flag;
4963 HeapFree(GetProcessHeap(), 0, fourcc_codes);
4965 memset(&hal_caps, 0, sizeof(hal_caps));
4966 hal_caps.dwSize = sizeof(hal_caps);
4967 hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, NULL);
4968 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
4970 mem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 2 * 2 * 16 + 1);
4972 for (i = 0; i < ARRAY_SIZE(formats); ++i)
4974 for (j = 0; j < ARRAY_SIZE(types); ++j)
4976 BOOL support;
4978 if (formats[i].overlay != types[j].overlay
4979 || (types[j].overlay && !(hal_caps.dwCaps & DDCAPS_OVERLAY)))
4980 continue;
4982 if (formats[i].overlay)
4983 support = supported_overlay_fmts & formats[i].support_flag;
4984 else
4985 support = supported_fmts & formats[i].support_flag;
4987 for (w = 1; w <= 8; w++)
4989 for (h = 1; h <= 8; h++)
4991 BOOL block_aligned = TRUE;
4992 BOOL todo = FALSE;
4994 if (w & (formats[i].block_width - 1) || h & (formats[i].block_height - 1))
4995 block_aligned = FALSE;
4997 memset(&ddsd, 0, sizeof(ddsd));
4998 ddsd.dwSize = sizeof(ddsd);
4999 ddsd.dwFlags = DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
5000 ddsd.ddsCaps.dwCaps = types[j].caps;
5001 ddsd.ddsCaps.dwCaps2 = types[j].caps2;
5002 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
5003 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_FOURCC;
5004 U4(ddsd).ddpfPixelFormat.dwFourCC = formats[i].fourcc;
5005 ddsd.dwWidth = w;
5006 ddsd.dwHeight = h;
5008 /* TODO: Handle power of two limitations. I cannot test the pow2
5009 * behavior on windows because I have no hardware that doesn't at
5010 * least support np2_conditional. There's probably no HW that
5011 * supports DXTN textures but no conditional np2 textures. */
5012 if (!support && !(types[j].caps & DDSCAPS_SYSTEMMEMORY))
5013 expect_hr = DDERR_INVALIDPARAMS;
5014 else if (formats[i].create_size_checked && !block_aligned)
5016 expect_hr = DDERR_INVALIDPARAMS;
5017 if (!(types[j].caps & DDSCAPS_TEXTURE))
5018 todo = TRUE;
5020 else
5021 expect_hr = D3D_OK;
5023 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
5024 todo_wine_if (todo)
5025 ok(hr == expect_hr,
5026 "Got unexpected hr %#x for format %s, resource type %s, size %ux%u, expected %#x.\n",
5027 hr, formats[i].name, types[j].name, w, h, expect_hr);
5029 if (SUCCEEDED(hr))
5030 IDirectDrawSurface7_Release(surface);
5035 if (formats[i].overlay)
5036 continue;
5038 for (j = 0; j < ARRAY_SIZE(user_mem_tests); ++j)
5040 memset(&ddsd, 0, sizeof(ddsd));
5041 ddsd.dwSize = sizeof(ddsd);
5042 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | user_mem_tests[j].flags;
5043 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE;
5045 switch (user_mem_tests[j].size_type)
5047 case SIZE_TYPE_ZERO:
5048 U1(ddsd).dwLinearSize = 0;
5049 break;
5051 case SIZE_TYPE_PITCH:
5052 U1(ddsd).dwLinearSize = 2 * formats[i].block_size;
5053 break;
5055 case SIZE_TYPE_SIZE:
5056 U1(ddsd).dwLinearSize = 2 * 2 * formats[i].block_size;
5057 break;
5059 U1(ddsd).dwLinearSize += user_mem_tests[j].rel_size;
5061 ddsd.lpSurface = mem;
5062 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
5063 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_FOURCC;
5064 U4(ddsd).ddpfPixelFormat.dwFourCC = formats[i].fourcc;
5065 ddsd.dwWidth = 8;
5066 ddsd.dwHeight = 8;
5068 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
5069 ok(hr == user_mem_tests[j].hr, "Test %u: Got unexpected hr %#x, format %s.\n", j, hr, formats[i].name);
5071 if (FAILED(hr))
5072 continue;
5074 memset(&ddsd, 0, sizeof(ddsd));
5075 ddsd.dwSize = sizeof(ddsd);
5076 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd);
5077 ok(SUCCEEDED(hr), "Test %u: Failed to get surface desc, hr %#x.\n", j, hr);
5078 ok(ddsd.dwFlags == (DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_LINEARSIZE),
5079 "Test %u: Got unexpected flags %#x.\n", j, ddsd.dwFlags);
5080 if (user_mem_tests[j].flags & DDSD_LPSURFACE)
5081 ok(U1(ddsd).dwLinearSize == ~0u, "Test %u: Got unexpected linear size %#x.\n",
5082 j, U1(ddsd).dwLinearSize);
5083 else
5084 ok(U1(ddsd).dwLinearSize == 2 * 2 * formats[i].block_size,
5085 "Test %u: Got unexpected linear size %#x, expected %#x.\n",
5086 j, U1(ddsd).dwLinearSize, 2 * 2 * formats[i].block_size);
5087 IDirectDrawSurface7_Release(surface);
5091 HeapFree(GetProcessHeap(), 0, mem);
5092 cleanup:
5093 IDirectDraw7_Release(ddraw);
5094 IDirect3DDevice7_Release(device);
5095 DestroyWindow(window);
5098 struct format_support_check
5100 const DDPIXELFORMAT *format;
5101 BOOL supported;
5104 static HRESULT WINAPI test_unsupported_formats_cb(DDPIXELFORMAT *fmt, void *ctx)
5106 struct format_support_check *format = ctx;
5108 if (!memcmp(format->format, fmt, sizeof(*fmt)))
5110 format->supported = TRUE;
5111 return DDENUMRET_CANCEL;
5114 return DDENUMRET_OK;
5117 static void test_unsupported_formats(void)
5119 HRESULT hr;
5120 BOOL expect_success;
5121 HWND window;
5122 IDirectDraw7 *ddraw;
5123 IDirect3D7 *d3d;
5124 IDirect3DDevice7 *device;
5125 IDirectDrawSurface7 *surface;
5126 DDSURFACEDESC2 ddsd;
5127 unsigned int i, j;
5128 DWORD expected_caps;
5129 static const struct
5131 const char *name;
5132 DDPIXELFORMAT fmt;
5134 formats[] =
5137 "D3DFMT_A8R8G8B8",
5139 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
5140 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
5144 "D3DFMT_P8",
5146 sizeof(DDPIXELFORMAT), DDPF_PALETTEINDEXED8 | DDPF_RGB, 0,
5147 {8 }, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}
5151 static const DWORD caps[] = {0, DDSCAPS_SYSTEMMEMORY, DDSCAPS_VIDEOMEMORY};
5153 window = create_window();
5154 if (!(device = create_device(window, DDSCL_NORMAL)))
5156 skip("Failed to create a 3D device, skipping test.\n");
5157 DestroyWindow(window);
5158 return;
5161 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
5162 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
5163 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **) &ddraw);
5164 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
5165 IDirect3D7_Release(d3d);
5167 for (i = 0; i < ARRAY_SIZE(formats); ++i)
5169 struct format_support_check check = {&formats[i].fmt, FALSE};
5170 hr = IDirect3DDevice7_EnumTextureFormats(device, test_unsupported_formats_cb, &check);
5171 ok(SUCCEEDED(hr), "Failed to enumerate texture formats %#x.\n", hr);
5173 for (j = 0; j < ARRAY_SIZE(caps); ++j)
5175 memset(&ddsd, 0, sizeof(ddsd));
5176 ddsd.dwSize = sizeof(ddsd);
5177 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
5178 U4(ddsd).ddpfPixelFormat = formats[i].fmt;
5179 ddsd.dwWidth = 4;
5180 ddsd.dwHeight = 4;
5181 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | caps[j];
5183 if (caps[j] & DDSCAPS_VIDEOMEMORY && !check.supported)
5184 expect_success = FALSE;
5185 else
5186 expect_success = TRUE;
5188 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
5189 ok(SUCCEEDED(hr) == expect_success,
5190 "Got unexpected hr %#x for format %s, caps %#x, expected %s.\n",
5191 hr, formats[i].name, caps[j], expect_success ? "success" : "failure");
5192 if (FAILED(hr))
5193 continue;
5195 memset(&ddsd, 0, sizeof(ddsd));
5196 ddsd.dwSize = sizeof(ddsd);
5197 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd);
5198 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
5200 if (caps[j] & DDSCAPS_VIDEOMEMORY)
5201 expected_caps = DDSCAPS_VIDEOMEMORY;
5202 else if (caps[j] & DDSCAPS_SYSTEMMEMORY)
5203 expected_caps = DDSCAPS_SYSTEMMEMORY;
5204 else if (check.supported)
5205 expected_caps = DDSCAPS_VIDEOMEMORY;
5206 else
5207 expected_caps = DDSCAPS_SYSTEMMEMORY;
5209 ok(ddsd.ddsCaps.dwCaps & expected_caps,
5210 "Expected capability %#x, format %s, input cap %#x.\n",
5211 expected_caps, formats[i].name, caps[j]);
5213 IDirectDrawSurface7_Release(surface);
5217 IDirectDraw7_Release(ddraw);
5218 IDirect3DDevice7_Release(device);
5219 DestroyWindow(window);
5222 static void test_rt_caps(void)
5224 const GUID *devtype = &IID_IDirect3DHALDevice;
5225 PALETTEENTRY palette_entries[256];
5226 IDirectDrawPalette *palette;
5227 IDirectDraw7 *ddraw;
5228 BOOL hal_ok = FALSE;
5229 DDPIXELFORMAT z_fmt;
5230 IDirect3D7 *d3d;
5231 unsigned int i;
5232 ULONG refcount;
5233 HWND window;
5234 HRESULT hr;
5236 static const DDPIXELFORMAT p8_fmt =
5238 sizeof(DDPIXELFORMAT), DDPF_PALETTEINDEXED8 | DDPF_RGB, 0,
5239 {8}, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000},
5242 const struct
5244 const DDPIXELFORMAT *pf;
5245 DWORD caps_in;
5246 DWORD caps_out;
5247 HRESULT create_device_hr;
5248 HRESULT set_rt_hr, alternative_set_rt_hr;
5250 test_data[] =
5253 NULL,
5254 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY,
5255 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
5256 D3D_OK,
5257 D3D_OK,
5258 D3D_OK,
5261 NULL,
5262 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE,
5263 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
5264 D3D_OK,
5265 D3D_OK,
5266 D3D_OK,
5269 NULL,
5270 DDSCAPS_OFFSCREENPLAIN,
5271 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
5272 DDERR_INVALIDCAPS,
5273 DDERR_INVALIDCAPS,
5274 DDERR_INVALIDCAPS,
5277 NULL,
5278 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
5279 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
5280 D3DERR_SURFACENOTINVIDMEM,
5281 DDERR_INVALIDPARAMS,
5282 D3D_OK,
5285 NULL,
5286 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
5287 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
5288 DDERR_INVALIDCAPS,
5289 DDERR_INVALIDCAPS,
5290 DDERR_INVALIDCAPS,
5293 NULL,
5294 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY,
5295 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
5296 D3D_OK,
5297 D3D_OK,
5298 D3D_OK,
5301 NULL,
5302 DDSCAPS_3DDEVICE,
5303 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
5304 D3D_OK,
5305 D3D_OK,
5306 D3D_OK,
5309 NULL,
5311 DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
5312 DDERR_INVALIDCAPS,
5313 DDERR_INVALIDCAPS,
5314 DDERR_INVALIDCAPS,
5317 NULL,
5318 DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
5319 DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
5320 D3DERR_SURFACENOTINVIDMEM,
5321 DDERR_INVALIDPARAMS,
5322 D3D_OK,
5325 NULL,
5326 DDSCAPS_SYSTEMMEMORY,
5327 DDSCAPS_SYSTEMMEMORY,
5328 DDERR_INVALIDCAPS,
5329 DDERR_INVALIDCAPS,
5330 DDERR_INVALIDCAPS,
5333 &p8_fmt,
5335 DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
5336 DDERR_INVALIDCAPS,
5337 DDERR_INVALIDCAPS,
5338 DDERR_INVALIDCAPS,
5341 &p8_fmt,
5342 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE,
5343 ~0U /* AMD r200 */,
5344 DDERR_NOPALETTEATTACHED,
5345 DDERR_INVALIDCAPS,
5346 DDERR_INVALIDCAPS,
5349 &p8_fmt,
5350 DDSCAPS_OFFSCREENPLAIN,
5351 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
5352 DDERR_INVALIDCAPS,
5353 DDERR_INVALIDCAPS,
5354 DDERR_INVALIDCAPS,
5357 &p8_fmt,
5358 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
5359 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
5360 DDERR_NOPALETTEATTACHED,
5361 DDERR_INVALIDCAPS,
5362 DDERR_INVALIDCAPS,
5365 &p8_fmt,
5366 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
5367 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
5368 DDERR_INVALIDCAPS,
5369 DDERR_INVALIDCAPS,
5370 DDERR_INVALIDCAPS,
5373 &z_fmt,
5374 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_ZBUFFER,
5375 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_ZBUFFER | DDSCAPS_LOCALVIDMEM,
5376 DDERR_INVALIDCAPS,
5377 DDERR_INVALIDPIXELFORMAT,
5378 DDERR_INVALIDPIXELFORMAT,
5381 &z_fmt,
5382 DDSCAPS_3DDEVICE | DDSCAPS_ZBUFFER,
5383 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_ZBUFFER | DDSCAPS_LOCALVIDMEM,
5384 DDERR_INVALIDCAPS,
5385 DDERR_INVALIDPIXELFORMAT,
5386 DDERR_INVALIDPIXELFORMAT,
5389 &z_fmt,
5390 DDSCAPS_ZBUFFER,
5391 DDSCAPS_VIDEOMEMORY | DDSCAPS_ZBUFFER | DDSCAPS_LOCALVIDMEM,
5392 DDERR_INVALIDCAPS,
5393 DDERR_INVALIDCAPS,
5394 DDERR_INVALIDCAPS,
5397 &z_fmt,
5398 DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE | DDSCAPS_ZBUFFER,
5399 DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE | DDSCAPS_ZBUFFER,
5400 DDERR_INVALIDCAPS,
5401 DDERR_INVALIDPARAMS,
5402 DDERR_INVALIDPIXELFORMAT,
5405 &z_fmt,
5406 DDSCAPS_SYSTEMMEMORY | DDSCAPS_ZBUFFER,
5407 DDSCAPS_SYSTEMMEMORY | DDSCAPS_ZBUFFER,
5408 DDERR_INVALIDCAPS,
5409 DDERR_INVALIDCAPS,
5410 DDERR_INVALIDCAPS,
5414 window = create_window();
5415 ddraw = create_ddraw();
5416 ok(!!ddraw, "Failed to create a ddraw object.\n");
5417 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
5418 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5420 if (FAILED(IDirectDraw7_QueryInterface(ddraw, &IID_IDirect3D7, (void **)&d3d)))
5422 skip("D3D interface is not available, skipping test.\n");
5423 goto done;
5426 hr = IDirect3D7_EnumDevices(d3d, enum_devtype_cb, &hal_ok);
5427 ok(SUCCEEDED(hr), "Failed to enumerate devices, hr %#x.\n", hr);
5428 if (hal_ok)
5429 devtype = &IID_IDirect3DTnLHalDevice;
5431 memset(&z_fmt, 0, sizeof(z_fmt));
5432 hr = IDirect3D7_EnumZBufferFormats(d3d, devtype, enum_z_fmt, &z_fmt);
5433 if (FAILED(hr) || !z_fmt.dwSize)
5435 skip("No depth buffer formats available, skipping test.\n");
5436 IDirect3D7_Release(d3d);
5437 goto done;
5440 memset(palette_entries, 0, sizeof(palette_entries));
5441 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, palette_entries, &palette, NULL);
5442 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
5444 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
5446 IDirectDrawSurface7 *surface, *rt, *expected_rt, *tmp;
5447 DDSURFACEDESC2 surface_desc;
5448 IDirect3DDevice7 *device;
5450 memset(&surface_desc, 0, sizeof(surface_desc));
5451 surface_desc.dwSize = sizeof(surface_desc);
5452 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
5453 surface_desc.ddsCaps.dwCaps = test_data[i].caps_in;
5454 if (test_data[i].pf)
5456 surface_desc.dwFlags |= DDSD_PIXELFORMAT;
5457 U4(surface_desc).ddpfPixelFormat = *test_data[i].pf;
5459 surface_desc.dwWidth = 640;
5460 surface_desc.dwHeight = 480;
5461 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
5462 ok(SUCCEEDED(hr), "Test %u: Failed to create surface with caps %#x, hr %#x.\n",
5463 i, test_data[i].caps_in, hr);
5465 memset(&surface_desc, 0, sizeof(surface_desc));
5466 surface_desc.dwSize = sizeof(surface_desc);
5467 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &surface_desc);
5468 ok(SUCCEEDED(hr), "Test %u: Failed to get surface desc, hr %#x.\n", i, hr);
5469 ok(test_data[i].caps_out == ~0U || surface_desc.ddsCaps.dwCaps == test_data[i].caps_out,
5470 "Test %u: Got unexpected caps %#x, expected %#x.\n",
5471 i, surface_desc.ddsCaps.dwCaps, test_data[i].caps_out);
5473 hr = IDirect3D7_CreateDevice(d3d, devtype, surface, &device);
5474 ok(hr == test_data[i].create_device_hr, "Test %u: Got unexpected hr %#x, expected %#x.\n",
5475 i, hr, test_data[i].create_device_hr);
5476 if (FAILED(hr))
5478 if (hr == DDERR_NOPALETTEATTACHED)
5480 hr = IDirectDrawSurface7_SetPalette(surface, palette);
5481 ok(SUCCEEDED(hr), "Test %u: Failed to set palette, hr %#x.\n", i, hr);
5482 hr = IDirect3D7_CreateDevice(d3d, devtype, surface, &device);
5483 if (surface_desc.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY)
5484 ok(hr == DDERR_INVALIDPIXELFORMAT, "Test %u: Got unexpected hr %#x.\n", i, hr);
5485 else
5486 ok(hr == D3DERR_SURFACENOTINVIDMEM, "Test %u: Got unexpected hr %#x.\n", i, hr);
5488 IDirectDrawSurface7_Release(surface);
5490 memset(&surface_desc, 0, sizeof(surface_desc));
5491 surface_desc.dwSize = sizeof(surface_desc);
5492 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
5493 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
5494 surface_desc.dwWidth = 640;
5495 surface_desc.dwHeight = 480;
5496 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
5497 ok(SUCCEEDED(hr), "Test %u: Failed to create surface, hr %#x.\n", i, hr);
5499 hr = IDirect3D7_CreateDevice(d3d, devtype, surface, &device);
5500 ok(SUCCEEDED(hr), "Test %u: Failed to create device, hr %#x.\n", i, hr);
5503 memset(&surface_desc, 0, sizeof(surface_desc));
5504 surface_desc.dwSize = sizeof(surface_desc);
5505 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
5506 surface_desc.ddsCaps.dwCaps = test_data[i].caps_in;
5507 if (test_data[i].pf)
5509 surface_desc.dwFlags |= DDSD_PIXELFORMAT;
5510 U4(surface_desc).ddpfPixelFormat = *test_data[i].pf;
5512 surface_desc.dwWidth = 640;
5513 surface_desc.dwHeight = 480;
5514 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &rt, NULL);
5515 ok(SUCCEEDED(hr), "Test %u: Failed to create surface with caps %#x, hr %#x.\n",
5516 i, test_data[i].caps_in, hr);
5518 hr = IDirect3DDevice7_SetRenderTarget(device, rt, 0);
5519 ok(hr == test_data[i].set_rt_hr || broken(hr == test_data[i].alternative_set_rt_hr),
5520 "Test %u: Got unexpected hr %#x, expected %#x.\n",
5521 i, hr, test_data[i].set_rt_hr);
5522 if (SUCCEEDED(hr) || hr == DDERR_INVALIDPIXELFORMAT)
5523 expected_rt = rt;
5524 else
5525 expected_rt = surface;
5527 hr = IDirect3DDevice7_GetRenderTarget(device, &tmp);
5528 ok(SUCCEEDED(hr), "Test %u: Failed to get render target, hr %#x.\n", i, hr);
5529 ok(tmp == expected_rt, "Test %u: Got unexpected rt %p.\n", i, tmp);
5531 IDirectDrawSurface7_Release(tmp);
5532 IDirectDrawSurface7_Release(rt);
5533 refcount = IDirect3DDevice7_Release(device);
5534 ok(refcount == 0, "Test %u: The device was not properly freed, refcount %u.\n", i, refcount);
5535 refcount = IDirectDrawSurface7_Release(surface);
5536 ok(refcount == 0, "Test %u: The surface was not properly freed, refcount %u.\n", i, refcount);
5539 IDirectDrawPalette_Release(palette);
5540 IDirect3D7_Release(d3d);
5542 done:
5543 refcount = IDirectDraw7_Release(ddraw);
5544 ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount);
5545 DestroyWindow(window);
5548 static void test_primary_caps(void)
5550 const DWORD placement = DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY | DDSCAPS_SYSTEMMEMORY;
5551 IDirectDrawSurface7 *surface;
5552 DDSURFACEDESC2 surface_desc;
5553 IDirectDraw7 *ddraw;
5554 unsigned int i;
5555 ULONG refcount;
5556 HWND window;
5557 HRESULT hr;
5559 static const struct
5561 DWORD coop_level;
5562 DWORD caps_in;
5563 DWORD back_buffer_count;
5564 HRESULT hr;
5565 DWORD caps_out;
5567 test_data[] =
5570 DDSCL_NORMAL,
5571 DDSCAPS_PRIMARYSURFACE,
5572 ~0u,
5573 DD_OK,
5574 DDSCAPS_VISIBLE | DDSCAPS_PRIMARYSURFACE,
5577 DDSCL_NORMAL,
5578 DDSCAPS_PRIMARYSURFACE | DDSCAPS_TEXTURE,
5579 ~0u,
5580 DDERR_INVALIDCAPS,
5581 ~0u,
5584 DDSCL_NORMAL,
5585 DDSCAPS_PRIMARYSURFACE | DDSCAPS_FRONTBUFFER,
5586 ~0u,
5587 DDERR_INVALIDCAPS,
5588 ~0u,
5591 DDSCL_NORMAL,
5592 DDSCAPS_PRIMARYSURFACE | DDSCAPS_BACKBUFFER,
5593 ~0u,
5594 DDERR_INVALIDCAPS,
5595 ~0u,
5598 DDSCL_NORMAL,
5599 DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP,
5600 ~0u,
5601 DDERR_INVALIDCAPS,
5602 ~0u,
5605 DDSCL_NORMAL,
5606 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX,
5607 ~0u,
5608 DDERR_INVALIDCAPS,
5609 ~0u,
5612 DDSCL_NORMAL,
5613 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
5614 ~0u,
5615 DDERR_INVALIDCAPS,
5616 ~0u,
5619 DDSCL_NORMAL,
5620 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
5622 DDERR_INVALIDCAPS,
5623 ~0u,
5626 DDSCL_NORMAL,
5627 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
5629 DDERR_NOEXCLUSIVEMODE,
5630 ~0u,
5633 DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN,
5634 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
5636 DDERR_INVALIDCAPS,
5637 ~0u,
5640 DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN,
5641 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
5643 DD_OK,
5644 DDSCAPS_VISIBLE | DDSCAPS_PRIMARYSURFACE | DDSCAPS_FRONTBUFFER | DDSCAPS_FLIP | DDSCAPS_COMPLEX,
5647 DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN,
5648 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP | DDSCAPS_FRONTBUFFER,
5650 DDERR_INVALIDCAPS,
5651 ~0u,
5654 DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN,
5655 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP | DDSCAPS_BACKBUFFER,
5657 DDERR_INVALIDCAPS,
5658 ~0u,
5662 window = create_window();
5663 ddraw = create_ddraw();
5664 ok(!!ddraw, "Failed to create a ddraw object.\n");
5666 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
5668 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, test_data[i].coop_level);
5669 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5671 memset(&surface_desc, 0, sizeof(surface_desc));
5672 surface_desc.dwSize = sizeof(surface_desc);
5673 surface_desc.dwFlags = DDSD_CAPS;
5674 if (test_data[i].back_buffer_count != ~0u)
5675 surface_desc.dwFlags |= DDSD_BACKBUFFERCOUNT;
5676 surface_desc.ddsCaps.dwCaps = test_data[i].caps_in;
5677 U5(surface_desc).dwBackBufferCount = test_data[i].back_buffer_count;
5678 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
5679 ok(hr == test_data[i].hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, test_data[i].hr);
5680 if (FAILED(hr))
5681 continue;
5683 memset(&surface_desc, 0, sizeof(surface_desc));
5684 surface_desc.dwSize = sizeof(surface_desc);
5685 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &surface_desc);
5686 ok(SUCCEEDED(hr), "Test %u: Failed to get surface desc, hr %#x.\n", i, hr);
5687 ok((surface_desc.ddsCaps.dwCaps & ~placement) == test_data[i].caps_out,
5688 "Test %u: Got unexpected caps %#x, expected %#x.\n",
5689 i, surface_desc.ddsCaps.dwCaps, test_data[i].caps_out);
5691 IDirectDrawSurface7_Release(surface);
5694 refcount = IDirectDraw7_Release(ddraw);
5695 ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount);
5696 DestroyWindow(window);
5699 static void test_surface_lock(void)
5701 IDirectDraw7 *ddraw;
5702 IDirect3D7 *d3d = NULL;
5703 IDirectDrawSurface7 *surface;
5704 IDirect3DDevice7 *device;
5705 HRESULT hr, expected_hr;
5706 HWND window;
5707 unsigned int i;
5708 DDSURFACEDESC2 ddsd;
5709 ULONG refcount;
5710 DDPIXELFORMAT z_fmt;
5711 BOOL hal_ok = FALSE;
5712 const GUID *devtype = &IID_IDirect3DHALDevice;
5713 D3DDEVICEDESC7 device_desc;
5714 BOOL cubemap_supported;
5715 static const struct
5717 DWORD caps;
5718 DWORD caps2;
5719 const char *name;
5721 tests[] =
5724 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY,
5726 "videomemory offscreenplain"
5729 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
5731 "systemmemory offscreenplain"
5734 DDSCAPS_PRIMARYSURFACE,
5736 "primary"
5739 DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY,
5741 "videomemory texture"
5744 DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY,
5745 DDSCAPS2_OPAQUE,
5746 "opaque videomemory texture"
5749 DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY,
5751 "systemmemory texture"
5754 DDSCAPS_TEXTURE,
5755 DDSCAPS2_TEXTUREMANAGE,
5756 "managed texture"
5759 DDSCAPS_TEXTURE,
5760 DDSCAPS2_D3DTEXTUREMANAGE,
5761 "managed texture"
5764 DDSCAPS_TEXTURE,
5765 DDSCAPS2_TEXTUREMANAGE | DDSCAPS2_OPAQUE,
5766 "opaque managed texture"
5769 DDSCAPS_TEXTURE,
5770 DDSCAPS2_D3DTEXTUREMANAGE | DDSCAPS2_OPAQUE,
5771 "opaque managed texture"
5774 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE,
5776 "render target"
5779 DDSCAPS_ZBUFFER,
5781 "Z buffer"
5784 DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_VIDEOMEMORY,
5785 DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES,
5786 "videomemory cube"
5789 DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_VIDEOMEMORY,
5790 DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES | DDSCAPS2_OPAQUE,
5791 "opaque videomemory cube"
5794 DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_SYSTEMMEMORY,
5795 DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES,
5796 "systemmemory cube"
5799 DDSCAPS_TEXTURE | DDSCAPS_COMPLEX,
5800 DDSCAPS2_TEXTUREMANAGE | DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES,
5801 "managed cube"
5804 DDSCAPS_TEXTURE | DDSCAPS_COMPLEX,
5805 DDSCAPS2_D3DTEXTUREMANAGE | DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES,
5806 "managed cube"
5809 DDSCAPS_TEXTURE | DDSCAPS_COMPLEX,
5810 DDSCAPS2_TEXTUREMANAGE | DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES | DDSCAPS2_OPAQUE,
5811 "opaque managed cube"
5814 DDSCAPS_TEXTURE | DDSCAPS_COMPLEX,
5815 DDSCAPS2_D3DTEXTUREMANAGE | DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES | DDSCAPS2_OPAQUE,
5816 "opaque managed cube"
5820 window = create_window();
5821 ddraw = create_ddraw();
5822 ok(!!ddraw, "Failed to create a ddraw object.\n");
5823 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
5824 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5826 if (FAILED(IDirectDraw7_QueryInterface(ddraw, &IID_IDirect3D7, (void **)&d3d)))
5828 skip("D3D interface is not available, skipping test.\n");
5829 goto done;
5832 hr = IDirect3D7_EnumDevices(d3d, enum_devtype_cb, &hal_ok);
5833 ok(SUCCEEDED(hr), "Failed to enumerate devices, hr %#x.\n", hr);
5834 if (hal_ok)
5835 devtype = &IID_IDirect3DTnLHalDevice;
5837 memset(&z_fmt, 0, sizeof(z_fmt));
5838 hr = IDirect3D7_EnumZBufferFormats(d3d, devtype, enum_z_fmt, &z_fmt);
5839 if (FAILED(hr) || !z_fmt.dwSize)
5841 skip("No depth buffer formats available, skipping test.\n");
5842 goto done;
5845 memset(&ddsd, 0, sizeof(ddsd));
5846 ddsd.dwSize = sizeof(ddsd);
5847 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
5848 ddsd.dwWidth = 64;
5849 ddsd.dwHeight = 64;
5850 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
5851 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
5852 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5854 hr = IDirect3D7_CreateDevice(d3d, devtype, surface, &device);
5855 ok(SUCCEEDED(hr), "Failed to create device, hr %#x.\n", hr);
5856 hr = IDirect3DDevice7_GetCaps(device, &device_desc);
5857 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
5858 cubemap_supported = !!(device_desc.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_CUBEMAP);
5859 IDirect3DDevice7_Release(device);
5861 IDirectDrawSurface7_Release(surface);
5863 for (i = 0; i < ARRAY_SIZE(tests); ++i)
5865 if (!cubemap_supported && tests[i].caps2 & DDSCAPS2_CUBEMAP)
5866 continue;
5868 memset(&ddsd, 0, sizeof(ddsd));
5869 ddsd.dwSize = sizeof(ddsd);
5870 ddsd.dwFlags = DDSD_CAPS;
5871 if (!(tests[i].caps & DDSCAPS_PRIMARYSURFACE))
5873 ddsd.dwFlags |= DDSD_WIDTH | DDSD_HEIGHT;
5874 ddsd.dwWidth = 64;
5875 ddsd.dwHeight = 64;
5877 if (tests[i].caps & DDSCAPS_ZBUFFER)
5879 ddsd.dwFlags |= DDSD_PIXELFORMAT;
5880 U4(ddsd).ddpfPixelFormat = z_fmt;
5882 ddsd.ddsCaps.dwCaps = tests[i].caps;
5883 ddsd.ddsCaps.dwCaps2 = tests[i].caps2;
5885 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
5886 ok(SUCCEEDED(hr), "Failed to create surface, type %s, hr %#x.\n", tests[i].name, hr);
5888 memset(&ddsd, 0, sizeof(ddsd));
5889 ddsd.dwSize = sizeof(ddsd);
5890 hr = IDirectDrawSurface7_Lock(surface, NULL, &ddsd, DDLOCK_WAIT, NULL);
5891 ok(SUCCEEDED(hr), "Failed to lock surface, type %s, hr %#x.\n", tests[i].name, hr);
5892 if (SUCCEEDED(hr))
5894 ok(ddsd.dwSize == sizeof(ddsd), "Got unexpected dwSize %u, type %s.\n", ddsd.dwSize, tests[i].name);
5895 hr = IDirectDrawSurface7_Unlock(surface, NULL);
5896 ok(SUCCEEDED(hr), "Failed to unlock surface, type %s, hr %#x.\n", tests[i].name, hr);
5899 memset(&ddsd, 0, sizeof(ddsd));
5900 expected_hr = tests[i].caps & DDSCAPS_TEXTURE && !(tests[i].caps & DDSCAPS_VIDEOMEMORY)
5901 ? DD_OK : DDERR_INVALIDPARAMS;
5902 hr = IDirectDrawSurface7_Lock(surface, NULL, &ddsd, DDLOCK_WAIT, NULL);
5903 ok(hr == expected_hr, "Got hr %#x, expected %#x, type %s.\n", hr, expected_hr, tests[i].name);
5904 if (SUCCEEDED(hr))
5906 ok(!ddsd.dwSize, "Got unexpected dwSize %u, type %s.\n", ddsd.dwSize, tests[i].name);
5907 ok(!!ddsd.lpSurface, "Got NULL lpSurface, type %s.\n", tests[i].name);
5908 hr = IDirectDrawSurface7_Unlock(surface, NULL);
5909 ok(SUCCEEDED(hr), "Failed to unlock surface, type %s, hr %#x.\n", tests[i].name, hr);
5912 IDirectDrawSurface7_Release(surface);
5915 done:
5916 if (d3d)
5917 IDirect3D7_Release(d3d);
5918 refcount = IDirectDraw7_Release(ddraw);
5919 ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount);
5920 DestroyWindow(window);
5923 static void test_surface_discard(void)
5925 IDirect3DDevice7 *device;
5926 IDirect3D7 *d3d;
5927 IDirectDraw7 *ddraw;
5928 HRESULT hr;
5929 HWND window;
5930 DDSURFACEDESC2 ddsd;
5931 IDirectDrawSurface7 *surface, *target;
5932 void *addr;
5933 static const struct
5935 DWORD caps, caps2;
5936 BOOL discard;
5938 tests[] =
5940 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0, TRUE},
5941 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY, 0, FALSE},
5942 {DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, 0, TRUE},
5943 {DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, 0, FALSE},
5944 {DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, FALSE},
5945 {DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE | DDSCAPS2_HINTDYNAMIC, FALSE},
5946 {DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, FALSE},
5947 {DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE | DDSCAPS2_HINTDYNAMIC, FALSE},
5949 unsigned int i;
5951 window = create_window();
5952 if (!(device = create_device(window, DDSCL_NORMAL)))
5954 skip("Failed to create a 3D device, skipping test.\n");
5955 DestroyWindow(window);
5956 return;
5958 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
5959 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
5960 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
5961 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
5962 hr = IDirect3DDevice7_GetRenderTarget(device, &target);
5963 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
5965 for (i = 0; i < ARRAY_SIZE(tests); ++i)
5967 BOOL discarded;
5969 memset(&ddsd, 0, sizeof(ddsd));
5970 ddsd.dwSize = sizeof(ddsd);
5971 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
5972 ddsd.ddsCaps.dwCaps = tests[i].caps;
5973 ddsd.ddsCaps.dwCaps2 = tests[i].caps2;
5974 ddsd.dwWidth = 64;
5975 ddsd.dwHeight = 64;
5976 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
5977 ok(SUCCEEDED(hr), "Failed to create offscreen surface, hr %#x, case %u.\n", hr, i);
5979 memset(&ddsd, 0, sizeof(ddsd));
5980 ddsd.dwSize = sizeof(ddsd);
5981 hr = IDirectDrawSurface7_Lock(surface, NULL, &ddsd, 0, NULL);
5982 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
5983 addr = ddsd.lpSurface;
5984 hr = IDirectDrawSurface7_Unlock(surface, NULL);
5985 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
5987 memset(&ddsd, 0, sizeof(ddsd));
5988 ddsd.dwSize = sizeof(ddsd);
5989 hr = IDirectDrawSurface7_Lock(surface, NULL, &ddsd, DDLOCK_DISCARDCONTENTS, NULL);
5990 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
5991 discarded = ddsd.lpSurface != addr;
5992 hr = IDirectDrawSurface7_Unlock(surface, NULL);
5993 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
5995 hr = IDirectDrawSurface7_Blt(target, NULL, surface, NULL, DDBLT_WAIT, NULL);
5996 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
5998 memset(&ddsd, 0, sizeof(ddsd));
5999 ddsd.dwSize = sizeof(ddsd);
6000 hr = IDirectDrawSurface7_Lock(surface, NULL, &ddsd, DDLOCK_DISCARDCONTENTS, NULL);
6001 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
6002 discarded |= ddsd.lpSurface != addr;
6003 hr = IDirectDrawSurface7_Unlock(surface, NULL);
6004 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
6006 IDirectDrawSurface7_Release(surface);
6008 /* Windows 7 reliably changes the address of surfaces that are discardable (Nvidia Kepler,
6009 * AMD r500, evergreen). Windows XP, at least on AMD r200, does not. */
6010 ok(!discarded || tests[i].discard, "Expected surface not to be discarded, case %u\n", i);
6013 IDirectDrawSurface7_Release(target);
6014 IDirectDraw7_Release(ddraw);
6015 IDirect3D7_Release(d3d);
6016 IDirect3DDevice7_Release(device);
6017 DestroyWindow(window);
6020 static void fill_surface(IDirectDrawSurface7 *surface, D3DCOLOR color)
6022 DDSURFACEDESC2 surface_desc = {sizeof(surface_desc)};
6023 HRESULT hr;
6024 unsigned int x, y;
6025 DWORD *ptr;
6027 hr = IDirectDrawSurface7_Lock(surface, NULL, &surface_desc, DDLOCK_WAIT, NULL);
6028 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
6030 for (y = 0; y < surface_desc.dwHeight; ++y)
6032 ptr = (DWORD *)((BYTE *)surface_desc.lpSurface + y * surface_desc.lPitch);
6033 for (x = 0; x < surface_desc.dwWidth; ++x)
6035 ptr[x] = color;
6039 hr = IDirectDrawSurface7_Unlock(surface, NULL);
6040 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
6043 static void test_flip(void)
6045 const DWORD placement = DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY | DDSCAPS_SYSTEMMEMORY;
6046 IDirectDrawSurface7 *frontbuffer, *backbuffer1, *backbuffer2, *backbuffer3, *surface;
6047 DDSCAPS2 caps = {DDSCAPS_FLIP, 0, 0, {0}};
6048 DDSURFACEDESC2 surface_desc;
6049 D3DDEVICEDESC7 device_desc;
6050 IDirect3DDevice7 *device;
6051 BOOL sysmem_primary;
6052 IDirectDraw7 *ddraw;
6053 DWORD expected_caps;
6054 unsigned int i;
6055 D3DCOLOR color;
6056 ULONG refcount;
6057 HWND window;
6058 HRESULT hr;
6060 static const struct
6062 const char *name;
6063 DWORD caps;
6065 test_data[] =
6067 {"PRIMARYSURFACE", DDSCAPS_PRIMARYSURFACE},
6068 {"OFFSCREENPLAIN", DDSCAPS_OFFSCREENPLAIN},
6069 {"TEXTURE", DDSCAPS_TEXTURE},
6072 window = create_window();
6073 ddraw = create_ddraw();
6074 ok(!!ddraw, "Failed to create a ddraw object.\n");
6076 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
6077 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6079 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
6081 /* Creating a flippable texture induces a BSoD on some versions of the
6082 * Intel graphics driver. At least Intel GMA 950 with driver version
6083 * 6.14.10.4926 on Windows XP SP3 is affected. */
6084 if ((test_data[i].caps & DDSCAPS_TEXTURE) && ddraw_is_intel(ddraw))
6086 win_skip("Skipping flippable texture test.\n");
6087 continue;
6090 memset(&surface_desc, 0, sizeof(surface_desc));
6091 surface_desc.dwSize = sizeof(surface_desc);
6092 surface_desc.dwFlags = DDSD_CAPS;
6093 if (!(test_data[i].caps & DDSCAPS_PRIMARYSURFACE))
6094 surface_desc.dwFlags |= DDSD_WIDTH | DDSD_HEIGHT;
6095 surface_desc.ddsCaps.dwCaps = DDSCAPS_COMPLEX | DDSCAPS_FLIP | test_data[i].caps;
6096 surface_desc.dwWidth = 512;
6097 surface_desc.dwHeight = 512;
6098 U5(surface_desc).dwBackBufferCount = 3;
6099 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &frontbuffer, NULL);
6100 ok(hr == DDERR_INVALIDCAPS, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
6102 surface_desc.ddsCaps.dwCaps &= ~DDSCAPS_FLIP;
6103 surface_desc.dwFlags |= DDSD_BACKBUFFERCOUNT;
6104 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &frontbuffer, NULL);
6105 ok(hr == DDERR_INVALIDCAPS, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
6107 surface_desc.ddsCaps.dwCaps &= ~DDSCAPS_COMPLEX;
6108 surface_desc.ddsCaps.dwCaps |= DDSCAPS_FLIP;
6109 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &frontbuffer, NULL);
6110 ok(hr == DDERR_INVALIDCAPS, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
6112 surface_desc.ddsCaps.dwCaps |= DDSCAPS_COMPLEX;
6113 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &frontbuffer, NULL);
6114 if (is_ddraw64 && test_data[i].caps & DDSCAPS_TEXTURE)
6115 todo_wine ok(hr == E_NOINTERFACE, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
6116 else todo_wine_if(test_data[i].caps & DDSCAPS_TEXTURE)
6117 ok(SUCCEEDED(hr), "%s: Failed to create surface, hr %#x.\n", test_data[i].name, hr);
6118 if (FAILED(hr))
6119 continue;
6121 memset(&surface_desc, 0, sizeof(surface_desc));
6122 surface_desc.dwSize = sizeof(surface_desc);
6123 hr = IDirectDrawSurface7_GetSurfaceDesc(frontbuffer, &surface_desc);
6124 ok(SUCCEEDED(hr), "%s: Failed to get surface desc, hr %#x.\n", test_data[i].name, hr);
6125 expected_caps = DDSCAPS_FRONTBUFFER | DDSCAPS_COMPLEX | DDSCAPS_FLIP | test_data[i].caps;
6126 if (test_data[i].caps & DDSCAPS_PRIMARYSURFACE)
6127 expected_caps |= DDSCAPS_VISIBLE;
6128 ok((surface_desc.ddsCaps.dwCaps & ~placement) == expected_caps,
6129 "%s: Got unexpected caps %#x.\n", test_data[i].name, surface_desc.ddsCaps.dwCaps);
6130 sysmem_primary = surface_desc.ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY;
6132 hr = IDirectDrawSurface7_GetAttachedSurface(frontbuffer, &caps, &backbuffer1);
6133 ok(SUCCEEDED(hr), "%s: Failed to get attached surface, hr %#x.\n", test_data[i].name, hr);
6134 memset(&surface_desc, 0, sizeof(surface_desc));
6135 surface_desc.dwSize = sizeof(surface_desc);
6136 hr = IDirectDrawSurface7_GetSurfaceDesc(backbuffer1, &surface_desc);
6137 ok(SUCCEEDED(hr), "%s: Failed to get surface desc, hr %#x.\n", test_data[i].name, hr);
6138 ok(!U5(surface_desc).dwBackBufferCount, "%s: Got unexpected back buffer count %u.\n",
6139 test_data[i].name, U5(surface_desc).dwBackBufferCount);
6140 expected_caps &= ~(DDSCAPS_VISIBLE | DDSCAPS_PRIMARYSURFACE | DDSCAPS_FRONTBUFFER);
6141 expected_caps |= DDSCAPS_BACKBUFFER;
6142 ok((surface_desc.ddsCaps.dwCaps & ~placement) == expected_caps,
6143 "%s: Got unexpected caps %#x.\n", test_data[i].name, surface_desc.ddsCaps.dwCaps);
6145 hr = IDirectDrawSurface7_GetAttachedSurface(backbuffer1, &caps, &backbuffer2);
6146 ok(SUCCEEDED(hr), "%s: Failed to get attached surface, hr %#x.\n", test_data[i].name, hr);
6147 memset(&surface_desc, 0, sizeof(surface_desc));
6148 surface_desc.dwSize = sizeof(surface_desc);
6149 hr = IDirectDrawSurface7_GetSurfaceDesc(backbuffer2, &surface_desc);
6150 ok(SUCCEEDED(hr), "%s: Failed to get surface desc, hr %#x.\n", test_data[i].name, hr);
6151 ok(!U5(surface_desc).dwBackBufferCount, "%s: Got unexpected back buffer count %u.\n",
6152 test_data[i].name, U5(surface_desc).dwBackBufferCount);
6153 expected_caps &= ~DDSCAPS_BACKBUFFER;
6154 ok((surface_desc.ddsCaps.dwCaps & ~placement) == expected_caps,
6155 "%s: Got unexpected caps %#x.\n", test_data[i].name, surface_desc.ddsCaps.dwCaps);
6157 hr = IDirectDrawSurface7_GetAttachedSurface(backbuffer2, &caps, &backbuffer3);
6158 ok(SUCCEEDED(hr), "%s: Failed to get attached surface, hr %#x.\n", test_data[i].name, hr);
6159 memset(&surface_desc, 0, sizeof(surface_desc));
6160 surface_desc.dwSize = sizeof(surface_desc);
6161 hr = IDirectDrawSurface7_GetSurfaceDesc(backbuffer3, &surface_desc);
6162 ok(SUCCEEDED(hr), "%s: Failed to get surface desc, hr %#x.\n", test_data[i].name, hr);
6163 ok(!U5(surface_desc).dwBackBufferCount, "%s: Got unexpected back buffer count %u.\n",
6164 test_data[i].name, U5(surface_desc).dwBackBufferCount);
6165 ok((surface_desc.ddsCaps.dwCaps & ~placement) == expected_caps,
6166 "%s: Got unexpected caps %#x.\n", test_data[i].name, surface_desc.ddsCaps.dwCaps);
6168 hr = IDirectDrawSurface7_GetAttachedSurface(backbuffer3, &caps, &surface);
6169 ok(SUCCEEDED(hr), "%s: Failed to get attached surface, hr %#x.\n", test_data[i].name, hr);
6170 ok(surface == frontbuffer, "%s: Got unexpected surface %p, expected %p.\n",
6171 test_data[i].name, surface, frontbuffer);
6172 IDirectDrawSurface7_Release(surface);
6174 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL | DDSCL_FULLSCREEN);
6175 ok(SUCCEEDED(hr), "%s: Failed to set cooperative level, hr %#x.\n", test_data[i].name, hr);
6176 hr = IDirectDrawSurface7_IsLost(frontbuffer);
6177 ok(hr == DD_OK, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
6178 hr = IDirectDrawSurface7_Flip(frontbuffer, NULL, DDFLIP_WAIT);
6179 if (test_data[i].caps & DDSCAPS_PRIMARYSURFACE)
6180 ok(hr == DDERR_NOEXCLUSIVEMODE, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
6181 else
6182 ok(SUCCEEDED(hr), "%s: Failed to flip, hr %#x.\n", test_data[i].name, hr);
6183 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
6184 ok(SUCCEEDED(hr), "%s: Failed to set cooperative level, hr %#x.\n", test_data[i].name, hr);
6185 hr = IDirectDrawSurface7_IsLost(frontbuffer);
6186 todo_wine ok(hr == DDERR_SURFACELOST, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
6187 hr = IDirectDraw7_RestoreAllSurfaces(ddraw);
6188 ok(SUCCEEDED(hr), "%s: Failed to restore surfaces, hr %#x.\n", test_data[i].name, hr);
6190 memset(&surface_desc, 0, sizeof(surface_desc));
6191 surface_desc.dwSize = sizeof(surface_desc);
6192 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
6193 surface_desc.ddsCaps.dwCaps = 0;
6194 surface_desc.dwWidth = 640;
6195 surface_desc.dwHeight = 480;
6196 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
6197 ok(SUCCEEDED(hr), "%s: Failed to create surface, hr %#x.\n", test_data[i].name, hr);
6198 hr = IDirectDrawSurface7_Flip(frontbuffer, surface, DDFLIP_WAIT);
6199 ok(hr == DDERR_NOTFLIPPABLE, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
6200 IDirectDrawSurface7_Release(surface);
6202 hr = IDirectDrawSurface7_Flip(frontbuffer, frontbuffer, DDFLIP_WAIT);
6203 ok(hr == DDERR_NOTFLIPPABLE, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
6204 hr = IDirectDrawSurface7_Flip(backbuffer1, NULL, DDFLIP_WAIT);
6205 ok(hr == DDERR_NOTFLIPPABLE, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
6206 hr = IDirectDrawSurface7_Flip(backbuffer2, NULL, DDFLIP_WAIT);
6207 ok(hr == DDERR_NOTFLIPPABLE, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
6208 hr = IDirectDrawSurface7_Flip(backbuffer3, NULL, DDFLIP_WAIT);
6209 ok(hr == DDERR_NOTFLIPPABLE, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
6211 /* The Nvidia Geforce 7 driver cannot do a color fill on a texture backbuffer after
6212 * the backbuffer has been locked. Do it ourselves as a workaround. Unlike ddraw1
6213 * and 2 GetSurfaceDesc does not cause issues in ddraw4 and ddraw7. */
6214 fill_surface(backbuffer1, 0xffff0000);
6215 fill_surface(backbuffer2, 0xff00ff00);
6216 fill_surface(backbuffer3, 0xff0000ff);
6218 hr = IDirectDrawSurface7_Flip(frontbuffer, NULL, DDFLIP_WAIT);
6219 ok(SUCCEEDED(hr), "%s: Failed to flip, hr %#x.\n", test_data[i].name, hr);
6220 color = get_surface_color(backbuffer1, 320, 240);
6221 /* The testbot seems to just copy the contents of one surface to all the
6222 * others, instead of properly flipping. */
6223 ok(compare_color(color, 0x0000ff00, 1) || broken(sysmem_primary && compare_color(color, 0x000000ff, 1)),
6224 "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
6225 color = get_surface_color(backbuffer2, 320, 240);
6226 ok(compare_color(color, 0x000000ff, 1), "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
6227 fill_surface(backbuffer3, 0xffff0000);
6229 hr = IDirectDrawSurface7_Flip(frontbuffer, NULL, DDFLIP_WAIT);
6230 ok(SUCCEEDED(hr), "%s: Failed to flip, hr %#x.\n", test_data[i].name, hr);
6231 color = get_surface_color(backbuffer1, 320, 240);
6232 ok(compare_color(color, 0x000000ff, 1) || broken(sysmem_primary && compare_color(color, 0x00ff0000, 1)),
6233 "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
6234 color = get_surface_color(backbuffer2, 320, 240);
6235 ok(compare_color(color, 0x00ff0000, 1), "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
6236 fill_surface(backbuffer3, 0xff00ff00);
6238 hr = IDirectDrawSurface7_Flip(frontbuffer, NULL, DDFLIP_WAIT);
6239 ok(SUCCEEDED(hr), "%s: Failed to flip, hr %#x.\n", test_data[i].name, hr);
6240 color = get_surface_color(backbuffer1, 320, 240);
6241 ok(compare_color(color, 0x00ff0000, 1) || broken(sysmem_primary && compare_color(color, 0x0000ff00, 1)),
6242 "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
6243 color = get_surface_color(backbuffer2, 320, 240);
6244 ok(compare_color(color, 0x0000ff00, 1), "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
6245 fill_surface(backbuffer3, 0xff0000ff);
6247 hr = IDirectDrawSurface7_Flip(frontbuffer, backbuffer1, DDFLIP_WAIT);
6248 ok(SUCCEEDED(hr), "%s: Failed to flip, hr %#x.\n", test_data[i].name, hr);
6249 color = get_surface_color(backbuffer2, 320, 240);
6250 ok(compare_color(color, 0x0000ff00, 1) || broken(sysmem_primary && compare_color(color, 0x000000ff, 1)),
6251 "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
6252 color = get_surface_color(backbuffer3, 320, 240);
6253 ok(compare_color(color, 0x000000ff, 1), "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
6254 fill_surface(backbuffer1, 0xffff0000);
6256 hr = IDirectDrawSurface7_Flip(frontbuffer, backbuffer2, DDFLIP_WAIT);
6257 ok(SUCCEEDED(hr), "%s: Failed to flip, hr %#x.\n", test_data[i].name, hr);
6258 color = get_surface_color(backbuffer1, 320, 240);
6259 ok(compare_color(color, 0x00ff0000, 1), "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
6260 color = get_surface_color(backbuffer3, 320, 240);
6261 ok(compare_color(color, 0x000000ff, 1) || broken(sysmem_primary && compare_color(color, 0x00ff0000, 1)),
6262 "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
6263 fill_surface(backbuffer2, 0xff00ff00);
6265 hr = IDirectDrawSurface7_Flip(frontbuffer, backbuffer3, DDFLIP_WAIT);
6266 ok(SUCCEEDED(hr), "%s: Failed to flip, hr %#x.\n", test_data[i].name, hr);
6267 color = get_surface_color(backbuffer1, 320, 240);
6268 ok(compare_color(color, 0x00ff0000, 1) || broken(sysmem_primary && compare_color(color, 0x0000ff00, 1)),
6269 "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
6270 color = get_surface_color(backbuffer2, 320, 240);
6271 ok(compare_color(color, 0x0000ff00, 1), "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
6273 IDirectDrawSurface7_Release(backbuffer3);
6274 IDirectDrawSurface7_Release(backbuffer2);
6275 IDirectDrawSurface7_Release(backbuffer1);
6276 IDirectDrawSurface7_Release(frontbuffer);
6279 if (!(device = create_device(window, DDSCL_NORMAL)))
6281 skip("Failed to create 3D device.\n");
6282 goto done;
6284 hr = IDirect3DDevice7_GetCaps(device, &device_desc);
6285 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
6286 IDirect3DDevice7_Release(device);
6287 if (!(device_desc.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_CUBEMAP))
6289 skip("Cubemaps are not supported.\n");
6290 goto done;
6293 memset(&surface_desc, 0, sizeof(surface_desc));
6294 surface_desc.dwSize = sizeof(surface_desc);
6295 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
6296 surface_desc.ddsCaps.dwCaps = DDSCAPS_COMPLEX | DDSCAPS_FLIP | DDSCAPS_TEXTURE;
6297 surface_desc.ddsCaps.dwCaps2 = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES;
6298 surface_desc.dwWidth = 128;
6299 surface_desc.dwHeight = 128;
6300 U5(surface_desc).dwBackBufferCount = 3;
6301 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &frontbuffer, NULL);
6302 ok(hr == DDERR_INVALIDCAPS, "Got unexpected hr %#x.\n", hr);
6304 surface_desc.ddsCaps.dwCaps &= ~DDSCAPS_FLIP;
6305 surface_desc.dwFlags |= DDSD_BACKBUFFERCOUNT;
6306 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &frontbuffer, NULL);
6307 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
6309 surface_desc.ddsCaps.dwCaps &= ~DDSCAPS_COMPLEX;
6310 surface_desc.ddsCaps.dwCaps |= DDSCAPS_FLIP;
6311 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &frontbuffer, NULL);
6312 ok(hr == DDERR_INVALIDCAPS, "Got unexpected hr %#x.\n", hr);
6314 surface_desc.ddsCaps.dwCaps |= DDSCAPS_COMPLEX;
6315 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &frontbuffer, NULL);
6316 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
6318 U5(surface_desc).dwBackBufferCount = 1;
6319 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &frontbuffer, NULL);
6320 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
6322 U5(surface_desc).dwBackBufferCount = 0;
6323 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &frontbuffer, NULL);
6324 ok(hr == DDERR_INVALIDCAPS, "Got unexpected hr %#x.\n", hr);
6326 done:
6327 refcount = IDirectDraw7_Release(ddraw);
6328 ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount);
6329 DestroyWindow(window);
6332 static void reset_ddsd(DDSURFACEDESC2 *ddsd)
6334 memset(ddsd, 0, sizeof(*ddsd));
6335 ddsd->dwSize = sizeof(*ddsd);
6338 static void test_set_surface_desc(void)
6340 IDirectDraw7 *ddraw;
6341 HWND window;
6342 HRESULT hr;
6343 DDSURFACEDESC2 ddsd;
6344 IDirectDrawSurface7 *surface;
6345 BYTE data[16*16*4];
6346 ULONG ref;
6347 unsigned int i;
6348 static const struct
6350 DWORD caps, caps2;
6351 BOOL supported;
6352 const char *name;
6354 invalid_caps_tests[] =
6356 {DDSCAPS_VIDEOMEMORY, 0, FALSE, "videomemory plain"},
6357 {DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, 0, TRUE, "systemmemory texture"},
6358 {DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, FALSE, "managed texture"},
6359 {DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, FALSE, "managed texture"},
6360 {DDSCAPS_PRIMARYSURFACE | DDSCAPS_SYSTEMMEMORY, 0, FALSE, "systemmemory primary"},
6363 window = create_window();
6364 ddraw = create_ddraw();
6365 ok(!!ddraw, "Failed to create a ddraw object.\n");
6366 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6367 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6369 reset_ddsd(&ddsd);
6370 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_PIXELFORMAT;
6371 ddsd.dwWidth = 8;
6372 ddsd.dwHeight = 8;
6373 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
6374 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
6375 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
6376 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
6377 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
6378 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000ff;
6379 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
6381 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
6382 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6384 reset_ddsd(&ddsd);
6385 ddsd.dwFlags = DDSD_LPSURFACE;
6386 ddsd.lpSurface = data;
6387 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6388 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
6390 /* Redundantly setting the same lpSurface is not an error. */
6391 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6392 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
6394 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd);
6395 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
6396 ok(!(ddsd.dwFlags & DDSD_LPSURFACE), "DDSD_LPSURFACE is set.\n");
6397 ok(ddsd.lpSurface == NULL, "lpSurface is %p, expected NULL.\n", ddsd.lpSurface);
6399 hr = IDirectDrawSurface7_Lock(surface, NULL, &ddsd, 0, NULL);
6400 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
6401 ok(!(ddsd.dwFlags & DDSD_LPSURFACE), "DDSD_LPSURFACE is set.\n");
6402 ok(ddsd.lpSurface == data, "lpSurface is %p, expected %p.\n", data, data);
6403 hr = IDirectDrawSurface7_Unlock(surface, NULL);
6404 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
6406 reset_ddsd(&ddsd);
6407 ddsd.dwFlags = DDSD_LPSURFACE;
6408 ddsd.lpSurface = data;
6409 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 1);
6410 ok(hr == DDERR_INVALIDPARAMS, "SetSurfaceDesc with flags=1 returned %#x.\n", hr);
6412 ddsd.lpSurface = NULL;
6413 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6414 ok(hr == DDERR_INVALIDPARAMS, "Setting lpSurface=NULL returned %#x.\n", hr);
6416 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, NULL, 0);
6417 ok(hr == DDERR_INVALIDPARAMS, "SetSurfaceDesc with NULL desc returned %#x.\n", hr);
6419 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd);
6420 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
6421 ok(ddsd.ddsCaps.dwCaps == (DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN),
6422 "Got unexpected caps %#x.\n", ddsd.ddsCaps.dwCaps);
6423 ok(ddsd.ddsCaps.dwCaps2 == 0, "Got unexpected caps2 %#x.\n", 0);
6425 /* Setting the caps is an error. This also means the original description cannot be reapplied. */
6426 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6427 ok(hr == DDERR_INVALIDPARAMS, "Setting the original desc returned %#x.\n", hr);
6429 ddsd.dwFlags = DDSD_CAPS;
6430 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6431 ok(hr == DDERR_INVALIDPARAMS, "Setting DDSD_CAPS returned %#x.\n", hr);
6433 /* dwCaps = 0 is allowed, but ignored. Caps2 can be anything and is ignored too. */
6434 ddsd.dwFlags = DDSD_CAPS | DDSD_LPSURFACE;
6435 ddsd.lpSurface = data;
6436 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6437 ok(hr == DDERR_INVALIDCAPS, "Setting DDSD_CAPS returned %#x.\n", hr);
6438 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
6439 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6440 ok(hr == DDERR_INVALIDCAPS, "Setting DDSD_CAPS returned %#x.\n", hr);
6441 ddsd.ddsCaps.dwCaps = 0;
6442 ddsd.ddsCaps.dwCaps2 = 0xdeadbeef;
6443 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6444 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
6446 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd);
6447 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
6448 ok(ddsd.ddsCaps.dwCaps == (DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN),
6449 "Got unexpected caps %#x.\n", ddsd.ddsCaps.dwCaps);
6450 ok(ddsd.ddsCaps.dwCaps2 == 0, "Got unexpected caps2 %#x.\n", 0);
6452 /* Setting the height is allowed, but it cannot be set to 0, and only if LPSURFACE is set too. */
6453 reset_ddsd(&ddsd);
6454 ddsd.dwFlags = DDSD_HEIGHT;
6455 ddsd.dwHeight = 16;
6456 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6457 ok(hr == DDERR_INVALIDPARAMS, "Setting height without lpSurface returned %#x.\n", hr);
6459 ddsd.lpSurface = data;
6460 ddsd.dwFlags = DDSD_HEIGHT | DDSD_LPSURFACE;
6461 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6462 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
6464 ddsd.dwHeight = 0;
6465 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6466 ok(hr == DDERR_INVALIDPARAMS, "Setting height=0 returned %#x.\n", hr);
6468 reset_ddsd(&ddsd);
6469 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd);
6470 ok(SUCCEEDED(hr), "GetSurfaceDesc failed, hr %#x.\n", hr);
6471 ok(ddsd.dwWidth == 8, "SetSurfaceDesc: Expected width 8, got %u.\n", ddsd.dwWidth);
6472 ok(ddsd.dwHeight == 16, "SetSurfaceDesc: Expected height 16, got %u.\n", ddsd.dwHeight);
6474 /* Pitch and width can be set, but only together, and only with LPSURFACE. They must not be 0. */
6475 reset_ddsd(&ddsd);
6476 ddsd.dwFlags = DDSD_PITCH;
6477 U1(ddsd).lPitch = 8 * 4;
6478 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6479 ok(hr == DDERR_INVALIDPARAMS, "Setting pitch without lpSurface or width returned %#x.\n", hr);
6481 ddsd.dwFlags = DDSD_WIDTH;
6482 ddsd.dwWidth = 16;
6483 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6484 ok(hr == DDERR_INVALIDPARAMS, "Setting width without lpSurface or pitch returned %#x.\n", hr);
6486 ddsd.dwFlags = DDSD_PITCH | DDSD_LPSURFACE;
6487 ddsd.lpSurface = data;
6488 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6489 ok(hr == DDERR_INVALIDPARAMS, "Setting pitch and lpSurface without width returned %#x.\n", hr);
6491 ddsd.dwFlags = DDSD_WIDTH | DDSD_LPSURFACE;
6492 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6493 ok(hr == DDERR_INVALIDPARAMS, "Setting width and lpSurface without pitch returned %#x.\n", hr);
6495 ddsd.dwFlags = DDSD_WIDTH | DDSD_PITCH | DDSD_LPSURFACE;
6496 U1(ddsd).lPitch = 16 * 4;
6497 ddsd.dwWidth = 16;
6498 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6499 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
6501 reset_ddsd(&ddsd);
6502 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd);
6503 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
6504 ok(ddsd.dwWidth == 16, "SetSurfaceDesc: Expected width 8, got %u.\n", ddsd.dwWidth);
6505 ok(ddsd.dwHeight == 16, "SetSurfaceDesc: Expected height 16, got %u.\n", ddsd.dwHeight);
6506 ok(U1(ddsd).lPitch == 16 * 4, "SetSurfaceDesc: Expected pitch 64, got %u.\n", U1(ddsd).lPitch);
6508 /* The pitch must be 32 bit aligned and > 0, but is not verified for sanity otherwise.
6510 * VMware rejects those calls, but all real drivers accept it. Mark the VMware behavior broken. */
6511 ddsd.dwFlags = DDSD_WIDTH | DDSD_PITCH | DDSD_LPSURFACE;
6512 U1(ddsd).lPitch = 4 * 4;
6513 ddsd.lpSurface = data;
6514 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6515 ok(SUCCEEDED(hr) || broken(hr == DDERR_INVALIDPARAMS), "Failed to set surface desc, hr %#x.\n", hr);
6517 U1(ddsd).lPitch = 4;
6518 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6519 ok(SUCCEEDED(hr) || broken(hr == DDERR_INVALIDPARAMS), "Failed to set surface desc, hr %#x.\n", hr);
6521 U1(ddsd).lPitch = 16 * 4 + 1;
6522 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6523 ok(hr == DDERR_INVALIDPARAMS, "Setting misaligned pitch returned %#x.\n", hr);
6525 U1(ddsd).lPitch = 16 * 4 + 3;
6526 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6527 ok(hr == DDERR_INVALIDPARAMS, "Setting misaligned pitch returned %#x.\n", hr);
6529 U1(ddsd).lPitch = -4;
6530 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6531 ok(hr == DDERR_INVALIDPARAMS, "Setting negative pitch returned %#x.\n", hr);
6533 U1(ddsd).lPitch = 16 * 4;
6534 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6535 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
6537 reset_ddsd(&ddsd);
6538 ddsd.dwFlags = DDSD_WIDTH | DDSD_PITCH | DDSD_LPSURFACE;
6539 U1(ddsd).lPitch = 0;
6540 ddsd.dwWidth = 16;
6541 ddsd.lpSurface = data;
6542 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6543 ok(hr == DDERR_INVALIDPARAMS, "Setting zero pitch returned %#x.\n", hr);
6545 ddsd.dwFlags = DDSD_WIDTH | DDSD_PITCH | DDSD_LPSURFACE;
6546 U1(ddsd).lPitch = 16 * 4;
6547 ddsd.dwWidth = 0;
6548 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6549 ok(hr == DDERR_INVALIDPARAMS, "Setting zero width returned %#x.\n", hr);
6551 /* Setting the pixelformat without LPSURFACE is an error, but with LPSURFACE it works. */
6552 ddsd.dwFlags = DDSD_PIXELFORMAT;
6553 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
6554 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
6555 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
6556 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
6557 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
6558 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000ff;
6559 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6560 ok(hr == DDERR_INVALIDPARAMS, "Setting the pixel format returned %#x.\n", hr);
6562 ddsd.dwFlags = DDSD_PIXELFORMAT | DDSD_LPSURFACE;
6563 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6564 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
6566 /* Can't set color keys. */
6567 reset_ddsd(&ddsd);
6568 ddsd.dwFlags = DDSD_CKSRCBLT;
6569 ddsd.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00ff0000;
6570 ddsd.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00ff0000;
6571 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6572 ok(hr == DDERR_INVALIDPARAMS, "Setting ddckCKSrcBlt returned %#x.\n", hr);
6574 ddsd.dwFlags = DDSD_CKSRCBLT | DDSD_LPSURFACE;
6575 ddsd.lpSurface = data;
6576 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6577 ok(hr == DDERR_INVALIDPARAMS, "Setting ddckCKSrcBlt returned %#x.\n", hr);
6579 IDirectDrawSurface7_Release(surface);
6581 /* SetSurfaceDesc needs systemmemory surfaces.
6583 * As a sidenote, fourcc surfaces aren't allowed in sysmem, thus testing
6584 * DDSD_LINEARSIZE is moot. */
6585 for (i = 0; i < ARRAY_SIZE(invalid_caps_tests); ++i)
6587 reset_ddsd(&ddsd);
6588 ddsd.dwFlags = DDSD_CAPS;
6589 ddsd.ddsCaps.dwCaps = invalid_caps_tests[i].caps;
6590 ddsd.ddsCaps.dwCaps2 = invalid_caps_tests[i].caps2;
6591 if (!(invalid_caps_tests[i].caps & DDSCAPS_PRIMARYSURFACE))
6593 ddsd.dwFlags |= DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
6594 ddsd.dwWidth = 8;
6595 ddsd.dwHeight = 8;
6596 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
6597 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
6598 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
6599 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
6600 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
6601 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000ff;
6604 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
6605 if (is_ddraw64 && (invalid_caps_tests[i].caps & DDSCAPS_TEXTURE))
6606 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Got unexpected hr %#x.\n", i, hr);
6607 else
6608 ok(hr == DD_OK || hr == DDERR_NODIRECTDRAWHW, "Test %u: Got unexpected hr %#x.\n", i, hr);
6609 if (FAILED(hr))
6610 continue;
6612 reset_ddsd(&ddsd);
6613 ddsd.dwFlags = DDSD_LPSURFACE;
6614 ddsd.lpSurface = data;
6615 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6616 if (invalid_caps_tests[i].supported)
6618 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
6620 else
6622 ok(hr == DDERR_INVALIDSURFACETYPE, "SetSurfaceDesc on a %s surface returned %#x.\n",
6623 invalid_caps_tests[i].name, hr);
6625 /* Check priority of error conditions. */
6626 ddsd.dwFlags = DDSD_WIDTH;
6627 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6628 ok(hr == DDERR_INVALIDSURFACETYPE, "SetSurfaceDesc on a %s surface returned %#x.\n",
6629 invalid_caps_tests[i].name, hr);
6632 IDirectDrawSurface7_Release(surface);
6635 ref = IDirectDraw7_Release(ddraw);
6636 ok(ref == 0, "Ddraw object not properly released, refcount %u.\n", ref);
6637 DestroyWindow(window);
6640 static void test_user_memory_getdc(void)
6642 IDirectDraw7 *ddraw;
6643 HWND window;
6644 HRESULT hr;
6645 DDSURFACEDESC2 ddsd;
6646 IDirectDrawSurface7 *surface;
6647 DWORD data[16][16];
6648 HGDIOBJ *bitmap;
6649 DIBSECTION dib;
6650 ULONG ref;
6651 int size;
6652 HDC dc;
6653 unsigned int x, y;
6655 window = create_window();
6656 ddraw = create_ddraw();
6657 ok(!!ddraw, "Failed to create a ddraw object.\n");
6658 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6659 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6661 reset_ddsd(&ddsd);
6662 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_PIXELFORMAT;
6663 ddsd.dwWidth = 16;
6664 ddsd.dwHeight = 16;
6665 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
6666 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
6667 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
6668 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
6669 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
6670 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000ff;
6671 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
6672 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
6673 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6675 memset(data, 0xaa, sizeof(data));
6676 reset_ddsd(&ddsd);
6677 ddsd.dwFlags = DDSD_LPSURFACE;
6678 ddsd.lpSurface = data;
6679 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6680 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
6682 hr = IDirectDrawSurface7_GetDC(surface, &dc);
6683 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
6684 bitmap = GetCurrentObject(dc, OBJ_BITMAP);
6685 ok(!!bitmap, "Failed to get bitmap.\n");
6686 size = GetObjectA(bitmap, sizeof(dib), &dib);
6687 ok(size == sizeof(dib), "Got unexpected size %d.\n", size);
6688 ok(dib.dsBm.bmBits == data, "Got unexpected bits %p, expected %p.\n", dib.dsBm.bmBits, data);
6689 BitBlt(dc, 0, 0, 16, 8, NULL, 0, 0, WHITENESS);
6690 BitBlt(dc, 0, 8, 16, 8, NULL, 0, 0, BLACKNESS);
6691 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
6692 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
6694 ok(data[0][0] == 0xffffffff, "Expected color 0xffffffff, got %#x.\n", data[0][0]);
6695 ok(data[15][15] == 0x00000000, "Expected color 0x00000000, got %#x.\n", data[15][15]);
6697 ddsd.dwFlags = DDSD_LPSURFACE | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PITCH;
6698 ddsd.lpSurface = data;
6699 ddsd.dwWidth = 4;
6700 ddsd.dwHeight = 8;
6701 U1(ddsd).lPitch = sizeof(*data);
6702 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6703 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
6705 memset(data, 0xaa, sizeof(data));
6706 hr = IDirectDrawSurface7_GetDC(surface, &dc);
6707 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
6708 BitBlt(dc, 0, 0, 4, 8, NULL, 0, 0, BLACKNESS);
6709 BitBlt(dc, 1, 1, 2, 2, NULL, 0, 0, WHITENESS);
6710 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
6711 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
6713 for (y = 0; y < 4; y++)
6715 for (x = 0; x < 4; x++)
6717 if ((x == 1 || x == 2) && (y == 1 || y == 2))
6718 ok(data[y][x] == 0xffffffff, "Expected color 0xffffffff on position %ux%u, got %#x.\n",
6719 x, y, data[y][x]);
6720 else
6721 ok(data[y][x] == 0x00000000, "Expected color 0x00000000 on position %ux%u, got %#x.\n",
6722 x, y, data[y][x]);
6725 ok(data[0][5] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 5x0, got %#x.\n",
6726 data[0][5]);
6727 ok(data[7][3] == 0x00000000, "Expected color 0x00000000 on position 3x7, got %#x.\n",
6728 data[7][3]);
6729 ok(data[7][4] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 4x7, got %#x.\n",
6730 data[7][4]);
6731 ok(data[8][0] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 0x8, got %#x.\n",
6732 data[8][0]);
6734 IDirectDrawSurface7_Release(surface);
6735 ref = IDirectDraw7_Release(ddraw);
6736 ok(ref == 0, "Ddraw object not properly released, refcount %u.\n", ref);
6737 DestroyWindow(window);
6740 static void test_sysmem_overlay(void)
6742 IDirectDraw7 *ddraw;
6743 HWND window;
6744 HRESULT hr;
6745 DDSURFACEDESC2 ddsd;
6746 IDirectDrawSurface7 *surface;
6747 ULONG ref;
6749 window = create_window();
6750 ddraw = create_ddraw();
6751 ok(!!ddraw, "Failed to create a ddraw object.\n");
6752 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6753 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6755 reset_ddsd(&ddsd);
6756 ddsd.dwFlags = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT;
6757 ddsd.dwWidth = 16;
6758 ddsd.dwHeight = 16;
6759 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OVERLAY;
6760 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
6761 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
6762 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
6763 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
6764 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
6765 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000ff;
6766 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
6767 ok(hr == DDERR_NOOVERLAYHW, "Got unexpected hr %#x.\n", hr);
6769 ref = IDirectDraw7_Release(ddraw);
6770 ok(ref == 0, "Ddraw object not properly released, refcount %u.\n", ref);
6771 DestroyWindow(window);
6774 static void test_primary_palette(void)
6776 DDSCAPS2 surface_caps = {DDSCAPS_FLIP, 0, 0, {0}};
6777 IDirectDrawSurface7 *primary, *backbuffer;
6778 PALETTEENTRY palette_entries[256];
6779 IDirectDrawPalette *palette, *tmp;
6780 DDSURFACEDESC2 surface_desc;
6781 IDirectDraw7 *ddraw;
6782 DWORD palette_caps;
6783 ULONG refcount;
6784 HWND window;
6785 HRESULT hr;
6787 window = create_window();
6788 ddraw = create_ddraw();
6789 ok(!!ddraw, "Failed to create a ddraw object.\n");
6790 if (FAILED(IDirectDraw7_SetDisplayMode(ddraw, 640, 480, 8, 0, 0)))
6792 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
6793 IDirectDraw7_Release(ddraw);
6794 DestroyWindow(window);
6795 return;
6797 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
6798 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6800 memset(&surface_desc, 0, sizeof(surface_desc));
6801 surface_desc.dwSize = sizeof(surface_desc);
6802 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
6803 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
6804 U5(surface_desc).dwBackBufferCount = 1;
6805 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &primary, NULL);
6806 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6807 hr = IDirectDrawSurface7_GetAttachedSurface(primary, &surface_caps, &backbuffer);
6808 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
6810 memset(palette_entries, 0, sizeof(palette_entries));
6811 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256, palette_entries, &palette, NULL);
6812 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
6813 refcount = get_refcount((IUnknown *)palette);
6814 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
6816 hr = IDirectDrawPalette_GetCaps(palette, &palette_caps);
6817 ok(SUCCEEDED(hr), "Failed to get palette caps, hr %#x.\n", hr);
6818 ok(palette_caps == (DDPCAPS_8BIT | DDPCAPS_ALLOW256), "Got unexpected palette caps %#x.\n", palette_caps);
6820 hr = IDirectDrawSurface7_SetPalette(primary, palette);
6821 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
6823 /* The Windows 8 testbot attaches the palette to the backbuffer as well,
6824 * and is generally somewhat broken with respect to 8 bpp / palette
6825 * handling. */
6826 if (SUCCEEDED(IDirectDrawSurface7_GetPalette(backbuffer, &tmp)))
6828 win_skip("Broken palette handling detected, skipping tests.\n");
6829 IDirectDrawPalette_Release(tmp);
6830 IDirectDrawPalette_Release(palette);
6831 /* The Windows 8 testbot keeps extra references to the primary and
6832 * backbuffer while in 8 bpp mode. */
6833 hr = IDirectDraw7_RestoreDisplayMode(ddraw);
6834 ok(SUCCEEDED(hr), "Failed to restore display mode, hr %#x.\n", hr);
6835 goto done;
6838 refcount = get_refcount((IUnknown *)palette);
6839 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
6841 hr = IDirectDrawPalette_GetCaps(palette, &palette_caps);
6842 ok(SUCCEEDED(hr), "Failed to get palette caps, hr %#x.\n", hr);
6843 ok(palette_caps == (DDPCAPS_8BIT | DDPCAPS_PRIMARYSURFACE | DDPCAPS_ALLOW256),
6844 "Got unexpected palette caps %#x.\n", palette_caps);
6846 hr = IDirectDrawSurface7_SetPalette(primary, NULL);
6847 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
6848 refcount = get_refcount((IUnknown *)palette);
6849 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
6851 hr = IDirectDrawPalette_GetCaps(palette, &palette_caps);
6852 ok(SUCCEEDED(hr), "Failed to get palette caps, hr %#x.\n", hr);
6853 ok(palette_caps == (DDPCAPS_8BIT | DDPCAPS_ALLOW256), "Got unexpected palette caps %#x.\n", palette_caps);
6855 hr = IDirectDrawSurface7_SetPalette(primary, palette);
6856 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
6857 refcount = get_refcount((IUnknown *)palette);
6858 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
6860 hr = IDirectDrawSurface7_GetPalette(primary, &tmp);
6861 ok(SUCCEEDED(hr), "Failed to get palette, hr %#x.\n", hr);
6862 ok(tmp == palette, "Got unexpected palette %p, expected %p.\n", tmp, palette);
6863 IDirectDrawPalette_Release(tmp);
6864 hr = IDirectDrawSurface7_GetPalette(backbuffer, &tmp);
6865 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x.\n", hr);
6867 refcount = IDirectDrawPalette_Release(palette);
6868 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
6869 refcount = IDirectDrawPalette_Release(palette);
6870 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6872 /* Note that this only seems to work when the palette is attached to the
6873 * primary surface. When attached to a regular surface, attempting to get
6874 * the palette here will cause an access violation. */
6875 hr = IDirectDrawSurface7_GetPalette(primary, &tmp);
6876 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x.\n", hr);
6878 hr = IDirectDrawSurface7_IsLost(primary);
6879 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6881 memset(&surface_desc, 0, sizeof(surface_desc));
6882 surface_desc.dwSize = sizeof(surface_desc);
6883 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &surface_desc);
6884 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
6885 ok(surface_desc.dwWidth == 640, "Got unexpected surface width %u.\n", surface_desc.dwWidth);
6886 ok(surface_desc.dwHeight == 480, "Got unexpected surface height %u.\n", surface_desc.dwHeight);
6887 ok(U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount == 8, "Got unexpected bit count %u.\n",
6888 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount);
6890 hr = set_display_mode(ddraw, 640, 480);
6891 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
6893 memset(&surface_desc, 0, sizeof(surface_desc));
6894 surface_desc.dwSize = sizeof(surface_desc);
6895 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &surface_desc);
6896 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
6897 ok(surface_desc.dwWidth == 640, "Got unexpected surface width %u.\n", surface_desc.dwWidth);
6898 ok(surface_desc.dwHeight == 480, "Got unexpected surface height %u.\n", surface_desc.dwHeight);
6899 ok(U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount == 32
6900 || U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount == 24,
6901 "Got unexpected bit count %u.\n", U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount);
6903 hr = IDirectDrawSurface7_IsLost(primary);
6904 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
6905 hr = IDirectDrawSurface7_Restore(primary);
6906 ok(hr == DDERR_WRONGMODE, "Got unexpected hr %#x.\n", hr);
6907 hr = IDirectDrawSurface7_IsLost(primary);
6908 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
6910 memset(&surface_desc, 0, sizeof(surface_desc));
6911 surface_desc.dwSize = sizeof(surface_desc);
6912 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &surface_desc);
6913 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
6914 ok(surface_desc.dwWidth == 640, "Got unexpected surface width %u.\n", surface_desc.dwWidth);
6915 ok(surface_desc.dwHeight == 480, "Got unexpected surface height %u.\n", surface_desc.dwHeight);
6916 ok(U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount == 32
6917 || U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount == 24,
6918 "Got unexpected bit count %u.\n", U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount);
6920 done:
6921 refcount = IDirectDrawSurface7_Release(backbuffer);
6922 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
6923 refcount = IDirectDrawSurface7_Release(primary);
6924 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6925 refcount = IDirectDraw7_Release(ddraw);
6926 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6927 DestroyWindow(window);
6930 static HRESULT WINAPI surface_counter(IDirectDrawSurface7 *surface, DDSURFACEDESC2 *desc, void *context)
6932 UINT *surface_count = context;
6934 ++(*surface_count);
6935 IDirectDrawSurface_Release(surface);
6937 return DDENUMRET_OK;
6940 static void test_surface_attachment(void)
6942 IDirectDrawSurface7 *surface1, *surface2, *surface3, *surface4;
6943 IDirectDrawSurface *surface1v1, *surface2v1;
6944 DDSCAPS2 caps = {DDSCAPS_TEXTURE, 0, 0, {0}};
6945 DDSURFACEDESC2 surface_desc;
6946 IDirectDraw7 *ddraw;
6947 UINT surface_count;
6948 ULONG refcount;
6949 HWND window;
6950 HRESULT hr;
6952 window = create_window();
6953 ddraw = create_ddraw();
6954 ok(!!ddraw, "Failed to create a ddraw object.\n");
6955 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6956 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6958 memset(&surface_desc, 0, sizeof(surface_desc));
6959 surface_desc.dwSize = sizeof(surface_desc);
6960 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_MIPMAPCOUNT;
6961 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
6962 U2(surface_desc).dwMipMapCount = 3;
6963 surface_desc.dwWidth = 128;
6964 surface_desc.dwHeight = 128;
6965 if (FAILED(IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface1, NULL)))
6967 skip("Failed to create a texture, skipping tests.\n");
6968 IDirectDraw7_Release(ddraw);
6969 DestroyWindow(window);
6970 return;
6973 hr = IDirectDrawSurface7_GetAttachedSurface(surface1, &caps, &surface2);
6974 ok(SUCCEEDED(hr), "Failed to get mip level, hr %#x.\n", hr);
6975 hr = IDirectDrawSurface7_GetAttachedSurface(surface2, &caps, &surface3);
6976 ok(SUCCEEDED(hr), "Failed to get mip level, hr %#x.\n", hr);
6977 hr = IDirectDrawSurface7_GetAttachedSurface(surface3, &caps, &surface4);
6978 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
6980 surface_count = 0;
6981 IDirectDrawSurface7_EnumAttachedSurfaces(surface1, &surface_count, surface_counter);
6982 ok(surface_count == 1, "Got unexpected surface_count %u.\n", surface_count);
6983 surface_count = 0;
6984 IDirectDrawSurface7_EnumAttachedSurfaces(surface2, &surface_count, surface_counter);
6985 ok(surface_count == 1, "Got unexpected surface_count %u.\n", surface_count);
6986 surface_count = 0;
6987 IDirectDrawSurface7_EnumAttachedSurfaces(surface3, &surface_count, surface_counter);
6988 ok(!surface_count, "Got unexpected surface_count %u.\n", surface_count);
6990 memset(&surface_desc, 0, sizeof(surface_desc));
6991 surface_desc.dwSize = sizeof(surface_desc);
6992 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
6993 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
6994 surface_desc.dwWidth = 16;
6995 surface_desc.dwHeight = 16;
6996 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface4, NULL);
6997 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6999 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface4);
7000 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7001 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface1);
7002 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7003 hr = IDirectDrawSurface7_AddAttachedSurface(surface3, surface4);
7004 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7005 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface3);
7006 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7007 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface4);
7008 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7009 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface2);
7010 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7012 IDirectDrawSurface7_Release(surface4);
7014 memset(&surface_desc, 0, sizeof(surface_desc));
7015 surface_desc.dwSize = sizeof(surface_desc);
7016 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
7017 surface_desc.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
7018 surface_desc.dwWidth = 16;
7019 surface_desc.dwHeight = 16;
7020 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface4, NULL);
7021 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7023 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface4);
7024 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7025 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface1);
7026 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7027 hr = IDirectDrawSurface7_AddAttachedSurface(surface3, surface4);
7028 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7029 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface3);
7030 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7031 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface4);
7032 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7033 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface2);
7034 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7036 IDirectDrawSurface7_Release(surface4);
7037 IDirectDrawSurface7_Release(surface3);
7038 IDirectDrawSurface7_Release(surface2);
7039 IDirectDrawSurface7_Release(surface1);
7041 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
7042 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
7044 /* Try a single primary and two offscreen plain surfaces. */
7045 memset(&surface_desc, 0, sizeof(surface_desc));
7046 surface_desc.dwSize = sizeof(surface_desc);
7047 surface_desc.dwFlags = DDSD_CAPS;
7048 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
7049 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface1, NULL);
7050 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7052 memset(&surface_desc, 0, sizeof(surface_desc));
7053 surface_desc.dwSize = sizeof(surface_desc);
7054 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
7055 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
7056 surface_desc.dwWidth = registry_mode.dmPelsWidth;
7057 surface_desc.dwHeight = registry_mode.dmPelsHeight;
7058 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface2, NULL);
7059 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7061 memset(&surface_desc, 0, sizeof(surface_desc));
7062 surface_desc.dwSize = sizeof(surface_desc);
7063 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
7064 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
7065 surface_desc.dwWidth = registry_mode.dmPelsWidth;
7066 surface_desc.dwHeight = registry_mode.dmPelsHeight;
7067 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface3, NULL);
7068 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7070 /* This one has a different size. */
7071 memset(&surface_desc, 0, sizeof(surface_desc));
7072 surface_desc.dwSize = sizeof(surface_desc);
7073 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
7074 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
7075 surface_desc.dwWidth = 128;
7076 surface_desc.dwHeight = 128;
7077 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface4, NULL);
7078 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7080 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface2);
7081 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7082 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface1);
7083 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7084 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface3);
7085 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7086 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface4);
7087 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7088 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface1);
7089 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7091 IDirectDrawSurface7_Release(surface4);
7092 IDirectDrawSurface7_Release(surface3);
7093 IDirectDrawSurface7_Release(surface2);
7094 IDirectDrawSurface7_Release(surface1);
7096 /* Test DeleteAttachedSurface() and automatic detachment of attached surfaces on release. */
7097 memset(&surface_desc, 0, sizeof(surface_desc));
7098 surface_desc.dwSize = sizeof(surface_desc);
7099 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
7100 surface_desc.dwWidth = 64;
7101 surface_desc.dwHeight = 64;
7102 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
7103 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
7104 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB; /* D3DFMT_R5G6B5 */
7105 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 16;
7106 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0xf800;
7107 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x07e0;
7108 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x001f;
7109 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface1, NULL);
7110 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7111 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface3, NULL);
7112 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7114 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
7115 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_ZBUFFER;
7116 U1(U4(surface_desc).ddpfPixelFormat).dwZBufferBitDepth = 16;
7117 U3(U4(surface_desc).ddpfPixelFormat).dwZBitMask = 0x0000ffff;
7118 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface2, NULL);
7119 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7121 hr = IDirectDrawSurface7_QueryInterface(surface1, &IID_IDirectDrawSurface, (void **)&surface1v1);
7122 ok(SUCCEEDED(hr), "Failed to get interface, hr %#x.\n", hr);
7123 hr = IDirectDrawSurface7_QueryInterface(surface2, &IID_IDirectDrawSurface, (void **)&surface2v1);
7124 ok(SUCCEEDED(hr), "Failed to get interface, hr %#x.\n", hr);
7126 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface2);
7127 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
7128 refcount = get_refcount((IUnknown *)surface2);
7129 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
7130 refcount = get_refcount((IUnknown *)surface2v1);
7131 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
7132 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface2);
7133 ok(hr == DDERR_SURFACEALREADYATTACHED, "Got unexpected hr %#x.\n", hr);
7134 hr = IDirectDrawSurface_AddAttachedSurface(surface1v1, surface2v1);
7135 todo_wine ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7136 hr = IDirectDrawSurface_DeleteAttachedSurface(surface1v1, 0, surface2v1);
7137 ok(hr == DDERR_SURFACENOTATTACHED, "Got unexpected hr %#x.\n", hr);
7139 /* Attaching while already attached to other surface. */
7140 hr = IDirectDrawSurface7_AddAttachedSurface(surface3, surface2);
7141 todo_wine ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
7142 hr = IDirectDrawSurface7_DeleteAttachedSurface(surface3, 0, surface2);
7143 todo_wine ok(SUCCEEDED(hr), "Failed to detach surface, hr %#x.\n", hr);
7144 IDirectDrawSurface7_Release(surface3);
7146 hr = IDirectDrawSurface7_DeleteAttachedSurface(surface1, 0, surface2);
7147 ok(SUCCEEDED(hr), "Failed to detach surface, hr %#x.\n", hr);
7148 refcount = get_refcount((IUnknown *)surface2);
7149 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
7150 refcount = get_refcount((IUnknown *)surface2v1);
7151 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
7153 /* DeleteAttachedSurface() when attaching via IDirectDrawSurface. */
7154 hr = IDirectDrawSurface_AddAttachedSurface(surface1v1, surface2v1);
7155 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
7156 hr = IDirectDrawSurface7_DeleteAttachedSurface(surface1, 0, surface2);
7157 ok(hr == DDERR_SURFACENOTATTACHED, "Got unexpected hr %#x.\n", hr);
7158 hr = IDirectDrawSurface_DeleteAttachedSurface(surface1v1, 0, surface2v1);
7159 ok(SUCCEEDED(hr), "Failed to detach surface, hr %#x.\n", hr);
7160 refcount = IDirectDrawSurface7_Release(surface2);
7161 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7162 refcount = IDirectDrawSurface7_Release(surface1);
7163 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7165 /* Automatic detachment on release. */
7166 hr = IDirectDrawSurface_AddAttachedSurface(surface1v1, surface2v1);
7167 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
7168 refcount = get_refcount((IUnknown *)surface2v1);
7169 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
7170 refcount = IDirectDrawSurface_Release(surface1v1);
7171 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7172 refcount = IDirectDrawSurface_Release(surface2v1);
7173 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7174 refcount = IDirectDraw7_Release(ddraw);
7175 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7176 DestroyWindow(window);
7179 static void test_private_data(void)
7181 IDirectDraw7 *ddraw;
7182 IDirectDrawSurface7 *surface, *surface2;
7183 DDSURFACEDESC2 surface_desc;
7184 ULONG refcount, refcount2, refcount3;
7185 IUnknown *ptr;
7186 DWORD size = sizeof(ptr);
7187 HRESULT hr;
7188 HWND window;
7189 DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, {0}};
7190 DWORD data[] = {1, 2, 3, 4};
7191 DDCAPS hal_caps;
7192 static const GUID ddraw_private_data_test_guid =
7194 0xfdb37466,
7195 0x428f,
7196 0x4edf,
7197 {0xa3,0x7f,0x9b,0x1d,0xf4,0x88,0xc5,0xfc}
7199 static const GUID ddraw_private_data_test_guid2 =
7201 0x2e5afac2,
7202 0x87b5,
7203 0x4c10,
7204 {0x9b,0x4b,0x89,0xd7,0xd1,0x12,0xe7,0x2b}
7207 window = create_window();
7208 ddraw = create_ddraw();
7209 ok(!!ddraw, "Failed to create a ddraw object.\n");
7210 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
7211 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
7213 reset_ddsd(&surface_desc);
7214 surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
7215 surface_desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
7216 surface_desc.dwHeight = 4;
7217 surface_desc.dwWidth = 4;
7218 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7219 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7221 /* NULL pointers are not valid, but don't cause a crash. */
7222 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, NULL,
7223 sizeof(IUnknown *), DDSPD_IUNKNOWNPOINTER);
7224 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7225 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, NULL, 0, 0);
7226 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7227 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, NULL, 1, 0);
7228 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7230 /* DDSPD_IUNKNOWNPOINTER needs sizeof(IUnknown *) bytes of data. */
7231 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
7232 0, DDSPD_IUNKNOWNPOINTER);
7233 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7234 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
7235 5, DDSPD_IUNKNOWNPOINTER);
7236 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7237 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
7238 sizeof(ddraw) * 2, DDSPD_IUNKNOWNPOINTER);
7239 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7241 /* Note that with a size != 0 and size != sizeof(IUnknown *) and
7242 * DDSPD_IUNKNOWNPOINTER set SetPrivateData in ddraw4 and ddraw7
7243 * erases the old content and returns an error. This behavior has
7244 * been fixed in d3d8 and d3d9. Unless an application is found
7245 * that depends on this we don't care about this behavior. */
7246 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
7247 sizeof(ddraw), DDSPD_IUNKNOWNPOINTER);
7248 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
7249 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
7250 0, DDSPD_IUNKNOWNPOINTER);
7251 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7252 size = sizeof(ptr);
7253 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid, &ptr, &size);
7254 ok(SUCCEEDED(hr), "Failed to get private data, hr %#x.\n", hr);
7255 hr = IDirectDrawSurface7_FreePrivateData(surface, &ddraw_private_data_test_guid);
7256 ok(SUCCEEDED(hr), "Failed to free private data, hr %#x.\n", hr);
7258 refcount = get_refcount((IUnknown *)ddraw);
7259 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
7260 sizeof(ddraw), DDSPD_IUNKNOWNPOINTER);
7261 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
7262 refcount2 = get_refcount((IUnknown *)ddraw);
7263 ok(refcount2 == refcount + 1, "Got unexpected refcount %u.\n", refcount2);
7265 hr = IDirectDrawSurface7_FreePrivateData(surface, &ddraw_private_data_test_guid);
7266 ok(SUCCEEDED(hr), "Failed to free private data, hr %#x.\n", hr);
7267 refcount2 = get_refcount((IUnknown *)ddraw);
7268 ok(refcount2 == refcount, "Got unexpected refcount %u.\n", refcount2);
7270 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
7271 sizeof(ddraw), DDSPD_IUNKNOWNPOINTER);
7272 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
7273 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, surface,
7274 sizeof(surface), DDSPD_IUNKNOWNPOINTER);
7275 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
7276 refcount2 = get_refcount((IUnknown *)ddraw);
7277 ok(refcount2 == refcount, "Got unexpected refcount %u.\n", refcount2);
7279 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
7280 sizeof(ddraw), DDSPD_IUNKNOWNPOINTER);
7281 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
7282 size = 2 * sizeof(ptr);
7283 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid, &ptr, &size);
7284 ok(SUCCEEDED(hr), "Failed to get private data, hr %#x.\n", hr);
7285 ok(size == sizeof(ddraw), "Got unexpected size %u.\n", size);
7286 refcount2 = get_refcount(ptr);
7287 /* Object is NOT addref'ed by the getter. */
7288 ok(ptr == (IUnknown *)ddraw, "Returned interface pointer is %p, expected %p.\n", ptr, ddraw);
7289 ok(refcount2 == refcount + 1, "Got unexpected refcount %u.\n", refcount2);
7291 ptr = (IUnknown *)0xdeadbeef;
7292 size = 1;
7293 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid, NULL, &size);
7294 ok(hr == DDERR_MOREDATA, "Got unexpected hr %#x.\n", hr);
7295 ok(size == sizeof(ddraw), "Got unexpected size %u.\n", size);
7296 size = 2 * sizeof(ptr);
7297 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid, NULL, &size);
7298 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7299 ok(size == 2 * sizeof(ptr), "Got unexpected size %u.\n", size);
7300 size = 1;
7301 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid, &ptr, &size);
7302 ok(hr == DDERR_MOREDATA, "Got unexpected hr %#x.\n", hr);
7303 ok(size == sizeof(ddraw), "Got unexpected size %u.\n", size);
7304 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
7305 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid2, NULL, NULL);
7306 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
7307 size = 0xdeadbabe;
7308 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid2, &ptr, &size);
7309 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
7310 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
7311 ok(size == 0xdeadbabe, "Got unexpected size %u.\n", size);
7312 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid, NULL, NULL);
7313 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7315 refcount3 = IDirectDrawSurface7_Release(surface);
7316 ok(!refcount3, "Got unexpected refcount %u.\n", refcount3);
7318 /* Destroying the surface frees the reference held on the private data. It also frees
7319 * the reference the surface is holding on its creating object. */
7320 refcount2 = get_refcount((IUnknown *)ddraw);
7321 ok(refcount2 == refcount - 1, "Got unexpected refcount %u.\n", refcount2);
7323 memset(&hal_caps, 0, sizeof(hal_caps));
7324 hal_caps.dwSize = sizeof(hal_caps);
7325 hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, NULL);
7326 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
7327 if ((hal_caps.ddsCaps.dwCaps & (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP)) == (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP)
7328 && !is_ddraw64)
7330 reset_ddsd(&surface_desc);
7331 surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_MIPMAPCOUNT;
7332 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
7333 surface_desc.dwHeight = 4;
7334 surface_desc.dwWidth = 4;
7335 U2(surface_desc).dwMipMapCount = 2;
7336 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7337 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7338 hr = IDirectDrawSurface7_GetAttachedSurface(surface, &caps, &surface2);
7339 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
7341 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, data, sizeof(data), 0);
7342 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
7343 hr = IDirectDrawSurface7_GetPrivateData(surface2, &ddraw_private_data_test_guid, NULL, NULL);
7344 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
7346 IDirectDrawSurface7_Release(surface2);
7347 IDirectDrawSurface7_Release(surface);
7349 else
7350 skip("Mipmapped textures not supported, skipping mipmap private data test.\n");
7352 refcount = IDirectDraw7_Release(ddraw);
7353 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7354 DestroyWindow(window);
7357 static void test_pixel_format(void)
7359 HWND window, window2 = NULL;
7360 HDC hdc, hdc2 = NULL;
7361 HMODULE gl = NULL;
7362 int format, test_format;
7363 PIXELFORMATDESCRIPTOR pfd;
7364 IDirectDraw7 *ddraw = NULL;
7365 IDirectDrawClipper *clipper = NULL;
7366 DDSURFACEDESC2 ddsd;
7367 IDirectDrawSurface7 *primary = NULL;
7368 DDBLTFX fx;
7369 HRESULT hr;
7371 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
7372 100, 100, 160, 160, NULL, NULL, NULL, NULL);
7373 if (!window)
7375 skip("Failed to create window\n");
7376 return;
7379 window2 = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
7380 100, 100, 160, 160, NULL, NULL, NULL, NULL);
7382 hdc = GetDC(window);
7383 if (!hdc)
7385 skip("Failed to get DC\n");
7386 goto cleanup;
7389 if (window2)
7390 hdc2 = GetDC(window2);
7392 gl = LoadLibraryA("opengl32.dll");
7393 ok(!!gl, "failed to load opengl32.dll; SetPixelFormat()/GetPixelFormat() may not work right\n");
7395 format = GetPixelFormat(hdc);
7396 ok(format == 0, "new window has pixel format %d\n", format);
7398 ZeroMemory(&pfd, sizeof(pfd));
7399 pfd.nSize = sizeof(pfd);
7400 pfd.nVersion = 1;
7401 pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
7402 pfd.iPixelType = PFD_TYPE_RGBA;
7403 pfd.iLayerType = PFD_MAIN_PLANE;
7404 format = ChoosePixelFormat(hdc, &pfd);
7405 if (format <= 0)
7407 skip("no pixel format available\n");
7408 goto cleanup;
7411 if (!SetPixelFormat(hdc, format, &pfd) || GetPixelFormat(hdc) != format)
7413 skip("failed to set pixel format\n");
7414 goto cleanup;
7417 if (!hdc2 || !SetPixelFormat(hdc2, format, &pfd) || GetPixelFormat(hdc2) != format)
7419 skip("failed to set pixel format on second window\n");
7420 if (hdc2)
7422 ReleaseDC(window2, hdc2);
7423 hdc2 = NULL;
7427 ddraw = create_ddraw();
7428 ok(!!ddraw, "Failed to create a ddraw object.\n");
7430 test_format = GetPixelFormat(hdc);
7431 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
7433 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
7434 if (FAILED(hr))
7436 skip("Failed to set cooperative level, hr %#x.\n", hr);
7437 goto cleanup;
7440 test_format = GetPixelFormat(hdc);
7441 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
7443 if (hdc2)
7445 hr = IDirectDraw7_CreateClipper(ddraw, 0, &clipper, NULL);
7446 ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr);
7447 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window2);
7448 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
7450 test_format = GetPixelFormat(hdc);
7451 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
7453 test_format = GetPixelFormat(hdc2);
7454 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
7457 memset(&ddsd, 0, sizeof(ddsd));
7458 ddsd.dwSize = sizeof(ddsd);
7459 ddsd.dwFlags = DDSD_CAPS;
7460 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
7462 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
7463 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
7465 test_format = GetPixelFormat(hdc);
7466 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
7468 if (hdc2)
7470 test_format = GetPixelFormat(hdc2);
7471 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
7474 if (clipper)
7476 hr = IDirectDrawSurface7_SetClipper(primary, clipper);
7477 ok(SUCCEEDED(hr), "Failed to set clipper, hr %#x.\n", hr);
7479 test_format = GetPixelFormat(hdc);
7480 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
7482 test_format = GetPixelFormat(hdc2);
7483 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
7486 memset(&fx, 0, sizeof(fx));
7487 fx.dwSize = sizeof(fx);
7488 hr = IDirectDrawSurface7_Blt(primary, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
7489 ok(SUCCEEDED(hr), "Failed to clear source surface, hr %#x.\n", hr);
7491 test_format = GetPixelFormat(hdc);
7492 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
7494 if (hdc2)
7496 test_format = GetPixelFormat(hdc2);
7497 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
7500 cleanup:
7501 if (primary) IDirectDrawSurface7_Release(primary);
7502 if (clipper) IDirectDrawClipper_Release(clipper);
7503 if (ddraw) IDirectDraw7_Release(ddraw);
7504 if (gl) FreeLibrary(gl);
7505 if (hdc) ReleaseDC(window, hdc);
7506 if (hdc2) ReleaseDC(window2, hdc2);
7507 if (window) DestroyWindow(window);
7508 if (window2) DestroyWindow(window2);
7511 static void test_create_surface_pitch(void)
7513 IDirectDrawSurface7 *surface;
7514 DDSURFACEDESC2 surface_desc;
7515 IDirectDraw7 *ddraw;
7516 unsigned int i;
7517 ULONG refcount;
7518 HWND window;
7519 HRESULT hr;
7520 void *mem;
7522 static const struct
7524 DWORD caps;
7525 DWORD flags_in;
7526 DWORD pitch_in;
7527 HRESULT hr;
7528 DWORD flags_out;
7529 DWORD pitch_out32;
7530 DWORD pitch_out64;
7532 test_data[] =
7534 /* 0 */
7535 {DDSCAPS_VIDEOMEMORY | DDSCAPS_OFFSCREENPLAIN,
7536 0, 0, DD_OK,
7537 DDSD_PITCH, 0x100, 0x100},
7538 {DDSCAPS_VIDEOMEMORY | DDSCAPS_OFFSCREENPLAIN,
7539 DDSD_PITCH, 0x104, DD_OK,
7540 DDSD_PITCH, 0x100, 0x100},
7541 {DDSCAPS_VIDEOMEMORY | DDSCAPS_OFFSCREENPLAIN,
7542 DDSD_PITCH, 0x0f8, DD_OK,
7543 DDSD_PITCH, 0x100, 0x100},
7544 {DDSCAPS_VIDEOMEMORY | DDSCAPS_OFFSCREENPLAIN,
7545 DDSD_LPSURFACE | DDSD_PITCH, 0x100, DDERR_INVALIDCAPS,
7546 0, 0, 0 },
7547 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
7548 0, 0, DD_OK,
7549 DDSD_PITCH, 0x100, 0x0fc},
7550 /* 5 */
7551 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
7552 DDSD_PITCH, 0x104, DD_OK,
7553 DDSD_PITCH, 0x100, 0x0fc},
7554 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
7555 DDSD_PITCH, 0x0f8, DD_OK,
7556 DDSD_PITCH, 0x100, 0x0fc},
7557 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
7558 DDSD_PITCH | DDSD_LINEARSIZE, 0, DD_OK,
7559 DDSD_PITCH, 0x100, 0x0fc},
7560 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
7561 DDSD_LPSURFACE, 0, DDERR_INVALIDPARAMS,
7562 0, 0, 0 },
7563 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
7564 DDSD_LPSURFACE | DDSD_PITCH, 0x100, DD_OK,
7565 DDSD_PITCH, 0x100, 0x100},
7566 /* 10 */
7567 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
7568 DDSD_LPSURFACE | DDSD_PITCH, 0x0fe, DDERR_INVALIDPARAMS,
7569 0, 0, 0 },
7570 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
7571 DDSD_LPSURFACE | DDSD_PITCH, 0x0fc, DD_OK,
7572 DDSD_PITCH, 0x0fc, 0x0fc},
7573 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
7574 DDSD_LPSURFACE | DDSD_PITCH, 0x0f8, DDERR_INVALIDPARAMS,
7575 0, 0, 0 },
7576 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
7577 DDSD_LPSURFACE | DDSD_LINEARSIZE, 0x100, DDERR_INVALIDPARAMS,
7578 0, 0, 0 },
7579 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
7580 DDSD_LPSURFACE | DDSD_LINEARSIZE, 0x3f00, DDERR_INVALIDPARAMS,
7581 0, 0, 0 },
7582 /* 15 */
7583 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
7584 DDSD_LPSURFACE | DDSD_PITCH | DDSD_LINEARSIZE, 0x100, DD_OK,
7585 DDSD_PITCH, 0x100, 0x100},
7586 {DDSCAPS_VIDEOMEMORY | DDSCAPS_OFFSCREENPLAIN | DDSCAPS_ALLOCONLOAD,
7587 0, 0, DDERR_INVALIDCAPS,
7588 0, 0, 0 },
7589 {DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD,
7590 0, 0, DD_OK,
7591 DDSD_PITCH, 0x100, 0 },
7592 {DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD,
7593 DDSD_LPSURFACE | DDSD_PITCH, 0x100, DDERR_INVALIDCAPS,
7594 0, 0, 0 },
7595 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN | DDSCAPS_ALLOCONLOAD,
7596 0, 0, DDERR_INVALIDCAPS,
7597 0, 0, 0 },
7598 /* 20 */
7599 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD,
7600 0, 0, DD_OK,
7601 DDSD_PITCH, 0x100, 0 },
7602 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD,
7603 DDSD_LPSURFACE | DDSD_PITCH, 0x100, DD_OK,
7604 DDSD_PITCH, 0x100, 0 },
7606 DWORD flags_mask = DDSD_PITCH | DDSD_LPSURFACE | DDSD_LINEARSIZE;
7608 window = create_window();
7609 ddraw = create_ddraw();
7610 ok(!!ddraw, "Failed to create a ddraw object.\n");
7611 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
7612 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
7614 mem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ((63 * 4) + 8) * 63);
7616 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
7618 memset(&surface_desc, 0, sizeof(surface_desc));
7619 surface_desc.dwSize = sizeof(surface_desc);
7620 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | test_data[i].flags_in;
7621 surface_desc.ddsCaps.dwCaps = test_data[i].caps;
7622 surface_desc.dwWidth = 63;
7623 surface_desc.dwHeight = 63;
7624 U1(surface_desc).lPitch = test_data[i].pitch_in;
7625 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
7626 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
7627 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
7628 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
7629 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
7630 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
7631 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7632 if (test_data[i].flags_in & DDSD_LPSURFACE)
7634 HRESULT expected_hr = SUCCEEDED(test_data[i].hr) ? DDERR_INVALIDPARAMS : test_data[i].hr;
7635 ok(hr == expected_hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, expected_hr);
7636 surface_desc.lpSurface = mem;
7637 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7639 if ((test_data[i].caps & DDSCAPS_VIDEOMEMORY) && hr == DDERR_NODIRECTDRAWHW)
7640 continue;
7641 if (is_ddraw64 && (test_data[i].caps & DDSCAPS_TEXTURE) && SUCCEEDED(test_data[i].hr))
7642 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Got unexpected hr %#x.\n", i, hr);
7643 else
7644 ok(hr == test_data[i].hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, test_data[i].hr);
7645 if (FAILED(hr))
7646 continue;
7648 memset(&surface_desc, 0, sizeof(surface_desc));
7649 surface_desc.dwSize = sizeof(surface_desc);
7650 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &surface_desc);
7651 ok(SUCCEEDED(hr), "Test %u: Failed to get surface desc, hr %#x.\n", i, hr);
7652 ok((surface_desc.dwFlags & flags_mask) == test_data[i].flags_out,
7653 "Test %u: Got unexpected flags %#x, expected %#x.\n",
7654 i, surface_desc.dwFlags & flags_mask, test_data[i].flags_out);
7655 /* The pitch for textures seems to be implementation specific. */
7656 if (!(test_data[i].caps & DDSCAPS_TEXTURE))
7658 if (is_ddraw64 && test_data[i].pitch_out32 != test_data[i].pitch_out64)
7659 todo_wine ok(U1(surface_desc).lPitch == test_data[i].pitch_out64,
7660 "Test %u: Got unexpected pitch %u, expected %u.\n",
7661 i, U1(surface_desc).lPitch, test_data[i].pitch_out64);
7662 else
7663 ok(U1(surface_desc).lPitch == test_data[i].pitch_out32,
7664 "Test %u: Got unexpected pitch %u, expected %u.\n",
7665 i, U1(surface_desc).lPitch, test_data[i].pitch_out32);
7667 ok(!surface_desc.lpSurface, "Test %u: Got unexpected lpSurface %p.\n", i, surface_desc.lpSurface);
7669 IDirectDrawSurface7_Release(surface);
7672 HeapFree(GetProcessHeap(), 0, mem);
7673 refcount = IDirectDraw7_Release(ddraw);
7674 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7675 DestroyWindow(window);
7678 static void test_mipmap(void)
7680 IDirectDrawSurface7 *surface, *surface2;
7681 DDSURFACEDESC2 surface_desc;
7682 IDirectDraw7 *ddraw;
7683 unsigned int i;
7684 ULONG refcount;
7685 HWND window;
7686 HRESULT hr;
7687 DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, {0}};
7688 DDCAPS hal_caps;
7690 static const struct
7692 DWORD flags;
7693 DWORD caps;
7694 DWORD width;
7695 DWORD height;
7696 DWORD mipmap_count_in;
7697 HRESULT hr;
7698 DWORD mipmap_count_out;
7700 tests[] =
7702 {DDSD_MIPMAPCOUNT, DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP, 128, 32, 3, DD_OK, 3},
7703 {DDSD_MIPMAPCOUNT, DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP, 128, 32, 0, DDERR_INVALIDPARAMS, 0},
7704 {0, DDSCAPS_TEXTURE | DDSCAPS_MIPMAP, 128, 32, 0, DD_OK, 1},
7705 {0, DDSCAPS_MIPMAP, 128, 32, 0, DDERR_INVALIDCAPS, 0},
7706 {0, DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP, 128, 32, 0, DD_OK, 8},
7707 {0, DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP, 32, 64, 0, DD_OK, 7},
7710 window = create_window();
7711 ddraw = create_ddraw();
7712 ok(!!ddraw, "Failed to create a ddraw object.\n");
7713 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
7714 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
7716 memset(&hal_caps, 0, sizeof(hal_caps));
7717 hal_caps.dwSize = sizeof(hal_caps);
7718 hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, NULL);
7719 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
7720 if ((hal_caps.ddsCaps.dwCaps & (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP)) != (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP)
7721 || is_ddraw64)
7723 skip("Mipmapped textures not supported, skipping tests.\n");
7724 IDirectDraw7_Release(ddraw);
7725 DestroyWindow(window);
7726 return;
7729 for (i = 0; i < ARRAY_SIZE(tests); ++i)
7731 memset(&surface_desc, 0, sizeof(surface_desc));
7732 surface_desc.dwSize = sizeof(surface_desc);
7733 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | tests[i].flags;
7734 surface_desc.ddsCaps.dwCaps = tests[i].caps;
7735 surface_desc.dwWidth = tests[i].width;
7736 surface_desc.dwHeight = tests[i].height;
7737 if (tests[i].flags & DDSD_MIPMAPCOUNT)
7738 U2(surface_desc).dwMipMapCount = tests[i].mipmap_count_in;
7739 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7740 ok(hr == tests[i].hr, "Test %u: Got unexpected hr %#x.\n", i, hr);
7741 if (FAILED(hr))
7742 continue;
7744 memset(&surface_desc, 0, sizeof(surface_desc));
7745 surface_desc.dwSize = sizeof(surface_desc);
7746 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &surface_desc);
7747 ok(SUCCEEDED(hr), "Test %u: Failed to get surface desc, hr %#x.\n", i, hr);
7748 ok(surface_desc.dwFlags & DDSD_MIPMAPCOUNT,
7749 "Test %u: Got unexpected flags %#x.\n", i, surface_desc.dwFlags);
7750 ok(U2(surface_desc).dwMipMapCount == tests[i].mipmap_count_out,
7751 "Test %u: Got unexpected mipmap count %u.\n", i, U2(surface_desc).dwMipMapCount);
7753 if (U2(surface_desc).dwMipMapCount > 1)
7755 hr = IDirectDrawSurface7_GetAttachedSurface(surface, &caps, &surface2);
7756 ok(SUCCEEDED(hr), "Test %u: Failed to get attached surface, hr %#x.\n", i, hr);
7758 memset(&surface_desc, 0, sizeof(surface_desc));
7759 surface_desc.dwSize = sizeof(surface_desc);
7760 hr = IDirectDrawSurface7_Lock(surface, NULL, &surface_desc, 0, NULL);
7761 ok(SUCCEEDED(hr), "Test %u: Failed to lock surface, hr %#x.\n", i, hr);
7762 memset(&surface_desc, 0, sizeof(surface_desc));
7763 surface_desc.dwSize = sizeof(surface_desc);
7764 hr = IDirectDrawSurface7_Lock(surface2, NULL, &surface_desc, 0, NULL);
7765 ok(SUCCEEDED(hr), "Test %u: Failed to lock surface, hr %#x.\n", i, hr);
7766 IDirectDrawSurface7_Unlock(surface2, NULL);
7767 IDirectDrawSurface7_Unlock(surface, NULL);
7769 IDirectDrawSurface7_Release(surface2);
7772 IDirectDrawSurface7_Release(surface);
7775 refcount = IDirectDraw7_Release(ddraw);
7776 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7777 DestroyWindow(window);
7780 static void test_palette_complex(void)
7782 IDirectDrawSurface7 *surface, *mipmap, *tmp;
7783 DDSURFACEDESC2 surface_desc;
7784 IDirectDraw7 *ddraw;
7785 IDirectDrawPalette *palette, *palette2;
7786 ULONG refcount;
7787 HWND window;
7788 HRESULT hr;
7789 DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, {0}};
7790 DDCAPS hal_caps;
7791 PALETTEENTRY palette_entries[256];
7792 unsigned int i;
7794 window = create_window();
7795 ddraw = create_ddraw();
7796 ok(!!ddraw, "Failed to create a ddraw object.\n");
7797 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
7798 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
7800 memset(&hal_caps, 0, sizeof(hal_caps));
7801 hal_caps.dwSize = sizeof(hal_caps);
7802 hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, NULL);
7803 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
7804 if ((hal_caps.ddsCaps.dwCaps & (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP)) != (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP)
7805 || is_ddraw64)
7807 skip("Mipmapped textures not supported, skipping mipmap palette test.\n");
7808 IDirectDraw7_Release(ddraw);
7809 DestroyWindow(window);
7810 return;
7813 memset(&surface_desc, 0, sizeof(surface_desc));
7814 surface_desc.dwSize = sizeof(surface_desc);
7815 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
7816 surface_desc.dwWidth = 128;
7817 surface_desc.dwHeight = 128;
7818 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
7819 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
7820 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
7821 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 8;
7822 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7823 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7825 memset(palette_entries, 0, sizeof(palette_entries));
7826 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
7827 palette_entries, &palette, NULL);
7828 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
7830 palette2 = (void *)0xdeadbeef;
7831 hr = IDirectDrawSurface7_GetPalette(surface, &palette2);
7832 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x.\n", hr);
7833 ok(!palette2, "Got unexpected palette %p.\n", palette2);
7834 hr = IDirectDrawSurface7_SetPalette(surface, palette);
7835 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
7836 hr = IDirectDrawSurface7_GetPalette(surface, &palette2);
7837 ok(SUCCEEDED(hr), "Failed to get palette, hr %#x.\n", hr);
7838 ok(palette == palette2, "Got unexpected palette %p.\n", palette2);
7839 IDirectDrawPalette_Release(palette2);
7841 mipmap = surface;
7842 IDirectDrawSurface7_AddRef(mipmap);
7843 for (i = 0; i < 7; ++i)
7845 hr = IDirectDrawSurface7_GetAttachedSurface(mipmap, &caps, &tmp);
7846 ok(SUCCEEDED(hr), "Failed to get attached surface, i %u, hr %#x.\n", i, hr);
7847 palette2 = (void *)0xdeadbeef;
7848 hr = IDirectDrawSurface7_GetPalette(tmp, &palette2);
7849 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x, i %u.\n", hr, i);
7850 ok(!palette2, "Got unexpected palette %p, i %u.\n", palette2, i);
7852 hr = IDirectDrawSurface7_SetPalette(tmp, palette);
7853 ok(hr == DDERR_NOTONMIPMAPSUBLEVEL, "Got unexpected hr %#x, i %u.\n", hr, i);
7855 hr = IDirectDrawSurface7_GetPalette(tmp, &palette2);
7856 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x, i %u.\n", hr, i);
7857 ok(!palette2, "Got unexpected palette %p, i %u.\n", palette2, i);
7859 /* Ddraw7 uses the palette of the mipmap for GetDC, just like previous
7860 * ddraw versions. Combined with the test results above this means no
7861 * palette is available. So depending on the driver either GetDC fails
7862 * or the DIB color table contains random data. */
7864 IDirectDrawSurface7_Release(mipmap);
7865 mipmap = tmp;
7868 hr = IDirectDrawSurface7_GetAttachedSurface(mipmap, &caps, &tmp);
7869 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
7870 IDirectDrawSurface7_Release(mipmap);
7871 refcount = IDirectDrawSurface7_Release(surface);
7872 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7874 /* Test DDERR_INVALIDPIXELFORMAT vs DDERR_NOTONMIPMAPSUBLEVEL. */
7875 memset(&surface_desc, 0, sizeof(surface_desc));
7876 surface_desc.dwSize = sizeof(surface_desc);
7877 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
7878 surface_desc.dwWidth = 128;
7879 surface_desc.dwHeight = 128;
7880 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
7881 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
7882 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
7883 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
7884 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
7885 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
7886 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
7887 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7888 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7890 hr = IDirectDrawSurface7_GetAttachedSurface(surface, &caps, &mipmap);
7891 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
7892 hr = IDirectDrawSurface7_SetPalette(mipmap, palette);
7893 ok(hr == DDERR_NOTONMIPMAPSUBLEVEL, "Got unexpected hr %#x.\n", hr);
7895 IDirectDrawSurface7_Release(mipmap);
7896 refcount = IDirectDrawSurface7_Release(surface);
7897 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7898 refcount = IDirectDrawPalette_Release(palette);
7899 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7901 refcount = IDirectDraw7_Release(ddraw);
7902 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7903 DestroyWindow(window);
7906 static void test_p8_blit(void)
7908 IDirectDrawSurface7 *src, *dst, *dst_p8;
7909 DDSURFACEDESC2 surface_desc;
7910 IDirectDraw7 *ddraw;
7911 IDirectDrawPalette *palette, *palette2;
7912 ULONG refcount;
7913 HWND window;
7914 HRESULT hr;
7915 PALETTEENTRY palette_entries[256];
7916 unsigned int x;
7917 DDBLTFX fx;
7918 BOOL is_warp;
7919 static const BYTE src_data[] = {0x10, 0x1, 0x2, 0x3, 0x4, 0x5, 0xff, 0x80};
7920 static const BYTE src_data2[] = {0x10, 0x5, 0x4, 0x3, 0x2, 0x1, 0xff, 0x80};
7921 static const BYTE expected_p8[] = {0x10, 0x1, 0x4, 0x3, 0x4, 0x5, 0xff, 0x80};
7922 static const D3DCOLOR expected[] =
7924 0x00101010, 0x00010101, 0x00020202, 0x00030303,
7925 0x00040404, 0x00050505, 0x00ffffff, 0x00808080,
7927 D3DCOLOR color;
7929 window = create_window();
7930 ddraw = create_ddraw();
7931 ok(!!ddraw, "Failed to create a ddraw object.\n");
7932 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
7933 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
7934 is_warp = ddraw_is_warp(ddraw);
7936 memset(palette_entries, 0, sizeof(palette_entries));
7937 palette_entries[1].peGreen = 0xff;
7938 palette_entries[2].peBlue = 0xff;
7939 palette_entries[3].peFlags = 0xff;
7940 palette_entries[4].peRed = 0xff;
7941 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
7942 palette_entries, &palette, NULL);
7943 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
7944 palette_entries[1].peBlue = 0xff;
7945 palette_entries[2].peGreen = 0xff;
7946 palette_entries[3].peRed = 0xff;
7947 palette_entries[4].peFlags = 0x0;
7948 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
7949 palette_entries, &palette2, NULL);
7950 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
7952 memset(&surface_desc, 0, sizeof(surface_desc));
7953 surface_desc.dwSize = sizeof(surface_desc);
7954 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
7955 surface_desc.dwWidth = 8;
7956 surface_desc.dwHeight = 1;
7957 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
7958 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
7959 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
7960 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 8;
7961 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &src, NULL);
7962 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7963 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &dst_p8, NULL);
7964 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7965 hr = IDirectDrawSurface7_SetPalette(dst_p8, palette2);
7966 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
7968 memset(&surface_desc, 0, sizeof(surface_desc));
7969 surface_desc.dwSize = sizeof(surface_desc);
7970 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
7971 surface_desc.dwWidth = 8;
7972 surface_desc.dwHeight = 1;
7973 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
7974 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
7975 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
7976 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
7977 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
7978 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
7979 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
7980 U5(U4(surface_desc).ddpfPixelFormat).dwRGBAlphaBitMask = 0xff000000;
7981 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &dst, NULL);
7982 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7984 memset(&surface_desc, 0, sizeof(surface_desc));
7985 surface_desc.dwSize = sizeof(surface_desc);
7986 hr = IDirectDrawSurface7_Lock(src, NULL, &surface_desc, DDLOCK_WAIT, NULL);
7987 ok(SUCCEEDED(hr), "Failed to lock source surface, hr %#x.\n", hr);
7988 memcpy(surface_desc.lpSurface, src_data, sizeof(src_data));
7989 hr = IDirectDrawSurface7_Unlock(src, NULL);
7990 ok(SUCCEEDED(hr), "Failed to unlock source surface, hr %#x.\n", hr);
7992 hr = IDirectDrawSurface7_Lock(dst_p8, NULL, &surface_desc, DDLOCK_WAIT, NULL);
7993 ok(SUCCEEDED(hr), "Failed to lock destination surface, hr %#x.\n", hr);
7994 memcpy(surface_desc.lpSurface, src_data2, sizeof(src_data2));
7995 hr = IDirectDrawSurface7_Unlock(dst_p8, NULL);
7996 ok(SUCCEEDED(hr), "Failed to unlock destination surface, hr %#x.\n", hr);
7998 hr = IDirectDrawSurface7_SetPalette(src, palette);
7999 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
8000 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_WAIT, NULL);
8001 /* The r500 Windows 7 driver returns E_NOTIMPL. r200 on Windows XP works.
8002 * The Geforce 7 driver on Windows Vista returns E_FAIL. Newer Nvidia GPUs work. */
8003 ok(SUCCEEDED(hr) || broken(hr == E_NOTIMPL) || broken(hr == E_FAIL),
8004 "Failed to blit, hr %#x.\n", hr);
8006 if (SUCCEEDED(hr))
8008 for (x = 0; x < ARRAY_SIZE(expected); ++x)
8010 color = get_surface_color(dst, x, 0);
8011 todo_wine ok(compare_color(color, expected[x], 0),
8012 "Pixel %u: Got color %#x, expected %#x.\n",
8013 x, color, expected[x]);
8017 memset(&fx, 0, sizeof(fx));
8018 fx.dwSize = sizeof(fx);
8019 fx.ddckSrcColorkey.dwColorSpaceHighValue = 0x2;
8020 fx.ddckSrcColorkey.dwColorSpaceLowValue = 0x2;
8021 hr = IDirectDrawSurface7_Blt(dst_p8, NULL, src, NULL, DDBLT_WAIT | DDBLT_KEYSRCOVERRIDE, &fx);
8022 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
8024 hr = IDirectDrawSurface7_Lock(dst_p8, NULL, &surface_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
8025 ok(SUCCEEDED(hr), "Failed to lock destination surface, hr %#x.\n", hr);
8026 /* A color keyed P8 blit doesn't do anything on WARP - it just leaves the data in the destination
8027 * surface untouched. P8 blits without color keys work. Error checking (DDBLT_KEYSRC without a key
8028 * for example) also works as expected.
8030 * Using DDBLT_KEYSRC instead of DDBLT_KEYSRCOVERRIDE doesn't change this. Doing this blit with
8031 * the display mode set to P8 doesn't help either. */
8032 ok(!memcmp(surface_desc.lpSurface, expected_p8, sizeof(expected_p8))
8033 || broken(is_warp && !memcmp(surface_desc.lpSurface, src_data2, sizeof(src_data2))),
8034 "Got unexpected P8 color key blit result.\n");
8035 hr = IDirectDrawSurface7_Unlock(dst_p8, NULL);
8036 ok(SUCCEEDED(hr), "Failed to unlock destination surface, hr %#x.\n", hr);
8038 IDirectDrawSurface7_Release(src);
8039 IDirectDrawSurface7_Release(dst);
8040 IDirectDrawSurface7_Release(dst_p8);
8041 IDirectDrawPalette_Release(palette);
8042 IDirectDrawPalette_Release(palette2);
8044 refcount = IDirectDraw7_Release(ddraw);
8045 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8046 DestroyWindow(window);
8049 static void test_material(void)
8051 static const D3DCOLORVALUE null_color;
8052 IDirect3DDevice7 *device;
8053 D3DMATERIAL7 material;
8054 ULONG refcount;
8055 HWND window;
8056 HRESULT hr;
8058 window = create_window();
8059 if (!(device = create_device(window, DDSCL_NORMAL)))
8061 skip("Failed to create a 3D device, skipping test.\n");
8062 DestroyWindow(window);
8063 return;
8066 hr = IDirect3DDevice7_GetMaterial(device, &material);
8067 ok(SUCCEEDED(hr), "Failed to get material, hr %#x.\n", hr);
8068 ok(!memcmp(&U(material).diffuse, &null_color, sizeof(null_color)),
8069 "Got unexpected diffuse color {%.8e, %.8e, %.8e, %.8e}.\n",
8070 U1(U(material).diffuse).r, U2(U(material).diffuse).g,
8071 U3(U(material).diffuse).b, U4(U(material).diffuse).a);
8072 ok(!memcmp(&U1(material).ambient, &null_color, sizeof(null_color)),
8073 "Got unexpected ambient color {%.8e, %.8e, %.8e, %.8e}.\n",
8074 U1(U1(material).ambient).r, U2(U1(material).ambient).g,
8075 U3(U1(material).ambient).b, U4(U1(material).ambient).a);
8076 ok(!memcmp(&U2(material).specular, &null_color, sizeof(null_color)),
8077 "Got unexpected specular color {%.8e, %.8e, %.8e, %.8e}.\n",
8078 U1(U2(material).specular).r, U2(U2(material).specular).g,
8079 U3(U2(material).specular).b, U4(U2(material).specular).a);
8080 ok(!memcmp(&U3(material).emissive, &null_color, sizeof(null_color)),
8081 "Got unexpected emissive color {%.8e, %.8e, %.8e, %.8e}.\n",
8082 U1(U3(material).emissive).r, U2(U3(material).emissive).g,
8083 U3(U3(material).emissive).b, U4(U3(material).emissive).a);
8084 ok(U4(material).power == 0.0f, "Got unexpected power %.8e.\n", U4(material).power);
8086 refcount = IDirect3DDevice7_Release(device);
8087 ok(!refcount, "Device has %u references left.\n", refcount);
8088 DestroyWindow(window);
8091 static void test_palette_gdi(void)
8093 IDirectDrawSurface7 *surface, *primary;
8094 DDSURFACEDESC2 surface_desc;
8095 IDirectDraw7 *ddraw;
8096 IDirectDrawPalette *palette, *palette2;
8097 ULONG refcount;
8098 HWND window;
8099 HRESULT hr;
8100 PALETTEENTRY palette_entries[256];
8101 UINT i;
8102 HDC dc;
8103 DDBLTFX fx;
8104 RECT r;
8105 COLORREF color;
8106 /* On the Windows 8 testbot palette index 0 of the onscreen palette is forced to
8107 * r = 0, g = 0, b = 0. Do not attempt to set it to something else as this is
8108 * not the point of this test. */
8109 static const RGBQUAD expected1[] =
8111 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
8112 {0x03, 0x00, 0x00, 0x00}, {0x15, 0x14, 0x13, 0x00},
8114 static const RGBQUAD expected2[] =
8116 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
8117 {0x03, 0x00, 0x00, 0x00}, {0x25, 0x24, 0x23, 0x00},
8119 static const RGBQUAD expected3[] =
8121 {0x00, 0x00, 0x00, 0x00}, {0x40, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x40, 0x00},
8122 {0x00, 0x40, 0x00, 0x00}, {0x56, 0x34, 0x12, 0x00},
8124 HPALETTE ddraw_palette_handle;
8125 /* Similar to index 0, index 255 is r = 0xff, g = 0xff, b = 0xff on the Win8 VMs. */
8126 RGBQUAD rgbquad[255];
8127 static const RGBQUAD rgb_zero = {0, 0, 0, 0};
8129 window = create_window();
8130 ddraw = create_ddraw();
8131 ok(!!ddraw, "Failed to create a ddraw object.\n");
8132 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
8133 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
8135 memset(&surface_desc, 0, sizeof(surface_desc));
8136 surface_desc.dwSize = sizeof(surface_desc);
8137 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
8138 surface_desc.dwWidth = 16;
8139 surface_desc.dwHeight = 16;
8140 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
8141 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
8142 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
8143 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 8;
8144 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8145 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8147 /* Avoid colors from the Windows default palette. */
8148 memset(palette_entries, 0, sizeof(palette_entries));
8149 palette_entries[1].peRed = 0x01;
8150 palette_entries[2].peGreen = 0x02;
8151 palette_entries[3].peBlue = 0x03;
8152 palette_entries[4].peRed = 0x13;
8153 palette_entries[4].peGreen = 0x14;
8154 palette_entries[4].peBlue = 0x15;
8155 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
8156 palette_entries, &palette, NULL);
8157 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
8159 /* If there is no palette assigned and the display mode is not 8 bpp, some
8160 * drivers refuse to create a DC while others allow it. If a DC is created,
8161 * the DIB color table is uninitialized and contains random colors. No error
8162 * is generated when trying to read pixels and random garbage is returned.
8164 * The most likely explanation is that if the driver creates a DC, it (or
8165 * the higher-level runtime) uses GetSystemPaletteEntries to find the
8166 * palette, but GetSystemPaletteEntries fails when bpp > 8 and the palette
8167 * contains uninitialized garbage. See comments below for the P8 case. */
8169 hr = IDirectDrawSurface7_SetPalette(surface, palette);
8170 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
8171 hr = IDirectDrawSurface7_GetDC(surface, &dc);
8172 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
8173 ddraw_palette_handle = SelectPalette(dc, GetStockObject(DEFAULT_PALETTE), FALSE);
8174 ok(ddraw_palette_handle == GetStockObject(DEFAULT_PALETTE),
8175 "Got unexpected palette %p, expected %p.\n",
8176 ddraw_palette_handle, GetStockObject(DEFAULT_PALETTE));
8178 i = GetDIBColorTable(dc, 0, ARRAY_SIZE(rgbquad), rgbquad);
8179 ok(i == ARRAY_SIZE(rgbquad), "Expected count 255, got %u.\n", i);
8180 for (i = 0; i < ARRAY_SIZE(expected1); ++i)
8182 ok(!memcmp(&rgbquad[i], &expected1[i], sizeof(rgbquad[i])),
8183 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8184 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
8185 expected1[i].rgbRed, expected1[i].rgbGreen, expected1[i].rgbBlue);
8187 for (; i < ARRAY_SIZE(rgbquad); ++i)
8189 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
8190 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
8191 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
8194 /* Update the palette while the DC is in use. This does not modify the DC. */
8195 palette_entries[4].peRed = 0x23;
8196 palette_entries[4].peGreen = 0x24;
8197 palette_entries[4].peBlue = 0x25;
8198 hr = IDirectDrawPalette_SetEntries(palette, 0, 4, 1, &palette_entries[4]);
8199 ok(SUCCEEDED(hr), "Failed to set palette entries, hr %#x.\n", hr);
8201 i = GetDIBColorTable(dc, 4, 1, &rgbquad[4]);
8202 ok(i == 1, "Expected count 1, got %u.\n", i);
8203 ok(!memcmp(&rgbquad[4], &expected1[4], sizeof(rgbquad[4])),
8204 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8205 i, rgbquad[4].rgbRed, rgbquad[4].rgbGreen, rgbquad[4].rgbBlue,
8206 expected1[4].rgbRed, expected1[4].rgbGreen, expected1[4].rgbBlue);
8208 /* Neither does re-setting the palette. */
8209 hr = IDirectDrawSurface7_SetPalette(surface, NULL);
8210 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
8211 hr = IDirectDrawSurface7_SetPalette(surface, palette);
8212 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
8214 i = GetDIBColorTable(dc, 4, 1, &rgbquad[4]);
8215 ok(i == 1, "Expected count 1, got %u.\n", i);
8216 ok(!memcmp(&rgbquad[4], &expected1[4], sizeof(rgbquad[4])),
8217 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8218 i, rgbquad[4].rgbRed, rgbquad[4].rgbGreen, rgbquad[4].rgbBlue,
8219 expected1[4].rgbRed, expected1[4].rgbGreen, expected1[4].rgbBlue);
8221 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
8222 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
8224 /* Refresh the DC. This updates the palette. */
8225 hr = IDirectDrawSurface7_GetDC(surface, &dc);
8226 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
8227 i = GetDIBColorTable(dc, 0, ARRAY_SIZE(rgbquad), rgbquad);
8228 ok(i == ARRAY_SIZE(rgbquad), "Expected count 255, got %u.\n", i);
8229 for (i = 0; i < ARRAY_SIZE(expected2); ++i)
8231 ok(!memcmp(&rgbquad[i], &expected2[i], sizeof(rgbquad[i])),
8232 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8233 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
8234 expected2[i].rgbRed, expected2[i].rgbGreen, expected2[i].rgbBlue);
8236 for (; i < ARRAY_SIZE(rgbquad); ++i)
8238 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
8239 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
8240 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
8242 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
8243 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
8245 refcount = IDirectDrawSurface7_Release(surface);
8246 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8248 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
8249 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
8250 if (FAILED(IDirectDraw7_SetDisplayMode(ddraw, 640, 480, 8, 0, 0)))
8252 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
8253 IDirectDrawPalette_Release(palette);
8254 IDirectDraw7_Release(ddraw);
8255 DestroyWindow(window);
8256 return;
8258 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
8260 memset(&surface_desc, 0, sizeof(surface_desc));
8261 surface_desc.dwSize = sizeof(surface_desc);
8262 surface_desc.dwFlags = DDSD_CAPS;
8263 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
8264 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &primary, NULL);
8265 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8267 memset(&fx, 0, sizeof(fx));
8268 fx.dwSize = sizeof(fx);
8269 U5(fx).dwFillColor = 3;
8270 SetRect(&r, 0, 0, 319, 479);
8271 hr = IDirectDrawSurface7_Blt(primary, &r, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
8272 ok(SUCCEEDED(hr), "Failed to clear surface, hr %#x.\n", hr);
8273 SetRect(&r, 320, 0, 639, 479);
8274 U5(fx).dwFillColor = 4;
8275 hr = IDirectDrawSurface7_Blt(primary, &r, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
8276 ok(SUCCEEDED(hr), "Failed to clear surface, hr %#x.\n", hr);
8278 hr = IDirectDrawSurface7_SetPalette(primary, palette);
8279 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
8280 hr = IDirectDrawSurface7_GetDC(primary, &dc);
8281 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
8283 color = GetPixel(dc, 160, 240);
8284 ok(color == 0x00030000, "Clear index 3: Got unexpected color 0x%08x.\n", color);
8285 color = GetPixel(dc, 480, 240);
8286 ok(color == 0x00252423, "Clear index 4: Got unexpected color 0x%08x.\n", color);
8288 ddraw_palette_handle = SelectPalette(dc, GetStockObject(DEFAULT_PALETTE), FALSE);
8289 ok(ddraw_palette_handle == GetStockObject(DEFAULT_PALETTE),
8290 "Got unexpected palette %p, expected %p.\n",
8291 ddraw_palette_handle, GetStockObject(DEFAULT_PALETTE));
8292 SelectPalette(dc, ddraw_palette_handle, FALSE);
8294 /* The primary uses the system palette. In exclusive mode, the system palette matches
8295 * the ddraw palette attached to the primary, so the result is what you would expect
8296 * from a regular surface. Tests for the interaction between the ddraw palette and
8297 * the system palette are not included pending an application that depends on this.
8298 * The relation between those causes problems on Windows Vista and newer for games
8299 * like Age of Empires or StarcCaft. Don't emulate it without a real need. */
8300 i = GetDIBColorTable(dc, 0, ARRAY_SIZE(rgbquad), rgbquad);
8301 ok(i == ARRAY_SIZE(rgbquad), "Expected count 255, got %u.\n", i);
8302 for (i = 0; i < ARRAY_SIZE(expected2); ++i)
8304 ok(!memcmp(&rgbquad[i], &expected2[i], sizeof(rgbquad[i])),
8305 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8306 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
8307 expected2[i].rgbRed, expected2[i].rgbGreen, expected2[i].rgbBlue);
8309 for (; i < ARRAY_SIZE(rgbquad); ++i)
8311 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
8312 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
8313 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
8315 hr = IDirectDrawSurface7_ReleaseDC(primary, dc);
8316 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
8318 memset(&surface_desc, 0, sizeof(surface_desc));
8319 surface_desc.dwSize = sizeof(surface_desc);
8320 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
8321 surface_desc.dwWidth = 16;
8322 surface_desc.dwHeight = 16;
8323 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
8324 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8325 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8327 /* Here the offscreen surface appears to use the primary's palette,
8328 * but in all likelihood it is actually the system palette. */
8329 hr = IDirectDrawSurface7_GetDC(surface, &dc);
8330 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
8331 i = GetDIBColorTable(dc, 0, ARRAY_SIZE(rgbquad), rgbquad);
8332 ok(i == ARRAY_SIZE(rgbquad), "Expected count 255, got %u.\n", i);
8333 for (i = 0; i < ARRAY_SIZE(expected2); ++i)
8335 ok(!memcmp(&rgbquad[i], &expected2[i], sizeof(rgbquad[i])),
8336 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8337 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
8338 expected2[i].rgbRed, expected2[i].rgbGreen, expected2[i].rgbBlue);
8340 for (; i < ARRAY_SIZE(rgbquad); ++i)
8342 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
8343 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
8344 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
8346 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
8347 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
8349 /* On real hardware a change to the primary surface's palette applies immediately,
8350 * even on device contexts from offscreen surfaces that do not have their own
8351 * palette. On the testbot VMs this is not the case. Don't test this until we
8352 * know of an application that depends on this. */
8354 memset(palette_entries, 0, sizeof(palette_entries));
8355 palette_entries[1].peBlue = 0x40;
8356 palette_entries[2].peRed = 0x40;
8357 palette_entries[3].peGreen = 0x40;
8358 palette_entries[4].peRed = 0x12;
8359 palette_entries[4].peGreen = 0x34;
8360 palette_entries[4].peBlue = 0x56;
8361 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
8362 palette_entries, &palette2, NULL);
8363 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
8364 hr = IDirectDrawSurface7_SetPalette(surface, palette2);
8365 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
8367 /* A palette assigned to the offscreen surface overrides the primary / system
8368 * palette. */
8369 hr = IDirectDrawSurface7_GetDC(surface, &dc);
8370 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
8371 i = GetDIBColorTable(dc, 0, ARRAY_SIZE(rgbquad), rgbquad);
8372 ok(i == ARRAY_SIZE(rgbquad), "Expected count 255, got %u.\n", i);
8373 for (i = 0; i < ARRAY_SIZE(expected3); ++i)
8375 ok(!memcmp(&rgbquad[i], &expected3[i], sizeof(rgbquad[i])),
8376 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8377 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
8378 expected3[i].rgbRed, expected3[i].rgbGreen, expected3[i].rgbBlue);
8380 for (; i < ARRAY_SIZE(rgbquad); ++i)
8382 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
8383 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
8384 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
8386 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
8387 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
8389 refcount = IDirectDrawSurface7_Release(surface);
8390 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8392 /* The Windows 8 testbot keeps extra references to the primary and
8393 * backbuffer while in 8 bpp mode. */
8394 hr = IDirectDraw7_RestoreDisplayMode(ddraw);
8395 ok(SUCCEEDED(hr), "Failed to restore display mode, hr %#x.\n", hr);
8397 refcount = IDirectDrawSurface7_Release(primary);
8398 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8399 refcount = IDirectDrawPalette_Release(palette2);
8400 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8401 refcount = IDirectDrawPalette_Release(palette);
8402 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8403 refcount = IDirectDraw7_Release(ddraw);
8404 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8405 DestroyWindow(window);
8408 static void test_palette_alpha(void)
8410 IDirectDrawSurface7 *surface;
8411 DDSURFACEDESC2 surface_desc;
8412 IDirectDraw7 *ddraw;
8413 IDirectDrawPalette *palette;
8414 ULONG refcount;
8415 HWND window;
8416 HRESULT hr;
8417 PALETTEENTRY palette_entries[256];
8418 unsigned int i;
8419 static const struct
8421 DWORD caps, flags;
8422 BOOL attach_allowed;
8423 const char *name;
8425 test_data[] =
8427 {DDSCAPS_OFFSCREENPLAIN, DDSD_WIDTH | DDSD_HEIGHT, FALSE, "offscreenplain"},
8428 {DDSCAPS_TEXTURE, DDSD_WIDTH | DDSD_HEIGHT, TRUE, "texture"},
8429 {DDSCAPS_PRIMARYSURFACE, 0, FALSE, "primary"}
8432 window = create_window();
8433 ddraw = create_ddraw();
8434 ok(!!ddraw, "Failed to create a ddraw object.\n");
8435 if (FAILED(IDirectDraw7_SetDisplayMode(ddraw, 640, 480, 8, 0, 0)))
8437 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
8438 IDirectDraw7_Release(ddraw);
8439 DestroyWindow(window);
8440 return;
8442 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
8443 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
8445 memset(palette_entries, 0, sizeof(palette_entries));
8446 palette_entries[1].peFlags = 0x42;
8447 palette_entries[2].peFlags = 0xff;
8448 palette_entries[3].peFlags = 0x80;
8449 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, palette_entries, &palette, NULL);
8450 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
8452 memset(palette_entries, 0x66, sizeof(palette_entries));
8453 hr = IDirectDrawPalette_GetEntries(palette, 0, 1, 4, palette_entries);
8454 ok(SUCCEEDED(hr), "Failed to get palette entries, hr %#x.\n", hr);
8455 ok(palette_entries[0].peFlags == 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
8456 palette_entries[0].peFlags);
8457 ok(palette_entries[1].peFlags == 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
8458 palette_entries[1].peFlags);
8459 ok(palette_entries[2].peFlags == 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
8460 palette_entries[2].peFlags);
8461 ok(palette_entries[3].peFlags == 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
8462 palette_entries[3].peFlags);
8464 IDirectDrawPalette_Release(palette);
8466 memset(palette_entries, 0, sizeof(palette_entries));
8467 palette_entries[1].peFlags = 0x42;
8468 palette_entries[1].peRed = 0xff;
8469 palette_entries[2].peFlags = 0xff;
8470 palette_entries[3].peFlags = 0x80;
8471 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_ALLOW256 | DDPCAPS_8BIT | DDPCAPS_ALPHA,
8472 palette_entries, &palette, NULL);
8473 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
8475 memset(palette_entries, 0x66, sizeof(palette_entries));
8476 hr = IDirectDrawPalette_GetEntries(palette, 0, 1, 4, palette_entries);
8477 ok(SUCCEEDED(hr), "Failed to get palette entries, hr %#x.\n", hr);
8478 ok(palette_entries[0].peFlags == 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
8479 palette_entries[0].peFlags);
8480 ok(palette_entries[1].peFlags == 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
8481 palette_entries[1].peFlags);
8482 ok(palette_entries[2].peFlags == 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
8483 palette_entries[2].peFlags);
8484 ok(palette_entries[3].peFlags == 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
8485 palette_entries[3].peFlags);
8487 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
8489 memset(&surface_desc, 0, sizeof(surface_desc));
8490 surface_desc.dwSize = sizeof(surface_desc);
8491 surface_desc.dwFlags = DDSD_CAPS | test_data[i].flags;
8492 surface_desc.dwWidth = 128;
8493 surface_desc.dwHeight = 128;
8494 surface_desc.ddsCaps.dwCaps = test_data[i].caps;
8495 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8496 ok(SUCCEEDED(hr), "Failed to create %s surface, hr %#x.\n", test_data[i].name, hr);
8498 hr = IDirectDrawSurface7_SetPalette(surface, palette);
8499 if (test_data[i].attach_allowed)
8500 ok(SUCCEEDED(hr), "Failed to attach palette to %s surface, hr %#x.\n", test_data[i].name, hr);
8501 else
8502 ok(hr == DDERR_INVALIDSURFACETYPE, "Got unexpected hr %#x, %s surface.\n", hr, test_data[i].name);
8504 if (SUCCEEDED(hr))
8506 HDC dc;
8507 RGBQUAD rgbquad;
8508 UINT retval;
8510 hr = IDirectDrawSurface7_GetDC(surface, &dc);
8511 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x, %s surface.\n", hr, test_data[i].name);
8512 retval = GetDIBColorTable(dc, 1, 1, &rgbquad);
8513 ok(retval == 1, "GetDIBColorTable returned unexpected result %u.\n", retval);
8514 ok(rgbquad.rgbRed == 0xff, "Expected rgbRed = 0xff, got %#x, %s surface.\n",
8515 rgbquad.rgbRed, test_data[i].name);
8516 ok(rgbquad.rgbGreen == 0, "Expected rgbGreen = 0, got %#x, %s surface.\n",
8517 rgbquad.rgbGreen, test_data[i].name);
8518 ok(rgbquad.rgbBlue == 0, "Expected rgbBlue = 0, got %#x, %s surface.\n",
8519 rgbquad.rgbBlue, test_data[i].name);
8520 ok(rgbquad.rgbReserved == 0, "Expected rgbReserved = 0, got %u, %s surface.\n",
8521 rgbquad.rgbReserved, test_data[i].name);
8522 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
8523 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
8525 IDirectDrawSurface7_Release(surface);
8528 /* Test INVALIDSURFACETYPE vs INVALIDPIXELFORMAT. */
8529 memset(&surface_desc, 0, sizeof(surface_desc));
8530 surface_desc.dwSize = sizeof(surface_desc);
8531 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
8532 surface_desc.dwWidth = 128;
8533 surface_desc.dwHeight = 128;
8534 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
8535 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
8536 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
8537 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
8538 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
8539 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
8540 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
8541 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8542 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8543 hr = IDirectDrawSurface7_SetPalette(surface, palette);
8544 ok(hr == DDERR_INVALIDSURFACETYPE, "Got unexpected hr %#x.\n", hr);
8545 IDirectDrawSurface7_Release(surface);
8547 /* The Windows 8 testbot keeps extra references to the primary
8548 * while in 8 bpp mode. */
8549 hr = IDirectDraw7_RestoreDisplayMode(ddraw);
8550 ok(SUCCEEDED(hr), "Failed to restore display mode, hr %#x.\n", hr);
8552 refcount = IDirectDrawPalette_Release(palette);
8553 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8554 refcount = IDirectDraw7_Release(ddraw);
8555 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8556 DestroyWindow(window);
8559 static void test_vb_writeonly(void)
8561 IDirect3DDevice7 *device;
8562 IDirect3D7 *d3d;
8563 IDirect3DVertexBuffer7 *buffer;
8564 HWND window;
8565 HRESULT hr;
8566 D3DVERTEXBUFFERDESC desc;
8567 void *ptr;
8568 static const struct vec4 quad[] =
8570 { 0.0f, 480.0f, 0.0f, 1.0f},
8571 { 0.0f, 0.0f, 0.0f, 1.0f},
8572 {640.0f, 480.0f, 0.0f, 1.0f},
8573 {640.0f, 0.0f, 0.0f, 1.0f},
8576 window = create_window();
8577 if (!(device = create_device(window, DDSCL_NORMAL)))
8579 skip("Failed to create a 3D device, skipping test.\n");
8580 DestroyWindow(window);
8581 return;
8584 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
8585 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
8587 memset(&desc, 0, sizeof(desc));
8588 desc.dwSize = sizeof(desc);
8589 desc.dwCaps = D3DVBCAPS_WRITEONLY;
8590 desc.dwFVF = D3DFVF_XYZRHW;
8591 desc.dwNumVertices = ARRAY_SIZE(quad);
8592 hr = IDirect3D7_CreateVertexBuffer(d3d, &desc, &buffer, 0);
8593 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
8595 hr = IDirect3DVertexBuffer7_Lock(buffer, DDLOCK_DISCARDCONTENTS, &ptr, NULL);
8596 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
8597 memcpy(ptr, quad, sizeof(quad));
8598 hr = IDirect3DVertexBuffer7_Unlock(buffer);
8599 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
8601 hr = IDirect3DDevice7_BeginScene(device);
8602 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
8603 hr = IDirect3DDevice7_DrawPrimitiveVB(device, D3DPT_TRIANGLESTRIP, buffer, 0, 4, 0);
8604 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
8605 hr = IDirect3DDevice7_EndScene(device);
8606 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
8608 hr = IDirect3DVertexBuffer7_Lock(buffer, 0, &ptr, NULL);
8609 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
8610 ok (!memcmp(ptr, quad, sizeof(quad)), "Got unexpected vertex buffer data.\n");
8611 hr = IDirect3DVertexBuffer7_Unlock(buffer);
8612 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
8614 hr = IDirect3DVertexBuffer7_Lock(buffer, DDLOCK_READONLY, &ptr, NULL);
8615 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
8616 ok (!memcmp(ptr, quad, sizeof(quad)), "Got unexpected vertex buffer data.\n");
8617 hr = IDirect3DVertexBuffer7_Unlock(buffer);
8618 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
8620 IDirect3DVertexBuffer7_Release(buffer);
8621 IDirect3D7_Release(d3d);
8622 IDirect3DDevice7_Release(device);
8623 DestroyWindow(window);
8626 static void test_lost_device(void)
8628 IDirectDrawSurface7 *surface;
8629 DDSURFACEDESC2 surface_desc;
8630 HWND window1, window2;
8631 IDirectDraw7 *ddraw;
8632 ULONG refcount;
8633 HRESULT hr;
8634 BOOL ret;
8636 window1 = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
8637 0, 0, 640, 480, 0, 0, 0, 0);
8638 window2 = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
8639 0, 0, 640, 480, 0, 0, 0, 0);
8640 ddraw = create_ddraw();
8641 ok(!!ddraw, "Failed to create a ddraw object.\n");
8642 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window1, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
8643 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
8645 memset(&surface_desc, 0, sizeof(surface_desc));
8646 surface_desc.dwSize = sizeof(surface_desc);
8647 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
8648 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
8649 U5(surface_desc).dwBackBufferCount = 1;
8650 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8651 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8653 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8654 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8655 hr = IDirectDrawSurface7_IsLost(surface);
8656 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8657 hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
8658 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8660 ret = SetForegroundWindow(GetDesktopWindow());
8661 ok(ret, "Failed to set foreground window.\n");
8662 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8663 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
8664 hr = IDirectDrawSurface7_IsLost(surface);
8665 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
8666 hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
8667 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
8669 ret = SetForegroundWindow(window1);
8670 ok(ret, "Failed to set foreground window.\n");
8671 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8672 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8673 hr = IDirectDrawSurface7_IsLost(surface);
8674 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
8675 hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
8676 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
8678 hr = IDirectDraw7_RestoreAllSurfaces(ddraw);
8679 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8680 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8681 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8682 hr = IDirectDrawSurface7_IsLost(surface);
8683 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8684 hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
8685 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8687 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window1, DDSCL_NORMAL);
8688 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8689 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8690 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8691 hr = IDirectDrawSurface7_IsLost(surface);
8692 todo_wine ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
8693 hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
8694 todo_wine ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
8696 /* Trying to restore the primary will crash, probably because flippable
8697 * surfaces can't exist in DDSCL_NORMAL. */
8698 IDirectDrawSurface7_Release(surface);
8699 memset(&surface_desc, 0, sizeof(surface_desc));
8700 surface_desc.dwSize = sizeof(surface_desc);
8701 surface_desc.dwFlags = DDSD_CAPS;
8702 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
8703 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8704 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8706 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8707 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8708 hr = IDirectDrawSurface7_IsLost(surface);
8709 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8711 ret = SetForegroundWindow(GetDesktopWindow());
8712 ok(ret, "Failed to set foreground window.\n");
8713 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8714 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8715 hr = IDirectDrawSurface7_IsLost(surface);
8716 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8718 ret = SetForegroundWindow(window1);
8719 ok(ret, "Failed to set foreground window.\n");
8720 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8721 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8722 hr = IDirectDrawSurface7_IsLost(surface);
8723 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8725 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window1, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
8726 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8727 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8728 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8729 hr = IDirectDrawSurface7_IsLost(surface);
8730 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
8732 hr = IDirectDraw7_RestoreAllSurfaces(ddraw);
8733 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8734 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8735 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8736 hr = IDirectDrawSurface7_IsLost(surface);
8737 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8739 IDirectDrawSurface7_Release(surface);
8740 memset(&surface_desc, 0, sizeof(surface_desc));
8741 surface_desc.dwSize = sizeof(surface_desc);
8742 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
8743 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
8744 U5(surface_desc).dwBackBufferCount = 1;
8745 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8746 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8748 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window1, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
8749 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8750 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8751 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8752 hr = IDirectDrawSurface7_IsLost(surface);
8753 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8754 hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
8755 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8757 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window1, DDSCL_NORMAL | DDSCL_FULLSCREEN);
8758 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8759 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8760 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8761 hr = IDirectDrawSurface7_IsLost(surface);
8762 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8763 hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
8764 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
8766 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window1, DDSCL_NORMAL);
8767 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8768 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8769 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8770 hr = IDirectDrawSurface7_IsLost(surface);
8771 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8772 hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
8773 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
8775 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window2, DDSCL_NORMAL);
8776 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8777 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8778 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8779 hr = IDirectDrawSurface7_IsLost(surface);
8780 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8781 hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
8782 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
8784 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window2, DDSCL_NORMAL | DDSCL_FULLSCREEN);
8785 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8786 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8787 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8788 hr = IDirectDrawSurface7_IsLost(surface);
8789 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8790 hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
8791 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
8793 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window2, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
8794 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8795 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8796 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8797 hr = IDirectDrawSurface7_IsLost(surface);
8798 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
8799 hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
8800 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
8802 IDirectDrawSurface7_Release(surface);
8803 refcount = IDirectDraw7_Release(ddraw);
8804 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8805 DestroyWindow(window2);
8806 DestroyWindow(window1);
8809 static void test_resource_priority(void)
8811 IDirectDrawSurface7 *surface, *mipmap;
8812 DDSURFACEDESC2 surface_desc;
8813 IDirectDraw7 *ddraw;
8814 ULONG refcount;
8815 HWND window;
8816 HRESULT hr;
8817 DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, {0}};
8818 DDCAPS hal_caps;
8819 DWORD needed_caps = DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_MIPMAP;
8820 unsigned int i;
8821 DWORD priority;
8822 static const struct
8824 DWORD caps, caps2;
8825 const char *name;
8826 HRESULT hr;
8827 /* SetPriority on offscreenplain surfaces crashes on AMD GPUs on Win7. */
8828 BOOL crash;
8830 test_data[] =
8832 {DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, 0, "vidmem texture", DDERR_INVALIDPARAMS, FALSE},
8833 {DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, 0, "sysmem texture", DDERR_INVALIDPARAMS, FALSE},
8834 {DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, "managed texture", DD_OK, FALSE},
8835 {DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, "managed texture", DD_OK, FALSE},
8836 {DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP,
8837 DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES | DDSCAPS2_TEXTUREMANAGE,
8838 "cubemap", DD_OK, FALSE},
8839 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0, "vidmem offscreenplain", DDERR_INVALIDOBJECT, TRUE},
8840 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY, 0, "sysmem offscreenplain", DDERR_INVALIDOBJECT, TRUE},
8843 window = create_window();
8844 ddraw = create_ddraw();
8845 ok(!!ddraw, "Failed to create a ddraw object.\n");
8846 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
8847 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
8849 memset(&hal_caps, 0, sizeof(hal_caps));
8850 hal_caps.dwSize = sizeof(hal_caps);
8851 hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, NULL);
8852 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
8853 if ((hal_caps.ddsCaps.dwCaps & needed_caps) != needed_caps
8854 || !(hal_caps.ddsCaps.dwCaps & DDSCAPS2_TEXTUREMANAGE))
8856 skip("Required surface types not supported, skipping test.\n");
8857 goto done;
8860 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
8862 memset(&surface_desc, 0, sizeof(surface_desc));
8863 surface_desc.dwSize = sizeof(surface_desc);
8864 surface_desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
8865 surface_desc.dwWidth = 32;
8866 surface_desc.dwHeight = 32;
8867 surface_desc.ddsCaps.dwCaps = test_data[i].caps;
8868 surface_desc.ddsCaps.dwCaps2 = test_data[i].caps2;
8869 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8870 if (is_ddraw64 && (test_data[i].caps & DDSCAPS_TEXTURE))
8872 todo_wine ok(hr == E_NOINTERFACE, "Got unexpected hr %#x, type %s.\n", hr, test_data[i].name);
8873 if (SUCCEEDED(hr))
8874 IDirectDrawSurface7_Release(surface);
8875 continue;
8877 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x, type %s.\n", hr, test_data[i].name);
8879 /* Priority == NULL segfaults. */
8880 priority = 0xdeadbeef;
8881 hr = IDirectDrawSurface7_GetPriority(surface, &priority);
8882 ok(hr == test_data[i].hr, "Got unexpected hr %#x, type %s.\n", hr, test_data[i].name);
8883 if (SUCCEEDED(test_data[i].hr))
8884 ok(priority == 0, "Got unexpected priority %u, type %s.\n", priority, test_data[i].name);
8885 else
8886 ok(priority == 0xdeadbeef, "Got unexpected priority %u, type %s.\n", priority, test_data[i].name);
8888 if (!test_data[i].crash)
8890 hr = IDirectDrawSurface7_SetPriority(surface, 1);
8891 ok(hr == test_data[i].hr, "Got unexpected hr %#x, type %s.\n", hr, test_data[i].name);
8892 hr = IDirectDrawSurface7_GetPriority(surface, &priority);
8893 ok(hr == test_data[i].hr, "Got unexpected hr %#x, type %s.\n", hr, test_data[i].name);
8894 if (SUCCEEDED(test_data[i].hr))
8896 ok(priority == 1, "Got unexpected priority %u, type %s.\n", priority, test_data[i].name);
8897 hr = IDirectDrawSurface7_SetPriority(surface, 2);
8898 ok(hr == test_data[i].hr, "Got unexpected hr %#x, type %s.\n", hr, test_data[i].name);
8900 else
8901 ok(priority == 0xdeadbeef, "Got unexpected priority %u, type %s.\n", priority, test_data[i].name);
8904 if (test_data[i].caps2 & DDSCAPS2_CUBEMAP)
8906 caps.dwCaps2 = DDSCAPS2_CUBEMAP_NEGATIVEZ;
8907 hr = IDirectDrawSurface7_GetAttachedSurface(surface, &caps, &mipmap);
8908 ok(SUCCEEDED(hr), "Failed to get attached surface, i %u, hr %#x.\n", i, hr);
8909 /* IDirectDrawSurface7_SetPriority crashes when called on non-positive X surfaces on Windows */
8910 priority = 0xdeadbeef;
8911 hr = IDirectDrawSurface7_GetPriority(mipmap, &priority);
8912 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x, type %s.\n", hr, test_data[i].name);
8913 ok(priority == 0xdeadbeef, "Got unexpected priority %u, type %s.\n", priority, test_data[i].name);
8915 IDirectDrawSurface7_Release(mipmap);
8918 IDirectDrawSurface7_Release(surface);
8921 if (is_ddraw64)
8922 goto done;
8924 memset(&surface_desc, 0, sizeof(surface_desc));
8925 surface_desc.dwSize = sizeof(surface_desc);
8926 surface_desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_MIPMAPCOUNT;
8927 surface_desc.dwWidth = 32;
8928 surface_desc.dwHeight = 32;
8929 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
8930 surface_desc.ddsCaps.dwCaps2 = DDSCAPS2_TEXTUREMANAGE;
8931 U2(surface_desc).dwMipMapCount = 2;
8932 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8933 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8934 caps.dwCaps2 = 0;
8935 hr = IDirectDrawSurface7_GetAttachedSurface(surface, &caps, &mipmap);
8936 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
8938 priority = 0xdeadbeef;
8939 hr = IDirectDrawSurface7_GetPriority(mipmap, &priority);
8940 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x, type managed mipmap.\n", hr);
8941 ok(priority == 0xdeadbeef, "Got unexpected priority %u, type managed mipmap.\n", priority);
8942 /* SetPriority on the mipmap surface crashes. */
8943 hr = IDirectDrawSurface7_GetPriority(surface, &priority);
8944 ok(SUCCEEDED(hr), "Failed to get priority, hr %#x.\n", hr);
8945 ok(priority == 0, "Got unexpected priority %u, type managed mipmap.\n", priority);
8947 IDirectDrawSurface7_Release(mipmap);
8948 refcount = IDirectDrawSurface7_Release(surface);
8949 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8951 done:
8952 refcount = IDirectDraw7_Release(ddraw);
8953 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8954 DestroyWindow(window);
8957 static void test_surface_desc_lock(void)
8959 IDirectDrawSurface7 *surface;
8960 DDSURFACEDESC2 surface_desc;
8961 IDirectDraw7 *ddraw;
8962 ULONG refcount;
8963 HWND window;
8964 HRESULT hr;
8966 window = create_window();
8967 ddraw = create_ddraw();
8968 ok(!!ddraw, "Failed to create a ddraw object.\n");
8969 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
8970 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
8972 memset(&surface_desc, 0, sizeof(surface_desc));
8973 surface_desc.dwSize = sizeof(surface_desc);
8974 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
8975 surface_desc.dwWidth = 16;
8976 surface_desc.dwHeight = 16;
8977 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
8978 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8979 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8981 memset(&surface_desc, 0xaa, sizeof(surface_desc));
8982 surface_desc.dwSize = sizeof(surface_desc);
8983 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &surface_desc);
8984 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
8985 ok(!surface_desc.lpSurface, "Got unexpected lpSurface %p.\n", surface_desc.lpSurface);
8987 memset(&surface_desc, 0xaa, sizeof(surface_desc));
8988 surface_desc.dwSize = sizeof(surface_desc);
8989 hr = IDirectDrawSurface7_Lock(surface, NULL, &surface_desc, 0, NULL);
8990 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
8991 ok(surface_desc.lpSurface != NULL, "Got unexpected lpSurface %p.\n", surface_desc.lpSurface);
8992 memset(&surface_desc, 0xaa, sizeof(surface_desc));
8993 surface_desc.dwSize = sizeof(surface_desc);
8994 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &surface_desc);
8995 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
8996 ok(!surface_desc.lpSurface, "Got unexpected lpSurface %p.\n", surface_desc.lpSurface);
8997 hr = IDirectDrawSurface7_Unlock(surface, NULL);
8998 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
9000 memset(&surface_desc, 0xaa, sizeof(surface_desc));
9001 surface_desc.dwSize = sizeof(surface_desc);
9002 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &surface_desc);
9003 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
9004 ok(!surface_desc.lpSurface, "Got unexpected lpSurface %p.\n", surface_desc.lpSurface);
9006 IDirectDrawSurface7_Release(surface);
9007 refcount = IDirectDraw7_Release(ddraw);
9008 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
9009 DestroyWindow(window);
9012 static void test_fog_interpolation(void)
9014 HRESULT hr;
9015 IDirect3DDevice7 *device;
9016 IDirectDrawSurface7 *rt;
9017 ULONG refcount;
9018 HWND window;
9019 D3DCOLOR color;
9020 static struct
9022 struct vec3 position;
9023 D3DCOLOR diffuse;
9024 D3DCOLOR specular;
9026 quad[] =
9028 {{-1.0f, -1.0f, 0.0f}, 0xffff0000, 0xff000000},
9029 {{-1.0f, 1.0f, 0.0f}, 0xffff0000, 0xff000000},
9030 {{ 1.0f, -1.0f, 1.0f}, 0xffff0000, 0x00000000},
9031 {{ 1.0f, 1.0f, 1.0f}, 0xffff0000, 0x00000000},
9033 union
9035 DWORD d;
9036 float f;
9037 } conv;
9038 unsigned int i;
9039 static const struct
9041 D3DFOGMODE vfog, tfog;
9042 D3DSHADEMODE shade;
9043 D3DCOLOR middle_color;
9044 BOOL todo;
9046 tests[] =
9048 {D3DFOG_NONE, D3DFOG_NONE, D3DSHADE_FLAT, 0x00007f80, FALSE},
9049 {D3DFOG_NONE, D3DFOG_NONE, D3DSHADE_GOURAUD, 0x00007f80, FALSE},
9050 {D3DFOG_EXP, D3DFOG_NONE, D3DSHADE_FLAT, 0x00007f80, TRUE},
9051 {D3DFOG_EXP, D3DFOG_NONE, D3DSHADE_GOURAUD, 0x00007f80, TRUE},
9052 {D3DFOG_NONE, D3DFOG_EXP, D3DSHADE_FLAT, 0x0000ea15, FALSE},
9053 {D3DFOG_NONE, D3DFOG_EXP, D3DSHADE_GOURAUD, 0x0000ea15, FALSE},
9054 {D3DFOG_EXP, D3DFOG_EXP, D3DSHADE_FLAT, 0x0000ea15, FALSE},
9055 {D3DFOG_EXP, D3DFOG_EXP, D3DSHADE_GOURAUD, 0x0000ea15, FALSE},
9057 D3DDEVICEDESC7 caps;
9059 window = create_window();
9060 if (!(device = create_device(window, DDSCL_NORMAL)))
9062 skip("Failed to create a 3D device, skipping test.\n");
9063 DestroyWindow(window);
9064 return;
9067 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
9068 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
9069 hr = IDirect3DDevice7_GetCaps(device, &caps);
9070 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
9071 if (!(caps.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGTABLE))
9072 skip("D3DPRASTERCAPS_FOGTABLE not supported, skipping some fog tests\n");
9074 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
9075 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9076 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, FALSE);
9077 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9078 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, TRUE);
9079 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9080 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGCOLOR, 0x0000ff00);
9081 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9082 conv.f = 5.0;
9083 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGDENSITY, conv.d);
9084 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9086 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
9087 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
9088 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TFACTOR);
9089 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
9090 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_TEXTUREFACTOR, 0x000000ff);
9091 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9093 for (i = 0; i < ARRAY_SIZE(tests); ++i)
9095 if (!(caps.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGTABLE) && tests[i].tfog)
9096 continue;
9098 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00808080, 0.0f, 0);
9099 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
9101 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_SHADEMODE, tests[i].shade);
9102 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9103 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGVERTEXMODE, tests[i].vfog);
9104 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9105 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGTABLEMODE, tests[i].tfog);
9106 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9107 hr = IDirect3DDevice7_BeginScene(device);
9108 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
9109 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
9110 D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_SPECULAR, quad, 4, 0);
9111 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9112 hr = IDirect3DDevice7_EndScene(device);
9113 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
9115 color = get_surface_color(rt, 0, 240);
9116 ok(compare_color(color, 0x000000ff, 2), "Got unexpected color 0x%08x, case %u.\n", color, i);
9117 color = get_surface_color(rt, 320, 240);
9118 todo_wine_if (tests[i].todo)
9119 ok(compare_color(color, tests[i].middle_color, 2),
9120 "Got unexpected color 0x%08x, case %u.\n", color, i);
9121 color = get_surface_color(rt, 639, 240);
9122 ok(compare_color(color, 0x0000fd02, 2), "Got unexpected color 0x%08x, case %u.\n", color, i);
9125 IDirectDrawSurface7_Release(rt);
9126 refcount = IDirect3DDevice7_Release(device);
9127 ok(!refcount, "Device has %u references left.\n", refcount);
9128 DestroyWindow(window);
9131 static void test_negative_fixedfunction_fog(void)
9133 HRESULT hr;
9134 IDirect3DDevice7 *device;
9135 IDirectDrawSurface7 *rt;
9136 ULONG refcount;
9137 HWND window;
9138 D3DCOLOR color;
9139 static struct
9141 struct vec3 position;
9142 D3DCOLOR diffuse;
9144 quad[] =
9146 {{-1.0f, -1.0f, -0.5f}, 0xffff0000},
9147 {{-1.0f, 1.0f, -0.5f}, 0xffff0000},
9148 {{ 1.0f, -1.0f, -0.5f}, 0xffff0000},
9149 {{ 1.0f, 1.0f, -0.5f}, 0xffff0000},
9151 static struct
9153 struct vec4 position;
9154 D3DCOLOR diffuse;
9156 tquad[] =
9158 {{ 0.0f, 0.0f, -0.5f, 1.0f}, 0xffff0000},
9159 {{640.0f, 0.0f, -0.5f, 1.0f}, 0xffff0000},
9160 {{ 0.0f, 480.0f, -0.5f, 1.0f}, 0xffff0000},
9161 {{640.0f, 480.0f, -0.5f, 1.0f}, 0xffff0000},
9163 unsigned int i;
9164 static D3DMATRIX zero =
9166 1.0f, 0.0f, 0.0f, 0.0f,
9167 0.0f, 1.0f, 0.0f, 0.0f,
9168 0.0f, 0.0f, 0.0f, 0.0f,
9169 0.0f, 0.0f, 0.0f, 1.0f
9171 static D3DMATRIX identity =
9173 1.0f, 0.0f, 0.0f, 0.0f,
9174 0.0f, 1.0f, 0.0f, 0.0f,
9175 0.0f, 0.0f, 1.0f, 0.0f,
9176 0.0f, 0.0f, 0.0f, 1.0f
9178 static const struct
9180 DWORD pos_type;
9181 void *quad;
9182 D3DMATRIX *matrix;
9183 union
9185 float f;
9186 DWORD d;
9187 } start, end;
9188 D3DFOGMODE vfog, tfog;
9189 DWORD color, color_broken, color_broken2;
9191 tests[] =
9193 /* Run the XYZRHW tests first. Depth clamping is broken after RHW draws on the testbot.
9195 * Geforce8+ GPUs on Windows abs() table fog, everything else does not. */
9196 {D3DFVF_XYZRHW, tquad, &identity, { 0.0f}, {1.0f}, D3DFOG_NONE, D3DFOG_LINEAR,
9197 0x00ff0000, 0x00808000, 0x00808000},
9198 /* r200 GPUs and presumably all d3d8 and older HW clamp the fog
9199 * parameters to 0.0 and 1.0 in the table fog case. */
9200 {D3DFVF_XYZRHW, tquad, &identity, {-1.0f}, {0.0f}, D3DFOG_NONE, D3DFOG_LINEAR,
9201 0x00808000, 0x00ff0000, 0x0000ff00},
9202 /* test_fog_interpolation shows that vertex fog evaluates the fog
9203 * equation in the vertex pipeline. Start = -1.0 && end = 0.0 shows
9204 * that the abs happens before the fog equation is evaluated.
9206 * Vertex fog abs() behavior is the same on all GPUs. */
9207 {D3DFVF_XYZ, quad, &zero, { 0.0f}, {1.0f}, D3DFOG_LINEAR, D3DFOG_NONE,
9208 0x00808000, 0x00808000, 0x00808000},
9209 {D3DFVF_XYZ, quad, &zero, {-1.0f}, {0.0f}, D3DFOG_LINEAR, D3DFOG_NONE,
9210 0x0000ff00, 0x0000ff00, 0x0000ff00},
9211 {D3DFVF_XYZ, quad, &zero, { 0.0f}, {1.0f}, D3DFOG_EXP, D3DFOG_NONE,
9212 0x009b6400, 0x009b6400, 0x009b6400},
9214 D3DDEVICEDESC7 caps;
9216 window = create_window();
9217 if (!(device = create_device(window, DDSCL_NORMAL)))
9219 skip("Failed to create a 3D device, skipping test.\n");
9220 DestroyWindow(window);
9221 return;
9224 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
9225 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
9226 hr = IDirect3DDevice7_GetCaps(device, &caps);
9227 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
9228 if (!(caps.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGTABLE))
9229 skip("D3DPRASTERCAPS_FOGTABLE not supported, skipping some fog tests.\n");
9231 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
9232 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9233 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
9234 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9235 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, TRUE);
9236 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9237 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGCOLOR, 0x0000ff00);
9238 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9239 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CLIPPING, FALSE);
9240 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
9242 for (i = 0; i < ARRAY_SIZE(tests); ++i)
9244 if (!(caps.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGTABLE) && tests[i].tfog)
9245 continue;
9247 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x000000ff, 0.0f, 0);
9248 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
9250 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, tests[i].matrix);
9251 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
9252 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGSTART, tests[i].start.d);
9253 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9254 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGEND, tests[i].end.d);
9255 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9256 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGVERTEXMODE, tests[i].vfog);
9257 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9258 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGTABLEMODE, tests[i].tfog);
9259 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9261 hr = IDirect3DDevice7_BeginScene(device);
9262 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
9263 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
9264 tests[i].pos_type | D3DFVF_DIFFUSE, tests[i].quad, 4, 0);
9265 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9266 hr = IDirect3DDevice7_EndScene(device);
9267 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
9269 color = get_surface_color(rt, 0, 240);
9270 ok(compare_color(color, tests[i].color, 2) || broken(compare_color(color, tests[i].color_broken, 2))
9271 || broken(compare_color(color, tests[i].color_broken2, 2)),
9272 "Got unexpected color 0x%08x, case %u.\n", color, i);
9275 IDirectDrawSurface7_Release(rt);
9276 refcount = IDirect3DDevice7_Release(device);
9277 ok(!refcount, "Device has %u references left.\n", refcount);
9278 DestroyWindow(window);
9281 static void test_table_fog_zw(void)
9283 HRESULT hr;
9284 IDirect3DDevice7 *device;
9285 IDirectDrawSurface7 *rt;
9286 ULONG refcount;
9287 HWND window;
9288 D3DCOLOR color;
9289 static struct
9291 struct vec4 position;
9292 D3DCOLOR diffuse;
9294 quad[] =
9296 {{ 0.0f, 0.0f, 0.0f, 0.0f}, 0xffff0000},
9297 {{640.0f, 0.0f, 0.0f, 0.0f}, 0xffff0000},
9298 {{ 0.0f, 480.0f, 0.0f, 0.0f}, 0xffff0000},
9299 {{640.0f, 480.0f, 0.0f, 0.0f}, 0xffff0000},
9301 static D3DMATRIX identity =
9303 1.0f, 0.0f, 0.0f, 0.0f,
9304 0.0f, 1.0f, 0.0f, 0.0f,
9305 0.0f, 0.0f, 1.0f, 0.0f,
9306 0.0f, 0.0f, 0.0f, 1.0f
9308 D3DDEVICEDESC7 caps;
9309 static const struct
9311 float z, w;
9312 D3DZBUFFERTYPE z_test;
9313 D3DCOLOR color;
9315 tests[] =
9317 {0.7f, 0.0f, D3DZB_TRUE, 0x004cb200},
9318 {0.7f, 0.0f, D3DZB_FALSE, 0x004cb200},
9319 {0.7f, 0.3f, D3DZB_TRUE, 0x004cb200},
9320 {0.7f, 0.3f, D3DZB_FALSE, 0x004cb200},
9321 {0.7f, 3.0f, D3DZB_TRUE, 0x004cb200},
9322 {0.7f, 3.0f, D3DZB_FALSE, 0x004cb200},
9323 {0.3f, 0.0f, D3DZB_TRUE, 0x00b24c00},
9324 {0.3f, 0.0f, D3DZB_FALSE, 0x00b24c00},
9326 unsigned int i;
9328 window = create_window();
9329 if (!(device = create_device(window, DDSCL_NORMAL)))
9331 skip("Failed to create a 3D device, skipping test.\n");
9332 DestroyWindow(window);
9333 return;
9336 hr = IDirect3DDevice7_GetCaps(device, &caps);
9337 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
9338 if (!(caps.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGTABLE))
9340 skip("D3DPRASTERCAPS_FOGTABLE not supported, skipping POSITIONT table fog test.\n");
9341 goto done;
9343 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
9344 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
9346 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
9347 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9348 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, TRUE);
9349 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9350 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGCOLOR, 0x0000ff00);
9351 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9352 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CLIPPING, FALSE);
9353 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
9354 /* Work around an AMD Windows driver bug. Needs a proj matrix applied redundantly. */
9355 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &identity);
9356 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
9357 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGTABLEMODE, D3DFOG_LINEAR);
9358 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9360 for (i = 0; i < ARRAY_SIZE(tests); ++i)
9362 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x000000ff, 1.0f, 0);
9363 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
9365 quad[0].position.z = tests[i].z;
9366 quad[1].position.z = tests[i].z;
9367 quad[2].position.z = tests[i].z;
9368 quad[3].position.z = tests[i].z;
9369 quad[0].position.w = tests[i].w;
9370 quad[1].position.w = tests[i].w;
9371 quad[2].position.w = tests[i].w;
9372 quad[3].position.w = tests[i].w;
9373 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, tests[i].z_test);
9374 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9376 hr = IDirect3DDevice7_BeginScene(device);
9377 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
9378 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
9379 D3DFVF_XYZRHW | D3DFVF_DIFFUSE, quad, 4, 0);
9380 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9381 hr = IDirect3DDevice7_EndScene(device);
9382 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
9384 color = get_surface_color(rt, 0, 240);
9385 ok(compare_color(color, tests[i].color, 2),
9386 "Got unexpected color 0x%08x, expected 0x%8x, case %u.\n", color, tests[i].color, i);
9389 IDirectDrawSurface7_Release(rt);
9390 done:
9391 refcount = IDirect3DDevice7_Release(device);
9392 ok(!refcount, "Device has %u references left.\n", refcount);
9393 DestroyWindow(window);
9396 static void test_signed_formats(void)
9398 HRESULT hr;
9399 IDirect3DDevice7 *device;
9400 IDirect3D7 *d3d;
9401 IDirectDraw7 *ddraw;
9402 IDirectDrawSurface7 *surface, *rt;
9403 DDSURFACEDESC2 surface_desc;
9404 ULONG refcount;
9405 HWND window;
9406 D3DCOLOR color, expected_color;
9407 static struct
9409 struct vec3 position;
9410 struct vec2 texcoord;
9412 quad[] =
9414 {{-1.0f, -1.0f, 0.0f}, {0.0f, 1.0f}},
9415 {{-1.0f, 1.0f, 0.0f}, {0.0f, 0.0f}},
9416 {{ 1.0f, -1.0f, 0.0f}, {1.0f, 1.0f}},
9417 {{ 1.0f, 1.0f, 0.0f}, {1.0f, 0.0f}},
9419 /* See test_signed_formats() in dlls/d3d9/tests/visual.c for an explanation
9420 * of these values. */
9421 static const USHORT content_v8u8[4][4] =
9423 {0x0000, 0x7f7f, 0x8880, 0x0000},
9424 {0x0080, 0x8000, 0x7f00, 0x007f},
9425 {0x193b, 0xe8c8, 0x0808, 0xf8f8},
9426 {0x4444, 0xc0c0, 0xa066, 0x22e0},
9428 static const DWORD content_x8l8v8u8[4][4] =
9430 {0x00000000, 0x00ff7f7f, 0x00008880, 0x00ff0000},
9431 {0x00000080, 0x00008000, 0x00007f00, 0x0000007f},
9432 {0x0041193b, 0x0051e8c8, 0x00040808, 0x00fff8f8},
9433 {0x00824444, 0x0000c0c0, 0x00c2a066, 0x009222e0},
9435 static const USHORT content_l6v5u5[4][4] =
9437 {0x0000, 0xfdef, 0x0230, 0xfc00},
9438 {0x0010, 0x0200, 0x01e0, 0x000f},
9439 {0x4067, 0x53b9, 0x0421, 0xffff},
9440 {0x8108, 0x0318, 0xc28c, 0x909c},
9442 static const struct
9444 const char *name;
9445 const void *content;
9446 SIZE_T pixel_size;
9447 BOOL blue;
9448 unsigned int slop, slop_broken;
9449 DDPIXELFORMAT format;
9451 formats[] =
9454 "D3DFMT_V8U8", content_v8u8, sizeof(WORD), FALSE, 1, 0,
9456 sizeof(DDPIXELFORMAT), DDPF_BUMPDUDV, 0,
9457 {16}, {0x000000ff}, {0x0000ff00}, {0x00000000}, {0x00000000}
9461 "D3DFMT_X8L8V8U8", content_x8l8v8u8, sizeof(DWORD), TRUE, 1, 0,
9463 sizeof(DDPIXELFORMAT), DDPF_BUMPDUDV | DDPF_BUMPLUMINANCE, 0,
9464 {32}, {0x000000ff}, {0x0000ff00}, {0x00ff0000}, {0x00000000}
9468 "D3DFMT_L6V5U5", content_l6v5u5, sizeof(WORD), TRUE, 4, 7,
9470 sizeof(DDPIXELFORMAT), DDPF_BUMPDUDV | DDPF_BUMPLUMINANCE, 0,
9471 {16}, {0x0000001f}, {0x000003e0}, {0x0000fc00}, {0x00000000}
9475 /* No V16U16 or Q8W8V8U8 support in ddraw. */
9477 static const D3DCOLOR expected_colors[4][4] =
9479 {0x00808080, 0x00fefeff, 0x00010780, 0x008080ff},
9480 {0x00018080, 0x00800180, 0x0080fe80, 0x00fe8080},
9481 {0x00ba98a0, 0x004767a8, 0x00888881, 0x007878ff},
9482 {0x00c3c3c0, 0x003f3f80, 0x00e51fe1, 0x005fa2c8},
9484 unsigned int i, width, x, y;
9485 D3DDEVICEDESC7 device_desc;
9487 window = create_window();
9488 if (!(device = create_device(window, DDSCL_NORMAL)))
9490 skip("Failed to create a 3D device, skipping test.\n");
9491 DestroyWindow(window);
9492 return;
9495 hr = IDirect3DDevice7_GetCaps(device, &device_desc);
9496 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
9497 if (!(device_desc.dwTextureOpCaps & D3DTEXOPCAPS_BLENDFACTORALPHA))
9499 skip("D3DTOP_BLENDFACTORALPHA not supported, skipping bumpmap format tests.\n");
9500 goto done;
9503 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
9504 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
9505 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
9506 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
9507 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
9508 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
9510 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
9511 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9513 /* dst = tex * 0.5 + 1.0 * (1.0 - 0.5) = tex * 0.5 + 0.5 */
9514 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_TEXTUREFACTOR, 0x80ffffff);
9515 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9516 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_BLENDFACTORALPHA);
9517 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
9518 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
9519 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
9520 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLORARG2, D3DTA_TFACTOR);
9521 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
9523 for (i = 0; i < ARRAY_SIZE(formats); ++i)
9525 for (width = 1; width < 5; width += 3)
9527 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00000000, 0.0f, 0);
9528 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
9530 memset(&surface_desc, 0, sizeof(surface_desc));
9531 surface_desc.dwSize = sizeof(surface_desc);
9532 surface_desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS;
9533 surface_desc.dwWidth = width;
9534 surface_desc.dwHeight = 4;
9535 U4(surface_desc).ddpfPixelFormat = formats[i].format;
9536 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY;
9537 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
9538 if (FAILED(hr))
9540 skip("%s textures not supported, skipping.\n", formats[i].name);
9541 continue;
9543 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x, format %s.\n", hr, formats[i].name);
9544 hr = IDirect3DDevice7_SetTexture(device, 0, surface);
9545 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x, format %s.\n", hr, formats[i].name);
9547 memset(&surface_desc, 0, sizeof(surface_desc));
9548 surface_desc.dwSize = sizeof(surface_desc);
9549 hr = IDirectDrawSurface7_Lock(surface, NULL, &surface_desc, 0, NULL);
9550 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x, format %s.\n", hr, formats[i].name);
9551 for (y = 0; y < 4; y++)
9553 memcpy((char *)surface_desc.lpSurface + y * U1(surface_desc).lPitch,
9554 (char *)formats[i].content + y * 4 * formats[i].pixel_size,
9555 width * formats[i].pixel_size);
9557 hr = IDirectDrawSurface7_Unlock(surface, NULL);
9558 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, format %s.\n", hr, formats[i].name);
9560 hr = IDirect3DDevice7_BeginScene(device);
9561 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
9562 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
9563 D3DFVF_XYZ | D3DFVF_TEX1, quad, 4, 0);
9564 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9565 hr = IDirect3DDevice7_EndScene(device);
9566 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
9568 for (y = 0; y < 4; y++)
9570 for (x = 0; x < width; x++)
9572 expected_color = expected_colors[y][x];
9573 if (!formats[i].blue)
9574 expected_color |= 0x000000ff;
9576 color = get_surface_color(rt, 80 + 160 * x, 60 + 120 * y);
9577 ok(compare_color(color, expected_color, formats[i].slop)
9578 || broken(compare_color(color, expected_color, formats[i].slop_broken)),
9579 "Expected color 0x%08x, got 0x%08x, format %s, location %ux%u.\n",
9580 expected_color, color, formats[i].name, x, y);
9584 IDirectDrawSurface7_Release(surface);
9589 IDirectDrawSurface7_Release(rt);
9590 IDirectDraw7_Release(ddraw);
9591 IDirect3D7_Release(d3d);
9593 done:
9594 refcount = IDirect3DDevice7_Release(device);
9595 ok(!refcount, "Device has %u references left.\n", refcount);
9596 DestroyWindow(window);
9599 static void test_color_fill(void)
9601 HRESULT hr;
9602 IDirect3DDevice7 *device;
9603 IDirect3D7 *d3d;
9604 IDirectDraw7 *ddraw;
9605 IDirectDrawSurface7 *surface, *surface2;
9606 DDSURFACEDESC2 surface_desc;
9607 DDPIXELFORMAT z_fmt;
9608 ULONG refcount;
9609 HWND window;
9610 unsigned int i;
9611 DDBLTFX fx;
9612 RECT rect = {5, 5, 7, 7};
9613 DWORD *color;
9614 DWORD supported_fmts = 0, num_fourcc_codes, *fourcc_codes;
9615 DDCAPS hal_caps;
9616 static const struct
9618 DWORD caps, caps2;
9619 HRESULT colorfill_hr, depthfill_hr;
9620 BOOL rop_success;
9621 const char *name;
9622 DWORD result;
9623 BOOL check_result;
9624 DDPIXELFORMAT format;
9626 tests[] =
9629 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0,
9630 DD_OK, DDERR_INVALIDPARAMS, TRUE, "vidmem offscreenplain RGB", 0xdeadbeef, TRUE,
9632 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
9633 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9637 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY, 0,
9638 DD_OK, DDERR_INVALIDPARAMS, TRUE, "sysmem offscreenplain RGB", 0xdeadbeef, TRUE,
9640 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
9641 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9645 DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, 0,
9646 DD_OK, DDERR_INVALIDPARAMS, TRUE, "vidmem texture RGB", 0xdeadbeef, TRUE,
9648 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
9649 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9653 DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, 0,
9654 DD_OK, DDERR_INVALIDPARAMS, TRUE, "sysmem texture RGB", 0xdeadbeef, TRUE,
9656 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
9657 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9661 DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE,
9662 DD_OK, DDERR_INVALIDPARAMS, TRUE, "managed texture RGB", 0xdeadbeef, TRUE,
9664 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
9665 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9669 DDSCAPS_ZBUFFER | DDSCAPS_VIDEOMEMORY, 0,
9670 DDERR_INVALIDPARAMS, DD_OK, TRUE, "vidmem zbuffer", 0xdeadbeef, TRUE,
9671 {0, 0, 0, {0}, {0}, {0}, {0}, {0}}
9674 DDSCAPS_ZBUFFER | DDSCAPS_SYSTEMMEMORY, 0,
9675 DDERR_INVALIDPARAMS, DD_OK, TRUE, "sysmem zbuffer", 0xdeadbeef, TRUE,
9676 {0, 0, 0, {0}, {0}, {0}, {0}, {0}}
9679 /* Colorfill on YUV surfaces always returns DD_OK, but the content is
9680 * different afterwards. DX9+ GPUs set one of the two luminance values
9681 * in each block, but AMD and Nvidia GPUs disagree on which luminance
9682 * value they set. r200 (dx8) just sets the entire block to the clear
9683 * value. */
9684 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0,
9685 DD_OK, DDERR_INVALIDPARAMS, FALSE, "vidmem offscreenplain YUY2", 0, FALSE,
9687 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y', 'U', 'Y', '2'),
9688 {0}, {0}, {0}, {0}, {0}
9692 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0,
9693 DD_OK, DDERR_INVALIDPARAMS, FALSE, "vidmem offscreenplain UYVY", 0, FALSE,
9695 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('U', 'Y', 'V', 'Y'),
9696 {0}, {0}, {0}, {0}, {0}
9700 DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY, 0,
9701 DD_OK, DDERR_INVALIDPARAMS, FALSE, "vidmem overlay YUY2", 0, FALSE,
9703 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y', 'U', 'Y', '2'),
9704 {0}, {0}, {0}, {0}, {0}
9708 DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY, 0,
9709 DD_OK, DDERR_INVALIDPARAMS, FALSE, "vidmem overlay UYVY", 0, FALSE,
9711 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('U', 'Y', 'V', 'Y'),
9712 {0}, {0}, {0}, {0}, {0}
9716 DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, 0,
9717 E_NOTIMPL, DDERR_INVALIDPARAMS, FALSE, "vidmem texture DXT1", 0, FALSE,
9719 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('D', 'X', 'T', '1'),
9720 {0}, {0}, {0}, {0}, {0}
9724 DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, 0,
9725 E_NOTIMPL, DDERR_INVALIDPARAMS, FALSE, "sysmem texture DXT1", 0, FALSE,
9727 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('D', 'X', 'T', '1'),
9728 {0}, {0}, {0}, {0}, {0}
9732 /* The testbot fills this with 0x00 instead of the blue channel. The sysmem
9733 * surface works, presumably because it is handled by the runtime instead of
9734 * the driver. */
9735 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0,
9736 DD_OK, DDERR_INVALIDPARAMS, TRUE, "vidmem offscreenplain P8", 0xefefefef, FALSE,
9738 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_PALETTEINDEXED8, 0,
9739 {8}, {0}, {0}, {0}, {0}
9743 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY, 0,
9744 DD_OK, DDERR_INVALIDPARAMS, TRUE, "sysmem offscreenplain P8", 0xefefefef, TRUE,
9746 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_PALETTEINDEXED8, 0,
9747 {8}, {0}, {0}, {0}, {0}
9751 static const struct
9753 DWORD rop;
9754 const char *name;
9755 HRESULT hr;
9757 rops[] =
9759 {SRCCOPY, "SRCCOPY", DD_OK},
9760 {SRCPAINT, "SRCPAINT", DDERR_NORASTEROPHW},
9761 {SRCAND, "SRCAND", DDERR_NORASTEROPHW},
9762 {SRCINVERT, "SRCINVERT", DDERR_NORASTEROPHW},
9763 {SRCERASE, "SRCERASE", DDERR_NORASTEROPHW},
9764 {NOTSRCCOPY, "NOTSRCCOPY", DDERR_NORASTEROPHW},
9765 {NOTSRCERASE, "NOTSRCERASE", DDERR_NORASTEROPHW},
9766 {MERGECOPY, "MERGECOPY", DDERR_NORASTEROPHW},
9767 {MERGEPAINT, "MERGEPAINT", DDERR_NORASTEROPHW},
9768 {PATCOPY, "PATCOPY", DDERR_NORASTEROPHW},
9769 {PATPAINT, "PATPAINT", DDERR_NORASTEROPHW},
9770 {PATINVERT, "PATINVERT", DDERR_NORASTEROPHW},
9771 {DSTINVERT, "DSTINVERT", DDERR_NORASTEROPHW},
9772 {BLACKNESS, "BLACKNESS", DD_OK},
9773 {WHITENESS, "WHITENESS", DD_OK},
9774 {0xaa0029, "0xaa0029", DDERR_NORASTEROPHW} /* noop */
9777 window = create_window();
9778 if (!(device = create_device(window, DDSCL_NORMAL)))
9780 skip("Failed to create a 3D device, skipping test.\n");
9781 DestroyWindow(window);
9782 return;
9785 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
9786 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
9787 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
9788 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
9790 memset(&z_fmt, 0, sizeof(z_fmt));
9791 IDirect3D7_EnumZBufferFormats(d3d, &IID_IDirect3DHALDevice, enum_z_fmt, &z_fmt);
9792 if (!z_fmt.dwSize)
9793 skip("No Z buffer formats supported, skipping Z buffer colorfill test.\n");
9795 IDirect3DDevice7_EnumTextureFormats(device, test_block_formats_creation_cb, &supported_fmts);
9796 if (!(supported_fmts & SUPPORT_DXT1))
9797 skip("DXT1 textures not supported, skipping DXT1 colorfill test.\n");
9799 IDirect3D7_Release(d3d);
9801 hr = IDirectDraw7_GetFourCCCodes(ddraw, &num_fourcc_codes, NULL);
9802 ok(SUCCEEDED(hr), "Failed to get fourcc codes %#x.\n", hr);
9803 fourcc_codes = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
9804 num_fourcc_codes * sizeof(*fourcc_codes));
9805 if (!fourcc_codes)
9806 goto done;
9807 hr = IDirectDraw7_GetFourCCCodes(ddraw, &num_fourcc_codes, fourcc_codes);
9808 ok(SUCCEEDED(hr), "Failed to get fourcc codes %#x.\n", hr);
9809 for (i = 0; i < num_fourcc_codes; i++)
9811 if (fourcc_codes[i] == MAKEFOURCC('Y', 'U', 'Y', '2'))
9812 supported_fmts |= SUPPORT_YUY2;
9813 else if (fourcc_codes[i] == MAKEFOURCC('U', 'Y', 'V', 'Y'))
9814 supported_fmts |= SUPPORT_UYVY;
9816 HeapFree(GetProcessHeap(), 0, fourcc_codes);
9818 memset(&hal_caps, 0, sizeof(hal_caps));
9819 hal_caps.dwSize = sizeof(hal_caps);
9820 hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, NULL);
9821 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
9823 if (!(supported_fmts & (SUPPORT_YUY2 | SUPPORT_UYVY)) || !(hal_caps.dwCaps & DDCAPS_OVERLAY))
9824 skip("Overlays or some YUV formats not supported, skipping YUV colorfill tests.\n");
9826 for (i = 0; i < ARRAY_SIZE(tests); ++i)
9828 DWORD expected_broken = tests[i].result;
9830 /* Some Windows drivers modify dwFillColor when it is used on P8 or FourCC formats. */
9831 memset(&fx, 0, sizeof(fx));
9832 fx.dwSize = sizeof(fx);
9833 U5(fx).dwFillColor = 0xdeadbeef;
9835 memset(&surface_desc, 0, sizeof(surface_desc));
9836 surface_desc.dwSize = sizeof(surface_desc);
9837 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
9838 surface_desc.dwWidth = 64;
9839 surface_desc.dwHeight = 64;
9840 U4(surface_desc).ddpfPixelFormat = tests[i].format;
9841 surface_desc.ddsCaps.dwCaps = tests[i].caps;
9842 surface_desc.ddsCaps.dwCaps2 = tests[i].caps2;
9844 if (tests[i].format.dwFourCC == MAKEFOURCC('D','X','T','1') && !(supported_fmts & SUPPORT_DXT1))
9845 continue;
9846 if (tests[i].format.dwFourCC == MAKEFOURCC('Y','U','Y','2') && !(supported_fmts & SUPPORT_YUY2))
9847 continue;
9848 if (tests[i].format.dwFourCC == MAKEFOURCC('U','Y','V','Y') && !(supported_fmts & SUPPORT_UYVY))
9849 continue;
9850 if (tests[i].caps & DDSCAPS_OVERLAY && !(hal_caps.dwCaps & DDCAPS_OVERLAY))
9851 continue;
9853 if (tests[i].caps & DDSCAPS_ZBUFFER)
9855 if (!z_fmt.dwSize)
9856 continue;
9858 U4(surface_desc).ddpfPixelFormat = z_fmt;
9859 /* Some drivers seem to convert depth values incorrectly or not at
9860 * all. Affects at least AMD PALM, 8.17.10.1247. */
9861 if (tests[i].caps & DDSCAPS_VIDEOMEMORY)
9863 DWORD expected;
9864 float f, g;
9866 expected = tests[i].result & U3(z_fmt).dwZBitMask;
9867 f = ceilf(log2f(expected + 1.0f));
9868 g = (f + 1.0f) / 2.0f;
9869 g -= (int)g;
9870 expected_broken = (expected / exp2f(f) - g) * 256;
9871 expected_broken *= 0x01010101;
9875 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
9876 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x, surface %s.\n", hr, tests[i].name);
9878 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
9879 todo_wine_if (tests[i].format.dwFourCC)
9880 ok(hr == tests[i].colorfill_hr, "Blt returned %#x, expected %#x, surface %s.\n",
9881 hr, tests[i].colorfill_hr, tests[i].name);
9883 hr = IDirectDrawSurface7_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
9884 todo_wine_if (tests[i].format.dwFourCC)
9885 ok(hr == tests[i].colorfill_hr, "Blt returned %#x, expected %#x, surface %s.\n",
9886 hr, tests[i].colorfill_hr, tests[i].name);
9888 if (SUCCEEDED(hr) && tests[i].check_result)
9890 memset(&surface_desc, 0, sizeof(surface_desc));
9891 surface_desc.dwSize = sizeof(surface_desc);
9892 hr = IDirectDrawSurface7_Lock(surface, NULL, &surface_desc, DDLOCK_READONLY, 0);
9893 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x, surface %s.\n", hr, tests[i].name);
9894 color = surface_desc.lpSurface;
9895 ok(*color == tests[i].result, "Got clear result 0x%08x, expected 0x%08x, surface %s.\n",
9896 *color, tests[i].result, tests[i].name);
9897 hr = IDirectDrawSurface7_Unlock(surface, NULL);
9898 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, surface %s.\n", hr, tests[i].name);
9901 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
9902 ok(hr == tests[i].depthfill_hr, "Blt returned %#x, expected %#x, surface %s.\n",
9903 hr, tests[i].depthfill_hr, tests[i].name);
9904 hr = IDirectDrawSurface7_Blt(surface, &rect, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
9905 ok(hr == tests[i].depthfill_hr, "Blt returned %#x, expected %#x, surface %s.\n",
9906 hr, tests[i].depthfill_hr, tests[i].name);
9908 if (SUCCEEDED(hr) && tests[i].check_result)
9910 memset(&surface_desc, 0, sizeof(surface_desc));
9911 surface_desc.dwSize = sizeof(surface_desc);
9912 hr = IDirectDrawSurface7_Lock(surface, NULL, &surface_desc, DDLOCK_READONLY, 0);
9913 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x, surface %s.\n", hr, tests[i].name);
9914 color = surface_desc.lpSurface;
9915 ok((*color & U3(z_fmt).dwZBitMask) == (tests[i].result & U3(z_fmt).dwZBitMask)
9916 || broken((*color & U3(z_fmt).dwZBitMask) == (expected_broken & U3(z_fmt).dwZBitMask)),
9917 "Got clear result 0x%08x, expected 0x%08x, surface %s.\n",
9918 *color & U3(z_fmt).dwZBitMask, tests[i].result & U3(z_fmt).dwZBitMask, tests[i].name);
9919 hr = IDirectDrawSurface7_Unlock(surface, NULL);
9920 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, surface %s.\n", hr, tests[i].name);
9923 U5(fx).dwFillColor = 0xdeadbeef;
9924 fx.dwROP = BLACKNESS;
9925 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_ROP | DDBLT_WAIT, &fx);
9926 ok(FAILED(hr) == !tests[i].rop_success, "Blt returned %#x, expected %s, surface %s.\n",
9927 hr, tests[i].rop_success ? "success" : "failure", tests[i].name);
9928 ok(U5(fx).dwFillColor == 0xdeadbeef, "dwFillColor was set to 0x%08x, surface %s\n",
9929 U5(fx).dwFillColor, tests[i].name);
9931 if (SUCCEEDED(hr) && tests[i].check_result)
9933 memset(&surface_desc, 0, sizeof(surface_desc));
9934 surface_desc.dwSize = sizeof(surface_desc);
9935 hr = IDirectDrawSurface7_Lock(surface, NULL, &surface_desc, DDLOCK_READONLY, 0);
9936 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x, surface %s.\n", hr, tests[i].name);
9937 color = surface_desc.lpSurface;
9938 ok(*color == 0, "Got clear result 0x%08x, expected 0x00000000, surface %s.\n",
9939 *color, tests[i].name);
9940 hr = IDirectDrawSurface7_Unlock(surface, NULL);
9941 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, surface %s.\n", hr, tests[i].name);
9944 fx.dwROP = WHITENESS;
9945 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_ROP | DDBLT_WAIT, &fx);
9946 ok(FAILED(hr) == !tests[i].rop_success, "Blt returned %#x, expected %s, surface %s.\n",
9947 hr, tests[i].rop_success ? "success" : "failure", tests[i].name);
9948 ok(U5(fx).dwFillColor == 0xdeadbeef, "dwFillColor was set to 0x%08x, surface %s\n",
9949 U5(fx).dwFillColor, tests[i].name);
9951 if (SUCCEEDED(hr) && tests[i].check_result)
9953 memset(&surface_desc, 0, sizeof(surface_desc));
9954 surface_desc.dwSize = sizeof(surface_desc);
9955 hr = IDirectDrawSurface7_Lock(surface, NULL, &surface_desc, DDLOCK_READONLY, 0);
9956 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x, surface %s.\n", hr, tests[i].name);
9957 color = surface_desc.lpSurface;
9958 /* WHITENESS sets the alpha channel to 0x00. Ignore this for now. */
9959 ok((*color & 0x00ffffff) == 0x00ffffff, "Got clear result 0x%08x, expected 0xffffffff, surface %s.\n",
9960 *color, tests[i].name);
9961 hr = IDirectDrawSurface7_Unlock(surface, NULL);
9962 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, surface %s.\n", hr, tests[i].name);
9965 IDirectDrawSurface7_Release(surface);
9968 memset(&fx, 0, sizeof(fx));
9969 fx.dwSize = sizeof(fx);
9970 U5(fx).dwFillColor = 0xdeadbeef;
9971 fx.dwROP = WHITENESS;
9973 memset(&surface_desc, 0, sizeof(surface_desc));
9974 surface_desc.dwSize = sizeof(surface_desc);
9975 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
9976 surface_desc.dwWidth = 64;
9977 surface_desc.dwHeight = 64;
9978 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
9979 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
9980 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
9981 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
9982 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
9983 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
9984 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
9985 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
9986 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
9987 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface2, NULL);
9988 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
9990 /* No DDBLTFX. */
9991 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_COLORFILL | DDBLT_WAIT, NULL);
9992 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
9993 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_ROP | DDBLT_WAIT, NULL);
9994 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
9996 /* Unused source rectangle. */
9997 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
9998 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
9999 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_ROP | DDBLT_WAIT, &fx);
10000 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10002 /* Unused source surface. */
10003 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
10004 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10005 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, NULL, DDBLT_ROP | DDBLT_WAIT, &fx);
10006 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10007 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
10008 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10009 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, &rect, DDBLT_ROP | DDBLT_WAIT, &fx);
10010 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10012 /* Inverted destination or source rectangle. */
10013 SetRect(&rect, 5, 7, 7, 5);
10014 hr = IDirectDrawSurface7_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
10015 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
10016 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
10017 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10018 hr = IDirectDrawSurface7_Blt(surface, &rect, surface2, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
10019 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10020 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
10021 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10022 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, &rect, DDBLT_ROP | DDBLT_WAIT, &fx);
10023 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
10025 /* Negative rectangle. */
10026 SetRect(&rect, -1, -1, 5, 5);
10027 hr = IDirectDrawSurface7_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
10028 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
10029 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
10030 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10031 hr = IDirectDrawSurface7_Blt(surface, &rect, surface2, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
10032 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10033 hr = IDirectDrawSurface7_Blt(surface, &rect, surface2, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
10034 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10035 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, &rect, DDBLT_ROP | DDBLT_WAIT, &fx);
10036 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
10038 /* Out of bounds rectangle. */
10039 SetRect(&rect, 0, 0, 65, 65);
10040 hr = IDirectDrawSurface7_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
10041 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
10042 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, &rect, DDBLT_ROP | DDBLT_WAIT, &fx);
10043 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
10045 /* Combine multiple flags. */
10046 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
10047 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10048 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_ROP | DDBLT_WAIT, &fx);
10049 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10050 hr = IDirectDrawSurface7_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_ROP | DDBLT_WAIT, &fx);
10051 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10053 for (i = 0; i < ARRAY_SIZE(rops); ++i)
10055 fx.dwROP = rops[i].rop;
10056 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, NULL, DDBLT_ROP | DDBLT_WAIT, &fx);
10057 ok(hr == rops[i].hr, "Got unexpected hr %#x for rop %s.\n", hr, rops[i].name);
10060 IDirectDrawSurface7_Release(surface2);
10061 IDirectDrawSurface7_Release(surface);
10063 if (!z_fmt.dwSize)
10064 goto done;
10066 memset(&surface_desc, 0, sizeof(surface_desc));
10067 surface_desc.dwSize = sizeof(surface_desc);
10068 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
10069 surface_desc.dwWidth = 64;
10070 surface_desc.dwHeight = 64;
10071 U4(surface_desc).ddpfPixelFormat = z_fmt;
10072 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
10073 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
10074 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
10075 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface2, NULL);
10076 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
10078 /* No DDBLTFX. */
10079 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, NULL);
10080 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10082 /* Unused source rectangle. */
10083 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
10084 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10086 /* Unused source surface. */
10087 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
10088 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10089 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
10090 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10092 /* Inverted destination or source rectangle. */
10093 SetRect(&rect, 5, 7, 7, 5);
10094 hr = IDirectDrawSurface7_Blt(surface, &rect, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
10095 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
10096 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
10097 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10098 hr = IDirectDrawSurface7_Blt(surface, &rect, surface2, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
10099 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10100 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
10101 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10103 /* Negative rectangle. */
10104 SetRect(&rect, -1, -1, 5, 5);
10105 hr = IDirectDrawSurface7_Blt(surface, &rect, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
10106 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
10107 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
10108 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10109 hr = IDirectDrawSurface7_Blt(surface, &rect, surface2, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
10110 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10111 hr = IDirectDrawSurface7_Blt(surface, &rect, surface2, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
10112 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10114 /* Out of bounds rectangle. */
10115 SetRect(&rect, 0, 0, 65, 65);
10116 hr = IDirectDrawSurface7_Blt(surface, &rect, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
10117 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
10119 /* Combine multiple flags. */
10120 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
10121 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10123 IDirectDrawSurface7_Release(surface2);
10124 IDirectDrawSurface7_Release(surface);
10126 done:
10127 IDirectDraw7_Release(ddraw);
10128 refcount = IDirect3DDevice7_Release(device);
10129 ok(!refcount, "Device has %u references left.\n", refcount);
10130 DestroyWindow(window);
10133 static void test_texcoordindex(void)
10135 static D3DMATRIX mat =
10137 1.0f, 0.0f, 0.0f, 0.0f,
10138 0.0f, 0.0f, 0.0f, 0.0f,
10139 0.0f, 0.0f, 0.0f, 0.0f,
10140 0.0f, 0.0f, 0.0f, 0.0f,
10142 static struct
10144 struct vec3 pos;
10145 struct vec2 texcoord1;
10146 struct vec2 texcoord2;
10147 struct vec2 texcoord3;
10149 quad[] =
10151 {{-1.0f, -1.0f, 0.0f}, {0.0f, 1.0f}, {0.0f, 0.0f}, {1.0f, 1.0f}},
10152 {{-1.0f, 1.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 1.0f}, {1.0f, 0.0f}},
10153 {{ 1.0f, -1.0f, 0.0f}, {1.0f, 1.0f}, {1.0f, 0.0f}, {0.0f, 1.0f}},
10154 {{ 1.0f, 1.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 0.0f}},
10156 static const DWORD fvf = D3DFVF_XYZ | D3DFVF_TEX3;
10157 IDirect3DDevice7 *device;
10158 IDirect3D7 *d3d;
10159 IDirectDraw7 *ddraw;
10160 IDirectDrawSurface7 *rt;
10161 HWND window;
10162 HRESULT hr;
10163 IDirectDrawSurface7 *texture1, *texture2;
10164 DDSURFACEDESC2 surface_desc;
10165 ULONG refcount;
10166 D3DCOLOR color;
10167 DWORD *ptr;
10169 window = create_window();
10170 if (!(device = create_device(window, DDSCL_NORMAL)))
10172 skip("Failed to create a 3D device, skipping test.\n");
10173 DestroyWindow(window);
10174 return;
10177 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
10178 ok(SUCCEEDED(hr), "Failed to get Direct3D7 interface, hr %#x.\n", hr);
10179 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
10180 ok(SUCCEEDED(hr), "Failed to get DirectDraw7 interface, hr %#x.\n", hr);
10181 IDirect3D7_Release(d3d);
10183 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
10184 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
10186 memset(&surface_desc, 0, sizeof(surface_desc));
10187 surface_desc.dwSize = sizeof(surface_desc);
10188 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
10189 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
10190 surface_desc.dwWidth = 2;
10191 surface_desc.dwHeight = 2;
10192 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
10193 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
10194 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
10195 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
10196 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
10197 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
10198 U5(U4(surface_desc).ddpfPixelFormat).dwRGBAlphaBitMask = 0xff000000;
10199 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &texture1, NULL);
10200 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
10201 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &texture2, NULL);
10202 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
10204 memset(&surface_desc, 0, sizeof(surface_desc));
10205 surface_desc.dwSize = sizeof(surface_desc);
10206 hr = IDirectDrawSurface7_Lock(texture1, 0, &surface_desc, 0, NULL);
10207 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
10208 ptr = surface_desc.lpSurface;
10209 ptr[0] = 0xff000000;
10210 ptr[1] = 0xff00ff00;
10211 ptr += U1(surface_desc).lPitch / sizeof(*ptr);
10212 ptr[0] = 0xff0000ff;
10213 ptr[1] = 0xff00ffff;
10214 hr = IDirectDrawSurface7_Unlock(texture1, NULL);
10215 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
10217 memset(&surface_desc, 0, sizeof(surface_desc));
10218 surface_desc.dwSize = sizeof(surface_desc);
10219 hr = IDirectDrawSurface7_Lock(texture2, 0, &surface_desc, 0, NULL);
10220 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
10221 ptr = surface_desc.lpSurface;
10222 ptr[0] = 0xff000000;
10223 ptr[1] = 0xff0000ff;
10224 ptr += U1(surface_desc).lPitch / sizeof(*ptr);
10225 ptr[0] = 0xffff0000;
10226 ptr[1] = 0xffff00ff;
10227 hr = IDirectDrawSurface7_Unlock(texture2, 0);
10228 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
10230 hr = IDirect3DDevice7_SetTexture(device, 0, texture1);
10231 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
10232 hr = IDirect3DDevice7_SetTexture(device, 1, texture2);
10233 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
10234 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
10235 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
10236 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
10237 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
10238 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
10239 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
10240 hr = IDirect3DDevice7_SetTextureStageState(device, 1, D3DTSS_COLOROP, D3DTOP_ADD);
10241 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
10242 hr = IDirect3DDevice7_SetTextureStageState(device, 1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
10243 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
10244 hr = IDirect3DDevice7_SetTextureStageState(device, 1, D3DTSS_COLORARG2, D3DTA_CURRENT);
10245 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
10246 hr = IDirect3DDevice7_SetTextureStageState(device, 2, D3DTSS_COLOROP, D3DTOP_DISABLE);
10247 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
10249 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_TEXCOORDINDEX, 1);
10250 ok(SUCCEEDED(hr), "Failed to set texcoord index, hr %#x.\n", hr);
10251 hr = IDirect3DDevice7_SetTextureStageState(device, 1, D3DTSS_TEXCOORDINDEX, 0);
10252 ok(SUCCEEDED(hr), "Failed to set texcoord index, hr %#x.\n", hr);
10254 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, FALSE);
10255 ok(SUCCEEDED(hr), "Failed to disable z-buffering, hr %#x.\n", hr);
10257 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffff00, 1.0f, 0);
10258 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
10260 hr = IDirect3DDevice7_BeginScene(device);
10261 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
10262 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, fvf, quad, 4, 0);
10263 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10264 hr = IDirect3DDevice7_EndScene(device);
10265 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
10267 color = get_surface_color(rt, 160, 120);
10268 ok(compare_color(color, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color);
10269 color = get_surface_color(rt, 480, 120);
10270 ok(compare_color(color, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color);
10271 color = get_surface_color(rt, 160, 360);
10272 ok(compare_color(color, 0x00ff0000, 2), "Got unexpected color 0x%08x.\n", color);
10273 color = get_surface_color(rt, 480, 360);
10274 ok(compare_color(color, 0x00ffffff, 2), "Got unexpected color 0x%08x.\n", color);
10276 hr = IDirect3DDevice7_SetTextureStageState(device, 1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);
10277 ok(SUCCEEDED(hr), "Failed to set texture transform flags, hr %#x.\n", hr);
10278 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_TEXTURE1, &mat);
10279 ok(SUCCEEDED(hr), "Failed to set transformation matrix, hr %#x.\n", hr);
10281 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffff00, 1.0f, 0);
10282 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
10284 hr = IDirect3DDevice7_BeginScene(device);
10285 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
10286 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, fvf, quad, 4, 0);
10287 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10288 hr = IDirect3DDevice7_EndScene(device);
10289 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
10291 color = get_surface_color(rt, 160, 120);
10292 ok(compare_color(color, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color);
10293 color = get_surface_color(rt, 480, 120);
10294 ok(compare_color(color, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color);
10295 color = get_surface_color(rt, 160, 360);
10296 ok(compare_color(color, 0x00000000, 2), "Got unexpected color 0x%08x.\n", color);
10297 color = get_surface_color(rt, 480, 360);
10298 ok(compare_color(color, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color);
10300 hr = IDirect3DDevice7_SetTextureStageState(device, 1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE);
10301 ok(SUCCEEDED(hr), "Failed to set texture transform flags, hr %#x.\n", hr);
10302 hr = IDirect3DDevice7_SetTextureStageState(device, 1, D3DTSS_TEXCOORDINDEX, 2);
10303 ok(SUCCEEDED(hr), "Failed to set texcoord index, hr %#x.\n", hr);
10305 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffff00, 1.0f, 0);
10306 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
10308 hr = IDirect3DDevice7_BeginScene(device);
10309 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
10310 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, fvf, quad, 4, 0);
10311 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10312 hr = IDirect3DDevice7_EndScene(device);
10313 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
10315 color = get_surface_color(rt, 160, 120);
10316 ok(compare_color(color, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color);
10317 color = get_surface_color(rt, 480, 120);
10318 ok(compare_color(color, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color);
10319 color = get_surface_color(rt, 160, 360);
10320 ok(compare_color(color, 0x00ff00ff, 2), "Got unexpected color 0x%08x.\n", color);
10321 color = get_surface_color(rt, 480, 360);
10322 ok(compare_color(color, 0x00ffff00, 2), "Got unexpected color 0x%08x.\n", color);
10324 IDirectDrawSurface7_Release(texture1);
10325 IDirectDrawSurface7_Release(texture2);
10327 IDirectDrawSurface7_Release(rt);
10328 IDirectDraw_Release(ddraw);
10329 refcount = IDirect3DDevice7_Release(device);
10330 ok(!refcount, "Device has %u references left.\n", refcount);
10331 DestroyWindow(window);
10334 static void test_colorkey_precision(void)
10336 static struct
10338 struct vec3 pos;
10339 struct vec2 texcoord;
10341 quad[] =
10343 {{-1.0f, -1.0f, 0.0f}, {0.0f, 1.0f}},
10344 {{-1.0f, 1.0f, 0.0f}, {0.0f, 0.0f}},
10345 {{ 1.0f, -1.0f, 0.0f}, {1.0f, 1.0f}},
10346 {{ 1.0f, 1.0f, 0.0f}, {1.0f, 0.0f}},
10348 IDirect3DDevice7 *device;
10349 IDirect3D7 *d3d;
10350 IDirectDraw7 *ddraw;
10351 IDirectDrawSurface7 *rt;
10352 HWND window;
10353 HRESULT hr;
10354 IDirectDrawSurface7 *src, *dst, *texture;
10355 DDSURFACEDESC2 surface_desc, lock_desc;
10356 ULONG refcount;
10357 D3DCOLOR color;
10358 unsigned int t, c;
10359 DDCOLORKEY ckey;
10360 DDBLTFX fx;
10361 DWORD data[4] = {0}, color_mask;
10362 BOOL is_nvidia, is_warp;
10363 static const struct
10365 unsigned int max, shift, bpp, clear;
10366 const char *name;
10367 BOOL skip_nv;
10368 DDPIXELFORMAT fmt;
10370 tests[] =
10373 255, 0, 4, 0x00345678, "D3DFMT_X8R8G8B8", FALSE,
10375 sizeof(DDPIXELFORMAT), DDPF_RGB, 0,
10376 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0x00000000}
10381 63, 5, 2, 0x5678, "D3DFMT_R5G6B5, G channel", FALSE,
10383 sizeof(DDPIXELFORMAT), DDPF_RGB, 0,
10384 {16}, {0xf800}, {0x07e0}, {0x001f}, {0x0000}
10389 31, 0, 2, 0x5678, "D3DFMT_R5G6B5, B channel", FALSE,
10391 sizeof(DDPIXELFORMAT), DDPF_RGB, 0,
10392 {16}, {0xf800}, {0x07e0}, {0x001f}, {0x0000}
10397 15, 0, 2, 0x0678, "D3DFMT_A4R4G4B4", TRUE,
10399 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
10400 {16}, {0x0f00}, {0x00f0}, {0x000f}, {0xf000}
10405 window = create_window();
10406 if (!(device = create_device(window, DDSCL_NORMAL)))
10408 skip("Failed to create a 3D device, skipping test.\n");
10409 DestroyWindow(window);
10410 return;
10413 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
10414 ok(SUCCEEDED(hr), "Failed to get Direct3D7 interface, hr %#x.\n", hr);
10415 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
10416 ok(SUCCEEDED(hr), "Failed to get DirectDraw7 interface, hr %#x.\n", hr);
10417 IDirect3D7_Release(d3d);
10418 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
10419 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
10421 is_nvidia = ddraw_is_nvidia(ddraw);
10422 /* The Windows 8 WARP driver has plenty of false negatives in X8R8G8B8
10423 * (color key doesn't match although the values are equal), and a false
10424 * positive when the color key is 0 and the texture contains the value 1.
10425 * I don't want to mark this broken unconditionally since this would
10426 * essentially disable the test on Windows. Also on random occasions
10427 * 254 == 255 and 255 != 255.*/
10428 is_warp = ddraw_is_warp(ddraw);
10430 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
10431 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
10432 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
10433 ok(SUCCEEDED(hr), "Failed to disable z-buffering, hr %#x.\n", hr);
10434 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, TRUE);
10435 ok(SUCCEEDED(hr), "Failed to enable color keying, hr %#x.\n", hr);
10436 /* Multiply the texture read result with 0, that way the result color if the key doesn't
10437 * match is constant. In theory color keying works without reading the texture result
10438 * (meaning we could just op=arg1, arg1=tfactor), but the Geforce7 Windows driver begs
10439 * to differ. */
10440 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_MODULATE);
10441 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
10442 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
10443 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
10444 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLORARG2, D3DTA_TFACTOR);
10445 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
10446 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_TEXTUREFACTOR, 0x00000000);
10447 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
10449 memset(&fx, 0, sizeof(fx));
10450 fx.dwSize = sizeof(fx);
10451 memset(&lock_desc, 0, sizeof(lock_desc));
10452 lock_desc.dwSize = sizeof(lock_desc);
10454 for (t = 0; t < ARRAY_SIZE(tests); ++t)
10456 if (is_nvidia && tests[t].skip_nv)
10458 win_skip("Skipping test %s on Nvidia Windows drivers.\n", tests[t].name);
10459 continue;
10462 memset(&surface_desc, 0, sizeof(surface_desc));
10463 surface_desc.dwSize = sizeof(surface_desc);
10464 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
10465 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
10466 surface_desc.dwWidth = 4;
10467 surface_desc.dwHeight = 1;
10468 U4(surface_desc).ddpfPixelFormat = tests[t].fmt;
10469 /* Windows XP (at least with the r200 driver, other drivers untested) produces
10470 * garbage when doing color keyed texture->texture blits. */
10471 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &src, NULL);
10472 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
10473 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &dst, NULL);
10474 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
10476 U5(fx).dwFillColor = tests[t].clear;
10477 /* On the w8 testbot (WARP driver) the blit result has different values in the
10478 * X channel. */
10479 color_mask = U2(tests[t].fmt).dwRBitMask
10480 | U3(tests[t].fmt).dwGBitMask
10481 | U4(tests[t].fmt).dwBBitMask;
10483 for (c = 0; c <= tests[t].max; ++c)
10485 /* The idiotic Nvidia Windows driver can't change the color key on a d3d
10486 * texture after it has been set once... */
10487 surface_desc.dwFlags |= DDSD_CKSRCBLT;
10488 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
10489 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = c << tests[t].shift;
10490 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = c << tests[t].shift;
10491 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &texture, NULL);
10492 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
10493 hr = IDirect3DDevice7_SetTexture(device, 0, texture);
10494 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
10496 hr = IDirectDrawSurface7_Blt(dst, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
10497 ok(SUCCEEDED(hr), "Failed to clear destination surface, hr %#x.\n", hr);
10499 hr = IDirectDrawSurface7_Lock(src, NULL, &lock_desc, DDLOCK_WAIT, NULL);
10500 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
10501 switch (tests[t].bpp)
10503 case 4:
10504 ((DWORD *)lock_desc.lpSurface)[0] = (c ? c - 1 : 0) << tests[t].shift;
10505 ((DWORD *)lock_desc.lpSurface)[1] = c << tests[t].shift;
10506 ((DWORD *)lock_desc.lpSurface)[2] = min(c + 1, tests[t].max) << tests[t].shift;
10507 ((DWORD *)lock_desc.lpSurface)[3] = 0xffffffff;
10508 break;
10510 case 2:
10511 ((WORD *)lock_desc.lpSurface)[0] = (c ? c - 1 : 0) << tests[t].shift;
10512 ((WORD *)lock_desc.lpSurface)[1] = c << tests[t].shift;
10513 ((WORD *)lock_desc.lpSurface)[2] = min(c + 1, tests[t].max) << tests[t].shift;
10514 ((WORD *)lock_desc.lpSurface)[3] = 0xffff;
10515 break;
10517 hr = IDirectDrawSurface7_Unlock(src, 0);
10518 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
10519 hr = IDirectDrawSurface7_Blt(texture, NULL, src, NULL, DDBLT_WAIT, NULL);
10520 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
10522 ckey.dwColorSpaceLowValue = c << tests[t].shift;
10523 ckey.dwColorSpaceHighValue = c << tests[t].shift;
10524 hr = IDirectDrawSurface7_SetColorKey(src, DDCKEY_SRCBLT, &ckey);
10525 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
10527 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_KEYSRC | DDBLT_WAIT, NULL);
10528 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
10530 /* Don't make this read only, it somehow breaks the detection of the Nvidia bug below. */
10531 hr = IDirectDrawSurface7_Lock(dst, NULL, &lock_desc, DDLOCK_WAIT, NULL);
10532 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
10533 switch (tests[t].bpp)
10535 case 4:
10536 data[0] = ((DWORD *)lock_desc.lpSurface)[0] & color_mask;
10537 data[1] = ((DWORD *)lock_desc.lpSurface)[1] & color_mask;
10538 data[2] = ((DWORD *)lock_desc.lpSurface)[2] & color_mask;
10539 data[3] = ((DWORD *)lock_desc.lpSurface)[3] & color_mask;
10540 break;
10542 case 2:
10543 data[0] = ((WORD *)lock_desc.lpSurface)[0] & color_mask;
10544 data[1] = ((WORD *)lock_desc.lpSurface)[1] & color_mask;
10545 data[2] = ((WORD *)lock_desc.lpSurface)[2] & color_mask;
10546 data[3] = ((WORD *)lock_desc.lpSurface)[3] & color_mask;
10547 break;
10549 hr = IDirectDrawSurface7_Unlock(dst, 0);
10550 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
10552 if (!c)
10554 ok(data[0] == tests[t].clear, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10555 tests[t].clear, data[0], tests[t].name, c);
10557 if (data[3] == tests[t].clear)
10559 /* My Geforce GTX 460 on Windows 7 misbehaves when A4R4G4B4 is blitted with color
10560 * keying: The blit takes ~0.5 seconds, and subsequent color keying draws are broken,
10561 * even when a different surface is used. The blit itself doesn't draw anything,
10562 * so we can detect the bug by looking at the otherwise unused 4th texel. It should
10563 * never be masked out by the key.
10565 * On Windows 10 the problem is worse, Blt just hangs. For this reason the ARGB4444
10566 * test is disabled on Nvidia.
10568 * Also appears to affect the testbot in some way with R5G6B5. Color keying is
10569 * terrible on WARP. */
10570 skip("Nvidia A4R4G4B4 color keying blit bug detected, skipping.\n");
10571 IDirectDrawSurface7_Release(texture);
10572 IDirectDrawSurface7_Release(src);
10573 IDirectDrawSurface7_Release(dst);
10574 goto done;
10577 else
10578 ok(data[0] == (c - 1) << tests[t].shift, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10579 (c - 1) << tests[t].shift, data[0], tests[t].name, c);
10581 ok(data[1] == tests[t].clear, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10582 tests[t].clear, data[1], tests[t].name, c);
10584 if (c == tests[t].max)
10585 ok(data[2] == tests[t].clear, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10586 tests[t].clear, data[2], tests[t].name, c);
10587 else
10588 ok(data[2] == (c + 1) << tests[t].shift, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10589 (c + 1) << tests[t].shift, data[2], tests[t].name, c);
10591 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x0000ff00, 1.0f, 0);
10592 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
10594 hr = IDirect3DDevice7_BeginScene(device);
10595 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
10596 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_TEX1, quad, 4, 0);
10597 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10598 hr = IDirect3DDevice7_EndScene(device);
10599 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
10601 color = get_surface_color(rt, 80, 240);
10602 if (!c)
10603 ok(compare_color(color, 0x0000ff00, 1) || broken(is_warp && compare_color(color, 0x00000000, 1)),
10604 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10605 color, tests[t].name, c);
10606 else
10607 ok(compare_color(color, 0x00000000, 1) || broken(is_warp && compare_color(color, 0x0000ff00, 1)),
10608 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10609 color, tests[t].name, c);
10611 color = get_surface_color(rt, 240, 240);
10612 ok(compare_color(color, 0x0000ff00, 1) || broken(is_warp && compare_color(color, 0x00000000, 1)),
10613 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10614 color, tests[t].name, c);
10616 color = get_surface_color(rt, 400, 240);
10617 if (c == tests[t].max)
10618 ok(compare_color(color, 0x0000ff00, 1) || broken(is_warp && compare_color(color, 0x00000000, 1)),
10619 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10620 color, tests[t].name, c);
10621 else
10622 ok(compare_color(color, 0x00000000, 1) || broken(is_warp && compare_color(color, 0x0000ff00, 1)),
10623 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10624 color, tests[t].name, c);
10626 IDirectDrawSurface7_Release(texture);
10628 IDirectDrawSurface7_Release(src);
10629 IDirectDrawSurface7_Release(dst);
10631 done:
10633 IDirectDrawSurface7_Release(rt);
10634 IDirectDraw7_Release(ddraw);
10635 refcount = IDirect3DDevice7_Release(device);
10636 ok(!refcount, "Device has %u references left.\n", refcount);
10637 DestroyWindow(window);
10640 static void test_range_colorkey(void)
10642 IDirectDraw7 *ddraw;
10643 HWND window;
10644 HRESULT hr;
10645 IDirectDrawSurface7 *surface;
10646 DDSURFACEDESC2 surface_desc;
10647 ULONG refcount;
10648 DDCOLORKEY ckey;
10650 window = create_window();
10651 ddraw = create_ddraw();
10652 ok(!!ddraw, "Failed to create a ddraw object.\n");
10653 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
10654 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
10656 memset(&surface_desc, 0, sizeof(surface_desc));
10657 surface_desc.dwSize = sizeof(surface_desc);
10658 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CKSRCBLT;
10659 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
10660 surface_desc.dwWidth = 1;
10661 surface_desc.dwHeight = 1;
10662 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
10663 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
10664 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
10665 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
10666 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
10667 U5(U4(surface_desc).ddpfPixelFormat).dwRGBAlphaBitMask = 0x00000000;
10669 /* Creating a surface with a range color key fails with DDERR_NOCOLORKEY. */
10670 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00000000;
10671 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00000001;
10672 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
10673 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
10675 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00000001;
10676 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00000000;
10677 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
10678 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
10680 /* Same for DDSCAPS_OFFSCREENPLAIN. */
10681 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
10682 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00000000;
10683 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00000001;
10684 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
10685 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
10687 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00000001;
10688 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00000000;
10689 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
10690 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
10692 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00000000;
10693 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00000000;
10694 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
10695 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
10697 /* Setting a range color key without DDCKEY_COLORSPACE collapses the key. */
10698 ckey.dwColorSpaceLowValue = 0x00000000;
10699 ckey.dwColorSpaceHighValue = 0x00000001;
10700 hr = IDirectDrawSurface7_SetColorKey(surface, DDCKEY_SRCBLT, &ckey);
10701 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
10703 hr = IDirectDrawSurface7_GetColorKey(surface, DDCKEY_SRCBLT, &ckey);
10704 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
10705 ok(!ckey.dwColorSpaceLowValue, "Got unexpected value 0x%08x.\n", ckey.dwColorSpaceLowValue);
10706 ok(!ckey.dwColorSpaceHighValue, "Got unexpected value 0x%08x.\n", ckey.dwColorSpaceHighValue);
10708 ckey.dwColorSpaceLowValue = 0x00000001;
10709 ckey.dwColorSpaceHighValue = 0x00000000;
10710 hr = IDirectDrawSurface7_SetColorKey(surface, DDCKEY_SRCBLT, &ckey);
10711 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
10713 hr = IDirectDrawSurface7_GetColorKey(surface, DDCKEY_SRCBLT, &ckey);
10714 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
10715 ok(ckey.dwColorSpaceLowValue == 0x00000001, "Got unexpected value 0x%08x.\n", ckey.dwColorSpaceLowValue);
10716 ok(ckey.dwColorSpaceHighValue == 0x00000001, "Got unexpected value 0x%08x.\n", ckey.dwColorSpaceHighValue);
10718 /* DDCKEY_COLORSPACE is ignored if the key is a single value. */
10719 ckey.dwColorSpaceLowValue = 0x00000000;
10720 ckey.dwColorSpaceHighValue = 0x00000000;
10721 hr = IDirectDrawSurface7_SetColorKey(surface, DDCKEY_SRCBLT | DDCKEY_COLORSPACE, &ckey);
10722 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
10724 /* Using it with a range key results in DDERR_NOCOLORKEYHW. */
10725 ckey.dwColorSpaceLowValue = 0x00000001;
10726 ckey.dwColorSpaceHighValue = 0x00000000;
10727 hr = IDirectDrawSurface7_SetColorKey(surface, DDCKEY_SRCBLT | DDCKEY_COLORSPACE, &ckey);
10728 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
10729 ckey.dwColorSpaceLowValue = 0x00000000;
10730 ckey.dwColorSpaceHighValue = 0x00000001;
10731 hr = IDirectDrawSurface7_SetColorKey(surface, DDCKEY_SRCBLT | DDCKEY_COLORSPACE, &ckey);
10732 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
10733 /* Range destination keys don't work either. */
10734 hr = IDirectDrawSurface7_SetColorKey(surface, DDCKEY_DESTBLT | DDCKEY_COLORSPACE, &ckey);
10735 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
10737 /* Just to show it's not because of A, R, and G having equal values. */
10738 ckey.dwColorSpaceLowValue = 0x00000000;
10739 ckey.dwColorSpaceHighValue = 0x01010101;
10740 hr = IDirectDrawSurface7_SetColorKey(surface, DDCKEY_SRCBLT | DDCKEY_COLORSPACE, &ckey);
10741 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
10743 /* None of these operations modified the key. */
10744 hr = IDirectDrawSurface7_GetColorKey(surface, DDCKEY_SRCBLT, &ckey);
10745 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
10746 ok(!ckey.dwColorSpaceLowValue, "Got unexpected value 0x%08x.\n", ckey.dwColorSpaceLowValue);
10747 ok(!ckey.dwColorSpaceHighValue, "Got unexpected value 0x%08x.\n", ckey.dwColorSpaceHighValue);
10749 IDirectDrawSurface7_Release(surface),
10750 refcount = IDirectDraw7_Release(ddraw);
10751 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
10752 DestroyWindow(window);
10755 static void test_shademode(void)
10757 IDirect3DVertexBuffer7 *vb_strip, *vb_list, *buffer;
10758 IDirect3DDevice7 *device;
10759 D3DVERTEXBUFFERDESC desc;
10760 IDirectDrawSurface7 *rt;
10761 DWORD color0, color1;
10762 void *data = NULL;
10763 IDirect3D7 *d3d;
10764 ULONG refcount;
10765 UINT i, count;
10766 HWND window;
10767 HRESULT hr;
10768 static const struct
10770 struct vec3 position;
10771 DWORD diffuse;
10773 quad_strip[] =
10775 {{-1.0f, -1.0f, 0.0f}, 0xffff0000},
10776 {{-1.0f, 1.0f, 0.0f}, 0xff00ff00},
10777 {{ 1.0f, -1.0f, 0.0f}, 0xff0000ff},
10778 {{ 1.0f, 1.0f, 0.0f}, 0xffffffff},
10780 quad_list[] =
10782 {{-1.0f, -1.0f, 0.0f}, 0xffff0000},
10783 {{-1.0f, 1.0f, 0.0f}, 0xff00ff00},
10784 {{ 1.0f, -1.0f, 0.0f}, 0xff0000ff},
10786 {{ 1.0f, -1.0f, 0.0f}, 0xff0000ff},
10787 {{-1.0f, 1.0f, 0.0f}, 0xff00ff00},
10788 {{ 1.0f, 1.0f, 0.0f}, 0xffffffff},
10790 static const struct
10792 DWORD primtype;
10793 DWORD shademode;
10794 DWORD color0, color1;
10796 tests[] =
10798 {D3DPT_TRIANGLESTRIP, D3DSHADE_FLAT, 0x00ff0000, 0x0000ff00},
10799 {D3DPT_TRIANGLESTRIP, D3DSHADE_PHONG, 0x000dca28, 0x000d45c7},
10800 {D3DPT_TRIANGLESTRIP, D3DSHADE_GOURAUD, 0x000dca28, 0x000d45c7},
10801 {D3DPT_TRIANGLESTRIP, D3DSHADE_PHONG, 0x000dca28, 0x000d45c7},
10802 {D3DPT_TRIANGLELIST, D3DSHADE_FLAT, 0x00ff0000, 0x000000ff},
10803 {D3DPT_TRIANGLELIST, D3DSHADE_GOURAUD, 0x000dca28, 0x000d45c7},
10806 window = create_window();
10807 if (!(device = create_device(window, DDSCL_NORMAL)))
10809 skip("Failed to create a 3D device, skipping test.\n");
10810 DestroyWindow(window);
10811 return;
10814 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
10815 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
10816 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
10817 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
10819 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
10820 ok(hr == D3D_OK, "Failed to disable lighting, hr %#x.\n", hr);
10821 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, FALSE);
10822 ok(SUCCEEDED(hr), "Failed to disable fog, hr %#x.\n", hr);
10824 memset(&desc, 0, sizeof(desc));
10825 desc.dwSize = sizeof(desc);
10826 desc.dwCaps = D3DVBCAPS_WRITEONLY;
10827 desc.dwFVF = D3DFVF_XYZ | D3DFVF_DIFFUSE;
10828 desc.dwNumVertices = ARRAY_SIZE(quad_strip);
10829 hr = IDirect3D7_CreateVertexBuffer(d3d, &desc, &vb_strip, 0);
10830 ok(hr == D3D_OK, "Failed to create vertex buffer, hr %#x.\n", hr);
10831 hr = IDirect3DVertexBuffer7_Lock(vb_strip, 0, &data, NULL);
10832 ok(hr == D3D_OK, "Failed to lock vertex buffer, hr %#x.\n", hr);
10833 memcpy(data, quad_strip, sizeof(quad_strip));
10834 hr = IDirect3DVertexBuffer7_Unlock(vb_strip);
10835 ok(hr == D3D_OK, "Failed to unlock vertex buffer, hr %#x.\n", hr);
10837 desc.dwNumVertices = ARRAY_SIZE(quad_list);
10838 hr = IDirect3D7_CreateVertexBuffer(d3d, &desc, &vb_list, 0);
10839 ok(hr == D3D_OK, "Failed to create vertex buffer, hr %#x.\n", hr);
10840 hr = IDirect3DVertexBuffer7_Lock(vb_list, 0, &data, NULL);
10841 ok(hr == D3D_OK, "Failed to lock vertex buffer, hr %#x.\n", hr);
10842 memcpy(data, quad_list, sizeof(quad_list));
10843 hr = IDirect3DVertexBuffer7_Unlock(vb_list);
10844 ok(hr == D3D_OK, "Failed to unlock vertex buffer, hr %#x.\n", hr);
10846 /* Try it first with a TRIANGLESTRIP. Do it with different geometry because
10847 * the color fixups we have to do for FLAT shading will be dependent on that. */
10849 for (i = 0; i < ARRAY_SIZE(tests); ++i)
10851 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0f, 0);
10852 ok(hr == D3D_OK, "Failed to clear, hr %#x.\n", hr);
10854 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_SHADEMODE, tests[i].shademode);
10855 ok(hr == D3D_OK, "Failed to set shade mode, hr %#x.\n", hr);
10857 hr = IDirect3DDevice7_BeginScene(device);
10858 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
10859 buffer = tests[i].primtype == D3DPT_TRIANGLESTRIP ? vb_strip : vb_list;
10860 count = tests[i].primtype == D3DPT_TRIANGLESTRIP ? 4 : 6;
10861 hr = IDirect3DDevice7_DrawPrimitiveVB(device, tests[i].primtype, buffer, 0, count, 0);
10862 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10863 hr = IDirect3DDevice7_EndScene(device);
10864 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
10866 color0 = get_surface_color(rt, 100, 100); /* Inside first triangle */
10867 color1 = get_surface_color(rt, 500, 350); /* Inside second triangle */
10869 /* For D3DSHADE_FLAT it should take the color of the first vertex of
10870 * each triangle. This requires EXT_provoking_vertex or similar
10871 * functionality being available. */
10872 /* PHONG should be the same as GOURAUD, since no hardware implements
10873 * this. */
10874 ok(compare_color(color0, tests[i].color0, 1), "Test %u shading has color0 %08x, expected %08x.\n",
10875 i, color0, tests[i].color0);
10876 ok(compare_color(color1, tests[i].color1, 1), "Test %u shading has color1 %08x, expected %08x.\n",
10877 i, color1, tests[i].color1);
10880 IDirect3DVertexBuffer7_Release(vb_strip);
10881 IDirect3DVertexBuffer7_Release(vb_list);
10882 IDirectDrawSurface7_Release(rt);
10883 IDirect3D7_Release(d3d);
10884 refcount = IDirect3DDevice7_Release(device);
10885 ok(!refcount, "Device has %u references left.\n", refcount);
10886 DestroyWindow(window);
10889 static void test_lockrect_invalid(void)
10891 unsigned int i, r;
10892 IDirectDraw7 *ddraw;
10893 IDirectDrawSurface7 *surface;
10894 HWND window;
10895 HRESULT hr;
10896 DDSURFACEDESC2 surface_desc;
10897 DDSURFACEDESC2 locked_desc;
10898 DDCAPS hal_caps;
10899 DWORD needed_caps = DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY;
10900 static RECT valid[] =
10902 {60, 60, 68, 68},
10903 {60, 60, 60, 68},
10904 {60, 60, 68, 60},
10905 {120, 60, 128, 68},
10906 {60, 120, 68, 128},
10908 static RECT invalid[] =
10910 {68, 60, 60, 68}, /* left > right */
10911 {60, 68, 68, 60}, /* top > bottom */
10912 {-8, 60, 0, 68}, /* left < surface */
10913 {60, -8, 68, 0}, /* top < surface */
10914 {-16, 60, -8, 68}, /* right < surface */
10915 {60, -16, 68, -8}, /* bottom < surface */
10916 {60, 60, 136, 68}, /* right > surface */
10917 {60, 60, 68, 136}, /* bottom > surface */
10918 {136, 60, 144, 68}, /* left > surface */
10919 {60, 136, 68, 144}, /* top > surface */
10921 static const struct
10923 DWORD caps, caps2;
10924 const char *name;
10925 HRESULT hr;
10927 resources[] =
10929 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY, 0, "sysmem offscreenplain", DDERR_INVALIDPARAMS},
10930 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0, "vidmem offscreenplain", DDERR_INVALIDPARAMS},
10931 {DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, 0, "sysmem texture", DD_OK},
10932 {DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, 0, "vidmem texture", DDERR_INVALIDPARAMS},
10933 {DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, "managed texture", DD_OK},
10936 window = create_window();
10937 ddraw = create_ddraw();
10938 ok(!!ddraw, "Failed to create a ddraw object.\n");
10939 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
10940 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
10942 memset(&hal_caps, 0, sizeof(hal_caps));
10943 hal_caps.dwSize = sizeof(hal_caps);
10944 hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, NULL);
10945 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
10946 if ((hal_caps.ddsCaps.dwCaps & needed_caps) != needed_caps
10947 || !(hal_caps.ddsCaps.dwCaps & DDSCAPS2_TEXTUREMANAGE))
10949 skip("Required surface types not supported, skipping test.\n");
10950 goto done;
10953 for (r = 0; r < ARRAY_SIZE(resources); ++r)
10955 memset(&surface_desc, 0, sizeof(surface_desc));
10956 surface_desc.dwSize = sizeof(surface_desc);
10957 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
10958 surface_desc.ddsCaps.dwCaps = resources[r].caps;
10959 surface_desc.ddsCaps.dwCaps2 = resources[r].caps2;
10960 surface_desc.dwWidth = 128;
10961 surface_desc.dwHeight = 128;
10962 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
10963 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
10964 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
10965 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0xff0000;
10966 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x00ff00;
10967 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x0000ff;
10969 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
10970 if (is_ddraw64 && (resources[r].caps & DDSCAPS_TEXTURE))
10972 todo_wine ok(hr == E_NOINTERFACE, "Got unexpected hr %#x, type %s.\n", hr, resources[r].name);
10973 if (SUCCEEDED(hr))
10974 IDirectDrawSurface7_Release(surface);
10975 continue;
10977 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x, type %s.\n", hr, resources[r].name);
10979 /* Crashes in ddraw7
10980 hr = IDirectDrawSurface7_Lock(surface, NULL, NULL, DDLOCK_WAIT, NULL);
10981 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x, type %s.\n", hr, resources[r].name);
10984 for (i = 0; i < ARRAY_SIZE(valid); ++i)
10986 RECT *rect = &valid[i];
10988 memset(&locked_desc, 0, sizeof(locked_desc));
10989 locked_desc.dwSize = sizeof(locked_desc);
10991 hr = IDirectDrawSurface7_Lock(surface, rect, &locked_desc, DDLOCK_WAIT, NULL);
10992 ok(SUCCEEDED(hr), "Lock failed (%#x) for rect %s, type %s.\n",
10993 hr, wine_dbgstr_rect(rect), resources[r].name);
10995 hr = IDirectDrawSurface7_Unlock(surface, NULL);
10996 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
10999 for (i = 0; i < ARRAY_SIZE(invalid); ++i)
11001 RECT *rect = &invalid[i];
11003 memset(&locked_desc, 1, sizeof(locked_desc));
11004 locked_desc.dwSize = sizeof(locked_desc);
11006 hr = IDirectDrawSurface7_Lock(surface, rect, &locked_desc, DDLOCK_WAIT, NULL);
11007 todo_wine_if (SUCCEEDED(resources[r].hr))
11008 ok(hr == resources[r].hr, "Lock returned %#x for rect %s, type %s.\n",
11009 hr, wine_dbgstr_rect(rect), resources[r].name);
11010 if (SUCCEEDED(hr))
11012 hr = IDirectDrawSurface7_Unlock(surface, NULL);
11013 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
11015 else
11016 ok(!locked_desc.lpSurface, "Got unexpected lpSurface %p.\n", locked_desc.lpSurface);
11019 hr = IDirectDrawSurface7_Lock(surface, NULL, &locked_desc, DDLOCK_WAIT, NULL);
11020 ok(SUCCEEDED(hr), "Lock(rect = NULL) failed, hr %#x, type %s.\n",
11021 hr, resources[r].name);
11022 hr = IDirectDrawSurface7_Lock(surface, NULL, &locked_desc, DDLOCK_WAIT, NULL);
11023 ok(hr == DDERR_SURFACEBUSY, "Double lock(rect = NULL) returned %#x, type %s.\n",
11024 hr, resources[r].name);
11025 hr = IDirectDrawSurface7_Unlock(surface, NULL);
11026 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
11028 hr = IDirectDrawSurface7_Lock(surface, &valid[0], &locked_desc, DDLOCK_WAIT, NULL);
11029 ok(SUCCEEDED(hr), "Lock(rect = %s) failed (%#x).\n", wine_dbgstr_rect(&valid[0]), hr);
11030 hr = IDirectDrawSurface7_Lock(surface, &valid[0], &locked_desc, DDLOCK_WAIT, NULL);
11031 ok(hr == DDERR_SURFACEBUSY, "Double lock(rect = %s) failed (%#x).\n",
11032 wine_dbgstr_rect(&valid[0]), hr);
11034 /* Locking a different rectangle returns DD_OK, but it seems to break the surface.
11035 * Afterwards unlocking the surface fails(NULL rectangle or both locked rectangles) */
11037 hr = IDirectDrawSurface7_Unlock(surface, NULL);
11038 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
11040 IDirectDrawSurface7_Release(surface);
11043 done:
11044 IDirectDraw7_Release(ddraw);
11045 DestroyWindow(window);
11048 static void test_yv12_overlay(void)
11050 IDirectDrawSurface7 *src_surface, *dst_surface;
11051 RECT rect = {13, 17, 14, 18};
11052 unsigned int offset, y;
11053 DDSURFACEDESC2 desc;
11054 unsigned char *base;
11055 IDirectDraw7 *ddraw;
11056 HWND window;
11057 HRESULT hr;
11059 window = create_window();
11060 ddraw = create_ddraw();
11061 ok(!!ddraw, "Failed to create a ddraw object.\n");
11062 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
11063 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
11065 if (!(src_surface = create_overlay(ddraw, 256, 256, MAKEFOURCC('Y','V','1','2'))))
11067 skip("Failed to create a YV12 overlay, skipping test.\n");
11068 goto done;
11071 memset(&desc, 0, sizeof(desc));
11072 desc.dwSize = sizeof(desc);
11073 hr = IDirectDrawSurface7_Lock(src_surface, NULL, &desc, DDLOCK_WAIT, NULL);
11074 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
11076 ok(desc.dwFlags == (DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_PITCH),
11077 "Got unexpected flags %#x.\n", desc.dwFlags);
11078 ok(desc.ddsCaps.dwCaps == (DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM | DDSCAPS_HWCODEC)
11079 || desc.ddsCaps.dwCaps == (DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM),
11080 "Got unexpected caps %#x.\n", desc.ddsCaps.dwCaps);
11081 ok(desc.dwWidth == 256, "Got unexpected width %u.\n", desc.dwWidth);
11082 ok(desc.dwHeight == 256, "Got unexpected height %u.\n", desc.dwHeight);
11083 /* The overlay pitch seems to have 256 byte alignment. */
11084 ok(!(U1(desc).lPitch & 0xff), "Got unexpected pitch %u.\n", U1(desc).lPitch);
11086 /* Fill the surface with some data for the blit test. */
11087 base = desc.lpSurface;
11088 /* Luminance */
11089 for (y = 0; y < desc.dwHeight; ++y)
11091 memset(base + U1(desc).lPitch * y, 0x10, desc.dwWidth);
11093 /* V */
11094 for (; y < desc.dwHeight + desc.dwHeight / 4; ++y)
11096 memset(base + U1(desc).lPitch * y, 0x20, desc.dwWidth);
11098 /* U */
11099 for (; y < desc.dwHeight + desc.dwHeight / 2; ++y)
11101 memset(base + U1(desc).lPitch * y, 0x30, desc.dwWidth);
11104 hr = IDirectDrawSurface7_Unlock(src_surface, NULL);
11105 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
11107 /* YV12 uses 2x2 blocks with 6 bytes per block (4*Y, 1*U, 1*V). Unlike
11108 * other block-based formats like DXT the entire Y channel is stored in
11109 * one big chunk of memory, followed by the chroma channels. So partial
11110 * locks do not really make sense. Show that they are allowed nevertheless
11111 * and the offset points into the luminance data. */
11112 hr = IDirectDrawSurface7_Lock(src_surface, &rect, &desc, DDLOCK_WAIT, NULL);
11113 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
11114 offset = ((const unsigned char *)desc.lpSurface - base);
11115 ok(offset == rect.top * U1(desc).lPitch + rect.left, "Got unexpected offset %u, expected %u.\n",
11116 offset, rect.top * U1(desc).lPitch + rect.left);
11117 hr = IDirectDrawSurface7_Unlock(src_surface, NULL);
11118 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
11120 if (!(dst_surface = create_overlay(ddraw, 256, 256, MAKEFOURCC('Y','V','1','2'))))
11122 /* Windows XP with a Radeon X1600 GPU refuses to create a second
11123 * overlay surface, DDERR_NOOVERLAYHW, making the blit tests moot. */
11124 skip("Failed to create a second YV12 surface, skipping blit test.\n");
11125 IDirectDrawSurface7_Release(src_surface);
11126 goto done;
11129 hr = IDirectDrawSurface7_Blt(dst_surface, NULL, src_surface, NULL, DDBLT_WAIT, NULL);
11130 /* VMware rejects YV12 blits. This behavior has not been seen on real
11131 * hardware yet, so mark it broken. */
11132 ok(SUCCEEDED(hr) || broken(hr == E_NOTIMPL), "Failed to blit, hr %#x.\n", hr);
11134 if (SUCCEEDED(hr))
11136 memset(&desc, 0, sizeof(desc));
11137 desc.dwSize = sizeof(desc);
11138 hr = IDirectDrawSurface7_Lock(dst_surface, NULL, &desc, DDLOCK_WAIT, NULL);
11139 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
11141 base = desc.lpSurface;
11142 ok(base[0] == 0x10, "Got unexpected Y data 0x%02x.\n", base[0]);
11143 base += desc.dwHeight * U1(desc).lPitch;
11144 todo_wine ok(base[0] == 0x20, "Got unexpected V data 0x%02x.\n", base[0]);
11145 base += desc.dwHeight / 4 * U1(desc).lPitch;
11146 todo_wine ok(base[0] == 0x30, "Got unexpected U data 0x%02x.\n", base[0]);
11148 hr = IDirectDrawSurface7_Unlock(dst_surface, NULL);
11149 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
11152 IDirectDrawSurface7_Release(dst_surface);
11153 IDirectDrawSurface7_Release(src_surface);
11154 done:
11155 IDirectDraw7_Release(ddraw);
11156 DestroyWindow(window);
11159 static BOOL dwm_enabled(void)
11161 BOOL ret = FALSE;
11163 if (!strcmp(winetest_platform, "wine"))
11164 return FALSE;
11165 if (!pDwmIsCompositionEnabled)
11166 return FALSE;
11167 if (FAILED(pDwmIsCompositionEnabled(&ret)))
11168 return FALSE;
11169 return ret;
11172 static void test_offscreen_overlay(void)
11174 IDirectDrawSurface7 *overlay, *offscreen, *primary;
11175 DDSURFACEDESC2 surface_desc;
11176 IDirectDraw7 *ddraw;
11177 HWND window;
11178 HRESULT hr;
11179 HDC dc;
11181 window = create_window();
11182 ddraw = create_ddraw();
11183 ok(!!ddraw, "Failed to create a ddraw object.\n");
11184 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
11185 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
11187 if (!(overlay = create_overlay(ddraw, 64, 64, MAKEFOURCC('U','Y','V','Y'))))
11189 skip("Failed to create a UYVY overlay, skipping test.\n");
11190 goto done;
11193 memset(&surface_desc, 0, sizeof(surface_desc));
11194 surface_desc.dwSize = sizeof(surface_desc);
11195 surface_desc.dwFlags = DDSD_CAPS;
11196 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
11197 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &primary, NULL);
11198 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
11200 /* On Windows 7, and probably Vista, UpdateOverlay() will return
11201 * DDERR_OUTOFCAPS if the dwm is active. Calling GetDC() on the primary
11202 * surface prevents this by disabling the dwm. */
11203 hr = IDirectDrawSurface7_GetDC(primary, &dc);
11204 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
11205 hr = IDirectDrawSurface7_ReleaseDC(primary, dc);
11206 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
11208 /* Try to overlay a NULL surface. */
11209 hr = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, NULL, NULL, DDOVER_SHOW, NULL);
11210 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
11211 hr = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, NULL, NULL, DDOVER_HIDE, NULL);
11212 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
11214 /* Try to overlay an offscreen surface. */
11215 memset(&surface_desc, 0, sizeof(surface_desc));
11216 surface_desc.dwSize = sizeof(surface_desc);
11217 surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
11218 surface_desc.dwWidth = 64;
11219 surface_desc.dwHeight = 64;
11220 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
11221 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
11222 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
11223 U4(surface_desc).ddpfPixelFormat.dwFourCC = 0;
11224 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 16;
11225 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0xf800;
11226 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x07e0;
11227 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x001f;
11228 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &offscreen, NULL);
11229 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
11231 hr = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, offscreen, NULL, DDOVER_SHOW, NULL);
11232 ok(SUCCEEDED(hr) || broken(hr == DDERR_OUTOFCAPS && dwm_enabled())
11233 || broken(hr == E_NOTIMPL && ddraw_is_vmware(ddraw)),
11234 "Failed to update overlay, hr %#x.\n", hr);
11236 /* Try to overlay the primary with a non-overlay surface. */
11237 hr = IDirectDrawSurface7_UpdateOverlay(offscreen, NULL, primary, NULL, DDOVER_SHOW, NULL);
11238 ok(hr == DDERR_NOTAOVERLAYSURFACE, "Got unexpected hr %#x.\n", hr);
11239 hr = IDirectDrawSurface7_UpdateOverlay(offscreen, NULL, primary, NULL, DDOVER_HIDE, NULL);
11240 ok(hr == DDERR_NOTAOVERLAYSURFACE, "Got unexpected hr %#x.\n", hr);
11242 IDirectDrawSurface7_Release(offscreen);
11243 IDirectDrawSurface7_Release(primary);
11244 IDirectDrawSurface7_Release(overlay);
11245 done:
11246 IDirectDraw7_Release(ddraw);
11247 DestroyWindow(window);
11250 static void test_overlay_rect(void)
11252 IDirectDrawSurface7 *overlay, *primary = NULL;
11253 DDSURFACEDESC2 surface_desc;
11254 RECT rect = {0, 0, 64, 64};
11255 IDirectDraw7 *ddraw;
11256 LONG pos_x, pos_y;
11257 HRESULT hr, hr2;
11258 HWND window;
11259 HDC dc;
11261 window = create_window();
11262 ddraw = create_ddraw();
11263 ok(!!ddraw, "Failed to create a ddraw object.\n");
11264 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
11265 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
11267 if (!(overlay = create_overlay(ddraw, 64, 64, MAKEFOURCC('U','Y','V','Y'))))
11269 skip("Failed to create a UYVY overlay, skipping test.\n");
11270 goto done;
11273 memset(&surface_desc, 0, sizeof(surface_desc));
11274 surface_desc.dwSize = sizeof(surface_desc);
11275 surface_desc.dwFlags = DDSD_CAPS;
11276 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
11277 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &primary, NULL);
11278 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
11280 /* On Windows 7, and probably Vista, UpdateOverlay() will return
11281 * DDERR_OUTOFCAPS if the dwm is active. Calling GetDC() on the primary
11282 * surface prevents this by disabling the dwm. */
11283 hr = IDirectDrawSurface7_GetDC(primary, &dc);
11284 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
11285 hr = IDirectDrawSurface7_ReleaseDC(primary, dc);
11286 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
11288 /* On Windows 8 and newer DWM can't be turned off, making overlays unusable. */
11289 if (dwm_enabled())
11291 win_skip("Cannot disable DWM, skipping overlay test.\n");
11292 goto done;
11295 /* The dx sdk sort of implies that rect must be set when DDOVER_SHOW is
11296 * used. This is not true in Windows Vista and earlier, but changed in
11297 * Windows 7. */
11298 hr = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, primary, &rect, DDOVER_SHOW, NULL);
11299 ok(SUCCEEDED(hr), "Failed to update overlay, hr %#x.\n", hr);
11300 hr = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, primary, NULL, DDOVER_HIDE, NULL);
11301 ok(SUCCEEDED(hr), "Failed to update overlay, hr %#x.\n", hr);
11302 hr = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, primary, NULL, DDOVER_SHOW, NULL);
11303 ok(hr == DD_OK || hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
11305 /* Show that the overlay position is the (top, left) coordinate of the
11306 * destination rectangle. */
11307 OffsetRect(&rect, 32, 16);
11308 hr = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, primary, &rect, DDOVER_SHOW, NULL);
11309 ok(SUCCEEDED(hr), "Failed to update overlay, hr %#x.\n", hr);
11310 pos_x = -1; pos_y = -1;
11311 hr = IDirectDrawSurface7_GetOverlayPosition(overlay, &pos_x, &pos_y);
11312 ok(SUCCEEDED(hr), "Failed to get overlay position, hr %#x.\n", hr);
11313 ok(pos_x == rect.left, "Got unexpected pos_x %d, expected %d.\n", pos_x, rect.left);
11314 ok(pos_y == rect.top, "Got unexpected pos_y %d, expected %d.\n", pos_y, rect.top);
11316 /* Passing a NULL dest rect sets the position to 0/0. Visually it can be
11317 * seen that the overlay overlays the whole primary(==screen). */
11318 hr2 = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, primary, NULL, 0, NULL);
11319 ok(hr2 == DD_OK || hr2 == DDERR_INVALIDPARAMS || hr2 == DDERR_OUTOFCAPS, "Got unexpected hr %#x.\n", hr2);
11320 hr = IDirectDrawSurface7_GetOverlayPosition(overlay, &pos_x, &pos_y);
11321 ok(SUCCEEDED(hr), "Failed to get overlay position, hr %#x.\n", hr);
11322 if (SUCCEEDED(hr2))
11324 ok(!pos_x, "Got unexpected pos_x %d.\n", pos_x);
11325 ok(!pos_y, "Got unexpected pos_y %d.\n", pos_y);
11327 else
11329 ok(pos_x == 32, "Got unexpected pos_x %d.\n", pos_x);
11330 ok(pos_y == 16, "Got unexpected pos_y %d.\n", pos_y);
11333 /* The position cannot be retrieved when the overlay is not shown. */
11334 hr = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, primary, &rect, DDOVER_HIDE, NULL);
11335 ok(SUCCEEDED(hr), "Failed to update overlay, hr %#x.\n", hr);
11336 pos_x = -1; pos_y = -1;
11337 hr = IDirectDrawSurface7_GetOverlayPosition(overlay, &pos_x, &pos_y);
11338 ok(hr == DDERR_OVERLAYNOTVISIBLE, "Got unexpected hr %#x.\n", hr);
11339 ok(!pos_x, "Got unexpected pos_x %d.\n", pos_x);
11340 ok(!pos_y, "Got unexpected pos_y %d.\n", pos_y);
11342 IDirectDrawSurface7_Release(overlay);
11343 done:
11344 if (primary)
11345 IDirectDrawSurface7_Release(primary);
11346 IDirectDraw7_Release(ddraw);
11347 DestroyWindow(window);
11350 static void test_blt(void)
11352 IDirectDrawSurface7 *surface, *rt;
11353 DDSURFACEDESC2 surface_desc;
11354 IDirect3DDevice7 *device;
11355 IDirectDraw7 *ddraw;
11356 IDirect3D7 *d3d;
11357 unsigned int i;
11358 ULONG refcount;
11359 HWND window;
11360 HRESULT hr;
11362 static struct
11364 RECT src_rect;
11365 RECT dst_rect;
11366 HRESULT hr;
11368 test_data[] =
11370 {{160, 0, 640, 480}, { 0, 0, 480, 480}, DD_OK}, /* Overlapped blit. */
11371 {{160, 480, 640, 0}, { 0, 0, 480, 480}, DDERR_INVALIDRECT}, /* Overlapped blit, flipped source. */
11372 {{640, 0, 160, 480}, { 0, 0, 480, 480}, DDERR_INVALIDRECT}, /* Overlapped blit, mirrored source. */
11373 {{160, 0, 480, 480}, { 0, 0, 480, 480}, DD_OK}, /* Overlapped blit, stretched x. */
11374 {{160, 160, 640, 480}, { 0, 0, 480, 480}, DD_OK}, /* Overlapped blit, stretched y. */
11375 {{ 0, 0, 640, 480}, { 0, 0, 640, 480}, DD_OK}, /* Full surface blit. */
11376 {{ 0, 0, 640, 480}, { 0, 480, 640, 0}, DDERR_INVALIDRECT}, /* Full surface, flipped destination. */
11377 {{ 0, 0, 640, 480}, {640, 0, 0, 480}, DDERR_INVALIDRECT}, /* Full surface, mirrored destination. */
11378 {{ 0, 480, 640, 0}, { 0, 0, 640, 480}, DDERR_INVALIDRECT}, /* Full surface, flipped source. */
11379 {{640, 0, 0, 480}, { 0, 0, 640, 480}, DDERR_INVALIDRECT}, /* Full surface, mirrored source. */
11382 window = create_window();
11383 if (!(device = create_device(window, DDSCL_NORMAL)))
11385 skip("Failed to create a 3D device, skipping test.\n");
11386 DestroyWindow(window);
11387 return;
11390 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
11391 ok(SUCCEEDED(hr), "Failed to get Direct3D7 interface, hr %#x.\n", hr);
11392 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
11393 ok(SUCCEEDED(hr), "Failed to get DirectDraw7 interface, hr %#x.\n", hr);
11394 IDirect3D7_Release(d3d);
11395 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
11396 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
11398 memset(&surface_desc, 0, sizeof(surface_desc));
11399 surface_desc.dwSize = sizeof(surface_desc);
11400 surface_desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
11401 surface_desc.dwWidth = 640;
11402 surface_desc.dwHeight = 480;
11403 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
11404 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
11405 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
11407 hr = IDirectDrawSurface7_Blt(surface, NULL, surface, NULL, 0, NULL);
11408 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
11410 hr = IDirectDrawSurface7_Blt(surface, NULL, rt, NULL, 0, NULL);
11411 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
11413 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
11415 hr = IDirectDrawSurface7_Blt(surface, &test_data[i].dst_rect,
11416 surface, &test_data[i].src_rect, DDBLT_WAIT, NULL);
11417 ok(hr == test_data[i].hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, test_data[i].hr);
11419 hr = IDirectDrawSurface7_Blt(surface, &test_data[i].dst_rect,
11420 rt, &test_data[i].src_rect, DDBLT_WAIT, NULL);
11421 ok(hr == test_data[i].hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, test_data[i].hr);
11423 hr = IDirectDrawSurface7_Blt(surface, &test_data[i].dst_rect,
11424 NULL, &test_data[i].src_rect, DDBLT_WAIT, NULL);
11425 ok(hr == DDERR_INVALIDPARAMS, "Test %u: Got unexpected hr %#x.\n", i, hr);
11427 hr = IDirectDrawSurface7_Blt(surface, &test_data[i].dst_rect, NULL, NULL, DDBLT_WAIT, NULL);
11428 ok(hr == DDERR_INVALIDPARAMS, "Test %u: Got unexpected hr %#x.\n", i, hr);
11431 IDirectDrawSurface7_Release(surface);
11432 IDirectDrawSurface7_Release(rt);
11433 IDirectDraw7_Release(ddraw);
11434 refcount = IDirect3DDevice7_Release(device);
11435 ok(!refcount, "Device has %u references left.\n", refcount);
11436 DestroyWindow(window);
11439 static void test_blt_z_alpha(void)
11441 DWORD blt_flags[] =
11443 /* 0 */
11444 DDBLT_ALPHADEST,
11445 DDBLT_ALPHADESTCONSTOVERRIDE,
11446 DDBLT_ALPHADESTNEG,
11447 DDBLT_ALPHADESTSURFACEOVERRIDE,
11448 DDBLT_ALPHAEDGEBLEND,
11449 /* 5 */
11450 DDBLT_ALPHASRC,
11451 DDBLT_ALPHASRCCONSTOVERRIDE,
11452 DDBLT_ALPHASRCNEG,
11453 DDBLT_ALPHASRCSURFACEOVERRIDE,
11454 DDBLT_ZBUFFER,
11455 /* 10 */
11456 DDBLT_ZBUFFERDESTCONSTOVERRIDE,
11457 DDBLT_ZBUFFERDESTOVERRIDE,
11458 DDBLT_ZBUFFERSRCCONSTOVERRIDE,
11459 DDBLT_ZBUFFERSRCOVERRIDE,
11461 IDirectDrawSurface7 *src_surface, *dst_surface;
11462 DDSURFACEDESC2 surface_desc;
11463 IDirectDraw7 *ddraw;
11464 DDPIXELFORMAT pf;
11465 ULONG refcount;
11466 unsigned int i;
11467 D3DCOLOR color;
11468 HWND window;
11469 HRESULT hr;
11470 DDBLTFX fx;
11472 window = create_window();
11473 ddraw = create_ddraw();
11474 ok(!!ddraw, "Failed to create a ddraw object.\n");
11475 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
11476 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
11478 memset(&pf, 0, sizeof(pf));
11479 pf.dwSize = sizeof(pf);
11480 pf.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
11481 U1(pf).dwRGBBitCount = 32;
11482 U2(pf).dwRBitMask = 0x00ff0000;
11483 U3(pf).dwGBitMask = 0x0000ff00;
11484 U4(pf).dwBBitMask = 0x000000ff;
11485 U5(pf).dwRGBAlphaBitMask = 0xff000000;
11487 memset(&surface_desc, 0, sizeof(surface_desc));
11488 surface_desc.dwSize = sizeof(surface_desc);
11489 surface_desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_PIXELFORMAT;
11490 surface_desc.dwWidth = 64;
11491 surface_desc.dwHeight = 64;
11492 U4(surface_desc).ddpfPixelFormat = pf;
11493 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
11495 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &src_surface, NULL);
11496 ok(SUCCEEDED(hr), "Failed to create source surface, hr %#x.\n", hr);
11497 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &dst_surface, NULL);
11498 ok(SUCCEEDED(hr), "Failed to create destination surface, hr %#x.\n", hr);
11500 memset(&fx, 0, sizeof(fx));
11501 fx.dwSize = sizeof(fx);
11502 fx.dwZBufferOpCode = D3DCMP_NEVER;
11503 fx.dwZDestConstBitDepth = 32;
11504 U1(fx).dwZDestConst = 0x11111111;
11505 fx.dwZSrcConstBitDepth = 32;
11506 U2(fx).dwZSrcConst = 0xeeeeeeee;
11507 fx.dwAlphaEdgeBlendBitDepth = 8;
11508 fx.dwAlphaEdgeBlend = 0x7f;
11509 fx.dwAlphaDestConstBitDepth = 8;
11510 U3(fx).dwAlphaDestConst = 0xdd;
11511 fx.dwAlphaSrcConstBitDepth = 8;
11512 U4(fx).dwAlphaSrcConst = 0x22;
11514 for (i = 0; i < ARRAY_SIZE(blt_flags); ++i)
11516 fx.dwFillColor = 0x3300ff00;
11517 hr = IDirectDrawSurface7_Blt(src_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
11518 ok(SUCCEEDED(hr), "Test %u: Got unexpected hr %#x.\n", i, hr);
11520 fx.dwFillColor = 0xccff0000;
11521 hr = IDirectDrawSurface7_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
11522 ok(SUCCEEDED(hr), "Test %u: Got unexpected hr %#x.\n", i, hr);
11524 hr = IDirectDrawSurface7_Blt(dst_surface, NULL, src_surface, NULL, blt_flags[i] | DDBLT_WAIT, &fx);
11525 ok(SUCCEEDED(hr), "Test %u: Got unexpected hr %#x.\n", i, hr);
11527 color = get_surface_color(dst_surface, 32, 32);
11528 ok(compare_color(color, 0x0000ff00, 0), "Test %u: Got unexpected color 0x%08x.\n", i, color);
11531 IDirectDrawSurface7_Release(dst_surface);
11532 IDirectDrawSurface7_Release(src_surface);
11533 refcount = IDirectDraw7_Release(ddraw);
11534 ok(!refcount, "DirectDraw has %u references left.\n", refcount);
11535 DestroyWindow(window);
11538 static void test_color_clamping(void)
11540 static D3DMATRIX mat =
11542 1.0f, 0.0f, 0.0f, 0.0f,
11543 0.0f, 1.0f, 0.0f, 0.0f,
11544 0.0f, 0.0f, 1.0f, 0.0f,
11545 0.0f, 0.0f, 0.0f, 1.0f,
11547 static struct vec3 quad[] =
11549 {-1.0f, -1.0f, 0.1f},
11550 {-1.0f, 1.0f, 0.1f},
11551 { 1.0f, -1.0f, 0.1f},
11552 { 1.0f, 1.0f, 0.1f},
11554 IDirect3DDevice7 *device;
11555 IDirectDrawSurface7 *rt;
11556 ULONG refcount;
11557 D3DCOLOR color;
11558 HWND window;
11559 HRESULT hr;
11561 window = create_window();
11562 if (!(device = create_device(window, DDSCL_NORMAL)))
11564 skip("Failed to create a 3D device, skipping test.\n");
11565 DestroyWindow(window);
11566 return;
11569 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
11570 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
11572 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &mat);
11573 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#x.\n", hr);
11574 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_VIEW, &mat);
11575 ok(SUCCEEDED(hr), "Failed to set view transform, hr %#x.\n", hr);
11576 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &mat);
11577 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
11578 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CLIPPING, FALSE);
11579 ok(SUCCEEDED(hr), "Failed to disable clipping, hr %#x.\n", hr);
11580 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, FALSE);
11581 ok(SUCCEEDED(hr), "Failed to disable Z test, hr %#x.\n", hr);
11582 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, FALSE);
11583 ok(SUCCEEDED(hr), "Failed to disable fog, hr %#x.\n", hr);
11584 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_STENCILENABLE, FALSE);
11585 ok(SUCCEEDED(hr), "Failed to disable stencil test, hr %#x.\n", hr);
11586 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CULLMODE, D3DCULL_NONE);
11587 ok(SUCCEEDED(hr), "Failed to disable culling, hr %#x.\n", hr);
11588 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
11589 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
11591 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_TEXTUREFACTOR, 0xff404040);
11592 ok(SUCCEEDED(hr), "Failed to set texture factor, hr %#x.\n", hr);
11593 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_ADD);
11594 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
11595 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);
11596 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
11597 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLORARG2, D3DTA_SPECULAR);
11598 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
11599 hr = IDirect3DDevice7_SetTextureStageState(device, 1, D3DTSS_COLOROP, D3DTOP_MODULATE);
11600 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
11601 hr = IDirect3DDevice7_SetTextureStageState(device, 1, D3DTSS_COLORARG1, D3DTA_TFACTOR);
11602 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
11603 hr = IDirect3DDevice7_SetTextureStageState(device, 1, D3DTSS_COLORARG2, D3DTA_CURRENT);
11604 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
11606 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff00ff00, 0.0f, 0);
11607 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
11609 hr = IDirect3DDevice7_BeginScene(device);
11610 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
11612 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, quad, 4, 0);
11613 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
11615 hr = IDirect3DDevice7_EndScene(device);
11616 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
11618 color = get_surface_color(rt, 320, 240);
11619 ok(compare_color(color, 0x00404040, 1), "Got unexpected color 0x%08x.\n", color);
11621 IDirectDrawSurface7_Release(rt);
11622 refcount = IDirect3DDevice7_Release(device);
11623 ok(!refcount, "Device has %u references left.\n", refcount);
11624 DestroyWindow(window);
11627 static void test_getdc(void)
11629 DDSCAPS2 caps = {DDSCAPS_COMPLEX, DDSCAPS2_CUBEMAP_NEGATIVEZ, 0, {0}};
11630 IDirectDrawSurface7 *surface, *surface2, *tmp;
11631 DDSURFACEDESC2 surface_desc, map_desc;
11632 IDirectDraw7 *ddraw;
11633 unsigned int i;
11634 HWND window;
11635 HDC dc, dc2;
11636 HRESULT hr;
11638 static const struct
11640 const char *name;
11641 DDPIXELFORMAT format;
11642 BOOL getdc_supported;
11643 HRESULT alt_result;
11645 test_data[] =
11647 {"D3DFMT_A8R8G8B8", {sizeof(test_data->format), DDPF_RGB | DDPF_ALPHAPIXELS, 0, {32},
11648 {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}}, TRUE},
11649 {"D3DFMT_X8R8G8B8", {sizeof(test_data->format), DDPF_RGB, 0, {32},
11650 {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0x00000000}}, TRUE},
11651 {"D3DFMT_R5G6B5", {sizeof(test_data->format), DDPF_RGB, 0, {16},
11652 {0x0000f800}, {0x000007e0}, {0x0000001f}, {0x00000000}}, TRUE},
11653 {"D3DFMT_X1R5G5B5", {sizeof(test_data->format), DDPF_RGB, 0, {16},
11654 {0x00007c00}, {0x000003e0}, {0x0000001f}, {0x00000000}}, TRUE},
11655 {"D3DFMT_A1R5G5B5", {sizeof(test_data->format), DDPF_RGB | DDPF_ALPHAPIXELS, 0, {16},
11656 {0x00007c00}, {0x000003e0}, {0x0000001f}, {0x00008000}}, TRUE},
11657 {"D3DFMT_A4R4G4B4", {sizeof(test_data->format), DDPF_RGB | DDPF_ALPHAPIXELS, 0, {16},
11658 {0x00000f00}, {0x000000f0}, {0x0000000f}, {0x0000f000}}, TRUE, DDERR_CANTCREATEDC /* Vista+ */},
11659 {"D3DFMT_X4R4G4B4", {sizeof(test_data->format), DDPF_RGB, 0, {16},
11660 {0x00000f00}, {0x000000f0}, {0x0000000f}, {0x00000000}}, TRUE, DDERR_CANTCREATEDC /* Vista+ */},
11661 {"D3DFMT_A2R10G10B10", {sizeof(test_data->format), DDPF_RGB | DDPF_ALPHAPIXELS, 0, {32},
11662 {0xc0000000}, {0x3ff00000}, {0x000ffc00}, {0x000003ff}}, TRUE},
11663 {"D3DFMT_A8B8G8R8", {sizeof(test_data->format), DDPF_RGB | DDPF_ALPHAPIXELS, 0, {32},
11664 {0x000000ff}, {0x0000ff00}, {0x00ff0000}, {0xff000000}}, TRUE, DDERR_CANTCREATEDC /* Vista+ */},
11665 {"D3DFMT_X8B8G8R8", {sizeof(test_data->format), DDPF_RGB, 0, {32},
11666 {0x000000ff}, {0x0000ff00}, {0x00ff0000}, {0x00000000}}, TRUE, DDERR_CANTCREATEDC /* Vista+ */},
11667 {"D3DFMT_R3G3B2", {sizeof(test_data->format), DDPF_RGB, 0, {8},
11668 {0x000000e0}, {0x0000001c}, {0x00000003}, {0x00000000}}, FALSE},
11669 /* GetDC() on a P8 surface fails unless the display mode is 8 bpp.
11670 * This is not implemented in wine yet, so disable the test for now.
11671 * Succeeding P8 GetDC() calls are tested in the ddraw:visual test.
11672 {"D3DFMT_P8", {sizeof(test_data->format), DDPF_PALETTEINDEXED8 | DDPF_RGB, 0, {8 },
11673 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
11675 {"D3DFMT_L8", {sizeof(test_data->format), DDPF_LUMINANCE, 0, {8},
11676 {0x000000ff}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
11677 {"D3DFMT_A8L8", {sizeof(test_data->format), DDPF_ALPHAPIXELS | DDPF_LUMINANCE, 0, {16},
11678 {0x000000ff}, {0x00000000}, {0x00000000}, {0x0000ff00}}, FALSE},
11679 {"D3DFMT_DXT1", {sizeof(test_data->format), DDPF_FOURCC, MAKEFOURCC('D','X','T','1'), {0},
11680 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
11681 {"D3DFMT_DXT2", {sizeof(test_data->format), DDPF_FOURCC, MAKEFOURCC('D','X','T','2'), {0},
11682 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
11683 {"D3DFMT_DXT3", {sizeof(test_data->format), DDPF_FOURCC, MAKEFOURCC('D','X','T','3'), {0},
11684 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
11685 {"D3DFMT_DXT4", {sizeof(test_data->format), DDPF_FOURCC, MAKEFOURCC('D','X','T','4'), {0},
11686 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
11687 {"D3DFMT_DXT5", {sizeof(test_data->format), DDPF_FOURCC, MAKEFOURCC('D','X','T','5'), {0},
11688 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
11691 window = create_window();
11692 ddraw = create_ddraw();
11693 ok(!!ddraw, "Failed to create a ddraw object.\n");
11694 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
11695 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
11697 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
11699 memset(&surface_desc, 0, sizeof(surface_desc));
11700 surface_desc.dwSize = sizeof(surface_desc);
11701 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
11702 surface_desc.dwWidth = 64;
11703 surface_desc.dwHeight = 64;
11704 U4(surface_desc).ddpfPixelFormat = test_data[i].format;
11705 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
11707 if (FAILED(IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL)))
11709 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
11710 surface_desc.ddsCaps.dwCaps2 = DDSCAPS2_TEXTUREMANAGE;
11711 if (FAILED(hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL)))
11713 skip("Failed to create surface for format %s (hr %#x), skipping tests.\n", test_data[i].name, hr);
11714 continue;
11718 dc = (void *)0x1234;
11719 hr = IDirectDrawSurface7_GetDC(surface, &dc);
11720 if (test_data[i].getdc_supported)
11721 ok(SUCCEEDED(hr) || (test_data[i].alt_result && hr == test_data[i].alt_result),
11722 "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11723 else
11724 ok(FAILED(hr), "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11726 if (SUCCEEDED(hr))
11728 unsigned int width_bytes;
11729 DIBSECTION dib;
11730 HBITMAP bitmap;
11731 DWORD type;
11732 int size;
11734 type = GetObjectType(dc);
11735 ok(type == OBJ_MEMDC, "Got unexpected object type %#x for format %s.\n", type, test_data[i].name);
11736 bitmap = GetCurrentObject(dc, OBJ_BITMAP);
11737 type = GetObjectType(bitmap);
11738 ok(type == OBJ_BITMAP, "Got unexpected object type %#x for format %s.\n", type, test_data[i].name);
11740 size = GetObjectA(bitmap, sizeof(dib), &dib);
11741 ok(size == sizeof(dib), "Got unexpected size %d for format %s.\n", size, test_data[i].name);
11742 ok(!dib.dsBm.bmType, "Got unexpected type %#x for format %s.\n",
11743 dib.dsBm.bmType, test_data[i].name);
11744 ok(dib.dsBm.bmWidth == surface_desc.dwWidth, "Got unexpected width %d for format %s.\n",
11745 dib.dsBm.bmWidth, test_data[i].name);
11746 ok(dib.dsBm.bmHeight == surface_desc.dwHeight, "Got unexpected height %d for format %s.\n",
11747 dib.dsBm.bmHeight, test_data[i].name);
11748 width_bytes = ((dib.dsBm.bmWidth * U1(test_data[i].format).dwRGBBitCount + 31) >> 3) & ~3;
11749 ok(dib.dsBm.bmWidthBytes == width_bytes, "Got unexpected width bytes %d for format %s.\n",
11750 dib.dsBm.bmWidthBytes, test_data[i].name);
11751 ok(dib.dsBm.bmPlanes == 1, "Got unexpected plane count %d for format %s.\n",
11752 dib.dsBm.bmPlanes, test_data[i].name);
11753 ok(dib.dsBm.bmBitsPixel == U1(test_data[i].format).dwRGBBitCount,
11754 "Got unexpected bit count %d for format %s.\n",
11755 dib.dsBm.bmBitsPixel, test_data[i].name);
11756 ok(!!dib.dsBm.bmBits, "Got unexpected bits %p for format %s.\n",
11757 dib.dsBm.bmBits, test_data[i].name);
11759 ok(dib.dsBmih.biSize == sizeof(dib.dsBmih), "Got unexpected size %u for format %s.\n",
11760 dib.dsBmih.biSize, test_data[i].name);
11761 ok(dib.dsBmih.biWidth == surface_desc.dwWidth, "Got unexpected width %d for format %s.\n",
11762 dib.dsBmih.biHeight, test_data[i].name);
11763 ok(dib.dsBmih.biHeight == surface_desc.dwHeight, "Got unexpected height %d for format %s.\n",
11764 dib.dsBmih.biHeight, test_data[i].name);
11765 ok(dib.dsBmih.biPlanes == 1, "Got unexpected plane count %u for format %s.\n",
11766 dib.dsBmih.biPlanes, test_data[i].name);
11767 ok(dib.dsBmih.biBitCount == U1(test_data[i].format).dwRGBBitCount,
11768 "Got unexpected bit count %u for format %s.\n",
11769 dib.dsBmih.biBitCount, test_data[i].name);
11770 ok(dib.dsBmih.biCompression == (U1(test_data[i].format).dwRGBBitCount == 16 ? BI_BITFIELDS : BI_RGB)
11771 || broken(U1(test_data[i].format).dwRGBBitCount == 32 && dib.dsBmih.biCompression == BI_BITFIELDS),
11772 "Got unexpected compression %#x for format %s.\n",
11773 dib.dsBmih.biCompression, test_data[i].name);
11774 ok(!dib.dsBmih.biSizeImage, "Got unexpected image size %u for format %s.\n",
11775 dib.dsBmih.biSizeImage, test_data[i].name);
11776 ok(!dib.dsBmih.biXPelsPerMeter, "Got unexpected horizontal resolution %d for format %s.\n",
11777 dib.dsBmih.biXPelsPerMeter, test_data[i].name);
11778 ok(!dib.dsBmih.biYPelsPerMeter, "Got unexpected vertical resolution %d for format %s.\n",
11779 dib.dsBmih.biYPelsPerMeter, test_data[i].name);
11780 ok(!dib.dsBmih.biClrUsed, "Got unexpected used colour count %u for format %s.\n",
11781 dib.dsBmih.biClrUsed, test_data[i].name);
11782 ok(!dib.dsBmih.biClrImportant, "Got unexpected important colour count %u for format %s.\n",
11783 dib.dsBmih.biClrImportant, test_data[i].name);
11785 if (dib.dsBmih.biCompression == BI_BITFIELDS)
11787 ok((dib.dsBitfields[0] == U2(test_data[i].format).dwRBitMask
11788 && dib.dsBitfields[1] == U3(test_data[i].format).dwGBitMask
11789 && dib.dsBitfields[2] == U4(test_data[i].format).dwBBitMask)
11790 || broken(!dib.dsBitfields[0] && !dib.dsBitfields[1] && !dib.dsBitfields[2]),
11791 "Got unexpected colour masks 0x%08x 0x%08x 0x%08x for format %s.\n",
11792 dib.dsBitfields[0], dib.dsBitfields[1], dib.dsBitfields[2], test_data[i].name);
11794 else
11796 ok(!dib.dsBitfields[0] && !dib.dsBitfields[1] && !dib.dsBitfields[2],
11797 "Got unexpected colour masks 0x%08x 0x%08x 0x%08x for format %s.\n",
11798 dib.dsBitfields[0], dib.dsBitfields[1], dib.dsBitfields[2], test_data[i].name);
11800 ok(!dib.dshSection, "Got unexpected section %p for format %s.\n", dib.dshSection, test_data[i].name);
11801 ok(!dib.dsOffset, "Got unexpected offset %u for format %s.\n", dib.dsOffset, test_data[i].name);
11803 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
11804 ok(hr == DD_OK, "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11806 else
11808 ok(!dc, "Got unexpected dc %p for format %s.\n", dc, test_data[i].name);
11811 IDirectDrawSurface7_Release(surface);
11813 if (FAILED(hr))
11814 continue;
11816 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
11817 surface_desc.ddsCaps.dwCaps2 = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES | DDSCAPS2_TEXTUREMANAGE;
11818 if (FAILED(hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL)))
11820 skip("Failed to create cube texture for format %s (hr %#x), skipping tests.\n", test_data[i].name, hr);
11821 continue;
11824 hr = IDirectDrawSurface7_GetAttachedSurface(surface, &caps, &surface2);
11825 ok(SUCCEEDED(hr), "Failed to get attached surface for format %s, hr %#x.\n", test_data[i].name, hr);
11826 hr = IDirectDrawSurface7_GetAttachedSurface(surface2, &caps, &tmp);
11827 ok(SUCCEEDED(hr), "Failed to get attached surface for format %s, hr %#x.\n", test_data[i].name, hr);
11828 IDirectDrawSurface7_Release(surface2);
11829 hr = IDirectDrawSurface7_GetAttachedSurface(tmp, &caps, &surface2);
11830 ok(SUCCEEDED(hr), "Failed to get attached surface for format %s, hr %#x.\n", test_data[i].name, hr);
11831 IDirectDrawSurface7_Release(tmp);
11833 hr = IDirectDrawSurface7_GetDC(surface, &dc);
11834 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11835 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
11836 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11837 hr = IDirectDrawSurface7_GetDC(surface2, &dc);
11838 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11839 hr = IDirectDrawSurface7_ReleaseDC(surface2, dc);
11840 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11842 hr = IDirectDrawSurface7_GetDC(surface, &dc);
11843 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11844 dc2 = (void *)0x1234;
11845 hr = IDirectDrawSurface7_GetDC(surface, &dc2);
11846 ok(hr == DDERR_DCALREADYCREATED, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11847 ok(dc2 == (void *)0x1234, "Got unexpected dc %p for format %s.\n", dc, test_data[i].name);
11848 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
11849 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11850 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
11851 ok(hr == DDERR_NODC, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11853 map_desc.dwSize = sizeof(map_desc);
11854 hr = IDirectDrawSurface7_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
11855 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
11856 hr = IDirectDrawSurface7_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
11857 ok(hr == DDERR_SURFACEBUSY, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11858 hr = IDirectDrawSurface7_Unlock(surface, NULL);
11859 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
11860 hr = IDirectDrawSurface7_Unlock(surface, NULL);
11861 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11863 hr = IDirectDrawSurface7_GetDC(surface, &dc);
11864 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11865 hr = IDirectDrawSurface7_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
11866 ok(hr == DDERR_SURFACEBUSY, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11867 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
11868 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11870 hr = IDirectDrawSurface7_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
11871 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
11872 hr = IDirectDrawSurface7_GetDC(surface, &dc);
11873 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11874 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
11875 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11876 hr = IDirectDrawSurface7_Unlock(surface, NULL);
11877 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
11879 hr = IDirectDrawSurface7_GetDC(surface, &dc);
11880 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11881 hr = IDirectDrawSurface7_GetDC(surface2, &dc2);
11882 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11883 hr = IDirectDrawSurface7_ReleaseDC(surface2, dc2);
11884 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11885 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
11886 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11888 hr = IDirectDrawSurface7_GetDC(surface2, &dc);
11889 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11890 hr = IDirectDrawSurface7_GetDC(surface, &dc2);
11891 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11892 hr = IDirectDrawSurface7_ReleaseDC(surface, dc2);
11893 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11894 hr = IDirectDrawSurface7_ReleaseDC(surface2, dc);
11895 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11897 hr = IDirectDrawSurface7_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
11898 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
11899 hr = IDirectDrawSurface7_Lock(surface2, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
11900 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
11901 hr = IDirectDrawSurface7_Unlock(surface2, NULL);
11902 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
11903 hr = IDirectDrawSurface7_Unlock(surface, NULL);
11904 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
11906 hr = IDirectDrawSurface7_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
11907 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
11908 hr = IDirectDrawSurface7_GetDC(surface, &dc);
11909 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11910 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
11911 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11912 hr = IDirectDrawSurface7_Unlock(surface, NULL);
11913 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
11915 hr = IDirectDrawSurface7_Lock(surface2, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
11916 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
11917 hr = IDirectDrawSurface7_GetDC(surface, &dc);
11918 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11919 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
11920 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11921 hr = IDirectDrawSurface7_Unlock(surface2, NULL);
11922 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
11924 hr = IDirectDrawSurface7_GetDC(surface, &dc);
11925 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11926 hr = IDirectDrawSurface7_Lock(surface2, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
11927 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
11928 hr = IDirectDrawSurface7_Unlock(surface2, NULL);
11929 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
11930 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
11931 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11933 hr = IDirectDrawSurface7_GetDC(surface2, &dc);
11934 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11935 hr = IDirectDrawSurface7_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
11936 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
11937 hr = IDirectDrawSurface7_Unlock(surface, NULL);
11938 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
11939 hr = IDirectDrawSurface7_ReleaseDC(surface2, dc);
11940 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11942 hr = IDirectDrawSurface7_Unlock(surface, NULL);
11943 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11944 hr = IDirectDrawSurface7_GetDC(surface2, &dc);
11945 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11946 hr = IDirectDrawSurface7_Unlock(surface, NULL);
11947 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11948 hr = IDirectDrawSurface7_ReleaseDC(surface2, dc);
11949 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11950 hr = IDirectDrawSurface7_Unlock(surface, NULL);
11951 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11953 hr = IDirectDrawSurface7_Unlock(surface2, NULL);
11954 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11955 hr = IDirectDrawSurface7_GetDC(surface, &dc);
11956 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11957 hr = IDirectDrawSurface7_Unlock(surface2, NULL);
11958 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11959 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
11960 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11961 hr = IDirectDrawSurface7_Unlock(surface2, NULL);
11962 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11964 IDirectDrawSurface7_Release(surface2);
11965 IDirectDrawSurface7_Release(surface);
11968 IDirectDraw7_Release(ddraw);
11969 DestroyWindow(window);
11972 static void test_draw_primitive(void)
11974 static WORD indices[] = {0, 1, 2, 3};
11975 static struct vec3 quad[] =
11977 {-1.0f, -1.0f, 0.0f},
11978 {-1.0f, 1.0f, 0.0f},
11979 { 1.0f, -1.0f, 0.0f},
11980 { 1.0f, 1.0f, 0.0f},
11982 D3DDRAWPRIMITIVESTRIDEDDATA strided;
11983 D3DVERTEXBUFFERDESC vb_desc;
11984 IDirect3DVertexBuffer7 *vb;
11985 IDirect3DDevice7 *device;
11986 IDirect3D7 *d3d;
11987 ULONG refcount;
11988 HWND window;
11989 HRESULT hr;
11990 void *data;
11992 window = create_window();
11993 if (!(device = create_device(window, DDSCL_NORMAL)))
11995 skip("Failed to create a 3D device, skipping test.\n");
11996 DestroyWindow(window);
11997 return;
12000 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
12001 ok(SUCCEEDED(hr), "Failed to get D3D interface, hr %#x.\n", hr);
12003 memset(&vb_desc, 0, sizeof(vb_desc));
12004 vb_desc.dwSize = sizeof(vb_desc);
12005 vb_desc.dwFVF = D3DFVF_XYZ;
12006 vb_desc.dwNumVertices = 4;
12007 hr = IDirect3D7_CreateVertexBuffer(d3d, &vb_desc, &vb, 0);
12008 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
12010 IDirect3D7_Release(d3d);
12012 memset(&strided, 0, sizeof(strided));
12014 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, NULL, 0, NULL, 0, 0);
12015 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12016 hr = IDirect3DDevice7_DrawIndexedPrimitiveStrided(device,
12017 D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, &strided, 0, NULL, 0, 0);
12018 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12019 hr = IDirect3DDevice7_DrawIndexedPrimitiveVB(device, D3DPT_TRIANGLESTRIP, vb, 0, 0, NULL, 0, 0);
12020 todo_wine ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
12021 hr = IDirect3DDevice7_DrawIndexedPrimitiveVB(device, D3DPT_TRIANGLESTRIP, vb, 0, 0, NULL, 0, 0);
12022 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12023 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, NULL, 0, 0);
12024 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12025 hr = IDirect3DDevice7_DrawPrimitiveStrided(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, &strided, 0, 0);
12026 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12027 hr = IDirect3DDevice7_DrawPrimitiveVB(device, D3DPT_TRIANGLESTRIP, vb, 0, 0, 0);
12028 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12030 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, NULL, 0, indices, 4, 0);
12031 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12032 hr = IDirect3DDevice7_DrawIndexedPrimitiveStrided(device,
12033 D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, &strided, 0, indices, 4, 0);
12034 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12035 hr = IDirect3DDevice7_DrawIndexedPrimitiveVB(device, D3DPT_TRIANGLESTRIP, vb, 0, 0, indices, 4, 0);
12036 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12038 strided.position.lpvData = quad;
12039 strided.position.dwStride = sizeof(*quad);
12040 hr = IDirect3DVertexBuffer7_Lock(vb, 0, &data, NULL);
12041 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
12042 memcpy(data, quad, sizeof(quad));
12043 hr = IDirect3DVertexBuffer7_Unlock(vb);
12044 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
12046 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, quad, 4, NULL, 0, 0);
12047 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12048 hr = IDirect3DDevice7_DrawIndexedPrimitiveStrided(device,
12049 D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, &strided, 4, NULL, 0, 0);
12050 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12051 hr = IDirect3DDevice7_DrawIndexedPrimitiveVB(device, D3DPT_TRIANGLESTRIP, vb, 0, 4, NULL, 0, 0);
12052 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12053 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, quad, 4, 0);
12054 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12055 hr = IDirect3DDevice7_DrawPrimitiveStrided(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, &strided, 4, 0);
12056 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12057 hr = IDirect3DDevice7_DrawPrimitiveVB(device, D3DPT_TRIANGLESTRIP, vb, 0, 4, 0);
12058 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12060 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, quad, 4, indices, 4, 0);
12061 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12062 hr = IDirect3DDevice7_DrawIndexedPrimitiveStrided(device,
12063 D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, &strided, 4, indices, 4, 0);
12064 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12065 hr = IDirect3DDevice7_DrawIndexedPrimitiveVB(device, D3DPT_TRIANGLESTRIP, vb, 0, 4, indices, 4, 0);
12066 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12068 IDirect3DVertexBuffer7_Release(vb);
12069 refcount = IDirect3DDevice7_Release(device);
12070 ok(!refcount, "Device has %u references left.\n", refcount);
12071 DestroyWindow(window);
12074 static void test_edge_antialiasing_blending(void)
12076 IDirectDrawSurface7 *offscreen;
12077 DDSURFACEDESC2 surface_desc;
12078 D3DDEVICEDESC7 device_desc;
12079 IDirect3DDevice7 *device;
12080 IDirectDraw7 *ddraw;
12081 IDirect3D7 *d3d;
12082 ULONG refcount;
12083 D3DCOLOR color;
12084 HWND window;
12085 HRESULT hr;
12087 static D3DMATRIX mat =
12089 1.0f, 0.0f, 0.0f, 0.0f,
12090 0.0f, 1.0f, 0.0f, 0.0f,
12091 0.0f, 0.0f, 1.0f, 0.0f,
12092 0.0f, 0.0f, 0.0f, 1.0f,
12094 static struct
12096 struct vec3 position;
12097 DWORD diffuse;
12099 green_quad[] =
12101 {{-1.0f, -1.0f, 0.1f}, 0x7f00ff00},
12102 {{-1.0f, 1.0f, 0.1f}, 0x7f00ff00},
12103 {{ 1.0f, -1.0f, 0.1f}, 0x7f00ff00},
12104 {{ 1.0f, 1.0f, 0.1f}, 0x7f00ff00},
12106 static struct
12108 struct vec3 position;
12109 DWORD diffuse;
12111 red_quad[] =
12113 {{-1.0f, -1.0f, 0.1f}, 0xccff0000},
12114 {{-1.0f, 1.0f, 0.1f}, 0xccff0000},
12115 {{ 1.0f, -1.0f, 0.1f}, 0xccff0000},
12116 {{ 1.0f, 1.0f, 0.1f}, 0xccff0000},
12119 window = create_window();
12120 if (!(device = create_device(window, DDSCL_NORMAL)))
12122 skip("Failed to create a 3D device.\n");
12123 DestroyWindow(window);
12124 return;
12127 hr = IDirect3DDevice7_GetCaps(device, &device_desc);
12128 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
12129 trace("Line edge antialiasing support: %#x.\n",
12130 device_desc.dpcLineCaps.dwRasterCaps & D3DPRASTERCAPS_ANTIALIASEDGES);
12131 trace("Triangle edge antialiasing support: %#x.\n",
12132 device_desc.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_ANTIALIASEDGES);
12134 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
12135 ok(SUCCEEDED(hr), "Failed to get D3D interface, hr %#x.\n", hr);
12136 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
12137 ok(SUCCEEDED(hr), "Failed to get DirectDraw7 interface, hr %#x.\n", hr);
12138 IDirect3D7_Release(d3d);
12140 memset(&surface_desc, 0, sizeof(surface_desc));
12141 surface_desc.dwSize = sizeof(surface_desc);
12142 surface_desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_PIXELFORMAT;
12143 surface_desc.dwWidth = 640;
12144 surface_desc.dwHeight = 480;
12145 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_3DDEVICE;
12146 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
12147 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
12148 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
12149 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
12150 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
12151 U5(U4(surface_desc).ddpfPixelFormat).dwRGBAlphaBitMask = 0xff000000;
12152 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &offscreen, NULL);
12153 ok(hr == D3D_OK, "Creating the offscreen render target failed, hr %#x.\n", hr);
12155 hr = IDirect3DDevice7_SetRenderTarget(device, offscreen, 0);
12156 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
12158 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &mat);
12159 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#x.\n", hr);
12160 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_VIEW, &mat);
12161 ok(SUCCEEDED(hr), "Failed to set view transform, hr %#x.\n", hr);
12162 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &mat);
12163 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
12164 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CLIPPING, FALSE);
12165 ok(SUCCEEDED(hr), "Failed to disable clipping, hr %#x.\n", hr);
12166 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, FALSE);
12167 ok(SUCCEEDED(hr), "Failed to disable Z test, hr %#x.\n", hr);
12168 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, FALSE);
12169 ok(SUCCEEDED(hr), "Failed to disable fog, hr %#x.\n", hr);
12170 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_STENCILENABLE, FALSE);
12171 ok(SUCCEEDED(hr), "Failed to disable stencil test, hr %#x.\n", hr);
12172 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CULLMODE, D3DCULL_NONE);
12173 ok(SUCCEEDED(hr), "Failed to disable culling, hr %#x.\n", hr);
12174 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
12175 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
12177 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);
12178 ok(SUCCEEDED(hr), "Failed to enable blending, hr %#x.\n", hr);
12179 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);
12180 ok(SUCCEEDED(hr), "Failed to set src blend, hr %#x.\n", hr);
12181 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_DESTBLEND, D3DBLEND_DESTALPHA);
12182 ok(SUCCEEDED(hr), "Failed to set dest blend, hr %#x.\n", hr);
12184 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
12185 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
12186 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);
12187 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
12188 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
12189 ok(SUCCEEDED(hr), "Failed to set alpha op, hr %#x.\n", hr);
12190 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);
12191 ok(SUCCEEDED(hr), "Failed to set alpha arg, hr %#x.\n", hr);
12193 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xccff0000, 0.0f, 0);
12194 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
12195 hr = IDirect3DDevice7_BeginScene(device);
12196 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
12197 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE,
12198 green_quad, 4, 0);
12199 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12200 hr = IDirect3DDevice7_EndScene(device);
12201 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
12202 color = get_surface_color(offscreen, 320, 240);
12203 ok(compare_color(color, 0x00cc7f00, 1), "Got unexpected color 0x%08x.\n", color);
12205 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x7f00ff00, 0.0f, 0);
12206 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
12207 hr = IDirect3DDevice7_BeginScene(device);
12208 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
12209 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE,
12210 red_quad, 4, 0);
12211 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12212 hr = IDirect3DDevice7_EndScene(device);
12213 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
12214 color = get_surface_color(offscreen, 320, 240);
12215 ok(compare_color(color, 0x00cc7f00, 1), "Got unexpected color 0x%08x.\n", color);
12217 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, FALSE);
12218 ok(SUCCEEDED(hr), "Failed to disable blending, hr %#x.\n", hr);
12220 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xccff0000, 0.0f, 0);
12221 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
12222 hr = IDirect3DDevice7_BeginScene(device);
12223 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
12224 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE,
12225 green_quad, 4, 0);
12226 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12227 hr = IDirect3DDevice7_EndScene(device);
12228 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
12229 color = get_surface_color(offscreen, 320, 240);
12230 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
12232 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x7f00ff00, 0.0f, 0);
12233 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
12234 hr = IDirect3DDevice7_BeginScene(device);
12235 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
12236 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE,
12237 red_quad, 4, 0);
12238 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12239 hr = IDirect3DDevice7_EndScene(device);
12240 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
12241 color = get_surface_color(offscreen, 320, 240);
12242 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
12244 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_EDGEANTIALIAS, TRUE);
12245 ok(SUCCEEDED(hr), "Failed to enable edge antialiasing, hr %#x.\n", hr);
12247 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xccff0000, 0.0f, 0);
12248 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
12249 hr = IDirect3DDevice7_BeginScene(device);
12250 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
12251 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE,
12252 green_quad, 4, 0);
12253 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12254 hr = IDirect3DDevice7_EndScene(device);
12255 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
12256 color = get_surface_color(offscreen, 320, 240);
12257 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
12259 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x7f00ff00, 0.0f, 0);
12260 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
12261 hr = IDirect3DDevice7_BeginScene(device);
12262 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
12263 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE,
12264 red_quad, 4, 0);
12265 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12266 hr = IDirect3DDevice7_EndScene(device);
12267 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
12268 color = get_surface_color(offscreen, 320, 240);
12269 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
12271 IDirectDrawSurface7_Release(offscreen);
12272 IDirectDraw7_Release(ddraw);
12273 refcount = IDirect3DDevice7_Release(device);
12274 ok(!refcount, "Device has %u references left.\n", refcount);
12275 DestroyWindow(window);
12278 static void test_display_mode_surface_pixel_format(void)
12280 unsigned int width, height, bpp;
12281 IDirectDrawSurface7 *surface;
12282 DDSURFACEDESC2 surface_desc;
12283 IDirectDraw7 *ddraw;
12284 ULONG refcount;
12285 HWND window;
12286 HRESULT hr;
12288 if (!(ddraw = create_ddraw()))
12290 skip("Failed to create ddraw.\n");
12291 return;
12294 surface_desc.dwSize = sizeof(surface_desc);
12295 hr = IDirectDraw7_GetDisplayMode(ddraw, &surface_desc);
12296 ok(SUCCEEDED(hr), "Failed to get display mode, hr %#x.\n", hr);
12297 width = surface_desc.dwWidth;
12298 height = surface_desc.dwHeight;
12300 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
12301 0, 0, width, height, NULL, NULL, NULL, NULL);
12302 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
12303 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
12305 bpp = 0;
12306 if (SUCCEEDED(IDirectDraw7_SetDisplayMode(ddraw, width, height, 16, 0, 0)))
12307 bpp = 16;
12308 if (SUCCEEDED(IDirectDraw7_SetDisplayMode(ddraw, width, height, 24, 0, 0)))
12309 bpp = 24;
12310 if (SUCCEEDED(IDirectDraw7_SetDisplayMode(ddraw, width, height, 32, 0, 0)))
12311 bpp = 32;
12312 ok(bpp, "Set display mode failed.\n");
12314 surface_desc.dwSize = sizeof(surface_desc);
12315 hr = IDirectDraw7_GetDisplayMode(ddraw, &surface_desc);
12316 ok(SUCCEEDED(hr), "Failed to get display mode, hr %#x.\n", hr);
12317 ok(surface_desc.dwWidth == width, "Got width %u, expected %u.\n", surface_desc.dwWidth, width);
12318 ok(surface_desc.dwHeight == height, "Got height %u, expected %u.\n", surface_desc.dwHeight, height);
12319 ok(U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount == bpp, "Got bpp %u, expected %u.\n",
12320 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount, bpp);
12322 memset(&surface_desc, 0, sizeof(surface_desc));
12323 surface_desc.dwSize = sizeof(surface_desc);
12324 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
12325 U5(surface_desc).dwBackBufferCount = 1;
12326 surface_desc.ddsCaps.dwCaps = DDSCAPS_COMPLEX | DDSCAPS_FLIP | DDSCAPS_PRIMARYSURFACE;
12327 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
12328 ok(hr == D3D_OK, "Failed to create surface, hr %#x.\n", hr);
12329 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &surface_desc);
12330 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
12331 ok(surface_desc.dwWidth == width, "Got width %u, expected %u.\n", surface_desc.dwWidth, width);
12332 ok(surface_desc.dwHeight == height, "Got height %u, expected %u.\n", surface_desc.dwHeight, height);
12333 ok(U4(surface_desc).ddpfPixelFormat.dwFlags == DDPF_RGB, "Got unexpected pixel format flags %#x.\n",
12334 U4(surface_desc).ddpfPixelFormat.dwFlags);
12335 ok(U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount == bpp, "Got bpp %u, expected %u.\n",
12336 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount, bpp);
12337 IDirectDrawSurface7_Release(surface);
12339 memset(&surface_desc, 0, sizeof(surface_desc));
12340 surface_desc.dwSize = sizeof(surface_desc);
12341 surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
12342 surface_desc.dwWidth = width;
12343 surface_desc.dwHeight = height;
12344 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
12345 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
12346 ok(hr == D3D_OK, "Failed to create surface, hr %#x.\n", hr);
12347 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &surface_desc);
12348 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
12349 ok(U4(surface_desc).ddpfPixelFormat.dwFlags == DDPF_RGB, "Got unexpected pixel format flags %#x.\n",
12350 U4(surface_desc).ddpfPixelFormat.dwFlags);
12351 ok(U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount == bpp, "Got bpp %u, expected %u.\n",
12352 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount, bpp);
12353 IDirectDrawSurface7_Release(surface);
12355 refcount = IDirectDraw7_Release(ddraw);
12356 ok(!refcount, "DirectDraw has %u references left.\n", refcount);
12357 DestroyWindow(window);
12360 static void test_surface_desc_size(void)
12362 union
12364 DWORD dwSize;
12365 DDSURFACEDESC desc1;
12366 DDSURFACEDESC2 desc2;
12367 BYTE blob[1024];
12368 } desc;
12369 IDirectDrawSurface7 *surface7;
12370 IDirectDrawSurface3 *surface3;
12371 IDirectDrawSurface *surface;
12372 DDSURFACEDESC2 surface_desc;
12373 HRESULT expected_hr, hr;
12374 IDirectDraw7 *ddraw;
12375 unsigned int i, j;
12376 ULONG refcount;
12378 static const struct
12380 unsigned int caps;
12381 const char *name;
12383 surface_caps[] =
12385 {DDSCAPS_OFFSCREENPLAIN, "offscreenplain"},
12386 {DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, "systemmemory texture"},
12387 {DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, "videomemory texture"},
12389 static const unsigned int desc_sizes[] =
12391 sizeof(DDSURFACEDESC),
12392 sizeof(DDSURFACEDESC2),
12393 sizeof(DDSURFACEDESC) + 1,
12394 sizeof(DDSURFACEDESC2) + 1,
12395 2 * sizeof(DDSURFACEDESC),
12396 2 * sizeof(DDSURFACEDESC2),
12397 sizeof(DDSURFACEDESC) - 1,
12398 sizeof(DDSURFACEDESC2) - 1,
12399 sizeof(DDSURFACEDESC) / 2,
12400 sizeof(DDSURFACEDESC2) / 2,
12404 sizeof(desc) / 2,
12405 sizeof(desc) - 100,
12408 if (!(ddraw = create_ddraw()))
12410 skip("Failed to create ddraw.\n");
12411 return;
12413 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
12414 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
12416 for (i = 0; i < ARRAY_SIZE(surface_caps); ++i)
12418 memset(&surface_desc, 0, sizeof(surface_desc));
12419 surface_desc.dwSize = sizeof(surface_desc);
12420 surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
12421 surface_desc.ddsCaps.dwCaps = surface_caps[i].caps;
12422 surface_desc.dwHeight = 128;
12423 surface_desc.dwWidth = 128;
12424 if (FAILED(IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface7, NULL)))
12426 skip("Failed to create surface, type %s.\n", surface_caps[i].name);
12427 continue;
12429 hr = IDirectDrawSurface_QueryInterface(surface7, &IID_IDirectDrawSurface, (void **)&surface);
12430 ok(hr == DD_OK, "Failed to query IDirectDrawSurface, hr %#x, type %s.\n", hr, surface_caps[i].name);
12431 hr = IDirectDrawSurface_QueryInterface(surface7, &IID_IDirectDrawSurface3, (void **)&surface3);
12432 ok(hr == DD_OK, "Failed to query IDirectDrawSurface3, hr %#x, type %s.\n", hr, surface_caps[i].name);
12434 /* GetSurfaceDesc() */
12435 for (j = 0; j < ARRAY_SIZE(desc_sizes); ++j)
12437 memset(&desc, 0, sizeof(desc));
12438 desc.dwSize = desc_sizes[j];
12439 expected_hr = desc.dwSize == sizeof(DDSURFACEDESC) ? DD_OK : DDERR_INVALIDPARAMS;
12440 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &desc.desc1);
12441 ok(hr == expected_hr, "Got hr %#x, expected %#x, dwSize %u, type %s.\n",
12442 hr, expected_hr, desc_sizes[j], surface_caps[i].name);
12444 memset(&desc, 0, sizeof(desc));
12445 desc.dwSize = desc_sizes[j];
12446 expected_hr = desc.dwSize == sizeof(DDSURFACEDESC) ? DD_OK : DDERR_INVALIDPARAMS;
12447 hr = IDirectDrawSurface3_GetSurfaceDesc(surface3, &desc.desc1);
12448 ok(hr == expected_hr, "Got hr %#x, expected %#x, dwSize %u, type %s.\n",
12449 hr, expected_hr, desc_sizes[j], surface_caps[i].name);
12451 memset(&desc, 0, sizeof(desc));
12452 desc.dwSize = desc_sizes[j];
12453 expected_hr = desc.dwSize == sizeof(DDSURFACEDESC2) ? DD_OK : DDERR_INVALIDPARAMS;
12454 hr = IDirectDrawSurface7_GetSurfaceDesc(surface7, &desc.desc2);
12455 ok(hr == expected_hr, "Got hr %#x, expected %#x, dwSize %u, type %s.\n",
12456 hr, expected_hr, desc_sizes[j], surface_caps[i].name);
12459 /* Lock() */
12460 for (j = 0; j < ARRAY_SIZE(desc_sizes); ++j)
12462 const BOOL ignore_size = surface_caps[i].caps & DDSCAPS_TEXTURE
12463 && !(surface_caps[i].caps & DDSCAPS_VIDEOMEMORY);
12464 const BOOL valid_size = desc_sizes[j] == sizeof(DDSURFACEDESC)
12465 || desc_sizes[j] == sizeof(DDSURFACEDESC2);
12466 DWORD expected_texture_stage;
12468 memset(&desc, 0, sizeof(desc));
12469 desc.dwSize = desc_sizes[j];
12470 desc.desc2.dwTextureStage = 0xdeadbeef;
12471 desc.blob[sizeof(DDSURFACEDESC2)] = 0xef;
12472 hr = IDirectDrawSurface_Lock(surface, NULL, &desc.desc1, 0, 0);
12473 expected_hr = ignore_size || valid_size ? DD_OK : DDERR_INVALIDPARAMS;
12474 ok(hr == expected_hr, "Got hr %#x, expected %#x, dwSize %u, type %s.\n",
12475 hr, expected_hr, desc_sizes[j], surface_caps[i].name);
12476 ok(desc.dwSize == desc_sizes[j], "dwSize was changed from %u to %u, type %s.\n",
12477 desc_sizes[j], desc.dwSize, surface_caps[i].name);
12478 ok(desc.blob[sizeof(DDSURFACEDESC2)] == 0xef, "Got unexpected byte %02x, dwSize %u, type %s.\n",
12479 desc.blob[sizeof(DDSURFACEDESC2)], desc_sizes[j], surface_caps[i].name);
12480 if (SUCCEEDED(hr))
12482 ok(desc.desc1.dwWidth == 128, "Got unexpected width %u, dwSize %u, type %s.\n",
12483 desc.desc1.dwWidth, desc_sizes[j], surface_caps[i].name);
12484 ok(desc.desc1.dwHeight == 128, "Got unexpected height %u, dwSize %u, type %s.\n",
12485 desc.desc1.dwHeight, desc_sizes[j], surface_caps[i].name);
12486 expected_texture_stage = desc_sizes[j] >= sizeof(DDSURFACEDESC2) ? 0 : 0xdeadbeef;
12487 todo_wine_if(!expected_texture_stage)
12488 ok(desc.desc2.dwTextureStage == expected_texture_stage,
12489 "Got unexpected texture stage %#x, dwSize %u, type %s.\n",
12490 desc.desc2.dwTextureStage, desc_sizes[j], surface_caps[i].name);
12491 IDirectDrawSurface_Unlock(surface, NULL);
12494 memset(&desc, 0, sizeof(desc));
12495 desc.dwSize = desc_sizes[j];
12496 desc.desc2.dwTextureStage = 0xdeadbeef;
12497 desc.blob[sizeof(DDSURFACEDESC2)] = 0xef;
12498 hr = IDirectDrawSurface3_Lock(surface3, NULL, &desc.desc1, 0, 0);
12499 expected_hr = ignore_size || valid_size ? DD_OK : DDERR_INVALIDPARAMS;
12500 ok(hr == expected_hr, "Got hr %#x, expected %#x, dwSize %u, type %s.\n",
12501 hr, expected_hr, desc_sizes[j], surface_caps[i].name);
12502 ok(desc.dwSize == desc_sizes[j], "dwSize was changed from %u to %u, type %s.\n",
12503 desc_sizes[j], desc.dwSize, surface_caps[i].name);
12504 ok(desc.blob[sizeof(DDSURFACEDESC2)] == 0xef, "Got unexpected byte %02x, dwSize %u, type %s.\n",
12505 desc.blob[sizeof(DDSURFACEDESC2)], desc_sizes[j], surface_caps[i].name);
12506 if (SUCCEEDED(hr))
12508 ok(desc.desc1.dwWidth == 128, "Got unexpected width %u, dwSize %u, type %s.\n",
12509 desc.desc1.dwWidth, desc_sizes[j], surface_caps[i].name);
12510 ok(desc.desc1.dwHeight == 128, "Got unexpected height %u, dwSize %u, type %s.\n",
12511 desc.desc1.dwHeight, desc_sizes[j], surface_caps[i].name);
12512 expected_texture_stage = desc_sizes[j] >= sizeof(DDSURFACEDESC2) ? 0 : 0xdeadbeef;
12513 todo_wine_if(!expected_texture_stage)
12514 ok(desc.desc2.dwTextureStage == expected_texture_stage,
12515 "Got unexpected texture stage %#x, dwSize %u, type %s.\n",
12516 desc.desc2.dwTextureStage, desc_sizes[j], surface_caps[i].name);
12517 IDirectDrawSurface3_Unlock(surface3, NULL);
12520 memset(&desc, 0, sizeof(desc));
12521 desc.dwSize = desc_sizes[j];
12522 desc.desc2.dwTextureStage = 0xdeadbeef;
12523 desc.blob[sizeof(DDSURFACEDESC2)] = 0xef;
12524 hr = IDirectDrawSurface7_Lock(surface7, NULL, &desc.desc2, 0, 0);
12525 expected_hr = ignore_size || valid_size ? DD_OK : DDERR_INVALIDPARAMS;
12526 ok(hr == expected_hr, "Got hr %#x, expected %#x, dwSize %u, type %s.\n",
12527 hr, expected_hr, desc_sizes[j], surface_caps[i].name);
12528 ok(desc.dwSize == desc_sizes[j], "dwSize was changed from %u to %u, type %s.\n",
12529 desc_sizes[j], desc.dwSize, surface_caps[i].name);
12530 ok(desc.blob[sizeof(DDSURFACEDESC2)] == 0xef, "Got unexpected byte %02x, dwSize %u, type %s.\n",
12531 desc.blob[sizeof(DDSURFACEDESC2)], desc_sizes[j], surface_caps[i].name);
12532 if (SUCCEEDED(hr))
12534 ok(desc.desc2.dwWidth == 128, "Got unexpected width %u, dwSize %u, type %s.\n",
12535 desc.desc2.dwWidth, desc_sizes[j], surface_caps[i].name);
12536 ok(desc.desc2.dwHeight == 128, "Got unexpected height %u, dwSize %u, type %s.\n",
12537 desc.desc2.dwHeight, desc_sizes[j], surface_caps[i].name);
12538 expected_texture_stage = desc_sizes[j] >= sizeof(DDSURFACEDESC2) ? 0 : 0xdeadbeef;
12539 ok(desc.desc2.dwTextureStage == expected_texture_stage,
12540 "Got unexpected texture stage %#x, dwSize %u, type %s.\n",
12541 desc.desc2.dwTextureStage, desc_sizes[j], surface_caps[i].name);
12542 IDirectDrawSurface7_Unlock(surface7, NULL);
12546 IDirectDrawSurface7_Release(surface7);
12547 IDirectDrawSurface3_Release(surface3);
12548 IDirectDrawSurface_Release(surface);
12551 /* GetDisplayMode() */
12552 for (j = 0; j < ARRAY_SIZE(desc_sizes); ++j)
12554 memset(&desc, 0xcc, sizeof(desc));
12555 desc.dwSize = desc_sizes[j];
12556 expected_hr = (desc.dwSize == sizeof(DDSURFACEDESC) || desc.dwSize == sizeof(DDSURFACEDESC2))
12557 ? DD_OK : DDERR_INVALIDPARAMS;
12558 hr = IDirectDraw7_GetDisplayMode(ddraw, &desc.desc2);
12559 ok(hr == expected_hr, "Got hr %#x, expected %#x, size %u.\n", hr, expected_hr, desc_sizes[j]);
12560 if (SUCCEEDED(hr))
12562 ok(desc.dwSize == sizeof(DDSURFACEDESC2), "Wrong size %u for %u.\n", desc.dwSize, desc_sizes[j]);
12563 ok(desc.blob[desc_sizes[j]] == 0xcc, "Overflow for size %u.\n", desc_sizes[j]);
12564 ok(desc.blob[desc_sizes[j] - 1] != 0xcc, "Struct not cleared for size %u.\n", desc_sizes[j]);
12568 refcount = IDirectDraw7_Release(ddraw);
12569 ok(!refcount, "DirectDraw has %u references left.\n", refcount);
12572 static void test_get_surface_from_dc(void)
12574 IDirectDrawSurface *surface1, *tmp1;
12575 IDirectDrawSurface7 *surface, *tmp;
12576 DDSURFACEDESC2 surface_desc;
12577 IDirectDraw7 *ddraw;
12578 HDC dc, device_dc;
12579 ULONG refcount;
12580 HWND window;
12581 HRESULT hr;
12582 DWORD ret;
12584 window = create_window();
12585 ddraw = create_ddraw();
12586 ok(!!ddraw, "Failed to create a ddraw object.\n");
12587 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
12588 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
12590 memset(&surface_desc, 0, sizeof(surface_desc));
12591 surface_desc.dwSize = sizeof(surface_desc);
12592 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
12593 surface_desc.dwWidth = 64;
12594 surface_desc.dwHeight = 64;
12595 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
12597 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
12598 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
12599 hr = IDirectDrawSurface7_QueryInterface(surface, &IID_IDirectDrawSurface, (void **)&surface1);
12600 ok(SUCCEEDED(hr), "Failed to query IDirectDrawSurface interface, hr %#x.\n", hr);
12602 refcount = get_refcount((IUnknown *)surface1);
12603 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
12604 refcount = get_refcount((IUnknown *)surface);
12605 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
12607 hr = IDirectDrawSurface7_GetDC(surface, &dc);
12608 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
12610 tmp1 = (void *)0xdeadbeef;
12611 device_dc = (void *)0xdeadbeef;
12612 hr = GetSurfaceFromDC(NULL, &tmp1, &device_dc);
12613 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
12614 ok(!tmp1, "Got unexpected surface %p.\n", tmp1);
12615 ok(!device_dc, "Got unexpected device_dc %p.\n", device_dc);
12617 device_dc = (void *)0xdeadbeef;
12618 hr = GetSurfaceFromDC(dc, NULL, &device_dc);
12619 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
12620 ok(device_dc == (void *)0xdeadbeef, "Got unexpected device_dc %p.\n", device_dc);
12622 tmp1 = (void *)0xdeadbeef;
12623 hr = GetSurfaceFromDC(dc, &tmp1, NULL);
12624 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
12625 ok(!tmp1, "Got unexpected surface %p.\n", tmp1);
12627 hr = GetSurfaceFromDC(dc, &tmp1, &device_dc);
12628 ok(SUCCEEDED(hr), "GetSurfaceFromDC failed, hr %#x.\n", hr);
12629 ok(tmp1 == surface1, "Got unexpected surface %p, expected %p.\n", tmp1, surface1);
12630 IDirectDrawSurface_Release(tmp1);
12632 ret = GetObjectType(device_dc);
12633 todo_wine ok(ret == OBJ_DC, "Got unexpected object type %#x.\n", ret);
12634 ret = GetDeviceCaps(device_dc, TECHNOLOGY);
12635 todo_wine ok(ret == DT_RASDISPLAY, "Got unexpected technology %#x.\n", ret);
12637 hr = IDirectDraw7_GetSurfaceFromDC(ddraw, dc, NULL);
12638 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
12640 hr = IDirectDraw7_GetSurfaceFromDC(ddraw, dc, &tmp);
12641 ok(SUCCEEDED(hr), "GetSurfaceFromDC failed, hr %#x.\n", hr);
12642 ok(tmp == surface, "Got unexpected surface %p, expected %p.\n", tmp, surface);
12644 refcount = get_refcount((IUnknown *)surface1);
12645 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
12646 refcount = get_refcount((IUnknown *)surface);
12647 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
12649 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
12650 ok(SUCCEEDED(hr), "ReleaseDC failed, hr %#x.\n", hr);
12652 IDirectDrawSurface_Release(tmp);
12654 dc = CreateCompatibleDC(NULL);
12655 ok(!!dc, "CreateCompatibleDC failed.\n");
12657 tmp1 = (void *)0xdeadbeef;
12658 device_dc = (void *)0xdeadbeef;
12659 hr = GetSurfaceFromDC(dc, &tmp1, &device_dc);
12660 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
12661 ok(!tmp1, "Got unexpected surface %p.\n", tmp1);
12662 ok(!device_dc, "Got unexpected device_dc %p.\n", device_dc);
12664 tmp = (void *)0xdeadbeef;
12665 hr = IDirectDraw7_GetSurfaceFromDC(ddraw, dc, &tmp);
12666 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
12667 ok(!tmp, "Got unexpected surface %p.\n", tmp);
12669 ok(DeleteDC(dc), "DeleteDC failed.\n");
12671 tmp = (void *)0xdeadbeef;
12672 hr = IDirectDraw7_GetSurfaceFromDC(ddraw, NULL, &tmp);
12673 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
12674 ok(!tmp, "Got unexpected surface %p.\n", tmp);
12676 IDirectDrawSurface7_Release(surface);
12677 IDirectDrawSurface_Release(surface1);
12678 IDirectDraw7_Release(ddraw);
12679 DestroyWindow(window);
12682 static void test_ck_operation(void)
12684 IDirectDrawSurface7 *src, *dst;
12685 IDirectDrawSurface *src1, *dst1;
12686 DDSURFACEDESC2 surface_desc;
12687 IDirectDraw7 *ddraw;
12688 ULONG refcount;
12689 HWND window;
12690 HRESULT hr;
12691 D3DCOLOR *color;
12692 unsigned int i;
12693 DDCOLORKEY ckey;
12694 DDBLTFX fx;
12696 window = create_window();
12697 ddraw = create_ddraw();
12698 ok(!!ddraw, "Failed to create a ddraw object.\n");
12699 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
12700 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
12702 memset(&surface_desc, 0, sizeof(surface_desc));
12703 surface_desc.dwSize = sizeof(surface_desc);
12704 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
12705 surface_desc.dwWidth = 4;
12706 surface_desc.dwHeight = 1;
12707 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
12708 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
12709 U1(U4(surface_desc.ddpfPixelFormat)).dwRGBBitCount = 32;
12710 U2(U4(surface_desc.ddpfPixelFormat)).dwRBitMask = 0x00ff0000;
12711 U3(U4(surface_desc.ddpfPixelFormat)).dwGBitMask = 0x0000ff00;
12712 U4(U4(surface_desc.ddpfPixelFormat)).dwBBitMask = 0x000000ff;
12713 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &dst, NULL);
12714 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
12716 surface_desc.dwFlags |= DDSD_CKSRCBLT;
12717 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00ff00ff;
12718 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00ff00ff;
12719 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &src, NULL);
12720 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
12722 hr = IDirectDrawSurface7_Lock(src, NULL, &surface_desc, DDLOCK_WAIT, NULL);
12723 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
12724 ok(!(surface_desc.dwFlags & DDSD_LPSURFACE), "Surface desc has LPSURFACE Flags set.\n");
12725 color = surface_desc.lpSurface;
12726 color[0] = 0x77010203;
12727 color[1] = 0x00010203;
12728 color[2] = 0x77ff00ff;
12729 color[3] = 0x00ff00ff;
12730 hr = IDirectDrawSurface7_Unlock(src, NULL);
12731 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
12733 for (i = 0; i < 2; ++i)
12735 hr = IDirectDrawSurface7_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
12736 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
12737 color = surface_desc.lpSurface;
12738 color[0] = 0xcccccccc;
12739 color[1] = 0xcccccccc;
12740 color[2] = 0xcccccccc;
12741 color[3] = 0xcccccccc;
12742 hr = IDirectDrawSurface7_Unlock(dst, NULL);
12743 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
12745 if (i)
12747 hr = IDirectDrawSurface7_BltFast(dst, 0, 0, src, NULL, DDBLTFAST_SRCCOLORKEY);
12748 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
12750 else
12752 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_KEYSRC, NULL);
12753 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
12756 hr = IDirectDrawSurface7_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT | DDLOCK_READONLY, NULL);
12757 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
12758 ok(!(surface_desc.dwFlags & DDSD_LPSURFACE), "Surface desc has LPSURFACE Flags set.\n");
12759 color = surface_desc.lpSurface;
12760 /* Different behavior on some drivers / windows versions. Some versions ignore the X channel when
12761 * color keying, but copy it to the destination surface. Others (sysmem surfaces) apply it for
12762 * color keying, but do not copy it into the destination surface. Nvidia neither uses it for
12763 * color keying nor copies it. */
12764 ok((color[0] == 0x77010203 && color[1] == 0x00010203
12765 && color[2] == 0xcccccccc && color[3] == 0xcccccccc) /* AMD, Wine */
12766 || broken(color[0] == 0x00010203 && color[1] == 0x00010203
12767 && color[2] == 0x00ff00ff && color[3] == 0xcccccccc) /* Sysmem surfaces? */
12768 || broken(color[0] == 0x00010203 && color[1] == 0x00010203
12769 && color[2] == 0xcccccccc && color[3] == 0xcccccccc) /* Nvidia */
12770 || broken(color[0] == 0xff010203 && color[1] == 0xff010203
12771 && color[2] == 0xcccccccc && color[3] == 0xcccccccc) /* Testbot */,
12772 "Destination data after blitting is %08x %08x %08x %08x, i=%u.\n",
12773 color[0], color[1], color[2], color[3], i);
12774 hr = IDirectDrawSurface7_Unlock(dst, NULL);
12775 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
12778 hr = IDirectDrawSurface7_GetColorKey(src, DDCKEY_SRCBLT, &ckey);
12779 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
12780 ok(ckey.dwColorSpaceLowValue == 0x00ff00ff && ckey.dwColorSpaceHighValue == 0x00ff00ff,
12781 "Got unexpected color key low=%08x high=%08x.\n", ckey.dwColorSpaceLowValue, ckey.dwColorSpaceHighValue);
12783 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0x0000ff00;
12784 hr = IDirectDrawSurface7_SetColorKey(src, DDCKEY_SRCBLT, &ckey);
12785 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
12787 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0;
12788 hr = IDirectDrawSurface7_GetColorKey(src, DDCKEY_SRCBLT, &ckey);
12789 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
12790 ok(ckey.dwColorSpaceLowValue == 0x0000ff00 && ckey.dwColorSpaceHighValue == 0x0000ff00,
12791 "Got unexpected color key low=%08x high=%08x.\n", ckey.dwColorSpaceLowValue, ckey.dwColorSpaceHighValue);
12793 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0;
12794 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0;
12795 hr = IDirectDrawSurface7_GetSurfaceDesc(src, &surface_desc);
12796 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
12797 ok(surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue == 0x0000ff00
12798 && surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue == 0x0000ff00,
12799 "Got unexpected color key low=%08x high=%08x.\n", surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue,
12800 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue);
12802 /* Test SetColorKey with dwColorSpaceHighValue < dwColorSpaceLowValue */
12803 ckey.dwColorSpaceLowValue = 0x000000ff;
12804 ckey.dwColorSpaceHighValue = 0x00000000;
12805 hr = IDirectDrawSurface7_SetColorKey(src, DDCKEY_SRCBLT, &ckey);
12806 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
12808 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0;
12809 hr = IDirectDrawSurface7_GetColorKey(src, DDCKEY_SRCBLT, &ckey);
12810 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
12811 ok(ckey.dwColorSpaceLowValue == 0x000000ff && ckey.dwColorSpaceHighValue == 0x000000ff,
12812 "Got unexpected color key low=%08x high=%08x.\n", ckey.dwColorSpaceLowValue, ckey.dwColorSpaceHighValue);
12814 ckey.dwColorSpaceLowValue = 0x000000ff;
12815 ckey.dwColorSpaceHighValue = 0x00000001;
12816 hr = IDirectDrawSurface7_SetColorKey(src, DDCKEY_SRCBLT, &ckey);
12817 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
12819 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0;
12820 hr = IDirectDrawSurface7_GetColorKey(src, DDCKEY_SRCBLT, &ckey);
12821 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
12822 ok(ckey.dwColorSpaceLowValue == 0x000000ff && ckey.dwColorSpaceHighValue == 0x000000ff,
12823 "Got unexpected color key low=%08x high=%08x.\n", ckey.dwColorSpaceLowValue, ckey.dwColorSpaceHighValue);
12825 ckey.dwColorSpaceLowValue = 0x000000fe;
12826 ckey.dwColorSpaceHighValue = 0x000000fd;
12827 hr = IDirectDrawSurface7_SetColorKey(src, DDCKEY_SRCBLT, &ckey);
12828 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
12830 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0;
12831 hr = IDirectDrawSurface7_GetColorKey(src, DDCKEY_SRCBLT, &ckey);
12832 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
12833 ok(ckey.dwColorSpaceLowValue == 0x000000fe && ckey.dwColorSpaceHighValue == 0x000000fe,
12834 "Got unexpected color key low=%08x high=%08x.\n", ckey.dwColorSpaceLowValue, ckey.dwColorSpaceHighValue);
12836 IDirectDrawSurface7_Release(src);
12837 IDirectDrawSurface7_Release(dst);
12839 /* Test source and destination keys and where they are read from. Use a surface with alpha
12840 * to avoid driver-dependent content in the X channel. */
12841 memset(&surface_desc, 0, sizeof(surface_desc));
12842 surface_desc.dwSize = sizeof(surface_desc);
12843 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
12844 surface_desc.dwWidth = 6;
12845 surface_desc.dwHeight = 1;
12846 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
12847 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
12848 U1(U4(surface_desc.ddpfPixelFormat)).dwRGBBitCount = 32;
12849 U2(U4(surface_desc.ddpfPixelFormat)).dwRBitMask = 0x00ff0000;
12850 U3(U4(surface_desc.ddpfPixelFormat)).dwGBitMask = 0x0000ff00;
12851 U4(U4(surface_desc.ddpfPixelFormat)).dwBBitMask = 0x000000ff;
12852 U5(U4(surface_desc.ddpfPixelFormat)).dwRGBAlphaBitMask = 0xff000000;
12853 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &dst, NULL);
12854 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
12855 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &src, NULL);
12856 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
12858 ckey.dwColorSpaceLowValue = 0x0000ff00;
12859 ckey.dwColorSpaceHighValue = 0x0000ff00;
12860 hr = IDirectDrawSurface7_SetColorKey(dst, DDCKEY_SRCBLT, &ckey);
12861 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
12862 ckey.dwColorSpaceLowValue = 0x00ff0000;
12863 ckey.dwColorSpaceHighValue = 0x00ff0000;
12864 hr = IDirectDrawSurface7_SetColorKey(dst, DDCKEY_DESTBLT, &ckey);
12865 ok(SUCCEEDED(hr) || hr == DDERR_NOCOLORKEYHW, "Failed to set color key, hr %#x.\n", hr);
12866 if (FAILED(hr))
12868 /* Nvidia reject dest keys, AMD allows them. This applies to vidmem and sysmem surfaces. */
12869 skip("Failed to set destination color key, skipping related tests.\n");
12870 goto done;
12873 ckey.dwColorSpaceLowValue = 0x000000ff;
12874 ckey.dwColorSpaceHighValue = 0x000000ff;
12875 hr = IDirectDrawSurface7_SetColorKey(src, DDCKEY_SRCBLT, &ckey);
12876 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
12877 ckey.dwColorSpaceLowValue = 0x000000aa;
12878 ckey.dwColorSpaceHighValue = 0x000000aa;
12879 hr = IDirectDrawSurface7_SetColorKey(src, DDCKEY_DESTBLT, &ckey);
12880 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
12882 memset(&fx, 0, sizeof(fx));
12883 fx.dwSize = sizeof(fx);
12884 fx.ddckSrcColorkey.dwColorSpaceHighValue = 0x00110000;
12885 fx.ddckSrcColorkey.dwColorSpaceLowValue = 0x00110000;
12886 fx.ddckDestColorkey.dwColorSpaceHighValue = 0x00001100;
12887 fx.ddckDestColorkey.dwColorSpaceLowValue = 0x00001100;
12889 hr = IDirectDrawSurface7_Lock(src, NULL, &surface_desc, DDLOCK_WAIT, NULL);
12890 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
12891 color = surface_desc.lpSurface;
12892 color[0] = 0x000000ff; /* Applies to src blt key in src surface. */
12893 color[1] = 0x000000aa; /* Applies to dst blt key in src surface. */
12894 color[2] = 0x00ff0000; /* Dst color key in dst surface. */
12895 color[3] = 0x0000ff00; /* Src color key in dst surface. */
12896 color[4] = 0x00001100; /* Src color key in ddbltfx. */
12897 color[5] = 0x00110000; /* Dst color key in ddbltfx. */
12898 hr = IDirectDrawSurface7_Unlock(src, NULL);
12899 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
12901 hr = IDirectDrawSurface7_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
12902 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
12903 color = surface_desc.lpSurface;
12904 color[0] = color[1] = color[2] = color[3] = color[4] = color[5] = 0x55555555;
12905 hr = IDirectDrawSurface7_Unlock(dst, NULL);
12906 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
12908 /* Test a blit without keying. */
12909 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, 0, &fx);
12910 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
12912 hr = IDirectDrawSurface7_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
12913 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
12914 color = surface_desc.lpSurface;
12915 /* Should have copied src data unmodified to dst. */
12916 ok(color[0] == 0x000000ff && color[1] == 0x000000aa && color[2] == 0x00ff0000 &&
12917 color[3] == 0x0000ff00 && color[4] == 0x00001100 && color[5] == 0x00110000,
12918 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
12919 color[0], color[1], color[2], color[3], color[4], color[5]);
12921 color[0] = color[1] = color[2] = color[3] = color[4] = color[5] = 0x55555555;
12922 hr = IDirectDrawSurface7_Unlock(dst, NULL);
12923 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
12925 /* Src key. */
12926 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_KEYSRC, &fx);
12927 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
12929 hr = IDirectDrawSurface7_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
12930 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
12931 color = surface_desc.lpSurface;
12932 /* Src key applied to color[0]. It is unmodified, the others are copied. */
12933 ok(color[0] == 0x55555555 && color[1] == 0x000000aa && color[2] == 0x00ff0000 &&
12934 color[3] == 0x0000ff00 && color[4] == 0x00001100 && color[5] == 0x00110000,
12935 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
12936 color[0], color[1], color[2], color[3], color[4], color[5]);
12938 color[0] = color[1] = color[2] = color[3] = color[4] = color[5] = 0x55555555;
12939 hr = IDirectDrawSurface7_Unlock(dst, NULL);
12940 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
12942 /* Src override. */
12943 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_KEYSRCOVERRIDE, &fx);
12944 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
12946 hr = IDirectDrawSurface7_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
12947 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
12948 color = surface_desc.lpSurface;
12949 /* Override key applied to color[5]. It is unmodified, the others are copied. */
12950 ok(color[0] == 0x000000ff && color[1] == 0x000000aa && color[2] == 0x00ff0000 &&
12951 color[3] == 0x0000ff00 && color[4] == 0x00001100 && color[5] == 0x55555555,
12952 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
12953 color[0], color[1], color[2], color[3], color[4], color[5]);
12955 color[0] = color[1] = color[2] = color[3] = color[4] = color[5] = 0x55555555;
12956 hr = IDirectDrawSurface7_Unlock(dst, NULL);
12957 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
12959 /* Src override AND src key. That is not supposed to work. */
12960 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_KEYSRC | DDBLT_KEYSRCOVERRIDE, &fx);
12961 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
12963 hr = IDirectDrawSurface7_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
12964 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
12965 color = surface_desc.lpSurface;
12966 /* Ensure the destination was not changed. */
12967 ok(color[0] == 0x55555555 && color[1] == 0x55555555 && color[2] == 0x55555555 &&
12968 color[3] == 0x55555555 && color[4] == 0x55555555 && color[5] == 0x55555555,
12969 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
12970 color[0], color[1], color[2], color[3], color[4], color[5]);
12972 /* Use different dst colors for the dst key test. */
12973 color[0] = 0x00ff0000; /* Dest key in dst surface. */
12974 color[1] = 0x00ff0000; /* Dest key in dst surface. */
12975 color[2] = 0x00001100; /* Dest key in override. */
12976 color[3] = 0x00001100; /* Dest key in override. */
12977 color[4] = 0x000000aa; /* Dest key in src surface. */
12978 color[5] = 0x000000aa; /* Dest key in src surface. */
12979 hr = IDirectDrawSurface7_Unlock(dst, NULL);
12980 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
12982 /* Dest key blit. The key is taken from the DESTINATION surface in v7! */
12983 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_KEYDEST, &fx);
12984 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
12986 hr = IDirectDrawSurface7_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
12987 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
12988 color = surface_desc.lpSurface;
12989 /* Dst key applied to color[0,1], they are the only changed pixels. */
12990 todo_wine ok(color[0] == 0x000000ff && color[1] == 0x000000aa && color[2] == 0x00001100 &&
12991 color[3] == 0x00001100 && color[4] == 0x000000aa && color[5] == 0x000000aa,
12992 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
12993 color[0], color[1], color[2], color[3], color[4], color[5]);
12995 color[0] = 0x00ff0000; /* Dest key in dst surface. */
12996 color[1] = 0x00ff0000; /* Dest key in dst surface. */
12997 color[2] = 0x00001100; /* Dest key in override. */
12998 color[3] = 0x00001100; /* Dest key in override. */
12999 color[4] = 0x000000aa; /* Dest key in src surface. */
13000 color[5] = 0x000000aa; /* Dest key in src surface. */
13001 hr = IDirectDrawSurface7_Unlock(dst, NULL);
13002 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
13004 /* What happens with a QI'd older version of the interface? It takes the key
13005 * from the source surface. */
13006 hr = IDirectDrawSurface7_QueryInterface(src, &IID_IDirectDrawSurface, (void **)&src1);
13007 ok(SUCCEEDED(hr), "Failed to query IDirectDrawSurface interface, hr %#x.\n", hr);
13008 hr = IDirectDrawSurface7_QueryInterface(dst, &IID_IDirectDrawSurface, (void **)&dst1);
13009 ok(SUCCEEDED(hr), "Failed to query IDirectDrawSurface interface, hr %#x.\n", hr);
13011 hr = IDirectDrawSurface_Blt(dst1, NULL, src1, NULL, DDBLT_KEYDEST, &fx);
13012 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
13014 IDirectDrawSurface_Release(dst1);
13015 IDirectDrawSurface_Release(src1);
13017 hr = IDirectDrawSurface7_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
13018 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
13019 color = surface_desc.lpSurface;
13020 /* Dst key applied to color[4,5], they are the only changed pixels. */
13021 ok(color[0] == 0x00ff0000 && color[1] == 0x00ff0000 && color[2] == 0x00001100 &&
13022 color[3] == 0x00001100 && color[4] == 0x00001100 && color[5] == 0x00110000,
13023 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
13024 color[0], color[1], color[2], color[3], color[4], color[5]);
13026 color[0] = 0x00ff0000; /* Dest key in dst surface. */
13027 color[1] = 0x00ff0000; /* Dest key in dst surface. */
13028 color[2] = 0x00001100; /* Dest key in override. */
13029 color[3] = 0x00001100; /* Dest key in override. */
13030 color[4] = 0x000000aa; /* Dest key in src surface. */
13031 color[5] = 0x000000aa; /* Dest key in src surface. */
13032 hr = IDirectDrawSurface7_Unlock(dst, NULL);
13033 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
13035 /* Dest override key blit. */
13036 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_KEYDESTOVERRIDE, &fx);
13037 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
13039 hr = IDirectDrawSurface7_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
13040 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
13041 color = surface_desc.lpSurface;
13042 /* Dst key applied to color[2,3], they are the only changed pixels. */
13043 ok(color[0] == 0x00ff0000 && color[1] == 0x00ff0000 && color[2] == 0x00ff0000 &&
13044 color[3] == 0x0000ff00 && color[4] == 0x000000aa && color[5] == 0x000000aa,
13045 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
13046 color[0], color[1], color[2], color[3], color[4], color[5]);
13048 color[0] = 0x00ff0000; /* Dest key in dst surface. */
13049 color[1] = 0x00ff0000; /* Dest key in dst surface. */
13050 color[2] = 0x00001100; /* Dest key in override. */
13051 color[3] = 0x00001100; /* Dest key in override. */
13052 color[4] = 0x000000aa; /* Dest key in src surface. */
13053 color[5] = 0x000000aa; /* Dest key in src surface. */
13054 hr = IDirectDrawSurface7_Unlock(dst, NULL);
13055 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
13057 /* Dest override together with surface key. Supposed to fail. */
13058 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_KEYDEST | DDBLT_KEYDESTOVERRIDE, &fx);
13059 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
13061 hr = IDirectDrawSurface7_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
13062 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
13063 color = surface_desc.lpSurface;
13064 /* Destination is unchanged. */
13065 ok(color[0] == 0x00ff0000 && color[1] == 0x00ff0000 && color[2] == 0x00001100 &&
13066 color[3] == 0x00001100 && color[4] == 0x000000aa && color[5] == 0x000000aa,
13067 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
13068 color[0], color[1], color[2], color[3], color[4], color[5]);
13069 hr = IDirectDrawSurface7_Unlock(dst, NULL);
13070 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
13072 /* Source and destination key. This is driver dependent. New HW treats it like
13073 * DDBLT_KEYSRC. Older HW and some software renderers apply both keys. */
13074 if (0)
13076 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_KEYDEST | DDBLT_KEYSRC, &fx);
13077 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
13079 hr = IDirectDrawSurface7_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
13080 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
13081 color = surface_desc.lpSurface;
13082 /* Color[0] is filtered by the src key, 2-5 are filtered by the dst key, if
13083 * the driver applies it. */
13084 ok(color[0] == 0x00ff0000 && color[1] == 0x000000aa && color[2] == 0x00ff0000 &&
13085 color[3] == 0x0000ff00 && color[4] == 0x00001100 && color[5] == 0x00110000,
13086 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
13087 color[0], color[1], color[2], color[3], color[4], color[5]);
13089 color[0] = 0x00ff0000; /* Dest key in dst surface. */
13090 color[1] = 0x00ff0000; /* Dest key in dst surface. */
13091 color[2] = 0x00001100; /* Dest key in override. */
13092 color[3] = 0x00001100; /* Dest key in override. */
13093 color[4] = 0x000000aa; /* Dest key in src surface. */
13094 color[5] = 0x000000aa; /* Dest key in src surface. */
13095 hr = IDirectDrawSurface7_Unlock(dst, NULL);
13096 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
13099 /* Override keys without ddbltfx parameter fail */
13100 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_KEYDESTOVERRIDE, NULL);
13101 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
13102 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_KEYSRCOVERRIDE, NULL);
13103 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
13105 /* Try blitting without keys in the source surface. */
13106 hr = IDirectDrawSurface7_SetColorKey(src, DDCKEY_SRCBLT, NULL);
13107 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
13108 hr = IDirectDrawSurface7_SetColorKey(src, DDCKEY_DESTBLT, NULL);
13109 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
13111 /* That fails now. Do not bother to check that the data is unmodified. */
13112 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_KEYSRC, &fx);
13113 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
13115 /* Dest key blit still works, the destination surface key is used in v7. */
13116 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_KEYDEST, &fx);
13117 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
13119 hr = IDirectDrawSurface7_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
13120 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
13121 color = surface_desc.lpSurface;
13122 /* Dst key applied to color[0,1], they are the only changed pixels. */
13123 todo_wine ok(color[0] == 0x000000ff && color[1] == 0x000000aa && color[2] == 0x00001100 &&
13124 color[3] == 0x00001100 && color[4] == 0x000000aa && color[5] == 0x000000aa,
13125 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
13126 color[0], color[1], color[2], color[3], color[4], color[5]);
13127 hr = IDirectDrawSurface7_Unlock(dst, NULL);
13128 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
13130 /* Try blitting without keys in the destination surface. */
13131 hr = IDirectDrawSurface7_SetColorKey(dst, DDCKEY_SRCBLT, NULL);
13132 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
13133 hr = IDirectDrawSurface7_SetColorKey(dst, DDCKEY_DESTBLT, NULL);
13134 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
13136 /* This fails, as sanity would dictate. */
13137 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_KEYDEST, &fx);
13138 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
13140 done:
13141 IDirectDrawSurface7_Release(src);
13142 IDirectDrawSurface7_Release(dst);
13143 refcount = IDirectDraw7_Release(ddraw);
13144 ok(!refcount, "DirectDraw has %u references left.\n", refcount);
13145 DestroyWindow(window);
13148 static void test_vb_refcount(void)
13150 ULONG prev_d3d_refcount, prev_device_refcount;
13151 ULONG cur_d3d_refcount, cur_device_refcount;
13152 IDirect3DVertexBuffer7 *vb, *vb7;
13153 D3DVERTEXBUFFERDESC vb_desc;
13154 IDirect3DVertexBuffer *vb1;
13155 IDirect3DDevice7 *device;
13156 IDirect3D7 *d3d;
13157 ULONG refcount;
13158 IUnknown *unk;
13159 HWND window;
13160 HRESULT hr;
13162 window = create_window();
13163 if (!(device = create_device(window, DDSCL_NORMAL)))
13165 skip("Failed to create a 3D device, skipping test.\n");
13166 DestroyWindow(window);
13167 return;
13170 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
13171 ok(SUCCEEDED(hr), "Failed to get Direct3D7 interface, hr %#x.\n", hr);
13173 prev_d3d_refcount = get_refcount((IUnknown *)d3d);
13174 prev_device_refcount = get_refcount((IUnknown *)device);
13176 memset(&vb_desc, 0, sizeof(vb_desc));
13177 vb_desc.dwSize = sizeof(vb_desc);
13178 vb_desc.dwFVF = D3DFVF_XYZ;
13179 vb_desc.dwNumVertices = 4;
13180 hr = IDirect3D7_CreateVertexBuffer(d3d, &vb_desc, &vb, 0);
13181 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
13183 cur_d3d_refcount = get_refcount((IUnknown *)d3d);
13184 cur_device_refcount = get_refcount((IUnknown *)device);
13185 ok(cur_d3d_refcount > prev_d3d_refcount, "D3D object refcount didn't change from %u.\n", prev_d3d_refcount);
13186 ok(cur_device_refcount == prev_device_refcount, "Device refcount changed from %u to %u.\n",
13187 prev_device_refcount, cur_device_refcount);
13189 prev_d3d_refcount = cur_d3d_refcount;
13190 hr = IDirect3DVertexBuffer7_QueryInterface(vb, &IID_IDirect3DVertexBuffer7, (void **)&vb7);
13191 ok(hr == DD_OK, "Failed to query IDirect3DVertexBuffer7, hr %#x.\n", hr);
13192 cur_d3d_refcount = get_refcount((IUnknown *)d3d);
13193 ok(cur_d3d_refcount == prev_d3d_refcount, "D3D object refcount changed from %u to %u.\n",
13194 prev_d3d_refcount, cur_d3d_refcount);
13195 IDirect3DVertexBuffer7_Release(vb7);
13197 hr = IDirect3DVertexBuffer7_QueryInterface(vb, &IID_IDirect3DVertexBuffer, (void **)&vb1);
13198 ok(hr == E_NOINTERFACE, "Querying IDirect3DVertexBuffer returned unexpected hr %#x.\n", hr);
13200 hr = IDirect3DVertexBuffer_QueryInterface(vb, &IID_IUnknown, (void **)&unk);
13201 ok(hr == DD_OK, "Failed to query IUnknown, hr %#x.\n", hr);
13202 ok((IUnknown *)vb == unk,
13203 "IDirect3DVertexBuffer7 and IUnknown interface pointers don't match, %p != %p.\n", vb, unk);
13204 IUnknown_Release(unk);
13206 refcount = IDirect3DVertexBuffer7_Release(vb);
13207 ok(!refcount, "Vertex buffer has %u references left.\n", refcount);
13209 IDirect3D7_Release(d3d);
13210 refcount = IDirect3DDevice7_Release(device);
13211 ok(!refcount, "Device has %u references left.\n", refcount);
13212 DestroyWindow(window);
13215 static void test_compute_sphere_visibility(void)
13217 static D3DVALUE clip_plane[4] = {1.0f, 0.0f, 0.0f, 0.5f};
13218 static D3DMATRIX proj_1 =
13220 1.810660f, 0.000000f, 0.000000f, 0.000000f,
13221 0.000000f, 2.414213f, 0.000000f, 0.000000f,
13222 0.000000f, 0.000000f, 1.020408f, 1.000000f,
13223 0.000000f, 0.000000f, -0.102041f, 0.000000f,
13225 static D3DMATRIX proj_2 =
13227 10.0f, 0.0f, 0.0f, 0.0f,
13228 0.0f, 10.0f, 0.0f, 0.0f,
13229 0.0f, 0.0f, 10.0f, 0.0f,
13230 0.0f, 0.0f, 0.0f, 1.0f,
13232 static D3DMATRIX view_1 =
13234 1.000000f, 0.000000f, 0.000000f, 0.000000f,
13235 0.000000f, 0.768221f, -0.640185f, 0.000000f,
13236 -0.000000f, 0.640185f, 0.768221f, 0.000000f,
13237 -14.852037f, 9.857489f, 11.600972f, 1.000000f,
13239 static D3DMATRIX identity =
13241 1.0f, 0.0f, 0.0f, 0.0f,
13242 0.0f, 1.0f, 0.0f, 0.0f,
13243 0.0f, 0.0f, 1.0f, 0.0f,
13244 0.0f, 0.0f, 0.0f, 1.0f,
13246 static struct
13248 D3DMATRIX *view, *proj;
13249 unsigned int sphere_count;
13250 D3DVECTOR center[3];
13251 D3DVALUE radius[3];
13252 DWORD enable_planes;
13253 const DWORD expected[3];
13255 tests[] =
13257 {&view_1, &proj_1, 1, {{{11.461533f}, {-4.761727f}, {-1.171646f}}}, {38.252632f}, 0, {0x3f}},
13258 {&view_1, &proj_1, 3, {{{-3.515620f}, {-1.560661f}, {-12.464638f}},
13259 {{14.290396f}, {-2.981143f}, {-24.311312f}},
13260 {{1.461626f}, {-6.093709f}, {-13.901010f}}},
13261 {4.354097f, 12.500704f, 17.251318f}, 0, {0x103d, 0x3f, 0x3f}},
13262 {&identity, &proj_2, 1, {{{0.0f}, {0.0f}, {0.05f}}}, {0.04f}, 0, {0}},
13263 {&identity, &identity, 1, {{{0.0f}, {0.0f}, {0.5f}}}, {0.5f}, 0, {0}},
13264 {&identity, &identity, 1, {{{0.0f}, {0.0f}, {0.0f}}}, {0.0f}, 0, {0}},
13265 {&identity, &identity, 1, {{{-1.0f}, {-1.0f}, {0.5f}}}, {0.25f}, 0, {0x9}}, /* 5 */
13266 {&identity, &identity, 1, {{{-20.0f}, {0.0f}, {0.5f}}}, {3.0f}, 0, {0x103d}},
13267 {&identity, &identity, 1, {{{20.0f}, {0.0f}, {0.5f}}}, {3.0f}, 0, {0x203e}},
13268 {&identity, &identity, 1, {{{0.0f}, {-20.0f}, {0.5f}}}, {3.0f}, 0, {0x803b}},
13269 {&identity, &identity, 1, {{{0.0f}, {20.0f}, {0.5f}}}, {3.0f}, 0, {0x4037}},
13270 {&identity, &identity, 1, {{{0.0f}, {0.0f}, {-20.0f}}}, {3.0f}, 0, {0x1001f}}, /* 10 */
13271 {&identity, &identity, 1, {{{0.0f}, {0.0f}, {20.0f}}}, {3.0f}, 0, {0x2002f}},
13272 {&identity, &identity, 1, {{{0.0f}, {0.0f}, {0.0f}}}, {5.0f}, 1, {0x7f}},
13273 {&identity, &identity, 1, {{{-0.5f}, {0.0f}, {0.0f}}}, {5.0f}, 1, {0x7f}},
13274 {&identity, &identity, 1, {{{-0.5f}, {0.0f}, {0.0f}}}, {1.0f}, 1, {0x51}},
13275 {&identity, &identity, 1, {{{-2.5f}, {0.0f}, {0.0f}}}, {1.0f}, 1, {0x41051}}, /* 15 */
13277 IDirect3DDevice7 *device;
13278 unsigned int i, j;
13279 DWORD result[3];
13280 ULONG refcount;
13281 HWND window;
13282 HRESULT hr;
13284 window = create_window();
13285 if (!(device = create_device(window, DDSCL_NORMAL)))
13287 skip("Failed to create a 3D device, skipping test.\n");
13288 DestroyWindow(window);
13289 return;
13292 hr = IDirect3DDevice7_SetClipPlane(device, 0, clip_plane);
13293 ok(SUCCEEDED(hr), "Failed to set user clip plane, hr %#x.\n", hr);
13295 IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &identity);
13297 for (i = 0; i < ARRAY_SIZE(tests); ++i)
13299 IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_VIEW, tests[i].view);
13300 IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, tests[i].proj);
13302 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CLIPPLANEENABLE,
13303 tests[i].enable_planes);
13304 ok(SUCCEEDED(hr), "Failed to enable / disable user clip planes, hr %#x.\n", hr);
13306 hr = IDirect3DDevice7_ComputeSphereVisibility(device, tests[i].center, tests[i].radius,
13307 tests[i].sphere_count, 0, result);
13308 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
13310 for (j = 0; j < tests[i].sphere_count; ++j)
13311 ok(result[j] == tests[i].expected[j], "Test %u sphere %u: expected %#x, got %#x.\n",
13312 i, j, tests[i].expected[j], result[j]);
13315 refcount = IDirect3DDevice7_Release(device);
13316 ok(!refcount, "Device has %u references left.\n", refcount);
13317 DestroyWindow(window);
13320 static void test_clip_planes_limits(void)
13322 IDirect3DDevice7 *device;
13323 D3DDEVICEDESC7 caps;
13324 unsigned int i;
13325 ULONG refcount;
13326 float plane[4];
13327 HWND window;
13328 DWORD state;
13329 HRESULT hr;
13331 window = create_window();
13332 if (!(device = create_device(window, DDSCL_NORMAL)))
13334 skip("Failed to create 3D device.\n");
13335 DestroyWindow(window);
13336 return;
13339 memset(&caps, 0, sizeof(caps));
13340 hr = IDirect3DDevice7_GetCaps(device, &caps);
13341 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
13343 trace("Max user clip planes: %u.\n", caps.wMaxUserClipPlanes);
13345 for (i = 0; i < D3DMAXUSERCLIPPLANES; ++i)
13347 memset(plane, 0xff, sizeof(plane));
13348 hr = IDirect3DDevice7_GetClipPlane(device, i, plane);
13349 ok(hr == D3D_OK, "Failed to get clip plane %u, hr %#x.\n", i, hr);
13350 ok(!plane[0] && !plane[1] && !plane[2] && !plane[3],
13351 "Got unexpected plane %u: %.8e, %.8e, %.8e, %.8e.\n",
13352 i, plane[0], plane[1], plane[2], plane[3]);
13355 plane[0] = 2.0f;
13356 plane[1] = 8.0f;
13357 plane[2] = 5.0f;
13358 for (i = 0; i < D3DMAXUSERCLIPPLANES; ++i)
13360 plane[3] = i;
13361 hr = IDirect3DDevice7_SetClipPlane(device, i, plane);
13362 ok(hr == D3D_OK, "Failed to set clip plane %u, hr %#x.\n", i, hr);
13364 for (i = 0; i < D3DMAXUSERCLIPPLANES; ++i)
13366 memset(plane, 0xff, sizeof(plane));
13367 hr = IDirect3DDevice7_GetClipPlane(device, i, plane);
13368 ok(hr == D3D_OK, "Failed to get clip plane %u, hr %#x.\n", i, hr);
13369 ok(plane[0] == 2.0f && plane[1] == 8.0f && plane[2] == 5.0f && plane[3] == i,
13370 "Got unexpected plane %u: %.8e, %.8e, %.8e, %.8e.\n",
13371 i, plane[0], plane[1], plane[2], plane[3]);
13374 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CLIPPLANEENABLE, 0xffffffff);
13375 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
13376 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_CLIPPLANEENABLE, &state);
13377 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
13378 ok(state == 0xffffffff, "Got unexpected state %#x.\n", state);
13379 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CLIPPLANEENABLE, 0x80000000);
13380 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
13381 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_CLIPPLANEENABLE, &state);
13382 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
13383 ok(state == 0x80000000, "Got unexpected state %#x.\n", state);
13385 refcount = IDirect3DDevice7_Release(device);
13386 ok(!refcount, "Device has %u references left.\n", refcount);
13387 DestroyWindow(window);
13390 START_TEST(ddraw7)
13392 DDDEVICEIDENTIFIER2 identifier;
13393 HMODULE module, dwmapi;
13394 DEVMODEW current_mode;
13395 IDirectDraw7 *ddraw;
13397 module = GetModuleHandleA("ddraw.dll");
13398 if (!(pDirectDrawCreateEx = (void *)GetProcAddress(module, "DirectDrawCreateEx")))
13400 win_skip("DirectDrawCreateEx not available, skipping tests.\n");
13401 return;
13404 if (!(ddraw = create_ddraw()))
13406 skip("Failed to create a ddraw object, skipping tests.\n");
13407 return;
13410 if (ddraw_get_identifier(ddraw, &identifier))
13412 trace("Driver string: \"%s\"\n", identifier.szDriver);
13413 trace("Description string: \"%s\"\n", identifier.szDescription);
13414 trace("Driver version %d.%d.%d.%d\n",
13415 HIWORD(U(identifier.liDriverVersion).HighPart), LOWORD(U(identifier.liDriverVersion).HighPart),
13416 HIWORD(U(identifier.liDriverVersion).LowPart), LOWORD(U(identifier.liDriverVersion).LowPart));
13418 IDirectDraw7_Release(ddraw);
13420 memset(&current_mode, 0, sizeof(current_mode));
13421 current_mode.dmSize = sizeof(current_mode);
13422 ok(EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &current_mode), "Failed to get display mode.\n");
13423 registry_mode.dmSize = sizeof(registry_mode);
13424 ok(EnumDisplaySettingsW(NULL, ENUM_REGISTRY_SETTINGS, &registry_mode), "Failed to get display mode.\n");
13425 if (registry_mode.dmPelsWidth != current_mode.dmPelsWidth
13426 || registry_mode.dmPelsHeight != current_mode.dmPelsHeight)
13428 skip("Current mode does not match registry mode, skipping test.\n");
13429 return;
13432 if ((dwmapi = LoadLibraryA("dwmapi.dll")))
13433 pDwmIsCompositionEnabled = (void *)GetProcAddress(dwmapi, "DwmIsCompositionEnabled");
13435 test_process_vertices();
13436 test_coop_level_create_device_window();
13437 test_clipper_blt();
13438 test_coop_level_d3d_state();
13439 test_surface_interface_mismatch();
13440 test_coop_level_threaded();
13441 test_depth_blit();
13442 test_texture_load_ckey();
13443 test_zenable();
13444 test_ck_rgba();
13445 test_ck_default();
13446 test_ck_complex();
13447 test_surface_qi();
13448 test_device_qi();
13449 test_wndproc();
13450 test_window_style();
13451 test_redundant_mode_set();
13452 test_coop_level_mode_set();
13453 test_coop_level_mode_set_multi();
13454 test_initialize();
13455 test_coop_level_surf_create();
13456 test_vb_discard();
13457 test_coop_level_multi_window();
13458 test_draw_strided();
13459 test_lighting();
13460 test_specular_lighting();
13461 test_clear_rect_count();
13462 test_coop_level_versions();
13463 test_fog_special();
13464 test_lighting_interface_versions();
13465 test_coop_level_activateapp();
13466 test_texturemanage();
13467 test_block_formats_creation();
13468 test_unsupported_formats();
13469 test_rt_caps();
13470 test_primary_caps();
13471 test_surface_lock();
13472 test_surface_discard();
13473 test_flip();
13474 test_set_surface_desc();
13475 test_user_memory_getdc();
13476 test_sysmem_overlay();
13477 test_primary_palette();
13478 test_surface_attachment();
13479 test_private_data();
13480 test_pixel_format();
13481 test_create_surface_pitch();
13482 test_mipmap();
13483 test_palette_complex();
13484 test_p8_blit();
13485 test_material();
13486 test_palette_gdi();
13487 test_palette_alpha();
13488 test_vb_writeonly();
13489 test_lost_device();
13490 test_resource_priority();
13491 test_surface_desc_lock();
13492 test_fog_interpolation();
13493 test_negative_fixedfunction_fog();
13494 test_table_fog_zw();
13495 test_signed_formats();
13496 test_color_fill();
13497 test_texcoordindex();
13498 test_colorkey_precision();
13499 test_range_colorkey();
13500 test_shademode();
13501 test_lockrect_invalid();
13502 test_yv12_overlay();
13503 test_offscreen_overlay();
13504 test_overlay_rect();
13505 test_blt();
13506 test_blt_z_alpha();
13507 test_color_clamping();
13508 test_getdc();
13509 test_draw_primitive();
13510 test_edge_antialiasing_blending();
13511 test_display_mode_surface_pixel_format();
13512 test_surface_desc_size();
13513 test_get_surface_from_dc();
13514 test_ck_operation();
13515 test_vb_refcount();
13516 test_compute_sphere_visibility();
13517 test_clip_planes_limits();