wined3d: Consider CPU blitter when clearing discarded textures.
[wine.git] / dlls / ddraw / tests / ddraw7.c
blob91822281d06589b8ebd8b1f293d128c71af4a5e1
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 struct vec2
37 float x, y;
40 struct vec3
42 float x, y, z;
45 struct vec4
47 float x, y, z, w;
50 struct create_window_thread_param
52 HWND window;
53 HANDLE window_created;
54 HANDLE destroy_window;
55 HANDLE thread;
58 static BOOL compare_float(float f, float g, unsigned int ulps)
60 int x = *(int *)&f;
61 int y = *(int *)&g;
63 if (x < 0)
64 x = INT_MIN - x;
65 if (y < 0)
66 y = INT_MIN - y;
68 if (abs(x - y) > ulps)
69 return FALSE;
71 return TRUE;
74 static BOOL compare_vec3(struct vec3 *vec, float x, float y, float z, unsigned int ulps)
76 return compare_float(vec->x, x, ulps)
77 && compare_float(vec->y, y, ulps)
78 && compare_float(vec->z, z, ulps);
81 static BOOL compare_vec4(const struct vec4 *vec, float x, float y, float z, float w, unsigned int ulps)
83 return compare_float(vec->x, x, ulps)
84 && compare_float(vec->y, y, ulps)
85 && compare_float(vec->z, z, ulps)
86 && compare_float(vec->w, w, ulps);
89 static BOOL compare_color(D3DCOLOR c1, D3DCOLOR c2, BYTE max_diff)
91 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
92 c1 >>= 8; c2 >>= 8;
93 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
94 c1 >>= 8; c2 >>= 8;
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 return TRUE;
101 static ULONG get_refcount(IUnknown *iface)
103 IUnknown_AddRef(iface);
104 return IUnknown_Release(iface);
107 static BOOL ddraw_is_warp(IDirectDraw7 *ddraw)
109 DDDEVICEIDENTIFIER2 identifier;
110 HRESULT hr;
112 if (!strcmp(winetest_platform, "wine"))
113 return FALSE;
115 hr = IDirectDraw7_GetDeviceIdentifier(ddraw, &identifier, 0);
116 ok(SUCCEEDED(hr), "Failed to get device identifier, hr %#x.\n", hr);
118 return !!strstr(identifier.szDriver, "warp");
121 static BOOL ddraw_is_nvidia(IDirectDraw7 *ddraw)
123 DDDEVICEIDENTIFIER2 identifier;
124 HRESULT hr;
126 if (!strcmp(winetest_platform, "wine"))
127 return FALSE;
129 hr = IDirectDraw7_GetDeviceIdentifier(ddraw, &identifier, 0);
130 ok(SUCCEEDED(hr), "Failed to get device identifier, hr %#x.\n", hr);
132 return identifier.dwVendorId == 0x10de;
135 static BOOL ddraw_is_intel(IDirectDraw7 *ddraw)
137 DDDEVICEIDENTIFIER2 identifier;
138 HRESULT hr;
140 if (!strcmp(winetest_platform, "wine"))
141 return FALSE;
143 hr = IDirectDraw7_GetDeviceIdentifier(ddraw, &identifier, 0);
144 ok(SUCCEEDED(hr), "Failed to get device identifier, hr %#x.\n", hr);
146 return identifier.dwVendorId == 0x8086;
149 static IDirectDrawSurface7 *create_overlay(IDirectDraw7 *ddraw,
150 unsigned int width, unsigned int height, DWORD format)
152 IDirectDrawSurface7 *surface;
153 DDSURFACEDESC2 desc;
155 memset(&desc, 0, sizeof(desc));
156 desc.dwSize = sizeof(desc);
157 desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
158 desc.dwWidth = width;
159 desc.dwHeight = height;
160 desc.ddsCaps.dwCaps = DDSCAPS_OVERLAY;
161 U4(desc).ddpfPixelFormat.dwSize = sizeof(U4(desc).ddpfPixelFormat);
162 U4(desc).ddpfPixelFormat.dwFlags = DDPF_FOURCC;
163 U4(desc).ddpfPixelFormat.dwFourCC = format;
165 if (FAILED(IDirectDraw7_CreateSurface(ddraw, &desc, &surface, NULL)))
166 return NULL;
167 return surface;
170 static HWND create_window(void)
172 RECT r = {0, 0, 640, 480};
174 AdjustWindowRect(&r, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
176 return CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
177 CW_USEDEFAULT, CW_USEDEFAULT, r.right - r.left, r.bottom - r.top, NULL, NULL, NULL, NULL);
180 static DWORD WINAPI create_window_thread_proc(void *param)
182 struct create_window_thread_param *p = param;
183 DWORD res;
184 BOOL ret;
186 p->window = create_window();
187 ret = SetEvent(p->window_created);
188 ok(ret, "SetEvent failed, last error %#x.\n", GetLastError());
190 for (;;)
192 MSG msg;
194 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
195 DispatchMessageA(&msg);
196 res = WaitForSingleObject(p->destroy_window, 100);
197 if (res == WAIT_OBJECT_0)
198 break;
199 if (res != WAIT_TIMEOUT)
201 ok(0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
202 break;
206 DestroyWindow(p->window);
208 return 0;
211 static void create_window_thread(struct create_window_thread_param *p)
213 DWORD res, tid;
215 p->window_created = CreateEventA(NULL, FALSE, FALSE, NULL);
216 ok(!!p->window_created, "CreateEvent failed, last error %#x.\n", GetLastError());
217 p->destroy_window = CreateEventA(NULL, FALSE, FALSE, NULL);
218 ok(!!p->destroy_window, "CreateEvent failed, last error %#x.\n", GetLastError());
219 p->thread = CreateThread(NULL, 0, create_window_thread_proc, p, 0, &tid);
220 ok(!!p->thread, "Failed to create thread, last error %#x.\n", GetLastError());
221 res = WaitForSingleObject(p->window_created, INFINITE);
222 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
225 static void destroy_window_thread(struct create_window_thread_param *p)
227 SetEvent(p->destroy_window);
228 WaitForSingleObject(p->thread, INFINITE);
229 CloseHandle(p->destroy_window);
230 CloseHandle(p->window_created);
231 CloseHandle(p->thread);
234 static IDirectDrawSurface7 *get_depth_stencil(IDirect3DDevice7 *device)
236 IDirectDrawSurface7 *rt, *ret;
237 DDSCAPS2 caps = {DDSCAPS_ZBUFFER, 0, 0, {0}};
238 HRESULT hr;
240 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
241 ok(SUCCEEDED(hr), "Failed to get the render target, hr %#x.\n", hr);
242 hr = IDirectDrawSurface7_GetAttachedSurface(rt, &caps, &ret);
243 ok(SUCCEEDED(hr) || hr == DDERR_NOTFOUND, "Failed to get the z buffer, hr %#x.\n", hr);
244 IDirectDrawSurface7_Release(rt);
245 return ret;
248 static HRESULT set_display_mode(IDirectDraw7 *ddraw, DWORD width, DWORD height)
250 if (SUCCEEDED(IDirectDraw7_SetDisplayMode(ddraw, width, height, 32, 0, 0)))
251 return DD_OK;
252 return IDirectDraw7_SetDisplayMode(ddraw, width, height, 24, 0, 0);
255 static D3DCOLOR get_surface_color(IDirectDrawSurface7 *surface, UINT x, UINT y)
257 RECT rect = {x, y, x + 1, y + 1};
258 DDSURFACEDESC2 surface_desc;
259 D3DCOLOR color;
260 HRESULT hr;
262 memset(&surface_desc, 0, sizeof(surface_desc));
263 surface_desc.dwSize = sizeof(surface_desc);
265 hr = IDirectDrawSurface7_Lock(surface, &rect, &surface_desc, DDLOCK_READONLY, NULL);
266 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
267 if (FAILED(hr))
268 return 0xdeadbeef;
270 color = *((DWORD *)surface_desc.lpSurface) & 0x00ffffff;
272 hr = IDirectDrawSurface7_Unlock(surface, &rect);
273 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
275 return color;
278 static HRESULT CALLBACK enum_z_fmt(DDPIXELFORMAT *format, void *ctx)
280 DDPIXELFORMAT *z_fmt = ctx;
282 if (U1(*format).dwZBufferBitDepth > U1(*z_fmt).dwZBufferBitDepth)
283 *z_fmt = *format;
285 return DDENUMRET_OK;
288 static IDirectDraw7 *create_ddraw(void)
290 IDirectDraw7 *ddraw;
292 if (FAILED(pDirectDrawCreateEx(NULL, (void **)&ddraw, &IID_IDirectDraw7, NULL)))
293 return NULL;
295 return ddraw;
298 static HRESULT WINAPI enum_devtype_cb(char *desc_str, char *name, D3DDEVICEDESC7 *desc, void *ctx)
300 BOOL *hal_ok = ctx;
301 if (IsEqualGUID(&desc->deviceGUID, &IID_IDirect3DTnLHalDevice))
303 *hal_ok = TRUE;
304 return DDENUMRET_CANCEL;
306 return DDENUMRET_OK;
309 static IDirect3DDevice7 *create_device(HWND window, DWORD coop_level)
311 IDirectDrawSurface7 *surface, *ds;
312 IDirect3DDevice7 *device = NULL;
313 DDSURFACEDESC2 surface_desc;
314 DDPIXELFORMAT z_fmt;
315 IDirectDraw7 *ddraw;
316 IDirect3D7 *d3d7;
317 HRESULT hr;
318 BOOL hal_ok = FALSE;
319 const GUID *devtype = &IID_IDirect3DHALDevice;
321 if (!(ddraw = create_ddraw()))
322 return NULL;
324 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, coop_level);
325 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
327 memset(&surface_desc, 0, sizeof(surface_desc));
328 surface_desc.dwSize = sizeof(surface_desc);
329 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
330 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
331 surface_desc.dwWidth = 640;
332 surface_desc.dwHeight = 480;
334 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
335 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
337 if (coop_level & DDSCL_NORMAL)
339 IDirectDrawClipper *clipper;
341 hr = IDirectDraw7_CreateClipper(ddraw, 0, &clipper, NULL);
342 ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr);
343 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
344 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
345 hr = IDirectDrawSurface7_SetClipper(surface, clipper);
346 ok(SUCCEEDED(hr), "Failed to set surface clipper, hr %#x.\n", hr);
347 IDirectDrawClipper_Release(clipper);
350 hr = IDirectDraw7_QueryInterface(ddraw, &IID_IDirect3D7, (void **)&d3d7);
351 IDirectDraw7_Release(ddraw);
352 if (FAILED(hr))
354 IDirectDrawSurface7_Release(surface);
355 return NULL;
358 hr = IDirect3D7_EnumDevices(d3d7, enum_devtype_cb, &hal_ok);
359 ok(SUCCEEDED(hr), "Failed to enumerate devices, hr %#x.\n", hr);
360 if (hal_ok) devtype = &IID_IDirect3DTnLHalDevice;
362 memset(&z_fmt, 0, sizeof(z_fmt));
363 hr = IDirect3D7_EnumZBufferFormats(d3d7, devtype, enum_z_fmt, &z_fmt);
364 if (FAILED(hr) || !z_fmt.dwSize)
366 IDirect3D7_Release(d3d7);
367 IDirectDrawSurface7_Release(surface);
368 return NULL;
371 memset(&surface_desc, 0, sizeof(surface_desc));
372 surface_desc.dwSize = sizeof(surface_desc);
373 surface_desc.dwFlags = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT;
374 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
375 U4(surface_desc).ddpfPixelFormat = z_fmt;
376 surface_desc.dwWidth = 640;
377 surface_desc.dwHeight = 480;
378 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &ds, NULL);
379 ok(SUCCEEDED(hr), "Failed to create depth buffer, hr %#x.\n", hr);
380 if (FAILED(hr))
382 IDirect3D7_Release(d3d7);
383 IDirectDrawSurface7_Release(surface);
384 return NULL;
387 hr = IDirectDrawSurface_AddAttachedSurface(surface, ds);
388 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
389 IDirectDrawSurface7_Release(ds);
390 if (FAILED(hr))
392 IDirect3D7_Release(d3d7);
393 IDirectDrawSurface7_Release(surface);
394 return NULL;
397 hr = IDirect3D7_CreateDevice(d3d7, devtype, surface, &device);
398 IDirect3D7_Release(d3d7);
399 IDirectDrawSurface7_Release(surface);
400 if (FAILED(hr))
401 return NULL;
403 return device;
406 struct message
408 UINT message;
409 BOOL check_wparam;
410 WPARAM expect_wparam;
413 static const struct message *expect_messages;
415 static LRESULT CALLBACK test_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
417 if (expect_messages && message == expect_messages->message)
419 if (expect_messages->check_wparam)
420 ok (wparam == expect_messages->expect_wparam,
421 "Got unexpected wparam %lx for message %x, expected %lx.\n",
422 wparam, message, expect_messages->expect_wparam);
424 ++expect_messages;
427 return DefWindowProcA(hwnd, message, wparam, lparam);
430 /* Set the wndproc back to what ddraw expects it to be, and release the ddraw
431 * interface. This prevents subsequent SetCooperativeLevel() calls on a
432 * different window from failing with DDERR_HWNDALREADYSET. */
433 static void fix_wndproc(HWND window, LONG_PTR proc)
435 IDirectDraw7 *ddraw;
436 HRESULT hr;
438 if (!(ddraw = create_ddraw()))
439 return;
441 SetWindowLongPtrA(window, GWLP_WNDPROC, proc);
442 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
443 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
444 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
445 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
447 IDirectDraw7_Release(ddraw);
450 static void test_process_vertices(void)
452 IDirect3DVertexBuffer7 *src_vb, *dst_vb1, *dst_vb2;
453 D3DVERTEXBUFFERDESC vb_desc;
454 IDirect3DDevice7 *device;
455 struct vec4 *dst_data;
456 struct vec3 *dst_data2;
457 struct vec3 *src_data;
458 IDirect3D7 *d3d7;
459 D3DVIEWPORT7 vp;
460 HWND window;
461 HRESULT hr;
463 static D3DMATRIX world =
465 0.0f, 1.0f, 0.0f, 0.0f,
466 1.0f, 0.0f, 0.0f, 0.0f,
467 0.0f, 0.0f, 0.0f, 1.0f,
468 0.0f, 1.0f, 1.0f, 1.0f,
470 static D3DMATRIX view =
472 2.0f, 0.0f, 0.0f, 0.0f,
473 0.0f, -1.0f, 0.0f, 0.0f,
474 0.0f, 0.0f, 1.0f, 0.0f,
475 0.0f, 0.0f, 0.0f, 3.0f,
477 static D3DMATRIX proj =
479 1.0f, 0.0f, 0.0f, 1.0f,
480 0.0f, 1.0f, 1.0f, 0.0f,
481 0.0f, 1.0f, 1.0f, 0.0f,
482 1.0f, 0.0f, 0.0f, 1.0f,
485 window = create_window();
486 if (!(device = create_device(window, DDSCL_NORMAL)))
488 skip("Failed to create a 3D device, skipping test.\n");
489 DestroyWindow(window);
490 return;
493 hr = IDirect3DDevice7_GetDirect3D(device, &d3d7);
494 ok(SUCCEEDED(hr), "Failed to get Direct3D7 interface, hr %#x.\n", hr);
496 memset(&vb_desc, 0, sizeof(vb_desc));
497 vb_desc.dwSize = sizeof(vb_desc);
498 vb_desc.dwFVF = D3DFVF_XYZ;
499 vb_desc.dwNumVertices = 4;
500 hr = IDirect3D7_CreateVertexBuffer(d3d7, &vb_desc, &src_vb, 0);
501 ok(SUCCEEDED(hr), "Failed to create source vertex buffer, hr %#x.\n", hr);
503 hr = IDirect3DVertexBuffer7_Lock(src_vb, 0, (void **)&src_data, NULL);
504 ok(SUCCEEDED(hr), "Failed to lock source vertex buffer, hr %#x.\n", hr);
505 src_data[0].x = 0.0f;
506 src_data[0].y = 0.0f;
507 src_data[0].z = 0.0f;
508 src_data[1].x = 1.0f;
509 src_data[1].y = 1.0f;
510 src_data[1].z = 1.0f;
511 src_data[2].x = -1.0f;
512 src_data[2].y = -1.0f;
513 src_data[2].z = 0.5f;
514 src_data[3].x = 0.5f;
515 src_data[3].y = -0.5f;
516 src_data[3].z = 0.25f;
517 hr = IDirect3DVertexBuffer7_Unlock(src_vb);
518 ok(SUCCEEDED(hr), "Failed to unlock source vertex buffer, hr %#x.\n", hr);
520 memset(&vb_desc, 0, sizeof(vb_desc));
521 vb_desc.dwSize = sizeof(vb_desc);
522 vb_desc.dwFVF = D3DFVF_XYZRHW;
523 vb_desc.dwNumVertices = 4;
524 /* MSDN says that the last parameter must be 0 - check that. */
525 hr = IDirect3D7_CreateVertexBuffer(d3d7, &vb_desc, &dst_vb1, 4);
526 ok(SUCCEEDED(hr), "Failed to create 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_XYZ;
531 vb_desc.dwNumVertices = 5;
532 /* MSDN says that the last parameter must be 0 - check that. */
533 hr = IDirect3D7_CreateVertexBuffer(d3d7, &vb_desc, &dst_vb2, 12345678);
534 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
536 memset(&vp, 0, sizeof(vp));
537 vp.dwX = 64;
538 vp.dwY = 64;
539 vp.dwWidth = 128;
540 vp.dwHeight = 128;
541 vp.dvMinZ = 0.0f;
542 vp.dvMaxZ = 1.0f;
543 hr = IDirect3DDevice7_SetViewport(device, &vp);
544 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#x.\n", hr);
546 hr = IDirect3DVertexBuffer7_ProcessVertices(dst_vb1, D3DVOP_TRANSFORM, 0, 4, src_vb, 0, device, 0);
547 ok(SUCCEEDED(hr), "Failed to process vertices, hr %#x.\n", hr);
548 hr = IDirect3DVertexBuffer7_ProcessVertices(dst_vb2, D3DVOP_TRANSFORM, 0, 4, src_vb, 0, device, 0);
549 ok(SUCCEEDED(hr), "Failed to process vertices, hr %#x.\n", hr);
551 hr = IDirect3DVertexBuffer7_Lock(dst_vb1, 0, (void **)&dst_data, NULL);
552 ok(SUCCEEDED(hr), "Failed to lock destination vertex buffer, hr %#x.\n", hr);
553 ok(compare_vec4(&dst_data[0], +1.280e+2f, +1.280e+2f, +0.000e+0f, +1.000e+0f, 4096),
554 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
555 dst_data[0].x, dst_data[0].y, dst_data[0].z, dst_data[0].w);
556 ok(compare_vec4(&dst_data[1], +1.920e+2f, +6.400e+1f, +1.000e+0f, +1.000e+0f, 4096),
557 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
558 dst_data[1].x, dst_data[1].y, dst_data[1].z, dst_data[1].w);
559 ok(compare_vec4(&dst_data[2], +6.400e+1f, +1.920e+2f, +5.000e-1f, +1.000e+0f, 4096),
560 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
561 dst_data[2].x, dst_data[2].y, dst_data[2].z, dst_data[2].w);
562 ok(compare_vec4(&dst_data[3], +1.600e+2f, +1.600e+2f, +2.500e-1f, +1.000e+0f, 4096),
563 "Got unexpected vertex 3 {%.8e, %.8e, %.8e, %.8e}.\n",
564 dst_data[3].x, dst_data[3].y, dst_data[3].z, dst_data[3].w);
565 hr = IDirect3DVertexBuffer7_Unlock(dst_vb1);
566 ok(SUCCEEDED(hr), "Failed to unlock destination vertex buffer, hr %#x.\n", hr);
568 hr = IDirect3DVertexBuffer7_Lock(dst_vb2, 0, (void **)&dst_data2, NULL);
569 ok(SUCCEEDED(hr), "Failed to lock destination vertex buffer, hr %#x.\n", hr);
570 /* Small thing without much practical meaning, but I stumbled upon it,
571 * so let's check for it: If the output vertex buffer has no RHW value,
572 * the RHW value of the last vertex is written into the next vertex. */
573 ok(compare_vec3(&dst_data2[4], +1.000e+0f, +0.000e+0f, +0.000e+0f, 4096),
574 "Got unexpected vertex 4 {%.8e, %.8e, %.8e}.\n",
575 dst_data2[4].x, dst_data2[4].y, dst_data2[4].z);
576 hr = IDirect3DVertexBuffer7_Unlock(dst_vb2);
577 ok(SUCCEEDED(hr), "Failed to unlock destination vertex buffer, hr %#x.\n", hr);
579 /* Try a more complicated viewport, same vertices. */
580 memset(&vp, 0, sizeof(vp));
581 vp.dwX = 10;
582 vp.dwY = 5;
583 vp.dwWidth = 246;
584 vp.dwHeight = 130;
585 vp.dvMinZ = -2.0f;
586 vp.dvMaxZ = 4.0f;
587 hr = IDirect3DDevice7_SetViewport(device, &vp);
588 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#x.\n", hr);
590 hr = IDirect3DVertexBuffer7_ProcessVertices(dst_vb1, D3DVOP_TRANSFORM, 0, 4, src_vb, 0, device, 0);
591 ok(SUCCEEDED(hr), "Failed to process vertices, hr %#x.\n", hr);
593 hr = IDirect3DVertexBuffer7_Lock(dst_vb1, 0, (void **)&dst_data, NULL);
594 ok(SUCCEEDED(hr), "Failed to lock destination vertex buffer, hr %#x.\n", hr);
595 ok(compare_vec4(&dst_data[0], +1.330e+2f, +7.000e+1f, -2.000e+0f, +1.000e+0f, 4096),
596 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
597 dst_data[0].x, dst_data[0].y, dst_data[0].z, dst_data[0].w);
598 ok(compare_vec4(&dst_data[1], +2.560e+2f, +5.000e+0f, +4.000e+0f, +1.000e+0f, 4096),
599 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
600 dst_data[1].x, dst_data[1].y, dst_data[1].z, dst_data[1].w);
601 ok(compare_vec4(&dst_data[2], +1.000e+1f, +1.350e+2f, +1.000e+0f, +1.000e+0f, 4096),
602 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
603 dst_data[2].x, dst_data[2].y, dst_data[2].z, dst_data[2].w);
604 ok(compare_vec4(&dst_data[3], +1.945e+2f, +1.025e+2f, -5.000e-1f, +1.000e+0f, 4096),
605 "Got unexpected vertex 3 {%.8e, %.8e, %.8e, %.8e}.\n",
606 dst_data[3].x, dst_data[3].y, dst_data[3].z, dst_data[3].w);
607 hr = IDirect3DVertexBuffer7_Unlock(dst_vb1);
608 ok(SUCCEEDED(hr), "Failed to unlock destination vertex buffer, hr %#x.\n", hr);
610 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &world);
611 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#x.\n", hr);
612 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_VIEW, &view);
613 ok(SUCCEEDED(hr), "Failed to set view transform, hr %#x.\n", hr);
614 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &proj);
615 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
617 hr = IDirect3DVertexBuffer7_ProcessVertices(dst_vb1, D3DVOP_TRANSFORM, 0, 4, src_vb, 0, device, 0);
618 ok(SUCCEEDED(hr), "Failed to process vertices, hr %#x.\n", hr);
620 hr = IDirect3DVertexBuffer7_Lock(dst_vb1, 0, (void **)&dst_data, NULL);
621 ok(SUCCEEDED(hr), "Failed to lock destination vertex buffer, hr %#x.\n", hr);
622 ok(compare_vec4(&dst_data[0], +2.560e+2f, +7.000e+1f, -2.000e+0f, +3.333e-1f, 4096),
623 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
624 dst_data[0].x, dst_data[0].y, dst_data[0].z, dst_data[0].w);
625 ok(compare_vec4(&dst_data[1], +2.560e+2f, +7.813e+1f, -2.750e+0f, +1.250e-1f, 4096),
626 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
627 dst_data[1].x, dst_data[1].y, dst_data[1].z, dst_data[1].w);
628 ok(compare_vec4(&dst_data[2], +2.560e+2f, +4.400e+1f, +4.000e-1f, +4.000e-1f, 4096),
629 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
630 dst_data[2].x, dst_data[2].y, dst_data[2].z, dst_data[2].w);
631 ok(compare_vec4(&dst_data[3], +2.560e+2f, +8.182e+1f, -3.091e+0f, +3.636e-1f, 4096),
632 "Got unexpected vertex 3 {%.8e, %.8e, %.8e, %.8e}.\n",
633 dst_data[3].x, dst_data[3].y, dst_data[3].z, dst_data[3].w);
634 hr = IDirect3DVertexBuffer7_Unlock(dst_vb1);
635 ok(SUCCEEDED(hr), "Failed to unlock destination vertex buffer, hr %#x.\n", hr);
637 IDirect3DVertexBuffer7_Release(dst_vb2);
638 IDirect3DVertexBuffer7_Release(dst_vb1);
639 IDirect3DVertexBuffer7_Release(src_vb);
640 IDirect3D7_Release(d3d7);
641 IDirect3DDevice7_Release(device);
642 DestroyWindow(window);
645 static void test_coop_level_create_device_window(void)
647 HWND focus_window, device_window;
648 IDirectDraw7 *ddraw;
649 HRESULT hr;
651 focus_window = create_window();
652 ddraw = create_ddraw();
653 ok(!!ddraw, "Failed to create a ddraw object.\n");
655 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
656 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
657 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
658 ok(!device_window, "Unexpected device window found.\n");
659 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW);
660 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
661 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
662 ok(!device_window, "Unexpected device window found.\n");
663 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_NORMAL);
664 ok(hr == DDERR_INVALIDPARAMS, "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 | DDSCL_NORMAL | DDSCL_FULLSCREEN);
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_EXCLUSIVE | DDSCL_FULLSCREEN);
672 ok(hr == DDERR_NOFOCUSWINDOW || broken(hr == DDERR_INVALIDPARAMS), "Got unexpected hr %#x.\n", hr);
673 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
674 ok(!device_window, "Unexpected device window found.\n");
676 /* Windows versions before 98 / NT5 don't support DDSCL_CREATEDEVICEWINDOW. */
677 if (broken(hr == DDERR_INVALIDPARAMS))
679 win_skip("DDSCL_CREATEDEVICEWINDOW not supported, skipping test.\n");
680 IDirectDraw7_Release(ddraw);
681 DestroyWindow(focus_window);
682 return;
685 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
686 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
687 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
688 ok(!device_window, "Unexpected device window found.\n");
689 hr = IDirectDraw7_SetCooperativeLevel(ddraw, focus_window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
690 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
691 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
692 ok(!device_window, "Unexpected device window found.\n");
694 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
695 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
696 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
697 ok(!device_window, "Unexpected device window found.\n");
698 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_SETFOCUSWINDOW
699 | DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
700 ok(hr == DDERR_NOHWND, "Got unexpected hr %#x.\n", hr);
701 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
702 ok(!!device_window, "Device window not found.\n");
704 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
705 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
706 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
707 ok(!device_window, "Unexpected device window found.\n");
708 hr = IDirectDraw7_SetCooperativeLevel(ddraw, focus_window, DDSCL_SETFOCUSWINDOW
709 | DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
710 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
711 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
712 ok(!!device_window, "Device window not found.\n");
714 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
715 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
716 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
717 ok(!device_window, "Unexpected device window found.\n");
718 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
719 ok(hr == DDERR_NOFOCUSWINDOW, "Got unexpected hr %#x.\n", hr);
720 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
721 ok(!device_window, "Unexpected device window found.\n");
722 hr = IDirectDraw7_SetCooperativeLevel(ddraw, focus_window, DDSCL_SETFOCUSWINDOW);
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 == DD_OK, "Got unexpected hr %#x.\n", hr);
728 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
729 ok(!!device_window, "Device window not found.\n");
731 IDirectDraw7_Release(ddraw);
732 DestroyWindow(focus_window);
735 static void test_clipper_blt(void)
737 IDirectDrawSurface7 *src_surface, *dst_surface;
738 RECT client_rect, src_rect;
739 IDirectDrawClipper *clipper;
740 DDSURFACEDESC2 surface_desc;
741 unsigned int i, j, x, y;
742 IDirectDraw7 *ddraw;
743 RGNDATA *rgn_data;
744 D3DCOLOR color;
745 ULONG refcount;
746 HRGN r1, r2;
747 HWND window;
748 DDBLTFX fx;
749 HRESULT hr;
750 DWORD *ptr;
751 DWORD ret;
753 static const DWORD src_data[] =
755 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
756 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
757 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
759 static const D3DCOLOR expected1[] =
761 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
762 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
763 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
764 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
766 /* Nvidia on Windows seems to have an off-by-one error
767 * when processing source rectangles. Our left = 1 and
768 * right = 5 input reads from x = {1, 2, 3}. x = 4 is
769 * read as well, but only for the edge pixels on the
770 * output image. The bug happens on the y axis as well,
771 * but we only read one row there, and all source rows
772 * contain the same data. This bug is not dependent on
773 * the presence of a clipper. */
774 static const D3DCOLOR expected1_broken[] =
776 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
777 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
778 0x00000000, 0x00000000, 0x00ff0000, 0x00ff0000,
779 0x00000000, 0x00000000, 0x0000ff00, 0x00ff0000,
781 static const D3DCOLOR expected2[] =
783 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
784 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
785 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
786 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
789 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
790 10, 10, 640, 480, 0, 0, 0, 0);
791 ShowWindow(window, SW_SHOW);
792 ddraw = create_ddraw();
793 ok(!!ddraw, "Failed to create a ddraw object.\n");
795 ret = GetClientRect(window, &client_rect);
796 ok(ret, "Failed to get client rect.\n");
797 ret = MapWindowPoints(window, NULL, (POINT *)&client_rect, 2);
798 ok(ret, "Failed to map client rect.\n");
800 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
801 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
803 hr = IDirectDraw7_CreateClipper(ddraw, 0, &clipper, NULL);
804 ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr);
805 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
806 ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr);
807 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
808 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
809 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
810 ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr);
811 rgn_data = HeapAlloc(GetProcessHeap(), 0, ret);
812 hr = IDirectDrawClipper_GetClipList(clipper, NULL, rgn_data, &ret);
813 ok(SUCCEEDED(hr), "Failed to get clip list, hr %#x.\n", hr);
814 ok(rgn_data->rdh.dwSize == sizeof(rgn_data->rdh), "Got unexpected structure size %#x.\n", rgn_data->rdh.dwSize);
815 ok(rgn_data->rdh.iType == RDH_RECTANGLES, "Got unexpected type %#x.\n", rgn_data->rdh.iType);
816 ok(rgn_data->rdh.nCount >= 1, "Got unexpected count %u.\n", rgn_data->rdh.nCount);
817 ok(EqualRect(&rgn_data->rdh.rcBound, &client_rect),
818 "Got unexpected bounding rect %s, expected %s.\n",
819 wine_dbgstr_rect(&rgn_data->rdh.rcBound), wine_dbgstr_rect(&client_rect));
820 HeapFree(GetProcessHeap(), 0, rgn_data);
822 r1 = CreateRectRgn(0, 0, 320, 240);
823 ok(!!r1, "Failed to create region.\n");
824 r2 = CreateRectRgn(320, 240, 640, 480);
825 ok(!!r2, "Failed to create region.\n");
826 CombineRgn(r1, r1, r2, RGN_OR);
827 ret = GetRegionData(r1, 0, NULL);
828 rgn_data = HeapAlloc(GetProcessHeap(), 0, ret);
829 ret = GetRegionData(r1, ret, rgn_data);
830 ok(!!ret, "Failed to get region data.\n");
832 DeleteObject(r2);
833 DeleteObject(r1);
835 hr = IDirectDrawClipper_SetClipList(clipper, rgn_data, 0);
836 ok(hr == DDERR_CLIPPERISUSINGHWND, "Got unexpected hr %#x.\n", hr);
837 hr = IDirectDrawClipper_SetHWnd(clipper, 0, NULL);
838 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
839 hr = IDirectDrawClipper_SetClipList(clipper, rgn_data, 0);
840 ok(SUCCEEDED(hr), "Failed to set clip list, hr %#x.\n", hr);
842 HeapFree(GetProcessHeap(), 0, rgn_data);
844 memset(&surface_desc, 0, sizeof(surface_desc));
845 surface_desc.dwSize = sizeof(surface_desc);
846 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
847 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
848 surface_desc.dwWidth = 640;
849 surface_desc.dwHeight = 480;
850 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
851 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
852 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
853 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
854 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
855 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
857 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &src_surface, NULL);
858 ok(SUCCEEDED(hr), "Failed to create source surface, hr %#x.\n", hr);
859 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &dst_surface, NULL);
860 ok(SUCCEEDED(hr), "Failed to create destination surface, hr %#x.\n", hr);
862 memset(&fx, 0, sizeof(fx));
863 fx.dwSize = sizeof(fx);
864 hr = IDirectDrawSurface7_Blt(src_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
865 ok(SUCCEEDED(hr), "Failed to clear source surface, hr %#x.\n", hr);
866 hr = IDirectDrawSurface7_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
867 ok(SUCCEEDED(hr), "Failed to clear destination surface, hr %#x.\n", hr);
869 hr = IDirectDrawSurface7_Lock(src_surface, NULL, &surface_desc, 0, NULL);
870 ok(SUCCEEDED(hr), "Failed to lock source surface, hr %#x.\n", hr);
871 ok(U1(surface_desc).lPitch == 2560, "Got unexpected surface pitch %u.\n", U1(surface_desc).lPitch);
872 ptr = surface_desc.lpSurface;
873 memcpy(&ptr[ 0], &src_data[ 0], 6 * sizeof(DWORD));
874 memcpy(&ptr[ 640], &src_data[ 6], 6 * sizeof(DWORD));
875 memcpy(&ptr[1280], &src_data[12], 6 * sizeof(DWORD));
876 hr = IDirectDrawSurface7_Unlock(src_surface, NULL);
877 ok(SUCCEEDED(hr), "Failed to unlock source surface, hr %#x.\n", hr);
879 hr = IDirectDrawSurface7_SetClipper(dst_surface, clipper);
880 ok(SUCCEEDED(hr), "Failed to set clipper, hr %#x.\n", hr);
882 SetRect(&src_rect, 1, 1, 5, 2);
883 hr = IDirectDrawSurface7_Blt(dst_surface, NULL, src_surface, &src_rect, DDBLT_WAIT, NULL);
884 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
885 for (i = 0; i < 4; ++i)
887 for (j = 0; j < 4; ++j)
889 x = 80 * ((2 * j) + 1);
890 y = 60 * ((2 * i) + 1);
891 color = get_surface_color(dst_surface, x, y);
892 ok(compare_color(color, expected1[i * 4 + j], 1)
893 || broken(compare_color(color, expected1_broken[i * 4 + j], 1)),
894 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected1[i * 4 + j], x, y, color);
898 U5(fx).dwFillColor = 0xff0000ff;
899 hr = IDirectDrawSurface7_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
900 ok(SUCCEEDED(hr), "Failed to clear destination surface, hr %#x.\n", hr);
901 for (i = 0; i < 4; ++i)
903 for (j = 0; j < 4; ++j)
905 x = 80 * ((2 * j) + 1);
906 y = 60 * ((2 * i) + 1);
907 color = get_surface_color(dst_surface, x, y);
908 ok(compare_color(color, expected2[i * 4 + j], 1),
909 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected2[i * 4 + j], x, y, color);
913 hr = IDirectDrawSurface7_BltFast(dst_surface, 0, 0, src_surface, NULL, DDBLTFAST_WAIT);
914 ok(hr == DDERR_BLTFASTCANTCLIP, "Got unexpected hr %#x.\n", hr);
916 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
917 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
918 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
919 ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr);
920 DestroyWindow(window);
921 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
922 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
923 hr = IDirectDrawClipper_SetHWnd(clipper, 0, NULL);
924 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
925 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
926 ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr);
927 hr = IDirectDrawClipper_SetClipList(clipper, NULL, 0);
928 ok(SUCCEEDED(hr), "Failed to set clip list, hr %#x.\n", hr);
929 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
930 ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr);
931 hr = IDirectDrawSurface7_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
932 ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr);
934 IDirectDrawSurface7_Release(dst_surface);
935 IDirectDrawSurface7_Release(src_surface);
936 refcount = IDirectDrawClipper_Release(clipper);
937 ok(!refcount, "Clipper has %u references left.\n", refcount);
938 IDirectDraw7_Release(ddraw);
941 static void test_coop_level_d3d_state(void)
943 IDirectDrawSurface7 *rt, *surface;
944 IDirect3DDevice7 *device;
945 IDirectDraw7 *ddraw;
946 IDirect3D7 *d3d;
947 D3DCOLOR color;
948 DWORD value;
949 HWND window;
950 HRESULT hr;
952 window = create_window();
953 if (!(device = create_device(window, DDSCL_NORMAL)))
955 skip("Failed to create a 3D device, skipping test.\n");
956 DestroyWindow(window);
957 return;
960 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
961 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
962 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_ZENABLE, &value);
963 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
964 ok(!!value, "Got unexpected z-enable state %#x.\n", value);
965 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, &value);
966 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
967 ok(!value, "Got unexpected alpha blend enable state %#x.\n", value);
968 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);
969 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
970 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff0000, 0.0f, 0);
971 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
972 color = get_surface_color(rt, 320, 240);
973 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
975 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
976 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
977 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
978 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
979 IDirect3D7_Release(d3d);
980 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
981 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
982 hr = IDirectDrawSurface7_IsLost(rt);
983 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
984 hr = IDirectDraw7_RestoreAllSurfaces(ddraw);
985 ok(SUCCEEDED(hr), "Failed to restore surfaces, hr %#x.\n", hr);
986 IDirectDraw7_Release(ddraw);
988 hr = IDirect3DDevice7_GetRenderTarget(device, &surface);
989 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
990 ok(surface == rt, "Got unexpected surface %p.\n", surface);
991 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_ZENABLE, &value);
992 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
993 ok(!!value, "Got unexpected z-enable state %#x.\n", value);
994 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, &value);
995 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
996 ok(!!value, "Got unexpected alpha blend enable state %#x.\n", value);
997 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff00ff00, 0.0f, 0);
998 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
999 color = get_surface_color(rt, 320, 240);
1000 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
1002 IDirectDrawSurface7_Release(surface);
1003 IDirectDrawSurface7_Release(rt);
1004 IDirect3DDevice7_Release(device);
1005 DestroyWindow(window);
1008 static void test_surface_interface_mismatch(void)
1010 IDirectDraw7 *ddraw = NULL;
1011 IDirect3D7 *d3d = NULL;
1012 IDirectDrawSurface7 *surface = NULL, *ds;
1013 IDirectDrawSurface3 *surface3 = NULL;
1014 IDirect3DDevice7 *device = NULL;
1015 DDSURFACEDESC2 surface_desc;
1016 DDPIXELFORMAT z_fmt;
1017 ULONG refcount;
1018 HRESULT hr;
1019 D3DCOLOR color;
1020 HWND window;
1022 window = create_window();
1023 ddraw = create_ddraw();
1024 ok(!!ddraw, "Failed to create a ddraw object.\n");
1025 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
1026 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
1028 memset(&surface_desc, 0, sizeof(surface_desc));
1029 surface_desc.dwSize = sizeof(surface_desc);
1030 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1031 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
1032 surface_desc.dwWidth = 640;
1033 surface_desc.dwHeight = 480;
1035 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1036 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1038 hr = IDirectDrawSurface7_QueryInterface(surface, &IID_IDirectDrawSurface3, (void **)&surface3);
1039 ok(SUCCEEDED(hr), "Failed to QI IDirectDrawSurface3, hr %#x.\n", hr);
1041 if (FAILED(IDirectDraw7_QueryInterface(ddraw, &IID_IDirect3D7, (void **)&d3d)))
1043 skip("D3D interface is not available, skipping test.\n");
1044 goto cleanup;
1047 memset(&z_fmt, 0, sizeof(z_fmt));
1048 hr = IDirect3D7_EnumZBufferFormats(d3d, &IID_IDirect3DHALDevice, enum_z_fmt, &z_fmt);
1049 if (FAILED(hr) || !z_fmt.dwSize)
1051 skip("No depth buffer formats available, skipping test.\n");
1052 goto cleanup;
1055 memset(&surface_desc, 0, sizeof(surface_desc));
1056 surface_desc.dwSize = sizeof(surface_desc);
1057 surface_desc.dwFlags = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT;
1058 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
1059 U4(surface_desc).ddpfPixelFormat = z_fmt;
1060 surface_desc.dwWidth = 640;
1061 surface_desc.dwHeight = 480;
1062 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &ds, NULL);
1063 ok(SUCCEEDED(hr), "Failed to create depth buffer, hr %#x.\n", hr);
1064 if (FAILED(hr))
1065 goto cleanup;
1067 /* Using a different surface interface version still works */
1068 hr = IDirectDrawSurface3_AddAttachedSurface(surface3, (IDirectDrawSurface3 *)ds);
1069 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
1070 refcount = IDirectDrawSurface7_Release(ds);
1071 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
1072 if (FAILED(hr))
1073 goto cleanup;
1075 /* Here too */
1076 hr = IDirect3D7_CreateDevice(d3d, &IID_IDirect3DHALDevice, (IDirectDrawSurface7 *)surface3, &device);
1077 ok(SUCCEEDED(hr), "Failed to create d3d device.\n");
1078 if (FAILED(hr))
1079 goto cleanup;
1081 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff0000, 0.0f, 0);
1082 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
1083 color = get_surface_color(surface, 320, 240);
1084 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
1086 cleanup:
1087 if (surface3) IDirectDrawSurface3_Release(surface3);
1088 if (surface) IDirectDrawSurface7_Release(surface);
1089 if (device) IDirect3DDevice7_Release(device);
1090 if (d3d) IDirect3D7_Release(d3d);
1091 if (ddraw) IDirectDraw7_Release(ddraw);
1092 DestroyWindow(window);
1095 static void test_coop_level_threaded(void)
1097 struct create_window_thread_param p;
1098 IDirectDraw7 *ddraw;
1099 HRESULT hr;
1101 ddraw = create_ddraw();
1102 ok(!!ddraw, "Failed to create a ddraw object.\n");
1103 create_window_thread(&p);
1105 hr = IDirectDraw7_SetCooperativeLevel(ddraw, p.window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
1106 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
1108 IDirectDraw7_Release(ddraw);
1109 destroy_window_thread(&p);
1112 static void test_depth_blit(void)
1114 IDirect3DDevice7 *device;
1115 static struct
1117 float x, y, z;
1118 DWORD color;
1120 quad1[] =
1122 { -1.0, 1.0, 0.50f, 0xff00ff00},
1123 { 1.0, 1.0, 0.50f, 0xff00ff00},
1124 { -1.0, -1.0, 0.50f, 0xff00ff00},
1125 { 1.0, -1.0, 0.50f, 0xff00ff00},
1127 static const D3DCOLOR expected_colors[4][4] =
1129 {0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00},
1130 {0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00},
1131 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1132 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1134 DDSURFACEDESC2 ddsd_new, ddsd_existing;
1136 IDirectDrawSurface7 *ds1, *ds2, *ds3, *rt;
1137 RECT src_rect, dst_rect;
1138 unsigned int i, j;
1139 D3DCOLOR color;
1140 HRESULT hr;
1141 IDirect3D7 *d3d;
1142 IDirectDraw7 *ddraw;
1143 DDBLTFX fx;
1144 HWND window;
1146 window = create_window();
1147 if (!(device = create_device(window, DDSCL_NORMAL)))
1149 skip("Failed to create a 3D device, skipping test.\n");
1150 DestroyWindow(window);
1151 return;
1154 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
1155 ok(SUCCEEDED(hr), "Failed to get Direct3D7 interface, hr %#x.\n", hr);
1156 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
1157 ok(SUCCEEDED(hr), "Failed to get DirectDraw7 interface, hr %#x.\n", hr);
1158 IDirect3D7_Release(d3d);
1160 ds1 = get_depth_stencil(device);
1162 memset(&ddsd_new, 0, sizeof(ddsd_new));
1163 ddsd_new.dwSize = sizeof(ddsd_new);
1164 memset(&ddsd_existing, 0, sizeof(ddsd_existing));
1165 ddsd_existing.dwSize = sizeof(ddsd_existing);
1166 hr = IDirectDrawSurface7_GetSurfaceDesc(ds1, &ddsd_existing);
1167 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
1168 ddsd_new.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
1169 ddsd_new.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
1170 ddsd_new.dwWidth = ddsd_existing.dwWidth;
1171 ddsd_new.dwHeight = ddsd_existing.dwHeight;
1172 U4(ddsd_new).ddpfPixelFormat = U4(ddsd_existing).ddpfPixelFormat;
1173 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd_new, &ds2, NULL);
1174 ok(SUCCEEDED(hr), "Failed to create a z buffer, hr %#x.\n", hr);
1175 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd_new, &ds3, NULL);
1176 ok(SUCCEEDED(hr), "Failed to create a z buffer, hr %#x.\n", hr);
1177 IDirectDraw7_Release(ddraw);
1179 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_TRUE);
1180 ok(SUCCEEDED(hr), "Failed to enable z testing, hr %#x.\n", hr);
1181 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZFUNC, D3DCMP_LESSEQUAL);
1182 ok(SUCCEEDED(hr), "Failed to set the z function, hr %#x.\n", hr);
1183 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
1184 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
1186 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER, 0, 0.0f, 0);
1187 ok(SUCCEEDED(hr), "Failed to clear the z buffer, hr %#x.\n", hr);
1189 /* Partial blit. */
1190 SetRect(&src_rect, 0, 0, 320, 240);
1191 SetRect(&dst_rect, 0, 0, 320, 240);
1192 hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1193 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1194 /* Different locations. */
1195 SetRect(&src_rect, 0, 0, 320, 240);
1196 SetRect(&dst_rect, 320, 240, 640, 480);
1197 hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1198 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1199 /* Stretched. */
1200 SetRect(&src_rect, 0, 0, 320, 240);
1201 SetRect(&dst_rect, 0, 0, 640, 480);
1202 hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1203 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1204 /* Flipped. */
1205 SetRect(&src_rect, 0, 480, 640, 0);
1206 SetRect(&dst_rect, 0, 0, 640, 480);
1207 hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1208 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
1209 SetRect(&src_rect, 0, 0, 640, 480);
1210 SetRect(&dst_rect, 0, 480, 640, 0);
1211 hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1212 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
1213 /* Full, explicit. */
1214 SetRect(&src_rect, 0, 0, 640, 480);
1215 SetRect(&dst_rect, 0, 0, 640, 480);
1216 hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1217 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1218 /* Depth -> color blit: Succeeds on Win7 + Radeon HD 5700, fails on WinXP + Radeon X1600 */
1220 /* Depth blit inside a BeginScene / EndScene pair */
1221 hr = IDirect3DDevice7_BeginScene(device);
1222 ok(SUCCEEDED(hr), "Failed to start scene, hr %#x.\n", hr);
1223 /* From the current depth stencil */
1224 hr = IDirectDrawSurface7_Blt(ds2, NULL, ds1, NULL, DDBLT_WAIT, NULL);
1225 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1226 /* To the current depth stencil */
1227 hr = IDirectDrawSurface7_Blt(ds1, NULL, ds2, NULL, DDBLT_WAIT, NULL);
1228 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1229 /* Between unbound surfaces */
1230 hr = IDirectDrawSurface7_Blt(ds3, NULL, ds2, NULL, DDBLT_WAIT, NULL);
1231 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1232 hr = IDirect3DDevice7_EndScene(device);
1233 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1235 /* Avoid changing the depth stencil, it doesn't work properly on Windows.
1236 * Instead use DDBLT_DEPTHFILL to clear the depth stencil. Unfortunately
1237 * drivers disagree on the meaning of dwFillDepth. Only 0 seems to produce
1238 * a reliable result(z = 0.0) */
1239 memset(&fx, 0, sizeof(fx));
1240 fx.dwSize = sizeof(fx);
1241 hr = IDirectDrawSurface7_Blt(ds2, NULL, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
1242 ok(SUCCEEDED(hr), "Failed to clear the source z buffer, hr %#x.\n", hr);
1244 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER | D3DCLEAR_TARGET, 0xffff0000, 1.0f, 0);
1245 ok(SUCCEEDED(hr), "Failed to clear the color and z buffers, hr %#x.\n", hr);
1246 SetRect(&dst_rect, 0, 0, 320, 240);
1247 hr = IDirectDrawSurface7_Blt(ds1, &dst_rect, ds2, NULL, DDBLT_WAIT, NULL);
1248 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1249 IDirectDrawSurface7_Release(ds3);
1250 IDirectDrawSurface7_Release(ds2);
1251 IDirectDrawSurface7_Release(ds1);
1253 hr = IDirect3DDevice7_BeginScene(device);
1254 ok(SUCCEEDED(hr), "Failed to start scene, hr %#x.\n", hr);
1255 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE,
1256 quad1, 4, 0);
1257 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1258 hr = IDirect3DDevice7_EndScene(device);
1259 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1261 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
1262 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1263 for (i = 0; i < 4; ++i)
1265 for (j = 0; j < 4; ++j)
1267 unsigned int x = 80 * ((2 * j) + 1);
1268 unsigned int y = 60 * ((2 * i) + 1);
1269 color = get_surface_color(rt, x, y);
1270 ok(compare_color(color, expected_colors[i][j], 1),
1271 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected_colors[i][j], x, y, color);
1275 IDirectDrawSurface7_Release(rt);
1276 IDirect3DDevice7_Release(device);
1277 DestroyWindow(window);
1280 static void test_texture_load_ckey(void)
1282 HWND window;
1283 IDirect3DDevice7 *device;
1284 IDirectDraw7 *ddraw;
1285 IDirectDrawSurface7 *src;
1286 IDirectDrawSurface7 *dst;
1287 DDSURFACEDESC2 ddsd;
1288 HRESULT hr;
1289 DDCOLORKEY ckey;
1290 IDirect3D7 *d3d;
1292 window = create_window();
1293 if (!(device = create_device(window, DDSCL_NORMAL)))
1295 skip("Failed to create a 3D device, skipping test.\n");
1296 DestroyWindow(window);
1297 return;
1300 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
1301 ok(SUCCEEDED(hr), "Failed to get Direct3D7 interface, hr %#x.\n", hr);
1302 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
1303 ok(SUCCEEDED(hr), "Failed to get DirectDraw7 interface, hr %#x.\n", hr);
1304 IDirect3D7_Release(d3d);
1306 memset(&ddsd, 0, sizeof(ddsd));
1307 ddsd.dwSize = sizeof(ddsd);
1308 ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
1309 ddsd.dwHeight = 128;
1310 ddsd.dwWidth = 128;
1311 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY;
1312 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &src, NULL);
1313 ok(SUCCEEDED(hr), "Failed to create source texture, hr %#x.\n", hr);
1314 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1315 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &dst, NULL);
1316 ok(SUCCEEDED(hr), "Failed to create destination texture, hr %#x.\n", hr);
1318 /* No surface has a color key */
1319 hr = IDirect3DDevice7_Load(device, dst, NULL, src, NULL, 0);
1320 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1321 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0xdeadbeef;
1322 hr = IDirectDrawSurface7_GetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1323 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1324 ok(ckey.dwColorSpaceLowValue == 0xdeadbeef, "dwColorSpaceLowValue is %#x.\n", ckey.dwColorSpaceLowValue);
1325 ok(ckey.dwColorSpaceHighValue == 0xdeadbeef, "dwColorSpaceHighValue is %#x.\n", ckey.dwColorSpaceHighValue);
1327 /* Source surface has a color key */
1328 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0x0000ff00;
1329 hr = IDirectDrawSurface7_SetColorKey(src, DDCKEY_SRCBLT, &ckey);
1330 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1331 hr = IDirect3DDevice7_Load(device, dst, NULL, src, NULL, 0);
1332 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1333 hr = IDirectDrawSurface7_GetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1334 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1335 ok(ckey.dwColorSpaceLowValue == 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey.dwColorSpaceLowValue);
1336 ok(ckey.dwColorSpaceHighValue == 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey.dwColorSpaceHighValue);
1338 /* Both surfaces have a color key: Dest ckey is overwritten */
1339 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0x000000ff;
1340 hr = IDirectDrawSurface7_SetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1341 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1342 hr = IDirect3DDevice7_Load(device, dst, NULL, src, NULL, 0);
1343 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1344 hr = IDirectDrawSurface7_GetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1345 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1346 ok(ckey.dwColorSpaceLowValue == 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey.dwColorSpaceLowValue);
1347 ok(ckey.dwColorSpaceHighValue == 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey.dwColorSpaceHighValue);
1349 /* Only the destination has a color key: It is deleted. This behavior differs from
1350 * IDirect3DTexture(2)::Load */
1351 hr = IDirectDrawSurface7_SetColorKey(src, DDCKEY_SRCBLT, NULL);
1352 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1353 hr = IDirectDrawSurface7_GetColorKey(src, DDCKEY_SRCBLT, &ckey);
1354 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1355 hr = IDirect3DDevice7_Load(device, dst, NULL, src, NULL, 0);
1356 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1357 hr = IDirectDrawSurface7_GetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1358 todo_wine ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1360 IDirectDrawSurface7_Release(dst);
1361 IDirectDrawSurface7_Release(src);
1362 IDirectDraw7_Release(ddraw);
1363 IDirect3DDevice7_Release(device);
1364 DestroyWindow(window);
1367 static void test_zenable(void)
1369 static struct
1371 struct vec4 position;
1372 D3DCOLOR diffuse;
1374 tquad[] =
1376 {{ 0.0f, 480.0f, -0.5f, 1.0f}, 0xff00ff00},
1377 {{ 0.0f, 0.0f, -0.5f, 1.0f}, 0xff00ff00},
1378 {{640.0f, 480.0f, 1.5f, 1.0f}, 0xff00ff00},
1379 {{640.0f, 0.0f, 1.5f, 1.0f}, 0xff00ff00},
1381 IDirect3DDevice7 *device;
1382 IDirectDrawSurface7 *rt;
1383 D3DCOLOR color;
1384 HWND window;
1385 HRESULT hr;
1386 UINT x, y;
1387 UINT i, j;
1389 window = create_window();
1390 if (!(device = create_device(window, DDSCL_NORMAL)))
1392 skip("Failed to create a 3D device, skipping test.\n");
1393 DestroyWindow(window);
1394 return;
1397 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
1398 ok(SUCCEEDED(hr), "Failed to disable z-buffering, hr %#x.\n", hr);
1400 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffff0000, 0.0f, 0);
1401 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
1402 hr = IDirect3DDevice7_BeginScene(device);
1403 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1404 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_DIFFUSE, tquad, 4, 0);
1405 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1406 hr = IDirect3DDevice7_EndScene(device);
1407 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1409 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
1410 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1411 for (i = 0; i < 4; ++i)
1413 for (j = 0; j < 4; ++j)
1415 x = 80 * ((2 * j) + 1);
1416 y = 60 * ((2 * i) + 1);
1417 color = get_surface_color(rt, x, y);
1418 ok(compare_color(color, 0x0000ff00, 1),
1419 "Expected color 0x0000ff00 at %u, %u, got 0x%08x.\n", x, y, color);
1422 IDirectDrawSurface7_Release(rt);
1424 IDirect3DDevice7_Release(device);
1425 DestroyWindow(window);
1428 static void test_ck_rgba(void)
1430 static struct
1432 struct vec4 position;
1433 struct vec2 texcoord;
1435 tquad[] =
1437 {{ 0.0f, 480.0f, 0.25f, 1.0f}, {0.0f, 0.0f}},
1438 {{ 0.0f, 0.0f, 0.25f, 1.0f}, {0.0f, 1.0f}},
1439 {{640.0f, 480.0f, 0.25f, 1.0f}, {1.0f, 0.0f}},
1440 {{640.0f, 0.0f, 0.25f, 1.0f}, {1.0f, 1.0f}},
1441 {{ 0.0f, 480.0f, 0.75f, 1.0f}, {0.0f, 0.0f}},
1442 {{ 0.0f, 0.0f, 0.75f, 1.0f}, {0.0f, 1.0f}},
1443 {{640.0f, 480.0f, 0.75f, 1.0f}, {1.0f, 0.0f}},
1444 {{640.0f, 0.0f, 0.75f, 1.0f}, {1.0f, 1.0f}},
1446 static const struct
1448 D3DCOLOR fill_color;
1449 BOOL color_key;
1450 BOOL blend;
1451 D3DCOLOR result1, result1_broken;
1452 D3DCOLOR result2, result2_broken;
1454 tests[] =
1456 /* r200 on Windows doesn't check the alpha component when applying the color
1457 * key, so the key matches on every texel. */
1458 {0xff00ff00, TRUE, TRUE, 0x00ff0000, 0x00ff0000, 0x000000ff, 0x000000ff},
1459 {0xff00ff00, TRUE, FALSE, 0x00ff0000, 0x00ff0000, 0x000000ff, 0x000000ff},
1460 {0xff00ff00, FALSE, TRUE, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1461 {0xff00ff00, FALSE, FALSE, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1462 {0x7f00ff00, TRUE, TRUE, 0x00807f00, 0x00ff0000, 0x00807f00, 0x000000ff},
1463 {0x7f00ff00, TRUE, FALSE, 0x0000ff00, 0x00ff0000, 0x0000ff00, 0x000000ff},
1464 {0x7f00ff00, FALSE, TRUE, 0x00807f00, 0x00807f00, 0x00807f00, 0x00807f00},
1465 {0x7f00ff00, FALSE, FALSE, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1468 IDirectDrawSurface7 *texture;
1469 DDSURFACEDESC2 surface_desc;
1470 IDirect3DDevice7 *device;
1471 IDirectDrawSurface7 *rt;
1472 IDirectDraw7 *ddraw;
1473 IDirect3D7 *d3d;
1474 D3DCOLOR color;
1475 HWND window;
1476 DDBLTFX fx;
1477 HRESULT hr;
1478 UINT i;
1480 window = create_window();
1481 if (!(device = create_device(window, DDSCL_NORMAL)))
1483 skip("Failed to create a 3D device, skipping test.\n");
1484 DestroyWindow(window);
1485 return;
1488 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
1489 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
1490 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
1491 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
1492 IDirect3D7_Release(d3d);
1494 memset(&surface_desc, 0, sizeof(surface_desc));
1495 surface_desc.dwSize = sizeof(surface_desc);
1496 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CKSRCBLT;
1497 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1498 surface_desc.dwWidth = 256;
1499 surface_desc.dwHeight = 256;
1500 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
1501 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
1502 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
1503 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
1504 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
1505 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
1506 U5(U4(surface_desc).ddpfPixelFormat).dwRGBAlphaBitMask = 0xff000000;
1507 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0xff00ff00;
1508 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0xff00ff00;
1509 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &texture, NULL);
1510 ok(SUCCEEDED(hr), "Failed to create destination surface, hr %#x.\n", hr);
1512 hr = IDirect3DDevice7_SetTexture(device, 0, texture);
1513 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
1514 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);
1515 ok(SUCCEEDED(hr), "Failed to enable alpha blending, hr %#x.\n", hr);
1516 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA);
1517 ok(SUCCEEDED(hr), "Failed to enable alpha blending, hr %#x.\n", hr);
1519 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
1520 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1522 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
1524 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, tests[i].color_key);
1525 ok(SUCCEEDED(hr), "Failed to enable color keying, hr %#x.\n", hr);
1526 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, tests[i].blend);
1527 ok(SUCCEEDED(hr), "Failed to enable alpha blending, hr %#x.\n", hr);
1529 memset(&fx, 0, sizeof(fx));
1530 fx.dwSize = sizeof(fx);
1531 U5(fx).dwFillColor = tests[i].fill_color;
1532 hr = IDirectDrawSurface7_Blt(texture, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
1533 ok(SUCCEEDED(hr), "Failed to fill texture, hr %#x.\n", hr);
1535 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffff0000, 1.0f, 0);
1536 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
1537 hr = IDirect3DDevice7_BeginScene(device);
1538 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1539 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_TEX1, &tquad[0], 4, 0);
1540 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1541 hr = IDirect3DDevice7_EndScene(device);
1542 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1544 color = get_surface_color(rt, 320, 240);
1545 ok(compare_color(color, tests[i].result1, 1) || compare_color(color, tests[i].result1_broken, 1),
1546 "Expected color 0x%08x for test %u, got 0x%08x.\n",
1547 tests[i].result1, i, color);
1549 U5(fx).dwFillColor = 0xff0000ff;
1550 hr = IDirectDrawSurface7_Blt(texture, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
1551 ok(SUCCEEDED(hr), "Failed to fill texture, hr %#x.\n", hr);
1553 hr = IDirect3DDevice7_BeginScene(device);
1554 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1555 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_TEX1, &tquad[4], 4, 0);
1556 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1557 hr = IDirect3DDevice7_EndScene(device);
1558 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1560 /* This tests that fragments that are masked out by the color key are
1561 * discarded, instead of just fully transparent. */
1562 color = get_surface_color(rt, 320, 240);
1563 ok(compare_color(color, tests[i].result2, 1) || compare_color(color, tests[i].result2_broken, 1),
1564 "Expected color 0x%08x for test %u, got 0x%08x.\n",
1565 tests[i].result2, i, color);
1568 IDirectDrawSurface7_Release(rt);
1569 IDirectDrawSurface7_Release(texture);
1570 IDirectDraw7_Release(ddraw);
1571 IDirect3DDevice7_Release(device);
1572 DestroyWindow(window);
1575 static void test_ck_default(void)
1577 static struct
1579 struct vec4 position;
1580 struct vec2 texcoord;
1582 tquad[] =
1584 {{ 0.0f, 480.0f, 0.0f, 1.0f}, {0.0f, 0.0f}},
1585 {{ 0.0f, 0.0f, 0.0f, 1.0f}, {0.0f, 1.0f}},
1586 {{640.0f, 480.0f, 0.0f, 1.0f}, {1.0f, 0.0f}},
1587 {{640.0f, 0.0f, 0.0f, 1.0f}, {1.0f, 1.0f}},
1589 IDirectDrawSurface7 *surface, *rt;
1590 DDSURFACEDESC2 surface_desc;
1591 IDirect3DDevice7 *device;
1592 IDirectDraw7 *ddraw;
1593 IDirect3D7 *d3d;
1594 D3DCOLOR color;
1595 DWORD value;
1596 HWND window;
1597 DDBLTFX fx;
1598 HRESULT hr;
1600 window = create_window();
1601 if (!(device = create_device(window, DDSCL_NORMAL)))
1603 skip("Failed to create a 3D device, skipping test.\n");
1604 DestroyWindow(window);
1605 return;
1608 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
1609 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
1610 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
1611 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
1612 IDirect3D7_Release(d3d);
1614 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
1615 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1617 memset(&surface_desc, 0, sizeof(surface_desc));
1618 surface_desc.dwSize = sizeof(surface_desc);
1619 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CKSRCBLT;
1620 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1621 surface_desc.dwWidth = 256;
1622 surface_desc.dwHeight = 256;
1623 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
1624 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
1625 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
1626 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
1627 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
1628 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
1629 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x000000ff;
1630 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x000000ff;
1631 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1632 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1633 hr = IDirect3DDevice7_SetTexture(device, 0, surface);
1634 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
1636 memset(&fx, 0, sizeof(fx));
1637 fx.dwSize = sizeof(fx);
1638 U5(fx).dwFillColor = 0x000000ff;
1639 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
1640 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
1642 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff00ff00, 1.0f, 0);
1643 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
1644 hr = IDirect3DDevice7_BeginScene(device);
1645 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1646 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, &value);
1647 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
1648 ok(!value, "Got unexpected color keying state %#x.\n", value);
1649 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_TEX1, &tquad[0], 4, 0);
1650 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1651 hr = IDirect3DDevice7_EndScene(device);
1652 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1653 color = get_surface_color(rt, 320, 240);
1654 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
1656 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff00ff00, 1.0f, 0);
1657 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
1658 hr = IDirect3DDevice7_BeginScene(device);
1659 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1660 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, TRUE);
1661 ok(SUCCEEDED(hr), "Failed to enable color keying, hr %#x.\n", hr);
1662 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_TEX1, &tquad[0], 4, 0);
1663 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1664 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, &value);
1665 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
1666 ok(!!value, "Got unexpected color keying state %#x.\n", value);
1667 hr = IDirect3DDevice7_EndScene(device);
1668 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1669 color = get_surface_color(rt, 320, 240);
1670 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
1672 IDirectDrawSurface7_Release(surface);
1673 IDirectDrawSurface7_Release(rt);
1674 IDirect3DDevice7_Release(device);
1675 IDirectDraw7_Release(ddraw);
1676 DestroyWindow(window);
1679 static void test_ck_complex(void)
1681 IDirectDrawSurface7 *surface, *mipmap, *tmp;
1682 D3DDEVICEDESC7 device_desc;
1683 DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, {0}};
1684 DDSURFACEDESC2 surface_desc;
1685 IDirect3DDevice7 *device;
1686 DDCOLORKEY color_key;
1687 IDirectDraw7 *ddraw;
1688 IDirect3D7 *d3d;
1689 unsigned int i;
1690 ULONG refcount;
1691 HWND window;
1692 HRESULT hr;
1694 window = create_window();
1695 if (!(device = create_device(window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN)))
1697 skip("Failed to create a 3D device, skipping test.\n");
1698 DestroyWindow(window);
1699 return;
1701 hr = IDirect3DDevice7_GetCaps(device, &device_desc);
1702 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
1703 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
1704 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
1705 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
1706 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
1707 IDirect3D7_Release(d3d);
1709 memset(&surface_desc, 0, sizeof(surface_desc));
1710 surface_desc.dwSize = sizeof(surface_desc);
1711 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1712 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
1713 surface_desc.dwWidth = 128;
1714 surface_desc.dwHeight = 128;
1715 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1716 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1718 hr = IDirectDrawSurface7_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1719 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1720 color_key.dwColorSpaceLowValue = 0x0000ff00;
1721 color_key.dwColorSpaceHighValue = 0x0000ff00;
1722 hr = IDirectDrawSurface7_SetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1723 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1724 memset(&color_key, 0, sizeof(color_key));
1725 hr = IDirectDrawSurface7_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1726 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
1727 ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1728 color_key.dwColorSpaceLowValue);
1729 ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1730 color_key.dwColorSpaceHighValue);
1732 mipmap = surface;
1733 IDirectDrawSurface_AddRef(mipmap);
1734 for (i = 0; i < 7; ++i)
1736 hr = IDirectDrawSurface7_GetAttachedSurface(mipmap, &caps, &tmp);
1737 ok(SUCCEEDED(hr), "Failed to get attached surface, i %u, hr %#x.\n", i, hr);
1738 hr = IDirectDrawSurface7_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1739 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x, i %u.\n", hr, i);
1741 color_key.dwColorSpaceLowValue = 0x000000ff;
1742 color_key.dwColorSpaceHighValue = 0x000000ff;
1743 hr = IDirectDrawSurface7_SetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1744 ok(hr == DDERR_NOTONMIPMAPSUBLEVEL, "Got unexpected hr %#x, i %u.\n", hr, i);
1746 IDirectDrawSurface_Release(mipmap);
1747 mipmap = tmp;
1750 hr = IDirectDrawSurface7_GetAttachedSurface(mipmap, &caps, &tmp);
1751 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
1752 IDirectDrawSurface_Release(mipmap);
1753 refcount = IDirectDrawSurface7_Release(surface);
1754 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1756 memset(&surface_desc, 0, sizeof(surface_desc));
1757 surface_desc.dwSize = sizeof(surface_desc);
1758 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
1759 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
1760 U5(surface_desc).dwBackBufferCount = 1;
1761 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1762 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1764 hr = IDirectDrawSurface7_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1765 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1766 color_key.dwColorSpaceLowValue = 0x0000ff00;
1767 color_key.dwColorSpaceHighValue = 0x0000ff00;
1768 hr = IDirectDrawSurface7_SetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1769 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1770 memset(&color_key, 0, sizeof(color_key));
1771 hr = IDirectDrawSurface7_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1772 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
1773 ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1774 color_key.dwColorSpaceLowValue);
1775 ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1776 color_key.dwColorSpaceHighValue);
1778 hr = IDirectDrawSurface7_GetAttachedSurface(surface, &caps, &tmp);
1779 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
1781 hr = IDirectDrawSurface7_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1782 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x, i %u.\n", hr, i);
1783 color_key.dwColorSpaceLowValue = 0x0000ff00;
1784 color_key.dwColorSpaceHighValue = 0x0000ff00;
1785 hr = IDirectDrawSurface7_SetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1786 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1787 memset(&color_key, 0, sizeof(color_key));
1788 hr = IDirectDrawSurface7_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1789 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
1790 ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1791 color_key.dwColorSpaceLowValue);
1792 ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1793 color_key.dwColorSpaceHighValue);
1795 IDirectDrawSurface_Release(tmp);
1797 refcount = IDirectDrawSurface7_Release(surface);
1798 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1800 if (!(device_desc.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_CUBEMAP))
1802 skip("Device does not support cubemaps.\n");
1803 goto cleanup;
1805 memset(&surface_desc, 0, sizeof(surface_desc));
1806 surface_desc.dwSize = sizeof(surface_desc);
1807 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1808 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
1809 surface_desc.ddsCaps.dwCaps2 = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES;
1810 surface_desc.dwWidth = 128;
1811 surface_desc.dwHeight = 128;
1812 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1813 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1815 hr = IDirectDrawSurface7_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1816 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1817 color_key.dwColorSpaceLowValue = 0x0000ff00;
1818 color_key.dwColorSpaceHighValue = 0x0000ff00;
1819 hr = IDirectDrawSurface7_SetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1820 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1822 caps.dwCaps2 = DDSCAPS2_CUBEMAP_NEGATIVEZ;
1823 hr = IDirectDrawSurface7_GetAttachedSurface(surface, &caps, &mipmap);
1824 ok(SUCCEEDED(hr), "Failed to get attached surface, i %u, hr %#x.\n", i, hr);
1826 hr = IDirectDrawSurface7_GetColorKey(mipmap, DDCKEY_SRCBLT, &color_key);
1827 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1828 color_key.dwColorSpaceLowValue = 0x000000ff;
1829 color_key.dwColorSpaceHighValue = 0x000000ff;
1830 hr = IDirectDrawSurface7_SetColorKey(mipmap, DDCKEY_SRCBLT, &color_key);
1831 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1833 color_key.dwColorSpaceLowValue = 0;
1834 color_key.dwColorSpaceHighValue = 0;
1835 hr = IDirectDrawSurface7_GetColorKey(mipmap, DDCKEY_SRCBLT, &color_key);
1836 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
1837 ok(color_key.dwColorSpaceLowValue == 0x000000ff, "Got unexpected value 0x%08x.\n",
1838 color_key.dwColorSpaceLowValue);
1839 ok(color_key.dwColorSpaceHighValue == 0x000000ff, "Got unexpected value 0x%08x.\n",
1840 color_key.dwColorSpaceHighValue);
1842 IDirectDrawSurface_AddRef(mipmap);
1843 for (i = 0; i < 7; ++i)
1845 hr = IDirectDrawSurface7_GetAttachedSurface(mipmap, &caps, &tmp);
1846 ok(SUCCEEDED(hr), "Failed to get attached surface, i %u, hr %#x.\n", i, hr);
1847 hr = IDirectDrawSurface7_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1848 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x, i %u.\n", hr, i);
1850 color_key.dwColorSpaceLowValue = 0x000000ff;
1851 color_key.dwColorSpaceHighValue = 0x000000ff;
1852 hr = IDirectDrawSurface7_SetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1853 ok(hr == DDERR_NOTONMIPMAPSUBLEVEL, "Got unexpected hr %#x, i %u.\n", hr, i);
1855 IDirectDrawSurface_Release(mipmap);
1856 mipmap = tmp;
1859 IDirectDrawSurface7_Release(mipmap);
1861 refcount = IDirectDrawSurface7_Release(surface);
1862 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1864 cleanup:
1865 IDirectDraw7_Release(ddraw);
1866 refcount = IDirect3DDevice7_Release(device);
1867 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1868 DestroyWindow(window);
1871 struct qi_test
1873 REFIID iid;
1874 REFIID refcount_iid;
1875 HRESULT hr;
1878 static void test_qi(const char *test_name, IUnknown *base_iface,
1879 REFIID refcount_iid, const struct qi_test *tests, UINT entry_count)
1881 ULONG refcount, expected_refcount;
1882 IUnknown *iface1, *iface2;
1883 HRESULT hr;
1884 UINT i, j;
1886 for (i = 0; i < entry_count; ++i)
1888 hr = IUnknown_QueryInterface(base_iface, tests[i].iid, (void **)&iface1);
1889 ok(hr == tests[i].hr, "Got hr %#x for test \"%s\" %u.\n", hr, test_name, i);
1890 if (SUCCEEDED(hr))
1892 for (j = 0; j < entry_count; ++j)
1894 hr = IUnknown_QueryInterface(iface1, tests[j].iid, (void **)&iface2);
1895 ok(hr == tests[j].hr, "Got hr %#x for test \"%s\" %u, %u.\n", hr, test_name, i, j);
1896 if (SUCCEEDED(hr))
1898 expected_refcount = 0;
1899 if (IsEqualGUID(refcount_iid, tests[j].refcount_iid))
1900 ++expected_refcount;
1901 if (IsEqualGUID(tests[i].refcount_iid, tests[j].refcount_iid))
1902 ++expected_refcount;
1903 refcount = IUnknown_Release(iface2);
1904 ok(refcount == expected_refcount, "Got refcount %u for test \"%s\" %u, %u, expected %u.\n",
1905 refcount, test_name, i, j, expected_refcount);
1909 expected_refcount = 0;
1910 if (IsEqualGUID(refcount_iid, tests[i].refcount_iid))
1911 ++expected_refcount;
1912 refcount = IUnknown_Release(iface1);
1913 ok(refcount == expected_refcount, "Got refcount %u for test \"%s\" %u, expected %u.\n",
1914 refcount, test_name, i, expected_refcount);
1919 static void test_surface_qi(void)
1921 static const struct qi_test tests[] =
1923 {&IID_IDirect3DTexture2, NULL, E_NOINTERFACE},
1924 {&IID_IDirect3DTexture, NULL, E_NOINTERFACE},
1925 {&IID_IDirectDrawGammaControl, &IID_IDirectDrawGammaControl, S_OK },
1926 {&IID_IDirectDrawColorControl, NULL, E_NOINTERFACE},
1927 {&IID_IDirectDrawSurface7, &IID_IDirectDrawSurface7, S_OK },
1928 {&IID_IDirectDrawSurface4, &IID_IDirectDrawSurface4, S_OK },
1929 {&IID_IDirectDrawSurface3, &IID_IDirectDrawSurface3, S_OK },
1930 {&IID_IDirectDrawSurface2, &IID_IDirectDrawSurface2, S_OK },
1931 {&IID_IDirectDrawSurface, &IID_IDirectDrawSurface, S_OK },
1932 {&IID_IDirect3DDevice7, NULL, E_NOINTERFACE},
1933 {&IID_IDirect3DDevice3, NULL, E_NOINTERFACE},
1934 {&IID_IDirect3DDevice2, NULL, E_NOINTERFACE},
1935 {&IID_IDirect3DDevice, NULL, E_NOINTERFACE},
1936 {&IID_IDirect3DRampDevice, NULL, E_NOINTERFACE},
1937 {&IID_IDirect3DRGBDevice, NULL, E_NOINTERFACE},
1938 {&IID_IDirect3DHALDevice, NULL, E_NOINTERFACE},
1939 {&IID_IDirect3DMMXDevice, NULL, E_NOINTERFACE},
1940 {&IID_IDirect3DRefDevice, NULL, E_NOINTERFACE},
1941 {&IID_IDirect3DTnLHalDevice, NULL, E_NOINTERFACE},
1942 {&IID_IDirect3DNullDevice, NULL, E_NOINTERFACE},
1943 {&IID_IDirect3D7, NULL, E_NOINTERFACE},
1944 {&IID_IDirect3D3, NULL, E_NOINTERFACE},
1945 {&IID_IDirect3D2, NULL, E_NOINTERFACE},
1946 {&IID_IDirect3D, NULL, E_NOINTERFACE},
1947 {&IID_IDirectDraw7, NULL, E_NOINTERFACE},
1948 {&IID_IDirectDraw4, NULL, E_NOINTERFACE},
1949 {&IID_IDirectDraw3, NULL, E_NOINTERFACE},
1950 {&IID_IDirectDraw2, NULL, E_NOINTERFACE},
1951 {&IID_IDirectDraw, NULL, E_NOINTERFACE},
1952 {&IID_IDirect3DLight, NULL, E_NOINTERFACE},
1953 {&IID_IDirect3DMaterial, NULL, E_NOINTERFACE},
1954 {&IID_IDirect3DMaterial2, NULL, E_NOINTERFACE},
1955 {&IID_IDirect3DMaterial3, NULL, E_NOINTERFACE},
1956 {&IID_IDirect3DExecuteBuffer, NULL, E_NOINTERFACE},
1957 {&IID_IDirect3DViewport, NULL, E_NOINTERFACE},
1958 {&IID_IDirect3DViewport2, NULL, E_NOINTERFACE},
1959 {&IID_IDirect3DViewport3, NULL, E_NOINTERFACE},
1960 {&IID_IDirect3DVertexBuffer, NULL, E_NOINTERFACE},
1961 {&IID_IDirect3DVertexBuffer7, NULL, E_NOINTERFACE},
1962 {&IID_IDirectDrawPalette, NULL, E_NOINTERFACE},
1963 {&IID_IDirectDrawClipper, NULL, E_NOINTERFACE},
1964 {&IID_IUnknown, &IID_IDirectDrawSurface, S_OK },
1967 IDirectDrawSurface7 *surface;
1968 DDSURFACEDESC2 surface_desc;
1969 IDirect3DDevice7 *device;
1970 IDirectDraw7 *ddraw;
1971 HWND window;
1972 HRESULT hr;
1974 window = create_window();
1975 /* Try to create a D3D device to see if the ddraw implementation supports
1976 * D3D. 64-bit ddraw in particular doesn't seem to support D3D, and
1977 * doesn't support e.g. the IDirect3DTexture interfaces. */
1978 if (!(device = create_device(window, DDSCL_NORMAL)))
1980 skip("Failed to create a 3D device, skipping test.\n");
1981 DestroyWindow(window);
1982 return;
1984 IDirect3DDevice_Release(device);
1985 ddraw = create_ddraw();
1986 ok(!!ddraw, "Failed to create a ddraw object.\n");
1987 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
1988 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
1990 memset(&surface_desc, 0, sizeof(surface_desc));
1991 surface_desc.dwSize = sizeof(surface_desc);
1992 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1993 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1994 surface_desc.dwWidth = 512;
1995 surface_desc.dwHeight = 512;
1996 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, (IDirectDrawSurface7 **)0xdeadbeef, NULL);
1997 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1998 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1999 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
2001 test_qi("surface_qi", (IUnknown *)surface, &IID_IDirectDrawSurface7, tests, sizeof(tests) / sizeof(*tests));
2003 IDirectDrawSurface7_Release(surface);
2004 IDirectDraw7_Release(ddraw);
2005 DestroyWindow(window);
2008 static void test_device_qi(void)
2010 static const struct qi_test tests[] =
2012 {&IID_IDirect3DTexture2, NULL, E_NOINTERFACE},
2013 {&IID_IDirect3DTexture, NULL, E_NOINTERFACE},
2014 {&IID_IDirectDrawGammaControl, NULL, E_NOINTERFACE},
2015 {&IID_IDirectDrawColorControl, NULL, E_NOINTERFACE},
2016 {&IID_IDirectDrawSurface7, NULL, E_NOINTERFACE},
2017 {&IID_IDirectDrawSurface4, NULL, E_NOINTERFACE},
2018 {&IID_IDirectDrawSurface3, NULL, E_NOINTERFACE},
2019 {&IID_IDirectDrawSurface2, NULL, E_NOINTERFACE},
2020 {&IID_IDirectDrawSurface, NULL, E_NOINTERFACE},
2021 {&IID_IDirect3DDevice7, &IID_IDirect3DDevice7, S_OK },
2022 {&IID_IDirect3DDevice3, NULL, E_NOINTERFACE},
2023 {&IID_IDirect3DDevice2, NULL, E_NOINTERFACE},
2024 {&IID_IDirect3DDevice, NULL, E_NOINTERFACE},
2025 {&IID_IDirect3DRampDevice, NULL, E_NOINTERFACE},
2026 {&IID_IDirect3DRGBDevice, NULL, E_NOINTERFACE},
2027 {&IID_IDirect3DHALDevice, NULL, E_NOINTERFACE},
2028 {&IID_IDirect3DMMXDevice, NULL, E_NOINTERFACE},
2029 {&IID_IDirect3DRefDevice, NULL, E_NOINTERFACE},
2030 {&IID_IDirect3DTnLHalDevice, NULL, E_NOINTERFACE},
2031 {&IID_IDirect3DNullDevice, NULL, E_NOINTERFACE},
2032 {&IID_IDirect3D7, NULL, E_NOINTERFACE},
2033 {&IID_IDirect3D3, NULL, E_NOINTERFACE},
2034 {&IID_IDirect3D2, NULL, E_NOINTERFACE},
2035 {&IID_IDirect3D, NULL, E_NOINTERFACE},
2036 {&IID_IDirectDraw7, NULL, E_NOINTERFACE},
2037 {&IID_IDirectDraw4, NULL, E_NOINTERFACE},
2038 {&IID_IDirectDraw3, NULL, E_NOINTERFACE},
2039 {&IID_IDirectDraw2, NULL, E_NOINTERFACE},
2040 {&IID_IDirectDraw, NULL, E_NOINTERFACE},
2041 {&IID_IDirect3DLight, NULL, E_NOINTERFACE},
2042 {&IID_IDirect3DMaterial, NULL, E_NOINTERFACE},
2043 {&IID_IDirect3DMaterial2, NULL, E_NOINTERFACE},
2044 {&IID_IDirect3DMaterial3, NULL, E_NOINTERFACE},
2045 {&IID_IDirect3DExecuteBuffer, NULL, E_NOINTERFACE},
2046 {&IID_IDirect3DViewport, NULL, E_NOINTERFACE},
2047 {&IID_IDirect3DViewport2, NULL, E_NOINTERFACE},
2048 {&IID_IDirect3DViewport3, NULL, E_NOINTERFACE},
2049 {&IID_IDirect3DVertexBuffer, NULL, E_NOINTERFACE},
2050 {&IID_IDirect3DVertexBuffer7, NULL, E_NOINTERFACE},
2051 {&IID_IDirectDrawPalette, NULL, E_NOINTERFACE},
2052 {&IID_IDirectDrawClipper, NULL, E_NOINTERFACE},
2053 {&IID_IUnknown, &IID_IDirect3DDevice7, S_OK },
2056 IDirect3DDevice7 *device;
2057 HWND window;
2059 window = create_window();
2060 if (!(device = create_device(window, DDSCL_NORMAL)))
2062 skip("Failed to create a 3D device, skipping test.\n");
2063 DestroyWindow(window);
2064 return;
2067 test_qi("device_qi", (IUnknown *)device, &IID_IDirect3DDevice7, tests, sizeof(tests) / sizeof(*tests));
2069 IDirect3DDevice7_Release(device);
2070 DestroyWindow(window);
2073 static void test_wndproc(void)
2075 LONG_PTR proc, ddraw_proc;
2076 IDirectDraw7 *ddraw;
2077 WNDCLASSA wc = {0};
2078 HWND window;
2079 HRESULT hr;
2080 ULONG ref;
2082 static struct message messages[] =
2084 {WM_WINDOWPOSCHANGING, FALSE, 0},
2085 {WM_MOVE, FALSE, 0},
2086 {WM_SIZE, FALSE, 0},
2087 {WM_WINDOWPOSCHANGING, FALSE, 0},
2088 {WM_ACTIVATE, FALSE, 0},
2089 {WM_SETFOCUS, FALSE, 0},
2090 {0, FALSE, 0},
2093 /* DDSCL_EXCLUSIVE replaces the window's window proc. */
2094 ddraw = create_ddraw();
2095 ok(!!ddraw, "Failed to create a ddraw object.\n");
2097 wc.lpfnWndProc = test_proc;
2098 wc.lpszClassName = "ddraw_test_wndproc_wc";
2099 ok(RegisterClassA(&wc), "Failed to register window class.\n");
2101 window = CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
2102 WS_MAXIMIZE | WS_CAPTION , 0, 0, 640, 480, 0, 0, 0, 0);
2104 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2105 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2106 (LONG_PTR)test_proc, proc);
2107 expect_messages = messages;
2108 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2109 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2110 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2111 expect_messages = NULL;
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 ref = IDirectDraw7_Release(ddraw);
2116 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2117 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2118 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2119 (LONG_PTR)test_proc, proc);
2121 /* DDSCL_NORMAL doesn't. */
2122 ddraw = create_ddraw();
2123 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2124 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2125 (LONG_PTR)test_proc, proc);
2126 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL | DDSCL_FULLSCREEN);
2127 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2128 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2129 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2130 (LONG_PTR)test_proc, proc);
2131 ref = IDirectDraw7_Release(ddraw);
2132 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2133 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2134 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2135 (LONG_PTR)test_proc, proc);
2137 /* The original window proc is only restored by ddraw if the current
2138 * window proc matches the one ddraw set. This also affects switching
2139 * from DDSCL_NORMAL to DDSCL_EXCLUSIVE. */
2140 ddraw = create_ddraw();
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);
2144 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2145 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2146 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2147 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
2148 (LONG_PTR)test_proc, proc);
2149 ddraw_proc = proc;
2150 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2151 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2152 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2153 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2154 (LONG_PTR)test_proc, proc);
2155 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2156 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2157 proc = SetWindowLongPtrA(window, GWLP_WNDPROC, (LONG_PTR)DefWindowProcA);
2158 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
2159 (LONG_PTR)test_proc, proc);
2160 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2161 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2162 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2163 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#lx, got %#lx.\n",
2164 (LONG_PTR)DefWindowProcA, proc);
2165 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2166 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2167 proc = SetWindowLongPtrA(window, GWLP_WNDPROC, (LONG_PTR)ddraw_proc);
2168 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#lx, got %#lx.\n",
2169 (LONG_PTR)DefWindowProcA, proc);
2170 ref = IDirectDraw7_Release(ddraw);
2171 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2172 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2173 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2174 (LONG_PTR)test_proc, proc);
2176 ddraw = create_ddraw();
2177 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2178 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2179 (LONG_PTR)test_proc, proc);
2180 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2181 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2182 proc = SetWindowLongPtrA(window, GWLP_WNDPROC, (LONG_PTR)DefWindowProcA);
2183 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
2184 (LONG_PTR)test_proc, proc);
2185 ref = IDirectDraw7_Release(ddraw);
2186 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2187 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2188 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#lx, got %#lx.\n",
2189 (LONG_PTR)DefWindowProcA, proc);
2191 fix_wndproc(window, (LONG_PTR)test_proc);
2192 expect_messages = NULL;
2193 DestroyWindow(window);
2194 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL));
2197 static void test_window_style(void)
2199 LONG style, exstyle, tmp, expected_style;
2200 RECT fullscreen_rect, r;
2201 IDirectDraw7 *ddraw;
2202 HWND window;
2203 HRESULT hr;
2204 ULONG ref;
2205 BOOL ret;
2207 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
2208 0, 0, 100, 100, 0, 0, 0, 0);
2209 ddraw = create_ddraw();
2210 ok(!!ddraw, "Failed to create a ddraw object.\n");
2212 style = GetWindowLongA(window, GWL_STYLE);
2213 exstyle = GetWindowLongA(window, GWL_EXSTYLE);
2214 SetRect(&fullscreen_rect, 0, 0, registry_mode.dmPelsWidth, registry_mode.dmPelsHeight);
2216 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2217 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2219 tmp = GetWindowLongA(window, GWL_STYLE);
2220 todo_wine ok(tmp == style, "Expected window style %#x, got %#x.\n", style, tmp);
2221 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2222 todo_wine ok(tmp == exstyle, "Expected window extended style %#x, got %#x.\n", exstyle, tmp);
2224 GetWindowRect(window, &r);
2225 ok(EqualRect(&r, &fullscreen_rect), "Expected %s, got %s.\n",
2226 wine_dbgstr_rect(&fullscreen_rect), wine_dbgstr_rect(&r));
2227 GetClientRect(window, &r);
2228 todo_wine ok(!EqualRect(&r, &fullscreen_rect), "Client rect and window rect are equal.\n");
2230 ret = SetForegroundWindow(GetDesktopWindow());
2231 ok(ret, "Failed to set foreground window.\n");
2233 tmp = GetWindowLongA(window, GWL_STYLE);
2234 todo_wine ok(tmp == style, "Expected window style %#x, got %#x.\n", style, tmp);
2235 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2236 todo_wine ok(tmp == exstyle, "Expected window extended style %#x, got %#x.\n", exstyle, tmp);
2238 ret = SetForegroundWindow(window);
2239 ok(ret, "Failed to set foreground window.\n");
2240 /* Windows 7 (but not Vista and XP) shows the window when it receives focus. Hide it again,
2241 * the next tests expect this. */
2242 ShowWindow(window, SW_HIDE);
2244 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2245 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2247 tmp = GetWindowLongA(window, GWL_STYLE);
2248 todo_wine ok(tmp == style, "Expected window style %#x, got %#x.\n", style, tmp);
2249 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2250 todo_wine ok(tmp == exstyle, "Expected window extended style %#x, got %#x.\n", exstyle, tmp);
2252 ShowWindow(window, SW_SHOW);
2253 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2254 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2256 tmp = GetWindowLongA(window, GWL_STYLE);
2257 expected_style = style | WS_VISIBLE;
2258 todo_wine ok(tmp == expected_style, "Expected window style %#x, got %#x.\n", expected_style, tmp);
2259 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2260 expected_style = exstyle | WS_EX_TOPMOST;
2261 todo_wine ok(tmp == expected_style, "Expected window extended style %#x, got %#x.\n", expected_style, tmp);
2263 ret = SetForegroundWindow(GetDesktopWindow());
2264 ok(ret, "Failed to set foreground window.\n");
2265 tmp = GetWindowLongA(window, GWL_STYLE);
2266 expected_style = style | WS_VISIBLE | WS_MINIMIZE;
2267 todo_wine ok(tmp == expected_style, "Expected window style %#x, got %#x.\n", expected_style, tmp);
2268 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2269 expected_style = exstyle | WS_EX_TOPMOST;
2270 todo_wine ok(tmp == expected_style, "Expected window extended style %#x, got %#x.\n", expected_style, tmp);
2272 ref = IDirectDraw7_Release(ddraw);
2273 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2275 DestroyWindow(window);
2278 static void test_redundant_mode_set(void)
2280 DDSURFACEDESC2 surface_desc = {0};
2281 IDirectDraw7 *ddraw;
2282 RECT q, r, s;
2283 HWND window;
2284 HRESULT hr;
2285 ULONG ref;
2287 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
2288 0, 0, 100, 100, 0, 0, 0, 0);
2289 ddraw = create_ddraw();
2290 ok(!!ddraw, "Failed to create a ddraw object.\n");
2291 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2292 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2294 surface_desc.dwSize = sizeof(surface_desc);
2295 hr = IDirectDraw7_GetDisplayMode(ddraw, &surface_desc);
2296 ok(SUCCEEDED(hr), "GetDisplayMode failed, hr %#x.\n", hr);
2298 hr = IDirectDraw7_SetDisplayMode(ddraw, surface_desc.dwWidth, surface_desc.dwHeight,
2299 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount, 0, 0);
2300 ok(SUCCEEDED(hr), "SetDisplayMode failed, hr %#x.\n", hr);
2302 GetWindowRect(window, &q);
2303 r = q;
2304 r.right /= 2;
2305 r.bottom /= 2;
2306 SetWindowPos(window, HWND_TOP, r.left, r.top, r.right, r.bottom, 0);
2307 GetWindowRect(window, &s);
2308 ok(EqualRect(&r, &s), "Expected %s, got %s.\n", wine_dbgstr_rect(&r), wine_dbgstr_rect(&s));
2310 hr = IDirectDraw7_SetDisplayMode(ddraw, surface_desc.dwWidth, surface_desc.dwHeight,
2311 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount, 0, 0);
2312 ok(SUCCEEDED(hr), "SetDisplayMode failed, hr %#x.\n", hr);
2314 GetWindowRect(window, &s);
2315 ok(EqualRect(&r, &s) || broken(EqualRect(&q, &s) /* Windows 10 */),
2316 "Expected %s, got %s.\n", wine_dbgstr_rect(&r), wine_dbgstr_rect(&s));
2318 ref = IDirectDraw7_Release(ddraw);
2319 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2321 DestroyWindow(window);
2324 static SIZE screen_size, screen_size2;
2326 static LRESULT CALLBACK mode_set_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
2328 if (message == WM_SIZE)
2330 screen_size.cx = GetSystemMetrics(SM_CXSCREEN);
2331 screen_size.cy = GetSystemMetrics(SM_CYSCREEN);
2334 return test_proc(hwnd, message, wparam, lparam);
2337 static LRESULT CALLBACK mode_set_proc2(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
2339 if (message == WM_SIZE)
2341 screen_size2.cx = GetSystemMetrics(SM_CXSCREEN);
2342 screen_size2.cy = GetSystemMetrics(SM_CYSCREEN);
2345 return test_proc(hwnd, message, wparam, lparam);
2348 struct test_coop_level_mode_set_enum_param
2350 DWORD ddraw_width, ddraw_height, user32_width, user32_height;
2353 static HRESULT CALLBACK test_coop_level_mode_set_enum_cb(DDSURFACEDESC2 *surface_desc, void *context)
2355 struct test_coop_level_mode_set_enum_param *param = context;
2357 if (U1(U4(*surface_desc).ddpfPixelFormat).dwRGBBitCount != registry_mode.dmBitsPerPel)
2358 return DDENUMRET_OK;
2359 if (surface_desc->dwWidth == registry_mode.dmPelsWidth
2360 && surface_desc->dwHeight == registry_mode.dmPelsHeight)
2361 return DDENUMRET_OK;
2363 if (!param->ddraw_width)
2365 param->ddraw_width = surface_desc->dwWidth;
2366 param->ddraw_height = surface_desc->dwHeight;
2367 return DDENUMRET_OK;
2369 if (surface_desc->dwWidth == param->ddraw_width && surface_desc->dwHeight == param->ddraw_height)
2370 return DDENUMRET_OK;
2372 param->user32_width = surface_desc->dwWidth;
2373 param->user32_height = surface_desc->dwHeight;
2374 return DDENUMRET_CANCEL;
2377 static void test_coop_level_mode_set(void)
2379 IDirectDrawSurface7 *primary;
2380 RECT registry_rect, ddraw_rect, user32_rect, r;
2381 IDirectDraw7 *ddraw;
2382 DDSURFACEDESC2 ddsd;
2383 WNDCLASSA wc = {0};
2384 HWND window, window2;
2385 HRESULT hr;
2386 ULONG ref;
2387 MSG msg;
2388 struct test_coop_level_mode_set_enum_param param;
2389 DEVMODEW devmode;
2390 BOOL ret;
2391 LONG change_ret;
2393 static const struct message exclusive_messages[] =
2395 {WM_WINDOWPOSCHANGING, FALSE, 0},
2396 {WM_WINDOWPOSCHANGED, FALSE, 0},
2397 {WM_SIZE, FALSE, 0},
2398 {WM_DISPLAYCHANGE, FALSE, 0},
2399 {0, FALSE, 0},
2401 static const struct message exclusive_focus_loss_messages[] =
2403 {WM_ACTIVATE, TRUE, WA_INACTIVE},
2404 {WM_DISPLAYCHANGE, FALSE, 0},
2405 {WM_WINDOWPOSCHANGING, FALSE, 0},
2406 /* Like d3d8 and d3d9 ddraw seems to use SW_SHOWMINIMIZED instead of
2407 * SW_MINIMIZED, causing a recursive window activation that does not
2408 * produce the same result in Wine yet. Ignore the difference for now.
2409 * {WM_ACTIVATE, TRUE, 0x200000 | WA_ACTIVE}, */
2410 {WM_WINDOWPOSCHANGED, FALSE, 0},
2411 {WM_MOVE, FALSE, 0},
2412 {WM_SIZE, TRUE, SIZE_MINIMIZED},
2413 {WM_ACTIVATEAPP, TRUE, FALSE},
2414 {0, FALSE, 0},
2416 static const struct message exclusive_focus_restore_messages[] =
2418 {WM_WINDOWPOSCHANGING, FALSE, 0}, /* From the ShowWindow(SW_RESTORE). */
2419 {WM_WINDOWPOSCHANGING, FALSE, 0}, /* Generated by ddraw, matches d3d9 behavior. */
2420 {WM_WINDOWPOSCHANGED, FALSE, 0}, /* Matching previous message. */
2421 {WM_SIZE, FALSE, 0}, /* DefWindowProc. */
2422 {WM_DISPLAYCHANGE, FALSE, 0}, /* Ddraw restores mode. */
2423 /* Native redundantly sets the window size here. */
2424 {WM_ACTIVATEAPP, TRUE, TRUE}, /* End of ddraw's hooks. */
2425 {WM_WINDOWPOSCHANGED, FALSE, 0}, /* Matching the one from ShowWindow. */
2426 {WM_MOVE, FALSE, 0}, /* DefWindowProc. */
2427 {WM_SIZE, TRUE, SIZE_RESTORED}, /* DefWindowProc. */
2428 {0, FALSE, 0},
2430 static const struct message sc_restore_messages[] =
2432 {WM_SYSCOMMAND, TRUE, SC_RESTORE},
2433 {WM_WINDOWPOSCHANGING, FALSE, 0},
2434 {WM_WINDOWPOSCHANGED, FALSE, 0},
2435 {WM_SIZE, TRUE, SIZE_RESTORED},
2436 {0, FALSE, 0},
2438 static const struct message sc_minimize_messages[] =
2440 {WM_SYSCOMMAND, TRUE, SC_MINIMIZE},
2441 {WM_WINDOWPOSCHANGING, FALSE, 0},
2442 {WM_WINDOWPOSCHANGED, FALSE, 0},
2443 {WM_SIZE, TRUE, SIZE_MINIMIZED},
2444 {0, FALSE, 0},
2446 static const struct message sc_maximize_messages[] =
2448 {WM_SYSCOMMAND, TRUE, SC_MAXIMIZE},
2449 {WM_WINDOWPOSCHANGING, FALSE, 0},
2450 {WM_WINDOWPOSCHANGED, FALSE, 0},
2451 {WM_SIZE, TRUE, SIZE_MAXIMIZED},
2452 {0, FALSE, 0},
2455 static const struct message normal_messages[] =
2457 {WM_DISPLAYCHANGE, FALSE, 0},
2458 {0, FALSE, 0},
2461 ddraw = create_ddraw();
2462 ok(!!ddraw, "Failed to create a ddraw object.\n");
2464 memset(&param, 0, sizeof(param));
2465 hr = IDirectDraw7_EnumDisplayModes(ddraw, 0, NULL, &param, test_coop_level_mode_set_enum_cb);
2466 ok(SUCCEEDED(hr), "Failed to enumerate display mode, hr %#x.\n", hr);
2467 ref = IDirectDraw7_Release(ddraw);
2468 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2470 if (!param.user32_height)
2472 skip("Fewer than 3 different modes supported, skipping mode restore test.\n");
2473 return;
2476 SetRect(&registry_rect, 0, 0, registry_mode.dmPelsWidth, registry_mode.dmPelsHeight);
2477 SetRect(&ddraw_rect, 0, 0, param.ddraw_width, param.ddraw_height);
2478 SetRect(&user32_rect, 0, 0, param.user32_width, param.user32_height);
2480 memset(&devmode, 0, sizeof(devmode));
2481 devmode.dmSize = sizeof(devmode);
2482 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
2483 devmode.dmPelsWidth = param.user32_width;
2484 devmode.dmPelsHeight = param.user32_height;
2485 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
2486 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2488 ddraw = create_ddraw();
2489 ok(!!ddraw, "Failed to create a ddraw object.\n");
2491 wc.lpfnWndProc = mode_set_proc;
2492 wc.lpszClassName = "ddraw_test_wndproc_wc";
2493 ok(RegisterClassA(&wc), "Failed to register window class.\n");
2494 wc.lpfnWndProc = mode_set_proc2;
2495 wc.lpszClassName = "ddraw_test_wndproc_wc2";
2496 ok(RegisterClassA(&wc), "Failed to register window class.\n");
2498 window = CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test", WS_OVERLAPPEDWINDOW,
2499 0, 0, 100, 100, 0, 0, 0, 0);
2500 window2 = CreateWindowA("ddraw_test_wndproc_wc2", "ddraw_test", WS_OVERLAPPEDWINDOW,
2501 0, 0, 100, 100, 0, 0, 0, 0);
2503 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2504 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2506 GetWindowRect(window, &r);
2507 ok(EqualRect(&r, &user32_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&user32_rect),
2508 wine_dbgstr_rect(&r));
2510 memset(&ddsd, 0, sizeof(ddsd));
2511 ddsd.dwSize = sizeof(ddsd);
2512 ddsd.dwFlags = DDSD_CAPS;
2513 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2515 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2516 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2517 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2518 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2519 ok(ddsd.dwWidth == param.user32_width, "Expected surface width %u, got %u.\n",
2520 param.user32_width, ddsd.dwWidth);
2521 ok(ddsd.dwHeight == param.user32_height, "Expected surface height %u, got %u.\n",
2522 param.user32_height, ddsd.dwHeight);
2524 GetWindowRect(window, &r);
2525 ok(EqualRect(&r, &user32_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&user32_rect),
2526 wine_dbgstr_rect(&r));
2528 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2529 expect_messages = exclusive_messages;
2530 screen_size.cx = 0;
2531 screen_size.cy = 0;
2533 hr = IDirectDrawSurface7_IsLost(primary);
2534 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
2535 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
2536 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2537 hr = IDirectDrawSurface7_IsLost(primary);
2538 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2540 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2541 expect_messages = NULL;
2542 ok(screen_size.cx == param.ddraw_width && screen_size.cy == param.ddraw_height,
2543 "Expected screen size %ux%u, got %ux%u.\n",
2544 param.ddraw_width, param.ddraw_height, screen_size.cx, screen_size.cy);
2546 GetWindowRect(window, &r);
2547 ok(EqualRect(&r, &ddraw_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect),
2548 wine_dbgstr_rect(&r));
2550 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2551 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2552 ok(ddsd.dwWidth == param.user32_width, "Expected surface width %u, got %u.\n",
2553 param.user32_width, ddsd.dwWidth);
2554 ok(ddsd.dwHeight == param.user32_height, "Expected surface height %u, got %u.\n",
2555 param.user32_height, ddsd.dwHeight);
2556 IDirectDrawSurface7_Release(primary);
2558 memset(&ddsd, 0, sizeof(ddsd));
2559 ddsd.dwSize = sizeof(ddsd);
2560 ddsd.dwFlags = DDSD_CAPS;
2561 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2563 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2564 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2565 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2566 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2567 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2568 param.ddraw_width, ddsd.dwWidth);
2569 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2570 param.ddraw_height, ddsd.dwHeight);
2572 GetWindowRect(window, &r);
2573 ok(EqualRect(&r, &ddraw_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect),
2574 wine_dbgstr_rect(&r));
2576 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2577 expect_messages = exclusive_messages;
2578 screen_size.cx = 0;
2579 screen_size.cy = 0;
2581 hr = IDirectDrawSurface7_IsLost(primary);
2582 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
2583 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
2584 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2585 hr = IDirectDrawSurface7_IsLost(primary);
2586 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2588 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2589 expect_messages = NULL;
2590 ok(screen_size.cx == param.user32_width && screen_size.cy == param.user32_height,
2591 "Expected screen size %ux%u, got %ux%u.\n",
2592 param.user32_width, param.user32_height, screen_size.cx, screen_size.cy);
2594 GetWindowRect(window, &r);
2595 ok(EqualRect(&r, &user32_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&user32_rect),
2596 wine_dbgstr_rect(&r));
2598 expect_messages = exclusive_focus_loss_messages;
2599 ret = SetForegroundWindow(GetDesktopWindow());
2600 ok(ret, "Failed to set foreground window.\n");
2601 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2602 memset(&devmode, 0, sizeof(devmode));
2603 devmode.dmSize = sizeof(devmode);
2604 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
2605 ok(ret, "Failed to get display mode.\n");
2606 ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth
2607 && devmode.dmPelsHeight == registry_mode.dmPelsHeight, "Got unexpect screen size %ux%u.\n",
2608 devmode.dmPelsWidth, devmode.dmPelsHeight);
2610 expect_messages = exclusive_focus_restore_messages;
2611 ShowWindow(window, SW_RESTORE);
2612 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2614 GetWindowRect(window, &r);
2615 ok(EqualRect(&r, &ddraw_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect),
2616 wine_dbgstr_rect(&r));
2617 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
2618 ok(ret, "Failed to get display mode.\n");
2619 ok(devmode.dmPelsWidth == param.ddraw_width
2620 && devmode.dmPelsHeight == param.ddraw_height, "Got unexpect screen size %ux%u.\n",
2621 devmode.dmPelsWidth, devmode.dmPelsHeight);
2623 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2624 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2625 /* Normally the primary should be restored here. Unfortunately this causes the
2626 * GetSurfaceDesc call after the next display mode change to crash on the Windows 8
2627 * testbot. Another Restore call would presumably avoid the crash, but it also moots
2628 * the point of the GetSurfaceDesc call. */
2630 expect_messages = sc_minimize_messages;
2631 SendMessageA(window, WM_SYSCOMMAND, SC_MINIMIZE, 0);
2632 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2633 expect_messages = NULL;
2635 expect_messages = sc_restore_messages;
2636 SendMessageA(window, WM_SYSCOMMAND, SC_RESTORE, 0);
2637 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2638 expect_messages = NULL;
2640 expect_messages = sc_maximize_messages;
2641 SendMessageA(window, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
2642 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2643 expect_messages = NULL;
2645 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2646 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2648 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2649 expect_messages = exclusive_messages;
2650 screen_size.cx = 0;
2651 screen_size.cy = 0;
2653 hr = IDirectDrawSurface7_IsLost(primary);
2654 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2655 hr = IDirectDraw7_RestoreDisplayMode(ddraw);
2656 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
2657 hr = IDirectDrawSurface7_IsLost(primary);
2658 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2660 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2661 expect_messages = NULL;
2662 ok(screen_size.cx == registry_mode.dmPelsWidth
2663 && screen_size.cy == registry_mode.dmPelsHeight,
2664 "Expected screen size %ux%u, got %ux%u.\n",
2665 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight, screen_size.cx, screen_size.cy);
2667 GetWindowRect(window, &r);
2668 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2669 wine_dbgstr_rect(&r));
2671 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2672 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2673 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2674 param.ddraw_width, ddsd.dwWidth);
2675 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2676 param.ddraw_height, ddsd.dwHeight);
2677 IDirectDrawSurface7_Release(primary);
2679 /* For Wine. */
2680 change_ret = ChangeDisplaySettingsW(NULL, CDS_FULLSCREEN);
2681 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2683 memset(&ddsd, 0, sizeof(ddsd));
2684 ddsd.dwSize = sizeof(ddsd);
2685 ddsd.dwFlags = DDSD_CAPS;
2686 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2688 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2689 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2690 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2691 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2692 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2693 registry_mode.dmPelsWidth, ddsd.dwWidth);
2694 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2695 registry_mode.dmPelsHeight, ddsd.dwHeight);
2697 GetWindowRect(window, &r);
2698 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2699 wine_dbgstr_rect(&r));
2701 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2702 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2704 GetWindowRect(window, &r);
2705 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2706 wine_dbgstr_rect(&r));
2708 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2709 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2710 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2711 registry_mode.dmPelsWidth, ddsd.dwWidth);
2712 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2713 registry_mode.dmPelsHeight, ddsd.dwHeight);
2714 IDirectDrawSurface7_Release(primary);
2716 memset(&ddsd, 0, sizeof(ddsd));
2717 ddsd.dwSize = sizeof(ddsd);
2718 ddsd.dwFlags = DDSD_CAPS;
2719 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2721 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2722 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2723 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2724 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2725 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2726 registry_mode.dmPelsWidth, ddsd.dwWidth);
2727 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2728 registry_mode.dmPelsHeight, ddsd.dwHeight);
2730 GetWindowRect(window, &r);
2731 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2732 wine_dbgstr_rect(&r));
2734 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2735 expect_messages = normal_messages;
2736 screen_size.cx = 0;
2737 screen_size.cy = 0;
2739 hr = IDirectDrawSurface7_IsLost(primary);
2740 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
2741 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
2742 devmode.dmPelsWidth = param.user32_width;
2743 devmode.dmPelsHeight = param.user32_height;
2744 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
2745 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2746 hr = IDirectDrawSurface7_IsLost(primary);
2747 todo_wine ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2749 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2750 expect_messages = NULL;
2751 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2753 GetWindowRect(window, &r);
2754 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2755 wine_dbgstr_rect(&r));
2757 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2758 expect_messages = normal_messages;
2759 screen_size.cx = 0;
2760 screen_size.cy = 0;
2762 hr = IDirectDrawSurface7_Restore(primary);
2763 ok(hr == DDERR_WRONGMODE, "Got unexpected hr %#x.\n", hr);
2764 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
2765 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2766 hr = IDirectDrawSurface7_Restore(primary);
2767 ok(hr == DDERR_WRONGMODE, "Got unexpected hr %#x.\n", hr);
2768 hr = IDirectDrawSurface7_IsLost(primary);
2769 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2771 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2772 expect_messages = NULL;
2773 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2775 GetWindowRect(window, &r);
2776 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2777 wine_dbgstr_rect(&r));
2779 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2780 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2781 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2782 registry_mode.dmPelsWidth, ddsd.dwWidth);
2783 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2784 registry_mode.dmPelsHeight, ddsd.dwHeight);
2785 IDirectDrawSurface7_Release(primary);
2787 memset(&ddsd, 0, sizeof(ddsd));
2788 ddsd.dwSize = sizeof(ddsd);
2789 ddsd.dwFlags = DDSD_CAPS;
2790 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2792 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2793 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2794 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2795 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2796 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2797 param.ddraw_width, ddsd.dwWidth);
2798 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2799 param.ddraw_height, ddsd.dwHeight);
2801 GetWindowRect(window, &r);
2802 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2803 wine_dbgstr_rect(&r));
2805 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2806 expect_messages = normal_messages;
2807 screen_size.cx = 0;
2808 screen_size.cy = 0;
2810 hr = IDirectDrawSurface7_IsLost(primary);
2811 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
2812 hr = IDirectDraw7_RestoreDisplayMode(ddraw);
2813 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
2814 hr = IDirectDrawSurface7_IsLost(primary);
2815 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2817 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2818 expect_messages = NULL;
2819 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2821 GetWindowRect(window, &r);
2822 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2823 wine_dbgstr_rect(&r));
2825 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2826 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2827 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2828 param.ddraw_width, ddsd.dwWidth);
2829 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2830 param.ddraw_height, ddsd.dwHeight);
2831 IDirectDrawSurface7_Release(primary);
2833 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
2834 ok(ret, "Failed to get display mode.\n");
2835 ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth
2836 && devmode.dmPelsHeight == registry_mode.dmPelsHeight,
2837 "Expected resolution %ux%u, got %ux%u.\n",
2838 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight,
2839 devmode.dmPelsWidth, devmode.dmPelsHeight);
2840 change_ret = ChangeDisplaySettingsW(NULL, CDS_FULLSCREEN);
2841 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2843 memset(&ddsd, 0, sizeof(ddsd));
2844 ddsd.dwSize = sizeof(ddsd);
2845 ddsd.dwFlags = DDSD_CAPS;
2846 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2848 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2849 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2850 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2851 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2852 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2853 registry_mode.dmPelsWidth, ddsd.dwWidth);
2854 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2855 registry_mode.dmPelsHeight, ddsd.dwHeight);
2857 GetWindowRect(window, &r);
2858 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2859 wine_dbgstr_rect(&r));
2861 /* DDSCL_NORMAL | DDSCL_FULLSCREEN behaves the same as just DDSCL_NORMAL.
2862 * Resizing the window on mode changes is a property of DDSCL_EXCLUSIVE,
2863 * not DDSCL_FULLSCREEN. */
2864 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL | DDSCL_FULLSCREEN);
2865 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2867 GetWindowRect(window, &r);
2868 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2869 wine_dbgstr_rect(&r));
2871 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2872 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2873 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2874 registry_mode.dmPelsWidth, ddsd.dwWidth);
2875 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2876 registry_mode.dmPelsHeight, ddsd.dwHeight);
2877 IDirectDrawSurface7_Release(primary);
2879 memset(&ddsd, 0, sizeof(ddsd));
2880 ddsd.dwSize = sizeof(ddsd);
2881 ddsd.dwFlags = DDSD_CAPS;
2882 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2884 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2885 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2886 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2887 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2888 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2889 registry_mode.dmPelsWidth, ddsd.dwWidth);
2890 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2891 registry_mode.dmPelsHeight, ddsd.dwHeight);
2893 GetWindowRect(window, &r);
2894 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2895 wine_dbgstr_rect(&r));
2897 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2898 expect_messages = normal_messages;
2899 screen_size.cx = 0;
2900 screen_size.cy = 0;
2902 hr = IDirectDrawSurface7_IsLost(primary);
2903 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
2904 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
2905 devmode.dmPelsWidth = param.user32_width;
2906 devmode.dmPelsHeight = param.user32_height;
2907 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
2908 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2909 hr = IDirectDrawSurface7_IsLost(primary);
2910 todo_wine ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2912 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2913 expect_messages = NULL;
2914 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2916 GetWindowRect(window, &r);
2917 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2918 wine_dbgstr_rect(&r));
2920 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2921 expect_messages = normal_messages;
2922 screen_size.cx = 0;
2923 screen_size.cy = 0;
2925 hr = IDirectDrawSurface7_Restore(primary);
2926 ok(hr == DDERR_WRONGMODE, "Got unexpected hr %#x.\n", hr);
2927 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
2928 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2929 hr = IDirectDrawSurface7_Restore(primary);
2930 ok(hr == DDERR_WRONGMODE, "Got unexpected hr %#x.\n", hr);
2931 hr = IDirectDrawSurface7_IsLost(primary);
2932 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2934 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2935 expect_messages = NULL;
2936 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2938 GetWindowRect(window, &r);
2939 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2940 wine_dbgstr_rect(&r));
2942 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2943 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2944 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2945 registry_mode.dmPelsWidth, ddsd.dwWidth);
2946 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2947 registry_mode.dmPelsHeight, ddsd.dwHeight);
2948 IDirectDrawSurface7_Release(primary);
2950 memset(&ddsd, 0, sizeof(ddsd));
2951 ddsd.dwSize = sizeof(ddsd);
2952 ddsd.dwFlags = DDSD_CAPS;
2953 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2955 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2956 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2957 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2958 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2959 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2960 param.ddraw_width, ddsd.dwWidth);
2961 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2962 param.ddraw_height, ddsd.dwHeight);
2964 GetWindowRect(window, &r);
2965 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2966 wine_dbgstr_rect(&r));
2968 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2969 expect_messages = normal_messages;
2970 screen_size.cx = 0;
2971 screen_size.cy = 0;
2973 hr = IDirectDrawSurface7_IsLost(primary);
2974 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
2975 hr = IDirectDraw7_RestoreDisplayMode(ddraw);
2976 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
2977 hr = IDirectDrawSurface7_IsLost(primary);
2978 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2980 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2981 expect_messages = NULL;
2982 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2984 GetWindowRect(window, &r);
2985 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2986 wine_dbgstr_rect(&r));
2988 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2989 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2990 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2991 param.ddraw_width, ddsd.dwWidth);
2992 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2993 param.ddraw_height, ddsd.dwHeight);
2994 IDirectDrawSurface7_Release(primary);
2996 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
2997 ok(ret, "Failed to get display mode.\n");
2998 ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth
2999 && devmode.dmPelsHeight == registry_mode.dmPelsHeight,
3000 "Expected resolution %ux%u, got %ux%u.\n",
3001 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight,
3002 devmode.dmPelsWidth, devmode.dmPelsHeight);
3003 change_ret = ChangeDisplaySettingsW(NULL, CDS_FULLSCREEN);
3004 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
3006 memset(&ddsd, 0, sizeof(ddsd));
3007 ddsd.dwSize = sizeof(ddsd);
3008 ddsd.dwFlags = DDSD_CAPS;
3009 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3011 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
3012 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
3013 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
3014 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
3015 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
3016 registry_mode.dmPelsWidth, ddsd.dwWidth);
3017 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
3018 registry_mode.dmPelsHeight, ddsd.dwHeight);
3019 IDirectDrawSurface7_Release(primary);
3021 GetWindowRect(window, &r);
3022 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
3023 wine_dbgstr_rect(&r));
3025 /* Changing the coop level from EXCLUSIVE to NORMAL restores the screen resolution */
3026 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3027 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3028 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
3029 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3031 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
3032 expect_messages = exclusive_messages;
3033 screen_size.cx = 0;
3034 screen_size.cy = 0;
3036 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
3037 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3039 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
3040 expect_messages = NULL;
3041 ok(screen_size.cx == registry_mode.dmPelsWidth
3042 && screen_size.cy == registry_mode.dmPelsHeight,
3043 "Expected screen size %ux%u, got %ux%u.\n",
3044 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight,
3045 screen_size.cx, screen_size.cy);
3047 GetWindowRect(window, &r);
3048 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
3049 wine_dbgstr_rect(&r));
3051 memset(&ddsd, 0, sizeof(ddsd));
3052 ddsd.dwSize = sizeof(ddsd);
3053 ddsd.dwFlags = DDSD_CAPS;
3054 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3056 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
3057 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
3058 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
3059 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
3060 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
3061 registry_mode.dmPelsWidth, ddsd.dwWidth);
3062 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
3063 registry_mode.dmPelsHeight, ddsd.dwHeight);
3064 IDirectDrawSurface7_Release(primary);
3066 /* The screen restore is a property of DDSCL_EXCLUSIVE */
3067 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL | DDSCL_FULLSCREEN);
3068 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3069 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
3070 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3072 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
3073 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3075 memset(&ddsd, 0, sizeof(ddsd));
3076 ddsd.dwSize = sizeof(ddsd);
3077 ddsd.dwFlags = DDSD_CAPS;
3078 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3080 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
3081 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
3082 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
3083 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
3084 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
3085 param.ddraw_width, ddsd.dwWidth);
3086 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
3087 param.ddraw_height, ddsd.dwHeight);
3088 IDirectDrawSurface7_Release(primary);
3090 hr = IDirectDraw7_RestoreDisplayMode(ddraw);
3091 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
3093 /* If the window is changed at the same time, messages are sent to the new window. */
3094 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3095 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3096 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
3097 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3099 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
3100 expect_messages = exclusive_messages;
3101 screen_size.cx = 0;
3102 screen_size.cy = 0;
3103 screen_size2.cx = 0;
3104 screen_size2.cy = 0;
3106 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window2, DDSCL_NORMAL);
3107 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3109 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
3110 expect_messages = NULL;
3111 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n",
3112 screen_size.cx, screen_size.cy);
3113 ok(screen_size2.cx == registry_mode.dmPelsWidth && screen_size2.cy == registry_mode.dmPelsHeight,
3114 "Expected screen size 2 %ux%u, got %ux%u.\n",
3115 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight, screen_size2.cx, screen_size2.cy);
3117 GetWindowRect(window, &r);
3118 ok(EqualRect(&r, &ddraw_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect),
3119 wine_dbgstr_rect(&r));
3120 GetWindowRect(window2, &r);
3121 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
3122 wine_dbgstr_rect(&r));
3124 memset(&ddsd, 0, sizeof(ddsd));
3125 ddsd.dwSize = sizeof(ddsd);
3126 ddsd.dwFlags = DDSD_CAPS;
3127 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3129 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
3130 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
3131 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
3132 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
3133 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
3134 registry_mode.dmPelsWidth, ddsd.dwWidth);
3135 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
3136 registry_mode.dmPelsHeight, ddsd.dwHeight);
3137 IDirectDrawSurface7_Release(primary);
3139 ref = IDirectDraw7_Release(ddraw);
3140 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3142 GetWindowRect(window, &r);
3143 ok(EqualRect(&r, &ddraw_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect),
3144 wine_dbgstr_rect(&r));
3146 expect_messages = NULL;
3147 DestroyWindow(window);
3148 DestroyWindow(window2);
3149 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL));
3150 UnregisterClassA("ddraw_test_wndproc_wc2", GetModuleHandleA(NULL));
3153 static void test_coop_level_mode_set_multi(void)
3155 IDirectDraw7 *ddraw1, *ddraw2;
3156 UINT w, h;
3157 HWND window;
3158 HRESULT hr;
3159 ULONG ref;
3161 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
3162 0, 0, 100, 100, 0, 0, 0, 0);
3163 ddraw1 = create_ddraw();
3164 ok(!!ddraw1, "Failed to create a ddraw object.\n");
3166 /* With just a single ddraw object, the display mode is restored on
3167 * release. */
3168 hr = set_display_mode(ddraw1, 800, 600);
3169 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3170 w = GetSystemMetrics(SM_CXSCREEN);
3171 ok(w == 800, "Got unexpected screen width %u.\n", w);
3172 h = GetSystemMetrics(SM_CYSCREEN);
3173 ok(h == 600, "Got unexpected screen height %u.\n", h);
3175 ref = IDirectDraw7_Release(ddraw1);
3176 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3177 w = GetSystemMetrics(SM_CXSCREEN);
3178 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3179 h = GetSystemMetrics(SM_CYSCREEN);
3180 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3182 /* When there are multiple ddraw objects, the display mode is restored to
3183 * the initial mode, before the first SetDisplayMode() call. */
3184 ddraw1 = create_ddraw();
3185 hr = set_display_mode(ddraw1, 800, 600);
3186 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3187 w = GetSystemMetrics(SM_CXSCREEN);
3188 ok(w == 800, "Got unexpected screen width %u.\n", w);
3189 h = GetSystemMetrics(SM_CYSCREEN);
3190 ok(h == 600, "Got unexpected screen height %u.\n", h);
3192 ddraw2 = create_ddraw();
3193 hr = set_display_mode(ddraw2, 640, 480);
3194 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3195 w = GetSystemMetrics(SM_CXSCREEN);
3196 ok(w == 640, "Got unexpected screen width %u.\n", w);
3197 h = GetSystemMetrics(SM_CYSCREEN);
3198 ok(h == 480, "Got unexpected screen height %u.\n", h);
3200 ref = IDirectDraw7_Release(ddraw2);
3201 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3202 w = GetSystemMetrics(SM_CXSCREEN);
3203 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3204 h = GetSystemMetrics(SM_CYSCREEN);
3205 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3207 ref = IDirectDraw7_Release(ddraw1);
3208 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3209 w = GetSystemMetrics(SM_CXSCREEN);
3210 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3211 h = GetSystemMetrics(SM_CYSCREEN);
3212 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3214 /* Regardless of release ordering. */
3215 ddraw1 = create_ddraw();
3216 hr = set_display_mode(ddraw1, 800, 600);
3217 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3218 w = GetSystemMetrics(SM_CXSCREEN);
3219 ok(w == 800, "Got unexpected screen width %u.\n", w);
3220 h = GetSystemMetrics(SM_CYSCREEN);
3221 ok(h == 600, "Got unexpected screen height %u.\n", h);
3223 ddraw2 = create_ddraw();
3224 hr = set_display_mode(ddraw2, 640, 480);
3225 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3226 w = GetSystemMetrics(SM_CXSCREEN);
3227 ok(w == 640, "Got unexpected screen width %u.\n", w);
3228 h = GetSystemMetrics(SM_CYSCREEN);
3229 ok(h == 480, "Got unexpected screen height %u.\n", h);
3231 ref = IDirectDraw7_Release(ddraw1);
3232 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3233 w = GetSystemMetrics(SM_CXSCREEN);
3234 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3235 h = GetSystemMetrics(SM_CYSCREEN);
3236 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3238 ref = IDirectDraw7_Release(ddraw2);
3239 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3240 w = GetSystemMetrics(SM_CXSCREEN);
3241 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3242 h = GetSystemMetrics(SM_CYSCREEN);
3243 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3245 /* But only for ddraw objects that called SetDisplayMode(). */
3246 ddraw1 = create_ddraw();
3247 ddraw2 = create_ddraw();
3248 hr = set_display_mode(ddraw2, 640, 480);
3249 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3250 w = GetSystemMetrics(SM_CXSCREEN);
3251 ok(w == 640, "Got unexpected screen width %u.\n", w);
3252 h = GetSystemMetrics(SM_CYSCREEN);
3253 ok(h == 480, "Got unexpected screen height %u.\n", h);
3255 ref = IDirectDraw7_Release(ddraw1);
3256 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3257 w = GetSystemMetrics(SM_CXSCREEN);
3258 ok(w == 640, "Got unexpected screen width %u.\n", w);
3259 h = GetSystemMetrics(SM_CYSCREEN);
3260 ok(h == 480, "Got unexpected screen height %u.\n", h);
3262 ref = IDirectDraw7_Release(ddraw2);
3263 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3264 w = GetSystemMetrics(SM_CXSCREEN);
3265 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3266 h = GetSystemMetrics(SM_CYSCREEN);
3267 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3269 /* If there's a ddraw object that's currently in exclusive mode, it blocks
3270 * restoring the display mode. */
3271 ddraw1 = create_ddraw();
3272 hr = set_display_mode(ddraw1, 800, 600);
3273 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3274 w = GetSystemMetrics(SM_CXSCREEN);
3275 ok(w == 800, "Got unexpected screen width %u.\n", w);
3276 h = GetSystemMetrics(SM_CYSCREEN);
3277 ok(h == 600, "Got unexpected screen height %u.\n", h);
3279 ddraw2 = create_ddraw();
3280 hr = set_display_mode(ddraw2, 640, 480);
3281 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3282 w = GetSystemMetrics(SM_CXSCREEN);
3283 ok(w == 640, "Got unexpected screen width %u.\n", w);
3284 h = GetSystemMetrics(SM_CYSCREEN);
3285 ok(h == 480, "Got unexpected screen height %u.\n", h);
3287 hr = IDirectDraw7_SetCooperativeLevel(ddraw2, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3288 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3290 ref = IDirectDraw7_Release(ddraw1);
3291 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3292 w = GetSystemMetrics(SM_CXSCREEN);
3293 ok(w == 640, "Got unexpected screen width %u.\n", w);
3294 h = GetSystemMetrics(SM_CYSCREEN);
3295 ok(h == 480, "Got unexpected screen height %u.\n", h);
3297 ref = IDirectDraw7_Release(ddraw2);
3298 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3299 w = GetSystemMetrics(SM_CXSCREEN);
3300 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3301 h = GetSystemMetrics(SM_CYSCREEN);
3302 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3304 /* Exclusive mode blocks mode setting on other ddraw objects in general. */
3305 ddraw1 = create_ddraw();
3306 hr = set_display_mode(ddraw1, 800, 600);
3307 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3308 w = GetSystemMetrics(SM_CXSCREEN);
3309 ok(w == 800, "Got unexpected screen width %u.\n", w);
3310 h = GetSystemMetrics(SM_CYSCREEN);
3311 ok(h == 600, "Got unexpected screen height %u.\n", h);
3313 hr = IDirectDraw7_SetCooperativeLevel(ddraw1, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3314 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3316 ddraw2 = create_ddraw();
3317 hr = set_display_mode(ddraw2, 640, 480);
3318 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
3320 ref = IDirectDraw7_Release(ddraw1);
3321 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3322 w = GetSystemMetrics(SM_CXSCREEN);
3323 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3324 h = GetSystemMetrics(SM_CYSCREEN);
3325 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3327 ref = IDirectDraw7_Release(ddraw2);
3328 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3329 w = GetSystemMetrics(SM_CXSCREEN);
3330 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3331 h = GetSystemMetrics(SM_CYSCREEN);
3332 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3334 DestroyWindow(window);
3337 static void test_initialize(void)
3339 IDirectDraw7 *ddraw;
3340 HRESULT hr;
3342 ddraw = create_ddraw();
3343 ok(!!ddraw, "Failed to create a ddraw object.\n");
3345 hr = IDirectDraw7_Initialize(ddraw, NULL);
3346 ok(hr == DDERR_ALREADYINITIALIZED, "Initialize returned hr %#x.\n", hr);
3347 IDirectDraw7_Release(ddraw);
3349 CoInitialize(NULL);
3350 hr = CoCreateInstance(&CLSID_DirectDraw, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectDraw7, (void **)&ddraw);
3351 ok(SUCCEEDED(hr), "Failed to create IDirectDraw7 instance, hr %#x.\n", hr);
3352 hr = IDirectDraw7_Initialize(ddraw, NULL);
3353 ok(hr == DD_OK, "Initialize returned hr %#x, expected DD_OK.\n", hr);
3354 hr = IDirectDraw7_Initialize(ddraw, NULL);
3355 ok(hr == DDERR_ALREADYINITIALIZED, "Initialize returned hr %#x, expected DDERR_ALREADYINITIALIZED.\n", hr);
3356 IDirectDraw7_Release(ddraw);
3357 CoUninitialize();
3360 static void test_coop_level_surf_create(void)
3362 IDirectDrawSurface7 *surface;
3363 IDirectDraw7 *ddraw;
3364 DDSURFACEDESC2 ddsd;
3365 HRESULT hr;
3367 ddraw = create_ddraw();
3368 ok(!!ddraw, "Failed to create a ddraw object.\n");
3370 memset(&ddsd, 0, sizeof(ddsd));
3371 ddsd.dwSize = sizeof(ddsd);
3372 ddsd.dwFlags = DDSD_CAPS;
3373 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3374 surface = (void *)0xdeadbeef;
3375 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
3376 ok(hr == DDERR_NOCOOPERATIVELEVELSET, "Surface creation returned hr %#x.\n", hr);
3377 ok(surface == (void *)0xdeadbeef, "Got unexpected surface %p.\n", surface);
3379 IDirectDraw7_Release(ddraw);
3382 static void test_vb_discard(void)
3384 static const struct vec4 quad[] =
3386 { 0.0f, 480.0f, 0.0f, 1.0f},
3387 { 0.0f, 0.0f, 0.0f, 1.0f},
3388 {640.0f, 480.0f, 0.0f, 1.0f},
3389 {640.0f, 0.0f, 0.0f, 1.0f},
3392 IDirect3DDevice7 *device;
3393 IDirect3D7 *d3d;
3394 IDirect3DVertexBuffer7 *buffer;
3395 HWND window;
3396 HRESULT hr;
3397 D3DVERTEXBUFFERDESC desc;
3398 BYTE *data;
3399 static const unsigned int vbsize = 16;
3400 unsigned int i;
3402 window = create_window();
3403 if (!(device = create_device(window, DDSCL_NORMAL)))
3405 skip("Failed to create a 3D device, skipping test.\n");
3406 DestroyWindow(window);
3407 return;
3410 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
3411 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
3413 memset(&desc, 0, sizeof(desc));
3414 desc.dwSize = sizeof(desc);
3415 desc.dwCaps = D3DVBCAPS_WRITEONLY;
3416 desc.dwFVF = D3DFVF_XYZRHW;
3417 desc.dwNumVertices = vbsize;
3418 hr = IDirect3D7_CreateVertexBuffer(d3d, &desc, &buffer, 0);
3419 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
3421 hr = IDirect3DVertexBuffer7_Lock(buffer, DDLOCK_DISCARDCONTENTS, (void **)&data, NULL);
3422 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
3423 memcpy(data, quad, sizeof(quad));
3424 hr = IDirect3DVertexBuffer7_Unlock(buffer);
3425 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
3427 hr = IDirect3DDevice7_BeginScene(device);
3428 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
3429 hr = IDirect3DDevice7_DrawPrimitiveVB(device, D3DPT_TRIANGLESTRIP, buffer, 0, 4, 0);
3430 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3431 hr = IDirect3DDevice7_EndScene(device);
3432 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
3434 hr = IDirect3DVertexBuffer7_Lock(buffer, DDLOCK_DISCARDCONTENTS, (void **)&data, NULL);
3435 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
3436 memset(data, 0xaa, sizeof(struct vec4) * vbsize);
3437 hr = IDirect3DVertexBuffer7_Unlock(buffer);
3438 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
3440 hr = IDirect3DVertexBuffer7_Lock(buffer, DDLOCK_DISCARDCONTENTS, (void **)&data, NULL);
3441 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
3442 for (i = 0; i < sizeof(struct vec4) * vbsize; i++)
3444 if (data[i] != 0xaa)
3446 ok(FALSE, "Vertex buffer data byte %u is 0x%02x, expected 0xaa\n", i, data[i]);
3447 break;
3450 hr = IDirect3DVertexBuffer7_Unlock(buffer);
3451 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
3453 IDirect3DVertexBuffer7_Release(buffer);
3454 IDirect3D7_Release(d3d);
3455 IDirect3DDevice7_Release(device);
3456 DestroyWindow(window);
3459 static void test_coop_level_multi_window(void)
3461 HWND window1, window2;
3462 IDirectDraw7 *ddraw;
3463 HRESULT hr;
3465 window1 = create_window();
3466 window2 = create_window();
3467 ddraw = create_ddraw();
3468 ok(!!ddraw, "Failed to create a ddraw object.\n");
3470 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window1, DDSCL_NORMAL);
3471 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3472 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window2, DDSCL_NORMAL);
3473 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3474 ok(IsWindow(window1), "Window 1 was destroyed.\n");
3475 ok(IsWindow(window2), "Window 2 was destroyed.\n");
3477 IDirectDraw7_Release(ddraw);
3478 DestroyWindow(window2);
3479 DestroyWindow(window1);
3482 static void test_draw_strided(void)
3484 static struct vec3 position[] =
3486 {-1.0, -1.0, 0.0},
3487 {-1.0, 1.0, 0.0},
3488 { 1.0, 1.0, 0.0},
3489 { 1.0, -1.0, 0.0},
3491 static DWORD diffuse[] =
3493 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00,
3495 static WORD indices[] =
3497 0, 1, 2, 2, 3, 0
3500 IDirectDrawSurface7 *rt;
3501 IDirect3DDevice7 *device;
3502 D3DCOLOR color;
3503 HWND window;
3504 HRESULT hr;
3505 D3DDRAWPRIMITIVESTRIDEDDATA strided;
3507 window = create_window();
3508 if (!(device = create_device(window, DDSCL_NORMAL)))
3510 skip("Failed to create a 3D device, skipping test.\n");
3511 DestroyWindow(window);
3512 return;
3515 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
3516 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
3518 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
3519 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
3520 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00000000, 1.0f, 0);
3521 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
3522 hr = IDirect3DDevice7_BeginScene(device);
3523 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
3525 memset(&strided, 0x55, sizeof(strided));
3526 strided.position.lpvData = position;
3527 strided.position.dwStride = sizeof(*position);
3528 strided.diffuse.lpvData = diffuse;
3529 strided.diffuse.dwStride = sizeof(*diffuse);
3530 hr = IDirect3DDevice7_DrawIndexedPrimitiveStrided(device, D3DPT_TRIANGLELIST, D3DFVF_XYZ | D3DFVF_DIFFUSE,
3531 &strided, 4, indices, 6, 0);
3532 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3534 hr = IDirect3DDevice7_EndScene(device);
3535 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
3537 color = get_surface_color(rt, 320, 240);
3538 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
3540 IDirectDrawSurface7_Release(rt);
3541 IDirect3DDevice7_Release(device);
3542 DestroyWindow(window);
3545 static void test_lighting(void)
3547 static D3DMATRIX mat =
3549 1.0f, 0.0f, 0.0f, 0.0f,
3550 0.0f, 1.0f, 0.0f, 0.0f,
3551 0.0f, 0.0f, 1.0f, 0.0f,
3552 0.0f, 0.0f, 0.0f, 1.0f,
3554 mat_singular =
3556 1.0f, 0.0f, 1.0f, 0.0f,
3557 0.0f, 1.0f, 0.0f, 0.0f,
3558 1.0f, 0.0f, 1.0f, 0.0f,
3559 0.0f, 0.0f, 0.5f, 1.0f,
3561 mat_transf =
3563 0.0f, 0.0f, 1.0f, 0.0f,
3564 0.0f, 1.0f, 0.0f, 0.0f,
3565 -1.0f, 0.0f, 0.0f, 0.0f,
3566 10.f, 10.0f, 10.0f, 1.0f,
3568 mat_nonaffine =
3570 1.0f, 0.0f, 0.0f, 0.0f,
3571 0.0f, 1.0f, 0.0f, 0.0f,
3572 0.0f, 0.0f, 1.0f, -1.0f,
3573 10.f, 10.0f, 10.0f, 0.0f,
3575 static struct
3577 struct vec3 position;
3578 DWORD diffuse;
3580 unlitquad[] =
3582 {{-1.0f, -1.0f, 0.1f}, 0xffff0000},
3583 {{-1.0f, 0.0f, 0.1f}, 0xffff0000},
3584 {{ 0.0f, 0.0f, 0.1f}, 0xffff0000},
3585 {{ 0.0f, -1.0f, 0.1f}, 0xffff0000},
3587 litquad[] =
3589 {{-1.0f, 0.0f, 0.1f}, 0xff00ff00},
3590 {{-1.0f, 1.0f, 0.1f}, 0xff00ff00},
3591 {{ 0.0f, 1.0f, 0.1f}, 0xff00ff00},
3592 {{ 0.0f, 0.0f, 0.1f}, 0xff00ff00},
3594 static struct
3596 struct vec3 position;
3597 struct vec3 normal;
3598 DWORD diffuse;
3600 unlitnquad[] =
3602 {{0.0f, -1.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xff0000ff},
3603 {{0.0f, 0.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xff0000ff},
3604 {{1.0f, 0.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xff0000ff},
3605 {{1.0f, -1.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xff0000ff},
3607 litnquad[] =
3609 {{0.0f, 0.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xffffff00},
3610 {{0.0f, 1.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xffffff00},
3611 {{1.0f, 1.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xffffff00},
3612 {{1.0f, 0.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xffffff00},
3614 nquad[] =
3616 {{-1.0f, -1.0f, 0.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
3617 {{-1.0f, 1.0f, 0.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
3618 {{ 1.0f, 1.0f, 0.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
3619 {{ 1.0f, -1.0f, 0.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
3621 rotatedquad[] =
3623 {{-10.0f, -11.0f, 11.0f}, {-1.0f, 0.0f, 0.0f}, 0xff0000ff},
3624 {{-10.0f, -9.0f, 11.0f}, {-1.0f, 0.0f, 0.0f}, 0xff0000ff},
3625 {{-10.0f, -9.0f, 9.0f}, {-1.0f, 0.0f, 0.0f}, 0xff0000ff},
3626 {{-10.0f, -11.0f, 9.0f}, {-1.0f, 0.0f, 0.0f}, 0xff0000ff},
3628 translatedquad[] =
3630 {{-11.0f, -11.0f, -10.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
3631 {{-11.0f, -9.0f, -10.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
3632 {{ -9.0f, -9.0f, -10.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
3633 {{ -9.0f, -11.0f, -10.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
3635 static WORD indices[] = {0, 1, 2, 2, 3, 0};
3636 static const struct
3638 D3DMATRIX *world_matrix;
3639 void *quad;
3640 DWORD expected;
3641 const char *message;
3643 tests[] =
3645 {&mat, nquad, 0x000000ff, "Lit quad with light"},
3646 {&mat_singular, nquad, 0x000000ff, "Lit quad with singular world matrix"},
3647 {&mat_transf, rotatedquad, 0x000000ff, "Lit quad with transformation matrix"},
3648 {&mat_nonaffine, translatedquad, 0x00000000, "Lit quad with non-affine matrix"},
3651 HWND window;
3652 IDirect3DDevice7 *device;
3653 IDirectDrawSurface7 *rt;
3654 HRESULT hr;
3655 DWORD fvf = D3DFVF_XYZ | D3DFVF_DIFFUSE;
3656 DWORD nfvf = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_NORMAL;
3657 D3DCOLOR color;
3658 ULONG refcount;
3659 unsigned int i;
3661 window = create_window();
3662 if (!(device = create_device(window, DDSCL_NORMAL)))
3664 skip("Failed to create a 3D device, skipping test.\n");
3665 DestroyWindow(window);
3666 return;
3669 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
3670 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
3672 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
3673 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
3675 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &mat);
3676 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#x.\n", hr);
3677 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_VIEW, &mat);
3678 ok(SUCCEEDED(hr), "Failed to set view transform, hr %#x.\n", hr);
3679 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &mat);
3680 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
3681 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CLIPPING, FALSE);
3682 ok(SUCCEEDED(hr), "Failed to disable clipping, hr %#x.\n", hr);
3683 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, FALSE);
3684 ok(SUCCEEDED(hr), "Failed to disable z-buffering, hr %#x.\n", hr);
3685 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, FALSE);
3686 ok(SUCCEEDED(hr), "Failed to disable fog, hr %#x.\n", hr);
3687 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_STENCILENABLE, FALSE);
3688 ok(SUCCEEDED(hr), "Failed to disable stencil buffering, hr %#x.\n", hr);
3689 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CULLMODE, D3DCULL_NONE);
3690 ok(SUCCEEDED(hr), "Failed to disable culling, hr %#x.\n", hr);
3692 hr = IDirect3DDevice7_BeginScene(device);
3693 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
3695 /* No lights are defined... That means, lit vertices should be entirely black. */
3696 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
3697 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
3698 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, fvf, unlitquad, 4,
3699 indices, 6, 0);
3700 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3702 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, TRUE);
3703 ok(SUCCEEDED(hr), "Failed to enable lighting, hr %#x.\n", hr);
3704 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, fvf, litquad, 4,
3705 indices, 6, 0);
3706 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3708 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
3709 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
3710 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, nfvf, unlitnquad, 4,
3711 indices, 6, 0);
3712 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3714 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, TRUE);
3715 ok(SUCCEEDED(hr), "Failed to enable lighting, hr %#x.\n", hr);
3716 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, nfvf, litnquad, 4,
3717 indices, 6, 0);
3718 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3720 hr = IDirect3DDevice7_EndScene(device);
3721 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
3723 color = get_surface_color(rt, 160, 360);
3724 ok(color == 0x00ff0000, "Unlit quad without normals has color 0x%08x, expected 0x00ff0000.\n", color);
3725 color = get_surface_color(rt, 160, 120);
3726 ok(color == 0x00000000, "Lit quad without normals has color 0x%08x, expected 0x00000000.\n", color);
3727 color = get_surface_color(rt, 480, 360);
3728 ok(color == 0x000000ff, "Unlit quad with normals has color 0x%08x, expected 0x000000ff.\n", color);
3729 color = get_surface_color(rt, 480, 120);
3730 ok(color == 0x00000000, "Lit quad with normals has color 0x%08x, expected 0x00000000.\n", color);
3732 hr = IDirect3DDevice7_LightEnable(device, 0, TRUE);
3733 ok(SUCCEEDED(hr), "Failed to enable light 0, hr %#x.\n", hr);
3735 for (i = 0; i < sizeof(tests) / sizeof(tests[0]); ++i)
3737 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_WORLD, tests[i].world_matrix);
3738 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#x.\n", hr);
3740 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
3741 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
3743 hr = IDirect3DDevice7_BeginScene(device);
3744 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
3746 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, nfvf, tests[i].quad,
3747 4, indices, 6, 0);
3748 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3750 hr = IDirect3DDevice7_EndScene(device);
3751 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
3753 color = get_surface_color(rt, 320, 240);
3754 ok(color == tests[i].expected, "%s has color 0x%08x.\n", tests[i].message, color);
3757 IDirectDrawSurface7_Release(rt);
3759 refcount = IDirect3DDevice7_Release(device);
3760 ok(!refcount, "Device has %u references left.\n", refcount);
3761 DestroyWindow(window);
3764 static void test_specular_lighting(void)
3766 static const unsigned int vertices_side = 5;
3767 const unsigned int indices_count = (vertices_side - 1) * (vertices_side - 1) * 2 * 3;
3768 static const DWORD fvf = D3DFVF_XYZ | D3DFVF_NORMAL;
3769 static D3DMATRIX mat =
3771 1.0f, 0.0f, 0.0f, 0.0f,
3772 0.0f, 1.0f, 0.0f, 0.0f,
3773 0.0f, 0.0f, 1.0f, 0.0f,
3774 0.0f, 0.0f, 0.0f, 1.0f,
3776 static D3DLIGHT7 directional =
3778 D3DLIGHT_DIRECTIONAL,
3779 {{0.0f}, {0.0f}, {0.0f}, {0.0f}},
3780 {{1.0f}, {1.0f}, {1.0f}, {0.0f}},
3781 {{0.0f}, {0.0f}, {0.0f}, {0.0f}},
3782 {{0.0f}, {0.0f}, {0.0f}},
3783 {{0.0f}, {0.0f}, {1.0f}},
3785 point =
3787 D3DLIGHT_POINT,
3788 {{0.0f}, {0.0f}, {0.0f}, {0.0f}},
3789 {{1.0f}, {1.0f}, {1.0f}, {0.0f}},
3790 {{0.0f}, {0.0f}, {0.0f}, {0.0f}},
3791 {{0.0f}, {0.0f}, {0.0f}},
3792 {{0.0f}, {0.0f}, {0.0f}},
3793 100.0f,
3794 0.0f,
3795 0.0f, 0.0f, 1.0f,
3797 spot =
3799 D3DLIGHT_SPOT,
3800 {{0.0f}, {0.0f}, {0.0f}, {0.0f}},
3801 {{1.0f}, {1.0f}, {1.0f}, {0.0f}},
3802 {{0.0f}, {0.0f}, {0.0f}, {0.0f}},
3803 {{0.0f}, {0.0f}, {0.0f}},
3804 {{0.0f}, {0.0f}, {1.0f}},
3805 100.0f,
3806 1.0f,
3807 0.0f, 0.0f, 1.0f,
3808 M_PI / 12.0f, M_PI / 3.0f
3810 /* The chosen range value makes the test fail when using a manhattan
3811 * distance metric vs the correct euclidean distance. */
3812 point_range =
3814 D3DLIGHT_POINT,
3815 {{0.0f}, {0.0f}, {0.0f}, {0.0f}},
3816 {{1.0f}, {1.0f}, {1.0f}, {0.0f}},
3817 {{0.0f}, {0.0f}, {0.0f}, {0.0f}},
3818 {{0.0f}, {0.0f}, {0.0f}},
3819 {{0.0f}, {0.0f}, {0.0f}},
3820 1.2f,
3821 0.0f,
3822 0.0f, 0.0f, 1.0f,
3824 point_side =
3826 D3DLIGHT_POINT,
3827 {{0.0f}, {0.0f}, {0.0f}, {0.0f}},
3828 {{1.0f}, {1.0f}, {1.0f}, {0.0f}},
3829 {{0.0f}, {0.0f}, {0.0f}, {0.0f}},
3830 {{-1.1f}, {0.0f}, {1.1f}},
3831 {{0.0f}, {0.0f}, {0.0f}},
3832 100.0f,
3833 0.0f,
3834 1.0f, 0.0f, 0.0f,
3836 static const struct expected_color
3838 unsigned int x, y;
3839 D3DCOLOR color;
3841 expected_directional[] =
3843 {160, 120, 0x00ffffff},
3844 {320, 120, 0x00ffffff},
3845 {480, 120, 0x00ffffff},
3846 {160, 240, 0x00ffffff},
3847 {320, 240, 0x00ffffff},
3848 {480, 240, 0x00ffffff},
3849 {160, 360, 0x00ffffff},
3850 {320, 360, 0x00ffffff},
3851 {480, 360, 0x00ffffff},
3853 expected_directional_local[] =
3855 {160, 120, 0x003c3c3c},
3856 {320, 120, 0x00717171},
3857 {480, 120, 0x003c3c3c},
3858 {160, 240, 0x00717171},
3859 {320, 240, 0x00ffffff},
3860 {480, 240, 0x00717171},
3861 {160, 360, 0x003c3c3c},
3862 {320, 360, 0x00717171},
3863 {480, 360, 0x003c3c3c},
3865 expected_point[] =
3867 {160, 120, 0x00282828},
3868 {320, 120, 0x005a5a5a},
3869 {480, 120, 0x00282828},
3870 {160, 240, 0x005a5a5a},
3871 {320, 240, 0x00ffffff},
3872 {480, 240, 0x005a5a5a},
3873 {160, 360, 0x00282828},
3874 {320, 360, 0x005a5a5a},
3875 {480, 360, 0x00282828},
3877 expected_point_local[] =
3879 {160, 120, 0x00000000},
3880 {320, 120, 0x00070707},
3881 {480, 120, 0x00000000},
3882 {160, 240, 0x00070707},
3883 {320, 240, 0x00ffffff},
3884 {480, 240, 0x00070707},
3885 {160, 360, 0x00000000},
3886 {320, 360, 0x00070707},
3887 {480, 360, 0x00000000},
3889 expected_spot[] =
3891 {160, 120, 0x00000000},
3892 {320, 120, 0x00141414},
3893 {480, 120, 0x00000000},
3894 {160, 240, 0x00141414},
3895 {320, 240, 0x00ffffff},
3896 {480, 240, 0x00141414},
3897 {160, 360, 0x00000000},
3898 {320, 360, 0x00141414},
3899 {480, 360, 0x00000000},
3901 expected_spot_local[] =
3903 {160, 120, 0x00000000},
3904 {320, 120, 0x00020202},
3905 {480, 120, 0x00000000},
3906 {160, 240, 0x00020202},
3907 {320, 240, 0x00ffffff},
3908 {480, 240, 0x00020202},
3909 {160, 360, 0x00000000},
3910 {320, 360, 0x00020202},
3911 {480, 360, 0x00000000},
3913 expected_point_range[] =
3915 {160, 120, 0x00000000},
3916 {320, 120, 0x005a5a5a},
3917 {480, 120, 0x00000000},
3918 {160, 240, 0x005a5a5a},
3919 {320, 240, 0x00ffffff},
3920 {480, 240, 0x005a5a5a},
3921 {160, 360, 0x00000000},
3922 {320, 360, 0x005a5a5a},
3923 {480, 360, 0x00000000},
3925 expected_point_side[] =
3927 {160, 120, 0x00000000},
3928 {320, 120, 0x00000000},
3929 {480, 120, 0x00000000},
3930 {160, 240, 0x00000000},
3931 {320, 240, 0x00000000},
3932 {480, 240, 0x00000000},
3933 {160, 360, 0x00000000},
3934 {320, 360, 0x00000000},
3935 {480, 360, 0x00000000},
3937 static const struct
3939 D3DLIGHT7 *light;
3940 BOOL local_viewer;
3941 float specular_power;
3942 const struct expected_color *expected;
3943 unsigned int expected_count;
3945 tests[] =
3947 {&directional, FALSE, 30.0f, expected_directional,
3948 sizeof(expected_directional) / sizeof(expected_directional[0])},
3949 {&directional, TRUE, 30.0f, expected_directional_local,
3950 sizeof(expected_directional_local) / sizeof(expected_directional_local[0])},
3951 {&point, FALSE, 30.0f, expected_point,
3952 sizeof(expected_point) / sizeof(expected_point[0])},
3953 {&point, TRUE, 30.0f, expected_point_local,
3954 sizeof(expected_point_local) / sizeof(expected_point_local[0])},
3955 {&spot, FALSE, 30.0f, expected_spot,
3956 sizeof(expected_spot) / sizeof(expected_spot[0])},
3957 {&spot, TRUE, 30.0f, expected_spot_local,
3958 sizeof(expected_spot_local) / sizeof(expected_spot_local[0])},
3959 {&point_range, FALSE, 30.0f, expected_point_range,
3960 sizeof(expected_point_range) / sizeof(expected_point_range[0])},
3961 {&point_side, TRUE, 0.0f, expected_point_side,
3962 sizeof(expected_point_side) / sizeof(expected_point_side[0])},
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 < sizeof(tests) / sizeof(tests[0]); ++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 < sizeof(tests) / sizeof(*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 < sizeof(tests) / sizeof(*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 < sizeof(tests) / sizeof(*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 < sizeof(formats) / sizeof(*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 < sizeof(formats) / sizeof(*formats); i++)
4974 for (j = 0; j < sizeof(types) / sizeof(*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 < sizeof(user_mem_tests) / sizeof(*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 < sizeof(formats) / sizeof(*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 < sizeof(caps) / sizeof(*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 < sizeof(test_data) / sizeof(*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 < sizeof(test_data) / sizeof(*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 < sizeof(tests) / sizeof(*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 < sizeof(tests) / sizeof(*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 < sizeof(test_data) / sizeof(*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 DDSD_LINEARSIZE is moot. */
6584 for (i = 0; i < sizeof(invalid_caps_tests) / sizeof(*invalid_caps_tests); i++)
6586 reset_ddsd(&ddsd);
6587 ddsd.dwFlags = DDSD_CAPS;
6588 ddsd.ddsCaps.dwCaps = invalid_caps_tests[i].caps;
6589 ddsd.ddsCaps.dwCaps2 = invalid_caps_tests[i].caps2;
6590 if (!(invalid_caps_tests[i].caps & DDSCAPS_PRIMARYSURFACE))
6592 ddsd.dwFlags |= DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
6593 ddsd.dwWidth = 8;
6594 ddsd.dwHeight = 8;
6595 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
6596 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
6597 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
6598 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
6599 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
6600 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000ff;
6603 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
6604 if (is_ddraw64 && (invalid_caps_tests[i].caps & DDSCAPS_TEXTURE))
6605 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Got unexpected hr %#x.\n", i, hr);
6606 else
6607 ok(hr == DD_OK || hr == DDERR_NODIRECTDRAWHW, "Test %u: Got unexpected hr %#x.\n", i, hr);
6608 if (FAILED(hr))
6609 continue;
6611 reset_ddsd(&ddsd);
6612 ddsd.dwFlags = DDSD_LPSURFACE;
6613 ddsd.lpSurface = data;
6614 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6615 if (invalid_caps_tests[i].supported)
6617 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
6619 else
6621 ok(hr == DDERR_INVALIDSURFACETYPE, "SetSurfaceDesc on a %s surface returned %#x.\n",
6622 invalid_caps_tests[i].name, hr);
6624 /* Check priority of error conditions. */
6625 ddsd.dwFlags = DDSD_WIDTH;
6626 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6627 ok(hr == DDERR_INVALIDSURFACETYPE, "SetSurfaceDesc on a %s surface returned %#x.\n",
6628 invalid_caps_tests[i].name, hr);
6631 IDirectDrawSurface7_Release(surface);
6634 ref = IDirectDraw7_Release(ddraw);
6635 ok(ref == 0, "Ddraw object not properly released, refcount %u.\n", ref);
6636 DestroyWindow(window);
6639 static void test_user_memory_getdc(void)
6641 IDirectDraw7 *ddraw;
6642 HWND window;
6643 HRESULT hr;
6644 DDSURFACEDESC2 ddsd;
6645 IDirectDrawSurface7 *surface;
6646 DWORD data[16][16];
6647 HGDIOBJ *bitmap;
6648 DIBSECTION dib;
6649 ULONG ref;
6650 int size;
6651 HDC dc;
6652 unsigned int x, y;
6654 window = create_window();
6655 ddraw = create_ddraw();
6656 ok(!!ddraw, "Failed to create a ddraw object.\n");
6657 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6658 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6660 reset_ddsd(&ddsd);
6661 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_PIXELFORMAT;
6662 ddsd.dwWidth = 16;
6663 ddsd.dwHeight = 16;
6664 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
6665 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
6666 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
6667 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
6668 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
6669 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000ff;
6670 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
6671 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
6672 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6674 memset(data, 0xaa, sizeof(data));
6675 reset_ddsd(&ddsd);
6676 ddsd.dwFlags = DDSD_LPSURFACE;
6677 ddsd.lpSurface = data;
6678 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6679 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
6681 hr = IDirectDrawSurface7_GetDC(surface, &dc);
6682 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
6683 bitmap = GetCurrentObject(dc, OBJ_BITMAP);
6684 ok(!!bitmap, "Failed to get bitmap.\n");
6685 size = GetObjectA(bitmap, sizeof(dib), &dib);
6686 ok(size == sizeof(dib), "Got unexpected size %d.\n", size);
6687 ok(dib.dsBm.bmBits == data, "Got unexpected bits %p, expected %p.\n", dib.dsBm.bmBits, data);
6688 BitBlt(dc, 0, 0, 16, 8, NULL, 0, 0, WHITENESS);
6689 BitBlt(dc, 0, 8, 16, 8, NULL, 0, 0, BLACKNESS);
6690 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
6691 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
6693 ok(data[0][0] == 0xffffffff, "Expected color 0xffffffff, got %#x.\n", data[0][0]);
6694 ok(data[15][15] == 0x00000000, "Expected color 0x00000000, got %#x.\n", data[15][15]);
6696 ddsd.dwFlags = DDSD_LPSURFACE | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PITCH;
6697 ddsd.lpSurface = data;
6698 ddsd.dwWidth = 4;
6699 ddsd.dwHeight = 8;
6700 U1(ddsd).lPitch = sizeof(*data);
6701 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6702 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
6704 memset(data, 0xaa, sizeof(data));
6705 hr = IDirectDrawSurface7_GetDC(surface, &dc);
6706 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
6707 BitBlt(dc, 0, 0, 4, 8, NULL, 0, 0, BLACKNESS);
6708 BitBlt(dc, 1, 1, 2, 2, NULL, 0, 0, WHITENESS);
6709 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
6710 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
6712 for (y = 0; y < 4; y++)
6714 for (x = 0; x < 4; x++)
6716 if ((x == 1 || x == 2) && (y == 1 || y == 2))
6717 ok(data[y][x] == 0xffffffff, "Expected color 0xffffffff on position %ux%u, got %#x.\n",
6718 x, y, data[y][x]);
6719 else
6720 ok(data[y][x] == 0x00000000, "Expected color 0x00000000 on position %ux%u, got %#x.\n",
6721 x, y, data[y][x]);
6724 ok(data[0][5] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 5x0, got %#x.\n",
6725 data[0][5]);
6726 ok(data[7][3] == 0x00000000, "Expected color 0x00000000 on position 3x7, got %#x.\n",
6727 data[7][3]);
6728 ok(data[7][4] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 4x7, got %#x.\n",
6729 data[7][4]);
6730 ok(data[8][0] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 0x8, got %#x.\n",
6731 data[8][0]);
6733 IDirectDrawSurface7_Release(surface);
6734 ref = IDirectDraw7_Release(ddraw);
6735 ok(ref == 0, "Ddraw object not properly released, refcount %u.\n", ref);
6736 DestroyWindow(window);
6739 static void test_sysmem_overlay(void)
6741 IDirectDraw7 *ddraw;
6742 HWND window;
6743 HRESULT hr;
6744 DDSURFACEDESC2 ddsd;
6745 IDirectDrawSurface7 *surface;
6746 ULONG ref;
6748 window = create_window();
6749 ddraw = create_ddraw();
6750 ok(!!ddraw, "Failed to create a ddraw object.\n");
6751 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6752 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6754 reset_ddsd(&ddsd);
6755 ddsd.dwFlags = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT;
6756 ddsd.dwWidth = 16;
6757 ddsd.dwHeight = 16;
6758 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OVERLAY;
6759 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
6760 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
6761 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
6762 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
6763 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
6764 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000ff;
6765 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
6766 ok(hr == DDERR_NOOVERLAYHW, "Got unexpected hr %#x.\n", hr);
6768 ref = IDirectDraw7_Release(ddraw);
6769 ok(ref == 0, "Ddraw object not properly released, refcount %u.\n", ref);
6770 DestroyWindow(window);
6773 static void test_primary_palette(void)
6775 DDSCAPS2 surface_caps = {DDSCAPS_FLIP, 0, 0, {0}};
6776 IDirectDrawSurface7 *primary, *backbuffer;
6777 PALETTEENTRY palette_entries[256];
6778 IDirectDrawPalette *palette, *tmp;
6779 DDSURFACEDESC2 surface_desc;
6780 IDirectDraw7 *ddraw;
6781 DWORD palette_caps;
6782 ULONG refcount;
6783 HWND window;
6784 HRESULT hr;
6786 window = create_window();
6787 ddraw = create_ddraw();
6788 ok(!!ddraw, "Failed to create a ddraw object.\n");
6789 if (FAILED(IDirectDraw7_SetDisplayMode(ddraw, 640, 480, 8, 0, 0)))
6791 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
6792 IDirectDraw7_Release(ddraw);
6793 DestroyWindow(window);
6794 return;
6796 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
6797 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6799 memset(&surface_desc, 0, sizeof(surface_desc));
6800 surface_desc.dwSize = sizeof(surface_desc);
6801 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
6802 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
6803 U5(surface_desc).dwBackBufferCount = 1;
6804 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &primary, NULL);
6805 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6806 hr = IDirectDrawSurface7_GetAttachedSurface(primary, &surface_caps, &backbuffer);
6807 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
6809 memset(palette_entries, 0, sizeof(palette_entries));
6810 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256, palette_entries, &palette, NULL);
6811 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
6812 refcount = get_refcount((IUnknown *)palette);
6813 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
6815 hr = IDirectDrawPalette_GetCaps(palette, &palette_caps);
6816 ok(SUCCEEDED(hr), "Failed to get palette caps, hr %#x.\n", hr);
6817 ok(palette_caps == (DDPCAPS_8BIT | DDPCAPS_ALLOW256), "Got unexpected palette caps %#x.\n", palette_caps);
6819 hr = IDirectDrawSurface7_SetPalette(primary, palette);
6820 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
6822 /* The Windows 8 testbot attaches the palette to the backbuffer as well,
6823 * and is generally somewhat broken with respect to 8 bpp / palette
6824 * handling. */
6825 if (SUCCEEDED(IDirectDrawSurface7_GetPalette(backbuffer, &tmp)))
6827 win_skip("Broken palette handling detected, skipping tests.\n");
6828 IDirectDrawPalette_Release(tmp);
6829 IDirectDrawPalette_Release(palette);
6830 /* The Windows 8 testbot keeps extra references to the primary and
6831 * backbuffer while in 8 bpp mode. */
6832 hr = IDirectDraw7_RestoreDisplayMode(ddraw);
6833 ok(SUCCEEDED(hr), "Failed to restore display mode, hr %#x.\n", hr);
6834 goto done;
6837 refcount = get_refcount((IUnknown *)palette);
6838 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
6840 hr = IDirectDrawPalette_GetCaps(palette, &palette_caps);
6841 ok(SUCCEEDED(hr), "Failed to get palette caps, hr %#x.\n", hr);
6842 ok(palette_caps == (DDPCAPS_8BIT | DDPCAPS_PRIMARYSURFACE | DDPCAPS_ALLOW256),
6843 "Got unexpected palette caps %#x.\n", palette_caps);
6845 hr = IDirectDrawSurface7_SetPalette(primary, NULL);
6846 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
6847 refcount = get_refcount((IUnknown *)palette);
6848 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
6850 hr = IDirectDrawPalette_GetCaps(palette, &palette_caps);
6851 ok(SUCCEEDED(hr), "Failed to get palette caps, hr %#x.\n", hr);
6852 ok(palette_caps == (DDPCAPS_8BIT | DDPCAPS_ALLOW256), "Got unexpected palette caps %#x.\n", palette_caps);
6854 hr = IDirectDrawSurface7_SetPalette(primary, palette);
6855 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
6856 refcount = get_refcount((IUnknown *)palette);
6857 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
6859 hr = IDirectDrawSurface7_GetPalette(primary, &tmp);
6860 ok(SUCCEEDED(hr), "Failed to get palette, hr %#x.\n", hr);
6861 ok(tmp == palette, "Got unexpected palette %p, expected %p.\n", tmp, palette);
6862 IDirectDrawPalette_Release(tmp);
6863 hr = IDirectDrawSurface7_GetPalette(backbuffer, &tmp);
6864 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x.\n", hr);
6866 refcount = IDirectDrawPalette_Release(palette);
6867 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
6868 refcount = IDirectDrawPalette_Release(palette);
6869 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6871 /* Note that this only seems to work when the palette is attached to the
6872 * primary surface. When attached to a regular surface, attempting to get
6873 * the palette here will cause an access violation. */
6874 hr = IDirectDrawSurface7_GetPalette(primary, &tmp);
6875 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x.\n", hr);
6877 hr = IDirectDrawSurface7_IsLost(primary);
6878 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6880 memset(&surface_desc, 0, sizeof(surface_desc));
6881 surface_desc.dwSize = sizeof(surface_desc);
6882 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &surface_desc);
6883 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
6884 ok(surface_desc.dwWidth == 640, "Got unexpected surface width %u.\n", surface_desc.dwWidth);
6885 ok(surface_desc.dwHeight == 480, "Got unexpected surface height %u.\n", surface_desc.dwHeight);
6886 ok(U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount == 8, "Got unexpected bit count %u.\n",
6887 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount);
6889 hr = set_display_mode(ddraw, 640, 480);
6890 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
6892 memset(&surface_desc, 0, sizeof(surface_desc));
6893 surface_desc.dwSize = sizeof(surface_desc);
6894 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &surface_desc);
6895 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
6896 ok(surface_desc.dwWidth == 640, "Got unexpected surface width %u.\n", surface_desc.dwWidth);
6897 ok(surface_desc.dwHeight == 480, "Got unexpected surface height %u.\n", surface_desc.dwHeight);
6898 ok(U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount == 32
6899 || U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount == 24,
6900 "Got unexpected bit count %u.\n", U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount);
6902 hr = IDirectDrawSurface7_IsLost(primary);
6903 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
6904 hr = IDirectDrawSurface7_Restore(primary);
6905 ok(hr == DDERR_WRONGMODE, "Got unexpected hr %#x.\n", hr);
6906 hr = IDirectDrawSurface7_IsLost(primary);
6907 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
6909 memset(&surface_desc, 0, sizeof(surface_desc));
6910 surface_desc.dwSize = sizeof(surface_desc);
6911 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &surface_desc);
6912 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
6913 ok(surface_desc.dwWidth == 640, "Got unexpected surface width %u.\n", surface_desc.dwWidth);
6914 ok(surface_desc.dwHeight == 480, "Got unexpected surface height %u.\n", surface_desc.dwHeight);
6915 ok(U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount == 32
6916 || U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount == 24,
6917 "Got unexpected bit count %u.\n", U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount);
6919 done:
6920 refcount = IDirectDrawSurface7_Release(backbuffer);
6921 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
6922 refcount = IDirectDrawSurface7_Release(primary);
6923 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6924 refcount = IDirectDraw7_Release(ddraw);
6925 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6926 DestroyWindow(window);
6929 static HRESULT WINAPI surface_counter(IDirectDrawSurface7 *surface, DDSURFACEDESC2 *desc, void *context)
6931 UINT *surface_count = context;
6933 ++(*surface_count);
6934 IDirectDrawSurface_Release(surface);
6936 return DDENUMRET_OK;
6939 static void test_surface_attachment(void)
6941 IDirectDrawSurface7 *surface1, *surface2, *surface3, *surface4;
6942 IDirectDrawSurface *surface1v1, *surface2v1;
6943 DDSCAPS2 caps = {DDSCAPS_TEXTURE, 0, 0, {0}};
6944 DDSURFACEDESC2 surface_desc;
6945 IDirectDraw7 *ddraw;
6946 UINT surface_count;
6947 ULONG refcount;
6948 HWND window;
6949 HRESULT hr;
6951 window = create_window();
6952 ddraw = create_ddraw();
6953 ok(!!ddraw, "Failed to create a ddraw object.\n");
6954 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6955 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6957 memset(&surface_desc, 0, sizeof(surface_desc));
6958 surface_desc.dwSize = sizeof(surface_desc);
6959 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_MIPMAPCOUNT;
6960 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
6961 U2(surface_desc).dwMipMapCount = 3;
6962 surface_desc.dwWidth = 128;
6963 surface_desc.dwHeight = 128;
6964 if (FAILED(IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface1, NULL)))
6966 skip("Failed to create a texture, skipping tests.\n");
6967 IDirectDraw7_Release(ddraw);
6968 DestroyWindow(window);
6969 return;
6972 hr = IDirectDrawSurface7_GetAttachedSurface(surface1, &caps, &surface2);
6973 ok(SUCCEEDED(hr), "Failed to get mip level, hr %#x.\n", hr);
6974 hr = IDirectDrawSurface7_GetAttachedSurface(surface2, &caps, &surface3);
6975 ok(SUCCEEDED(hr), "Failed to get mip level, hr %#x.\n", hr);
6976 hr = IDirectDrawSurface7_GetAttachedSurface(surface3, &caps, &surface4);
6977 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
6979 surface_count = 0;
6980 IDirectDrawSurface7_EnumAttachedSurfaces(surface1, &surface_count, surface_counter);
6981 ok(surface_count == 1, "Got unexpected surface_count %u.\n", surface_count);
6982 surface_count = 0;
6983 IDirectDrawSurface7_EnumAttachedSurfaces(surface2, &surface_count, surface_counter);
6984 ok(surface_count == 1, "Got unexpected surface_count %u.\n", surface_count);
6985 surface_count = 0;
6986 IDirectDrawSurface7_EnumAttachedSurfaces(surface3, &surface_count, surface_counter);
6987 ok(!surface_count, "Got unexpected surface_count %u.\n", surface_count);
6989 memset(&surface_desc, 0, sizeof(surface_desc));
6990 surface_desc.dwSize = sizeof(surface_desc);
6991 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
6992 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
6993 surface_desc.dwWidth = 16;
6994 surface_desc.dwHeight = 16;
6995 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface4, NULL);
6996 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6998 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface4);
6999 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7000 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface1);
7001 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7002 hr = IDirectDrawSurface7_AddAttachedSurface(surface3, surface4);
7003 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7004 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface3);
7005 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7006 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface4);
7007 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7008 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface2);
7009 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7011 IDirectDrawSurface7_Release(surface4);
7013 memset(&surface_desc, 0, sizeof(surface_desc));
7014 surface_desc.dwSize = sizeof(surface_desc);
7015 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
7016 surface_desc.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
7017 surface_desc.dwWidth = 16;
7018 surface_desc.dwHeight = 16;
7019 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface4, NULL);
7020 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7022 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface4);
7023 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7024 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface1);
7025 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7026 hr = IDirectDrawSurface7_AddAttachedSurface(surface3, surface4);
7027 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7028 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface3);
7029 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7030 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface4);
7031 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7032 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface2);
7033 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7035 IDirectDrawSurface7_Release(surface4);
7036 IDirectDrawSurface7_Release(surface3);
7037 IDirectDrawSurface7_Release(surface2);
7038 IDirectDrawSurface7_Release(surface1);
7040 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
7041 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
7043 /* Try a single primary and two offscreen plain surfaces. */
7044 memset(&surface_desc, 0, sizeof(surface_desc));
7045 surface_desc.dwSize = sizeof(surface_desc);
7046 surface_desc.dwFlags = DDSD_CAPS;
7047 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
7048 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface1, NULL);
7049 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7051 memset(&surface_desc, 0, sizeof(surface_desc));
7052 surface_desc.dwSize = sizeof(surface_desc);
7053 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
7054 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
7055 surface_desc.dwWidth = registry_mode.dmPelsWidth;
7056 surface_desc.dwHeight = registry_mode.dmPelsHeight;
7057 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface2, NULL);
7058 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7060 memset(&surface_desc, 0, sizeof(surface_desc));
7061 surface_desc.dwSize = sizeof(surface_desc);
7062 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
7063 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
7064 surface_desc.dwWidth = registry_mode.dmPelsWidth;
7065 surface_desc.dwHeight = registry_mode.dmPelsHeight;
7066 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface3, NULL);
7067 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7069 /* This one has a different size. */
7070 memset(&surface_desc, 0, sizeof(surface_desc));
7071 surface_desc.dwSize = sizeof(surface_desc);
7072 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
7073 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
7074 surface_desc.dwWidth = 128;
7075 surface_desc.dwHeight = 128;
7076 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface4, NULL);
7077 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7079 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface2);
7080 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7081 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface1);
7082 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7083 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface3);
7084 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7085 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface4);
7086 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7087 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface1);
7088 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7090 IDirectDrawSurface7_Release(surface4);
7091 IDirectDrawSurface7_Release(surface3);
7092 IDirectDrawSurface7_Release(surface2);
7093 IDirectDrawSurface7_Release(surface1);
7095 /* Test DeleteAttachedSurface() and automatic detachment of attached surfaces on release. */
7096 memset(&surface_desc, 0, sizeof(surface_desc));
7097 surface_desc.dwSize = sizeof(surface_desc);
7098 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
7099 surface_desc.dwWidth = 64;
7100 surface_desc.dwHeight = 64;
7101 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
7102 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
7103 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB; /* D3DFMT_R5G6B5 */
7104 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 16;
7105 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0xf800;
7106 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x07e0;
7107 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x001f;
7108 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface1, NULL);
7109 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7110 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface3, NULL);
7111 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7113 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
7114 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_ZBUFFER;
7115 U1(U4(surface_desc).ddpfPixelFormat).dwZBufferBitDepth = 16;
7116 U3(U4(surface_desc).ddpfPixelFormat).dwZBitMask = 0x0000ffff;
7117 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface2, NULL);
7118 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7120 hr = IDirectDrawSurface7_QueryInterface(surface1, &IID_IDirectDrawSurface, (void **)&surface1v1);
7121 ok(SUCCEEDED(hr), "Failed to get interface, hr %#x.\n", hr);
7122 hr = IDirectDrawSurface7_QueryInterface(surface2, &IID_IDirectDrawSurface, (void **)&surface2v1);
7123 ok(SUCCEEDED(hr), "Failed to get interface, hr %#x.\n", hr);
7125 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface2);
7126 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
7127 refcount = get_refcount((IUnknown *)surface2);
7128 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
7129 refcount = get_refcount((IUnknown *)surface2v1);
7130 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
7131 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface2);
7132 ok(hr == DDERR_SURFACEALREADYATTACHED, "Got unexpected hr %#x.\n", hr);
7133 hr = IDirectDrawSurface_AddAttachedSurface(surface1v1, surface2v1);
7134 todo_wine ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7135 hr = IDirectDrawSurface_DeleteAttachedSurface(surface1v1, 0, surface2v1);
7136 ok(hr == DDERR_SURFACENOTATTACHED, "Got unexpected hr %#x.\n", hr);
7138 /* Attaching while already attached to other surface. */
7139 hr = IDirectDrawSurface7_AddAttachedSurface(surface3, surface2);
7140 todo_wine ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
7141 hr = IDirectDrawSurface7_DeleteAttachedSurface(surface3, 0, surface2);
7142 todo_wine ok(SUCCEEDED(hr), "Failed to detach surface, hr %#x.\n", hr);
7143 IDirectDrawSurface7_Release(surface3);
7145 hr = IDirectDrawSurface7_DeleteAttachedSurface(surface1, 0, surface2);
7146 ok(SUCCEEDED(hr), "Failed to detach surface, hr %#x.\n", hr);
7147 refcount = get_refcount((IUnknown *)surface2);
7148 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
7149 refcount = get_refcount((IUnknown *)surface2v1);
7150 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
7152 /* DeleteAttachedSurface() when attaching via IDirectDrawSurface. */
7153 hr = IDirectDrawSurface_AddAttachedSurface(surface1v1, surface2v1);
7154 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
7155 hr = IDirectDrawSurface7_DeleteAttachedSurface(surface1, 0, surface2);
7156 ok(hr == DDERR_SURFACENOTATTACHED, "Got unexpected hr %#x.\n", hr);
7157 hr = IDirectDrawSurface_DeleteAttachedSurface(surface1v1, 0, surface2v1);
7158 ok(SUCCEEDED(hr), "Failed to detach surface, hr %#x.\n", hr);
7159 refcount = IDirectDrawSurface7_Release(surface2);
7160 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7161 refcount = IDirectDrawSurface7_Release(surface1);
7162 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7164 /* Automatic detachment on release. */
7165 hr = IDirectDrawSurface_AddAttachedSurface(surface1v1, surface2v1);
7166 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
7167 refcount = get_refcount((IUnknown *)surface2v1);
7168 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
7169 refcount = IDirectDrawSurface_Release(surface1v1);
7170 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7171 refcount = IDirectDrawSurface_Release(surface2v1);
7172 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7173 refcount = IDirectDraw7_Release(ddraw);
7174 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7175 DestroyWindow(window);
7178 static void test_private_data(void)
7180 IDirectDraw7 *ddraw;
7181 IDirectDrawSurface7 *surface, *surface2;
7182 DDSURFACEDESC2 surface_desc;
7183 ULONG refcount, refcount2, refcount3;
7184 IUnknown *ptr;
7185 DWORD size = sizeof(ptr);
7186 HRESULT hr;
7187 HWND window;
7188 DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, {0}};
7189 DWORD data[] = {1, 2, 3, 4};
7190 DDCAPS hal_caps;
7191 static const GUID ddraw_private_data_test_guid =
7193 0xfdb37466,
7194 0x428f,
7195 0x4edf,
7196 {0xa3,0x7f,0x9b,0x1d,0xf4,0x88,0xc5,0xfc}
7198 static const GUID ddraw_private_data_test_guid2 =
7200 0x2e5afac2,
7201 0x87b5,
7202 0x4c10,
7203 {0x9b,0x4b,0x89,0xd7,0xd1,0x12,0xe7,0x2b}
7206 window = create_window();
7207 ddraw = create_ddraw();
7208 ok(!!ddraw, "Failed to create a ddraw object.\n");
7209 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
7210 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
7212 reset_ddsd(&surface_desc);
7213 surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
7214 surface_desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
7215 surface_desc.dwHeight = 4;
7216 surface_desc.dwWidth = 4;
7217 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7218 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7220 /* NULL pointers are not valid, but don't cause a crash. */
7221 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, NULL,
7222 sizeof(IUnknown *), DDSPD_IUNKNOWNPOINTER);
7223 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7224 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, NULL, 0, 0);
7225 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7226 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, NULL, 1, 0);
7227 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7229 /* DDSPD_IUNKNOWNPOINTER needs sizeof(IUnknown *) bytes of data. */
7230 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
7231 0, DDSPD_IUNKNOWNPOINTER);
7232 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7233 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
7234 5, DDSPD_IUNKNOWNPOINTER);
7235 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7236 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
7237 sizeof(ddraw) * 2, DDSPD_IUNKNOWNPOINTER);
7238 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7240 /* Note that with a size != 0 and size != sizeof(IUnknown *) and
7241 * DDSPD_IUNKNOWNPOINTER set SetPrivateData in ddraw4 and ddraw7
7242 * erases the old content and returns an error. This behavior has
7243 * been fixed in d3d8 and d3d9. Unless an application is found
7244 * that depends on this we don't care about this behavior. */
7245 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
7246 sizeof(ddraw), DDSPD_IUNKNOWNPOINTER);
7247 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
7248 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
7249 0, DDSPD_IUNKNOWNPOINTER);
7250 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7251 size = sizeof(ptr);
7252 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid, &ptr, &size);
7253 ok(SUCCEEDED(hr), "Failed to get private data, hr %#x.\n", hr);
7254 hr = IDirectDrawSurface7_FreePrivateData(surface, &ddraw_private_data_test_guid);
7255 ok(SUCCEEDED(hr), "Failed to free private data, hr %#x.\n", hr);
7257 refcount = get_refcount((IUnknown *)ddraw);
7258 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
7259 sizeof(ddraw), DDSPD_IUNKNOWNPOINTER);
7260 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
7261 refcount2 = get_refcount((IUnknown *)ddraw);
7262 ok(refcount2 == refcount + 1, "Got unexpected refcount %u.\n", refcount2);
7264 hr = IDirectDrawSurface7_FreePrivateData(surface, &ddraw_private_data_test_guid);
7265 ok(SUCCEEDED(hr), "Failed to free private data, hr %#x.\n", hr);
7266 refcount2 = get_refcount((IUnknown *)ddraw);
7267 ok(refcount2 == refcount, "Got unexpected refcount %u.\n", refcount2);
7269 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
7270 sizeof(ddraw), DDSPD_IUNKNOWNPOINTER);
7271 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
7272 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, surface,
7273 sizeof(surface), DDSPD_IUNKNOWNPOINTER);
7274 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
7275 refcount2 = get_refcount((IUnknown *)ddraw);
7276 ok(refcount2 == refcount, "Got unexpected refcount %u.\n", refcount2);
7278 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
7279 sizeof(ddraw), DDSPD_IUNKNOWNPOINTER);
7280 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
7281 size = 2 * sizeof(ptr);
7282 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid, &ptr, &size);
7283 ok(SUCCEEDED(hr), "Failed to get private data, hr %#x.\n", hr);
7284 ok(size == sizeof(ddraw), "Got unexpected size %u.\n", size);
7285 refcount2 = get_refcount(ptr);
7286 /* Object is NOT addref'ed by the getter. */
7287 ok(ptr == (IUnknown *)ddraw, "Returned interface pointer is %p, expected %p.\n", ptr, ddraw);
7288 ok(refcount2 == refcount + 1, "Got unexpected refcount %u.\n", refcount2);
7290 ptr = (IUnknown *)0xdeadbeef;
7291 size = 1;
7292 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid, NULL, &size);
7293 ok(hr == DDERR_MOREDATA, "Got unexpected hr %#x.\n", hr);
7294 ok(size == sizeof(ddraw), "Got unexpected size %u.\n", size);
7295 size = 2 * sizeof(ptr);
7296 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid, NULL, &size);
7297 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7298 ok(size == 2 * sizeof(ptr), "Got unexpected size %u.\n", size);
7299 size = 1;
7300 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid, &ptr, &size);
7301 ok(hr == DDERR_MOREDATA, "Got unexpected hr %#x.\n", hr);
7302 ok(size == sizeof(ddraw), "Got unexpected size %u.\n", size);
7303 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
7304 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid2, NULL, NULL);
7305 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
7306 size = 0xdeadbabe;
7307 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid2, &ptr, &size);
7308 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
7309 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
7310 ok(size == 0xdeadbabe, "Got unexpected size %u.\n", size);
7311 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid, NULL, NULL);
7312 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7314 refcount3 = IDirectDrawSurface7_Release(surface);
7315 ok(!refcount3, "Got unexpected refcount %u.\n", refcount3);
7317 /* Destroying the surface frees the reference held on the private data. It also frees
7318 * the reference the surface is holding on its creating object. */
7319 refcount2 = get_refcount((IUnknown *)ddraw);
7320 ok(refcount2 == refcount - 1, "Got unexpected refcount %u.\n", refcount2);
7322 memset(&hal_caps, 0, sizeof(hal_caps));
7323 hal_caps.dwSize = sizeof(hal_caps);
7324 hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, NULL);
7325 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
7326 if ((hal_caps.ddsCaps.dwCaps & (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP)) == (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP)
7327 && !is_ddraw64)
7329 reset_ddsd(&surface_desc);
7330 surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_MIPMAPCOUNT;
7331 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
7332 surface_desc.dwHeight = 4;
7333 surface_desc.dwWidth = 4;
7334 U2(surface_desc).dwMipMapCount = 2;
7335 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7336 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7337 hr = IDirectDrawSurface7_GetAttachedSurface(surface, &caps, &surface2);
7338 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
7340 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, data, sizeof(data), 0);
7341 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
7342 hr = IDirectDrawSurface7_GetPrivateData(surface2, &ddraw_private_data_test_guid, NULL, NULL);
7343 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
7345 IDirectDrawSurface7_Release(surface2);
7346 IDirectDrawSurface7_Release(surface);
7348 else
7349 skip("Mipmapped textures not supported, skipping mipmap private data test.\n");
7351 refcount = IDirectDraw7_Release(ddraw);
7352 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7353 DestroyWindow(window);
7356 static void test_pixel_format(void)
7358 HWND window, window2 = NULL;
7359 HDC hdc, hdc2 = NULL;
7360 HMODULE gl = NULL;
7361 int format, test_format;
7362 PIXELFORMATDESCRIPTOR pfd;
7363 IDirectDraw7 *ddraw = NULL;
7364 IDirectDrawClipper *clipper = NULL;
7365 DDSURFACEDESC2 ddsd;
7366 IDirectDrawSurface7 *primary = NULL;
7367 DDBLTFX fx;
7368 HRESULT hr;
7370 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
7371 100, 100, 160, 160, NULL, NULL, NULL, NULL);
7372 if (!window)
7374 skip("Failed to create window\n");
7375 return;
7378 window2 = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
7379 100, 100, 160, 160, NULL, NULL, NULL, NULL);
7381 hdc = GetDC(window);
7382 if (!hdc)
7384 skip("Failed to get DC\n");
7385 goto cleanup;
7388 if (window2)
7389 hdc2 = GetDC(window2);
7391 gl = LoadLibraryA("opengl32.dll");
7392 ok(!!gl, "failed to load opengl32.dll; SetPixelFormat()/GetPixelFormat() may not work right\n");
7394 format = GetPixelFormat(hdc);
7395 ok(format == 0, "new window has pixel format %d\n", format);
7397 ZeroMemory(&pfd, sizeof(pfd));
7398 pfd.nSize = sizeof(pfd);
7399 pfd.nVersion = 1;
7400 pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
7401 pfd.iPixelType = PFD_TYPE_RGBA;
7402 pfd.iLayerType = PFD_MAIN_PLANE;
7403 format = ChoosePixelFormat(hdc, &pfd);
7404 if (format <= 0)
7406 skip("no pixel format available\n");
7407 goto cleanup;
7410 if (!SetPixelFormat(hdc, format, &pfd) || GetPixelFormat(hdc) != format)
7412 skip("failed to set pixel format\n");
7413 goto cleanup;
7416 if (!hdc2 || !SetPixelFormat(hdc2, format, &pfd) || GetPixelFormat(hdc2) != format)
7418 skip("failed to set pixel format on second window\n");
7419 if (hdc2)
7421 ReleaseDC(window2, hdc2);
7422 hdc2 = NULL;
7426 ddraw = create_ddraw();
7427 ok(!!ddraw, "Failed to create a ddraw object.\n");
7429 test_format = GetPixelFormat(hdc);
7430 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
7432 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
7433 if (FAILED(hr))
7435 skip("Failed to set cooperative level, hr %#x.\n", hr);
7436 goto cleanup;
7439 test_format = GetPixelFormat(hdc);
7440 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
7442 if (hdc2)
7444 hr = IDirectDraw7_CreateClipper(ddraw, 0, &clipper, NULL);
7445 ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr);
7446 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window2);
7447 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
7449 test_format = GetPixelFormat(hdc);
7450 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
7452 test_format = GetPixelFormat(hdc2);
7453 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
7456 memset(&ddsd, 0, sizeof(ddsd));
7457 ddsd.dwSize = sizeof(ddsd);
7458 ddsd.dwFlags = DDSD_CAPS;
7459 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
7461 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
7462 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
7464 test_format = GetPixelFormat(hdc);
7465 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
7467 if (hdc2)
7469 test_format = GetPixelFormat(hdc2);
7470 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
7473 if (clipper)
7475 hr = IDirectDrawSurface7_SetClipper(primary, clipper);
7476 ok(SUCCEEDED(hr), "Failed to set clipper, hr %#x.\n", hr);
7478 test_format = GetPixelFormat(hdc);
7479 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
7481 test_format = GetPixelFormat(hdc2);
7482 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
7485 memset(&fx, 0, sizeof(fx));
7486 fx.dwSize = sizeof(fx);
7487 hr = IDirectDrawSurface7_Blt(primary, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
7488 ok(SUCCEEDED(hr), "Failed to clear source surface, hr %#x.\n", hr);
7490 test_format = GetPixelFormat(hdc);
7491 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
7493 if (hdc2)
7495 test_format = GetPixelFormat(hdc2);
7496 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
7499 cleanup:
7500 if (primary) IDirectDrawSurface7_Release(primary);
7501 if (clipper) IDirectDrawClipper_Release(clipper);
7502 if (ddraw) IDirectDraw7_Release(ddraw);
7503 if (gl) FreeLibrary(gl);
7504 if (hdc) ReleaseDC(window, hdc);
7505 if (hdc2) ReleaseDC(window2, hdc2);
7506 if (window) DestroyWindow(window);
7507 if (window2) DestroyWindow(window2);
7510 static void test_create_surface_pitch(void)
7512 IDirectDrawSurface7 *surface;
7513 DDSURFACEDESC2 surface_desc;
7514 IDirectDraw7 *ddraw;
7515 unsigned int i;
7516 ULONG refcount;
7517 HWND window;
7518 HRESULT hr;
7519 void *mem;
7521 static const struct
7523 DWORD caps;
7524 DWORD flags_in;
7525 DWORD pitch_in;
7526 HRESULT hr;
7527 DWORD flags_out;
7528 DWORD pitch_out32;
7529 DWORD pitch_out64;
7531 test_data[] =
7533 /* 0 */
7534 {DDSCAPS_VIDEOMEMORY | DDSCAPS_OFFSCREENPLAIN,
7535 0, 0, DD_OK,
7536 DDSD_PITCH, 0x100, 0x100},
7537 {DDSCAPS_VIDEOMEMORY | DDSCAPS_OFFSCREENPLAIN,
7538 DDSD_PITCH, 0x104, DD_OK,
7539 DDSD_PITCH, 0x100, 0x100},
7540 {DDSCAPS_VIDEOMEMORY | DDSCAPS_OFFSCREENPLAIN,
7541 DDSD_PITCH, 0x0f8, DD_OK,
7542 DDSD_PITCH, 0x100, 0x100},
7543 {DDSCAPS_VIDEOMEMORY | DDSCAPS_OFFSCREENPLAIN,
7544 DDSD_LPSURFACE | DDSD_PITCH, 0x100, DDERR_INVALIDCAPS,
7545 0, 0, 0 },
7546 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
7547 0, 0, DD_OK,
7548 DDSD_PITCH, 0x100, 0x0fc},
7549 /* 5 */
7550 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
7551 DDSD_PITCH, 0x104, DD_OK,
7552 DDSD_PITCH, 0x100, 0x0fc},
7553 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
7554 DDSD_PITCH, 0x0f8, DD_OK,
7555 DDSD_PITCH, 0x100, 0x0fc},
7556 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
7557 DDSD_PITCH | DDSD_LINEARSIZE, 0, DD_OK,
7558 DDSD_PITCH, 0x100, 0x0fc},
7559 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
7560 DDSD_LPSURFACE, 0, DDERR_INVALIDPARAMS,
7561 0, 0, 0 },
7562 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
7563 DDSD_LPSURFACE | DDSD_PITCH, 0x100, DD_OK,
7564 DDSD_PITCH, 0x100, 0x100},
7565 /* 10 */
7566 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
7567 DDSD_LPSURFACE | DDSD_PITCH, 0x0fe, DDERR_INVALIDPARAMS,
7568 0, 0, 0 },
7569 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
7570 DDSD_LPSURFACE | DDSD_PITCH, 0x0fc, DD_OK,
7571 DDSD_PITCH, 0x0fc, 0x0fc},
7572 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
7573 DDSD_LPSURFACE | DDSD_PITCH, 0x0f8, DDERR_INVALIDPARAMS,
7574 0, 0, 0 },
7575 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
7576 DDSD_LPSURFACE | DDSD_LINEARSIZE, 0x100, DDERR_INVALIDPARAMS,
7577 0, 0, 0 },
7578 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
7579 DDSD_LPSURFACE | DDSD_LINEARSIZE, 0x3f00, DDERR_INVALIDPARAMS,
7580 0, 0, 0 },
7581 /* 15 */
7582 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
7583 DDSD_LPSURFACE | DDSD_PITCH | DDSD_LINEARSIZE, 0x100, DD_OK,
7584 DDSD_PITCH, 0x100, 0x100},
7585 {DDSCAPS_VIDEOMEMORY | DDSCAPS_OFFSCREENPLAIN | DDSCAPS_ALLOCONLOAD,
7586 0, 0, DDERR_INVALIDCAPS,
7587 0, 0, 0 },
7588 {DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD,
7589 0, 0, DD_OK,
7590 DDSD_PITCH, 0x100, 0 },
7591 {DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD,
7592 DDSD_LPSURFACE | DDSD_PITCH, 0x100, DDERR_INVALIDCAPS,
7593 0, 0, 0 },
7594 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN | DDSCAPS_ALLOCONLOAD,
7595 0, 0, DDERR_INVALIDCAPS,
7596 0, 0, 0 },
7597 /* 20 */
7598 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD,
7599 0, 0, DD_OK,
7600 DDSD_PITCH, 0x100, 0 },
7601 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD,
7602 DDSD_LPSURFACE | DDSD_PITCH, 0x100, DD_OK,
7603 DDSD_PITCH, 0x100, 0 },
7605 DWORD flags_mask = DDSD_PITCH | DDSD_LPSURFACE | DDSD_LINEARSIZE;
7607 window = create_window();
7608 ddraw = create_ddraw();
7609 ok(!!ddraw, "Failed to create a ddraw object.\n");
7610 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
7611 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
7613 mem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ((63 * 4) + 8) * 63);
7615 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
7617 memset(&surface_desc, 0, sizeof(surface_desc));
7618 surface_desc.dwSize = sizeof(surface_desc);
7619 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | test_data[i].flags_in;
7620 surface_desc.ddsCaps.dwCaps = test_data[i].caps;
7621 surface_desc.dwWidth = 63;
7622 surface_desc.dwHeight = 63;
7623 U1(surface_desc).lPitch = test_data[i].pitch_in;
7624 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
7625 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
7626 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
7627 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
7628 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
7629 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
7630 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7631 if (test_data[i].flags_in & DDSD_LPSURFACE)
7633 HRESULT expected_hr = SUCCEEDED(test_data[i].hr) ? DDERR_INVALIDPARAMS : test_data[i].hr;
7634 ok(hr == expected_hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, expected_hr);
7635 surface_desc.lpSurface = mem;
7636 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7638 if ((test_data[i].caps & DDSCAPS_VIDEOMEMORY) && hr == DDERR_NODIRECTDRAWHW)
7639 continue;
7640 if (is_ddraw64 && (test_data[i].caps & DDSCAPS_TEXTURE) && SUCCEEDED(test_data[i].hr))
7641 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Got unexpected hr %#x.\n", i, hr);
7642 else
7643 ok(hr == test_data[i].hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, test_data[i].hr);
7644 if (FAILED(hr))
7645 continue;
7647 memset(&surface_desc, 0, sizeof(surface_desc));
7648 surface_desc.dwSize = sizeof(surface_desc);
7649 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &surface_desc);
7650 ok(SUCCEEDED(hr), "Test %u: Failed to get surface desc, hr %#x.\n", i, hr);
7651 ok((surface_desc.dwFlags & flags_mask) == test_data[i].flags_out,
7652 "Test %u: Got unexpected flags %#x, expected %#x.\n",
7653 i, surface_desc.dwFlags & flags_mask, test_data[i].flags_out);
7654 /* The pitch for textures seems to be implementation specific. */
7655 if (!(test_data[i].caps & DDSCAPS_TEXTURE))
7657 if (is_ddraw64 && test_data[i].pitch_out32 != test_data[i].pitch_out64)
7658 todo_wine ok(U1(surface_desc).lPitch == test_data[i].pitch_out64,
7659 "Test %u: Got unexpected pitch %u, expected %u.\n",
7660 i, U1(surface_desc).lPitch, test_data[i].pitch_out64);
7661 else
7662 ok(U1(surface_desc).lPitch == test_data[i].pitch_out32,
7663 "Test %u: Got unexpected pitch %u, expected %u.\n",
7664 i, U1(surface_desc).lPitch, test_data[i].pitch_out32);
7666 ok(!surface_desc.lpSurface, "Test %u: Got unexpected lpSurface %p.\n", i, surface_desc.lpSurface);
7668 IDirectDrawSurface7_Release(surface);
7671 HeapFree(GetProcessHeap(), 0, mem);
7672 refcount = IDirectDraw7_Release(ddraw);
7673 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7674 DestroyWindow(window);
7677 static void test_mipmap(void)
7679 IDirectDrawSurface7 *surface, *surface2;
7680 DDSURFACEDESC2 surface_desc;
7681 IDirectDraw7 *ddraw;
7682 unsigned int i;
7683 ULONG refcount;
7684 HWND window;
7685 HRESULT hr;
7686 DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, {0}};
7687 DDCAPS hal_caps;
7689 static const struct
7691 DWORD flags;
7692 DWORD caps;
7693 DWORD width;
7694 DWORD height;
7695 DWORD mipmap_count_in;
7696 HRESULT hr;
7697 DWORD mipmap_count_out;
7699 tests[] =
7701 {DDSD_MIPMAPCOUNT, DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP, 128, 32, 3, DD_OK, 3},
7702 {DDSD_MIPMAPCOUNT, DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP, 128, 32, 0, DDERR_INVALIDPARAMS, 0},
7703 {0, DDSCAPS_TEXTURE | DDSCAPS_MIPMAP, 128, 32, 0, DD_OK, 1},
7704 {0, DDSCAPS_MIPMAP, 128, 32, 0, DDERR_INVALIDCAPS, 0},
7705 {0, DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP, 128, 32, 0, DD_OK, 8},
7706 {0, DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP, 32, 64, 0, DD_OK, 7},
7709 window = create_window();
7710 ddraw = create_ddraw();
7711 ok(!!ddraw, "Failed to create a ddraw object.\n");
7712 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
7713 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
7715 memset(&hal_caps, 0, sizeof(hal_caps));
7716 hal_caps.dwSize = sizeof(hal_caps);
7717 hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, NULL);
7718 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
7719 if ((hal_caps.ddsCaps.dwCaps & (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP)) != (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP)
7720 || is_ddraw64)
7722 skip("Mipmapped textures not supported, skipping tests.\n");
7723 IDirectDraw7_Release(ddraw);
7724 DestroyWindow(window);
7725 return;
7728 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
7730 memset(&surface_desc, 0, sizeof(surface_desc));
7731 surface_desc.dwSize = sizeof(surface_desc);
7732 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | tests[i].flags;
7733 surface_desc.ddsCaps.dwCaps = tests[i].caps;
7734 surface_desc.dwWidth = tests[i].width;
7735 surface_desc.dwHeight = tests[i].height;
7736 if (tests[i].flags & DDSD_MIPMAPCOUNT)
7737 U2(surface_desc).dwMipMapCount = tests[i].mipmap_count_in;
7738 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7739 ok(hr == tests[i].hr, "Test %u: Got unexpected hr %#x.\n", i, hr);
7740 if (FAILED(hr))
7741 continue;
7743 memset(&surface_desc, 0, sizeof(surface_desc));
7744 surface_desc.dwSize = sizeof(surface_desc);
7745 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &surface_desc);
7746 ok(SUCCEEDED(hr), "Test %u: Failed to get surface desc, hr %#x.\n", i, hr);
7747 ok(surface_desc.dwFlags & DDSD_MIPMAPCOUNT,
7748 "Test %u: Got unexpected flags %#x.\n", i, surface_desc.dwFlags);
7749 ok(U2(surface_desc).dwMipMapCount == tests[i].mipmap_count_out,
7750 "Test %u: Got unexpected mipmap count %u.\n", i, U2(surface_desc).dwMipMapCount);
7752 if (U2(surface_desc).dwMipMapCount > 1)
7754 hr = IDirectDrawSurface7_GetAttachedSurface(surface, &caps, &surface2);
7755 ok(SUCCEEDED(hr), "Test %u: Failed to get attached surface, hr %#x.\n", i, hr);
7757 memset(&surface_desc, 0, sizeof(surface_desc));
7758 surface_desc.dwSize = sizeof(surface_desc);
7759 hr = IDirectDrawSurface7_Lock(surface, NULL, &surface_desc, 0, NULL);
7760 ok(SUCCEEDED(hr), "Test %u: Failed to lock surface, hr %#x.\n", i, hr);
7761 memset(&surface_desc, 0, sizeof(surface_desc));
7762 surface_desc.dwSize = sizeof(surface_desc);
7763 hr = IDirectDrawSurface7_Lock(surface2, NULL, &surface_desc, 0, NULL);
7764 ok(SUCCEEDED(hr), "Test %u: Failed to lock surface, hr %#x.\n", i, hr);
7765 IDirectDrawSurface7_Unlock(surface2, NULL);
7766 IDirectDrawSurface7_Unlock(surface, NULL);
7768 IDirectDrawSurface7_Release(surface2);
7771 IDirectDrawSurface7_Release(surface);
7774 refcount = IDirectDraw7_Release(ddraw);
7775 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7776 DestroyWindow(window);
7779 static void test_palette_complex(void)
7781 IDirectDrawSurface7 *surface, *mipmap, *tmp;
7782 DDSURFACEDESC2 surface_desc;
7783 IDirectDraw7 *ddraw;
7784 IDirectDrawPalette *palette, *palette2;
7785 ULONG refcount;
7786 HWND window;
7787 HRESULT hr;
7788 DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, {0}};
7789 DDCAPS hal_caps;
7790 PALETTEENTRY palette_entries[256];
7791 unsigned int i;
7793 window = create_window();
7794 ddraw = create_ddraw();
7795 ok(!!ddraw, "Failed to create a ddraw object.\n");
7796 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
7797 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
7799 memset(&hal_caps, 0, sizeof(hal_caps));
7800 hal_caps.dwSize = sizeof(hal_caps);
7801 hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, NULL);
7802 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
7803 if ((hal_caps.ddsCaps.dwCaps & (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP)) != (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP)
7804 || is_ddraw64)
7806 skip("Mipmapped textures not supported, skipping mipmap palette test.\n");
7807 IDirectDraw7_Release(ddraw);
7808 DestroyWindow(window);
7809 return;
7812 memset(&surface_desc, 0, sizeof(surface_desc));
7813 surface_desc.dwSize = sizeof(surface_desc);
7814 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
7815 surface_desc.dwWidth = 128;
7816 surface_desc.dwHeight = 128;
7817 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
7818 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
7819 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
7820 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 8;
7821 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7822 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7824 memset(palette_entries, 0, sizeof(palette_entries));
7825 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
7826 palette_entries, &palette, NULL);
7827 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
7829 palette2 = (void *)0xdeadbeef;
7830 hr = IDirectDrawSurface7_GetPalette(surface, &palette2);
7831 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x.\n", hr);
7832 ok(!palette2, "Got unexpected palette %p.\n", palette2);
7833 hr = IDirectDrawSurface7_SetPalette(surface, palette);
7834 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
7835 hr = IDirectDrawSurface7_GetPalette(surface, &palette2);
7836 ok(SUCCEEDED(hr), "Failed to get palette, hr %#x.\n", hr);
7837 ok(palette == palette2, "Got unexpected palette %p.\n", palette2);
7838 IDirectDrawPalette_Release(palette2);
7840 mipmap = surface;
7841 IDirectDrawSurface7_AddRef(mipmap);
7842 for (i = 0; i < 7; ++i)
7844 hr = IDirectDrawSurface7_GetAttachedSurface(mipmap, &caps, &tmp);
7845 ok(SUCCEEDED(hr), "Failed to get attached surface, i %u, hr %#x.\n", i, hr);
7846 palette2 = (void *)0xdeadbeef;
7847 hr = IDirectDrawSurface7_GetPalette(tmp, &palette2);
7848 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x, i %u.\n", hr, i);
7849 ok(!palette2, "Got unexpected palette %p, i %u.\n", palette2, i);
7851 hr = IDirectDrawSurface7_SetPalette(tmp, palette);
7852 ok(hr == DDERR_NOTONMIPMAPSUBLEVEL, "Got unexpected hr %#x, i %u.\n", hr, i);
7854 hr = IDirectDrawSurface7_GetPalette(tmp, &palette2);
7855 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x, i %u.\n", hr, i);
7856 ok(!palette2, "Got unexpected palette %p, i %u.\n", palette2, i);
7858 /* Ddraw7 uses the palette of the mipmap for GetDC, just like previous
7859 * ddraw versions. Combined with the test results above this means no
7860 * palette is available. So depending on the driver either GetDC fails
7861 * or the DIB color table contains random data. */
7863 IDirectDrawSurface7_Release(mipmap);
7864 mipmap = tmp;
7867 hr = IDirectDrawSurface7_GetAttachedSurface(mipmap, &caps, &tmp);
7868 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
7869 IDirectDrawSurface7_Release(mipmap);
7870 refcount = IDirectDrawSurface7_Release(surface);
7871 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7873 /* Test DDERR_INVALIDPIXELFORMAT vs DDERR_NOTONMIPMAPSUBLEVEL. */
7874 memset(&surface_desc, 0, sizeof(surface_desc));
7875 surface_desc.dwSize = sizeof(surface_desc);
7876 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
7877 surface_desc.dwWidth = 128;
7878 surface_desc.dwHeight = 128;
7879 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
7880 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
7881 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
7882 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
7883 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
7884 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
7885 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
7886 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7887 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7889 hr = IDirectDrawSurface7_GetAttachedSurface(surface, &caps, &mipmap);
7890 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
7891 hr = IDirectDrawSurface7_SetPalette(mipmap, palette);
7892 ok(hr == DDERR_NOTONMIPMAPSUBLEVEL, "Got unexpected hr %#x.\n", hr);
7894 IDirectDrawSurface7_Release(mipmap);
7895 refcount = IDirectDrawSurface7_Release(surface);
7896 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7897 refcount = IDirectDrawPalette_Release(palette);
7898 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7900 refcount = IDirectDraw7_Release(ddraw);
7901 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7902 DestroyWindow(window);
7905 static void test_p8_blit(void)
7907 IDirectDrawSurface7 *src, *dst, *dst_p8;
7908 DDSURFACEDESC2 surface_desc;
7909 IDirectDraw7 *ddraw;
7910 IDirectDrawPalette *palette, *palette2;
7911 ULONG refcount;
7912 HWND window;
7913 HRESULT hr;
7914 PALETTEENTRY palette_entries[256];
7915 unsigned int x;
7916 DDBLTFX fx;
7917 BOOL is_warp;
7918 static const BYTE src_data[] = {0x10, 0x1, 0x2, 0x3, 0x4, 0x5, 0xff, 0x80};
7919 static const BYTE src_data2[] = {0x10, 0x5, 0x4, 0x3, 0x2, 0x1, 0xff, 0x80};
7920 static const BYTE expected_p8[] = {0x10, 0x1, 0x4, 0x3, 0x4, 0x5, 0xff, 0x80};
7921 static const D3DCOLOR expected[] =
7923 0x00101010, 0x00010101, 0x00020202, 0x00030303,
7924 0x00040404, 0x00050505, 0x00ffffff, 0x00808080,
7926 D3DCOLOR color;
7928 window = create_window();
7929 ddraw = create_ddraw();
7930 ok(!!ddraw, "Failed to create a ddraw object.\n");
7931 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
7932 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
7933 is_warp = ddraw_is_warp(ddraw);
7935 memset(palette_entries, 0, sizeof(palette_entries));
7936 palette_entries[1].peGreen = 0xff;
7937 palette_entries[2].peBlue = 0xff;
7938 palette_entries[3].peFlags = 0xff;
7939 palette_entries[4].peRed = 0xff;
7940 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
7941 palette_entries, &palette, NULL);
7942 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
7943 palette_entries[1].peBlue = 0xff;
7944 palette_entries[2].peGreen = 0xff;
7945 palette_entries[3].peRed = 0xff;
7946 palette_entries[4].peFlags = 0x0;
7947 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
7948 palette_entries, &palette2, NULL);
7949 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
7951 memset(&surface_desc, 0, sizeof(surface_desc));
7952 surface_desc.dwSize = sizeof(surface_desc);
7953 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
7954 surface_desc.dwWidth = 8;
7955 surface_desc.dwHeight = 1;
7956 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
7957 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
7958 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
7959 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 8;
7960 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &src, NULL);
7961 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7962 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &dst_p8, NULL);
7963 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7964 hr = IDirectDrawSurface7_SetPalette(dst_p8, palette2);
7965 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
7967 memset(&surface_desc, 0, sizeof(surface_desc));
7968 surface_desc.dwSize = sizeof(surface_desc);
7969 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
7970 surface_desc.dwWidth = 8;
7971 surface_desc.dwHeight = 1;
7972 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
7973 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
7974 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
7975 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
7976 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
7977 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
7978 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
7979 U5(U4(surface_desc).ddpfPixelFormat).dwRGBAlphaBitMask = 0xff000000;
7980 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &dst, NULL);
7981 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7983 memset(&surface_desc, 0, sizeof(surface_desc));
7984 surface_desc.dwSize = sizeof(surface_desc);
7985 hr = IDirectDrawSurface7_Lock(src, NULL, &surface_desc, DDLOCK_WAIT, NULL);
7986 ok(SUCCEEDED(hr), "Failed to lock source surface, hr %#x.\n", hr);
7987 memcpy(surface_desc.lpSurface, src_data, sizeof(src_data));
7988 hr = IDirectDrawSurface7_Unlock(src, NULL);
7989 ok(SUCCEEDED(hr), "Failed to unlock source surface, hr %#x.\n", hr);
7991 hr = IDirectDrawSurface7_Lock(dst_p8, NULL, &surface_desc, DDLOCK_WAIT, NULL);
7992 ok(SUCCEEDED(hr), "Failed to lock destination surface, hr %#x.\n", hr);
7993 memcpy(surface_desc.lpSurface, src_data2, sizeof(src_data2));
7994 hr = IDirectDrawSurface7_Unlock(dst_p8, NULL);
7995 ok(SUCCEEDED(hr), "Failed to unlock destination surface, hr %#x.\n", hr);
7997 hr = IDirectDrawSurface7_SetPalette(src, palette);
7998 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
7999 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_WAIT, NULL);
8000 /* The r500 Windows 7 driver returns E_NOTIMPL. r200 on Windows XP works.
8001 * The Geforce 7 driver on Windows Vista returns E_FAIL. Newer Nvidia GPUs work. */
8002 ok(SUCCEEDED(hr) || broken(hr == E_NOTIMPL) || broken(hr == E_FAIL),
8003 "Failed to blit, hr %#x.\n", hr);
8005 if (SUCCEEDED(hr))
8007 for (x = 0; x < sizeof(expected) / sizeof(*expected); x++)
8009 color = get_surface_color(dst, x, 0);
8010 todo_wine ok(compare_color(color, expected[x], 0),
8011 "Pixel %u: Got color %#x, expected %#x.\n",
8012 x, color, expected[x]);
8016 memset(&fx, 0, sizeof(fx));
8017 fx.dwSize = sizeof(fx);
8018 fx.ddckSrcColorkey.dwColorSpaceHighValue = 0x2;
8019 fx.ddckSrcColorkey.dwColorSpaceLowValue = 0x2;
8020 hr = IDirectDrawSurface7_Blt(dst_p8, NULL, src, NULL, DDBLT_WAIT | DDBLT_KEYSRCOVERRIDE, &fx);
8021 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
8023 hr = IDirectDrawSurface7_Lock(dst_p8, NULL, &surface_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
8024 ok(SUCCEEDED(hr), "Failed to lock destination surface, hr %#x.\n", hr);
8025 /* A color keyed P8 blit doesn't do anything on WARP - it just leaves the data in the destination
8026 * surface untouched. P8 blits without color keys work. Error checking (DDBLT_KEYSRC without a key
8027 * for example) also works as expected.
8029 * Using DDBLT_KEYSRC instead of DDBLT_KEYSRCOVERRIDE doesn't change this. Doing this blit with
8030 * the display mode set to P8 doesn't help either. */
8031 ok(!memcmp(surface_desc.lpSurface, expected_p8, sizeof(expected_p8))
8032 || broken(is_warp && !memcmp(surface_desc.lpSurface, src_data2, sizeof(src_data2))),
8033 "Got unexpected P8 color key blit result.\n");
8034 hr = IDirectDrawSurface7_Unlock(dst_p8, NULL);
8035 ok(SUCCEEDED(hr), "Failed to unlock destination surface, hr %#x.\n", hr);
8037 IDirectDrawSurface7_Release(src);
8038 IDirectDrawSurface7_Release(dst);
8039 IDirectDrawSurface7_Release(dst_p8);
8040 IDirectDrawPalette_Release(palette);
8041 IDirectDrawPalette_Release(palette2);
8043 refcount = IDirectDraw7_Release(ddraw);
8044 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8045 DestroyWindow(window);
8048 static void test_material(void)
8050 static const D3DCOLORVALUE null_color;
8051 IDirect3DDevice7 *device;
8052 D3DMATERIAL7 material;
8053 ULONG refcount;
8054 HWND window;
8055 HRESULT hr;
8057 window = create_window();
8058 if (!(device = create_device(window, DDSCL_NORMAL)))
8060 skip("Failed to create a 3D device, skipping test.\n");
8061 DestroyWindow(window);
8062 return;
8065 hr = IDirect3DDevice7_GetMaterial(device, &material);
8066 ok(SUCCEEDED(hr), "Failed to get material, hr %#x.\n", hr);
8067 ok(!memcmp(&U(material).diffuse, &null_color, sizeof(null_color)),
8068 "Got unexpected diffuse color {%.8e, %.8e, %.8e, %.8e}.\n",
8069 U1(U(material).diffuse).r, U2(U(material).diffuse).g,
8070 U3(U(material).diffuse).b, U4(U(material).diffuse).a);
8071 ok(!memcmp(&U1(material).ambient, &null_color, sizeof(null_color)),
8072 "Got unexpected ambient color {%.8e, %.8e, %.8e, %.8e}.\n",
8073 U1(U1(material).ambient).r, U2(U1(material).ambient).g,
8074 U3(U1(material).ambient).b, U4(U1(material).ambient).a);
8075 ok(!memcmp(&U2(material).specular, &null_color, sizeof(null_color)),
8076 "Got unexpected specular color {%.8e, %.8e, %.8e, %.8e}.\n",
8077 U1(U2(material).specular).r, U2(U2(material).specular).g,
8078 U3(U2(material).specular).b, U4(U2(material).specular).a);
8079 ok(!memcmp(&U3(material).emissive, &null_color, sizeof(null_color)),
8080 "Got unexpected emissive color {%.8e, %.8e, %.8e, %.8e}.\n",
8081 U1(U3(material).emissive).r, U2(U3(material).emissive).g,
8082 U3(U3(material).emissive).b, U4(U3(material).emissive).a);
8083 ok(U4(material).power == 0.0f, "Got unexpected power %.8e.\n", U4(material).power);
8085 refcount = IDirect3DDevice7_Release(device);
8086 ok(!refcount, "Device has %u references left.\n", refcount);
8087 DestroyWindow(window);
8090 static void test_palette_gdi(void)
8092 IDirectDrawSurface7 *surface, *primary;
8093 DDSURFACEDESC2 surface_desc;
8094 IDirectDraw7 *ddraw;
8095 IDirectDrawPalette *palette, *palette2;
8096 ULONG refcount;
8097 HWND window;
8098 HRESULT hr;
8099 PALETTEENTRY palette_entries[256];
8100 UINT i;
8101 HDC dc;
8102 DDBLTFX fx;
8103 RECT r;
8104 COLORREF color;
8105 /* On the Windows 8 testbot palette index 0 of the onscreen palette is forced to
8106 * r = 0, g = 0, b = 0. Do not attempt to set it to something else as this is
8107 * not the point of this test. */
8108 static const RGBQUAD expected1[] =
8110 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
8111 {0x03, 0x00, 0x00, 0x00}, {0x15, 0x14, 0x13, 0x00},
8113 static const RGBQUAD expected2[] =
8115 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
8116 {0x03, 0x00, 0x00, 0x00}, {0x25, 0x24, 0x23, 0x00},
8118 static const RGBQUAD expected3[] =
8120 {0x00, 0x00, 0x00, 0x00}, {0x40, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x40, 0x00},
8121 {0x00, 0x40, 0x00, 0x00}, {0x56, 0x34, 0x12, 0x00},
8123 HPALETTE ddraw_palette_handle;
8124 /* Similar to index 0, index 255 is r = 0xff, g = 0xff, b = 0xff on the Win8 VMs. */
8125 RGBQUAD rgbquad[255];
8126 static const RGBQUAD rgb_zero = {0, 0, 0, 0};
8128 window = create_window();
8129 ddraw = create_ddraw();
8130 ok(!!ddraw, "Failed to create a ddraw object.\n");
8131 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
8132 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
8134 memset(&surface_desc, 0, sizeof(surface_desc));
8135 surface_desc.dwSize = sizeof(surface_desc);
8136 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
8137 surface_desc.dwWidth = 16;
8138 surface_desc.dwHeight = 16;
8139 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
8140 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
8141 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
8142 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 8;
8143 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8144 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8146 /* Avoid colors from the Windows default palette. */
8147 memset(palette_entries, 0, sizeof(palette_entries));
8148 palette_entries[1].peRed = 0x01;
8149 palette_entries[2].peGreen = 0x02;
8150 palette_entries[3].peBlue = 0x03;
8151 palette_entries[4].peRed = 0x13;
8152 palette_entries[4].peGreen = 0x14;
8153 palette_entries[4].peBlue = 0x15;
8154 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
8155 palette_entries, &palette, NULL);
8156 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
8158 /* If there is no palette assigned and the display mode is not 8 bpp, some
8159 * drivers refuse to create a DC while others allow it. If a DC is created,
8160 * the DIB color table is uninitialized and contains random colors. No error
8161 * is generated when trying to read pixels and random garbage is returned.
8163 * The most likely explanation is that if the driver creates a DC, it (or
8164 * the higher-level runtime) uses GetSystemPaletteEntries to find the
8165 * palette, but GetSystemPaletteEntries fails when bpp > 8 and the palette
8166 * contains uninitialized garbage. See comments below for the P8 case. */
8168 hr = IDirectDrawSurface7_SetPalette(surface, palette);
8169 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
8170 hr = IDirectDrawSurface7_GetDC(surface, &dc);
8171 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
8172 ddraw_palette_handle = SelectPalette(dc, GetStockObject(DEFAULT_PALETTE), FALSE);
8173 ok(ddraw_palette_handle == GetStockObject(DEFAULT_PALETTE),
8174 "Got unexpected palette %p, expected %p.\n",
8175 ddraw_palette_handle, GetStockObject(DEFAULT_PALETTE));
8177 i = GetDIBColorTable(dc, 0, sizeof(rgbquad) / sizeof(*rgbquad), rgbquad);
8178 ok(i == sizeof(rgbquad) / sizeof(*rgbquad), "Expected count 255, got %u.\n", i);
8179 for (i = 0; i < sizeof(expected1) / sizeof(*expected1); i++)
8181 ok(!memcmp(&rgbquad[i], &expected1[i], sizeof(rgbquad[i])),
8182 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8183 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
8184 expected1[i].rgbRed, expected1[i].rgbGreen, expected1[i].rgbBlue);
8186 for (; i < sizeof(rgbquad) / sizeof(*rgbquad); i++)
8188 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
8189 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
8190 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
8193 /* Update the palette while the DC is in use. This does not modify the DC. */
8194 palette_entries[4].peRed = 0x23;
8195 palette_entries[4].peGreen = 0x24;
8196 palette_entries[4].peBlue = 0x25;
8197 hr = IDirectDrawPalette_SetEntries(palette, 0, 4, 1, &palette_entries[4]);
8198 ok(SUCCEEDED(hr), "Failed to set palette entries, hr %#x.\n", hr);
8200 i = GetDIBColorTable(dc, 4, 1, &rgbquad[4]);
8201 ok(i == 1, "Expected count 1, got %u.\n", i);
8202 ok(!memcmp(&rgbquad[4], &expected1[4], sizeof(rgbquad[4])),
8203 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8204 i, rgbquad[4].rgbRed, rgbquad[4].rgbGreen, rgbquad[4].rgbBlue,
8205 expected1[4].rgbRed, expected1[4].rgbGreen, expected1[4].rgbBlue);
8207 /* Neither does re-setting the palette. */
8208 hr = IDirectDrawSurface7_SetPalette(surface, NULL);
8209 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
8210 hr = IDirectDrawSurface7_SetPalette(surface, palette);
8211 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
8213 i = GetDIBColorTable(dc, 4, 1, &rgbquad[4]);
8214 ok(i == 1, "Expected count 1, got %u.\n", i);
8215 ok(!memcmp(&rgbquad[4], &expected1[4], sizeof(rgbquad[4])),
8216 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8217 i, rgbquad[4].rgbRed, rgbquad[4].rgbGreen, rgbquad[4].rgbBlue,
8218 expected1[4].rgbRed, expected1[4].rgbGreen, expected1[4].rgbBlue);
8220 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
8221 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
8223 /* Refresh the DC. This updates the palette. */
8224 hr = IDirectDrawSurface7_GetDC(surface, &dc);
8225 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
8226 i = GetDIBColorTable(dc, 0, sizeof(rgbquad) / sizeof(*rgbquad), rgbquad);
8227 ok(i == sizeof(rgbquad) / sizeof(*rgbquad), "Expected count 255, got %u.\n", i);
8228 for (i = 0; i < sizeof(expected2) / sizeof(*expected2); i++)
8230 ok(!memcmp(&rgbquad[i], &expected2[i], sizeof(rgbquad[i])),
8231 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8232 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
8233 expected2[i].rgbRed, expected2[i].rgbGreen, expected2[i].rgbBlue);
8235 for (; i < sizeof(rgbquad) / sizeof(*rgbquad); i++)
8237 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
8238 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
8239 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
8241 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
8242 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
8244 refcount = IDirectDrawSurface7_Release(surface);
8245 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8247 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
8248 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
8249 if (FAILED(IDirectDraw7_SetDisplayMode(ddraw, 640, 480, 8, 0, 0)))
8251 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
8252 IDirectDrawPalette_Release(palette);
8253 IDirectDraw7_Release(ddraw);
8254 DestroyWindow(window);
8255 return;
8257 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
8259 memset(&surface_desc, 0, sizeof(surface_desc));
8260 surface_desc.dwSize = sizeof(surface_desc);
8261 surface_desc.dwFlags = DDSD_CAPS;
8262 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
8263 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &primary, NULL);
8264 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8266 memset(&fx, 0, sizeof(fx));
8267 fx.dwSize = sizeof(fx);
8268 U5(fx).dwFillColor = 3;
8269 SetRect(&r, 0, 0, 319, 479);
8270 hr = IDirectDrawSurface7_Blt(primary, &r, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
8271 ok(SUCCEEDED(hr), "Failed to clear surface, hr %#x.\n", hr);
8272 SetRect(&r, 320, 0, 639, 479);
8273 U5(fx).dwFillColor = 4;
8274 hr = IDirectDrawSurface7_Blt(primary, &r, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
8275 ok(SUCCEEDED(hr), "Failed to clear surface, hr %#x.\n", hr);
8277 hr = IDirectDrawSurface7_SetPalette(primary, palette);
8278 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
8279 hr = IDirectDrawSurface7_GetDC(primary, &dc);
8280 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
8282 color = GetPixel(dc, 160, 240);
8283 ok(color == 0x00030000, "Clear index 3: Got unexpected color 0x%08x.\n", color);
8284 color = GetPixel(dc, 480, 240);
8285 ok(color == 0x00252423, "Clear index 4: Got unexpected color 0x%08x.\n", color);
8287 ddraw_palette_handle = SelectPalette(dc, GetStockObject(DEFAULT_PALETTE), FALSE);
8288 ok(ddraw_palette_handle == GetStockObject(DEFAULT_PALETTE),
8289 "Got unexpected palette %p, expected %p.\n",
8290 ddraw_palette_handle, GetStockObject(DEFAULT_PALETTE));
8291 SelectPalette(dc, ddraw_palette_handle, FALSE);
8293 /* The primary uses the system palette. In exclusive mode, the system palette matches
8294 * the ddraw palette attached to the primary, so the result is what you would expect
8295 * from a regular surface. Tests for the interaction between the ddraw palette and
8296 * the system palette are not included pending an application that depends on this.
8297 * The relation between those causes problems on Windows Vista and newer for games
8298 * like Age of Empires or StarcCaft. Don't emulate it without a real need. */
8299 i = GetDIBColorTable(dc, 0, sizeof(rgbquad) / sizeof(*rgbquad), rgbquad);
8300 ok(i == sizeof(rgbquad) / sizeof(*rgbquad), "Expected count 255, got %u.\n", i);
8301 for (i = 0; i < sizeof(expected2) / sizeof(*expected2); i++)
8303 ok(!memcmp(&rgbquad[i], &expected2[i], sizeof(rgbquad[i])),
8304 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8305 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
8306 expected2[i].rgbRed, expected2[i].rgbGreen, expected2[i].rgbBlue);
8308 for (; i < sizeof(rgbquad) / sizeof(*rgbquad); i++)
8310 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
8311 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
8312 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
8314 hr = IDirectDrawSurface7_ReleaseDC(primary, dc);
8315 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
8317 memset(&surface_desc, 0, sizeof(surface_desc));
8318 surface_desc.dwSize = sizeof(surface_desc);
8319 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
8320 surface_desc.dwWidth = 16;
8321 surface_desc.dwHeight = 16;
8322 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
8323 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8324 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8326 /* Here the offscreen surface appears to use the primary's palette,
8327 * but in all likelihood it is actually the system palette. */
8328 hr = IDirectDrawSurface7_GetDC(surface, &dc);
8329 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
8330 i = GetDIBColorTable(dc, 0, sizeof(rgbquad) / sizeof(*rgbquad), rgbquad);
8331 ok(i == sizeof(rgbquad) / sizeof(*rgbquad), "Expected count 255, got %u.\n", i);
8332 for (i = 0; i < sizeof(expected2) / sizeof(*expected2); i++)
8334 ok(!memcmp(&rgbquad[i], &expected2[i], sizeof(rgbquad[i])),
8335 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8336 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
8337 expected2[i].rgbRed, expected2[i].rgbGreen, expected2[i].rgbBlue);
8339 for (; i < sizeof(rgbquad) / sizeof(*rgbquad); i++)
8341 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
8342 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
8343 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
8345 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
8346 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
8348 /* On real hardware a change to the primary surface's palette applies immediately,
8349 * even on device contexts from offscreen surfaces that do not have their own
8350 * palette. On the testbot VMs this is not the case. Don't test this until we
8351 * know of an application that depends on this. */
8353 memset(palette_entries, 0, sizeof(palette_entries));
8354 palette_entries[1].peBlue = 0x40;
8355 palette_entries[2].peRed = 0x40;
8356 palette_entries[3].peGreen = 0x40;
8357 palette_entries[4].peRed = 0x12;
8358 palette_entries[4].peGreen = 0x34;
8359 palette_entries[4].peBlue = 0x56;
8360 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
8361 palette_entries, &palette2, NULL);
8362 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
8363 hr = IDirectDrawSurface7_SetPalette(surface, palette2);
8364 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
8366 /* A palette assigned to the offscreen surface overrides the primary / system
8367 * palette. */
8368 hr = IDirectDrawSurface7_GetDC(surface, &dc);
8369 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
8370 i = GetDIBColorTable(dc, 0, sizeof(rgbquad) / sizeof(*rgbquad), rgbquad);
8371 ok(i == sizeof(rgbquad) / sizeof(*rgbquad), "Expected count 255, got %u.\n", i);
8372 for (i = 0; i < sizeof(expected3) / sizeof(*expected3); i++)
8374 ok(!memcmp(&rgbquad[i], &expected3[i], sizeof(rgbquad[i])),
8375 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8376 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
8377 expected3[i].rgbRed, expected3[i].rgbGreen, expected3[i].rgbBlue);
8379 for (; i < sizeof(rgbquad) / sizeof(*rgbquad); i++)
8381 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
8382 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
8383 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
8385 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
8386 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
8388 refcount = IDirectDrawSurface7_Release(surface);
8389 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8391 /* The Windows 8 testbot keeps extra references to the primary and
8392 * backbuffer while in 8 bpp mode. */
8393 hr = IDirectDraw7_RestoreDisplayMode(ddraw);
8394 ok(SUCCEEDED(hr), "Failed to restore display mode, hr %#x.\n", hr);
8396 refcount = IDirectDrawSurface7_Release(primary);
8397 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8398 refcount = IDirectDrawPalette_Release(palette2);
8399 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8400 refcount = IDirectDrawPalette_Release(palette);
8401 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8402 refcount = IDirectDraw7_Release(ddraw);
8403 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8404 DestroyWindow(window);
8407 static void test_palette_alpha(void)
8409 IDirectDrawSurface7 *surface;
8410 DDSURFACEDESC2 surface_desc;
8411 IDirectDraw7 *ddraw;
8412 IDirectDrawPalette *palette;
8413 ULONG refcount;
8414 HWND window;
8415 HRESULT hr;
8416 PALETTEENTRY palette_entries[256];
8417 unsigned int i;
8418 static const struct
8420 DWORD caps, flags;
8421 BOOL attach_allowed;
8422 const char *name;
8424 test_data[] =
8426 {DDSCAPS_OFFSCREENPLAIN, DDSD_WIDTH | DDSD_HEIGHT, FALSE, "offscreenplain"},
8427 {DDSCAPS_TEXTURE, DDSD_WIDTH | DDSD_HEIGHT, TRUE, "texture"},
8428 {DDSCAPS_PRIMARYSURFACE, 0, FALSE, "primary"}
8431 window = create_window();
8432 ddraw = create_ddraw();
8433 ok(!!ddraw, "Failed to create a ddraw object.\n");
8434 if (FAILED(IDirectDraw7_SetDisplayMode(ddraw, 640, 480, 8, 0, 0)))
8436 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
8437 IDirectDraw7_Release(ddraw);
8438 DestroyWindow(window);
8439 return;
8441 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
8442 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
8444 memset(palette_entries, 0, sizeof(palette_entries));
8445 palette_entries[1].peFlags = 0x42;
8446 palette_entries[2].peFlags = 0xff;
8447 palette_entries[3].peFlags = 0x80;
8448 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, palette_entries, &palette, NULL);
8449 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
8451 memset(palette_entries, 0x66, sizeof(palette_entries));
8452 hr = IDirectDrawPalette_GetEntries(palette, 0, 1, 4, palette_entries);
8453 ok(SUCCEEDED(hr), "Failed to get palette entries, hr %#x.\n", hr);
8454 ok(palette_entries[0].peFlags == 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
8455 palette_entries[0].peFlags);
8456 ok(palette_entries[1].peFlags == 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
8457 palette_entries[1].peFlags);
8458 ok(palette_entries[2].peFlags == 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
8459 palette_entries[2].peFlags);
8460 ok(palette_entries[3].peFlags == 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
8461 palette_entries[3].peFlags);
8463 IDirectDrawPalette_Release(palette);
8465 memset(palette_entries, 0, sizeof(palette_entries));
8466 palette_entries[1].peFlags = 0x42;
8467 palette_entries[1].peRed = 0xff;
8468 palette_entries[2].peFlags = 0xff;
8469 palette_entries[3].peFlags = 0x80;
8470 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_ALLOW256 | DDPCAPS_8BIT | DDPCAPS_ALPHA,
8471 palette_entries, &palette, NULL);
8472 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
8474 memset(palette_entries, 0x66, sizeof(palette_entries));
8475 hr = IDirectDrawPalette_GetEntries(palette, 0, 1, 4, palette_entries);
8476 ok(SUCCEEDED(hr), "Failed to get palette entries, hr %#x.\n", hr);
8477 ok(palette_entries[0].peFlags == 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
8478 palette_entries[0].peFlags);
8479 ok(palette_entries[1].peFlags == 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
8480 palette_entries[1].peFlags);
8481 ok(palette_entries[2].peFlags == 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
8482 palette_entries[2].peFlags);
8483 ok(palette_entries[3].peFlags == 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
8484 palette_entries[3].peFlags);
8486 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); i++)
8488 memset(&surface_desc, 0, sizeof(surface_desc));
8489 surface_desc.dwSize = sizeof(surface_desc);
8490 surface_desc.dwFlags = DDSD_CAPS | test_data[i].flags;
8491 surface_desc.dwWidth = 128;
8492 surface_desc.dwHeight = 128;
8493 surface_desc.ddsCaps.dwCaps = test_data[i].caps;
8494 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8495 ok(SUCCEEDED(hr), "Failed to create %s surface, hr %#x.\n", test_data[i].name, hr);
8497 hr = IDirectDrawSurface7_SetPalette(surface, palette);
8498 if (test_data[i].attach_allowed)
8499 ok(SUCCEEDED(hr), "Failed to attach palette to %s surface, hr %#x.\n", test_data[i].name, hr);
8500 else
8501 ok(hr == DDERR_INVALIDSURFACETYPE, "Got unexpected hr %#x, %s surface.\n", hr, test_data[i].name);
8503 if (SUCCEEDED(hr))
8505 HDC dc;
8506 RGBQUAD rgbquad;
8507 UINT retval;
8509 hr = IDirectDrawSurface7_GetDC(surface, &dc);
8510 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x, %s surface.\n", hr, test_data[i].name);
8511 retval = GetDIBColorTable(dc, 1, 1, &rgbquad);
8512 ok(retval == 1, "GetDIBColorTable returned unexpected result %u.\n", retval);
8513 ok(rgbquad.rgbRed == 0xff, "Expected rgbRed = 0xff, got %#x, %s surface.\n",
8514 rgbquad.rgbRed, test_data[i].name);
8515 ok(rgbquad.rgbGreen == 0, "Expected rgbGreen = 0, got %#x, %s surface.\n",
8516 rgbquad.rgbGreen, test_data[i].name);
8517 ok(rgbquad.rgbBlue == 0, "Expected rgbBlue = 0, got %#x, %s surface.\n",
8518 rgbquad.rgbBlue, test_data[i].name);
8519 ok(rgbquad.rgbReserved == 0, "Expected rgbReserved = 0, got %u, %s surface.\n",
8520 rgbquad.rgbReserved, test_data[i].name);
8521 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
8522 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
8524 IDirectDrawSurface7_Release(surface);
8527 /* Test INVALIDSURFACETYPE vs INVALIDPIXELFORMAT. */
8528 memset(&surface_desc, 0, sizeof(surface_desc));
8529 surface_desc.dwSize = sizeof(surface_desc);
8530 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
8531 surface_desc.dwWidth = 128;
8532 surface_desc.dwHeight = 128;
8533 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
8534 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
8535 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
8536 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
8537 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
8538 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
8539 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
8540 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8541 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8542 hr = IDirectDrawSurface7_SetPalette(surface, palette);
8543 ok(hr == DDERR_INVALIDSURFACETYPE, "Got unexpected hr %#x.\n", hr);
8544 IDirectDrawSurface7_Release(surface);
8546 /* The Windows 8 testbot keeps extra references to the primary
8547 * while in 8 bpp mode. */
8548 hr = IDirectDraw7_RestoreDisplayMode(ddraw);
8549 ok(SUCCEEDED(hr), "Failed to restore display mode, hr %#x.\n", hr);
8551 refcount = IDirectDrawPalette_Release(palette);
8552 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8553 refcount = IDirectDraw7_Release(ddraw);
8554 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8555 DestroyWindow(window);
8558 static void test_vb_writeonly(void)
8560 IDirect3DDevice7 *device;
8561 IDirect3D7 *d3d;
8562 IDirect3DVertexBuffer7 *buffer;
8563 HWND window;
8564 HRESULT hr;
8565 D3DVERTEXBUFFERDESC desc;
8566 void *ptr;
8567 static const struct vec4 quad[] =
8569 { 0.0f, 480.0f, 0.0f, 1.0f},
8570 { 0.0f, 0.0f, 0.0f, 1.0f},
8571 {640.0f, 480.0f, 0.0f, 1.0f},
8572 {640.0f, 0.0f, 0.0f, 1.0f},
8575 window = create_window();
8576 if (!(device = create_device(window, DDSCL_NORMAL)))
8578 skip("Failed to create a 3D device, skipping test.\n");
8579 DestroyWindow(window);
8580 return;
8583 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
8584 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
8586 memset(&desc, 0, sizeof(desc));
8587 desc.dwSize = sizeof(desc);
8588 desc.dwCaps = D3DVBCAPS_WRITEONLY;
8589 desc.dwFVF = D3DFVF_XYZRHW;
8590 desc.dwNumVertices = sizeof(quad) / sizeof(*quad);
8591 hr = IDirect3D7_CreateVertexBuffer(d3d, &desc, &buffer, 0);
8592 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
8594 hr = IDirect3DVertexBuffer7_Lock(buffer, DDLOCK_DISCARDCONTENTS, &ptr, NULL);
8595 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
8596 memcpy(ptr, quad, sizeof(quad));
8597 hr = IDirect3DVertexBuffer7_Unlock(buffer);
8598 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
8600 hr = IDirect3DDevice7_BeginScene(device);
8601 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
8602 hr = IDirect3DDevice7_DrawPrimitiveVB(device, D3DPT_TRIANGLESTRIP, buffer, 0, 4, 0);
8603 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
8604 hr = IDirect3DDevice7_EndScene(device);
8605 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
8607 hr = IDirect3DVertexBuffer7_Lock(buffer, 0, &ptr, NULL);
8608 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
8609 ok (!memcmp(ptr, quad, sizeof(quad)), "Got unexpected vertex buffer data.\n");
8610 hr = IDirect3DVertexBuffer7_Unlock(buffer);
8611 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
8613 hr = IDirect3DVertexBuffer7_Lock(buffer, DDLOCK_READONLY, &ptr, NULL);
8614 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
8615 ok (!memcmp(ptr, quad, sizeof(quad)), "Got unexpected vertex buffer data.\n");
8616 hr = IDirect3DVertexBuffer7_Unlock(buffer);
8617 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
8619 IDirect3DVertexBuffer7_Release(buffer);
8620 IDirect3D7_Release(d3d);
8621 IDirect3DDevice7_Release(device);
8622 DestroyWindow(window);
8625 static void test_lost_device(void)
8627 IDirectDrawSurface7 *surface;
8628 DDSURFACEDESC2 surface_desc;
8629 HWND window1, window2;
8630 IDirectDraw7 *ddraw;
8631 ULONG refcount;
8632 HRESULT hr;
8633 BOOL ret;
8635 window1 = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
8636 0, 0, 640, 480, 0, 0, 0, 0);
8637 window2 = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
8638 0, 0, 640, 480, 0, 0, 0, 0);
8639 ddraw = create_ddraw();
8640 ok(!!ddraw, "Failed to create a ddraw object.\n");
8641 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window1, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
8642 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
8644 memset(&surface_desc, 0, sizeof(surface_desc));
8645 surface_desc.dwSize = sizeof(surface_desc);
8646 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
8647 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
8648 U5(surface_desc).dwBackBufferCount = 1;
8649 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8650 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8652 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8653 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8654 hr = IDirectDrawSurface7_IsLost(surface);
8655 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8656 hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
8657 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8659 ret = SetForegroundWindow(GetDesktopWindow());
8660 ok(ret, "Failed to set foreground window.\n");
8661 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8662 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
8663 hr = IDirectDrawSurface7_IsLost(surface);
8664 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
8665 hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
8666 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
8668 ret = SetForegroundWindow(window1);
8669 ok(ret, "Failed to set foreground window.\n");
8670 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8671 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8672 hr = IDirectDrawSurface7_IsLost(surface);
8673 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
8674 hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
8675 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
8677 hr = IDirectDraw7_RestoreAllSurfaces(ddraw);
8678 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8679 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8680 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8681 hr = IDirectDrawSurface7_IsLost(surface);
8682 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8683 hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
8684 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8686 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window1, DDSCL_NORMAL);
8687 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8688 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8689 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8690 hr = IDirectDrawSurface7_IsLost(surface);
8691 todo_wine ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
8692 hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
8693 todo_wine ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
8695 /* Trying to restore the primary will crash, probably because flippable
8696 * surfaces can't exist in DDSCL_NORMAL. */
8697 IDirectDrawSurface7_Release(surface);
8698 memset(&surface_desc, 0, sizeof(surface_desc));
8699 surface_desc.dwSize = sizeof(surface_desc);
8700 surface_desc.dwFlags = DDSD_CAPS;
8701 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
8702 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8703 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8705 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8706 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8707 hr = IDirectDrawSurface7_IsLost(surface);
8708 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8710 ret = SetForegroundWindow(GetDesktopWindow());
8711 ok(ret, "Failed to set foreground window.\n");
8712 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8713 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8714 hr = IDirectDrawSurface7_IsLost(surface);
8715 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8717 ret = SetForegroundWindow(window1);
8718 ok(ret, "Failed to set foreground window.\n");
8719 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8720 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8721 hr = IDirectDrawSurface7_IsLost(surface);
8722 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8724 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window1, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
8725 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8726 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8727 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8728 hr = IDirectDrawSurface7_IsLost(surface);
8729 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
8731 hr = IDirectDraw7_RestoreAllSurfaces(ddraw);
8732 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8733 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8734 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8735 hr = IDirectDrawSurface7_IsLost(surface);
8736 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8738 IDirectDrawSurface7_Release(surface);
8739 memset(&surface_desc, 0, sizeof(surface_desc));
8740 surface_desc.dwSize = sizeof(surface_desc);
8741 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
8742 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
8743 U5(surface_desc).dwBackBufferCount = 1;
8744 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8745 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8747 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window1, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
8748 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8749 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8750 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8751 hr = IDirectDrawSurface7_IsLost(surface);
8752 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8753 hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
8754 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8756 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window1, DDSCL_NORMAL | DDSCL_FULLSCREEN);
8757 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8758 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8759 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8760 hr = IDirectDrawSurface7_IsLost(surface);
8761 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8762 hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
8763 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
8765 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window1, DDSCL_NORMAL);
8766 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8767 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8768 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8769 hr = IDirectDrawSurface7_IsLost(surface);
8770 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8771 hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
8772 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
8774 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window2, DDSCL_NORMAL);
8775 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8776 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8777 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8778 hr = IDirectDrawSurface7_IsLost(surface);
8779 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8780 hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
8781 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
8783 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window2, DDSCL_NORMAL | DDSCL_FULLSCREEN);
8784 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8785 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8786 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8787 hr = IDirectDrawSurface7_IsLost(surface);
8788 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8789 hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
8790 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
8792 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window2, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
8793 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8794 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8795 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8796 hr = IDirectDrawSurface7_IsLost(surface);
8797 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
8798 hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
8799 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
8801 IDirectDrawSurface7_Release(surface);
8802 refcount = IDirectDraw7_Release(ddraw);
8803 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8804 DestroyWindow(window2);
8805 DestroyWindow(window1);
8808 static void test_resource_priority(void)
8810 IDirectDrawSurface7 *surface, *mipmap;
8811 DDSURFACEDESC2 surface_desc;
8812 IDirectDraw7 *ddraw;
8813 ULONG refcount;
8814 HWND window;
8815 HRESULT hr;
8816 DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, {0}};
8817 DDCAPS hal_caps;
8818 DWORD needed_caps = DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_MIPMAP;
8819 unsigned int i;
8820 DWORD priority;
8821 static const struct
8823 DWORD caps, caps2;
8824 const char *name;
8825 HRESULT hr;
8826 /* SetPriority on offscreenplain surfaces crashes on AMD GPUs on Win7. */
8827 BOOL crash;
8829 test_data[] =
8831 {DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, 0, "vidmem texture", DDERR_INVALIDPARAMS, FALSE},
8832 {DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, 0, "sysmem texture", DDERR_INVALIDPARAMS, FALSE},
8833 {DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, "managed texture", DD_OK, FALSE},
8834 {DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, "managed texture", DD_OK, FALSE},
8835 {DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP,
8836 DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES | DDSCAPS2_TEXTUREMANAGE,
8837 "cubemap", DD_OK, FALSE},
8838 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0, "vidmem offscreenplain", DDERR_INVALIDOBJECT, TRUE},
8839 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY, 0, "sysmem offscreenplain", DDERR_INVALIDOBJECT, TRUE},
8842 window = create_window();
8843 ddraw = create_ddraw();
8844 ok(!!ddraw, "Failed to create a ddraw object.\n");
8845 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
8846 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
8848 memset(&hal_caps, 0, sizeof(hal_caps));
8849 hal_caps.dwSize = sizeof(hal_caps);
8850 hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, NULL);
8851 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
8852 if ((hal_caps.ddsCaps.dwCaps & needed_caps) != needed_caps
8853 || !(hal_caps.ddsCaps.dwCaps & DDSCAPS2_TEXTUREMANAGE))
8855 skip("Required surface types not supported, skipping test.\n");
8856 goto done;
8859 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); i++)
8861 memset(&surface_desc, 0, sizeof(surface_desc));
8862 surface_desc.dwSize = sizeof(surface_desc);
8863 surface_desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
8864 surface_desc.dwWidth = 32;
8865 surface_desc.dwHeight = 32;
8866 surface_desc.ddsCaps.dwCaps = test_data[i].caps;
8867 surface_desc.ddsCaps.dwCaps2 = test_data[i].caps2;
8868 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8869 if (is_ddraw64 && (test_data[i].caps & DDSCAPS_TEXTURE))
8871 todo_wine ok(hr == E_NOINTERFACE, "Got unexpected hr %#x, type %s.\n", hr, test_data[i].name);
8872 if (SUCCEEDED(hr))
8873 IDirectDrawSurface7_Release(surface);
8874 continue;
8876 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x, type %s.\n", hr, test_data[i].name);
8878 /* Priority == NULL segfaults. */
8879 priority = 0xdeadbeef;
8880 hr = IDirectDrawSurface7_GetPriority(surface, &priority);
8881 ok(hr == test_data[i].hr, "Got unexpected hr %#x, type %s.\n", hr, test_data[i].name);
8882 if (SUCCEEDED(test_data[i].hr))
8883 ok(priority == 0, "Got unexpected priority %u, type %s.\n", priority, test_data[i].name);
8884 else
8885 ok(priority == 0xdeadbeef, "Got unexpected priority %u, type %s.\n", priority, test_data[i].name);
8887 if (!test_data[i].crash)
8889 hr = IDirectDrawSurface7_SetPriority(surface, 1);
8890 ok(hr == test_data[i].hr, "Got unexpected hr %#x, type %s.\n", hr, test_data[i].name);
8891 hr = IDirectDrawSurface7_GetPriority(surface, &priority);
8892 ok(hr == test_data[i].hr, "Got unexpected hr %#x, type %s.\n", hr, test_data[i].name);
8893 if (SUCCEEDED(test_data[i].hr))
8895 ok(priority == 1, "Got unexpected priority %u, type %s.\n", priority, test_data[i].name);
8896 hr = IDirectDrawSurface7_SetPriority(surface, 2);
8897 ok(hr == test_data[i].hr, "Got unexpected hr %#x, type %s.\n", hr, test_data[i].name);
8899 else
8900 ok(priority == 0xdeadbeef, "Got unexpected priority %u, type %s.\n", priority, test_data[i].name);
8903 if (test_data[i].caps2 & DDSCAPS2_CUBEMAP)
8905 caps.dwCaps2 = DDSCAPS2_CUBEMAP_NEGATIVEZ;
8906 hr = IDirectDrawSurface7_GetAttachedSurface(surface, &caps, &mipmap);
8907 ok(SUCCEEDED(hr), "Failed to get attached surface, i %u, hr %#x.\n", i, hr);
8908 /* IDirectDrawSurface7_SetPriority crashes when called on non-positive X surfaces on Windows */
8909 priority = 0xdeadbeef;
8910 hr = IDirectDrawSurface7_GetPriority(mipmap, &priority);
8911 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x, type %s.\n", hr, test_data[i].name);
8912 ok(priority == 0xdeadbeef, "Got unexpected priority %u, type %s.\n", priority, test_data[i].name);
8914 IDirectDrawSurface7_Release(mipmap);
8917 IDirectDrawSurface7_Release(surface);
8920 if (is_ddraw64)
8921 goto done;
8923 memset(&surface_desc, 0, sizeof(surface_desc));
8924 surface_desc.dwSize = sizeof(surface_desc);
8925 surface_desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_MIPMAPCOUNT;
8926 surface_desc.dwWidth = 32;
8927 surface_desc.dwHeight = 32;
8928 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
8929 surface_desc.ddsCaps.dwCaps2 = DDSCAPS2_TEXTUREMANAGE;
8930 U2(surface_desc).dwMipMapCount = 2;
8931 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8932 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8933 caps.dwCaps2 = 0;
8934 hr = IDirectDrawSurface7_GetAttachedSurface(surface, &caps, &mipmap);
8935 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
8937 priority = 0xdeadbeef;
8938 hr = IDirectDrawSurface7_GetPriority(mipmap, &priority);
8939 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x, type managed mipmap.\n", hr);
8940 ok(priority == 0xdeadbeef, "Got unexpected priority %u, type managed mipmap.\n", priority);
8941 /* SetPriority on the mipmap surface crashes. */
8942 hr = IDirectDrawSurface7_GetPriority(surface, &priority);
8943 ok(SUCCEEDED(hr), "Failed to get priority, hr %#x.\n", hr);
8944 ok(priority == 0, "Got unexpected priority %u, type managed mipmap.\n", priority);
8946 IDirectDrawSurface7_Release(mipmap);
8947 refcount = IDirectDrawSurface7_Release(surface);
8948 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8950 done:
8951 refcount = IDirectDraw7_Release(ddraw);
8952 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8953 DestroyWindow(window);
8956 static void test_surface_desc_lock(void)
8958 IDirectDrawSurface7 *surface;
8959 DDSURFACEDESC2 surface_desc;
8960 IDirectDraw7 *ddraw;
8961 ULONG refcount;
8962 HWND window;
8963 HRESULT hr;
8965 window = create_window();
8966 ddraw = create_ddraw();
8967 ok(!!ddraw, "Failed to create a ddraw object.\n");
8968 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
8969 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
8971 memset(&surface_desc, 0, sizeof(surface_desc));
8972 surface_desc.dwSize = sizeof(surface_desc);
8973 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
8974 surface_desc.dwWidth = 16;
8975 surface_desc.dwHeight = 16;
8976 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
8977 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8978 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8980 memset(&surface_desc, 0xaa, sizeof(surface_desc));
8981 surface_desc.dwSize = sizeof(surface_desc);
8982 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &surface_desc);
8983 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
8984 ok(!surface_desc.lpSurface, "Got unexpected lpSurface %p.\n", surface_desc.lpSurface);
8986 memset(&surface_desc, 0xaa, sizeof(surface_desc));
8987 surface_desc.dwSize = sizeof(surface_desc);
8988 hr = IDirectDrawSurface7_Lock(surface, NULL, &surface_desc, 0, NULL);
8989 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
8990 ok(surface_desc.lpSurface != NULL, "Got unexpected lpSurface %p.\n", surface_desc.lpSurface);
8991 memset(&surface_desc, 0xaa, sizeof(surface_desc));
8992 surface_desc.dwSize = sizeof(surface_desc);
8993 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &surface_desc);
8994 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
8995 ok(!surface_desc.lpSurface, "Got unexpected lpSurface %p.\n", surface_desc.lpSurface);
8996 hr = IDirectDrawSurface7_Unlock(surface, NULL);
8997 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
8999 memset(&surface_desc, 0xaa, sizeof(surface_desc));
9000 surface_desc.dwSize = sizeof(surface_desc);
9001 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &surface_desc);
9002 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
9003 ok(!surface_desc.lpSurface, "Got unexpected lpSurface %p.\n", surface_desc.lpSurface);
9005 IDirectDrawSurface7_Release(surface);
9006 refcount = IDirectDraw7_Release(ddraw);
9007 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
9008 DestroyWindow(window);
9011 static void test_fog_interpolation(void)
9013 HRESULT hr;
9014 IDirect3DDevice7 *device;
9015 IDirectDrawSurface7 *rt;
9016 ULONG refcount;
9017 HWND window;
9018 D3DCOLOR color;
9019 static struct
9021 struct vec3 position;
9022 D3DCOLOR diffuse;
9023 D3DCOLOR specular;
9025 quad[] =
9027 {{-1.0f, -1.0f, 0.0f}, 0xffff0000, 0xff000000},
9028 {{-1.0f, 1.0f, 0.0f}, 0xffff0000, 0xff000000},
9029 {{ 1.0f, -1.0f, 1.0f}, 0xffff0000, 0x00000000},
9030 {{ 1.0f, 1.0f, 1.0f}, 0xffff0000, 0x00000000},
9032 union
9034 DWORD d;
9035 float f;
9036 } conv;
9037 unsigned int i;
9038 static const struct
9040 D3DFOGMODE vfog, tfog;
9041 D3DSHADEMODE shade;
9042 D3DCOLOR middle_color;
9043 BOOL todo;
9045 tests[] =
9047 {D3DFOG_NONE, D3DFOG_NONE, D3DSHADE_FLAT, 0x00007f80, FALSE},
9048 {D3DFOG_NONE, D3DFOG_NONE, D3DSHADE_GOURAUD, 0x00007f80, FALSE},
9049 {D3DFOG_EXP, D3DFOG_NONE, D3DSHADE_FLAT, 0x00007f80, TRUE},
9050 {D3DFOG_EXP, D3DFOG_NONE, D3DSHADE_GOURAUD, 0x00007f80, TRUE},
9051 {D3DFOG_NONE, D3DFOG_EXP, D3DSHADE_FLAT, 0x0000ea15, FALSE},
9052 {D3DFOG_NONE, D3DFOG_EXP, D3DSHADE_GOURAUD, 0x0000ea15, FALSE},
9053 {D3DFOG_EXP, D3DFOG_EXP, D3DSHADE_FLAT, 0x0000ea15, FALSE},
9054 {D3DFOG_EXP, D3DFOG_EXP, D3DSHADE_GOURAUD, 0x0000ea15, FALSE},
9056 D3DDEVICEDESC7 caps;
9058 window = create_window();
9059 if (!(device = create_device(window, DDSCL_NORMAL)))
9061 skip("Failed to create a 3D device, skipping test.\n");
9062 DestroyWindow(window);
9063 return;
9066 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
9067 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
9068 hr = IDirect3DDevice7_GetCaps(device, &caps);
9069 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
9070 if (!(caps.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGTABLE))
9071 skip("D3DPRASTERCAPS_FOGTABLE not supported, skipping some fog tests\n");
9073 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
9074 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9075 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, FALSE);
9076 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9077 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, TRUE);
9078 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9079 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGCOLOR, 0x0000ff00);
9080 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9081 conv.f = 5.0;
9082 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGDENSITY, conv.d);
9083 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9085 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
9086 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
9087 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TFACTOR);
9088 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
9089 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_TEXTUREFACTOR, 0x000000ff);
9090 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9092 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
9094 if(!(caps.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGTABLE) && tests[i].tfog)
9095 continue;
9097 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00808080, 0.0f, 0);
9098 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
9100 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_SHADEMODE, tests[i].shade);
9101 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9102 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGVERTEXMODE, tests[i].vfog);
9103 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9104 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGTABLEMODE, tests[i].tfog);
9105 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9106 hr = IDirect3DDevice7_BeginScene(device);
9107 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
9108 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
9109 D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_SPECULAR, quad, 4, 0);
9110 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9111 hr = IDirect3DDevice7_EndScene(device);
9112 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
9114 color = get_surface_color(rt, 0, 240);
9115 ok(compare_color(color, 0x000000ff, 2), "Got unexpected color 0x%08x, case %u.\n", color, i);
9116 color = get_surface_color(rt, 320, 240);
9117 todo_wine_if (tests[i].todo)
9118 ok(compare_color(color, tests[i].middle_color, 2),
9119 "Got unexpected color 0x%08x, case %u.\n", color, i);
9120 color = get_surface_color(rt, 639, 240);
9121 ok(compare_color(color, 0x0000fd02, 2), "Got unexpected color 0x%08x, case %u.\n", color, i);
9124 IDirectDrawSurface7_Release(rt);
9125 refcount = IDirect3DDevice7_Release(device);
9126 ok(!refcount, "Device has %u references left.\n", refcount);
9127 DestroyWindow(window);
9130 static void test_negative_fixedfunction_fog(void)
9132 HRESULT hr;
9133 IDirect3DDevice7 *device;
9134 IDirectDrawSurface7 *rt;
9135 ULONG refcount;
9136 HWND window;
9137 D3DCOLOR color;
9138 static struct
9140 struct vec3 position;
9141 D3DCOLOR diffuse;
9143 quad[] =
9145 {{-1.0f, -1.0f, -0.5f}, 0xffff0000},
9146 {{-1.0f, 1.0f, -0.5f}, 0xffff0000},
9147 {{ 1.0f, -1.0f, -0.5f}, 0xffff0000},
9148 {{ 1.0f, 1.0f, -0.5f}, 0xffff0000},
9150 static struct
9152 struct vec4 position;
9153 D3DCOLOR diffuse;
9155 tquad[] =
9157 {{ 0.0f, 0.0f, -0.5f, 1.0f}, 0xffff0000},
9158 {{640.0f, 0.0f, -0.5f, 1.0f}, 0xffff0000},
9159 {{ 0.0f, 480.0f, -0.5f, 1.0f}, 0xffff0000},
9160 {{640.0f, 480.0f, -0.5f, 1.0f}, 0xffff0000},
9162 unsigned int i;
9163 static D3DMATRIX zero =
9165 1.0f, 0.0f, 0.0f, 0.0f,
9166 0.0f, 1.0f, 0.0f, 0.0f,
9167 0.0f, 0.0f, 0.0f, 0.0f,
9168 0.0f, 0.0f, 0.0f, 1.0f
9170 static D3DMATRIX identity =
9172 1.0f, 0.0f, 0.0f, 0.0f,
9173 0.0f, 1.0f, 0.0f, 0.0f,
9174 0.0f, 0.0f, 1.0f, 0.0f,
9175 0.0f, 0.0f, 0.0f, 1.0f
9177 static const struct
9179 DWORD pos_type;
9180 void *quad;
9181 D3DMATRIX *matrix;
9182 union
9184 float f;
9185 DWORD d;
9186 } start, end;
9187 D3DFOGMODE vfog, tfog;
9188 DWORD color, color_broken, color_broken2;
9190 tests[] =
9192 /* Run the XYZRHW tests first. Depth clamping is broken after RHW draws on the testbot.
9194 * Geforce8+ GPUs on Windows abs() table fog, everything else does not. */
9195 {D3DFVF_XYZRHW, tquad, &identity, { 0.0f}, {1.0f}, D3DFOG_NONE, D3DFOG_LINEAR,
9196 0x00ff0000, 0x00808000, 0x00808000},
9197 /* r200 GPUs and presumably all d3d8 and older HW clamp the fog
9198 * parameters to 0.0 and 1.0 in the table fog case. */
9199 {D3DFVF_XYZRHW, tquad, &identity, {-1.0f}, {0.0f}, D3DFOG_NONE, D3DFOG_LINEAR,
9200 0x00808000, 0x00ff0000, 0x0000ff00},
9201 /* test_fog_interpolation shows that vertex fog evaluates the fog
9202 * equation in the vertex pipeline. Start = -1.0 && end = 0.0 shows
9203 * that the abs happens before the fog equation is evaluated.
9205 * Vertex fog abs() behavior is the same on all GPUs. */
9206 {D3DFVF_XYZ, quad, &zero, { 0.0f}, {1.0f}, D3DFOG_LINEAR, D3DFOG_NONE,
9207 0x00808000, 0x00808000, 0x00808000},
9208 {D3DFVF_XYZ, quad, &zero, {-1.0f}, {0.0f}, D3DFOG_LINEAR, D3DFOG_NONE,
9209 0x0000ff00, 0x0000ff00, 0x0000ff00},
9210 {D3DFVF_XYZ, quad, &zero, { 0.0f}, {1.0f}, D3DFOG_EXP, D3DFOG_NONE,
9211 0x009b6400, 0x009b6400, 0x009b6400},
9213 D3DDEVICEDESC7 caps;
9215 window = create_window();
9216 if (!(device = create_device(window, DDSCL_NORMAL)))
9218 skip("Failed to create a 3D device, skipping test.\n");
9219 DestroyWindow(window);
9220 return;
9223 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
9224 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
9225 hr = IDirect3DDevice7_GetCaps(device, &caps);
9226 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
9227 if (!(caps.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGTABLE))
9228 skip("D3DPRASTERCAPS_FOGTABLE not supported, skipping some fog tests.\n");
9230 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
9231 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9232 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
9233 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9234 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, TRUE);
9235 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9236 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGCOLOR, 0x0000ff00);
9237 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9238 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CLIPPING, FALSE);
9239 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
9241 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
9243 if (!(caps.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGTABLE) && tests[i].tfog)
9244 continue;
9246 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x000000ff, 0.0f, 0);
9247 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
9249 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, tests[i].matrix);
9250 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
9251 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGSTART, tests[i].start.d);
9252 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9253 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGEND, tests[i].end.d);
9254 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9255 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGVERTEXMODE, tests[i].vfog);
9256 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9257 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGTABLEMODE, tests[i].tfog);
9258 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9260 hr = IDirect3DDevice7_BeginScene(device);
9261 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
9262 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
9263 tests[i].pos_type | D3DFVF_DIFFUSE, tests[i].quad, 4, 0);
9264 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9265 hr = IDirect3DDevice7_EndScene(device);
9266 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
9268 color = get_surface_color(rt, 0, 240);
9269 ok(compare_color(color, tests[i].color, 2) || broken(compare_color(color, tests[i].color_broken, 2))
9270 || broken(compare_color(color, tests[i].color_broken2, 2)),
9271 "Got unexpected color 0x%08x, case %u.\n", color, i);
9274 IDirectDrawSurface7_Release(rt);
9275 refcount = IDirect3DDevice7_Release(device);
9276 ok(!refcount, "Device has %u references left.\n", refcount);
9277 DestroyWindow(window);
9280 static void test_table_fog_zw(void)
9282 HRESULT hr;
9283 IDirect3DDevice7 *device;
9284 IDirectDrawSurface7 *rt;
9285 ULONG refcount;
9286 HWND window;
9287 D3DCOLOR color;
9288 static struct
9290 struct vec4 position;
9291 D3DCOLOR diffuse;
9293 quad[] =
9295 {{ 0.0f, 0.0f, 0.0f, 0.0f}, 0xffff0000},
9296 {{640.0f, 0.0f, 0.0f, 0.0f}, 0xffff0000},
9297 {{ 0.0f, 480.0f, 0.0f, 0.0f}, 0xffff0000},
9298 {{640.0f, 480.0f, 0.0f, 0.0f}, 0xffff0000},
9300 static D3DMATRIX identity =
9302 1.0f, 0.0f, 0.0f, 0.0f,
9303 0.0f, 1.0f, 0.0f, 0.0f,
9304 0.0f, 0.0f, 1.0f, 0.0f,
9305 0.0f, 0.0f, 0.0f, 1.0f
9307 D3DDEVICEDESC7 caps;
9308 static const struct
9310 float z, w;
9311 D3DZBUFFERTYPE z_test;
9312 D3DCOLOR color;
9314 tests[] =
9316 {0.7f, 0.0f, D3DZB_TRUE, 0x004cb200},
9317 {0.7f, 0.0f, D3DZB_FALSE, 0x004cb200},
9318 {0.7f, 0.3f, D3DZB_TRUE, 0x004cb200},
9319 {0.7f, 0.3f, D3DZB_FALSE, 0x004cb200},
9320 {0.7f, 3.0f, D3DZB_TRUE, 0x004cb200},
9321 {0.7f, 3.0f, D3DZB_FALSE, 0x004cb200},
9322 {0.3f, 0.0f, D3DZB_TRUE, 0x00b24c00},
9323 {0.3f, 0.0f, D3DZB_FALSE, 0x00b24c00},
9325 unsigned int i;
9327 window = create_window();
9328 if (!(device = create_device(window, DDSCL_NORMAL)))
9330 skip("Failed to create a 3D device, skipping test.\n");
9331 DestroyWindow(window);
9332 return;
9335 hr = IDirect3DDevice7_GetCaps(device, &caps);
9336 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
9337 if (!(caps.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGTABLE))
9339 skip("D3DPRASTERCAPS_FOGTABLE not supported, skipping POSITIONT table fog test.\n");
9340 goto done;
9342 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
9343 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
9345 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
9346 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9347 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, TRUE);
9348 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9349 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGCOLOR, 0x0000ff00);
9350 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9351 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CLIPPING, FALSE);
9352 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
9353 /* Work around an AMD Windows driver bug. Needs a proj matrix applied redundantly. */
9354 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &identity);
9355 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
9356 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGTABLEMODE, D3DFOG_LINEAR);
9357 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9359 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
9361 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x000000ff, 1.0f, 0);
9362 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
9364 quad[0].position.z = tests[i].z;
9365 quad[1].position.z = tests[i].z;
9366 quad[2].position.z = tests[i].z;
9367 quad[3].position.z = tests[i].z;
9368 quad[0].position.w = tests[i].w;
9369 quad[1].position.w = tests[i].w;
9370 quad[2].position.w = tests[i].w;
9371 quad[3].position.w = tests[i].w;
9372 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, tests[i].z_test);
9373 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9375 hr = IDirect3DDevice7_BeginScene(device);
9376 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
9377 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
9378 D3DFVF_XYZRHW | D3DFVF_DIFFUSE, quad, 4, 0);
9379 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9380 hr = IDirect3DDevice7_EndScene(device);
9381 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
9383 color = get_surface_color(rt, 0, 240);
9384 ok(compare_color(color, tests[i].color, 2),
9385 "Got unexpected color 0x%08x, expected 0x%8x, case %u.\n", color, tests[i].color, i);
9388 IDirectDrawSurface7_Release(rt);
9389 done:
9390 refcount = IDirect3DDevice7_Release(device);
9391 ok(!refcount, "Device has %u references left.\n", refcount);
9392 DestroyWindow(window);
9395 static void test_signed_formats(void)
9397 HRESULT hr;
9398 IDirect3DDevice7 *device;
9399 IDirect3D7 *d3d;
9400 IDirectDraw7 *ddraw;
9401 IDirectDrawSurface7 *surface, *rt;
9402 DDSURFACEDESC2 surface_desc;
9403 ULONG refcount;
9404 HWND window;
9405 D3DCOLOR color, expected_color;
9406 static struct
9408 struct vec3 position;
9409 struct vec2 texcoord;
9411 quad[] =
9413 {{-1.0f, -1.0f, 0.0f}, {0.0f, 1.0f}},
9414 {{-1.0f, 1.0f, 0.0f}, {0.0f, 0.0f}},
9415 {{ 1.0f, -1.0f, 0.0f}, {1.0f, 1.0f}},
9416 {{ 1.0f, 1.0f, 0.0f}, {1.0f, 0.0f}},
9418 /* See test_signed_formats() in dlls/d3d9/tests/visual.c for an explanation
9419 * of these values. */
9420 static const USHORT content_v8u8[4][4] =
9422 {0x0000, 0x7f7f, 0x8880, 0x0000},
9423 {0x0080, 0x8000, 0x7f00, 0x007f},
9424 {0x193b, 0xe8c8, 0x0808, 0xf8f8},
9425 {0x4444, 0xc0c0, 0xa066, 0x22e0},
9427 static const DWORD content_x8l8v8u8[4][4] =
9429 {0x00000000, 0x00ff7f7f, 0x00008880, 0x00ff0000},
9430 {0x00000080, 0x00008000, 0x00007f00, 0x0000007f},
9431 {0x0041193b, 0x0051e8c8, 0x00040808, 0x00fff8f8},
9432 {0x00824444, 0x0000c0c0, 0x00c2a066, 0x009222e0},
9434 static const USHORT content_l6v5u5[4][4] =
9436 {0x0000, 0xfdef, 0x0230, 0xfc00},
9437 {0x0010, 0x0200, 0x01e0, 0x000f},
9438 {0x4067, 0x53b9, 0x0421, 0xffff},
9439 {0x8108, 0x0318, 0xc28c, 0x909c},
9441 static const struct
9443 const char *name;
9444 const void *content;
9445 SIZE_T pixel_size;
9446 BOOL blue;
9447 unsigned int slop, slop_broken;
9448 DDPIXELFORMAT format;
9450 formats[] =
9453 "D3DFMT_V8U8", content_v8u8, sizeof(WORD), FALSE, 1, 0,
9455 sizeof(DDPIXELFORMAT), DDPF_BUMPDUDV, 0,
9456 {16}, {0x000000ff}, {0x0000ff00}, {0x00000000}, {0x00000000}
9460 "D3DFMT_X8L8V8U8", content_x8l8v8u8, sizeof(DWORD), TRUE, 1, 0,
9462 sizeof(DDPIXELFORMAT), DDPF_BUMPDUDV | DDPF_BUMPLUMINANCE, 0,
9463 {32}, {0x000000ff}, {0x0000ff00}, {0x00ff0000}, {0x00000000}
9467 "D3DFMT_L6V5U5", content_l6v5u5, sizeof(WORD), TRUE, 4, 7,
9469 sizeof(DDPIXELFORMAT), DDPF_BUMPDUDV | DDPF_BUMPLUMINANCE, 0,
9470 {16}, {0x0000001f}, {0x000003e0}, {0x0000fc00}, {0x00000000}
9474 /* No V16U16 or Q8W8V8U8 support in ddraw. */
9476 static const D3DCOLOR expected_colors[4][4] =
9478 {0x00808080, 0x00fefeff, 0x00010780, 0x008080ff},
9479 {0x00018080, 0x00800180, 0x0080fe80, 0x00fe8080},
9480 {0x00ba98a0, 0x004767a8, 0x00888881, 0x007878ff},
9481 {0x00c3c3c0, 0x003f3f80, 0x00e51fe1, 0x005fa2c8},
9483 unsigned int i, width, x, y;
9484 D3DDEVICEDESC7 device_desc;
9486 window = create_window();
9487 if (!(device = create_device(window, DDSCL_NORMAL)))
9489 skip("Failed to create a 3D device, skipping test.\n");
9490 DestroyWindow(window);
9491 return;
9494 hr = IDirect3DDevice7_GetCaps(device, &device_desc);
9495 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
9496 if (!(device_desc.dwTextureOpCaps & D3DTEXOPCAPS_BLENDFACTORALPHA))
9498 skip("D3DTOP_BLENDFACTORALPHA not supported, skipping bumpmap format tests.\n");
9499 goto done;
9502 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
9503 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
9504 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
9505 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
9506 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
9507 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
9509 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
9510 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9512 /* dst = tex * 0.5 + 1.0 * (1.0 - 0.5) = tex * 0.5 + 0.5 */
9513 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_TEXTUREFACTOR, 0x80ffffff);
9514 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9515 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_BLENDFACTORALPHA);
9516 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
9517 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
9518 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
9519 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLORARG2, D3DTA_TFACTOR);
9520 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
9522 for (i = 0; i < sizeof(formats) / sizeof(*formats); i++)
9524 for (width = 1; width < 5; width += 3)
9526 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00000000, 0.0f, 0);
9527 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
9529 memset(&surface_desc, 0, sizeof(surface_desc));
9530 surface_desc.dwSize = sizeof(surface_desc);
9531 surface_desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS;
9532 surface_desc.dwWidth = width;
9533 surface_desc.dwHeight = 4;
9534 U4(surface_desc).ddpfPixelFormat = formats[i].format;
9535 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY;
9536 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
9537 if (FAILED(hr))
9539 skip("%s textures not supported, skipping.\n", formats[i].name);
9540 continue;
9542 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x, format %s.\n", hr, formats[i].name);
9543 hr = IDirect3DDevice7_SetTexture(device, 0, surface);
9544 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x, format %s.\n", hr, formats[i].name);
9546 memset(&surface_desc, 0, sizeof(surface_desc));
9547 surface_desc.dwSize = sizeof(surface_desc);
9548 hr = IDirectDrawSurface7_Lock(surface, NULL, &surface_desc, 0, NULL);
9549 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x, format %s.\n", hr, formats[i].name);
9550 for (y = 0; y < 4; y++)
9552 memcpy((char *)surface_desc.lpSurface + y * U1(surface_desc).lPitch,
9553 (char *)formats[i].content + y * 4 * formats[i].pixel_size,
9554 width * formats[i].pixel_size);
9556 hr = IDirectDrawSurface7_Unlock(surface, NULL);
9557 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, format %s.\n", hr, formats[i].name);
9559 hr = IDirect3DDevice7_BeginScene(device);
9560 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
9561 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
9562 D3DFVF_XYZ | D3DFVF_TEX1, quad, 4, 0);
9563 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9564 hr = IDirect3DDevice7_EndScene(device);
9565 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
9567 for (y = 0; y < 4; y++)
9569 for (x = 0; x < width; x++)
9571 expected_color = expected_colors[y][x];
9572 if (!formats[i].blue)
9573 expected_color |= 0x000000ff;
9575 color = get_surface_color(rt, 80 + 160 * x, 60 + 120 * y);
9576 ok(compare_color(color, expected_color, formats[i].slop)
9577 || broken(compare_color(color, expected_color, formats[i].slop_broken)),
9578 "Expected color 0x%08x, got 0x%08x, format %s, location %ux%u.\n",
9579 expected_color, color, formats[i].name, x, y);
9583 IDirectDrawSurface7_Release(surface);
9588 IDirectDrawSurface7_Release(rt);
9589 IDirectDraw7_Release(ddraw);
9590 IDirect3D7_Release(d3d);
9592 done:
9593 refcount = IDirect3DDevice7_Release(device);
9594 ok(!refcount, "Device has %u references left.\n", refcount);
9595 DestroyWindow(window);
9598 static void test_color_fill(void)
9600 HRESULT hr;
9601 IDirect3DDevice7 *device;
9602 IDirect3D7 *d3d;
9603 IDirectDraw7 *ddraw;
9604 IDirectDrawSurface7 *surface, *surface2;
9605 DDSURFACEDESC2 surface_desc;
9606 DDPIXELFORMAT z_fmt;
9607 ULONG refcount;
9608 HWND window;
9609 unsigned int i;
9610 DDBLTFX fx;
9611 RECT rect = {5, 5, 7, 7};
9612 DWORD *color;
9613 DWORD supported_fmts = 0, num_fourcc_codes, *fourcc_codes;
9614 DDCAPS hal_caps;
9615 static const struct
9617 DWORD caps, caps2;
9618 HRESULT colorfill_hr, depthfill_hr;
9619 BOOL rop_success;
9620 const char *name;
9621 DWORD result;
9622 BOOL check_result;
9623 DDPIXELFORMAT format;
9625 tests[] =
9628 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0,
9629 DD_OK, DDERR_INVALIDPARAMS, TRUE, "vidmem offscreenplain RGB", 0xdeadbeef, TRUE,
9631 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
9632 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9636 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY, 0,
9637 DD_OK, DDERR_INVALIDPARAMS, TRUE, "sysmem offscreenplain RGB", 0xdeadbeef, TRUE,
9639 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
9640 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9644 DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, 0,
9645 DD_OK, DDERR_INVALIDPARAMS, TRUE, "vidmem texture RGB", 0xdeadbeef, TRUE,
9647 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
9648 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9652 DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, 0,
9653 DD_OK, DDERR_INVALIDPARAMS, TRUE, "sysmem texture RGB", 0xdeadbeef, TRUE,
9655 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
9656 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9660 DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE,
9661 DD_OK, DDERR_INVALIDPARAMS, TRUE, "managed texture RGB", 0xdeadbeef, TRUE,
9663 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
9664 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9668 DDSCAPS_ZBUFFER | DDSCAPS_VIDEOMEMORY, 0,
9669 DDERR_INVALIDPARAMS, DD_OK, TRUE, "vidmem zbuffer", 0xdeadbeef, TRUE,
9670 {0, 0, 0, {0}, {0}, {0}, {0}, {0}}
9673 DDSCAPS_ZBUFFER | DDSCAPS_SYSTEMMEMORY, 0,
9674 DDERR_INVALIDPARAMS, DD_OK, TRUE, "sysmem zbuffer", 0xdeadbeef, TRUE,
9675 {0, 0, 0, {0}, {0}, {0}, {0}, {0}}
9678 /* Colorfill on YUV surfaces always returns DD_OK, but the content is
9679 * different afterwards. DX9+ GPUs set one of the two luminance values
9680 * in each block, but AMD and Nvidia GPUs disagree on which luminance
9681 * value they set. r200 (dx8) just sets the entire block to the clear
9682 * value. */
9683 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0,
9684 DD_OK, DDERR_INVALIDPARAMS, FALSE, "vidmem offscreenplain YUY2", 0, FALSE,
9686 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y', 'U', 'Y', '2'),
9687 {0}, {0}, {0}, {0}, {0}
9691 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0,
9692 DD_OK, DDERR_INVALIDPARAMS, FALSE, "vidmem offscreenplain UYVY", 0, FALSE,
9694 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('U', 'Y', 'V', 'Y'),
9695 {0}, {0}, {0}, {0}, {0}
9699 DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY, 0,
9700 DD_OK, DDERR_INVALIDPARAMS, FALSE, "vidmem overlay YUY2", 0, FALSE,
9702 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y', 'U', 'Y', '2'),
9703 {0}, {0}, {0}, {0}, {0}
9707 DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY, 0,
9708 DD_OK, DDERR_INVALIDPARAMS, FALSE, "vidmem overlay UYVY", 0, FALSE,
9710 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('U', 'Y', 'V', 'Y'),
9711 {0}, {0}, {0}, {0}, {0}
9715 DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, 0,
9716 E_NOTIMPL, DDERR_INVALIDPARAMS, FALSE, "vidmem texture DXT1", 0, FALSE,
9718 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('D', 'X', 'T', '1'),
9719 {0}, {0}, {0}, {0}, {0}
9723 DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, 0,
9724 E_NOTIMPL, DDERR_INVALIDPARAMS, FALSE, "sysmem texture DXT1", 0, FALSE,
9726 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('D', 'X', 'T', '1'),
9727 {0}, {0}, {0}, {0}, {0}
9731 /* The testbot fills this with 0x00 instead of the blue channel. The sysmem
9732 * surface works, presumably because it is handled by the runtime instead of
9733 * the driver. */
9734 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0,
9735 DD_OK, DDERR_INVALIDPARAMS, TRUE, "vidmem offscreenplain P8", 0xefefefef, FALSE,
9737 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_PALETTEINDEXED8, 0,
9738 {8}, {0}, {0}, {0}, {0}
9742 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY, 0,
9743 DD_OK, DDERR_INVALIDPARAMS, TRUE, "sysmem offscreenplain P8", 0xefefefef, TRUE,
9745 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_PALETTEINDEXED8, 0,
9746 {8}, {0}, {0}, {0}, {0}
9750 static const struct
9752 DWORD rop;
9753 const char *name;
9754 HRESULT hr;
9756 rops[] =
9758 {SRCCOPY, "SRCCOPY", DD_OK},
9759 {SRCPAINT, "SRCPAINT", DDERR_NORASTEROPHW},
9760 {SRCAND, "SRCAND", DDERR_NORASTEROPHW},
9761 {SRCINVERT, "SRCINVERT", DDERR_NORASTEROPHW},
9762 {SRCERASE, "SRCERASE", DDERR_NORASTEROPHW},
9763 {NOTSRCCOPY, "NOTSRCCOPY", DDERR_NORASTEROPHW},
9764 {NOTSRCERASE, "NOTSRCERASE", DDERR_NORASTEROPHW},
9765 {MERGECOPY, "MERGECOPY", DDERR_NORASTEROPHW},
9766 {MERGEPAINT, "MERGEPAINT", DDERR_NORASTEROPHW},
9767 {PATCOPY, "PATCOPY", DDERR_NORASTEROPHW},
9768 {PATPAINT, "PATPAINT", DDERR_NORASTEROPHW},
9769 {PATINVERT, "PATINVERT", DDERR_NORASTEROPHW},
9770 {DSTINVERT, "DSTINVERT", DDERR_NORASTEROPHW},
9771 {BLACKNESS, "BLACKNESS", DD_OK},
9772 {WHITENESS, "WHITENESS", DD_OK},
9773 {0xaa0029, "0xaa0029", DDERR_NORASTEROPHW} /* noop */
9776 window = create_window();
9777 if (!(device = create_device(window, DDSCL_NORMAL)))
9779 skip("Failed to create a 3D device, skipping test.\n");
9780 DestroyWindow(window);
9781 return;
9784 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
9785 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
9786 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
9787 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
9789 memset(&z_fmt, 0, sizeof(z_fmt));
9790 IDirect3D7_EnumZBufferFormats(d3d, &IID_IDirect3DHALDevice, enum_z_fmt, &z_fmt);
9791 if (!z_fmt.dwSize)
9792 skip("No Z buffer formats supported, skipping Z buffer colorfill test.\n");
9794 IDirect3DDevice7_EnumTextureFormats(device, test_block_formats_creation_cb, &supported_fmts);
9795 if (!(supported_fmts & SUPPORT_DXT1))
9796 skip("DXT1 textures not supported, skipping DXT1 colorfill test.\n");
9798 IDirect3D7_Release(d3d);
9800 hr = IDirectDraw7_GetFourCCCodes(ddraw, &num_fourcc_codes, NULL);
9801 ok(SUCCEEDED(hr), "Failed to get fourcc codes %#x.\n", hr);
9802 fourcc_codes = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
9803 num_fourcc_codes * sizeof(*fourcc_codes));
9804 if (!fourcc_codes)
9805 goto done;
9806 hr = IDirectDraw7_GetFourCCCodes(ddraw, &num_fourcc_codes, fourcc_codes);
9807 ok(SUCCEEDED(hr), "Failed to get fourcc codes %#x.\n", hr);
9808 for (i = 0; i < num_fourcc_codes; i++)
9810 if (fourcc_codes[i] == MAKEFOURCC('Y', 'U', 'Y', '2'))
9811 supported_fmts |= SUPPORT_YUY2;
9812 else if (fourcc_codes[i] == MAKEFOURCC('U', 'Y', 'V', 'Y'))
9813 supported_fmts |= SUPPORT_UYVY;
9815 HeapFree(GetProcessHeap(), 0, fourcc_codes);
9817 memset(&hal_caps, 0, sizeof(hal_caps));
9818 hal_caps.dwSize = sizeof(hal_caps);
9819 hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, NULL);
9820 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
9822 if (!(supported_fmts & (SUPPORT_YUY2 | SUPPORT_UYVY)) || !(hal_caps.dwCaps & DDCAPS_OVERLAY))
9823 skip("Overlays or some YUV formats not supported, skipping YUV colorfill tests.\n");
9825 for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++)
9827 DWORD expected_broken = tests[i].result;
9829 /* Some Windows drivers modify dwFillColor when it is used on P8 or FourCC formats. */
9830 memset(&fx, 0, sizeof(fx));
9831 fx.dwSize = sizeof(fx);
9832 U5(fx).dwFillColor = 0xdeadbeef;
9834 memset(&surface_desc, 0, sizeof(surface_desc));
9835 surface_desc.dwSize = sizeof(surface_desc);
9836 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
9837 surface_desc.dwWidth = 64;
9838 surface_desc.dwHeight = 64;
9839 U4(surface_desc).ddpfPixelFormat = tests[i].format;
9840 surface_desc.ddsCaps.dwCaps = tests[i].caps;
9841 surface_desc.ddsCaps.dwCaps2 = tests[i].caps2;
9843 if (tests[i].format.dwFourCC == MAKEFOURCC('D','X','T','1') && !(supported_fmts & SUPPORT_DXT1))
9844 continue;
9845 if (tests[i].format.dwFourCC == MAKEFOURCC('Y','U','Y','2') && !(supported_fmts & SUPPORT_YUY2))
9846 continue;
9847 if (tests[i].format.dwFourCC == MAKEFOURCC('U','Y','V','Y') && !(supported_fmts & SUPPORT_UYVY))
9848 continue;
9849 if (tests[i].caps & DDSCAPS_OVERLAY && !(hal_caps.dwCaps & DDCAPS_OVERLAY))
9850 continue;
9852 if (tests[i].caps & DDSCAPS_ZBUFFER)
9854 if (!z_fmt.dwSize)
9855 continue;
9857 U4(surface_desc).ddpfPixelFormat = z_fmt;
9858 /* Some drivers seem to convert depth values incorrectly or not at
9859 * all. Affects at least AMD PALM, 8.17.10.1247. */
9860 if (tests[i].caps & DDSCAPS_VIDEOMEMORY)
9862 DWORD expected;
9863 float f, g;
9865 expected = tests[i].result & U3(z_fmt).dwZBitMask;
9866 f = ceilf(log2f(expected + 1.0f));
9867 g = (f + 1.0f) / 2.0f;
9868 g -= (int)g;
9869 expected_broken = (expected / exp2f(f) - g) * 256;
9870 expected_broken *= 0x01010101;
9874 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
9875 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x, surface %s.\n", hr, tests[i].name);
9877 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
9878 todo_wine_if (tests[i].format.dwFourCC)
9879 ok(hr == tests[i].colorfill_hr, "Blt returned %#x, expected %#x, surface %s.\n",
9880 hr, tests[i].colorfill_hr, tests[i].name);
9882 hr = IDirectDrawSurface7_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
9883 todo_wine_if (tests[i].format.dwFourCC)
9884 ok(hr == tests[i].colorfill_hr, "Blt returned %#x, expected %#x, surface %s.\n",
9885 hr, tests[i].colorfill_hr, tests[i].name);
9887 if (SUCCEEDED(hr) && tests[i].check_result)
9889 memset(&surface_desc, 0, sizeof(surface_desc));
9890 surface_desc.dwSize = sizeof(surface_desc);
9891 hr = IDirectDrawSurface7_Lock(surface, NULL, &surface_desc, DDLOCK_READONLY, 0);
9892 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x, surface %s.\n", hr, tests[i].name);
9893 color = surface_desc.lpSurface;
9894 ok(*color == tests[i].result, "Got clear result 0x%08x, expected 0x%08x, surface %s.\n",
9895 *color, tests[i].result, tests[i].name);
9896 hr = IDirectDrawSurface7_Unlock(surface, NULL);
9897 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, surface %s.\n", hr, tests[i].name);
9900 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
9901 ok(hr == tests[i].depthfill_hr, "Blt returned %#x, expected %#x, surface %s.\n",
9902 hr, tests[i].depthfill_hr, tests[i].name);
9903 hr = IDirectDrawSurface7_Blt(surface, &rect, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
9904 ok(hr == tests[i].depthfill_hr, "Blt returned %#x, expected %#x, surface %s.\n",
9905 hr, tests[i].depthfill_hr, tests[i].name);
9907 if (SUCCEEDED(hr) && tests[i].check_result)
9909 memset(&surface_desc, 0, sizeof(surface_desc));
9910 surface_desc.dwSize = sizeof(surface_desc);
9911 hr = IDirectDrawSurface7_Lock(surface, NULL, &surface_desc, DDLOCK_READONLY, 0);
9912 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x, surface %s.\n", hr, tests[i].name);
9913 color = surface_desc.lpSurface;
9914 ok((*color & U3(z_fmt).dwZBitMask) == (tests[i].result & U3(z_fmt).dwZBitMask)
9915 || broken((*color & U3(z_fmt).dwZBitMask) == (expected_broken & U3(z_fmt).dwZBitMask)),
9916 "Got clear result 0x%08x, expected 0x%08x, surface %s.\n",
9917 *color & U3(z_fmt).dwZBitMask, tests[i].result & U3(z_fmt).dwZBitMask, tests[i].name);
9918 hr = IDirectDrawSurface7_Unlock(surface, NULL);
9919 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, surface %s.\n", hr, tests[i].name);
9922 U5(fx).dwFillColor = 0xdeadbeef;
9923 fx.dwROP = BLACKNESS;
9924 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_ROP | DDBLT_WAIT, &fx);
9925 ok(FAILED(hr) == !tests[i].rop_success, "Blt returned %#x, expected %s, surface %s.\n",
9926 hr, tests[i].rop_success ? "success" : "failure", tests[i].name);
9927 ok(U5(fx).dwFillColor == 0xdeadbeef, "dwFillColor was set to 0x%08x, surface %s\n",
9928 U5(fx).dwFillColor, tests[i].name);
9930 if (SUCCEEDED(hr) && tests[i].check_result)
9932 memset(&surface_desc, 0, sizeof(surface_desc));
9933 surface_desc.dwSize = sizeof(surface_desc);
9934 hr = IDirectDrawSurface7_Lock(surface, NULL, &surface_desc, DDLOCK_READONLY, 0);
9935 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x, surface %s.\n", hr, tests[i].name);
9936 color = surface_desc.lpSurface;
9937 ok(*color == 0, "Got clear result 0x%08x, expected 0x00000000, surface %s.\n",
9938 *color, tests[i].name);
9939 hr = IDirectDrawSurface7_Unlock(surface, NULL);
9940 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, surface %s.\n", hr, tests[i].name);
9943 fx.dwROP = WHITENESS;
9944 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_ROP | DDBLT_WAIT, &fx);
9945 ok(FAILED(hr) == !tests[i].rop_success, "Blt returned %#x, expected %s, surface %s.\n",
9946 hr, tests[i].rop_success ? "success" : "failure", tests[i].name);
9947 ok(U5(fx).dwFillColor == 0xdeadbeef, "dwFillColor was set to 0x%08x, surface %s\n",
9948 U5(fx).dwFillColor, tests[i].name);
9950 if (SUCCEEDED(hr) && tests[i].check_result)
9952 memset(&surface_desc, 0, sizeof(surface_desc));
9953 surface_desc.dwSize = sizeof(surface_desc);
9954 hr = IDirectDrawSurface7_Lock(surface, NULL, &surface_desc, DDLOCK_READONLY, 0);
9955 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x, surface %s.\n", hr, tests[i].name);
9956 color = surface_desc.lpSurface;
9957 /* WHITENESS sets the alpha channel to 0x00. Ignore this for now. */
9958 ok((*color & 0x00ffffff) == 0x00ffffff, "Got clear result 0x%08x, expected 0xffffffff, surface %s.\n",
9959 *color, tests[i].name);
9960 hr = IDirectDrawSurface7_Unlock(surface, NULL);
9961 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, surface %s.\n", hr, tests[i].name);
9964 IDirectDrawSurface7_Release(surface);
9967 memset(&fx, 0, sizeof(fx));
9968 fx.dwSize = sizeof(fx);
9969 U5(fx).dwFillColor = 0xdeadbeef;
9970 fx.dwROP = WHITENESS;
9972 memset(&surface_desc, 0, sizeof(surface_desc));
9973 surface_desc.dwSize = sizeof(surface_desc);
9974 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
9975 surface_desc.dwWidth = 64;
9976 surface_desc.dwHeight = 64;
9977 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
9978 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
9979 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
9980 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
9981 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
9982 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
9983 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
9984 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
9985 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
9986 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface2, NULL);
9987 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
9989 /* No DDBLTFX. */
9990 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_COLORFILL | DDBLT_WAIT, NULL);
9991 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
9992 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_ROP | DDBLT_WAIT, NULL);
9993 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
9995 /* Unused source rectangle. */
9996 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
9997 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
9998 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_ROP | DDBLT_WAIT, &fx);
9999 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10001 /* Unused source surface. */
10002 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
10003 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10004 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, NULL, DDBLT_ROP | DDBLT_WAIT, &fx);
10005 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10006 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
10007 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10008 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, &rect, DDBLT_ROP | DDBLT_WAIT, &fx);
10009 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10011 /* Inverted destination or source rectangle. */
10012 SetRect(&rect, 5, 7, 7, 5);
10013 hr = IDirectDrawSurface7_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
10014 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
10015 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
10016 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10017 hr = IDirectDrawSurface7_Blt(surface, &rect, surface2, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
10018 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10019 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
10020 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10021 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, &rect, DDBLT_ROP | DDBLT_WAIT, &fx);
10022 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
10024 /* Negative rectangle. */
10025 SetRect(&rect, -1, -1, 5, 5);
10026 hr = IDirectDrawSurface7_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
10027 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
10028 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
10029 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10030 hr = IDirectDrawSurface7_Blt(surface, &rect, surface2, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
10031 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10032 hr = IDirectDrawSurface7_Blt(surface, &rect, surface2, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
10033 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10034 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, &rect, DDBLT_ROP | DDBLT_WAIT, &fx);
10035 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
10037 /* Out of bounds rectangle. */
10038 SetRect(&rect, 0, 0, 65, 65);
10039 hr = IDirectDrawSurface7_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
10040 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
10041 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, &rect, DDBLT_ROP | DDBLT_WAIT, &fx);
10042 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
10044 /* Combine multiple flags. */
10045 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
10046 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10047 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_ROP | DDBLT_WAIT, &fx);
10048 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10049 hr = IDirectDrawSurface7_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_ROP | DDBLT_WAIT, &fx);
10050 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10052 for (i = 0; i < sizeof(rops) / sizeof(*rops); i++)
10054 fx.dwROP = rops[i].rop;
10055 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, NULL, DDBLT_ROP | DDBLT_WAIT, &fx);
10056 ok(hr == rops[i].hr, "Got unexpected hr %#x for rop %s.\n", hr, rops[i].name);
10059 IDirectDrawSurface7_Release(surface2);
10060 IDirectDrawSurface7_Release(surface);
10062 if (!z_fmt.dwSize)
10063 goto done;
10065 memset(&surface_desc, 0, sizeof(surface_desc));
10066 surface_desc.dwSize = sizeof(surface_desc);
10067 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
10068 surface_desc.dwWidth = 64;
10069 surface_desc.dwHeight = 64;
10070 U4(surface_desc).ddpfPixelFormat = z_fmt;
10071 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
10072 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
10073 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
10074 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface2, NULL);
10075 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
10077 /* No DDBLTFX. */
10078 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, NULL);
10079 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10081 /* Unused source rectangle. */
10082 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
10083 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10085 /* Unused source surface. */
10086 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
10087 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10088 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
10089 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10091 /* Inverted destination or source rectangle. */
10092 SetRect(&rect, 5, 7, 7, 5);
10093 hr = IDirectDrawSurface7_Blt(surface, &rect, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
10094 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
10095 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
10096 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10097 hr = IDirectDrawSurface7_Blt(surface, &rect, surface2, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
10098 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10099 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
10100 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10102 /* Negative rectangle. */
10103 SetRect(&rect, -1, -1, 5, 5);
10104 hr = IDirectDrawSurface7_Blt(surface, &rect, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
10105 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
10106 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
10107 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10108 hr = IDirectDrawSurface7_Blt(surface, &rect, surface2, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
10109 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10110 hr = IDirectDrawSurface7_Blt(surface, &rect, surface2, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
10111 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10113 /* Out of bounds rectangle. */
10114 SetRect(&rect, 0, 0, 65, 65);
10115 hr = IDirectDrawSurface7_Blt(surface, &rect, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
10116 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
10118 /* Combine multiple flags. */
10119 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
10120 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10122 IDirectDrawSurface7_Release(surface2);
10123 IDirectDrawSurface7_Release(surface);
10125 done:
10126 IDirectDraw7_Release(ddraw);
10127 refcount = IDirect3DDevice7_Release(device);
10128 ok(!refcount, "Device has %u references left.\n", refcount);
10129 DestroyWindow(window);
10132 static void test_texcoordindex(void)
10134 static D3DMATRIX mat =
10136 1.0f, 0.0f, 0.0f, 0.0f,
10137 0.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,
10141 static struct
10143 struct vec3 pos;
10144 struct vec2 texcoord1;
10145 struct vec2 texcoord2;
10146 struct vec2 texcoord3;
10148 quad[] =
10150 {{-1.0f, -1.0f, 0.0f}, {0.0f, 1.0f}, {0.0f, 0.0f}, {1.0f, 1.0f}},
10151 {{-1.0f, 1.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 1.0f}, {1.0f, 0.0f}},
10152 {{ 1.0f, -1.0f, 0.0f}, {1.0f, 1.0f}, {1.0f, 0.0f}, {0.0f, 1.0f}},
10153 {{ 1.0f, 1.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 0.0f}},
10155 static const DWORD fvf = D3DFVF_XYZ | D3DFVF_TEX3;
10156 IDirect3DDevice7 *device;
10157 IDirect3D7 *d3d;
10158 IDirectDraw7 *ddraw;
10159 IDirectDrawSurface7 *rt;
10160 HWND window;
10161 HRESULT hr;
10162 IDirectDrawSurface7 *texture1, *texture2;
10163 DDSURFACEDESC2 surface_desc;
10164 ULONG refcount;
10165 D3DCOLOR color;
10166 DWORD *ptr;
10168 window = create_window();
10169 if (!(device = create_device(window, DDSCL_NORMAL)))
10171 skip("Failed to create a 3D device, skipping test.\n");
10172 DestroyWindow(window);
10173 return;
10176 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
10177 ok(SUCCEEDED(hr), "Failed to get Direct3D7 interface, hr %#x.\n", hr);
10178 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
10179 ok(SUCCEEDED(hr), "Failed to get DirectDraw7 interface, hr %#x.\n", hr);
10180 IDirect3D7_Release(d3d);
10182 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
10183 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
10185 memset(&surface_desc, 0, sizeof(surface_desc));
10186 surface_desc.dwSize = sizeof(surface_desc);
10187 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
10188 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
10189 surface_desc.dwWidth = 2;
10190 surface_desc.dwHeight = 2;
10191 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
10192 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
10193 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
10194 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
10195 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
10196 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
10197 U5(U4(surface_desc).ddpfPixelFormat).dwRGBAlphaBitMask = 0xff000000;
10198 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &texture1, NULL);
10199 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
10200 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &texture2, NULL);
10201 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
10203 memset(&surface_desc, 0, sizeof(surface_desc));
10204 surface_desc.dwSize = sizeof(surface_desc);
10205 hr = IDirectDrawSurface7_Lock(texture1, 0, &surface_desc, 0, NULL);
10206 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
10207 ptr = surface_desc.lpSurface;
10208 ptr[0] = 0xff000000;
10209 ptr[1] = 0xff00ff00;
10210 ptr += U1(surface_desc).lPitch / sizeof(*ptr);
10211 ptr[0] = 0xff0000ff;
10212 ptr[1] = 0xff00ffff;
10213 hr = IDirectDrawSurface7_Unlock(texture1, NULL);
10214 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
10216 memset(&surface_desc, 0, sizeof(surface_desc));
10217 surface_desc.dwSize = sizeof(surface_desc);
10218 hr = IDirectDrawSurface7_Lock(texture2, 0, &surface_desc, 0, NULL);
10219 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
10220 ptr = surface_desc.lpSurface;
10221 ptr[0] = 0xff000000;
10222 ptr[1] = 0xff0000ff;
10223 ptr += U1(surface_desc).lPitch / sizeof(*ptr);
10224 ptr[0] = 0xffff0000;
10225 ptr[1] = 0xffff00ff;
10226 hr = IDirectDrawSurface7_Unlock(texture2, 0);
10227 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
10229 hr = IDirect3DDevice7_SetTexture(device, 0, texture1);
10230 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
10231 hr = IDirect3DDevice7_SetTexture(device, 1, texture2);
10232 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
10233 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
10234 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
10235 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
10236 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
10237 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
10238 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
10239 hr = IDirect3DDevice7_SetTextureStageState(device, 1, D3DTSS_COLOROP, D3DTOP_ADD);
10240 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
10241 hr = IDirect3DDevice7_SetTextureStageState(device, 1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
10242 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
10243 hr = IDirect3DDevice7_SetTextureStageState(device, 1, D3DTSS_COLORARG2, D3DTA_CURRENT);
10244 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
10245 hr = IDirect3DDevice7_SetTextureStageState(device, 2, D3DTSS_COLOROP, D3DTOP_DISABLE);
10246 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
10248 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_TEXCOORDINDEX, 1);
10249 ok(SUCCEEDED(hr), "Failed to set texcoord index, hr %#x.\n", hr);
10250 hr = IDirect3DDevice7_SetTextureStageState(device, 1, D3DTSS_TEXCOORDINDEX, 0);
10251 ok(SUCCEEDED(hr), "Failed to set texcoord index, hr %#x.\n", hr);
10253 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, FALSE);
10254 ok(SUCCEEDED(hr), "Failed to disable z-buffering, hr %#x.\n", hr);
10256 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffff00, 1.0f, 0);
10257 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
10259 hr = IDirect3DDevice7_BeginScene(device);
10260 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
10261 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, fvf, quad, 4, 0);
10262 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10263 hr = IDirect3DDevice7_EndScene(device);
10264 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
10266 color = get_surface_color(rt, 160, 120);
10267 ok(compare_color(color, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color);
10268 color = get_surface_color(rt, 480, 120);
10269 ok(compare_color(color, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color);
10270 color = get_surface_color(rt, 160, 360);
10271 ok(compare_color(color, 0x00ff0000, 2), "Got unexpected color 0x%08x.\n", color);
10272 color = get_surface_color(rt, 480, 360);
10273 ok(compare_color(color, 0x00ffffff, 2), "Got unexpected color 0x%08x.\n", color);
10275 hr = IDirect3DDevice7_SetTextureStageState(device, 1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);
10276 ok(SUCCEEDED(hr), "Failed to set texture transform flags, hr %#x.\n", hr);
10277 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_TEXTURE1, &mat);
10278 ok(SUCCEEDED(hr), "Failed to set transformation matrix, hr %#x.\n", hr);
10280 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffff00, 1.0f, 0);
10281 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
10283 hr = IDirect3DDevice7_BeginScene(device);
10284 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
10285 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, fvf, quad, 4, 0);
10286 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10287 hr = IDirect3DDevice7_EndScene(device);
10288 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
10290 color = get_surface_color(rt, 160, 120);
10291 ok(compare_color(color, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color);
10292 color = get_surface_color(rt, 480, 120);
10293 ok(compare_color(color, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color);
10294 color = get_surface_color(rt, 160, 360);
10295 ok(compare_color(color, 0x00000000, 2), "Got unexpected color 0x%08x.\n", color);
10296 color = get_surface_color(rt, 480, 360);
10297 ok(compare_color(color, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color);
10299 hr = IDirect3DDevice7_SetTextureStageState(device, 1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE);
10300 ok(SUCCEEDED(hr), "Failed to set texture transform flags, hr %#x.\n", hr);
10301 hr = IDirect3DDevice7_SetTextureStageState(device, 1, D3DTSS_TEXCOORDINDEX, 2);
10302 ok(SUCCEEDED(hr), "Failed to set texcoord index, hr %#x.\n", hr);
10304 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffff00, 1.0f, 0);
10305 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
10307 hr = IDirect3DDevice7_BeginScene(device);
10308 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
10309 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, fvf, quad, 4, 0);
10310 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10311 hr = IDirect3DDevice7_EndScene(device);
10312 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
10314 color = get_surface_color(rt, 160, 120);
10315 ok(compare_color(color, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color);
10316 color = get_surface_color(rt, 480, 120);
10317 ok(compare_color(color, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color);
10318 color = get_surface_color(rt, 160, 360);
10319 ok(compare_color(color, 0x00ff00ff, 2), "Got unexpected color 0x%08x.\n", color);
10320 color = get_surface_color(rt, 480, 360);
10321 ok(compare_color(color, 0x00ffff00, 2), "Got unexpected color 0x%08x.\n", color);
10323 IDirectDrawSurface7_Release(texture1);
10324 IDirectDrawSurface7_Release(texture2);
10326 IDirectDrawSurface7_Release(rt);
10327 IDirectDraw_Release(ddraw);
10328 refcount = IDirect3DDevice7_Release(device);
10329 ok(!refcount, "Device has %u references left.\n", refcount);
10330 DestroyWindow(window);
10333 static void test_colorkey_precision(void)
10335 static struct
10337 struct vec3 pos;
10338 struct vec2 texcoord;
10340 quad[] =
10342 {{-1.0f, -1.0f, 0.0f}, {0.0f, 1.0f}},
10343 {{-1.0f, 1.0f, 0.0f}, {0.0f, 0.0f}},
10344 {{ 1.0f, -1.0f, 0.0f}, {1.0f, 1.0f}},
10345 {{ 1.0f, 1.0f, 0.0f}, {1.0f, 0.0f}},
10347 IDirect3DDevice7 *device;
10348 IDirect3D7 *d3d;
10349 IDirectDraw7 *ddraw;
10350 IDirectDrawSurface7 *rt;
10351 HWND window;
10352 HRESULT hr;
10353 IDirectDrawSurface7 *src, *dst, *texture;
10354 DDSURFACEDESC2 surface_desc, lock_desc;
10355 ULONG refcount;
10356 D3DCOLOR color;
10357 unsigned int t, c;
10358 DDCOLORKEY ckey;
10359 DDBLTFX fx;
10360 DWORD data[4] = {0}, color_mask;
10361 BOOL is_nvidia, is_warp;
10362 static const struct
10364 unsigned int max, shift, bpp, clear;
10365 const char *name;
10366 BOOL skip_nv;
10367 DDPIXELFORMAT fmt;
10369 tests[] =
10372 255, 0, 4, 0x00345678, "D3DFMT_X8R8G8B8", FALSE,
10374 sizeof(DDPIXELFORMAT), DDPF_RGB, 0,
10375 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0x00000000}
10380 63, 5, 2, 0x5678, "D3DFMT_R5G6B5, G channel", FALSE,
10382 sizeof(DDPIXELFORMAT), DDPF_RGB, 0,
10383 {16}, {0xf800}, {0x07e0}, {0x001f}, {0x0000}
10388 31, 0, 2, 0x5678, "D3DFMT_R5G6B5, B channel", FALSE,
10390 sizeof(DDPIXELFORMAT), DDPF_RGB, 0,
10391 {16}, {0xf800}, {0x07e0}, {0x001f}, {0x0000}
10396 15, 0, 2, 0x0678, "D3DFMT_A4R4G4B4", TRUE,
10398 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
10399 {16}, {0x0f00}, {0x00f0}, {0x000f}, {0xf000}
10404 window = create_window();
10405 if (!(device = create_device(window, DDSCL_NORMAL)))
10407 skip("Failed to create a 3D device, skipping test.\n");
10408 DestroyWindow(window);
10409 return;
10412 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
10413 ok(SUCCEEDED(hr), "Failed to get Direct3D7 interface, hr %#x.\n", hr);
10414 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
10415 ok(SUCCEEDED(hr), "Failed to get DirectDraw7 interface, hr %#x.\n", hr);
10416 IDirect3D7_Release(d3d);
10417 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
10418 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
10420 is_nvidia = ddraw_is_nvidia(ddraw);
10421 /* The Windows 8 WARP driver has plenty of false negatives in X8R8G8B8
10422 * (color key doesn't match although the values are equal), and a false
10423 * positive when the color key is 0 and the texture contains the value 1.
10424 * I don't want to mark this broken unconditionally since this would
10425 * essentially disable the test on Windows. Also on random occasions
10426 * 254 == 255 and 255 != 255.*/
10427 is_warp = ddraw_is_warp(ddraw);
10429 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
10430 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
10431 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
10432 ok(SUCCEEDED(hr), "Failed to disable z-buffering, hr %#x.\n", hr);
10433 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, TRUE);
10434 ok(SUCCEEDED(hr), "Failed to enable color keying, hr %#x.\n", hr);
10435 /* Multiply the texture read result with 0, that way the result color if the key doesn't
10436 * match is constant. In theory color keying works without reading the texture result
10437 * (meaning we could just op=arg1, arg1=tfactor), but the Geforce7 Windows driver begs
10438 * to differ. */
10439 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_MODULATE);
10440 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
10441 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
10442 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
10443 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLORARG2, D3DTA_TFACTOR);
10444 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
10445 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_TEXTUREFACTOR, 0x00000000);
10446 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
10448 memset(&fx, 0, sizeof(fx));
10449 fx.dwSize = sizeof(fx);
10450 memset(&lock_desc, 0, sizeof(lock_desc));
10451 lock_desc.dwSize = sizeof(lock_desc);
10453 for (t = 0; t < sizeof(tests) / sizeof(*tests); ++t)
10455 if (is_nvidia && tests[t].skip_nv)
10457 win_skip("Skipping test %s on Nvidia Windows drivers.\n", tests[t].name);
10458 continue;
10461 memset(&surface_desc, 0, sizeof(surface_desc));
10462 surface_desc.dwSize = sizeof(surface_desc);
10463 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
10464 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
10465 surface_desc.dwWidth = 4;
10466 surface_desc.dwHeight = 1;
10467 U4(surface_desc).ddpfPixelFormat = tests[t].fmt;
10468 /* Windows XP (at least with the r200 driver, other drivers untested) produces
10469 * garbage when doing color keyed texture->texture blits. */
10470 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &src, NULL);
10471 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
10472 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &dst, NULL);
10473 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
10475 U5(fx).dwFillColor = tests[t].clear;
10476 /* On the w8 testbot (WARP driver) the blit result has different values in the
10477 * X channel. */
10478 color_mask = U2(tests[t].fmt).dwRBitMask
10479 | U3(tests[t].fmt).dwGBitMask
10480 | U4(tests[t].fmt).dwBBitMask;
10482 for (c = 0; c <= tests[t].max; ++c)
10484 /* The idiotic Nvidia Windows driver can't change the color key on a d3d
10485 * texture after it has been set once... */
10486 surface_desc.dwFlags |= DDSD_CKSRCBLT;
10487 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
10488 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = c << tests[t].shift;
10489 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = c << tests[t].shift;
10490 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &texture, NULL);
10491 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
10492 hr = IDirect3DDevice7_SetTexture(device, 0, texture);
10493 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
10495 hr = IDirectDrawSurface7_Blt(dst, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
10496 ok(SUCCEEDED(hr), "Failed to clear destination surface, hr %#x.\n", hr);
10498 hr = IDirectDrawSurface7_Lock(src, NULL, &lock_desc, DDLOCK_WAIT, NULL);
10499 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
10500 switch (tests[t].bpp)
10502 case 4:
10503 ((DWORD *)lock_desc.lpSurface)[0] = (c ? c - 1 : 0) << tests[t].shift;
10504 ((DWORD *)lock_desc.lpSurface)[1] = c << tests[t].shift;
10505 ((DWORD *)lock_desc.lpSurface)[2] = min(c + 1, tests[t].max) << tests[t].shift;
10506 ((DWORD *)lock_desc.lpSurface)[3] = 0xffffffff;
10507 break;
10509 case 2:
10510 ((WORD *)lock_desc.lpSurface)[0] = (c ? c - 1 : 0) << tests[t].shift;
10511 ((WORD *)lock_desc.lpSurface)[1] = c << tests[t].shift;
10512 ((WORD *)lock_desc.lpSurface)[2] = min(c + 1, tests[t].max) << tests[t].shift;
10513 ((WORD *)lock_desc.lpSurface)[3] = 0xffff;
10514 break;
10516 hr = IDirectDrawSurface7_Unlock(src, 0);
10517 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
10518 hr = IDirectDrawSurface7_Blt(texture, NULL, src, NULL, DDBLT_WAIT, NULL);
10519 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
10521 ckey.dwColorSpaceLowValue = c << tests[t].shift;
10522 ckey.dwColorSpaceHighValue = c << tests[t].shift;
10523 hr = IDirectDrawSurface7_SetColorKey(src, DDCKEY_SRCBLT, &ckey);
10524 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
10526 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_KEYSRC | DDBLT_WAIT, NULL);
10527 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
10529 /* Don't make this read only, it somehow breaks the detection of the Nvidia bug below. */
10530 hr = IDirectDrawSurface7_Lock(dst, NULL, &lock_desc, DDLOCK_WAIT, NULL);
10531 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
10532 switch (tests[t].bpp)
10534 case 4:
10535 data[0] = ((DWORD *)lock_desc.lpSurface)[0] & color_mask;
10536 data[1] = ((DWORD *)lock_desc.lpSurface)[1] & color_mask;
10537 data[2] = ((DWORD *)lock_desc.lpSurface)[2] & color_mask;
10538 data[3] = ((DWORD *)lock_desc.lpSurface)[3] & color_mask;
10539 break;
10541 case 2:
10542 data[0] = ((WORD *)lock_desc.lpSurface)[0] & color_mask;
10543 data[1] = ((WORD *)lock_desc.lpSurface)[1] & color_mask;
10544 data[2] = ((WORD *)lock_desc.lpSurface)[2] & color_mask;
10545 data[3] = ((WORD *)lock_desc.lpSurface)[3] & color_mask;
10546 break;
10548 hr = IDirectDrawSurface7_Unlock(dst, 0);
10549 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
10551 if (!c)
10553 ok(data[0] == tests[t].clear, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10554 tests[t].clear, data[0], tests[t].name, c);
10556 if (data[3] == tests[t].clear)
10558 /* My Geforce GTX 460 on Windows 7 misbehaves when A4R4G4B4 is blitted with color
10559 * keying: The blit takes ~0.5 seconds, and subsequent color keying draws are broken,
10560 * even when a different surface is used. The blit itself doesn't draw anything,
10561 * so we can detect the bug by looking at the otherwise unused 4th texel. It should
10562 * never be masked out by the key.
10564 * On Windows 10 the problem is worse, Blt just hangs. For this reason the ARGB4444
10565 * test is disabled on Nvidia.
10567 * Also appears to affect the testbot in some way with R5G6B5. Color keying is
10568 * terrible on WARP. */
10569 skip("Nvidia A4R4G4B4 color keying blit bug detected, skipping.\n");
10570 IDirectDrawSurface7_Release(texture);
10571 IDirectDrawSurface7_Release(src);
10572 IDirectDrawSurface7_Release(dst);
10573 goto done;
10576 else
10577 ok(data[0] == (c - 1) << tests[t].shift, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10578 (c - 1) << tests[t].shift, data[0], tests[t].name, c);
10580 ok(data[1] == tests[t].clear, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10581 tests[t].clear, data[1], tests[t].name, c);
10583 if (c == tests[t].max)
10584 ok(data[2] == tests[t].clear, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10585 tests[t].clear, data[2], tests[t].name, c);
10586 else
10587 ok(data[2] == (c + 1) << tests[t].shift, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10588 (c + 1) << tests[t].shift, data[2], tests[t].name, c);
10590 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x0000ff00, 1.0f, 0);
10591 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
10593 hr = IDirect3DDevice7_BeginScene(device);
10594 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
10595 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_TEX1, quad, 4, 0);
10596 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10597 hr = IDirect3DDevice7_EndScene(device);
10598 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
10600 color = get_surface_color(rt, 80, 240);
10601 if (!c)
10602 ok(compare_color(color, 0x0000ff00, 1) || broken(is_warp && compare_color(color, 0x00000000, 1)),
10603 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10604 color, tests[t].name, c);
10605 else
10606 ok(compare_color(color, 0x00000000, 1) || broken(is_warp && compare_color(color, 0x0000ff00, 1)),
10607 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10608 color, tests[t].name, c);
10610 color = get_surface_color(rt, 240, 240);
10611 ok(compare_color(color, 0x0000ff00, 1) || broken(is_warp && compare_color(color, 0x00000000, 1)),
10612 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10613 color, tests[t].name, c);
10615 color = get_surface_color(rt, 400, 240);
10616 if (c == tests[t].max)
10617 ok(compare_color(color, 0x0000ff00, 1) || broken(is_warp && compare_color(color, 0x00000000, 1)),
10618 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10619 color, tests[t].name, c);
10620 else
10621 ok(compare_color(color, 0x00000000, 1) || broken(is_warp && compare_color(color, 0x0000ff00, 1)),
10622 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10623 color, tests[t].name, c);
10625 IDirectDrawSurface7_Release(texture);
10627 IDirectDrawSurface7_Release(src);
10628 IDirectDrawSurface7_Release(dst);
10630 done:
10632 IDirectDrawSurface7_Release(rt);
10633 IDirectDraw7_Release(ddraw);
10634 refcount = IDirect3DDevice7_Release(device);
10635 ok(!refcount, "Device has %u references left.\n", refcount);
10636 DestroyWindow(window);
10639 static void test_range_colorkey(void)
10641 IDirectDraw7 *ddraw;
10642 HWND window;
10643 HRESULT hr;
10644 IDirectDrawSurface7 *surface;
10645 DDSURFACEDESC2 surface_desc;
10646 ULONG refcount;
10647 DDCOLORKEY ckey;
10649 window = create_window();
10650 ddraw = create_ddraw();
10651 ok(!!ddraw, "Failed to create a ddraw object.\n");
10652 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
10653 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
10655 memset(&surface_desc, 0, sizeof(surface_desc));
10656 surface_desc.dwSize = sizeof(surface_desc);
10657 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CKSRCBLT;
10658 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
10659 surface_desc.dwWidth = 1;
10660 surface_desc.dwHeight = 1;
10661 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
10662 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
10663 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
10664 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
10665 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
10666 U5(U4(surface_desc).ddpfPixelFormat).dwRGBAlphaBitMask = 0x00000000;
10668 /* Creating a surface with a range color key fails with DDERR_NOCOLORKEY. */
10669 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00000000;
10670 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00000001;
10671 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
10672 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
10674 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00000001;
10675 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00000000;
10676 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
10677 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
10679 /* Same for DDSCAPS_OFFSCREENPLAIN. */
10680 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
10681 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00000000;
10682 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00000001;
10683 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
10684 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
10686 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00000001;
10687 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00000000;
10688 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
10689 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
10691 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00000000;
10692 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00000000;
10693 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
10694 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
10696 /* Setting a range color key without DDCKEY_COLORSPACE collapses the key. */
10697 ckey.dwColorSpaceLowValue = 0x00000000;
10698 ckey.dwColorSpaceHighValue = 0x00000001;
10699 hr = IDirectDrawSurface7_SetColorKey(surface, DDCKEY_SRCBLT, &ckey);
10700 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
10702 hr = IDirectDrawSurface7_GetColorKey(surface, DDCKEY_SRCBLT, &ckey);
10703 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
10704 ok(!ckey.dwColorSpaceLowValue, "Got unexpected value 0x%08x.\n", ckey.dwColorSpaceLowValue);
10705 ok(!ckey.dwColorSpaceHighValue, "Got unexpected value 0x%08x.\n", ckey.dwColorSpaceHighValue);
10707 ckey.dwColorSpaceLowValue = 0x00000001;
10708 ckey.dwColorSpaceHighValue = 0x00000000;
10709 hr = IDirectDrawSurface7_SetColorKey(surface, DDCKEY_SRCBLT, &ckey);
10710 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
10712 hr = IDirectDrawSurface7_GetColorKey(surface, DDCKEY_SRCBLT, &ckey);
10713 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
10714 ok(ckey.dwColorSpaceLowValue == 0x00000001, "Got unexpected value 0x%08x.\n", ckey.dwColorSpaceLowValue);
10715 ok(ckey.dwColorSpaceHighValue == 0x00000001, "Got unexpected value 0x%08x.\n", ckey.dwColorSpaceHighValue);
10717 /* DDCKEY_COLORSPACE is ignored if the key is a single value. */
10718 ckey.dwColorSpaceLowValue = 0x00000000;
10719 ckey.dwColorSpaceHighValue = 0x00000000;
10720 hr = IDirectDrawSurface7_SetColorKey(surface, DDCKEY_SRCBLT | DDCKEY_COLORSPACE, &ckey);
10721 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
10723 /* Using it with a range key results in DDERR_NOCOLORKEYHW. */
10724 ckey.dwColorSpaceLowValue = 0x00000001;
10725 ckey.dwColorSpaceHighValue = 0x00000000;
10726 hr = IDirectDrawSurface7_SetColorKey(surface, DDCKEY_SRCBLT | DDCKEY_COLORSPACE, &ckey);
10727 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
10728 ckey.dwColorSpaceLowValue = 0x00000000;
10729 ckey.dwColorSpaceHighValue = 0x00000001;
10730 hr = IDirectDrawSurface7_SetColorKey(surface, DDCKEY_SRCBLT | DDCKEY_COLORSPACE, &ckey);
10731 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
10732 /* Range destination keys don't work either. */
10733 hr = IDirectDrawSurface7_SetColorKey(surface, DDCKEY_DESTBLT | DDCKEY_COLORSPACE, &ckey);
10734 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
10736 /* Just to show it's not because of A, R, and G having equal values. */
10737 ckey.dwColorSpaceLowValue = 0x00000000;
10738 ckey.dwColorSpaceHighValue = 0x01010101;
10739 hr = IDirectDrawSurface7_SetColorKey(surface, DDCKEY_SRCBLT | DDCKEY_COLORSPACE, &ckey);
10740 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
10742 /* None of these operations modified the key. */
10743 hr = IDirectDrawSurface7_GetColorKey(surface, DDCKEY_SRCBLT, &ckey);
10744 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
10745 ok(!ckey.dwColorSpaceLowValue, "Got unexpected value 0x%08x.\n", ckey.dwColorSpaceLowValue);
10746 ok(!ckey.dwColorSpaceHighValue, "Got unexpected value 0x%08x.\n", ckey.dwColorSpaceHighValue);
10748 IDirectDrawSurface7_Release(surface),
10749 refcount = IDirectDraw7_Release(ddraw);
10750 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
10751 DestroyWindow(window);
10754 static void test_shademode(void)
10756 IDirect3DVertexBuffer7 *vb_strip, *vb_list, *buffer;
10757 IDirect3DDevice7 *device;
10758 D3DVERTEXBUFFERDESC desc;
10759 IDirectDrawSurface7 *rt;
10760 DWORD color0, color1;
10761 void *data = NULL;
10762 IDirect3D7 *d3d;
10763 ULONG refcount;
10764 UINT i, count;
10765 HWND window;
10766 HRESULT hr;
10767 static const struct
10769 struct vec3 position;
10770 DWORD diffuse;
10772 quad_strip[] =
10774 {{-1.0f, -1.0f, 0.0f}, 0xffff0000},
10775 {{-1.0f, 1.0f, 0.0f}, 0xff00ff00},
10776 {{ 1.0f, -1.0f, 0.0f}, 0xff0000ff},
10777 {{ 1.0f, 1.0f, 0.0f}, 0xffffffff},
10779 quad_list[] =
10781 {{-1.0f, -1.0f, 0.0f}, 0xffff0000},
10782 {{-1.0f, 1.0f, 0.0f}, 0xff00ff00},
10783 {{ 1.0f, -1.0f, 0.0f}, 0xff0000ff},
10785 {{ 1.0f, -1.0f, 0.0f}, 0xff0000ff},
10786 {{-1.0f, 1.0f, 0.0f}, 0xff00ff00},
10787 {{ 1.0f, 1.0f, 0.0f}, 0xffffffff},
10789 static const struct
10791 DWORD primtype;
10792 DWORD shademode;
10793 DWORD color0, color1;
10795 tests[] =
10797 {D3DPT_TRIANGLESTRIP, D3DSHADE_FLAT, 0x00ff0000, 0x0000ff00},
10798 {D3DPT_TRIANGLESTRIP, D3DSHADE_PHONG, 0x000dca28, 0x000d45c7},
10799 {D3DPT_TRIANGLESTRIP, D3DSHADE_GOURAUD, 0x000dca28, 0x000d45c7},
10800 {D3DPT_TRIANGLESTRIP, D3DSHADE_PHONG, 0x000dca28, 0x000d45c7},
10801 {D3DPT_TRIANGLELIST, D3DSHADE_FLAT, 0x00ff0000, 0x000000ff},
10802 {D3DPT_TRIANGLELIST, D3DSHADE_GOURAUD, 0x000dca28, 0x000d45c7},
10805 window = create_window();
10806 if (!(device = create_device(window, DDSCL_NORMAL)))
10808 skip("Failed to create a 3D device, skipping test.\n");
10809 DestroyWindow(window);
10810 return;
10813 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
10814 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
10815 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
10816 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
10818 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
10819 ok(hr == D3D_OK, "Failed to disable lighting, hr %#x.\n", hr);
10820 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, FALSE);
10821 ok(SUCCEEDED(hr), "Failed to disable fog, hr %#x.\n", hr);
10823 memset(&desc, 0, sizeof(desc));
10824 desc.dwSize = sizeof(desc);
10825 desc.dwCaps = D3DVBCAPS_WRITEONLY;
10826 desc.dwFVF = D3DFVF_XYZ | D3DFVF_DIFFUSE;
10827 desc.dwNumVertices = sizeof(quad_strip) / sizeof(*quad_strip);
10828 hr = IDirect3D7_CreateVertexBuffer(d3d, &desc, &vb_strip, 0);
10829 ok(hr == D3D_OK, "Failed to create vertex buffer, hr %#x.\n", hr);
10830 hr = IDirect3DVertexBuffer7_Lock(vb_strip, 0, &data, NULL);
10831 ok(hr == D3D_OK, "Failed to lock vertex buffer, hr %#x.\n", hr);
10832 memcpy(data, quad_strip, sizeof(quad_strip));
10833 hr = IDirect3DVertexBuffer7_Unlock(vb_strip);
10834 ok(hr == D3D_OK, "Failed to unlock vertex buffer, hr %#x.\n", hr);
10836 desc.dwNumVertices = sizeof(quad_list) / sizeof(*quad_list);
10837 hr = IDirect3D7_CreateVertexBuffer(d3d, &desc, &vb_list, 0);
10838 ok(hr == D3D_OK, "Failed to create vertex buffer, hr %#x.\n", hr);
10839 hr = IDirect3DVertexBuffer7_Lock(vb_list, 0, &data, NULL);
10840 ok(hr == D3D_OK, "Failed to lock vertex buffer, hr %#x.\n", hr);
10841 memcpy(data, quad_list, sizeof(quad_list));
10842 hr = IDirect3DVertexBuffer7_Unlock(vb_list);
10843 ok(hr == D3D_OK, "Failed to unlock vertex buffer, hr %#x.\n", hr);
10845 /* Try it first with a TRIANGLESTRIP. Do it with different geometry because
10846 * the color fixups we have to do for FLAT shading will be dependent on that. */
10848 for (i = 0; i < sizeof(tests) / sizeof(tests[0]); ++i)
10850 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0f, 0);
10851 ok(hr == D3D_OK, "Failed to clear, hr %#x.\n", hr);
10853 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_SHADEMODE, tests[i].shademode);
10854 ok(hr == D3D_OK, "Failed to set shade mode, hr %#x.\n", hr);
10856 hr = IDirect3DDevice7_BeginScene(device);
10857 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
10858 buffer = tests[i].primtype == D3DPT_TRIANGLESTRIP ? vb_strip : vb_list;
10859 count = tests[i].primtype == D3DPT_TRIANGLESTRIP ? 4 : 6;
10860 hr = IDirect3DDevice7_DrawPrimitiveVB(device, tests[i].primtype, buffer, 0, count, 0);
10861 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10862 hr = IDirect3DDevice7_EndScene(device);
10863 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
10865 color0 = get_surface_color(rt, 100, 100); /* Inside first triangle */
10866 color1 = get_surface_color(rt, 500, 350); /* Inside second triangle */
10868 /* For D3DSHADE_FLAT it should take the color of the first vertex of
10869 * each triangle. This requires EXT_provoking_vertex or similar
10870 * functionality being available. */
10871 /* PHONG should be the same as GOURAUD, since no hardware implements
10872 * this. */
10873 ok(compare_color(color0, tests[i].color0, 1), "Test %u shading has color0 %08x, expected %08x.\n",
10874 i, color0, tests[i].color0);
10875 ok(compare_color(color1, tests[i].color1, 1), "Test %u shading has color1 %08x, expected %08x.\n",
10876 i, color1, tests[i].color1);
10879 IDirect3DVertexBuffer7_Release(vb_strip);
10880 IDirect3DVertexBuffer7_Release(vb_list);
10881 IDirectDrawSurface7_Release(rt);
10882 IDirect3D7_Release(d3d);
10883 refcount = IDirect3DDevice7_Release(device);
10884 ok(!refcount, "Device has %u references left.\n", refcount);
10885 DestroyWindow(window);
10888 static void test_lockrect_invalid(void)
10890 unsigned int i, r;
10891 IDirectDraw7 *ddraw;
10892 IDirectDrawSurface7 *surface;
10893 HWND window;
10894 HRESULT hr;
10895 DDSURFACEDESC2 surface_desc;
10896 DDSURFACEDESC2 locked_desc;
10897 DDCAPS hal_caps;
10898 DWORD needed_caps = DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY;
10899 static RECT valid[] =
10901 {60, 60, 68, 68},
10902 {60, 60, 60, 68},
10903 {60, 60, 68, 60},
10904 {120, 60, 128, 68},
10905 {60, 120, 68, 128},
10907 static RECT invalid[] =
10909 {68, 60, 60, 68}, /* left > right */
10910 {60, 68, 68, 60}, /* top > bottom */
10911 {-8, 60, 0, 68}, /* left < surface */
10912 {60, -8, 68, 0}, /* top < surface */
10913 {-16, 60, -8, 68}, /* right < surface */
10914 {60, -16, 68, -8}, /* bottom < surface */
10915 {60, 60, 136, 68}, /* right > surface */
10916 {60, 60, 68, 136}, /* bottom > surface */
10917 {136, 60, 144, 68}, /* left > surface */
10918 {60, 136, 68, 144}, /* top > surface */
10920 static const struct
10922 DWORD caps, caps2;
10923 const char *name;
10924 HRESULT hr;
10926 resources[] =
10928 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY, 0, "sysmem offscreenplain", DDERR_INVALIDPARAMS},
10929 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0, "vidmem offscreenplain", DDERR_INVALIDPARAMS},
10930 {DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, 0, "sysmem texture", DD_OK},
10931 {DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, 0, "vidmem texture", DDERR_INVALIDPARAMS},
10932 {DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, "managed texture", DD_OK},
10935 window = create_window();
10936 ddraw = create_ddraw();
10937 ok(!!ddraw, "Failed to create a ddraw object.\n");
10938 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
10939 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
10941 memset(&hal_caps, 0, sizeof(hal_caps));
10942 hal_caps.dwSize = sizeof(hal_caps);
10943 hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, NULL);
10944 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
10945 if ((hal_caps.ddsCaps.dwCaps & needed_caps) != needed_caps
10946 || !(hal_caps.ddsCaps.dwCaps & DDSCAPS2_TEXTUREMANAGE))
10948 skip("Required surface types not supported, skipping test.\n");
10949 goto done;
10952 for (r = 0; r < sizeof(resources) / sizeof(*resources); ++r)
10954 memset(&surface_desc, 0, sizeof(surface_desc));
10955 surface_desc.dwSize = sizeof(surface_desc);
10956 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
10957 surface_desc.ddsCaps.dwCaps = resources[r].caps;
10958 surface_desc.ddsCaps.dwCaps2 = resources[r].caps2;
10959 surface_desc.dwWidth = 128;
10960 surface_desc.dwHeight = 128;
10961 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
10962 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
10963 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
10964 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0xff0000;
10965 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x00ff00;
10966 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x0000ff;
10968 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
10969 if (is_ddraw64 && (resources[r].caps & DDSCAPS_TEXTURE))
10971 todo_wine ok(hr == E_NOINTERFACE, "Got unexpected hr %#x, type %s.\n", hr, resources[r].name);
10972 if (SUCCEEDED(hr))
10973 IDirectDrawSurface7_Release(surface);
10974 continue;
10976 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x, type %s.\n", hr, resources[r].name);
10978 /* Crashes in ddraw7
10979 hr = IDirectDrawSurface7_Lock(surface, NULL, NULL, DDLOCK_WAIT, NULL);
10980 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x, type %s.\n", hr, resources[r].name);
10983 for (i = 0; i < sizeof(valid) / sizeof(*valid); ++i)
10985 RECT *rect = &valid[i];
10987 memset(&locked_desc, 0, sizeof(locked_desc));
10988 locked_desc.dwSize = sizeof(locked_desc);
10990 hr = IDirectDrawSurface7_Lock(surface, rect, &locked_desc, DDLOCK_WAIT, NULL);
10991 ok(SUCCEEDED(hr), "Lock failed (%#x) for rect %s, type %s.\n",
10992 hr, wine_dbgstr_rect(rect), resources[r].name);
10994 hr = IDirectDrawSurface7_Unlock(surface, NULL);
10995 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
10998 for (i = 0; i < sizeof(invalid) / sizeof(*invalid); ++i)
11000 RECT *rect = &invalid[i];
11002 memset(&locked_desc, 1, sizeof(locked_desc));
11003 locked_desc.dwSize = sizeof(locked_desc);
11005 hr = IDirectDrawSurface7_Lock(surface, rect, &locked_desc, DDLOCK_WAIT, NULL);
11006 todo_wine_if (SUCCEEDED(resources[r].hr))
11007 ok(hr == resources[r].hr, "Lock returned %#x for rect %s, type %s.\n",
11008 hr, wine_dbgstr_rect(rect), resources[r].name);
11009 if (SUCCEEDED(hr))
11011 hr = IDirectDrawSurface7_Unlock(surface, NULL);
11012 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
11014 else
11015 ok(!locked_desc.lpSurface, "Got unexpected lpSurface %p.\n", locked_desc.lpSurface);
11018 hr = IDirectDrawSurface7_Lock(surface, NULL, &locked_desc, DDLOCK_WAIT, NULL);
11019 ok(SUCCEEDED(hr), "Lock(rect = NULL) failed, hr %#x, type %s.\n",
11020 hr, resources[r].name);
11021 hr = IDirectDrawSurface7_Lock(surface, NULL, &locked_desc, DDLOCK_WAIT, NULL);
11022 ok(hr == DDERR_SURFACEBUSY, "Double lock(rect = NULL) returned %#x, type %s.\n",
11023 hr, resources[r].name);
11024 hr = IDirectDrawSurface7_Unlock(surface, NULL);
11025 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
11027 hr = IDirectDrawSurface7_Lock(surface, &valid[0], &locked_desc, DDLOCK_WAIT, NULL);
11028 ok(SUCCEEDED(hr), "Lock(rect = %s) failed (%#x).\n", wine_dbgstr_rect(&valid[0]), hr);
11029 hr = IDirectDrawSurface7_Lock(surface, &valid[0], &locked_desc, DDLOCK_WAIT, NULL);
11030 ok(hr == DDERR_SURFACEBUSY, "Double lock(rect = %s) failed (%#x).\n",
11031 wine_dbgstr_rect(&valid[0]), hr);
11033 /* Locking a different rectangle returns DD_OK, but it seems to break the surface.
11034 * Afterwards unlocking the surface fails(NULL rectangle or both locked rectangles) */
11036 hr = IDirectDrawSurface7_Unlock(surface, NULL);
11037 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
11039 IDirectDrawSurface7_Release(surface);
11042 done:
11043 IDirectDraw7_Release(ddraw);
11044 DestroyWindow(window);
11047 static void test_yv12_overlay(void)
11049 IDirectDrawSurface7 *src_surface, *dst_surface;
11050 RECT rect = {13, 17, 14, 18};
11051 unsigned int offset, y;
11052 DDSURFACEDESC2 desc;
11053 unsigned char *base;
11054 IDirectDraw7 *ddraw;
11055 HWND window;
11056 HRESULT hr;
11058 window = create_window();
11059 ddraw = create_ddraw();
11060 ok(!!ddraw, "Failed to create a ddraw object.\n");
11061 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
11062 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
11064 if (!(src_surface = create_overlay(ddraw, 256, 256, MAKEFOURCC('Y','V','1','2'))))
11066 skip("Failed to create a YV12 overlay, skipping test.\n");
11067 goto done;
11070 memset(&desc, 0, sizeof(desc));
11071 desc.dwSize = sizeof(desc);
11072 hr = IDirectDrawSurface7_Lock(src_surface, NULL, &desc, DDLOCK_WAIT, NULL);
11073 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
11075 ok(desc.dwFlags == (DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_PITCH),
11076 "Got unexpected flags %#x.\n", desc.dwFlags);
11077 ok(desc.ddsCaps.dwCaps == (DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM | DDSCAPS_HWCODEC)
11078 || desc.ddsCaps.dwCaps == (DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM),
11079 "Got unexpected caps %#x.\n", desc.ddsCaps.dwCaps);
11080 ok(desc.dwWidth == 256, "Got unexpected width %u.\n", desc.dwWidth);
11081 ok(desc.dwHeight == 256, "Got unexpected height %u.\n", desc.dwHeight);
11082 /* The overlay pitch seems to have 256 byte alignment. */
11083 ok(!(U1(desc).lPitch & 0xff), "Got unexpected pitch %u.\n", U1(desc).lPitch);
11085 /* Fill the surface with some data for the blit test. */
11086 base = desc.lpSurface;
11087 /* Luminance */
11088 for (y = 0; y < desc.dwHeight; ++y)
11090 memset(base + U1(desc).lPitch * y, 0x10, desc.dwWidth);
11092 /* V */
11093 for (; y < desc.dwHeight + desc.dwHeight / 4; ++y)
11095 memset(base + U1(desc).lPitch * y, 0x20, desc.dwWidth);
11097 /* U */
11098 for (; y < desc.dwHeight + desc.dwHeight / 2; ++y)
11100 memset(base + U1(desc).lPitch * y, 0x30, desc.dwWidth);
11103 hr = IDirectDrawSurface7_Unlock(src_surface, NULL);
11104 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
11106 /* YV12 uses 2x2 blocks with 6 bytes per block (4*Y, 1*U, 1*V). Unlike
11107 * other block-based formats like DXT the entire Y channel is stored in
11108 * one big chunk of memory, followed by the chroma channels. So partial
11109 * locks do not really make sense. Show that they are allowed nevertheless
11110 * and the offset points into the luminance data. */
11111 hr = IDirectDrawSurface7_Lock(src_surface, &rect, &desc, DDLOCK_WAIT, NULL);
11112 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
11113 offset = ((const unsigned char *)desc.lpSurface - base);
11114 ok(offset == rect.top * U1(desc).lPitch + rect.left, "Got unexpected offset %u, expected %u.\n",
11115 offset, rect.top * U1(desc).lPitch + rect.left);
11116 hr = IDirectDrawSurface7_Unlock(src_surface, NULL);
11117 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
11119 if (!(dst_surface = create_overlay(ddraw, 256, 256, MAKEFOURCC('Y','V','1','2'))))
11121 /* Windows XP with a Radeon X1600 GPU refuses to create a second
11122 * overlay surface, DDERR_NOOVERLAYHW, making the blit tests moot. */
11123 skip("Failed to create a second YV12 surface, skipping blit test.\n");
11124 IDirectDrawSurface7_Release(src_surface);
11125 goto done;
11128 hr = IDirectDrawSurface7_Blt(dst_surface, NULL, src_surface, NULL, DDBLT_WAIT, NULL);
11129 /* VMware rejects YV12 blits. This behavior has not been seen on real
11130 * hardware yet, so mark it broken. */
11131 ok(SUCCEEDED(hr) || broken(hr == E_NOTIMPL), "Failed to blit, hr %#x.\n", hr);
11133 if (SUCCEEDED(hr))
11135 memset(&desc, 0, sizeof(desc));
11136 desc.dwSize = sizeof(desc);
11137 hr = IDirectDrawSurface7_Lock(dst_surface, NULL, &desc, DDLOCK_WAIT, NULL);
11138 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
11140 base = desc.lpSurface;
11141 ok(base[0] == 0x10, "Got unexpected Y data 0x%02x.\n", base[0]);
11142 base += desc.dwHeight * U1(desc).lPitch;
11143 todo_wine ok(base[0] == 0x20, "Got unexpected V data 0x%02x.\n", base[0]);
11144 base += desc.dwHeight / 4 * U1(desc).lPitch;
11145 todo_wine ok(base[0] == 0x30, "Got unexpected U data 0x%02x.\n", base[0]);
11147 hr = IDirectDrawSurface7_Unlock(dst_surface, NULL);
11148 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
11151 IDirectDrawSurface7_Release(dst_surface);
11152 IDirectDrawSurface7_Release(src_surface);
11153 done:
11154 IDirectDraw7_Release(ddraw);
11155 DestroyWindow(window);
11158 static BOOL dwm_enabled(void)
11160 BOOL ret = FALSE;
11162 if (!strcmp(winetest_platform, "wine"))
11163 return FALSE;
11164 if (!pDwmIsCompositionEnabled)
11165 return FALSE;
11166 if (FAILED(pDwmIsCompositionEnabled(&ret)))
11167 return FALSE;
11168 return ret;
11171 static void test_offscreen_overlay(void)
11173 IDirectDrawSurface7 *overlay, *offscreen, *primary;
11174 DDSURFACEDESC2 surface_desc;
11175 IDirectDraw7 *ddraw;
11176 HWND window;
11177 HRESULT hr;
11178 HDC dc;
11180 window = create_window();
11181 ddraw = create_ddraw();
11182 ok(!!ddraw, "Failed to create a ddraw object.\n");
11183 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
11184 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
11186 if (!(overlay = create_overlay(ddraw, 64, 64, MAKEFOURCC('U','Y','V','Y'))))
11188 skip("Failed to create a UYVY overlay, skipping test.\n");
11189 goto done;
11192 memset(&surface_desc, 0, sizeof(surface_desc));
11193 surface_desc.dwSize = sizeof(surface_desc);
11194 surface_desc.dwFlags = DDSD_CAPS;
11195 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
11196 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &primary, NULL);
11197 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
11199 /* On Windows 7, and probably Vista, UpdateOverlay() will return
11200 * DDERR_OUTOFCAPS if the dwm is active. Calling GetDC() on the primary
11201 * surface prevents this by disabling the dwm. */
11202 hr = IDirectDrawSurface7_GetDC(primary, &dc);
11203 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
11204 hr = IDirectDrawSurface7_ReleaseDC(primary, dc);
11205 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
11207 /* Try to overlay a NULL surface. */
11208 hr = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, NULL, NULL, DDOVER_SHOW, NULL);
11209 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
11210 hr = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, NULL, NULL, DDOVER_HIDE, NULL);
11211 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
11213 /* Try to overlay an offscreen surface. */
11214 memset(&surface_desc, 0, sizeof(surface_desc));
11215 surface_desc.dwSize = sizeof(surface_desc);
11216 surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
11217 surface_desc.dwWidth = 64;
11218 surface_desc.dwHeight = 64;
11219 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
11220 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
11221 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
11222 U4(surface_desc).ddpfPixelFormat.dwFourCC = 0;
11223 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 16;
11224 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0xf800;
11225 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x07e0;
11226 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x001f;
11227 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &offscreen, NULL);
11228 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
11230 hr = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, offscreen, NULL, DDOVER_SHOW, NULL);
11231 ok(SUCCEEDED(hr) || broken(hr == DDERR_OUTOFCAPS && dwm_enabled()),
11232 "Failed to update overlay, hr %#x.\n", hr);
11234 /* Try to overlay the primary with a non-overlay surface. */
11235 hr = IDirectDrawSurface7_UpdateOverlay(offscreen, NULL, primary, NULL, DDOVER_SHOW, NULL);
11236 ok(hr == DDERR_NOTAOVERLAYSURFACE, "Got unexpected hr %#x.\n", hr);
11237 hr = IDirectDrawSurface7_UpdateOverlay(offscreen, NULL, primary, NULL, DDOVER_HIDE, NULL);
11238 ok(hr == DDERR_NOTAOVERLAYSURFACE, "Got unexpected hr %#x.\n", hr);
11240 IDirectDrawSurface7_Release(offscreen);
11241 IDirectDrawSurface7_Release(primary);
11242 IDirectDrawSurface7_Release(overlay);
11243 done:
11244 IDirectDraw7_Release(ddraw);
11245 DestroyWindow(window);
11248 static void test_overlay_rect(void)
11250 IDirectDrawSurface7 *overlay, *primary = NULL;
11251 DDSURFACEDESC2 surface_desc;
11252 RECT rect = {0, 0, 64, 64};
11253 IDirectDraw7 *ddraw;
11254 LONG pos_x, pos_y;
11255 HRESULT hr, hr2;
11256 HWND window;
11257 HDC dc;
11259 window = create_window();
11260 ddraw = create_ddraw();
11261 ok(!!ddraw, "Failed to create a ddraw object.\n");
11262 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
11263 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
11265 if (!(overlay = create_overlay(ddraw, 64, 64, MAKEFOURCC('U','Y','V','Y'))))
11267 skip("Failed to create a UYVY overlay, skipping test.\n");
11268 goto done;
11271 memset(&surface_desc, 0, sizeof(surface_desc));
11272 surface_desc.dwSize = sizeof(surface_desc);
11273 surface_desc.dwFlags = DDSD_CAPS;
11274 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
11275 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &primary, NULL);
11276 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
11278 /* On Windows 7, and probably Vista, UpdateOverlay() will return
11279 * DDERR_OUTOFCAPS if the dwm is active. Calling GetDC() on the primary
11280 * surface prevents this by disabling the dwm. */
11281 hr = IDirectDrawSurface7_GetDC(primary, &dc);
11282 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
11283 hr = IDirectDrawSurface7_ReleaseDC(primary, dc);
11284 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
11286 /* On Windows 8 and newer DWM can't be turned off, making overlays unusable. */
11287 if (dwm_enabled())
11289 win_skip("Cannot disable DWM, skipping overlay test.\n");
11290 goto done;
11293 /* The dx sdk sort of implies that rect must be set when DDOVER_SHOW is
11294 * used. This is not true in Windows Vista and earlier, but changed in
11295 * Windows 7. */
11296 hr = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, primary, &rect, DDOVER_SHOW, NULL);
11297 ok(SUCCEEDED(hr), "Failed to update overlay, hr %#x.\n", hr);
11298 hr = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, primary, NULL, DDOVER_HIDE, NULL);
11299 ok(SUCCEEDED(hr), "Failed to update overlay, hr %#x.\n", hr);
11300 hr = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, primary, NULL, DDOVER_SHOW, NULL);
11301 ok(hr == DD_OK || hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
11303 /* Show that the overlay position is the (top, left) coordinate of the
11304 * destination rectangle. */
11305 OffsetRect(&rect, 32, 16);
11306 hr = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, primary, &rect, DDOVER_SHOW, NULL);
11307 ok(SUCCEEDED(hr), "Failed to update overlay, hr %#x.\n", hr);
11308 pos_x = -1; pos_y = -1;
11309 hr = IDirectDrawSurface7_GetOverlayPosition(overlay, &pos_x, &pos_y);
11310 ok(SUCCEEDED(hr), "Failed to get overlay position, hr %#x.\n", hr);
11311 ok(pos_x == rect.left, "Got unexpected pos_x %d, expected %d.\n", pos_x, rect.left);
11312 ok(pos_y == rect.top, "Got unexpected pos_y %d, expected %d.\n", pos_y, rect.top);
11314 /* Passing a NULL dest rect sets the position to 0/0. Visually it can be
11315 * seen that the overlay overlays the whole primary(==screen). */
11316 hr2 = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, primary, NULL, 0, NULL);
11317 ok(hr2 == DD_OK || hr2 == DDERR_INVALIDPARAMS || hr2 == DDERR_OUTOFCAPS, "Got unexpected hr %#x.\n", hr2);
11318 hr = IDirectDrawSurface7_GetOverlayPosition(overlay, &pos_x, &pos_y);
11319 ok(SUCCEEDED(hr), "Failed to get overlay position, hr %#x.\n", hr);
11320 if (SUCCEEDED(hr2))
11322 ok(!pos_x, "Got unexpected pos_x %d.\n", pos_x);
11323 ok(!pos_y, "Got unexpected pos_y %d.\n", pos_y);
11325 else
11327 ok(pos_x == 32, "Got unexpected pos_x %d.\n", pos_x);
11328 ok(pos_y == 16, "Got unexpected pos_y %d.\n", pos_y);
11331 /* The position cannot be retrieved when the overlay is not shown. */
11332 hr = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, primary, &rect, DDOVER_HIDE, NULL);
11333 ok(SUCCEEDED(hr), "Failed to update overlay, hr %#x.\n", hr);
11334 pos_x = -1; pos_y = -1;
11335 hr = IDirectDrawSurface7_GetOverlayPosition(overlay, &pos_x, &pos_y);
11336 ok(hr == DDERR_OVERLAYNOTVISIBLE, "Got unexpected hr %#x.\n", hr);
11337 ok(!pos_x, "Got unexpected pos_x %d.\n", pos_x);
11338 ok(!pos_y, "Got unexpected pos_y %d.\n", pos_y);
11340 IDirectDrawSurface7_Release(overlay);
11341 done:
11342 if (primary)
11343 IDirectDrawSurface7_Release(primary);
11344 IDirectDraw7_Release(ddraw);
11345 DestroyWindow(window);
11348 static void test_blt(void)
11350 IDirectDrawSurface7 *surface, *rt;
11351 DDSURFACEDESC2 surface_desc;
11352 IDirect3DDevice7 *device;
11353 IDirectDraw7 *ddraw;
11354 IDirect3D7 *d3d;
11355 unsigned int i;
11356 ULONG refcount;
11357 HWND window;
11358 HRESULT hr;
11360 static struct
11362 RECT src_rect;
11363 RECT dst_rect;
11364 HRESULT hr;
11366 test_data[] =
11368 {{160, 0, 640, 480}, { 0, 0, 480, 480}, DD_OK}, /* Overlapped blit. */
11369 {{160, 480, 640, 0}, { 0, 0, 480, 480}, DDERR_INVALIDRECT}, /* Overlapped blit, flipped source. */
11370 {{640, 0, 160, 480}, { 0, 0, 480, 480}, DDERR_INVALIDRECT}, /* Overlapped blit, mirrored source. */
11371 {{160, 0, 480, 480}, { 0, 0, 480, 480}, DD_OK}, /* Overlapped blit, stretched x. */
11372 {{160, 160, 640, 480}, { 0, 0, 480, 480}, DD_OK}, /* Overlapped blit, stretched y. */
11373 {{ 0, 0, 640, 480}, { 0, 0, 640, 480}, DD_OK}, /* Full surface blit. */
11374 {{ 0, 0, 640, 480}, { 0, 480, 640, 0}, DDERR_INVALIDRECT}, /* Full surface, flipped destination. */
11375 {{ 0, 0, 640, 480}, {640, 0, 0, 480}, DDERR_INVALIDRECT}, /* Full surface, mirrored destination. */
11376 {{ 0, 480, 640, 0}, { 0, 0, 640, 480}, DDERR_INVALIDRECT}, /* Full surface, flipped source. */
11377 {{640, 0, 0, 480}, { 0, 0, 640, 480}, DDERR_INVALIDRECT}, /* Full surface, mirrored source. */
11380 window = create_window();
11381 if (!(device = create_device(window, DDSCL_NORMAL)))
11383 skip("Failed to create a 3D device, skipping test.\n");
11384 DestroyWindow(window);
11385 return;
11388 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
11389 ok(SUCCEEDED(hr), "Failed to get Direct3D7 interface, hr %#x.\n", hr);
11390 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
11391 ok(SUCCEEDED(hr), "Failed to get DirectDraw7 interface, hr %#x.\n", hr);
11392 IDirect3D7_Release(d3d);
11393 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
11394 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
11396 memset(&surface_desc, 0, sizeof(surface_desc));
11397 surface_desc.dwSize = sizeof(surface_desc);
11398 surface_desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
11399 surface_desc.dwWidth = 640;
11400 surface_desc.dwHeight = 480;
11401 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
11402 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
11403 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
11405 hr = IDirectDrawSurface7_Blt(surface, NULL, surface, NULL, 0, NULL);
11406 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
11408 hr = IDirectDrawSurface7_Blt(surface, NULL, rt, NULL, 0, NULL);
11409 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
11411 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
11413 hr = IDirectDrawSurface7_Blt(surface, &test_data[i].dst_rect,
11414 surface, &test_data[i].src_rect, DDBLT_WAIT, NULL);
11415 ok(hr == test_data[i].hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, test_data[i].hr);
11417 hr = IDirectDrawSurface7_Blt(surface, &test_data[i].dst_rect,
11418 rt, &test_data[i].src_rect, DDBLT_WAIT, NULL);
11419 ok(hr == test_data[i].hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, test_data[i].hr);
11421 hr = IDirectDrawSurface7_Blt(surface, &test_data[i].dst_rect,
11422 NULL, &test_data[i].src_rect, DDBLT_WAIT, NULL);
11423 ok(hr == DDERR_INVALIDPARAMS, "Test %u: Got unexpected hr %#x.\n", i, hr);
11425 hr = IDirectDrawSurface7_Blt(surface, &test_data[i].dst_rect, NULL, NULL, DDBLT_WAIT, NULL);
11426 ok(hr == DDERR_INVALIDPARAMS, "Test %u: Got unexpected hr %#x.\n", i, hr);
11429 IDirectDrawSurface7_Release(surface);
11430 IDirectDrawSurface7_Release(rt);
11431 IDirectDraw7_Release(ddraw);
11432 refcount = IDirect3DDevice7_Release(device);
11433 ok(!refcount, "Device has %u references left.\n", refcount);
11434 DestroyWindow(window);
11437 static void test_blt_z_alpha(void)
11439 DWORD blt_flags[] =
11441 /* 0 */
11442 DDBLT_ALPHADEST,
11443 DDBLT_ALPHADESTCONSTOVERRIDE,
11444 DDBLT_ALPHADESTNEG,
11445 DDBLT_ALPHADESTSURFACEOVERRIDE,
11446 DDBLT_ALPHAEDGEBLEND,
11447 /* 5 */
11448 DDBLT_ALPHASRC,
11449 DDBLT_ALPHASRCCONSTOVERRIDE,
11450 DDBLT_ALPHASRCNEG,
11451 DDBLT_ALPHASRCSURFACEOVERRIDE,
11452 DDBLT_ZBUFFER,
11453 /* 10 */
11454 DDBLT_ZBUFFERDESTCONSTOVERRIDE,
11455 DDBLT_ZBUFFERDESTOVERRIDE,
11456 DDBLT_ZBUFFERSRCCONSTOVERRIDE,
11457 DDBLT_ZBUFFERSRCOVERRIDE,
11459 IDirectDrawSurface7 *src_surface, *dst_surface;
11460 DDSURFACEDESC2 surface_desc;
11461 IDirectDraw7 *ddraw;
11462 DDPIXELFORMAT pf;
11463 ULONG refcount;
11464 unsigned int i;
11465 D3DCOLOR color;
11466 HWND window;
11467 HRESULT hr;
11468 DDBLTFX fx;
11470 window = create_window();
11471 ddraw = create_ddraw();
11472 ok(!!ddraw, "Failed to create a ddraw object.\n");
11473 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
11474 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
11476 memset(&pf, 0, sizeof(pf));
11477 pf.dwSize = sizeof(pf);
11478 pf.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
11479 U1(pf).dwRGBBitCount = 32;
11480 U2(pf).dwRBitMask = 0x00ff0000;
11481 U3(pf).dwGBitMask = 0x0000ff00;
11482 U4(pf).dwBBitMask = 0x000000ff;
11483 U5(pf).dwRGBAlphaBitMask = 0xff000000;
11485 memset(&surface_desc, 0, sizeof(surface_desc));
11486 surface_desc.dwSize = sizeof(surface_desc);
11487 surface_desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_PIXELFORMAT;
11488 surface_desc.dwWidth = 64;
11489 surface_desc.dwHeight = 64;
11490 U4(surface_desc).ddpfPixelFormat = pf;
11491 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
11493 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &src_surface, NULL);
11494 ok(SUCCEEDED(hr), "Failed to create source surface, hr %#x.\n", hr);
11495 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &dst_surface, NULL);
11496 ok(SUCCEEDED(hr), "Failed to create destination surface, hr %#x.\n", hr);
11498 memset(&fx, 0, sizeof(fx));
11499 fx.dwSize = sizeof(fx);
11500 fx.dwZBufferOpCode = D3DCMP_NEVER;
11501 fx.dwZDestConstBitDepth = 32;
11502 U1(fx).dwZDestConst = 0x11111111;
11503 fx.dwZSrcConstBitDepth = 32;
11504 U2(fx).dwZSrcConst = 0xeeeeeeee;
11505 fx.dwAlphaEdgeBlendBitDepth = 8;
11506 fx.dwAlphaEdgeBlend = 0x7f;
11507 fx.dwAlphaDestConstBitDepth = 8;
11508 U3(fx).dwAlphaDestConst = 0xdd;
11509 fx.dwAlphaSrcConstBitDepth = 8;
11510 U4(fx).dwAlphaSrcConst = 0x22;
11512 for (i = 0; i < sizeof(blt_flags) / sizeof(*blt_flags); ++i)
11514 fx.dwFillColor = 0x3300ff00;
11515 hr = IDirectDrawSurface7_Blt(src_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
11516 ok(SUCCEEDED(hr), "Test %u: Got unexpected hr %#x.\n", i, hr);
11518 fx.dwFillColor = 0xccff0000;
11519 hr = IDirectDrawSurface7_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
11520 ok(SUCCEEDED(hr), "Test %u: Got unexpected hr %#x.\n", i, hr);
11522 hr = IDirectDrawSurface7_Blt(dst_surface, NULL, src_surface, NULL, blt_flags[i] | DDBLT_WAIT, &fx);
11523 ok(SUCCEEDED(hr), "Test %u: Got unexpected hr %#x.\n", i, hr);
11525 color = get_surface_color(dst_surface, 32, 32);
11526 ok(compare_color(color, 0x0000ff00, 0), "Test %u: Got unexpected color 0x%08x.\n", i, color);
11529 IDirectDrawSurface7_Release(dst_surface);
11530 IDirectDrawSurface7_Release(src_surface);
11531 refcount = IDirectDraw7_Release(ddraw);
11532 ok(!refcount, "DirectDraw has %u references left.\n", refcount);
11533 DestroyWindow(window);
11536 static void test_color_clamping(void)
11538 static D3DMATRIX mat =
11540 1.0f, 0.0f, 0.0f, 0.0f,
11541 0.0f, 1.0f, 0.0f, 0.0f,
11542 0.0f, 0.0f, 1.0f, 0.0f,
11543 0.0f, 0.0f, 0.0f, 1.0f,
11545 static struct vec3 quad[] =
11547 {-1.0f, -1.0f, 0.1f},
11548 {-1.0f, 1.0f, 0.1f},
11549 { 1.0f, -1.0f, 0.1f},
11550 { 1.0f, 1.0f, 0.1f},
11552 IDirect3DDevice7 *device;
11553 IDirectDrawSurface7 *rt;
11554 ULONG refcount;
11555 D3DCOLOR color;
11556 HWND window;
11557 HRESULT hr;
11559 window = create_window();
11560 if (!(device = create_device(window, DDSCL_NORMAL)))
11562 skip("Failed to create a 3D device, skipping test.\n");
11563 DestroyWindow(window);
11564 return;
11567 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
11568 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
11570 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &mat);
11571 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#x.\n", hr);
11572 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_VIEW, &mat);
11573 ok(SUCCEEDED(hr), "Failed to set view transform, hr %#x.\n", hr);
11574 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &mat);
11575 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
11576 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CLIPPING, FALSE);
11577 ok(SUCCEEDED(hr), "Failed to disable clipping, hr %#x.\n", hr);
11578 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, FALSE);
11579 ok(SUCCEEDED(hr), "Failed to disable Z test, hr %#x.\n", hr);
11580 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, FALSE);
11581 ok(SUCCEEDED(hr), "Failed to disable fog, hr %#x.\n", hr);
11582 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_STENCILENABLE, FALSE);
11583 ok(SUCCEEDED(hr), "Failed to disable stencil test, hr %#x.\n", hr);
11584 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CULLMODE, D3DCULL_NONE);
11585 ok(SUCCEEDED(hr), "Failed to disable culling, hr %#x.\n", hr);
11586 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
11587 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
11589 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_TEXTUREFACTOR, 0xff404040);
11590 ok(SUCCEEDED(hr), "Failed to set texture factor, hr %#x.\n", hr);
11591 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_ADD);
11592 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
11593 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);
11594 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
11595 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLORARG2, D3DTA_SPECULAR);
11596 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
11597 hr = IDirect3DDevice7_SetTextureStageState(device, 1, D3DTSS_COLOROP, D3DTOP_MODULATE);
11598 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
11599 hr = IDirect3DDevice7_SetTextureStageState(device, 1, D3DTSS_COLORARG1, D3DTA_TFACTOR);
11600 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
11601 hr = IDirect3DDevice7_SetTextureStageState(device, 1, D3DTSS_COLORARG2, D3DTA_CURRENT);
11602 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
11604 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff00ff00, 0.0f, 0);
11605 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
11607 hr = IDirect3DDevice7_BeginScene(device);
11608 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
11610 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, quad, 4, 0);
11611 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
11613 hr = IDirect3DDevice7_EndScene(device);
11614 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
11616 color = get_surface_color(rt, 320, 240);
11617 ok(compare_color(color, 0x00404040, 1), "Got unexpected color 0x%08x.\n", color);
11619 IDirectDrawSurface7_Release(rt);
11620 refcount = IDirect3DDevice7_Release(device);
11621 ok(!refcount, "Device has %u references left.\n", refcount);
11622 DestroyWindow(window);
11625 static void test_getdc(void)
11627 DDSCAPS2 caps = {DDSCAPS_COMPLEX, DDSCAPS2_CUBEMAP_NEGATIVEZ, 0, {0}};
11628 IDirectDrawSurface7 *surface, *surface2, *tmp;
11629 DDSURFACEDESC2 surface_desc, map_desc;
11630 IDirectDraw7 *ddraw;
11631 unsigned int i;
11632 HWND window;
11633 HDC dc, dc2;
11634 HRESULT hr;
11636 static const struct
11638 const char *name;
11639 DDPIXELFORMAT format;
11640 BOOL getdc_supported;
11641 HRESULT alt_result;
11643 test_data[] =
11645 {"D3DFMT_A8R8G8B8", {sizeof(test_data->format), DDPF_RGB | DDPF_ALPHAPIXELS, 0, {32},
11646 {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}}, TRUE},
11647 {"D3DFMT_X8R8G8B8", {sizeof(test_data->format), DDPF_RGB, 0, {32},
11648 {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0x00000000}}, TRUE},
11649 {"D3DFMT_R5G6B5", {sizeof(test_data->format), DDPF_RGB, 0, {16},
11650 {0x0000f800}, {0x000007e0}, {0x0000001f}, {0x00000000}}, TRUE},
11651 {"D3DFMT_X1R5G5B5", {sizeof(test_data->format), DDPF_RGB, 0, {16},
11652 {0x00007c00}, {0x000003e0}, {0x0000001f}, {0x00000000}}, TRUE},
11653 {"D3DFMT_A1R5G5B5", {sizeof(test_data->format), DDPF_RGB | DDPF_ALPHAPIXELS, 0, {16},
11654 {0x00007c00}, {0x000003e0}, {0x0000001f}, {0x00008000}}, TRUE},
11655 {"D3DFMT_A4R4G4B4", {sizeof(test_data->format), DDPF_RGB | DDPF_ALPHAPIXELS, 0, {16},
11656 {0x00000f00}, {0x000000f0}, {0x0000000f}, {0x0000f000}}, TRUE, DDERR_CANTCREATEDC /* Vista+ */},
11657 {"D3DFMT_X4R4G4B4", {sizeof(test_data->format), DDPF_RGB, 0, {16},
11658 {0x00000f00}, {0x000000f0}, {0x0000000f}, {0x00000000}}, TRUE, DDERR_CANTCREATEDC /* Vista+ */},
11659 {"D3DFMT_A2R10G10B10", {sizeof(test_data->format), DDPF_RGB | DDPF_ALPHAPIXELS, 0, {32},
11660 {0xc0000000}, {0x3ff00000}, {0x000ffc00}, {0x000003ff}}, TRUE},
11661 {"D3DFMT_A8B8G8R8", {sizeof(test_data->format), DDPF_RGB | DDPF_ALPHAPIXELS, 0, {32},
11662 {0x000000ff}, {0x0000ff00}, {0x00ff0000}, {0xff000000}}, TRUE, DDERR_CANTCREATEDC /* Vista+ */},
11663 {"D3DFMT_X8B8G8R8", {sizeof(test_data->format), DDPF_RGB, 0, {32},
11664 {0x000000ff}, {0x0000ff00}, {0x00ff0000}, {0x00000000}}, TRUE, DDERR_CANTCREATEDC /* Vista+ */},
11665 {"D3DFMT_R3G3B2", {sizeof(test_data->format), DDPF_RGB, 0, {8},
11666 {0x000000e0}, {0x0000001c}, {0x00000003}, {0x00000000}}, FALSE},
11667 /* GetDC() on a P8 surface fails unless the display mode is 8 bpp.
11668 * This is not implemented in wine yet, so disable the test for now.
11669 * Succeeding P8 GetDC() calls are tested in the ddraw:visual test.
11670 {"D3DFMT_P8", {sizeof(test_data->format), DDPF_PALETTEINDEXED8 | DDPF_RGB, 0, {8 },
11671 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
11673 {"D3DFMT_L8", {sizeof(test_data->format), DDPF_LUMINANCE, 0, {8},
11674 {0x000000ff}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
11675 {"D3DFMT_A8L8", {sizeof(test_data->format), DDPF_ALPHAPIXELS | DDPF_LUMINANCE, 0, {16},
11676 {0x000000ff}, {0x00000000}, {0x00000000}, {0x0000ff00}}, FALSE},
11677 {"D3DFMT_DXT1", {sizeof(test_data->format), DDPF_FOURCC, MAKEFOURCC('D','X','T','1'), {0},
11678 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
11679 {"D3DFMT_DXT2", {sizeof(test_data->format), DDPF_FOURCC, MAKEFOURCC('D','X','T','2'), {0},
11680 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
11681 {"D3DFMT_DXT3", {sizeof(test_data->format), DDPF_FOURCC, MAKEFOURCC('D','X','T','3'), {0},
11682 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
11683 {"D3DFMT_DXT4", {sizeof(test_data->format), DDPF_FOURCC, MAKEFOURCC('D','X','T','4'), {0},
11684 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
11685 {"D3DFMT_DXT5", {sizeof(test_data->format), DDPF_FOURCC, MAKEFOURCC('D','X','T','5'), {0},
11686 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
11689 window = create_window();
11690 ddraw = create_ddraw();
11691 ok(!!ddraw, "Failed to create a ddraw object.\n");
11692 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
11693 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
11695 for (i = 0; i < (sizeof(test_data) / sizeof(*test_data)); ++i)
11697 memset(&surface_desc, 0, sizeof(surface_desc));
11698 surface_desc.dwSize = sizeof(surface_desc);
11699 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
11700 surface_desc.dwWidth = 64;
11701 surface_desc.dwHeight = 64;
11702 U4(surface_desc).ddpfPixelFormat = test_data[i].format;
11703 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
11705 if (FAILED(IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL)))
11707 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
11708 surface_desc.ddsCaps.dwCaps2 = DDSCAPS2_TEXTUREMANAGE;
11709 if (FAILED(hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL)))
11711 skip("Failed to create surface for format %s (hr %#x), skipping tests.\n", test_data[i].name, hr);
11712 continue;
11716 dc = (void *)0x1234;
11717 hr = IDirectDrawSurface7_GetDC(surface, &dc);
11718 if (test_data[i].getdc_supported)
11719 ok(SUCCEEDED(hr) || (test_data[i].alt_result && hr == test_data[i].alt_result),
11720 "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11721 else
11722 ok(FAILED(hr), "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11724 if (SUCCEEDED(hr))
11726 unsigned int width_bytes;
11727 DIBSECTION dib;
11728 HBITMAP bitmap;
11729 DWORD type;
11730 int size;
11732 type = GetObjectType(dc);
11733 ok(type == OBJ_MEMDC, "Got unexpected object type %#x for format %s.\n", type, test_data[i].name);
11734 bitmap = GetCurrentObject(dc, OBJ_BITMAP);
11735 type = GetObjectType(bitmap);
11736 ok(type == OBJ_BITMAP, "Got unexpected object type %#x for format %s.\n", type, test_data[i].name);
11738 size = GetObjectA(bitmap, sizeof(dib), &dib);
11739 ok(size == sizeof(dib), "Got unexpected size %d for format %s.\n", size, test_data[i].name);
11740 ok(!dib.dsBm.bmType, "Got unexpected type %#x for format %s.\n",
11741 dib.dsBm.bmType, test_data[i].name);
11742 ok(dib.dsBm.bmWidth == surface_desc.dwWidth, "Got unexpected width %d for format %s.\n",
11743 dib.dsBm.bmWidth, test_data[i].name);
11744 ok(dib.dsBm.bmHeight == surface_desc.dwHeight, "Got unexpected height %d for format %s.\n",
11745 dib.dsBm.bmHeight, test_data[i].name);
11746 width_bytes = ((dib.dsBm.bmWidth * U1(test_data[i].format).dwRGBBitCount + 31) >> 3) & ~3;
11747 ok(dib.dsBm.bmWidthBytes == width_bytes, "Got unexpected width bytes %d for format %s.\n",
11748 dib.dsBm.bmWidthBytes, test_data[i].name);
11749 ok(dib.dsBm.bmPlanes == 1, "Got unexpected plane count %d for format %s.\n",
11750 dib.dsBm.bmPlanes, test_data[i].name);
11751 ok(dib.dsBm.bmBitsPixel == U1(test_data[i].format).dwRGBBitCount,
11752 "Got unexpected bit count %d for format %s.\n",
11753 dib.dsBm.bmBitsPixel, test_data[i].name);
11754 ok(!!dib.dsBm.bmBits, "Got unexpected bits %p for format %s.\n",
11755 dib.dsBm.bmBits, test_data[i].name);
11757 ok(dib.dsBmih.biSize == sizeof(dib.dsBmih), "Got unexpected size %u for format %s.\n",
11758 dib.dsBmih.biSize, test_data[i].name);
11759 ok(dib.dsBmih.biWidth == surface_desc.dwWidth, "Got unexpected width %d for format %s.\n",
11760 dib.dsBmih.biHeight, test_data[i].name);
11761 ok(dib.dsBmih.biHeight == surface_desc.dwHeight, "Got unexpected height %d for format %s.\n",
11762 dib.dsBmih.biHeight, test_data[i].name);
11763 ok(dib.dsBmih.biPlanes == 1, "Got unexpected plane count %u for format %s.\n",
11764 dib.dsBmih.biPlanes, test_data[i].name);
11765 ok(dib.dsBmih.biBitCount == U1(test_data[i].format).dwRGBBitCount,
11766 "Got unexpected bit count %u for format %s.\n",
11767 dib.dsBmih.biBitCount, test_data[i].name);
11768 ok(dib.dsBmih.biCompression == (U1(test_data[i].format).dwRGBBitCount == 16 ? BI_BITFIELDS : BI_RGB)
11769 || broken(U1(test_data[i].format).dwRGBBitCount == 32 && dib.dsBmih.biCompression == BI_BITFIELDS),
11770 "Got unexpected compression %#x for format %s.\n",
11771 dib.dsBmih.biCompression, test_data[i].name);
11772 ok(!dib.dsBmih.biSizeImage, "Got unexpected image size %u for format %s.\n",
11773 dib.dsBmih.biSizeImage, test_data[i].name);
11774 ok(!dib.dsBmih.biXPelsPerMeter, "Got unexpected horizontal resolution %d for format %s.\n",
11775 dib.dsBmih.biXPelsPerMeter, test_data[i].name);
11776 ok(!dib.dsBmih.biYPelsPerMeter, "Got unexpected vertical resolution %d for format %s.\n",
11777 dib.dsBmih.biYPelsPerMeter, test_data[i].name);
11778 ok(!dib.dsBmih.biClrUsed, "Got unexpected used colour count %u for format %s.\n",
11779 dib.dsBmih.biClrUsed, test_data[i].name);
11780 ok(!dib.dsBmih.biClrImportant, "Got unexpected important colour count %u for format %s.\n",
11781 dib.dsBmih.biClrImportant, test_data[i].name);
11783 if (dib.dsBmih.biCompression == BI_BITFIELDS)
11785 ok((dib.dsBitfields[0] == U2(test_data[i].format).dwRBitMask
11786 && dib.dsBitfields[1] == U3(test_data[i].format).dwGBitMask
11787 && dib.dsBitfields[2] == U4(test_data[i].format).dwBBitMask)
11788 || broken(!dib.dsBitfields[0] && !dib.dsBitfields[1] && !dib.dsBitfields[2]),
11789 "Got unexpected colour masks 0x%08x 0x%08x 0x%08x for format %s.\n",
11790 dib.dsBitfields[0], dib.dsBitfields[1], dib.dsBitfields[2], test_data[i].name);
11792 else
11794 ok(!dib.dsBitfields[0] && !dib.dsBitfields[1] && !dib.dsBitfields[2],
11795 "Got unexpected colour masks 0x%08x 0x%08x 0x%08x for format %s.\n",
11796 dib.dsBitfields[0], dib.dsBitfields[1], dib.dsBitfields[2], test_data[i].name);
11798 ok(!dib.dshSection, "Got unexpected section %p for format %s.\n", dib.dshSection, test_data[i].name);
11799 ok(!dib.dsOffset, "Got unexpected offset %u for format %s.\n", dib.dsOffset, test_data[i].name);
11801 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
11802 ok(hr == DD_OK, "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11804 else
11806 ok(!dc, "Got unexpected dc %p for format %s.\n", dc, test_data[i].name);
11809 IDirectDrawSurface7_Release(surface);
11811 if (FAILED(hr))
11812 continue;
11814 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
11815 surface_desc.ddsCaps.dwCaps2 = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES | DDSCAPS2_TEXTUREMANAGE;
11816 if (FAILED(hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL)))
11818 skip("Failed to create cube texture for format %s (hr %#x), skipping tests.\n", test_data[i].name, hr);
11819 continue;
11822 hr = IDirectDrawSurface7_GetAttachedSurface(surface, &caps, &surface2);
11823 ok(SUCCEEDED(hr), "Failed to get attached surface for format %s, hr %#x.\n", test_data[i].name, hr);
11824 hr = IDirectDrawSurface7_GetAttachedSurface(surface2, &caps, &tmp);
11825 ok(SUCCEEDED(hr), "Failed to get attached surface for format %s, hr %#x.\n", test_data[i].name, hr);
11826 IDirectDrawSurface7_Release(surface2);
11827 hr = IDirectDrawSurface7_GetAttachedSurface(tmp, &caps, &surface2);
11828 ok(SUCCEEDED(hr), "Failed to get attached surface for format %s, hr %#x.\n", test_data[i].name, hr);
11829 IDirectDrawSurface7_Release(tmp);
11831 hr = IDirectDrawSurface7_GetDC(surface, &dc);
11832 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11833 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
11834 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11835 hr = IDirectDrawSurface7_GetDC(surface2, &dc);
11836 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11837 hr = IDirectDrawSurface7_ReleaseDC(surface2, dc);
11838 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11840 hr = IDirectDrawSurface7_GetDC(surface, &dc);
11841 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11842 dc2 = (void *)0x1234;
11843 hr = IDirectDrawSurface7_GetDC(surface, &dc2);
11844 ok(hr == DDERR_DCALREADYCREATED, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11845 ok(dc2 == (void *)0x1234, "Got unexpected dc %p for format %s.\n", dc, test_data[i].name);
11846 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
11847 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11848 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
11849 ok(hr == DDERR_NODC, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11851 map_desc.dwSize = sizeof(map_desc);
11852 hr = IDirectDrawSurface7_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
11853 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
11854 hr = IDirectDrawSurface7_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
11855 ok(hr == DDERR_SURFACEBUSY, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11856 hr = IDirectDrawSurface7_Unlock(surface, NULL);
11857 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
11858 hr = IDirectDrawSurface7_Unlock(surface, NULL);
11859 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11861 hr = IDirectDrawSurface7_GetDC(surface, &dc);
11862 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11863 hr = IDirectDrawSurface7_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
11864 ok(hr == DDERR_SURFACEBUSY, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11865 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
11866 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11868 hr = IDirectDrawSurface7_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
11869 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
11870 hr = IDirectDrawSurface7_GetDC(surface, &dc);
11871 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11872 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
11873 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11874 hr = IDirectDrawSurface7_Unlock(surface, NULL);
11875 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
11877 hr = IDirectDrawSurface7_GetDC(surface, &dc);
11878 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11879 hr = IDirectDrawSurface7_GetDC(surface2, &dc2);
11880 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11881 hr = IDirectDrawSurface7_ReleaseDC(surface2, dc2);
11882 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11883 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
11884 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11886 hr = IDirectDrawSurface7_GetDC(surface2, &dc);
11887 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11888 hr = IDirectDrawSurface7_GetDC(surface, &dc2);
11889 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11890 hr = IDirectDrawSurface7_ReleaseDC(surface, dc2);
11891 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11892 hr = IDirectDrawSurface7_ReleaseDC(surface2, dc);
11893 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11895 hr = IDirectDrawSurface7_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
11896 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
11897 hr = IDirectDrawSurface7_Lock(surface2, 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_Unlock(surface2, NULL);
11900 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
11901 hr = IDirectDrawSurface7_Unlock(surface, NULL);
11902 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
11904 hr = IDirectDrawSurface7_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
11905 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
11906 hr = IDirectDrawSurface7_GetDC(surface, &dc);
11907 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11908 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
11909 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11910 hr = IDirectDrawSurface7_Unlock(surface, NULL);
11911 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
11913 hr = IDirectDrawSurface7_Lock(surface2, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
11914 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
11915 hr = IDirectDrawSurface7_GetDC(surface, &dc);
11916 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11917 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
11918 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11919 hr = IDirectDrawSurface7_Unlock(surface2, NULL);
11920 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
11922 hr = IDirectDrawSurface7_GetDC(surface, &dc);
11923 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11924 hr = IDirectDrawSurface7_Lock(surface2, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
11925 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
11926 hr = IDirectDrawSurface7_Unlock(surface2, NULL);
11927 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
11928 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
11929 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11931 hr = IDirectDrawSurface7_GetDC(surface2, &dc);
11932 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11933 hr = IDirectDrawSurface7_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
11934 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
11935 hr = IDirectDrawSurface7_Unlock(surface, NULL);
11936 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
11937 hr = IDirectDrawSurface7_ReleaseDC(surface2, dc);
11938 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11940 hr = IDirectDrawSurface7_Unlock(surface, NULL);
11941 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11942 hr = IDirectDrawSurface7_GetDC(surface2, &dc);
11943 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11944 hr = IDirectDrawSurface7_Unlock(surface, NULL);
11945 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11946 hr = IDirectDrawSurface7_ReleaseDC(surface2, dc);
11947 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11948 hr = IDirectDrawSurface7_Unlock(surface, NULL);
11949 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11951 hr = IDirectDrawSurface7_Unlock(surface2, NULL);
11952 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11953 hr = IDirectDrawSurface7_GetDC(surface, &dc);
11954 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11955 hr = IDirectDrawSurface7_Unlock(surface2, NULL);
11956 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11957 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
11958 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11959 hr = IDirectDrawSurface7_Unlock(surface2, NULL);
11960 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11962 IDirectDrawSurface7_Release(surface2);
11963 IDirectDrawSurface7_Release(surface);
11966 IDirectDraw7_Release(ddraw);
11967 DestroyWindow(window);
11970 static void test_draw_primitive(void)
11972 static WORD indices[] = {0, 1, 2, 3};
11973 static struct vec3 quad[] =
11975 {-1.0f, -1.0f, 0.0f},
11976 {-1.0f, 1.0f, 0.0f},
11977 { 1.0f, -1.0f, 0.0f},
11978 { 1.0f, 1.0f, 0.0f},
11980 D3DDRAWPRIMITIVESTRIDEDDATA strided;
11981 D3DVERTEXBUFFERDESC vb_desc;
11982 IDirect3DVertexBuffer7 *vb;
11983 IDirect3DDevice7 *device;
11984 IDirect3D7 *d3d;
11985 ULONG refcount;
11986 HWND window;
11987 HRESULT hr;
11988 void *data;
11990 window = create_window();
11991 if (!(device = create_device(window, DDSCL_NORMAL)))
11993 skip("Failed to create a 3D device, skipping test.\n");
11994 DestroyWindow(window);
11995 return;
11998 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
11999 ok(SUCCEEDED(hr), "Failed to get D3D interface, hr %#x.\n", hr);
12001 memset(&vb_desc, 0, sizeof(vb_desc));
12002 vb_desc.dwSize = sizeof(vb_desc);
12003 vb_desc.dwFVF = D3DFVF_XYZ;
12004 vb_desc.dwNumVertices = 4;
12005 hr = IDirect3D7_CreateVertexBuffer(d3d, &vb_desc, &vb, 0);
12006 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
12008 IDirect3D7_Release(d3d);
12010 memset(&strided, 0, sizeof(strided));
12012 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, NULL, 0, NULL, 0, 0);
12013 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12014 hr = IDirect3DDevice7_DrawIndexedPrimitiveStrided(device,
12015 D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, &strided, 0, NULL, 0, 0);
12016 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12017 hr = IDirect3DDevice7_DrawIndexedPrimitiveVB(device, D3DPT_TRIANGLESTRIP, vb, 0, 0, NULL, 0, 0);
12018 todo_wine ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
12019 hr = IDirect3DDevice7_DrawIndexedPrimitiveVB(device, D3DPT_TRIANGLESTRIP, vb, 0, 0, NULL, 0, 0);
12020 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12021 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, NULL, 0, 0);
12022 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12023 hr = IDirect3DDevice7_DrawPrimitiveStrided(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, &strided, 0, 0);
12024 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12025 hr = IDirect3DDevice7_DrawPrimitiveVB(device, D3DPT_TRIANGLESTRIP, vb, 0, 0, 0);
12026 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12028 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, NULL, 0, indices, 4, 0);
12029 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12030 hr = IDirect3DDevice7_DrawIndexedPrimitiveStrided(device,
12031 D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, &strided, 0, indices, 4, 0);
12032 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12033 hr = IDirect3DDevice7_DrawIndexedPrimitiveVB(device, D3DPT_TRIANGLESTRIP, vb, 0, 0, indices, 4, 0);
12034 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12036 strided.position.lpvData = quad;
12037 strided.position.dwStride = sizeof(*quad);
12038 hr = IDirect3DVertexBuffer7_Lock(vb, 0, &data, NULL);
12039 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
12040 memcpy(data, quad, sizeof(quad));
12041 hr = IDirect3DVertexBuffer7_Unlock(vb);
12042 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
12044 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, quad, 4, NULL, 0, 0);
12045 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12046 hr = IDirect3DDevice7_DrawIndexedPrimitiveStrided(device,
12047 D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, &strided, 4, NULL, 0, 0);
12048 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12049 hr = IDirect3DDevice7_DrawIndexedPrimitiveVB(device, D3DPT_TRIANGLESTRIP, vb, 0, 4, NULL, 0, 0);
12050 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12051 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, quad, 4, 0);
12052 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12053 hr = IDirect3DDevice7_DrawPrimitiveStrided(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, &strided, 4, 0);
12054 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12055 hr = IDirect3DDevice7_DrawPrimitiveVB(device, D3DPT_TRIANGLESTRIP, vb, 0, 4, 0);
12056 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12058 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, quad, 4, indices, 4, 0);
12059 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12060 hr = IDirect3DDevice7_DrawIndexedPrimitiveStrided(device,
12061 D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, &strided, 4, indices, 4, 0);
12062 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12063 hr = IDirect3DDevice7_DrawIndexedPrimitiveVB(device, D3DPT_TRIANGLESTRIP, vb, 0, 4, indices, 4, 0);
12064 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12066 IDirect3DVertexBuffer7_Release(vb);
12067 refcount = IDirect3DDevice7_Release(device);
12068 ok(!refcount, "Device has %u references left.\n", refcount);
12069 DestroyWindow(window);
12072 static void test_edge_antialiasing_blending(void)
12074 IDirectDrawSurface7 *offscreen;
12075 DDSURFACEDESC2 surface_desc;
12076 D3DDEVICEDESC7 device_desc;
12077 IDirect3DDevice7 *device;
12078 IDirectDraw7 *ddraw;
12079 IDirect3D7 *d3d;
12080 ULONG refcount;
12081 D3DCOLOR color;
12082 HWND window;
12083 HRESULT hr;
12085 static D3DMATRIX mat =
12087 1.0f, 0.0f, 0.0f, 0.0f,
12088 0.0f, 1.0f, 0.0f, 0.0f,
12089 0.0f, 0.0f, 1.0f, 0.0f,
12090 0.0f, 0.0f, 0.0f, 1.0f,
12092 static struct
12094 struct vec3 position;
12095 DWORD diffuse;
12097 green_quad[] =
12099 {{-1.0f, -1.0f, 0.1f}, 0x7f00ff00},
12100 {{-1.0f, 1.0f, 0.1f}, 0x7f00ff00},
12101 {{ 1.0f, -1.0f, 0.1f}, 0x7f00ff00},
12102 {{ 1.0f, 1.0f, 0.1f}, 0x7f00ff00},
12104 static struct
12106 struct vec3 position;
12107 DWORD diffuse;
12109 red_quad[] =
12111 {{-1.0f, -1.0f, 0.1f}, 0xccff0000},
12112 {{-1.0f, 1.0f, 0.1f}, 0xccff0000},
12113 {{ 1.0f, -1.0f, 0.1f}, 0xccff0000},
12114 {{ 1.0f, 1.0f, 0.1f}, 0xccff0000},
12117 window = create_window();
12118 if (!(device = create_device(window, DDSCL_NORMAL)))
12120 skip("Failed to create a 3D device.\n");
12121 DestroyWindow(window);
12122 return;
12125 hr = IDirect3DDevice7_GetCaps(device, &device_desc);
12126 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
12127 trace("Line edge antialiasing support: %#x.\n",
12128 device_desc.dpcLineCaps.dwRasterCaps & D3DPRASTERCAPS_ANTIALIASEDGES);
12129 trace("Triangle edge antialiasing support: %#x.\n",
12130 device_desc.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_ANTIALIASEDGES);
12132 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
12133 ok(SUCCEEDED(hr), "Failed to get D3D interface, hr %#x.\n", hr);
12134 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
12135 ok(SUCCEEDED(hr), "Failed to get DirectDraw7 interface, hr %#x.\n", hr);
12136 IDirect3D7_Release(d3d);
12138 memset(&surface_desc, 0, sizeof(surface_desc));
12139 surface_desc.dwSize = sizeof(surface_desc);
12140 surface_desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_PIXELFORMAT;
12141 surface_desc.dwWidth = 640;
12142 surface_desc.dwHeight = 480;
12143 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_3DDEVICE;
12144 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
12145 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
12146 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
12147 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
12148 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
12149 U5(U4(surface_desc).ddpfPixelFormat).dwRGBAlphaBitMask = 0xff000000;
12150 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &offscreen, NULL);
12151 ok(hr == D3D_OK, "Creating the offscreen render target failed, hr %#x.\n", hr);
12153 hr = IDirect3DDevice7_SetRenderTarget(device, offscreen, 0);
12154 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
12156 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &mat);
12157 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#x.\n", hr);
12158 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_VIEW, &mat);
12159 ok(SUCCEEDED(hr), "Failed to set view transform, hr %#x.\n", hr);
12160 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &mat);
12161 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
12162 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CLIPPING, FALSE);
12163 ok(SUCCEEDED(hr), "Failed to disable clipping, hr %#x.\n", hr);
12164 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, FALSE);
12165 ok(SUCCEEDED(hr), "Failed to disable Z test, hr %#x.\n", hr);
12166 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, FALSE);
12167 ok(SUCCEEDED(hr), "Failed to disable fog, hr %#x.\n", hr);
12168 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_STENCILENABLE, FALSE);
12169 ok(SUCCEEDED(hr), "Failed to disable stencil test, hr %#x.\n", hr);
12170 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CULLMODE, D3DCULL_NONE);
12171 ok(SUCCEEDED(hr), "Failed to disable culling, hr %#x.\n", hr);
12172 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
12173 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
12175 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);
12176 ok(SUCCEEDED(hr), "Failed to enable blending, hr %#x.\n", hr);
12177 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);
12178 ok(SUCCEEDED(hr), "Failed to set src blend, hr %#x.\n", hr);
12179 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_DESTBLEND, D3DBLEND_DESTALPHA);
12180 ok(SUCCEEDED(hr), "Failed to set dest blend, hr %#x.\n", hr);
12182 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
12183 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
12184 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);
12185 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
12186 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
12187 ok(SUCCEEDED(hr), "Failed to set alpha op, hr %#x.\n", hr);
12188 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);
12189 ok(SUCCEEDED(hr), "Failed to set alpha arg, hr %#x.\n", hr);
12191 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xccff0000, 0.0f, 0);
12192 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
12193 hr = IDirect3DDevice7_BeginScene(device);
12194 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
12195 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE,
12196 green_quad, 4, 0);
12197 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12198 hr = IDirect3DDevice7_EndScene(device);
12199 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
12200 color = get_surface_color(offscreen, 320, 240);
12201 ok(compare_color(color, 0x00cc7f00, 1), "Got unexpected color 0x%08x.\n", color);
12203 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x7f00ff00, 0.0f, 0);
12204 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
12205 hr = IDirect3DDevice7_BeginScene(device);
12206 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
12207 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE,
12208 red_quad, 4, 0);
12209 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12210 hr = IDirect3DDevice7_EndScene(device);
12211 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
12212 color = get_surface_color(offscreen, 320, 240);
12213 ok(compare_color(color, 0x00cc7f00, 1), "Got unexpected color 0x%08x.\n", color);
12215 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, FALSE);
12216 ok(SUCCEEDED(hr), "Failed to disable blending, hr %#x.\n", hr);
12218 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xccff0000, 0.0f, 0);
12219 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
12220 hr = IDirect3DDevice7_BeginScene(device);
12221 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
12222 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE,
12223 green_quad, 4, 0);
12224 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12225 hr = IDirect3DDevice7_EndScene(device);
12226 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
12227 color = get_surface_color(offscreen, 320, 240);
12228 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
12230 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x7f00ff00, 0.0f, 0);
12231 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
12232 hr = IDirect3DDevice7_BeginScene(device);
12233 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
12234 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE,
12235 red_quad, 4, 0);
12236 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12237 hr = IDirect3DDevice7_EndScene(device);
12238 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
12239 color = get_surface_color(offscreen, 320, 240);
12240 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
12242 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_EDGEANTIALIAS, TRUE);
12243 ok(SUCCEEDED(hr), "Failed to enable edge antialiasing, hr %#x.\n", hr);
12245 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xccff0000, 0.0f, 0);
12246 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
12247 hr = IDirect3DDevice7_BeginScene(device);
12248 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
12249 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE,
12250 green_quad, 4, 0);
12251 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12252 hr = IDirect3DDevice7_EndScene(device);
12253 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
12254 color = get_surface_color(offscreen, 320, 240);
12255 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
12257 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x7f00ff00, 0.0f, 0);
12258 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
12259 hr = IDirect3DDevice7_BeginScene(device);
12260 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
12261 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE,
12262 red_quad, 4, 0);
12263 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12264 hr = IDirect3DDevice7_EndScene(device);
12265 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
12266 color = get_surface_color(offscreen, 320, 240);
12267 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
12269 IDirectDrawSurface7_Release(offscreen);
12270 IDirectDraw7_Release(ddraw);
12271 refcount = IDirect3DDevice7_Release(device);
12272 ok(!refcount, "Device has %u references left.\n", refcount);
12273 DestroyWindow(window);
12276 static void test_display_mode_surface_pixel_format(void)
12278 unsigned int width, height, bpp;
12279 IDirectDrawSurface7 *surface;
12280 DDSURFACEDESC2 surface_desc;
12281 IDirectDraw7 *ddraw;
12282 ULONG refcount;
12283 HWND window;
12284 HRESULT hr;
12286 if (!(ddraw = create_ddraw()))
12288 skip("Failed to create ddraw.\n");
12289 return;
12292 surface_desc.dwSize = sizeof(surface_desc);
12293 hr = IDirectDraw7_GetDisplayMode(ddraw, &surface_desc);
12294 ok(SUCCEEDED(hr), "Failed to get display mode, hr %#x.\n", hr);
12295 width = surface_desc.dwWidth;
12296 height = surface_desc.dwHeight;
12298 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
12299 0, 0, width, height, NULL, NULL, NULL, NULL);
12300 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
12301 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
12303 bpp = 0;
12304 if (SUCCEEDED(IDirectDraw7_SetDisplayMode(ddraw, width, height, 16, 0, 0)))
12305 bpp = 16;
12306 if (SUCCEEDED(IDirectDraw7_SetDisplayMode(ddraw, width, height, 24, 0, 0)))
12307 bpp = 24;
12308 if (SUCCEEDED(IDirectDraw7_SetDisplayMode(ddraw, width, height, 32, 0, 0)))
12309 bpp = 32;
12310 ok(bpp, "Set display mode failed.\n");
12312 surface_desc.dwSize = sizeof(surface_desc);
12313 hr = IDirectDraw7_GetDisplayMode(ddraw, &surface_desc);
12314 ok(SUCCEEDED(hr), "Failed to get display mode, hr %#x.\n", hr);
12315 ok(surface_desc.dwWidth == width, "Got width %u, expected %u.\n", surface_desc.dwWidth, width);
12316 ok(surface_desc.dwHeight == height, "Got height %u, expected %u.\n", surface_desc.dwHeight, height);
12317 ok(U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount == bpp, "Got bpp %u, expected %u.\n",
12318 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount, bpp);
12320 memset(&surface_desc, 0, sizeof(surface_desc));
12321 surface_desc.dwSize = sizeof(surface_desc);
12322 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
12323 U5(surface_desc).dwBackBufferCount = 1;
12324 surface_desc.ddsCaps.dwCaps = DDSCAPS_COMPLEX | DDSCAPS_FLIP | DDSCAPS_PRIMARYSURFACE;
12325 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
12326 ok(hr == D3D_OK, "Failed to create surface, hr %#x.\n", hr);
12327 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &surface_desc);
12328 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
12329 ok(surface_desc.dwWidth == width, "Got width %u, expected %u.\n", surface_desc.dwWidth, width);
12330 ok(surface_desc.dwHeight == height, "Got height %u, expected %u.\n", surface_desc.dwHeight, height);
12331 ok(U4(surface_desc).ddpfPixelFormat.dwFlags == DDPF_RGB, "Got unexpected pixel format flags %#x.\n",
12332 U4(surface_desc).ddpfPixelFormat.dwFlags);
12333 ok(U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount == bpp, "Got bpp %u, expected %u.\n",
12334 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount, bpp);
12335 IDirectDrawSurface7_Release(surface);
12337 memset(&surface_desc, 0, sizeof(surface_desc));
12338 surface_desc.dwSize = sizeof(surface_desc);
12339 surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
12340 surface_desc.dwWidth = width;
12341 surface_desc.dwHeight = height;
12342 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
12343 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
12344 ok(hr == D3D_OK, "Failed to create surface, hr %#x.\n", hr);
12345 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &surface_desc);
12346 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
12347 ok(U4(surface_desc).ddpfPixelFormat.dwFlags == DDPF_RGB, "Got unexpected pixel format flags %#x.\n",
12348 U4(surface_desc).ddpfPixelFormat.dwFlags);
12349 ok(U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount == bpp, "Got bpp %u, expected %u.\n",
12350 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount, bpp);
12351 IDirectDrawSurface7_Release(surface);
12353 refcount = IDirectDraw7_Release(ddraw);
12354 ok(!refcount, "DirectDraw has %u references left.\n", refcount);
12355 DestroyWindow(window);
12358 static void test_surface_desc_size(void)
12360 union
12362 DWORD dwSize;
12363 DDSURFACEDESC desc1;
12364 DDSURFACEDESC2 desc2;
12365 BYTE blob[1024];
12366 } desc;
12367 IDirectDrawSurface7 *surface7;
12368 IDirectDrawSurface3 *surface3;
12369 IDirectDrawSurface *surface;
12370 DDSURFACEDESC2 surface_desc;
12371 HRESULT expected_hr, hr;
12372 IDirectDraw7 *ddraw;
12373 unsigned int i, j;
12374 ULONG refcount;
12376 static const struct
12378 unsigned int caps;
12379 const char *name;
12381 surface_caps[] =
12383 {DDSCAPS_OFFSCREENPLAIN, "offscreenplain"},
12384 {DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, "systemmemory texture"},
12385 {DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, "videomemory texture"},
12387 static const unsigned int desc_sizes[] =
12389 sizeof(DDSURFACEDESC),
12390 sizeof(DDSURFACEDESC2),
12391 sizeof(DDSURFACEDESC) + 1,
12392 sizeof(DDSURFACEDESC2) + 1,
12393 2 * sizeof(DDSURFACEDESC),
12394 2 * sizeof(DDSURFACEDESC2),
12395 sizeof(DDSURFACEDESC) - 1,
12396 sizeof(DDSURFACEDESC2) - 1,
12397 sizeof(DDSURFACEDESC) / 2,
12398 sizeof(DDSURFACEDESC2) / 2,
12402 sizeof(desc) / 2,
12403 sizeof(desc) - 100,
12406 if (!(ddraw = create_ddraw()))
12408 skip("Failed to create ddraw.\n");
12409 return;
12411 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
12412 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
12414 for (i = 0; i < sizeof(surface_caps) / sizeof(*surface_caps); ++i)
12416 memset(&surface_desc, 0, sizeof(surface_desc));
12417 surface_desc.dwSize = sizeof(surface_desc);
12418 surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
12419 surface_desc.ddsCaps.dwCaps = surface_caps[i].caps;
12420 surface_desc.dwHeight = 128;
12421 surface_desc.dwWidth = 128;
12422 if (FAILED(IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface7, NULL)))
12424 skip("Failed to create surface, type %s.\n", surface_caps[i].name);
12425 continue;
12427 hr = IDirectDrawSurface_QueryInterface(surface7, &IID_IDirectDrawSurface, (void **)&surface);
12428 ok(hr == DD_OK, "Failed to query IDirectDrawSurface, hr %#x, type %s.\n", hr, surface_caps[i].name);
12429 hr = IDirectDrawSurface_QueryInterface(surface7, &IID_IDirectDrawSurface3, (void **)&surface3);
12430 ok(hr == DD_OK, "Failed to query IDirectDrawSurface3, hr %#x, type %s.\n", hr, surface_caps[i].name);
12432 /* GetSurfaceDesc() */
12433 for (j = 0; j < sizeof(desc_sizes) / sizeof(*desc_sizes); ++j)
12435 memset(&desc, 0, sizeof(desc));
12436 desc.dwSize = desc_sizes[j];
12437 expected_hr = desc.dwSize == sizeof(DDSURFACEDESC) ? DD_OK : DDERR_INVALIDPARAMS;
12438 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &desc.desc1);
12439 ok(hr == expected_hr, "Got hr %#x, expected %#x, dwSize %u, type %s.\n",
12440 hr, expected_hr, desc_sizes[j], surface_caps[i].name);
12442 memset(&desc, 0, sizeof(desc));
12443 desc.dwSize = desc_sizes[j];
12444 expected_hr = desc.dwSize == sizeof(DDSURFACEDESC) ? DD_OK : DDERR_INVALIDPARAMS;
12445 hr = IDirectDrawSurface3_GetSurfaceDesc(surface3, &desc.desc1);
12446 ok(hr == expected_hr, "Got hr %#x, expected %#x, dwSize %u, type %s.\n",
12447 hr, expected_hr, desc_sizes[j], surface_caps[i].name);
12449 memset(&desc, 0, sizeof(desc));
12450 desc.dwSize = desc_sizes[j];
12451 expected_hr = desc.dwSize == sizeof(DDSURFACEDESC2) ? DD_OK : DDERR_INVALIDPARAMS;
12452 hr = IDirectDrawSurface7_GetSurfaceDesc(surface7, &desc.desc2);
12453 ok(hr == expected_hr, "Got hr %#x, expected %#x, dwSize %u, type %s.\n",
12454 hr, expected_hr, desc_sizes[j], surface_caps[i].name);
12457 /* Lock() */
12458 for (j = 0; j < sizeof(desc_sizes) / sizeof(*desc_sizes); ++j)
12460 const BOOL ignore_size = surface_caps[i].caps & DDSCAPS_TEXTURE
12461 && !(surface_caps[i].caps & DDSCAPS_VIDEOMEMORY);
12462 const BOOL valid_size = desc_sizes[j] == sizeof(DDSURFACEDESC)
12463 || desc_sizes[j] == sizeof(DDSURFACEDESC2);
12464 DWORD expected_texture_stage;
12466 memset(&desc, 0, sizeof(desc));
12467 desc.dwSize = desc_sizes[j];
12468 desc.desc2.dwTextureStage = 0xdeadbeef;
12469 desc.blob[sizeof(DDSURFACEDESC2)] = 0xef;
12470 hr = IDirectDrawSurface_Lock(surface, NULL, &desc.desc1, 0, 0);
12471 expected_hr = ignore_size || valid_size ? DD_OK : DDERR_INVALIDPARAMS;
12472 ok(hr == expected_hr, "Got hr %#x, expected %#x, dwSize %u, type %s.\n",
12473 hr, expected_hr, desc_sizes[j], surface_caps[i].name);
12474 ok(desc.dwSize == desc_sizes[j], "dwSize was changed from %u to %u, type %s.\n",
12475 desc_sizes[j], desc.dwSize, surface_caps[i].name);
12476 ok(desc.blob[sizeof(DDSURFACEDESC2)] == 0xef, "Got unexpected byte %02x, dwSize %u, type %s.\n",
12477 desc.blob[sizeof(DDSURFACEDESC2)], desc_sizes[j], surface_caps[i].name);
12478 if (SUCCEEDED(hr))
12480 ok(desc.desc1.dwWidth == 128, "Got unexpected width %u, dwSize %u, type %s.\n",
12481 desc.desc1.dwWidth, desc_sizes[j], surface_caps[i].name);
12482 ok(desc.desc1.dwHeight == 128, "Got unexpected height %u, dwSize %u, type %s.\n",
12483 desc.desc1.dwHeight, desc_sizes[j], surface_caps[i].name);
12484 expected_texture_stage = desc_sizes[j] >= sizeof(DDSURFACEDESC2) ? 0 : 0xdeadbeef;
12485 todo_wine_if(!expected_texture_stage)
12486 ok(desc.desc2.dwTextureStage == expected_texture_stage,
12487 "Got unexpected texture stage %#x, dwSize %u, type %s.\n",
12488 desc.desc2.dwTextureStage, desc_sizes[j], surface_caps[i].name);
12489 IDirectDrawSurface_Unlock(surface, NULL);
12492 memset(&desc, 0, sizeof(desc));
12493 desc.dwSize = desc_sizes[j];
12494 desc.desc2.dwTextureStage = 0xdeadbeef;
12495 desc.blob[sizeof(DDSURFACEDESC2)] = 0xef;
12496 hr = IDirectDrawSurface3_Lock(surface3, NULL, &desc.desc1, 0, 0);
12497 expected_hr = ignore_size || valid_size ? DD_OK : DDERR_INVALIDPARAMS;
12498 ok(hr == expected_hr, "Got hr %#x, expected %#x, dwSize %u, type %s.\n",
12499 hr, expected_hr, desc_sizes[j], surface_caps[i].name);
12500 ok(desc.dwSize == desc_sizes[j], "dwSize was changed from %u to %u, type %s.\n",
12501 desc_sizes[j], desc.dwSize, surface_caps[i].name);
12502 ok(desc.blob[sizeof(DDSURFACEDESC2)] == 0xef, "Got unexpected byte %02x, dwSize %u, type %s.\n",
12503 desc.blob[sizeof(DDSURFACEDESC2)], desc_sizes[j], surface_caps[i].name);
12504 if (SUCCEEDED(hr))
12506 ok(desc.desc1.dwWidth == 128, "Got unexpected width %u, dwSize %u, type %s.\n",
12507 desc.desc1.dwWidth, desc_sizes[j], surface_caps[i].name);
12508 ok(desc.desc1.dwHeight == 128, "Got unexpected height %u, dwSize %u, type %s.\n",
12509 desc.desc1.dwHeight, desc_sizes[j], surface_caps[i].name);
12510 expected_texture_stage = desc_sizes[j] >= sizeof(DDSURFACEDESC2) ? 0 : 0xdeadbeef;
12511 todo_wine_if(!expected_texture_stage)
12512 ok(desc.desc2.dwTextureStage == expected_texture_stage,
12513 "Got unexpected texture stage %#x, dwSize %u, type %s.\n",
12514 desc.desc2.dwTextureStage, desc_sizes[j], surface_caps[i].name);
12515 IDirectDrawSurface3_Unlock(surface3, NULL);
12518 memset(&desc, 0, sizeof(desc));
12519 desc.dwSize = desc_sizes[j];
12520 desc.desc2.dwTextureStage = 0xdeadbeef;
12521 desc.blob[sizeof(DDSURFACEDESC2)] = 0xef;
12522 hr = IDirectDrawSurface7_Lock(surface7, NULL, &desc.desc2, 0, 0);
12523 expected_hr = ignore_size || valid_size ? DD_OK : DDERR_INVALIDPARAMS;
12524 ok(hr == expected_hr, "Got hr %#x, expected %#x, dwSize %u, type %s.\n",
12525 hr, expected_hr, desc_sizes[j], surface_caps[i].name);
12526 ok(desc.dwSize == desc_sizes[j], "dwSize was changed from %u to %u, type %s.\n",
12527 desc_sizes[j], desc.dwSize, surface_caps[i].name);
12528 ok(desc.blob[sizeof(DDSURFACEDESC2)] == 0xef, "Got unexpected byte %02x, dwSize %u, type %s.\n",
12529 desc.blob[sizeof(DDSURFACEDESC2)], desc_sizes[j], surface_caps[i].name);
12530 if (SUCCEEDED(hr))
12532 ok(desc.desc2.dwWidth == 128, "Got unexpected width %u, dwSize %u, type %s.\n",
12533 desc.desc2.dwWidth, desc_sizes[j], surface_caps[i].name);
12534 ok(desc.desc2.dwHeight == 128, "Got unexpected height %u, dwSize %u, type %s.\n",
12535 desc.desc2.dwHeight, desc_sizes[j], surface_caps[i].name);
12536 expected_texture_stage = desc_sizes[j] >= sizeof(DDSURFACEDESC2) ? 0 : 0xdeadbeef;
12537 ok(desc.desc2.dwTextureStage == expected_texture_stage,
12538 "Got unexpected texture stage %#x, dwSize %u, type %s.\n",
12539 desc.desc2.dwTextureStage, desc_sizes[j], surface_caps[i].name);
12540 IDirectDrawSurface7_Unlock(surface7, NULL);
12544 IDirectDrawSurface7_Release(surface7);
12545 IDirectDrawSurface3_Release(surface3);
12546 IDirectDrawSurface_Release(surface);
12549 /* GetDisplayMode() */
12550 for (j = 0; j < sizeof(desc_sizes) / sizeof(*desc_sizes); ++j)
12552 memset(&desc, 0xcc, sizeof(desc));
12553 desc.dwSize = desc_sizes[j];
12554 expected_hr = (desc.dwSize == sizeof(DDSURFACEDESC) || desc.dwSize == sizeof(DDSURFACEDESC2))
12555 ? DD_OK : DDERR_INVALIDPARAMS;
12556 hr = IDirectDraw7_GetDisplayMode(ddraw, &desc.desc2);
12557 ok(hr == expected_hr, "Got hr %#x, expected %#x, size %u.\n", hr, expected_hr, desc_sizes[j]);
12558 if (SUCCEEDED(hr))
12560 ok(desc.dwSize == sizeof(DDSURFACEDESC2), "Wrong size %u for %u.\n", desc.dwSize, desc_sizes[j]);
12561 ok(desc.blob[desc_sizes[j]] == 0xcc, "Overflow for size %u.\n", desc_sizes[j]);
12562 ok(desc.blob[desc_sizes[j] - 1] != 0xcc, "Struct not cleared for size %u.\n", desc_sizes[j]);
12566 refcount = IDirectDraw7_Release(ddraw);
12567 ok(!refcount, "DirectDraw has %u references left.\n", refcount);
12570 static void test_get_surface_from_dc(void)
12572 IDirectDrawSurface *surface1, *tmp1;
12573 IDirectDrawSurface7 *surface, *tmp;
12574 DDSURFACEDESC2 surface_desc;
12575 IDirectDraw7 *ddraw;
12576 HDC dc, device_dc;
12577 ULONG refcount;
12578 HWND window;
12579 HRESULT hr;
12580 DWORD ret;
12582 window = create_window();
12583 ddraw = create_ddraw();
12584 ok(!!ddraw, "Failed to create a ddraw object.\n");
12585 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
12586 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
12588 memset(&surface_desc, 0, sizeof(surface_desc));
12589 surface_desc.dwSize = sizeof(surface_desc);
12590 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
12591 surface_desc.dwWidth = 64;
12592 surface_desc.dwHeight = 64;
12593 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
12595 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
12596 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
12597 hr = IDirectDrawSurface7_QueryInterface(surface, &IID_IDirectDrawSurface, (void **)&surface1);
12598 ok(SUCCEEDED(hr), "Failed to query IDirectDrawSurface interface, hr %#x.\n", hr);
12600 refcount = get_refcount((IUnknown *)surface1);
12601 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
12602 refcount = get_refcount((IUnknown *)surface);
12603 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
12605 hr = IDirectDrawSurface7_GetDC(surface, &dc);
12606 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
12608 tmp1 = (void *)0xdeadbeef;
12609 device_dc = (void *)0xdeadbeef;
12610 hr = GetSurfaceFromDC(NULL, &tmp1, &device_dc);
12611 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
12612 ok(!tmp1, "Got unexpected surface %p.\n", tmp1);
12613 ok(!device_dc, "Got unexpected device_dc %p.\n", device_dc);
12615 device_dc = (void *)0xdeadbeef;
12616 hr = GetSurfaceFromDC(dc, NULL, &device_dc);
12617 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
12618 ok(device_dc == (void *)0xdeadbeef, "Got unexpected device_dc %p.\n", device_dc);
12620 tmp1 = (void *)0xdeadbeef;
12621 hr = GetSurfaceFromDC(dc, &tmp1, NULL);
12622 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
12623 ok(!tmp1, "Got unexpected surface %p.\n", tmp1);
12625 hr = GetSurfaceFromDC(dc, &tmp1, &device_dc);
12626 ok(SUCCEEDED(hr), "GetSurfaceFromDC failed, hr %#x.\n", hr);
12627 ok(tmp1 == surface1, "Got unexpected surface %p, expected %p.\n", tmp1, surface1);
12628 IDirectDrawSurface_Release(tmp1);
12630 ret = GetObjectType(device_dc);
12631 todo_wine ok(ret == OBJ_DC, "Got unexpected object type %#x.\n", ret);
12632 ret = GetDeviceCaps(device_dc, TECHNOLOGY);
12633 todo_wine ok(ret == DT_RASDISPLAY, "Got unexpected technology %#x.\n", ret);
12635 hr = IDirectDraw7_GetSurfaceFromDC(ddraw, dc, NULL);
12636 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
12638 hr = IDirectDraw7_GetSurfaceFromDC(ddraw, dc, &tmp);
12639 ok(SUCCEEDED(hr), "GetSurfaceFromDC failed, hr %#x.\n", hr);
12640 ok(tmp == surface, "Got unexpected surface %p, expected %p.\n", tmp, surface);
12642 refcount = get_refcount((IUnknown *)surface1);
12643 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
12644 refcount = get_refcount((IUnknown *)surface);
12645 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
12647 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
12648 ok(SUCCEEDED(hr), "ReleaseDC failed, hr %#x.\n", hr);
12650 IDirectDrawSurface_Release(tmp);
12652 dc = CreateCompatibleDC(NULL);
12653 ok(!!dc, "CreateCompatibleDC failed.\n");
12655 tmp1 = (void *)0xdeadbeef;
12656 device_dc = (void *)0xdeadbeef;
12657 hr = GetSurfaceFromDC(dc, &tmp1, &device_dc);
12658 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
12659 ok(!tmp1, "Got unexpected surface %p.\n", tmp1);
12660 ok(!device_dc, "Got unexpected device_dc %p.\n", device_dc);
12662 tmp = (void *)0xdeadbeef;
12663 hr = IDirectDraw7_GetSurfaceFromDC(ddraw, dc, &tmp);
12664 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
12665 ok(!tmp, "Got unexpected surface %p.\n", tmp);
12667 ok(DeleteDC(dc), "DeleteDC failed.\n");
12669 tmp = (void *)0xdeadbeef;
12670 hr = IDirectDraw7_GetSurfaceFromDC(ddraw, NULL, &tmp);
12671 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
12672 ok(!tmp, "Got unexpected surface %p.\n", tmp);
12674 IDirectDrawSurface7_Release(surface);
12675 IDirectDrawSurface_Release(surface1);
12676 IDirectDraw7_Release(ddraw);
12677 DestroyWindow(window);
12680 static void test_ck_operation(void)
12682 IDirectDrawSurface7 *src, *dst;
12683 IDirectDrawSurface *src1, *dst1;
12684 DDSURFACEDESC2 surface_desc;
12685 IDirectDraw7 *ddraw;
12686 ULONG refcount;
12687 HWND window;
12688 HRESULT hr;
12689 D3DCOLOR *color;
12690 unsigned int i;
12691 DDCOLORKEY ckey;
12692 DDBLTFX fx;
12694 window = create_window();
12695 ddraw = create_ddraw();
12696 ok(!!ddraw, "Failed to create a ddraw object.\n");
12697 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
12698 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
12700 memset(&surface_desc, 0, sizeof(surface_desc));
12701 surface_desc.dwSize = sizeof(surface_desc);
12702 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
12703 surface_desc.dwWidth = 4;
12704 surface_desc.dwHeight = 1;
12705 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
12706 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
12707 U1(U4(surface_desc.ddpfPixelFormat)).dwRGBBitCount = 32;
12708 U2(U4(surface_desc.ddpfPixelFormat)).dwRBitMask = 0x00ff0000;
12709 U3(U4(surface_desc.ddpfPixelFormat)).dwGBitMask = 0x0000ff00;
12710 U4(U4(surface_desc.ddpfPixelFormat)).dwBBitMask = 0x000000ff;
12711 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &dst, NULL);
12712 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
12714 surface_desc.dwFlags |= DDSD_CKSRCBLT;
12715 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00ff00ff;
12716 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00ff00ff;
12717 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &src, NULL);
12718 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
12720 hr = IDirectDrawSurface7_Lock(src, NULL, &surface_desc, DDLOCK_WAIT, NULL);
12721 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
12722 ok(!(surface_desc.dwFlags & DDSD_LPSURFACE), "Surface desc has LPSURFACE Flags set.\n");
12723 color = surface_desc.lpSurface;
12724 color[0] = 0x77010203;
12725 color[1] = 0x00010203;
12726 color[2] = 0x77ff00ff;
12727 color[3] = 0x00ff00ff;
12728 hr = IDirectDrawSurface7_Unlock(src, NULL);
12729 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
12731 for (i = 0; i < 2; ++i)
12733 hr = IDirectDrawSurface7_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
12734 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
12735 color = surface_desc.lpSurface;
12736 color[0] = 0xcccccccc;
12737 color[1] = 0xcccccccc;
12738 color[2] = 0xcccccccc;
12739 color[3] = 0xcccccccc;
12740 hr = IDirectDrawSurface7_Unlock(dst, NULL);
12741 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
12743 if (i)
12745 hr = IDirectDrawSurface7_BltFast(dst, 0, 0, src, NULL, DDBLTFAST_SRCCOLORKEY);
12746 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
12748 else
12750 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_KEYSRC, NULL);
12751 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
12754 hr = IDirectDrawSurface7_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT | DDLOCK_READONLY, NULL);
12755 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
12756 ok(!(surface_desc.dwFlags & DDSD_LPSURFACE), "Surface desc has LPSURFACE Flags set.\n");
12757 color = surface_desc.lpSurface;
12758 /* Different behavior on some drivers / windows versions. Some versions ignore the X channel when
12759 * color keying, but copy it to the destination surface. Others (sysmem surfaces) apply it for
12760 * color keying, but do not copy it into the destination surface. Nvidia neither uses it for
12761 * color keying nor copies it. */
12762 ok((color[0] == 0x77010203 && color[1] == 0x00010203
12763 && color[2] == 0xcccccccc && color[3] == 0xcccccccc) /* AMD, Wine */
12764 || broken(color[0] == 0x00010203 && color[1] == 0x00010203
12765 && color[2] == 0x00ff00ff && color[3] == 0xcccccccc) /* Sysmem surfaces? */
12766 || broken(color[0] == 0x00010203 && color[1] == 0x00010203
12767 && color[2] == 0xcccccccc && color[3] == 0xcccccccc) /* Nvidia */
12768 || broken(color[0] == 0xff010203 && color[1] == 0xff010203
12769 && color[2] == 0xcccccccc && color[3] == 0xcccccccc) /* Testbot */,
12770 "Destination data after blitting is %08x %08x %08x %08x, i=%u.\n",
12771 color[0], color[1], color[2], color[3], i);
12772 hr = IDirectDrawSurface7_Unlock(dst, NULL);
12773 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
12776 hr = IDirectDrawSurface7_GetColorKey(src, DDCKEY_SRCBLT, &ckey);
12777 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
12778 ok(ckey.dwColorSpaceLowValue == 0x00ff00ff && ckey.dwColorSpaceHighValue == 0x00ff00ff,
12779 "Got unexpected color key low=%08x high=%08x.\n", ckey.dwColorSpaceLowValue, ckey.dwColorSpaceHighValue);
12781 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0x0000ff00;
12782 hr = IDirectDrawSurface7_SetColorKey(src, DDCKEY_SRCBLT, &ckey);
12783 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
12785 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0;
12786 hr = IDirectDrawSurface7_GetColorKey(src, DDCKEY_SRCBLT, &ckey);
12787 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
12788 ok(ckey.dwColorSpaceLowValue == 0x0000ff00 && ckey.dwColorSpaceHighValue == 0x0000ff00,
12789 "Got unexpected color key low=%08x high=%08x.\n", ckey.dwColorSpaceLowValue, ckey.dwColorSpaceHighValue);
12791 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0;
12792 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0;
12793 hr = IDirectDrawSurface7_GetSurfaceDesc(src, &surface_desc);
12794 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
12795 ok(surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue == 0x0000ff00
12796 && surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue == 0x0000ff00,
12797 "Got unexpected color key low=%08x high=%08x.\n", surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue,
12798 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue);
12800 /* Test SetColorKey with dwColorSpaceHighValue < dwColorSpaceLowValue */
12801 ckey.dwColorSpaceLowValue = 0x000000ff;
12802 ckey.dwColorSpaceHighValue = 0x00000000;
12803 hr = IDirectDrawSurface7_SetColorKey(src, DDCKEY_SRCBLT, &ckey);
12804 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
12806 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0;
12807 hr = IDirectDrawSurface7_GetColorKey(src, DDCKEY_SRCBLT, &ckey);
12808 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
12809 ok(ckey.dwColorSpaceLowValue == 0x000000ff && ckey.dwColorSpaceHighValue == 0x000000ff,
12810 "Got unexpected color key low=%08x high=%08x.\n", ckey.dwColorSpaceLowValue, ckey.dwColorSpaceHighValue);
12812 ckey.dwColorSpaceLowValue = 0x000000ff;
12813 ckey.dwColorSpaceHighValue = 0x00000001;
12814 hr = IDirectDrawSurface7_SetColorKey(src, DDCKEY_SRCBLT, &ckey);
12815 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
12817 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0;
12818 hr = IDirectDrawSurface7_GetColorKey(src, DDCKEY_SRCBLT, &ckey);
12819 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
12820 ok(ckey.dwColorSpaceLowValue == 0x000000ff && ckey.dwColorSpaceHighValue == 0x000000ff,
12821 "Got unexpected color key low=%08x high=%08x.\n", ckey.dwColorSpaceLowValue, ckey.dwColorSpaceHighValue);
12823 ckey.dwColorSpaceLowValue = 0x000000fe;
12824 ckey.dwColorSpaceHighValue = 0x000000fd;
12825 hr = IDirectDrawSurface7_SetColorKey(src, DDCKEY_SRCBLT, &ckey);
12826 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
12828 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0;
12829 hr = IDirectDrawSurface7_GetColorKey(src, DDCKEY_SRCBLT, &ckey);
12830 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
12831 ok(ckey.dwColorSpaceLowValue == 0x000000fe && ckey.dwColorSpaceHighValue == 0x000000fe,
12832 "Got unexpected color key low=%08x high=%08x.\n", ckey.dwColorSpaceLowValue, ckey.dwColorSpaceHighValue);
12834 IDirectDrawSurface7_Release(src);
12835 IDirectDrawSurface7_Release(dst);
12837 /* Test source and destination keys and where they are read from. Use a surface with alpha
12838 * to avoid driver-dependent content in the X channel. */
12839 memset(&surface_desc, 0, sizeof(surface_desc));
12840 surface_desc.dwSize = sizeof(surface_desc);
12841 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
12842 surface_desc.dwWidth = 6;
12843 surface_desc.dwHeight = 1;
12844 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
12845 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
12846 U1(U4(surface_desc.ddpfPixelFormat)).dwRGBBitCount = 32;
12847 U2(U4(surface_desc.ddpfPixelFormat)).dwRBitMask = 0x00ff0000;
12848 U3(U4(surface_desc.ddpfPixelFormat)).dwGBitMask = 0x0000ff00;
12849 U4(U4(surface_desc.ddpfPixelFormat)).dwBBitMask = 0x000000ff;
12850 U5(U4(surface_desc.ddpfPixelFormat)).dwRGBAlphaBitMask = 0xff000000;
12851 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &dst, NULL);
12852 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
12853 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &src, NULL);
12854 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
12856 ckey.dwColorSpaceLowValue = 0x0000ff00;
12857 ckey.dwColorSpaceHighValue = 0x0000ff00;
12858 hr = IDirectDrawSurface7_SetColorKey(dst, DDCKEY_SRCBLT, &ckey);
12859 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
12860 ckey.dwColorSpaceLowValue = 0x00ff0000;
12861 ckey.dwColorSpaceHighValue = 0x00ff0000;
12862 hr = IDirectDrawSurface7_SetColorKey(dst, DDCKEY_DESTBLT, &ckey);
12863 ok(SUCCEEDED(hr) || hr == DDERR_NOCOLORKEYHW, "Failed to set color key, hr %#x.\n", hr);
12864 if (FAILED(hr))
12866 /* Nvidia reject dest keys, AMD allows them. This applies to vidmem and sysmem surfaces. */
12867 skip("Failed to set destination color key, skipping related tests.\n");
12868 goto done;
12871 ckey.dwColorSpaceLowValue = 0x000000ff;
12872 ckey.dwColorSpaceHighValue = 0x000000ff;
12873 hr = IDirectDrawSurface7_SetColorKey(src, DDCKEY_SRCBLT, &ckey);
12874 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
12875 ckey.dwColorSpaceLowValue = 0x000000aa;
12876 ckey.dwColorSpaceHighValue = 0x000000aa;
12877 hr = IDirectDrawSurface7_SetColorKey(src, DDCKEY_DESTBLT, &ckey);
12878 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
12880 memset(&fx, 0, sizeof(fx));
12881 fx.dwSize = sizeof(fx);
12882 fx.ddckSrcColorkey.dwColorSpaceHighValue = 0x00110000;
12883 fx.ddckSrcColorkey.dwColorSpaceLowValue = 0x00110000;
12884 fx.ddckDestColorkey.dwColorSpaceHighValue = 0x00001100;
12885 fx.ddckDestColorkey.dwColorSpaceLowValue = 0x00001100;
12887 hr = IDirectDrawSurface7_Lock(src, NULL, &surface_desc, DDLOCK_WAIT, NULL);
12888 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
12889 color = surface_desc.lpSurface;
12890 color[0] = 0x000000ff; /* Applies to src blt key in src surface. */
12891 color[1] = 0x000000aa; /* Applies to dst blt key in src surface. */
12892 color[2] = 0x00ff0000; /* Dst color key in dst surface. */
12893 color[3] = 0x0000ff00; /* Src color key in dst surface. */
12894 color[4] = 0x00001100; /* Src color key in ddbltfx. */
12895 color[5] = 0x00110000; /* Dst color key in ddbltfx. */
12896 hr = IDirectDrawSurface7_Unlock(src, NULL);
12897 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
12899 hr = IDirectDrawSurface7_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
12900 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
12901 color = surface_desc.lpSurface;
12902 color[0] = color[1] = color[2] = color[3] = color[4] = color[5] = 0x55555555;
12903 hr = IDirectDrawSurface7_Unlock(dst, NULL);
12904 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
12906 /* Test a blit without keying. */
12907 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, 0, &fx);
12908 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
12910 hr = IDirectDrawSurface7_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
12911 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
12912 color = surface_desc.lpSurface;
12913 /* Should have copied src data unmodified to dst. */
12914 ok(color[0] == 0x000000ff && color[1] == 0x000000aa && color[2] == 0x00ff0000 &&
12915 color[3] == 0x0000ff00 && color[4] == 0x00001100 && color[5] == 0x00110000,
12916 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
12917 color[0], color[1], color[2], color[3], color[4], color[5]);
12919 color[0] = color[1] = color[2] = color[3] = color[4] = color[5] = 0x55555555;
12920 hr = IDirectDrawSurface7_Unlock(dst, NULL);
12921 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
12923 /* Src key. */
12924 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_KEYSRC, &fx);
12925 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
12927 hr = IDirectDrawSurface7_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
12928 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
12929 color = surface_desc.lpSurface;
12930 /* Src key applied to color[0]. It is unmodified, the others are copied. */
12931 ok(color[0] == 0x55555555 && color[1] == 0x000000aa && color[2] == 0x00ff0000 &&
12932 color[3] == 0x0000ff00 && color[4] == 0x00001100 && color[5] == 0x00110000,
12933 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
12934 color[0], color[1], color[2], color[3], color[4], color[5]);
12936 color[0] = color[1] = color[2] = color[3] = color[4] = color[5] = 0x55555555;
12937 hr = IDirectDrawSurface7_Unlock(dst, NULL);
12938 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
12940 /* Src override. */
12941 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_KEYSRCOVERRIDE, &fx);
12942 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
12944 hr = IDirectDrawSurface7_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
12945 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
12946 color = surface_desc.lpSurface;
12947 /* Override key applied to color[5]. It is unmodified, the others are copied. */
12948 ok(color[0] == 0x000000ff && color[1] == 0x000000aa && color[2] == 0x00ff0000 &&
12949 color[3] == 0x0000ff00 && color[4] == 0x00001100 && color[5] == 0x55555555,
12950 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
12951 color[0], color[1], color[2], color[3], color[4], color[5]);
12953 color[0] = color[1] = color[2] = color[3] = color[4] = color[5] = 0x55555555;
12954 hr = IDirectDrawSurface7_Unlock(dst, NULL);
12955 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
12957 /* Src override AND src key. That is not supposed to work. */
12958 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_KEYSRC | DDBLT_KEYSRCOVERRIDE, &fx);
12959 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
12961 hr = IDirectDrawSurface7_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
12962 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
12963 color = surface_desc.lpSurface;
12964 /* Ensure the destination was not changed. */
12965 ok(color[0] == 0x55555555 && color[1] == 0x55555555 && color[2] == 0x55555555 &&
12966 color[3] == 0x55555555 && color[4] == 0x55555555 && color[5] == 0x55555555,
12967 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
12968 color[0], color[1], color[2], color[3], color[4], color[5]);
12970 /* Use different dst colors for the dst key test. */
12971 color[0] = 0x00ff0000; /* Dest key in dst surface. */
12972 color[1] = 0x00ff0000; /* Dest key in dst surface. */
12973 color[2] = 0x00001100; /* Dest key in override. */
12974 color[3] = 0x00001100; /* Dest key in override. */
12975 color[4] = 0x000000aa; /* Dest key in src surface. */
12976 color[5] = 0x000000aa; /* Dest key in src surface. */
12977 hr = IDirectDrawSurface7_Unlock(dst, NULL);
12978 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
12980 /* Dest key blit. The key is taken from the DESTINATION surface in v7! */
12981 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_KEYDEST, &fx);
12982 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
12984 hr = IDirectDrawSurface7_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
12985 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
12986 color = surface_desc.lpSurface;
12987 /* Dst key applied to color[0,1], they are the only changed pixels. */
12988 todo_wine ok(color[0] == 0x000000ff && color[1] == 0x000000aa && color[2] == 0x00001100 &&
12989 color[3] == 0x00001100 && color[4] == 0x000000aa && color[5] == 0x000000aa,
12990 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
12991 color[0], color[1], color[2], color[3], color[4], color[5]);
12993 color[0] = 0x00ff0000; /* Dest key in dst surface. */
12994 color[1] = 0x00ff0000; /* Dest key in dst surface. */
12995 color[2] = 0x00001100; /* Dest key in override. */
12996 color[3] = 0x00001100; /* Dest key in override. */
12997 color[4] = 0x000000aa; /* Dest key in src surface. */
12998 color[5] = 0x000000aa; /* Dest key in src surface. */
12999 hr = IDirectDrawSurface7_Unlock(dst, NULL);
13000 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
13002 /* What happens with a QI'd older version of the interface? It takes the key
13003 * from the source surface. */
13004 hr = IDirectDrawSurface7_QueryInterface(src, &IID_IDirectDrawSurface, (void **)&src1);
13005 ok(SUCCEEDED(hr), "Failed to query IDirectDrawSurface interface, hr %#x.\n", hr);
13006 hr = IDirectDrawSurface7_QueryInterface(dst, &IID_IDirectDrawSurface, (void **)&dst1);
13007 ok(SUCCEEDED(hr), "Failed to query IDirectDrawSurface interface, hr %#x.\n", hr);
13009 hr = IDirectDrawSurface_Blt(dst1, NULL, src1, NULL, DDBLT_KEYDEST, &fx);
13010 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
13012 IDirectDrawSurface_Release(dst1);
13013 IDirectDrawSurface_Release(src1);
13015 hr = IDirectDrawSurface7_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
13016 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
13017 color = surface_desc.lpSurface;
13018 /* Dst key applied to color[4,5], they are the only changed pixels. */
13019 ok(color[0] == 0x00ff0000 && color[1] == 0x00ff0000 && color[2] == 0x00001100 &&
13020 color[3] == 0x00001100 && color[4] == 0x00001100 && color[5] == 0x00110000,
13021 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
13022 color[0], color[1], color[2], color[3], color[4], color[5]);
13024 color[0] = 0x00ff0000; /* Dest key in dst surface. */
13025 color[1] = 0x00ff0000; /* Dest key in dst surface. */
13026 color[2] = 0x00001100; /* Dest key in override. */
13027 color[3] = 0x00001100; /* Dest key in override. */
13028 color[4] = 0x000000aa; /* Dest key in src surface. */
13029 color[5] = 0x000000aa; /* Dest key in src surface. */
13030 hr = IDirectDrawSurface7_Unlock(dst, NULL);
13031 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
13033 /* Dest override key blit. */
13034 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_KEYDESTOVERRIDE, &fx);
13035 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
13037 hr = IDirectDrawSurface7_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
13038 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
13039 color = surface_desc.lpSurface;
13040 /* Dst key applied to color[2,3], they are the only changed pixels. */
13041 ok(color[0] == 0x00ff0000 && color[1] == 0x00ff0000 && color[2] == 0x00ff0000 &&
13042 color[3] == 0x0000ff00 && color[4] == 0x000000aa && color[5] == 0x000000aa,
13043 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
13044 color[0], color[1], color[2], color[3], color[4], color[5]);
13046 color[0] = 0x00ff0000; /* Dest key in dst surface. */
13047 color[1] = 0x00ff0000; /* Dest key in dst surface. */
13048 color[2] = 0x00001100; /* Dest key in override. */
13049 color[3] = 0x00001100; /* Dest key in override. */
13050 color[4] = 0x000000aa; /* Dest key in src surface. */
13051 color[5] = 0x000000aa; /* Dest key in src surface. */
13052 hr = IDirectDrawSurface7_Unlock(dst, NULL);
13053 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
13055 /* Dest override together with surface key. Supposed to fail. */
13056 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_KEYDEST | DDBLT_KEYDESTOVERRIDE, &fx);
13057 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
13059 hr = IDirectDrawSurface7_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
13060 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
13061 color = surface_desc.lpSurface;
13062 /* Destination is unchanged. */
13063 ok(color[0] == 0x00ff0000 && color[1] == 0x00ff0000 && color[2] == 0x00001100 &&
13064 color[3] == 0x00001100 && color[4] == 0x000000aa && color[5] == 0x000000aa,
13065 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
13066 color[0], color[1], color[2], color[3], color[4], color[5]);
13067 hr = IDirectDrawSurface7_Unlock(dst, NULL);
13068 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
13070 /* Source and destination key. This is driver dependent. New HW treats it like
13071 * DDBLT_KEYSRC. Older HW and some software renderers apply both keys. */
13072 if (0)
13074 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_KEYDEST | DDBLT_KEYSRC, &fx);
13075 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
13077 hr = IDirectDrawSurface7_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
13078 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
13079 color = surface_desc.lpSurface;
13080 /* Color[0] is filtered by the src key, 2-5 are filtered by the dst key, if
13081 * the driver applies it. */
13082 ok(color[0] == 0x00ff0000 && color[1] == 0x000000aa && color[2] == 0x00ff0000 &&
13083 color[3] == 0x0000ff00 && color[4] == 0x00001100 && color[5] == 0x00110000,
13084 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
13085 color[0], color[1], color[2], color[3], color[4], color[5]);
13087 color[0] = 0x00ff0000; /* Dest key in dst surface. */
13088 color[1] = 0x00ff0000; /* Dest key in dst surface. */
13089 color[2] = 0x00001100; /* Dest key in override. */
13090 color[3] = 0x00001100; /* Dest key in override. */
13091 color[4] = 0x000000aa; /* Dest key in src surface. */
13092 color[5] = 0x000000aa; /* Dest key in src surface. */
13093 hr = IDirectDrawSurface7_Unlock(dst, NULL);
13094 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
13097 /* Override keys without ddbltfx parameter fail */
13098 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_KEYDESTOVERRIDE, NULL);
13099 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
13100 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_KEYSRCOVERRIDE, NULL);
13101 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
13103 /* Try blitting without keys in the source surface. */
13104 hr = IDirectDrawSurface7_SetColorKey(src, DDCKEY_SRCBLT, NULL);
13105 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
13106 hr = IDirectDrawSurface7_SetColorKey(src, DDCKEY_DESTBLT, NULL);
13107 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
13109 /* That fails now. Do not bother to check that the data is unmodified. */
13110 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_KEYSRC, &fx);
13111 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
13113 /* Dest key blit still works, the destination surface key is used in v7. */
13114 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_KEYDEST, &fx);
13115 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
13117 hr = IDirectDrawSurface7_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
13118 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
13119 color = surface_desc.lpSurface;
13120 /* Dst key applied to color[0,1], they are the only changed pixels. */
13121 todo_wine ok(color[0] == 0x000000ff && color[1] == 0x000000aa && color[2] == 0x00001100 &&
13122 color[3] == 0x00001100 && color[4] == 0x000000aa && color[5] == 0x000000aa,
13123 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
13124 color[0], color[1], color[2], color[3], color[4], color[5]);
13125 hr = IDirectDrawSurface7_Unlock(dst, NULL);
13126 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
13128 /* Try blitting without keys in the destination surface. */
13129 hr = IDirectDrawSurface7_SetColorKey(dst, DDCKEY_SRCBLT, NULL);
13130 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
13131 hr = IDirectDrawSurface7_SetColorKey(dst, DDCKEY_DESTBLT, NULL);
13132 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
13134 /* This fails, as sanity would dictate. */
13135 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_KEYDEST, &fx);
13136 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
13138 done:
13139 IDirectDrawSurface7_Release(src);
13140 IDirectDrawSurface7_Release(dst);
13141 refcount = IDirectDraw7_Release(ddraw);
13142 ok(!refcount, "DirectDraw has %u references left.\n", refcount);
13143 DestroyWindow(window);
13146 static void test_vb_refcount(void)
13148 ULONG prev_d3d_refcount, prev_device_refcount;
13149 ULONG cur_d3d_refcount, cur_device_refcount;
13150 IDirect3DVertexBuffer7 *vb, *vb7;
13151 D3DVERTEXBUFFERDESC vb_desc;
13152 IDirect3DVertexBuffer *vb1;
13153 IDirect3DDevice7 *device;
13154 IDirect3D7 *d3d;
13155 ULONG refcount;
13156 IUnknown *unk;
13157 HWND window;
13158 HRESULT hr;
13160 window = create_window();
13161 if (!(device = create_device(window, DDSCL_NORMAL)))
13163 skip("Failed to create a 3D device, skipping test.\n");
13164 DestroyWindow(window);
13165 return;
13168 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
13169 ok(SUCCEEDED(hr), "Failed to get Direct3D7 interface, hr %#x.\n", hr);
13171 prev_d3d_refcount = get_refcount((IUnknown *)d3d);
13172 prev_device_refcount = get_refcount((IUnknown *)device);
13174 memset(&vb_desc, 0, sizeof(vb_desc));
13175 vb_desc.dwSize = sizeof(vb_desc);
13176 vb_desc.dwFVF = D3DFVF_XYZ;
13177 vb_desc.dwNumVertices = 4;
13178 hr = IDirect3D7_CreateVertexBuffer(d3d, &vb_desc, &vb, 0);
13179 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
13181 cur_d3d_refcount = get_refcount((IUnknown *)d3d);
13182 cur_device_refcount = get_refcount((IUnknown *)device);
13183 ok(cur_d3d_refcount > prev_d3d_refcount, "D3D object refcount didn't change from %u.\n", prev_d3d_refcount);
13184 ok(cur_device_refcount == prev_device_refcount, "Device refcount changed from %u to %u.\n",
13185 prev_device_refcount, cur_device_refcount);
13187 prev_d3d_refcount = cur_d3d_refcount;
13188 hr = IDirect3DVertexBuffer7_QueryInterface(vb, &IID_IDirect3DVertexBuffer7, (void **)&vb7);
13189 ok(hr == DD_OK, "Failed to query IDirect3DVertexBuffer7, hr %#x.\n", hr);
13190 cur_d3d_refcount = get_refcount((IUnknown *)d3d);
13191 ok(cur_d3d_refcount == prev_d3d_refcount, "D3D object refcount changed from %u to %u.\n",
13192 prev_d3d_refcount, cur_d3d_refcount);
13193 IDirect3DVertexBuffer7_Release(vb7);
13195 hr = IDirect3DVertexBuffer7_QueryInterface(vb, &IID_IDirect3DVertexBuffer, (void **)&vb1);
13196 ok(hr == E_NOINTERFACE, "Querying IDirect3DVertexBuffer returned unexpected hr %#x.\n", hr);
13198 hr = IDirect3DVertexBuffer_QueryInterface(vb, &IID_IUnknown, (void **)&unk);
13199 ok(hr == DD_OK, "Failed to query IUnknown, hr %#x.\n", hr);
13200 ok((IUnknown *)vb == unk,
13201 "IDirect3DVertexBuffer7 and IUnknown interface pointers don't match, %p != %p.\n", vb, unk);
13202 IUnknown_Release(unk);
13204 refcount = IDirect3DVertexBuffer7_Release(vb);
13205 ok(!refcount, "Vertex buffer has %u references left.\n", refcount);
13207 IDirect3D7_Release(d3d);
13208 refcount = IDirect3DDevice7_Release(device);
13209 ok(!refcount, "Device has %u references left.\n", refcount);
13210 DestroyWindow(window);
13213 static void test_compute_sphere_visibility(void)
13215 static D3DVALUE clip_plane[4] = {1.0f, 0.0f, 0.0f, 0.5f};
13216 static D3DMATRIX proj_1 =
13218 1.810660f, 0.000000f, 0.000000f, 0.000000f,
13219 0.000000f, 2.414213f, 0.000000f, 0.000000f,
13220 0.000000f, 0.000000f, 1.020408f, 1.000000f,
13221 0.000000f, 0.000000f, -0.102041f, 0.000000f,
13223 static D3DMATRIX proj_2 =
13225 10.0f, 0.0f, 0.0f, 0.0f,
13226 0.0f, 10.0f, 0.0f, 0.0f,
13227 0.0f, 0.0f, 10.0f, 0.0f,
13228 0.0f, 0.0f, 0.0f, 1.0f,
13230 static D3DMATRIX view_1 =
13232 1.000000f, 0.000000f, 0.000000f, 0.000000f,
13233 0.000000f, 0.768221f, -0.640185f, 0.000000f,
13234 -0.000000f, 0.640185f, 0.768221f, 0.000000f,
13235 -14.852037f, 9.857489f, 11.600972f, 1.000000f,
13237 static D3DMATRIX identity =
13239 1.0f, 0.0f, 0.0f, 0.0f,
13240 0.0f, 1.0f, 0.0f, 0.0f,
13241 0.0f, 0.0f, 1.0f, 0.0f,
13242 0.0f, 0.0f, 0.0f, 1.0f,
13244 static struct
13246 D3DMATRIX *view, *proj;
13247 unsigned int sphere_count;
13248 D3DVECTOR center[3];
13249 D3DVALUE radius[3];
13250 DWORD enable_planes;
13251 const DWORD expected[3];
13253 tests[] =
13255 {&view_1, &proj_1, 1, {{{11.461533f}, {-4.761727f}, {-1.171646f}}}, {38.252632f}, 0, {0x3f}},
13256 {&view_1, &proj_1, 3, {{{-3.515620f}, {-1.560661f}, {-12.464638f}},
13257 {{14.290396f}, {-2.981143f}, {-24.311312f}},
13258 {{1.461626f}, {-6.093709f}, {-13.901010f}}},
13259 {4.354097f, 12.500704f, 17.251318f}, 0, {0x103d, 0x3f, 0x3f}},
13260 {&identity, &proj_2, 1, {{{0.0f}, {0.0f}, {0.05f}}}, {0.04f}, 0, {0}},
13261 {&identity, &identity, 1, {{{0.0f}, {0.0f}, {0.5f}}}, {0.5f}, 0, {0}},
13262 {&identity, &identity, 1, {{{0.0f}, {0.0f}, {0.0f}}}, {0.0f}, 0, {0}},
13263 {&identity, &identity, 1, {{{-1.0f}, {-1.0f}, {0.5f}}}, {0.25f}, 0, {0x9}}, /* 5 */
13264 {&identity, &identity, 1, {{{-20.0f}, {0.0f}, {0.5f}}}, {3.0f}, 0, {0x103d}},
13265 {&identity, &identity, 1, {{{20.0f}, {0.0f}, {0.5f}}}, {3.0f}, 0, {0x203e}},
13266 {&identity, &identity, 1, {{{0.0f}, {-20.0f}, {0.5f}}}, {3.0f}, 0, {0x803b}},
13267 {&identity, &identity, 1, {{{0.0f}, {20.0f}, {0.5f}}}, {3.0f}, 0, {0x4037}},
13268 {&identity, &identity, 1, {{{0.0f}, {0.0f}, {-20.0f}}}, {3.0f}, 0, {0x1001f}}, /* 10 */
13269 {&identity, &identity, 1, {{{0.0f}, {0.0f}, {20.0f}}}, {3.0f}, 0, {0x2002f}},
13270 {&identity, &identity, 1, {{{0.0f}, {0.0f}, {0.0f}}}, {5.0f}, 1, {0x7f}},
13271 {&identity, &identity, 1, {{{-0.5f}, {0.0f}, {0.0f}}}, {5.0f}, 1, {0x7f}},
13272 {&identity, &identity, 1, {{{-0.5f}, {0.0f}, {0.0f}}}, {1.0f}, 1, {0x51}},
13273 {&identity, &identity, 1, {{{-2.5f}, {0.0f}, {0.0f}}}, {1.0f}, 1, {0x41051}}, /* 15 */
13275 IDirect3DDevice7 *device;
13276 unsigned int i, j;
13277 DWORD result[3];
13278 ULONG refcount;
13279 HWND window;
13280 HRESULT hr;
13282 window = create_window();
13283 if (!(device = create_device(window, DDSCL_NORMAL)))
13285 skip("Failed to create a 3D device, skipping test.\n");
13286 DestroyWindow(window);
13287 return;
13290 hr = IDirect3DDevice7_SetClipPlane(device, 0, clip_plane);
13291 ok(SUCCEEDED(hr), "Failed to set user clip plane, hr %#x.\n", hr);
13293 IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &identity);
13295 for (i = 0; i < sizeof(tests) / sizeof(tests[0]); ++i)
13297 IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_VIEW, tests[i].view);
13298 IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, tests[i].proj);
13300 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CLIPPLANEENABLE,
13301 tests[i].enable_planes);
13302 ok(SUCCEEDED(hr), "Failed to enable / disable user clip planes, hr %#x.\n", hr);
13304 hr = IDirect3DDevice7_ComputeSphereVisibility(device, tests[i].center, tests[i].radius,
13305 tests[i].sphere_count, 0, result);
13306 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
13308 for (j = 0; j < tests[i].sphere_count; ++j)
13309 ok(result[j] == tests[i].expected[j], "Test %u sphere %u: expected %#x, got %#x.\n",
13310 i, j, tests[i].expected[j], result[j]);
13313 refcount = IDirect3DDevice7_Release(device);
13314 ok(!refcount, "Device has %u references left.\n", refcount);
13315 DestroyWindow(window);
13318 static void test_clip_planes_limits(void)
13320 IDirect3DDevice7 *device;
13321 D3DDEVICEDESC7 caps;
13322 unsigned int i;
13323 ULONG refcount;
13324 float plane[4];
13325 HWND window;
13326 DWORD state;
13327 HRESULT hr;
13329 window = create_window();
13330 if (!(device = create_device(window, DDSCL_NORMAL)))
13332 skip("Failed to create 3D device.\n");
13333 DestroyWindow(window);
13334 return;
13337 memset(&caps, 0, sizeof(caps));
13338 hr = IDirect3DDevice7_GetCaps(device, &caps);
13339 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
13341 trace("Max user clip planes: %u.\n", caps.wMaxUserClipPlanes);
13343 for (i = 0; i < D3DMAXUSERCLIPPLANES; ++i)
13345 memset(plane, 0xff, sizeof(plane));
13346 hr = IDirect3DDevice7_GetClipPlane(device, i, plane);
13347 ok(hr == D3D_OK, "Failed to get clip plane %u, hr %#x.\n", i, hr);
13348 ok(!plane[0] && !plane[1] && !plane[2] && !plane[3],
13349 "Got unexpected plane %u: %.8e, %.8e, %.8e, %.8e.\n",
13350 i, plane[0], plane[1], plane[2], plane[3]);
13353 plane[0] = 2.0f;
13354 plane[1] = 8.0f;
13355 plane[2] = 5.0f;
13356 for (i = 0; i < D3DMAXUSERCLIPPLANES; ++i)
13358 plane[3] = i;
13359 hr = IDirect3DDevice7_SetClipPlane(device, i, plane);
13360 ok(hr == D3D_OK, "Failed to set clip plane %u, hr %#x.\n", i, hr);
13362 for (i = 0; i < D3DMAXUSERCLIPPLANES; ++i)
13364 memset(plane, 0xff, sizeof(plane));
13365 hr = IDirect3DDevice7_GetClipPlane(device, i, plane);
13366 ok(hr == D3D_OK, "Failed to get clip plane %u, hr %#x.\n", i, hr);
13367 ok(plane[0] == 2.0f && plane[1] == 8.0f && plane[2] == 5.0f && plane[3] == i,
13368 "Got unexpected plane %u: %.8e, %.8e, %.8e, %.8e.\n",
13369 i, plane[0], plane[1], plane[2], plane[3]);
13372 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CLIPPLANEENABLE, 0xffffffff);
13373 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
13374 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_CLIPPLANEENABLE, &state);
13375 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
13376 ok(state == 0xffffffff, "Got unexpected state %#x.\n", state);
13377 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CLIPPLANEENABLE, 0x80000000);
13378 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
13379 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_CLIPPLANEENABLE, &state);
13380 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
13381 ok(state == 0x80000000, "Got unexpected state %#x.\n", state);
13383 refcount = IDirect3DDevice7_Release(device);
13384 ok(!refcount, "Device has %u references left.\n", refcount);
13385 DestroyWindow(window);
13388 START_TEST(ddraw7)
13390 HMODULE module = GetModuleHandleA("ddraw.dll");
13391 HMODULE dwmapi;
13392 IDirectDraw7 *ddraw;
13393 DEVMODEW current_mode;
13395 if (!(pDirectDrawCreateEx = (void *)GetProcAddress(module, "DirectDrawCreateEx")))
13397 win_skip("DirectDrawCreateEx not available, skipping tests.\n");
13398 return;
13401 if (!(ddraw = create_ddraw()))
13403 skip("Failed to create a ddraw object, skipping tests.\n");
13404 return;
13406 IDirectDraw7_Release(ddraw);
13408 memset(&current_mode, 0, sizeof(current_mode));
13409 current_mode.dmSize = sizeof(current_mode);
13410 ok(EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &current_mode), "Failed to get display mode.\n");
13411 registry_mode.dmSize = sizeof(registry_mode);
13412 ok(EnumDisplaySettingsW(NULL, ENUM_REGISTRY_SETTINGS, &registry_mode), "Failed to get display mode.\n");
13413 if (registry_mode.dmPelsWidth != current_mode.dmPelsWidth
13414 || registry_mode.dmPelsHeight != current_mode.dmPelsHeight)
13416 skip("Current mode does not match registry mode, skipping test.\n");
13417 return;
13420 if ((dwmapi = LoadLibraryA("dwmapi.dll")))
13421 pDwmIsCompositionEnabled = (void *)GetProcAddress(dwmapi, "DwmIsCompositionEnabled");
13423 test_process_vertices();
13424 test_coop_level_create_device_window();
13425 test_clipper_blt();
13426 test_coop_level_d3d_state();
13427 test_surface_interface_mismatch();
13428 test_coop_level_threaded();
13429 test_depth_blit();
13430 test_texture_load_ckey();
13431 test_zenable();
13432 test_ck_rgba();
13433 test_ck_default();
13434 test_ck_complex();
13435 test_surface_qi();
13436 test_device_qi();
13437 test_wndproc();
13438 test_window_style();
13439 test_redundant_mode_set();
13440 test_coop_level_mode_set();
13441 test_coop_level_mode_set_multi();
13442 test_initialize();
13443 test_coop_level_surf_create();
13444 test_vb_discard();
13445 test_coop_level_multi_window();
13446 test_draw_strided();
13447 test_lighting();
13448 test_specular_lighting();
13449 test_clear_rect_count();
13450 test_coop_level_versions();
13451 test_fog_special();
13452 test_lighting_interface_versions();
13453 test_coop_level_activateapp();
13454 test_texturemanage();
13455 test_block_formats_creation();
13456 test_unsupported_formats();
13457 test_rt_caps();
13458 test_primary_caps();
13459 test_surface_lock();
13460 test_surface_discard();
13461 test_flip();
13462 test_set_surface_desc();
13463 test_user_memory_getdc();
13464 test_sysmem_overlay();
13465 test_primary_palette();
13466 test_surface_attachment();
13467 test_private_data();
13468 test_pixel_format();
13469 test_create_surface_pitch();
13470 test_mipmap();
13471 test_palette_complex();
13472 test_p8_blit();
13473 test_material();
13474 test_palette_gdi();
13475 test_palette_alpha();
13476 test_vb_writeonly();
13477 test_lost_device();
13478 test_resource_priority();
13479 test_surface_desc_lock();
13480 test_fog_interpolation();
13481 test_negative_fixedfunction_fog();
13482 test_table_fog_zw();
13483 test_signed_formats();
13484 test_color_fill();
13485 test_texcoordindex();
13486 test_colorkey_precision();
13487 test_range_colorkey();
13488 test_shademode();
13489 test_lockrect_invalid();
13490 test_yv12_overlay();
13491 test_offscreen_overlay();
13492 test_overlay_rect();
13493 test_blt();
13494 test_blt_z_alpha();
13495 test_color_clamping();
13496 test_getdc();
13497 test_draw_primitive();
13498 test_edge_antialiasing_blending();
13499 test_display_mode_surface_pixel_format();
13500 test_surface_desc_size();
13501 test_get_surface_from_dc();
13502 test_ck_operation();
13503 test_vb_refcount();
13504 test_compute_sphere_visibility();
13505 test_clip_planes_limits();