dmusic: Sync up the dmobject.[ch] files.
[wine.git] / dlls / ddraw / tests / ddraw7.c
blob35a45c0345666f021ed0c52146a364ab19f8648d
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_get_identifier(IDirectDraw7 *ddraw, DDDEVICEIDENTIFIER2 *identifier)
109 HRESULT hr;
111 hr = IDirectDraw7_GetDeviceIdentifier(ddraw, identifier, 0);
112 ok(SUCCEEDED(hr), "Failed to get device identifier, hr %#x.\n", hr);
114 return SUCCEEDED(hr);
117 static BOOL ddraw_is_warp(IDirectDraw7 *ddraw)
119 DDDEVICEIDENTIFIER2 identifier;
121 return strcmp(winetest_platform, "wine")
122 && ddraw_get_identifier(ddraw, &identifier)
123 && strstr(identifier.szDriver, "warp");
126 static BOOL ddraw_is_vendor(IDirectDraw7 *ddraw, DWORD vendor)
128 DDDEVICEIDENTIFIER2 identifier;
130 return strcmp(winetest_platform, "wine")
131 && ddraw_get_identifier(ddraw, &identifier)
132 && identifier.dwVendorId == vendor;
135 static BOOL ddraw_is_intel(IDirectDraw7 *ddraw)
137 return ddraw_is_vendor(ddraw, 0x8086);
140 static BOOL ddraw_is_nvidia(IDirectDraw7 *ddraw)
142 return ddraw_is_vendor(ddraw, 0x10de);
145 static BOOL ddraw_is_vmware(IDirectDraw7 *ddraw)
147 return ddraw_is_vendor(ddraw, 0x15ad);
150 static IDirectDrawSurface7 *create_overlay(IDirectDraw7 *ddraw,
151 unsigned int width, unsigned int height, DWORD format)
153 IDirectDrawSurface7 *surface;
154 DDSURFACEDESC2 desc;
156 memset(&desc, 0, sizeof(desc));
157 desc.dwSize = sizeof(desc);
158 desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
159 desc.dwWidth = width;
160 desc.dwHeight = height;
161 desc.ddsCaps.dwCaps = DDSCAPS_OVERLAY;
162 U4(desc).ddpfPixelFormat.dwSize = sizeof(U4(desc).ddpfPixelFormat);
163 U4(desc).ddpfPixelFormat.dwFlags = DDPF_FOURCC;
164 U4(desc).ddpfPixelFormat.dwFourCC = format;
166 if (FAILED(IDirectDraw7_CreateSurface(ddraw, &desc, &surface, NULL)))
167 return NULL;
168 return surface;
171 static HWND create_window(void)
173 RECT r = {0, 0, 640, 480};
175 AdjustWindowRect(&r, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
177 return CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
178 CW_USEDEFAULT, CW_USEDEFAULT, r.right - r.left, r.bottom - r.top, NULL, NULL, NULL, NULL);
181 static DWORD WINAPI create_window_thread_proc(void *param)
183 struct create_window_thread_param *p = param;
184 DWORD res;
185 BOOL ret;
187 p->window = create_window();
188 ret = SetEvent(p->window_created);
189 ok(ret, "SetEvent failed, last error %#x.\n", GetLastError());
191 for (;;)
193 MSG msg;
195 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
196 DispatchMessageA(&msg);
197 res = WaitForSingleObject(p->destroy_window, 100);
198 if (res == WAIT_OBJECT_0)
199 break;
200 if (res != WAIT_TIMEOUT)
202 ok(0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
203 break;
207 DestroyWindow(p->window);
209 return 0;
212 static void create_window_thread(struct create_window_thread_param *p)
214 DWORD res, tid;
216 p->window_created = CreateEventA(NULL, FALSE, FALSE, NULL);
217 ok(!!p->window_created, "CreateEvent failed, last error %#x.\n", GetLastError());
218 p->destroy_window = CreateEventA(NULL, FALSE, FALSE, NULL);
219 ok(!!p->destroy_window, "CreateEvent failed, last error %#x.\n", GetLastError());
220 p->thread = CreateThread(NULL, 0, create_window_thread_proc, p, 0, &tid);
221 ok(!!p->thread, "Failed to create thread, last error %#x.\n", GetLastError());
222 res = WaitForSingleObject(p->window_created, INFINITE);
223 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
226 static void destroy_window_thread(struct create_window_thread_param *p)
228 SetEvent(p->destroy_window);
229 WaitForSingleObject(p->thread, INFINITE);
230 CloseHandle(p->destroy_window);
231 CloseHandle(p->window_created);
232 CloseHandle(p->thread);
235 static IDirectDrawSurface7 *get_depth_stencil(IDirect3DDevice7 *device)
237 IDirectDrawSurface7 *rt, *ret;
238 DDSCAPS2 caps = {DDSCAPS_ZBUFFER, 0, 0, {0}};
239 HRESULT hr;
241 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
242 ok(SUCCEEDED(hr), "Failed to get the render target, hr %#x.\n", hr);
243 hr = IDirectDrawSurface7_GetAttachedSurface(rt, &caps, &ret);
244 ok(SUCCEEDED(hr) || hr == DDERR_NOTFOUND, "Failed to get the z buffer, hr %#x.\n", hr);
245 IDirectDrawSurface7_Release(rt);
246 return ret;
249 static HRESULT set_display_mode(IDirectDraw7 *ddraw, DWORD width, DWORD height)
251 if (SUCCEEDED(IDirectDraw7_SetDisplayMode(ddraw, width, height, 32, 0, 0)))
252 return DD_OK;
253 return IDirectDraw7_SetDisplayMode(ddraw, width, height, 24, 0, 0);
256 static D3DCOLOR get_surface_color(IDirectDrawSurface7 *surface, UINT x, UINT y)
258 RECT rect = {x, y, x + 1, y + 1};
259 DDSURFACEDESC2 surface_desc;
260 D3DCOLOR color;
261 HRESULT hr;
263 memset(&surface_desc, 0, sizeof(surface_desc));
264 surface_desc.dwSize = sizeof(surface_desc);
266 hr = IDirectDrawSurface7_Lock(surface, &rect, &surface_desc, DDLOCK_READONLY, NULL);
267 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
268 if (FAILED(hr))
269 return 0xdeadbeef;
271 color = *((DWORD *)surface_desc.lpSurface) & 0x00ffffff;
273 hr = IDirectDrawSurface7_Unlock(surface, &rect);
274 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
276 return color;
279 static void check_rect(IDirectDrawSurface7 *surface, RECT r, const char *message)
281 LONG x_coords[2][2] =
283 {r.left - 1, r.left + 1},
284 {r.right + 1, r.right - 1},
286 LONG y_coords[2][2] =
288 {r.top - 1, r.top + 1},
289 {r.bottom + 1, r.bottom - 1}
291 unsigned int i, j, x_side, y_side;
292 DWORD color;
293 LONG x, y;
295 for (i = 0; i < 2; ++i)
297 for (j = 0; j < 2; ++j)
299 for (x_side = 0; x_side < 2; ++x_side)
301 for (y_side = 0; y_side < 2; ++y_side)
303 DWORD expected = (x_side == 1 && y_side == 1) ? 0x00ffffff : 0x00000000;
305 x = x_coords[i][x_side];
306 y = y_coords[j][y_side];
307 if (x < 0 || x >= 640 || y < 0 || y >= 480)
308 continue;
309 color = get_surface_color(surface, x, y);
310 ok(color == expected, "%s: Pixel (%d, %d) has color %08x, expected %08x.\n",
311 message, x, y, color, expected);
318 static HRESULT CALLBACK enum_z_fmt(DDPIXELFORMAT *format, void *ctx)
320 DDPIXELFORMAT *z_fmt = ctx;
322 if (U1(*format).dwZBufferBitDepth > U1(*z_fmt).dwZBufferBitDepth)
323 *z_fmt = *format;
325 return DDENUMRET_OK;
328 static IDirectDraw7 *create_ddraw(void)
330 IDirectDraw7 *ddraw;
332 if (FAILED(pDirectDrawCreateEx(NULL, (void **)&ddraw, &IID_IDirectDraw7, NULL)))
333 return NULL;
335 return ddraw;
338 static HRESULT WINAPI enum_devtype_cb(char *desc_str, char *name, D3DDEVICEDESC7 *desc, void *ctx)
340 BOOL *hal_ok = ctx;
341 if (IsEqualGUID(&desc->deviceGUID, &IID_IDirect3DTnLHalDevice))
343 *hal_ok = TRUE;
344 return DDENUMRET_CANCEL;
346 return DDENUMRET_OK;
349 static IDirect3DDevice7 *create_device(HWND window, DWORD coop_level)
351 IDirectDrawSurface7 *surface, *ds;
352 IDirect3DDevice7 *device = NULL;
353 DDSURFACEDESC2 surface_desc;
354 DDPIXELFORMAT z_fmt;
355 IDirectDraw7 *ddraw;
356 IDirect3D7 *d3d7;
357 HRESULT hr;
358 BOOL hal_ok = FALSE;
359 const GUID *devtype = &IID_IDirect3DHALDevice;
361 if (!(ddraw = create_ddraw()))
362 return NULL;
364 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, coop_level);
365 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
367 memset(&surface_desc, 0, sizeof(surface_desc));
368 surface_desc.dwSize = sizeof(surface_desc);
369 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
370 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
371 surface_desc.dwWidth = 640;
372 surface_desc.dwHeight = 480;
374 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
375 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
377 if (coop_level & DDSCL_NORMAL)
379 IDirectDrawClipper *clipper;
381 hr = IDirectDraw7_CreateClipper(ddraw, 0, &clipper, NULL);
382 ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr);
383 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
384 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
385 hr = IDirectDrawSurface7_SetClipper(surface, clipper);
386 ok(SUCCEEDED(hr), "Failed to set surface clipper, hr %#x.\n", hr);
387 IDirectDrawClipper_Release(clipper);
390 hr = IDirectDraw7_QueryInterface(ddraw, &IID_IDirect3D7, (void **)&d3d7);
391 IDirectDraw7_Release(ddraw);
392 if (FAILED(hr))
394 IDirectDrawSurface7_Release(surface);
395 return NULL;
398 hr = IDirect3D7_EnumDevices(d3d7, enum_devtype_cb, &hal_ok);
399 ok(SUCCEEDED(hr), "Failed to enumerate devices, hr %#x.\n", hr);
400 if (hal_ok) devtype = &IID_IDirect3DTnLHalDevice;
402 memset(&z_fmt, 0, sizeof(z_fmt));
403 hr = IDirect3D7_EnumZBufferFormats(d3d7, devtype, enum_z_fmt, &z_fmt);
404 if (FAILED(hr) || !z_fmt.dwSize)
406 IDirect3D7_Release(d3d7);
407 IDirectDrawSurface7_Release(surface);
408 return NULL;
411 memset(&surface_desc, 0, sizeof(surface_desc));
412 surface_desc.dwSize = sizeof(surface_desc);
413 surface_desc.dwFlags = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT;
414 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
415 U4(surface_desc).ddpfPixelFormat = z_fmt;
416 surface_desc.dwWidth = 640;
417 surface_desc.dwHeight = 480;
418 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &ds, NULL);
419 ok(SUCCEEDED(hr), "Failed to create depth buffer, hr %#x.\n", hr);
420 if (FAILED(hr))
422 IDirect3D7_Release(d3d7);
423 IDirectDrawSurface7_Release(surface);
424 return NULL;
427 hr = IDirectDrawSurface_AddAttachedSurface(surface, ds);
428 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
429 IDirectDrawSurface7_Release(ds);
430 if (FAILED(hr))
432 IDirect3D7_Release(d3d7);
433 IDirectDrawSurface7_Release(surface);
434 return NULL;
437 hr = IDirect3D7_CreateDevice(d3d7, devtype, surface, &device);
438 IDirect3D7_Release(d3d7);
439 IDirectDrawSurface7_Release(surface);
440 if (FAILED(hr))
441 return NULL;
443 return device;
446 struct message
448 UINT message;
449 BOOL check_wparam;
450 WPARAM expect_wparam;
453 static const struct message *expect_messages;
455 static LRESULT CALLBACK test_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
457 if (expect_messages && message == expect_messages->message)
459 if (expect_messages->check_wparam)
460 ok (wparam == expect_messages->expect_wparam,
461 "Got unexpected wparam %lx for message %x, expected %lx.\n",
462 wparam, message, expect_messages->expect_wparam);
464 ++expect_messages;
467 return DefWindowProcA(hwnd, message, wparam, lparam);
470 /* Set the wndproc back to what ddraw expects it to be, and release the ddraw
471 * interface. This prevents subsequent SetCooperativeLevel() calls on a
472 * different window from failing with DDERR_HWNDALREADYSET. */
473 static void fix_wndproc(HWND window, LONG_PTR proc)
475 IDirectDraw7 *ddraw;
476 HRESULT hr;
478 if (!(ddraw = create_ddraw()))
479 return;
481 SetWindowLongPtrA(window, GWLP_WNDPROC, proc);
482 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
483 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
484 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
485 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
487 IDirectDraw7_Release(ddraw);
490 static void test_process_vertices(void)
492 IDirect3DVertexBuffer7 *src_vb, *dst_vb1, *dst_vb2;
493 D3DVERTEXBUFFERDESC vb_desc;
494 IDirect3DDevice7 *device;
495 struct vec4 *dst_data;
496 struct vec3 *dst_data2;
497 struct vec3 *src_data;
498 IDirect3D7 *d3d7;
499 D3DVIEWPORT7 vp;
500 HWND window;
501 HRESULT hr;
503 static D3DMATRIX world =
505 0.0f, 1.0f, 0.0f, 0.0f,
506 1.0f, 0.0f, 0.0f, 0.0f,
507 0.0f, 0.0f, 0.0f, 1.0f,
508 0.0f, 1.0f, 1.0f, 1.0f,
510 static D3DMATRIX view =
512 2.0f, 0.0f, 0.0f, 0.0f,
513 0.0f, -1.0f, 0.0f, 0.0f,
514 0.0f, 0.0f, 1.0f, 0.0f,
515 0.0f, 0.0f, 0.0f, 3.0f,
517 static D3DMATRIX proj =
519 1.0f, 0.0f, 0.0f, 1.0f,
520 0.0f, 1.0f, 1.0f, 0.0f,
521 0.0f, 1.0f, 1.0f, 0.0f,
522 1.0f, 0.0f, 0.0f, 1.0f,
525 window = create_window();
526 if (!(device = create_device(window, DDSCL_NORMAL)))
528 skip("Failed to create a 3D device, skipping test.\n");
529 DestroyWindow(window);
530 return;
533 hr = IDirect3DDevice7_GetDirect3D(device, &d3d7);
534 ok(SUCCEEDED(hr), "Failed to get Direct3D7 interface, hr %#x.\n", hr);
536 memset(&vb_desc, 0, sizeof(vb_desc));
537 vb_desc.dwSize = sizeof(vb_desc);
538 vb_desc.dwFVF = D3DFVF_XYZ;
539 vb_desc.dwNumVertices = 4;
540 hr = IDirect3D7_CreateVertexBuffer(d3d7, &vb_desc, &src_vb, 0);
541 ok(SUCCEEDED(hr), "Failed to create source vertex buffer, hr %#x.\n", hr);
543 hr = IDirect3DVertexBuffer7_Lock(src_vb, 0, (void **)&src_data, NULL);
544 ok(SUCCEEDED(hr), "Failed to lock source vertex buffer, hr %#x.\n", hr);
545 src_data[0].x = 0.0f;
546 src_data[0].y = 0.0f;
547 src_data[0].z = 0.0f;
548 src_data[1].x = 1.0f;
549 src_data[1].y = 1.0f;
550 src_data[1].z = 1.0f;
551 src_data[2].x = -1.0f;
552 src_data[2].y = -1.0f;
553 src_data[2].z = 0.5f;
554 src_data[3].x = 0.5f;
555 src_data[3].y = -0.5f;
556 src_data[3].z = 0.25f;
557 hr = IDirect3DVertexBuffer7_Unlock(src_vb);
558 ok(SUCCEEDED(hr), "Failed to unlock source vertex buffer, hr %#x.\n", hr);
560 memset(&vb_desc, 0, sizeof(vb_desc));
561 vb_desc.dwSize = sizeof(vb_desc);
562 vb_desc.dwFVF = D3DFVF_XYZRHW;
563 vb_desc.dwNumVertices = 4;
564 /* MSDN says that the last parameter must be 0 - check that. */
565 hr = IDirect3D7_CreateVertexBuffer(d3d7, &vb_desc, &dst_vb1, 4);
566 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
568 memset(&vb_desc, 0, sizeof(vb_desc));
569 vb_desc.dwSize = sizeof(vb_desc);
570 vb_desc.dwFVF = D3DFVF_XYZ;
571 vb_desc.dwNumVertices = 5;
572 /* MSDN says that the last parameter must be 0 - check that. */
573 hr = IDirect3D7_CreateVertexBuffer(d3d7, &vb_desc, &dst_vb2, 12345678);
574 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
576 memset(&vp, 0, sizeof(vp));
577 vp.dwX = 64;
578 vp.dwY = 64;
579 vp.dwWidth = 128;
580 vp.dwHeight = 128;
581 vp.dvMinZ = 0.0f;
582 vp.dvMaxZ = 1.0f;
583 hr = IDirect3DDevice7_SetViewport(device, &vp);
584 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#x.\n", hr);
586 hr = IDirect3DVertexBuffer7_ProcessVertices(dst_vb1, D3DVOP_TRANSFORM, 0, 4, src_vb, 0, device, 0);
587 ok(SUCCEEDED(hr), "Failed to process vertices, hr %#x.\n", hr);
588 hr = IDirect3DVertexBuffer7_ProcessVertices(dst_vb2, D3DVOP_TRANSFORM, 0, 4, src_vb, 0, device, 0);
589 ok(SUCCEEDED(hr), "Failed to process vertices, hr %#x.\n", hr);
591 hr = IDirect3DVertexBuffer7_Lock(dst_vb1, 0, (void **)&dst_data, NULL);
592 ok(SUCCEEDED(hr), "Failed to lock destination vertex buffer, hr %#x.\n", hr);
593 ok(compare_vec4(&dst_data[0], +1.280e+2f, +1.280e+2f, +0.000e+0f, +1.000e+0f, 4096),
594 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
595 dst_data[0].x, dst_data[0].y, dst_data[0].z, dst_data[0].w);
596 ok(compare_vec4(&dst_data[1], +1.920e+2f, +6.400e+1f, +1.000e+0f, +1.000e+0f, 4096),
597 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
598 dst_data[1].x, dst_data[1].y, dst_data[1].z, dst_data[1].w);
599 ok(compare_vec4(&dst_data[2], +6.400e+1f, +1.920e+2f, +5.000e-1f, +1.000e+0f, 4096),
600 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
601 dst_data[2].x, dst_data[2].y, dst_data[2].z, dst_data[2].w);
602 ok(compare_vec4(&dst_data[3], +1.600e+2f, +1.600e+2f, +2.500e-1f, +1.000e+0f, 4096),
603 "Got unexpected vertex 3 {%.8e, %.8e, %.8e, %.8e}.\n",
604 dst_data[3].x, dst_data[3].y, dst_data[3].z, dst_data[3].w);
605 hr = IDirect3DVertexBuffer7_Unlock(dst_vb1);
606 ok(SUCCEEDED(hr), "Failed to unlock destination vertex buffer, hr %#x.\n", hr);
608 hr = IDirect3DVertexBuffer7_Lock(dst_vb2, 0, (void **)&dst_data2, NULL);
609 ok(SUCCEEDED(hr), "Failed to lock destination vertex buffer, hr %#x.\n", hr);
610 /* Small thing without much practical meaning, but I stumbled upon it,
611 * so let's check for it: If the output vertex buffer has no RHW value,
612 * the RHW value of the last vertex is written into the next vertex. */
613 ok(compare_vec3(&dst_data2[4], +1.000e+0f, +0.000e+0f, +0.000e+0f, 4096),
614 "Got unexpected vertex 4 {%.8e, %.8e, %.8e}.\n",
615 dst_data2[4].x, dst_data2[4].y, dst_data2[4].z);
616 hr = IDirect3DVertexBuffer7_Unlock(dst_vb2);
617 ok(SUCCEEDED(hr), "Failed to unlock destination vertex buffer, hr %#x.\n", hr);
619 /* Try a more complicated viewport, same vertices. */
620 memset(&vp, 0, sizeof(vp));
621 vp.dwX = 10;
622 vp.dwY = 5;
623 vp.dwWidth = 246;
624 vp.dwHeight = 130;
625 vp.dvMinZ = -2.0f;
626 vp.dvMaxZ = 4.0f;
627 hr = IDirect3DDevice7_SetViewport(device, &vp);
628 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#x.\n", hr);
630 hr = IDirect3DVertexBuffer7_ProcessVertices(dst_vb1, D3DVOP_TRANSFORM, 0, 4, src_vb, 0, device, 0);
631 ok(SUCCEEDED(hr), "Failed to process vertices, hr %#x.\n", hr);
633 hr = IDirect3DVertexBuffer7_Lock(dst_vb1, 0, (void **)&dst_data, NULL);
634 ok(SUCCEEDED(hr), "Failed to lock destination vertex buffer, hr %#x.\n", hr);
635 ok(compare_vec4(&dst_data[0], +1.330e+2f, +7.000e+1f, -2.000e+0f, +1.000e+0f, 4096),
636 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
637 dst_data[0].x, dst_data[0].y, dst_data[0].z, dst_data[0].w);
638 ok(compare_vec4(&dst_data[1], +2.560e+2f, +5.000e+0f, +4.000e+0f, +1.000e+0f, 4096),
639 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
640 dst_data[1].x, dst_data[1].y, dst_data[1].z, dst_data[1].w);
641 ok(compare_vec4(&dst_data[2], +1.000e+1f, +1.350e+2f, +1.000e+0f, +1.000e+0f, 4096),
642 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
643 dst_data[2].x, dst_data[2].y, dst_data[2].z, dst_data[2].w);
644 ok(compare_vec4(&dst_data[3], +1.945e+2f, +1.025e+2f, -5.000e-1f, +1.000e+0f, 4096),
645 "Got unexpected vertex 3 {%.8e, %.8e, %.8e, %.8e}.\n",
646 dst_data[3].x, dst_data[3].y, dst_data[3].z, dst_data[3].w);
647 hr = IDirect3DVertexBuffer7_Unlock(dst_vb1);
648 ok(SUCCEEDED(hr), "Failed to unlock destination vertex buffer, hr %#x.\n", hr);
650 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &world);
651 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#x.\n", hr);
652 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_VIEW, &view);
653 ok(SUCCEEDED(hr), "Failed to set view transform, hr %#x.\n", hr);
654 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &proj);
655 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
657 hr = IDirect3DVertexBuffer7_ProcessVertices(dst_vb1, D3DVOP_TRANSFORM, 0, 4, src_vb, 0, device, 0);
658 ok(SUCCEEDED(hr), "Failed to process vertices, hr %#x.\n", hr);
660 hr = IDirect3DVertexBuffer7_Lock(dst_vb1, 0, (void **)&dst_data, NULL);
661 ok(SUCCEEDED(hr), "Failed to lock destination vertex buffer, hr %#x.\n", hr);
662 ok(compare_vec4(&dst_data[0], +2.560e+2f, +7.000e+1f, -2.000e+0f, +3.333e-1f, 4096),
663 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
664 dst_data[0].x, dst_data[0].y, dst_data[0].z, dst_data[0].w);
665 ok(compare_vec4(&dst_data[1], +2.560e+2f, +7.813e+1f, -2.750e+0f, +1.250e-1f, 4096),
666 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
667 dst_data[1].x, dst_data[1].y, dst_data[1].z, dst_data[1].w);
668 ok(compare_vec4(&dst_data[2], +2.560e+2f, +4.400e+1f, +4.000e-1f, +4.000e-1f, 4096),
669 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
670 dst_data[2].x, dst_data[2].y, dst_data[2].z, dst_data[2].w);
671 ok(compare_vec4(&dst_data[3], +2.560e+2f, +8.182e+1f, -3.091e+0f, +3.636e-1f, 4096),
672 "Got unexpected vertex 3 {%.8e, %.8e, %.8e, %.8e}.\n",
673 dst_data[3].x, dst_data[3].y, dst_data[3].z, dst_data[3].w);
674 hr = IDirect3DVertexBuffer7_Unlock(dst_vb1);
675 ok(SUCCEEDED(hr), "Failed to unlock destination vertex buffer, hr %#x.\n", hr);
677 IDirect3DVertexBuffer7_Release(dst_vb2);
678 IDirect3DVertexBuffer7_Release(dst_vb1);
679 IDirect3DVertexBuffer7_Release(src_vb);
680 IDirect3D7_Release(d3d7);
681 IDirect3DDevice7_Release(device);
682 DestroyWindow(window);
685 static void test_coop_level_create_device_window(void)
687 HWND focus_window, device_window;
688 IDirectDraw7 *ddraw;
689 HRESULT hr;
691 focus_window = create_window();
692 ddraw = create_ddraw();
693 ok(!!ddraw, "Failed to create a ddraw object.\n");
695 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
696 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
697 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
698 ok(!device_window, "Unexpected device window found.\n");
699 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW);
700 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
701 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
702 ok(!device_window, "Unexpected device window found.\n");
703 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_NORMAL);
704 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
705 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
706 ok(!device_window, "Unexpected device window found.\n");
707 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_NORMAL | DDSCL_FULLSCREEN);
708 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
709 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
710 ok(!device_window, "Unexpected device window found.\n");
711 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
712 ok(hr == DDERR_NOFOCUSWINDOW || broken(hr == DDERR_INVALIDPARAMS), "Got unexpected hr %#x.\n", hr);
713 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
714 ok(!device_window, "Unexpected device window found.\n");
716 /* Windows versions before 98 / NT5 don't support DDSCL_CREATEDEVICEWINDOW. */
717 if (broken(hr == DDERR_INVALIDPARAMS))
719 win_skip("DDSCL_CREATEDEVICEWINDOW not supported, skipping test.\n");
720 IDirectDraw7_Release(ddraw);
721 DestroyWindow(focus_window);
722 return;
725 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
726 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
727 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
728 ok(!device_window, "Unexpected device window found.\n");
729 hr = IDirectDraw7_SetCooperativeLevel(ddraw, focus_window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
730 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
731 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
732 ok(!device_window, "Unexpected device window found.\n");
734 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
735 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
736 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
737 ok(!device_window, "Unexpected device window found.\n");
738 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_SETFOCUSWINDOW
739 | DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
740 ok(hr == DDERR_NOHWND, "Got unexpected hr %#x.\n", hr);
741 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
742 ok(!!device_window, "Device window not found.\n");
744 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
745 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
746 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
747 ok(!device_window, "Unexpected device window found.\n");
748 hr = IDirectDraw7_SetCooperativeLevel(ddraw, focus_window, DDSCL_SETFOCUSWINDOW
749 | DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
750 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
751 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
752 ok(!!device_window, "Device window not found.\n");
754 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
755 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
756 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
757 ok(!device_window, "Unexpected device window found.\n");
758 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
759 ok(hr == DDERR_NOFOCUSWINDOW, "Got unexpected hr %#x.\n", hr);
760 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
761 ok(!device_window, "Unexpected device window found.\n");
762 hr = IDirectDraw7_SetCooperativeLevel(ddraw, focus_window, DDSCL_SETFOCUSWINDOW);
763 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
764 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
765 ok(!device_window, "Unexpected device window found.\n");
766 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
767 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
768 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
769 ok(!!device_window, "Device window not found.\n");
771 IDirectDraw7_Release(ddraw);
772 DestroyWindow(focus_window);
775 static void test_clipper_blt(void)
777 IDirectDrawSurface7 *src_surface, *dst_surface;
778 RECT client_rect, src_rect;
779 IDirectDrawClipper *clipper;
780 DDSURFACEDESC2 surface_desc;
781 unsigned int i, j, x, y;
782 IDirectDraw7 *ddraw;
783 RGNDATA *rgn_data;
784 D3DCOLOR color;
785 ULONG refcount;
786 HRGN r1, r2;
787 HWND window;
788 DDBLTFX fx;
789 HRESULT hr;
790 DWORD *ptr;
791 DWORD ret;
793 static const DWORD src_data[] =
795 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
796 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
797 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
799 static const D3DCOLOR expected1[] =
801 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
802 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
803 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
804 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
806 /* Nvidia on Windows seems to have an off-by-one error
807 * when processing source rectangles. Our left = 1 and
808 * right = 5 input reads from x = {1, 2, 3}. x = 4 is
809 * read as well, but only for the edge pixels on the
810 * output image. The bug happens on the y axis as well,
811 * but we only read one row there, and all source rows
812 * contain the same data. This bug is not dependent on
813 * the presence of a clipper. */
814 static const D3DCOLOR expected1_broken[] =
816 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
817 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
818 0x00000000, 0x00000000, 0x00ff0000, 0x00ff0000,
819 0x00000000, 0x00000000, 0x0000ff00, 0x00ff0000,
821 static const D3DCOLOR expected2[] =
823 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
824 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
825 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
826 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
829 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
830 10, 10, 640, 480, 0, 0, 0, 0);
831 ShowWindow(window, SW_SHOW);
832 ddraw = create_ddraw();
833 ok(!!ddraw, "Failed to create a ddraw object.\n");
835 ret = GetClientRect(window, &client_rect);
836 ok(ret, "Failed to get client rect.\n");
837 ret = MapWindowPoints(window, NULL, (POINT *)&client_rect, 2);
838 ok(ret, "Failed to map client rect.\n");
840 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
841 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
843 hr = IDirectDraw7_CreateClipper(ddraw, 0, &clipper, NULL);
844 ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr);
845 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
846 ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr);
847 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
848 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
849 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
850 ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr);
851 rgn_data = HeapAlloc(GetProcessHeap(), 0, ret);
852 hr = IDirectDrawClipper_GetClipList(clipper, NULL, rgn_data, &ret);
853 ok(SUCCEEDED(hr), "Failed to get clip list, hr %#x.\n", hr);
854 ok(rgn_data->rdh.dwSize == sizeof(rgn_data->rdh), "Got unexpected structure size %#x.\n", rgn_data->rdh.dwSize);
855 ok(rgn_data->rdh.iType == RDH_RECTANGLES, "Got unexpected type %#x.\n", rgn_data->rdh.iType);
856 ok(rgn_data->rdh.nCount >= 1, "Got unexpected count %u.\n", rgn_data->rdh.nCount);
857 ok(EqualRect(&rgn_data->rdh.rcBound, &client_rect),
858 "Got unexpected bounding rect %s, expected %s.\n",
859 wine_dbgstr_rect(&rgn_data->rdh.rcBound), wine_dbgstr_rect(&client_rect));
860 HeapFree(GetProcessHeap(), 0, rgn_data);
862 r1 = CreateRectRgn(0, 0, 320, 240);
863 ok(!!r1, "Failed to create region.\n");
864 r2 = CreateRectRgn(320, 240, 640, 480);
865 ok(!!r2, "Failed to create region.\n");
866 CombineRgn(r1, r1, r2, RGN_OR);
867 ret = GetRegionData(r1, 0, NULL);
868 rgn_data = HeapAlloc(GetProcessHeap(), 0, ret);
869 ret = GetRegionData(r1, ret, rgn_data);
870 ok(!!ret, "Failed to get region data.\n");
872 DeleteObject(r2);
873 DeleteObject(r1);
875 hr = IDirectDrawClipper_SetClipList(clipper, rgn_data, 0);
876 ok(hr == DDERR_CLIPPERISUSINGHWND, "Got unexpected hr %#x.\n", hr);
877 hr = IDirectDrawClipper_SetHWnd(clipper, 0, NULL);
878 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
879 hr = IDirectDrawClipper_SetClipList(clipper, rgn_data, 0);
880 ok(SUCCEEDED(hr), "Failed to set clip list, hr %#x.\n", hr);
882 HeapFree(GetProcessHeap(), 0, rgn_data);
884 memset(&surface_desc, 0, sizeof(surface_desc));
885 surface_desc.dwSize = sizeof(surface_desc);
886 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
887 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
888 surface_desc.dwWidth = 640;
889 surface_desc.dwHeight = 480;
890 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
891 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
892 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
893 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
894 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
895 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
897 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &src_surface, NULL);
898 ok(SUCCEEDED(hr), "Failed to create source surface, hr %#x.\n", hr);
899 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &dst_surface, NULL);
900 ok(SUCCEEDED(hr), "Failed to create destination surface, hr %#x.\n", hr);
902 memset(&fx, 0, sizeof(fx));
903 fx.dwSize = sizeof(fx);
904 hr = IDirectDrawSurface7_Blt(src_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
905 ok(SUCCEEDED(hr), "Failed to clear source surface, hr %#x.\n", hr);
906 hr = IDirectDrawSurface7_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
907 ok(SUCCEEDED(hr), "Failed to clear destination surface, hr %#x.\n", hr);
909 hr = IDirectDrawSurface7_Lock(src_surface, NULL, &surface_desc, 0, NULL);
910 ok(SUCCEEDED(hr), "Failed to lock source surface, hr %#x.\n", hr);
911 ok(U1(surface_desc).lPitch == 2560, "Got unexpected surface pitch %u.\n", U1(surface_desc).lPitch);
912 ptr = surface_desc.lpSurface;
913 memcpy(&ptr[ 0], &src_data[ 0], 6 * sizeof(DWORD));
914 memcpy(&ptr[ 640], &src_data[ 6], 6 * sizeof(DWORD));
915 memcpy(&ptr[1280], &src_data[12], 6 * sizeof(DWORD));
916 hr = IDirectDrawSurface7_Unlock(src_surface, NULL);
917 ok(SUCCEEDED(hr), "Failed to unlock source surface, hr %#x.\n", hr);
919 hr = IDirectDrawSurface7_SetClipper(dst_surface, clipper);
920 ok(SUCCEEDED(hr), "Failed to set clipper, hr %#x.\n", hr);
922 SetRect(&src_rect, 1, 1, 5, 2);
923 hr = IDirectDrawSurface7_Blt(dst_surface, NULL, src_surface, &src_rect, DDBLT_WAIT, NULL);
924 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
925 for (i = 0; i < 4; ++i)
927 for (j = 0; j < 4; ++j)
929 x = 80 * ((2 * j) + 1);
930 y = 60 * ((2 * i) + 1);
931 color = get_surface_color(dst_surface, x, y);
932 ok(compare_color(color, expected1[i * 4 + j], 1)
933 || broken(compare_color(color, expected1_broken[i * 4 + j], 1)),
934 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected1[i * 4 + j], x, y, color);
938 U5(fx).dwFillColor = 0xff0000ff;
939 hr = IDirectDrawSurface7_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
940 ok(SUCCEEDED(hr), "Failed to clear destination surface, hr %#x.\n", hr);
941 for (i = 0; i < 4; ++i)
943 for (j = 0; j < 4; ++j)
945 x = 80 * ((2 * j) + 1);
946 y = 60 * ((2 * i) + 1);
947 color = get_surface_color(dst_surface, x, y);
948 ok(compare_color(color, expected2[i * 4 + j], 1),
949 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected2[i * 4 + j], x, y, color);
953 hr = IDirectDrawSurface7_BltFast(dst_surface, 0, 0, src_surface, NULL, DDBLTFAST_WAIT);
954 ok(hr == DDERR_BLTFASTCANTCLIP, "Got unexpected hr %#x.\n", hr);
956 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
957 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
958 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
959 ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr);
960 DestroyWindow(window);
961 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
962 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
963 hr = IDirectDrawClipper_SetHWnd(clipper, 0, NULL);
964 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
965 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
966 ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr);
967 hr = IDirectDrawClipper_SetClipList(clipper, NULL, 0);
968 ok(SUCCEEDED(hr), "Failed to set clip list, hr %#x.\n", hr);
969 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
970 ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr);
971 hr = IDirectDrawSurface7_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
972 ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr);
974 IDirectDrawSurface7_Release(dst_surface);
975 IDirectDrawSurface7_Release(src_surface);
976 refcount = IDirectDrawClipper_Release(clipper);
977 ok(!refcount, "Clipper has %u references left.\n", refcount);
978 IDirectDraw7_Release(ddraw);
981 static void test_coop_level_d3d_state(void)
983 IDirectDrawSurface7 *rt, *surface;
984 IDirect3DDevice7 *device;
985 IDirectDraw7 *ddraw;
986 IDirect3D7 *d3d;
987 D3DCOLOR color;
988 DWORD value;
989 HWND window;
990 HRESULT hr;
992 window = create_window();
993 if (!(device = create_device(window, DDSCL_NORMAL)))
995 skip("Failed to create a 3D device, skipping test.\n");
996 DestroyWindow(window);
997 return;
1000 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
1001 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1002 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_ZENABLE, &value);
1003 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
1004 ok(!!value, "Got unexpected z-enable state %#x.\n", value);
1005 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, &value);
1006 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
1007 ok(!value, "Got unexpected alpha blend enable state %#x.\n", value);
1008 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);
1009 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
1010 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff0000, 0.0f, 0);
1011 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
1012 color = get_surface_color(rt, 320, 240);
1013 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
1015 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
1016 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
1017 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
1018 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
1019 IDirect3D7_Release(d3d);
1020 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
1021 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
1022 hr = IDirectDrawSurface7_IsLost(rt);
1023 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
1024 hr = IDirectDraw7_RestoreAllSurfaces(ddraw);
1025 ok(SUCCEEDED(hr), "Failed to restore surfaces, hr %#x.\n", hr);
1026 IDirectDraw7_Release(ddraw);
1028 hr = IDirect3DDevice7_GetRenderTarget(device, &surface);
1029 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1030 ok(surface == rt, "Got unexpected surface %p.\n", surface);
1031 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_ZENABLE, &value);
1032 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
1033 ok(!!value, "Got unexpected z-enable state %#x.\n", value);
1034 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, &value);
1035 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
1036 ok(!!value, "Got unexpected alpha blend enable state %#x.\n", value);
1037 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff00ff00, 0.0f, 0);
1038 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
1039 color = get_surface_color(rt, 320, 240);
1040 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
1042 IDirectDrawSurface7_Release(surface);
1043 IDirectDrawSurface7_Release(rt);
1044 IDirect3DDevice7_Release(device);
1045 DestroyWindow(window);
1048 static void test_surface_interface_mismatch(void)
1050 IDirectDraw7 *ddraw = NULL;
1051 IDirect3D7 *d3d = NULL;
1052 IDirectDrawSurface7 *surface = NULL, *ds;
1053 IDirectDrawSurface3 *surface3 = NULL;
1054 IDirect3DDevice7 *device = NULL;
1055 DDSURFACEDESC2 surface_desc;
1056 DDPIXELFORMAT z_fmt;
1057 ULONG refcount;
1058 HRESULT hr;
1059 D3DCOLOR color;
1060 HWND window;
1062 window = create_window();
1063 ddraw = create_ddraw();
1064 ok(!!ddraw, "Failed to create a ddraw object.\n");
1065 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
1066 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
1068 memset(&surface_desc, 0, sizeof(surface_desc));
1069 surface_desc.dwSize = sizeof(surface_desc);
1070 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1071 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
1072 surface_desc.dwWidth = 640;
1073 surface_desc.dwHeight = 480;
1075 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1076 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1078 hr = IDirectDrawSurface7_QueryInterface(surface, &IID_IDirectDrawSurface3, (void **)&surface3);
1079 ok(SUCCEEDED(hr), "Failed to QI IDirectDrawSurface3, hr %#x.\n", hr);
1081 if (FAILED(IDirectDraw7_QueryInterface(ddraw, &IID_IDirect3D7, (void **)&d3d)))
1083 skip("D3D interface is not available, skipping test.\n");
1084 goto cleanup;
1087 memset(&z_fmt, 0, sizeof(z_fmt));
1088 hr = IDirect3D7_EnumZBufferFormats(d3d, &IID_IDirect3DHALDevice, enum_z_fmt, &z_fmt);
1089 if (FAILED(hr) || !z_fmt.dwSize)
1091 skip("No depth buffer formats available, skipping test.\n");
1092 goto cleanup;
1095 memset(&surface_desc, 0, sizeof(surface_desc));
1096 surface_desc.dwSize = sizeof(surface_desc);
1097 surface_desc.dwFlags = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT;
1098 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
1099 U4(surface_desc).ddpfPixelFormat = z_fmt;
1100 surface_desc.dwWidth = 640;
1101 surface_desc.dwHeight = 480;
1102 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &ds, NULL);
1103 ok(SUCCEEDED(hr), "Failed to create depth buffer, hr %#x.\n", hr);
1104 if (FAILED(hr))
1105 goto cleanup;
1107 /* Using a different surface interface version still works */
1108 hr = IDirectDrawSurface3_AddAttachedSurface(surface3, (IDirectDrawSurface3 *)ds);
1109 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
1110 refcount = IDirectDrawSurface7_Release(ds);
1111 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
1112 if (FAILED(hr))
1113 goto cleanup;
1115 /* Here too */
1116 hr = IDirect3D7_CreateDevice(d3d, &IID_IDirect3DHALDevice, (IDirectDrawSurface7 *)surface3, &device);
1117 ok(SUCCEEDED(hr), "Failed to create d3d device.\n");
1118 if (FAILED(hr))
1119 goto cleanup;
1121 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff0000, 0.0f, 0);
1122 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
1123 color = get_surface_color(surface, 320, 240);
1124 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
1126 cleanup:
1127 if (surface3) IDirectDrawSurface3_Release(surface3);
1128 if (surface) IDirectDrawSurface7_Release(surface);
1129 if (device) IDirect3DDevice7_Release(device);
1130 if (d3d) IDirect3D7_Release(d3d);
1131 if (ddraw) IDirectDraw7_Release(ddraw);
1132 DestroyWindow(window);
1135 static void test_coop_level_threaded(void)
1137 struct create_window_thread_param p;
1138 IDirectDraw7 *ddraw;
1139 HRESULT hr;
1141 ddraw = create_ddraw();
1142 ok(!!ddraw, "Failed to create a ddraw object.\n");
1143 create_window_thread(&p);
1145 hr = IDirectDraw7_SetCooperativeLevel(ddraw, p.window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
1146 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
1148 IDirectDraw7_Release(ddraw);
1149 destroy_window_thread(&p);
1152 static void test_depth_blit(void)
1154 IDirect3DDevice7 *device;
1155 static struct
1157 float x, y, z;
1158 DWORD color;
1160 quad1[] =
1162 { -1.0, 1.0, 0.50f, 0xff00ff00},
1163 { 1.0, 1.0, 0.50f, 0xff00ff00},
1164 { -1.0, -1.0, 0.50f, 0xff00ff00},
1165 { 1.0, -1.0, 0.50f, 0xff00ff00},
1167 static const D3DCOLOR expected_colors[4][4] =
1169 {0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00},
1170 {0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00},
1171 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1172 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1174 DDSURFACEDESC2 ddsd_new, ddsd_existing;
1176 IDirectDrawSurface7 *ds1, *ds2, *ds3, *rt;
1177 RECT src_rect, dst_rect;
1178 unsigned int i, j;
1179 D3DCOLOR color;
1180 HRESULT hr;
1181 IDirect3D7 *d3d;
1182 IDirectDraw7 *ddraw;
1183 DDBLTFX fx;
1184 HWND window;
1186 window = create_window();
1187 if (!(device = create_device(window, DDSCL_NORMAL)))
1189 skip("Failed to create a 3D device, skipping test.\n");
1190 DestroyWindow(window);
1191 return;
1194 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
1195 ok(SUCCEEDED(hr), "Failed to get Direct3D7 interface, hr %#x.\n", hr);
1196 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
1197 ok(SUCCEEDED(hr), "Failed to get DirectDraw7 interface, hr %#x.\n", hr);
1198 IDirect3D7_Release(d3d);
1200 ds1 = get_depth_stencil(device);
1202 memset(&ddsd_new, 0, sizeof(ddsd_new));
1203 ddsd_new.dwSize = sizeof(ddsd_new);
1204 memset(&ddsd_existing, 0, sizeof(ddsd_existing));
1205 ddsd_existing.dwSize = sizeof(ddsd_existing);
1206 hr = IDirectDrawSurface7_GetSurfaceDesc(ds1, &ddsd_existing);
1207 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
1208 ddsd_new.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
1209 ddsd_new.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
1210 ddsd_new.dwWidth = ddsd_existing.dwWidth;
1211 ddsd_new.dwHeight = ddsd_existing.dwHeight;
1212 U4(ddsd_new).ddpfPixelFormat = U4(ddsd_existing).ddpfPixelFormat;
1213 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd_new, &ds2, NULL);
1214 ok(SUCCEEDED(hr), "Failed to create a z buffer, hr %#x.\n", hr);
1215 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd_new, &ds3, NULL);
1216 ok(SUCCEEDED(hr), "Failed to create a z buffer, hr %#x.\n", hr);
1217 IDirectDraw7_Release(ddraw);
1219 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_TRUE);
1220 ok(SUCCEEDED(hr), "Failed to enable z testing, hr %#x.\n", hr);
1221 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZFUNC, D3DCMP_LESSEQUAL);
1222 ok(SUCCEEDED(hr), "Failed to set the z function, hr %#x.\n", hr);
1223 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
1224 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
1226 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER, 0, 0.0f, 0);
1227 ok(SUCCEEDED(hr), "Failed to clear the z buffer, hr %#x.\n", hr);
1229 /* Partial blit. */
1230 SetRect(&src_rect, 0, 0, 320, 240);
1231 SetRect(&dst_rect, 0, 0, 320, 240);
1232 hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1233 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1234 /* Different locations. */
1235 SetRect(&src_rect, 0, 0, 320, 240);
1236 SetRect(&dst_rect, 320, 240, 640, 480);
1237 hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1238 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1239 /* Stretched. */
1240 SetRect(&src_rect, 0, 0, 320, 240);
1241 SetRect(&dst_rect, 0, 0, 640, 480);
1242 hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1243 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1244 /* Flipped. */
1245 SetRect(&src_rect, 0, 480, 640, 0);
1246 SetRect(&dst_rect, 0, 0, 640, 480);
1247 hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1248 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
1249 SetRect(&src_rect, 0, 0, 640, 480);
1250 SetRect(&dst_rect, 0, 480, 640, 0);
1251 hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1252 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
1253 /* Full, explicit. */
1254 SetRect(&src_rect, 0, 0, 640, 480);
1255 SetRect(&dst_rect, 0, 0, 640, 480);
1256 hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1257 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1258 /* Depth -> color blit: Succeeds on Win7 + Radeon HD 5700, fails on WinXP + Radeon X1600 */
1260 /* Depth blit inside a BeginScene / EndScene pair */
1261 hr = IDirect3DDevice7_BeginScene(device);
1262 ok(SUCCEEDED(hr), "Failed to start scene, hr %#x.\n", hr);
1263 /* From the current depth stencil */
1264 hr = IDirectDrawSurface7_Blt(ds2, NULL, ds1, NULL, DDBLT_WAIT, NULL);
1265 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1266 /* To the current depth stencil */
1267 hr = IDirectDrawSurface7_Blt(ds1, NULL, ds2, NULL, DDBLT_WAIT, NULL);
1268 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1269 /* Between unbound surfaces */
1270 hr = IDirectDrawSurface7_Blt(ds3, NULL, ds2, NULL, DDBLT_WAIT, NULL);
1271 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1272 hr = IDirect3DDevice7_EndScene(device);
1273 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1275 /* Avoid changing the depth stencil, it doesn't work properly on Windows.
1276 * Instead use DDBLT_DEPTHFILL to clear the depth stencil. Unfortunately
1277 * drivers disagree on the meaning of dwFillDepth. Only 0 seems to produce
1278 * a reliable result(z = 0.0) */
1279 memset(&fx, 0, sizeof(fx));
1280 fx.dwSize = sizeof(fx);
1281 hr = IDirectDrawSurface7_Blt(ds2, NULL, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
1282 ok(SUCCEEDED(hr), "Failed to clear the source z buffer, hr %#x.\n", hr);
1284 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER | D3DCLEAR_TARGET, 0xffff0000, 1.0f, 0);
1285 ok(SUCCEEDED(hr), "Failed to clear the color and z buffers, hr %#x.\n", hr);
1286 SetRect(&dst_rect, 0, 0, 320, 240);
1287 hr = IDirectDrawSurface7_Blt(ds1, &dst_rect, ds2, NULL, DDBLT_WAIT, NULL);
1288 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1289 IDirectDrawSurface7_Release(ds3);
1290 IDirectDrawSurface7_Release(ds2);
1291 IDirectDrawSurface7_Release(ds1);
1293 hr = IDirect3DDevice7_BeginScene(device);
1294 ok(SUCCEEDED(hr), "Failed to start scene, hr %#x.\n", hr);
1295 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE,
1296 quad1, 4, 0);
1297 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1298 hr = IDirect3DDevice7_EndScene(device);
1299 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1301 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
1302 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1303 for (i = 0; i < 4; ++i)
1305 for (j = 0; j < 4; ++j)
1307 unsigned int x = 80 * ((2 * j) + 1);
1308 unsigned int y = 60 * ((2 * i) + 1);
1309 color = get_surface_color(rt, x, y);
1310 ok(compare_color(color, expected_colors[i][j], 1),
1311 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected_colors[i][j], x, y, color);
1315 IDirectDrawSurface7_Release(rt);
1316 IDirect3DDevice7_Release(device);
1317 DestroyWindow(window);
1320 static void test_texture_load_ckey(void)
1322 HWND window;
1323 IDirect3DDevice7 *device;
1324 IDirectDraw7 *ddraw;
1325 IDirectDrawSurface7 *src;
1326 IDirectDrawSurface7 *dst;
1327 DDSURFACEDESC2 ddsd;
1328 HRESULT hr;
1329 DDCOLORKEY ckey;
1330 IDirect3D7 *d3d;
1332 window = create_window();
1333 if (!(device = create_device(window, DDSCL_NORMAL)))
1335 skip("Failed to create a 3D device, skipping test.\n");
1336 DestroyWindow(window);
1337 return;
1340 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
1341 ok(SUCCEEDED(hr), "Failed to get Direct3D7 interface, hr %#x.\n", hr);
1342 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
1343 ok(SUCCEEDED(hr), "Failed to get DirectDraw7 interface, hr %#x.\n", hr);
1344 IDirect3D7_Release(d3d);
1346 memset(&ddsd, 0, sizeof(ddsd));
1347 ddsd.dwSize = sizeof(ddsd);
1348 ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
1349 ddsd.dwHeight = 128;
1350 ddsd.dwWidth = 128;
1351 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY;
1352 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &src, NULL);
1353 ok(SUCCEEDED(hr), "Failed to create source texture, hr %#x.\n", hr);
1354 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1355 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &dst, NULL);
1356 ok(SUCCEEDED(hr), "Failed to create destination texture, hr %#x.\n", hr);
1358 /* No surface has a color key */
1359 hr = IDirect3DDevice7_Load(device, dst, NULL, src, NULL, 0);
1360 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1361 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0xdeadbeef;
1362 hr = IDirectDrawSurface7_GetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1363 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1364 ok(ckey.dwColorSpaceLowValue == 0xdeadbeef, "dwColorSpaceLowValue is %#x.\n", ckey.dwColorSpaceLowValue);
1365 ok(ckey.dwColorSpaceHighValue == 0xdeadbeef, "dwColorSpaceHighValue is %#x.\n", ckey.dwColorSpaceHighValue);
1367 /* Source surface has a color key */
1368 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0x0000ff00;
1369 hr = IDirectDrawSurface7_SetColorKey(src, DDCKEY_SRCBLT, &ckey);
1370 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1371 hr = IDirect3DDevice7_Load(device, dst, NULL, src, NULL, 0);
1372 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1373 hr = IDirectDrawSurface7_GetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1374 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1375 ok(ckey.dwColorSpaceLowValue == 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey.dwColorSpaceLowValue);
1376 ok(ckey.dwColorSpaceHighValue == 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey.dwColorSpaceHighValue);
1378 /* Both surfaces have a color key: Dest ckey is overwritten */
1379 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0x000000ff;
1380 hr = IDirectDrawSurface7_SetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1381 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1382 hr = IDirect3DDevice7_Load(device, dst, NULL, src, NULL, 0);
1383 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1384 hr = IDirectDrawSurface7_GetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1385 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1386 ok(ckey.dwColorSpaceLowValue == 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey.dwColorSpaceLowValue);
1387 ok(ckey.dwColorSpaceHighValue == 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey.dwColorSpaceHighValue);
1389 /* Only the destination has a color key: It is deleted. This behavior differs from
1390 * IDirect3DTexture(2)::Load */
1391 hr = IDirectDrawSurface7_SetColorKey(src, DDCKEY_SRCBLT, NULL);
1392 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1393 hr = IDirectDrawSurface7_GetColorKey(src, DDCKEY_SRCBLT, &ckey);
1394 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1395 hr = IDirect3DDevice7_Load(device, dst, NULL, src, NULL, 0);
1396 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1397 hr = IDirectDrawSurface7_GetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1398 todo_wine ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1400 IDirectDrawSurface7_Release(dst);
1401 IDirectDrawSurface7_Release(src);
1402 IDirectDraw7_Release(ddraw);
1403 IDirect3DDevice7_Release(device);
1404 DestroyWindow(window);
1407 static void test_zenable(void)
1409 static struct
1411 struct vec4 position;
1412 D3DCOLOR diffuse;
1414 tquad[] =
1416 {{ 0.0f, 480.0f, -0.5f, 1.0f}, 0xff00ff00},
1417 {{ 0.0f, 0.0f, -0.5f, 1.0f}, 0xff00ff00},
1418 {{640.0f, 480.0f, 1.5f, 1.0f}, 0xff00ff00},
1419 {{640.0f, 0.0f, 1.5f, 1.0f}, 0xff00ff00},
1421 IDirect3DDevice7 *device;
1422 IDirectDrawSurface7 *rt;
1423 D3DCOLOR color;
1424 HWND window;
1425 HRESULT hr;
1426 UINT x, y;
1427 UINT i, j;
1429 window = create_window();
1430 if (!(device = create_device(window, DDSCL_NORMAL)))
1432 skip("Failed to create a 3D device, skipping test.\n");
1433 DestroyWindow(window);
1434 return;
1437 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
1438 ok(SUCCEEDED(hr), "Failed to disable z-buffering, hr %#x.\n", hr);
1440 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffff0000, 0.0f, 0);
1441 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
1442 hr = IDirect3DDevice7_BeginScene(device);
1443 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1444 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_DIFFUSE, tquad, 4, 0);
1445 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1446 hr = IDirect3DDevice7_EndScene(device);
1447 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1449 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
1450 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1451 for (i = 0; i < 4; ++i)
1453 for (j = 0; j < 4; ++j)
1455 x = 80 * ((2 * j) + 1);
1456 y = 60 * ((2 * i) + 1);
1457 color = get_surface_color(rt, x, y);
1458 ok(compare_color(color, 0x0000ff00, 1),
1459 "Expected color 0x0000ff00 at %u, %u, got 0x%08x.\n", x, y, color);
1462 IDirectDrawSurface7_Release(rt);
1464 IDirect3DDevice7_Release(device);
1465 DestroyWindow(window);
1468 static void test_ck_rgba(void)
1470 static struct
1472 struct vec4 position;
1473 struct vec2 texcoord;
1475 tquad[] =
1477 {{ 0.0f, 480.0f, 0.25f, 1.0f}, {0.0f, 0.0f}},
1478 {{ 0.0f, 0.0f, 0.25f, 1.0f}, {0.0f, 1.0f}},
1479 {{640.0f, 480.0f, 0.25f, 1.0f}, {1.0f, 0.0f}},
1480 {{640.0f, 0.0f, 0.25f, 1.0f}, {1.0f, 1.0f}},
1481 {{ 0.0f, 480.0f, 0.75f, 1.0f}, {0.0f, 0.0f}},
1482 {{ 0.0f, 0.0f, 0.75f, 1.0f}, {0.0f, 1.0f}},
1483 {{640.0f, 480.0f, 0.75f, 1.0f}, {1.0f, 0.0f}},
1484 {{640.0f, 0.0f, 0.75f, 1.0f}, {1.0f, 1.0f}},
1486 static const struct
1488 D3DCOLOR fill_color;
1489 BOOL color_key;
1490 BOOL blend;
1491 D3DCOLOR result1, result1_broken;
1492 D3DCOLOR result2, result2_broken;
1494 tests[] =
1496 /* r200 on Windows doesn't check the alpha component when applying the color
1497 * key, so the key matches on every texel. */
1498 {0xff00ff00, TRUE, TRUE, 0x00ff0000, 0x00ff0000, 0x000000ff, 0x000000ff},
1499 {0xff00ff00, TRUE, FALSE, 0x00ff0000, 0x00ff0000, 0x000000ff, 0x000000ff},
1500 {0xff00ff00, FALSE, TRUE, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1501 {0xff00ff00, FALSE, FALSE, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1502 {0x7f00ff00, TRUE, TRUE, 0x00807f00, 0x00ff0000, 0x00807f00, 0x000000ff},
1503 {0x7f00ff00, TRUE, FALSE, 0x0000ff00, 0x00ff0000, 0x0000ff00, 0x000000ff},
1504 {0x7f00ff00, FALSE, TRUE, 0x00807f00, 0x00807f00, 0x00807f00, 0x00807f00},
1505 {0x7f00ff00, FALSE, FALSE, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1508 IDirectDrawSurface7 *texture;
1509 DDSURFACEDESC2 surface_desc;
1510 IDirect3DDevice7 *device;
1511 IDirectDrawSurface7 *rt;
1512 IDirectDraw7 *ddraw;
1513 IDirect3D7 *d3d;
1514 D3DCOLOR color;
1515 HWND window;
1516 DDBLTFX fx;
1517 HRESULT hr;
1518 UINT i;
1520 window = create_window();
1521 if (!(device = create_device(window, DDSCL_NORMAL)))
1523 skip("Failed to create a 3D device, skipping test.\n");
1524 DestroyWindow(window);
1525 return;
1528 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
1529 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
1530 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
1531 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
1532 IDirect3D7_Release(d3d);
1534 memset(&surface_desc, 0, sizeof(surface_desc));
1535 surface_desc.dwSize = sizeof(surface_desc);
1536 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CKSRCBLT;
1537 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1538 surface_desc.dwWidth = 256;
1539 surface_desc.dwHeight = 256;
1540 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
1541 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
1542 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
1543 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
1544 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
1545 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
1546 U5(U4(surface_desc).ddpfPixelFormat).dwRGBAlphaBitMask = 0xff000000;
1547 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0xff00ff00;
1548 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0xff00ff00;
1549 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &texture, NULL);
1550 ok(SUCCEEDED(hr), "Failed to create destination surface, hr %#x.\n", hr);
1552 hr = IDirect3DDevice7_SetTexture(device, 0, texture);
1553 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
1554 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);
1555 ok(SUCCEEDED(hr), "Failed to enable alpha blending, hr %#x.\n", hr);
1556 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA);
1557 ok(SUCCEEDED(hr), "Failed to enable alpha blending, hr %#x.\n", hr);
1559 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
1560 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1562 for (i = 0; i < ARRAY_SIZE(tests); ++i)
1564 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, tests[i].color_key);
1565 ok(SUCCEEDED(hr), "Failed to enable color keying, hr %#x.\n", hr);
1566 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, tests[i].blend);
1567 ok(SUCCEEDED(hr), "Failed to enable alpha blending, hr %#x.\n", hr);
1569 memset(&fx, 0, sizeof(fx));
1570 fx.dwSize = sizeof(fx);
1571 U5(fx).dwFillColor = tests[i].fill_color;
1572 hr = IDirectDrawSurface7_Blt(texture, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
1573 ok(SUCCEEDED(hr), "Failed to fill texture, hr %#x.\n", hr);
1575 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffff0000, 1.0f, 0);
1576 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
1577 hr = IDirect3DDevice7_BeginScene(device);
1578 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1579 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_TEX1, &tquad[0], 4, 0);
1580 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1581 hr = IDirect3DDevice7_EndScene(device);
1582 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1584 color = get_surface_color(rt, 320, 240);
1585 ok(compare_color(color, tests[i].result1, 1) || compare_color(color, tests[i].result1_broken, 1),
1586 "Expected color 0x%08x for test %u, got 0x%08x.\n",
1587 tests[i].result1, i, color);
1589 U5(fx).dwFillColor = 0xff0000ff;
1590 hr = IDirectDrawSurface7_Blt(texture, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
1591 ok(SUCCEEDED(hr), "Failed to fill texture, hr %#x.\n", hr);
1593 hr = IDirect3DDevice7_BeginScene(device);
1594 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1595 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_TEX1, &tquad[4], 4, 0);
1596 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1597 hr = IDirect3DDevice7_EndScene(device);
1598 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1600 /* This tests that fragments that are masked out by the color key are
1601 * discarded, instead of just fully transparent. */
1602 color = get_surface_color(rt, 320, 240);
1603 ok(compare_color(color, tests[i].result2, 1) || compare_color(color, tests[i].result2_broken, 1),
1604 "Expected color 0x%08x for test %u, got 0x%08x.\n",
1605 tests[i].result2, i, color);
1608 IDirectDrawSurface7_Release(rt);
1609 IDirectDrawSurface7_Release(texture);
1610 IDirectDraw7_Release(ddraw);
1611 IDirect3DDevice7_Release(device);
1612 DestroyWindow(window);
1615 static void test_ck_default(void)
1617 static struct
1619 struct vec4 position;
1620 struct vec2 texcoord;
1622 tquad[] =
1624 {{ 0.0f, 480.0f, 0.0f, 1.0f}, {0.0f, 0.0f}},
1625 {{ 0.0f, 0.0f, 0.0f, 1.0f}, {0.0f, 1.0f}},
1626 {{640.0f, 480.0f, 0.0f, 1.0f}, {1.0f, 0.0f}},
1627 {{640.0f, 0.0f, 0.0f, 1.0f}, {1.0f, 1.0f}},
1629 IDirectDrawSurface7 *surface, *rt;
1630 DDSURFACEDESC2 surface_desc;
1631 IDirect3DDevice7 *device;
1632 IDirectDraw7 *ddraw;
1633 IDirect3D7 *d3d;
1634 D3DCOLOR color;
1635 DWORD value;
1636 HWND window;
1637 DDBLTFX fx;
1638 HRESULT hr;
1640 window = create_window();
1641 if (!(device = create_device(window, DDSCL_NORMAL)))
1643 skip("Failed to create a 3D device, skipping test.\n");
1644 DestroyWindow(window);
1645 return;
1648 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
1649 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
1650 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
1651 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
1652 IDirect3D7_Release(d3d);
1654 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
1655 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1657 memset(&surface_desc, 0, sizeof(surface_desc));
1658 surface_desc.dwSize = sizeof(surface_desc);
1659 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CKSRCBLT;
1660 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1661 surface_desc.dwWidth = 256;
1662 surface_desc.dwHeight = 256;
1663 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
1664 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
1665 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
1666 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
1667 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
1668 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
1669 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x000000ff;
1670 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x000000ff;
1671 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1672 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1673 hr = IDirect3DDevice7_SetTexture(device, 0, surface);
1674 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
1676 memset(&fx, 0, sizeof(fx));
1677 fx.dwSize = sizeof(fx);
1678 U5(fx).dwFillColor = 0x000000ff;
1679 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
1680 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
1682 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff00ff00, 1.0f, 0);
1683 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
1684 hr = IDirect3DDevice7_BeginScene(device);
1685 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1686 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, &value);
1687 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
1688 ok(!value, "Got unexpected color keying state %#x.\n", value);
1689 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_TEX1, &tquad[0], 4, 0);
1690 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1691 hr = IDirect3DDevice7_EndScene(device);
1692 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1693 color = get_surface_color(rt, 320, 240);
1694 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
1696 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff00ff00, 1.0f, 0);
1697 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
1698 hr = IDirect3DDevice7_BeginScene(device);
1699 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1700 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, TRUE);
1701 ok(SUCCEEDED(hr), "Failed to enable color keying, hr %#x.\n", hr);
1702 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_TEX1, &tquad[0], 4, 0);
1703 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1704 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, &value);
1705 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
1706 ok(!!value, "Got unexpected color keying state %#x.\n", value);
1707 hr = IDirect3DDevice7_EndScene(device);
1708 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1709 color = get_surface_color(rt, 320, 240);
1710 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
1712 IDirectDrawSurface7_Release(surface);
1713 IDirectDrawSurface7_Release(rt);
1714 IDirect3DDevice7_Release(device);
1715 IDirectDraw7_Release(ddraw);
1716 DestroyWindow(window);
1719 static void test_ck_complex(void)
1721 IDirectDrawSurface7 *surface, *mipmap, *tmp;
1722 D3DDEVICEDESC7 device_desc;
1723 DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, {0}};
1724 DDSURFACEDESC2 surface_desc;
1725 IDirect3DDevice7 *device;
1726 DDCOLORKEY color_key;
1727 IDirectDraw7 *ddraw;
1728 IDirect3D7 *d3d;
1729 unsigned int i;
1730 ULONG refcount;
1731 HWND window;
1732 HRESULT hr;
1734 window = create_window();
1735 if (!(device = create_device(window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN)))
1737 skip("Failed to create a 3D device, skipping test.\n");
1738 DestroyWindow(window);
1739 return;
1741 hr = IDirect3DDevice7_GetCaps(device, &device_desc);
1742 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
1743 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
1744 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
1745 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
1746 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
1747 IDirect3D7_Release(d3d);
1749 memset(&surface_desc, 0, sizeof(surface_desc));
1750 surface_desc.dwSize = sizeof(surface_desc);
1751 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1752 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
1753 surface_desc.dwWidth = 128;
1754 surface_desc.dwHeight = 128;
1755 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1756 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1758 hr = IDirectDrawSurface7_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1759 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1760 color_key.dwColorSpaceLowValue = 0x0000ff00;
1761 color_key.dwColorSpaceHighValue = 0x0000ff00;
1762 hr = IDirectDrawSurface7_SetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1763 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1764 memset(&color_key, 0, sizeof(color_key));
1765 hr = IDirectDrawSurface7_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1766 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
1767 ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1768 color_key.dwColorSpaceLowValue);
1769 ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1770 color_key.dwColorSpaceHighValue);
1772 mipmap = surface;
1773 IDirectDrawSurface_AddRef(mipmap);
1774 for (i = 0; i < 7; ++i)
1776 hr = IDirectDrawSurface7_GetAttachedSurface(mipmap, &caps, &tmp);
1777 ok(SUCCEEDED(hr), "Failed to get attached surface, i %u, hr %#x.\n", i, hr);
1778 hr = IDirectDrawSurface7_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1779 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x, i %u.\n", hr, i);
1781 color_key.dwColorSpaceLowValue = 0x000000ff;
1782 color_key.dwColorSpaceHighValue = 0x000000ff;
1783 hr = IDirectDrawSurface7_SetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1784 ok(hr == DDERR_NOTONMIPMAPSUBLEVEL, "Got unexpected hr %#x, i %u.\n", hr, i);
1786 IDirectDrawSurface_Release(mipmap);
1787 mipmap = tmp;
1790 hr = IDirectDrawSurface7_GetAttachedSurface(mipmap, &caps, &tmp);
1791 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
1792 IDirectDrawSurface_Release(mipmap);
1793 refcount = IDirectDrawSurface7_Release(surface);
1794 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1796 memset(&surface_desc, 0, sizeof(surface_desc));
1797 surface_desc.dwSize = sizeof(surface_desc);
1798 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
1799 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
1800 U5(surface_desc).dwBackBufferCount = 1;
1801 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1802 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1804 hr = IDirectDrawSurface7_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1805 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1806 color_key.dwColorSpaceLowValue = 0x0000ff00;
1807 color_key.dwColorSpaceHighValue = 0x0000ff00;
1808 hr = IDirectDrawSurface7_SetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1809 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1810 memset(&color_key, 0, sizeof(color_key));
1811 hr = IDirectDrawSurface7_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1812 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
1813 ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1814 color_key.dwColorSpaceLowValue);
1815 ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1816 color_key.dwColorSpaceHighValue);
1818 hr = IDirectDrawSurface7_GetAttachedSurface(surface, &caps, &tmp);
1819 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
1821 hr = IDirectDrawSurface7_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1822 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x, i %u.\n", hr, i);
1823 color_key.dwColorSpaceLowValue = 0x0000ff00;
1824 color_key.dwColorSpaceHighValue = 0x0000ff00;
1825 hr = IDirectDrawSurface7_SetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1826 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1827 memset(&color_key, 0, sizeof(color_key));
1828 hr = IDirectDrawSurface7_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1829 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
1830 ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1831 color_key.dwColorSpaceLowValue);
1832 ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1833 color_key.dwColorSpaceHighValue);
1835 IDirectDrawSurface_Release(tmp);
1837 refcount = IDirectDrawSurface7_Release(surface);
1838 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1840 if (!(device_desc.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_CUBEMAP))
1842 skip("Device does not support cubemaps.\n");
1843 goto cleanup;
1845 memset(&surface_desc, 0, sizeof(surface_desc));
1846 surface_desc.dwSize = sizeof(surface_desc);
1847 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1848 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
1849 surface_desc.ddsCaps.dwCaps2 = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES;
1850 surface_desc.dwWidth = 128;
1851 surface_desc.dwHeight = 128;
1852 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1853 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1855 hr = IDirectDrawSurface7_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1856 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1857 color_key.dwColorSpaceLowValue = 0x0000ff00;
1858 color_key.dwColorSpaceHighValue = 0x0000ff00;
1859 hr = IDirectDrawSurface7_SetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1860 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1862 caps.dwCaps2 = DDSCAPS2_CUBEMAP_NEGATIVEZ;
1863 hr = IDirectDrawSurface7_GetAttachedSurface(surface, &caps, &mipmap);
1864 ok(SUCCEEDED(hr), "Failed to get attached surface, i %u, hr %#x.\n", i, hr);
1866 hr = IDirectDrawSurface7_GetColorKey(mipmap, DDCKEY_SRCBLT, &color_key);
1867 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1868 color_key.dwColorSpaceLowValue = 0x000000ff;
1869 color_key.dwColorSpaceHighValue = 0x000000ff;
1870 hr = IDirectDrawSurface7_SetColorKey(mipmap, DDCKEY_SRCBLT, &color_key);
1871 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1873 color_key.dwColorSpaceLowValue = 0;
1874 color_key.dwColorSpaceHighValue = 0;
1875 hr = IDirectDrawSurface7_GetColorKey(mipmap, DDCKEY_SRCBLT, &color_key);
1876 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
1877 ok(color_key.dwColorSpaceLowValue == 0x000000ff, "Got unexpected value 0x%08x.\n",
1878 color_key.dwColorSpaceLowValue);
1879 ok(color_key.dwColorSpaceHighValue == 0x000000ff, "Got unexpected value 0x%08x.\n",
1880 color_key.dwColorSpaceHighValue);
1882 IDirectDrawSurface_AddRef(mipmap);
1883 for (i = 0; i < 7; ++i)
1885 hr = IDirectDrawSurface7_GetAttachedSurface(mipmap, &caps, &tmp);
1886 ok(SUCCEEDED(hr), "Failed to get attached surface, i %u, hr %#x.\n", i, hr);
1887 hr = IDirectDrawSurface7_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1888 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x, i %u.\n", hr, i);
1890 color_key.dwColorSpaceLowValue = 0x000000ff;
1891 color_key.dwColorSpaceHighValue = 0x000000ff;
1892 hr = IDirectDrawSurface7_SetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1893 ok(hr == DDERR_NOTONMIPMAPSUBLEVEL, "Got unexpected hr %#x, i %u.\n", hr, i);
1895 IDirectDrawSurface_Release(mipmap);
1896 mipmap = tmp;
1899 IDirectDrawSurface7_Release(mipmap);
1901 refcount = IDirectDrawSurface7_Release(surface);
1902 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1904 cleanup:
1905 IDirectDraw7_Release(ddraw);
1906 refcount = IDirect3DDevice7_Release(device);
1907 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1908 DestroyWindow(window);
1911 struct qi_test
1913 REFIID iid;
1914 REFIID refcount_iid;
1915 HRESULT hr;
1918 static void test_qi(const char *test_name, IUnknown *base_iface,
1919 REFIID refcount_iid, const struct qi_test *tests, UINT entry_count)
1921 ULONG refcount, expected_refcount;
1922 IUnknown *iface1, *iface2;
1923 HRESULT hr;
1924 UINT i, j;
1926 for (i = 0; i < entry_count; ++i)
1928 hr = IUnknown_QueryInterface(base_iface, tests[i].iid, (void **)&iface1);
1929 ok(hr == tests[i].hr, "Got hr %#x for test \"%s\" %u.\n", hr, test_name, i);
1930 if (SUCCEEDED(hr))
1932 for (j = 0; j < entry_count; ++j)
1934 hr = IUnknown_QueryInterface(iface1, tests[j].iid, (void **)&iface2);
1935 ok(hr == tests[j].hr, "Got hr %#x for test \"%s\" %u, %u.\n", hr, test_name, i, j);
1936 if (SUCCEEDED(hr))
1938 expected_refcount = 0;
1939 if (IsEqualGUID(refcount_iid, tests[j].refcount_iid))
1940 ++expected_refcount;
1941 if (IsEqualGUID(tests[i].refcount_iid, tests[j].refcount_iid))
1942 ++expected_refcount;
1943 refcount = IUnknown_Release(iface2);
1944 ok(refcount == expected_refcount, "Got refcount %u for test \"%s\" %u, %u, expected %u.\n",
1945 refcount, test_name, i, j, expected_refcount);
1949 expected_refcount = 0;
1950 if (IsEqualGUID(refcount_iid, tests[i].refcount_iid))
1951 ++expected_refcount;
1952 refcount = IUnknown_Release(iface1);
1953 ok(refcount == expected_refcount, "Got refcount %u for test \"%s\" %u, expected %u.\n",
1954 refcount, test_name, i, expected_refcount);
1959 static void test_surface_qi(void)
1961 static const struct qi_test tests[] =
1963 {&IID_IDirect3DTexture2, NULL, E_NOINTERFACE},
1964 {&IID_IDirect3DTexture, NULL, E_NOINTERFACE},
1965 {&IID_IDirectDrawGammaControl, &IID_IDirectDrawGammaControl, S_OK },
1966 {&IID_IDirectDrawColorControl, NULL, E_NOINTERFACE},
1967 {&IID_IDirectDrawSurface7, &IID_IDirectDrawSurface7, S_OK },
1968 {&IID_IDirectDrawSurface4, &IID_IDirectDrawSurface4, S_OK },
1969 {&IID_IDirectDrawSurface3, &IID_IDirectDrawSurface3, S_OK },
1970 {&IID_IDirectDrawSurface2, &IID_IDirectDrawSurface2, S_OK },
1971 {&IID_IDirectDrawSurface, &IID_IDirectDrawSurface, S_OK },
1972 {&IID_IDirect3DDevice7, NULL, E_NOINTERFACE},
1973 {&IID_IDirect3DDevice3, NULL, E_NOINTERFACE},
1974 {&IID_IDirect3DDevice2, NULL, E_NOINTERFACE},
1975 {&IID_IDirect3DDevice, NULL, E_NOINTERFACE},
1976 {&IID_IDirect3DRampDevice, NULL, E_NOINTERFACE},
1977 {&IID_IDirect3DRGBDevice, NULL, E_NOINTERFACE},
1978 {&IID_IDirect3DHALDevice, NULL, E_NOINTERFACE},
1979 {&IID_IDirect3DMMXDevice, NULL, E_NOINTERFACE},
1980 {&IID_IDirect3DRefDevice, NULL, E_NOINTERFACE},
1981 {&IID_IDirect3DTnLHalDevice, NULL, E_NOINTERFACE},
1982 {&IID_IDirect3DNullDevice, NULL, E_NOINTERFACE},
1983 {&IID_IDirect3D7, NULL, E_NOINTERFACE},
1984 {&IID_IDirect3D3, NULL, E_NOINTERFACE},
1985 {&IID_IDirect3D2, NULL, E_NOINTERFACE},
1986 {&IID_IDirect3D, NULL, E_NOINTERFACE},
1987 {&IID_IDirectDraw7, NULL, E_NOINTERFACE},
1988 {&IID_IDirectDraw4, NULL, E_NOINTERFACE},
1989 {&IID_IDirectDraw3, NULL, E_NOINTERFACE},
1990 {&IID_IDirectDraw2, NULL, E_NOINTERFACE},
1991 {&IID_IDirectDraw, NULL, E_NOINTERFACE},
1992 {&IID_IDirect3DLight, NULL, E_NOINTERFACE},
1993 {&IID_IDirect3DMaterial, NULL, E_NOINTERFACE},
1994 {&IID_IDirect3DMaterial2, NULL, E_NOINTERFACE},
1995 {&IID_IDirect3DMaterial3, NULL, E_NOINTERFACE},
1996 {&IID_IDirect3DExecuteBuffer, NULL, E_NOINTERFACE},
1997 {&IID_IDirect3DViewport, NULL, E_NOINTERFACE},
1998 {&IID_IDirect3DViewport2, NULL, E_NOINTERFACE},
1999 {&IID_IDirect3DViewport3, NULL, E_NOINTERFACE},
2000 {&IID_IDirect3DVertexBuffer, NULL, E_NOINTERFACE},
2001 {&IID_IDirect3DVertexBuffer7, NULL, E_NOINTERFACE},
2002 {&IID_IDirectDrawPalette, NULL, E_NOINTERFACE},
2003 {&IID_IDirectDrawClipper, NULL, E_NOINTERFACE},
2004 {&IID_IUnknown, &IID_IDirectDrawSurface, S_OK },
2005 {NULL, NULL, E_INVALIDARG },
2008 IDirectDrawSurface7 *surface;
2009 DDSURFACEDESC2 surface_desc;
2010 IDirect3DDevice7 *device;
2011 IDirectDraw7 *ddraw;
2012 HWND window;
2013 HRESULT hr;
2015 window = create_window();
2016 /* Try to create a D3D device to see if the ddraw implementation supports
2017 * D3D. 64-bit ddraw in particular doesn't seem to support D3D, and
2018 * doesn't support e.g. the IDirect3DTexture interfaces. */
2019 if (!(device = create_device(window, DDSCL_NORMAL)))
2021 skip("Failed to create a 3D device, skipping test.\n");
2022 DestroyWindow(window);
2023 return;
2025 IDirect3DDevice_Release(device);
2026 ddraw = create_ddraw();
2027 ok(!!ddraw, "Failed to create a ddraw object.\n");
2028 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2029 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
2031 memset(&surface_desc, 0, sizeof(surface_desc));
2032 surface_desc.dwSize = sizeof(surface_desc);
2033 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
2034 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
2035 surface_desc.dwWidth = 512;
2036 surface_desc.dwHeight = 512;
2037 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, (IDirectDrawSurface7 **)0xdeadbeef, NULL);
2038 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2039 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
2040 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
2042 test_qi("surface_qi", (IUnknown *)surface, &IID_IDirectDrawSurface7, tests, ARRAY_SIZE(tests));
2044 IDirectDrawSurface7_Release(surface);
2045 IDirectDraw7_Release(ddraw);
2046 DestroyWindow(window);
2049 static void test_device_qi(void)
2051 static const struct qi_test tests[] =
2053 {&IID_IDirect3DTexture2, NULL, E_NOINTERFACE},
2054 {&IID_IDirect3DTexture, NULL, E_NOINTERFACE},
2055 {&IID_IDirectDrawGammaControl, NULL, E_NOINTERFACE},
2056 {&IID_IDirectDrawColorControl, NULL, E_NOINTERFACE},
2057 {&IID_IDirectDrawSurface7, NULL, E_NOINTERFACE},
2058 {&IID_IDirectDrawSurface4, NULL, E_NOINTERFACE},
2059 {&IID_IDirectDrawSurface3, NULL, E_NOINTERFACE},
2060 {&IID_IDirectDrawSurface2, NULL, E_NOINTERFACE},
2061 {&IID_IDirectDrawSurface, NULL, E_NOINTERFACE},
2062 {&IID_IDirect3DDevice7, &IID_IDirect3DDevice7, S_OK },
2063 {&IID_IDirect3DDevice3, NULL, E_NOINTERFACE},
2064 {&IID_IDirect3DDevice2, NULL, E_NOINTERFACE},
2065 {&IID_IDirect3DDevice, NULL, E_NOINTERFACE},
2066 {&IID_IDirect3DRampDevice, NULL, E_NOINTERFACE},
2067 {&IID_IDirect3DRGBDevice, NULL, E_NOINTERFACE},
2068 {&IID_IDirect3DHALDevice, NULL, E_NOINTERFACE},
2069 {&IID_IDirect3DMMXDevice, NULL, E_NOINTERFACE},
2070 {&IID_IDirect3DRefDevice, NULL, E_NOINTERFACE},
2071 {&IID_IDirect3DTnLHalDevice, NULL, E_NOINTERFACE},
2072 {&IID_IDirect3DNullDevice, NULL, E_NOINTERFACE},
2073 {&IID_IDirect3D7, NULL, E_NOINTERFACE},
2074 {&IID_IDirect3D3, NULL, E_NOINTERFACE},
2075 {&IID_IDirect3D2, NULL, E_NOINTERFACE},
2076 {&IID_IDirect3D, NULL, E_NOINTERFACE},
2077 {&IID_IDirectDraw7, NULL, E_NOINTERFACE},
2078 {&IID_IDirectDraw4, NULL, E_NOINTERFACE},
2079 {&IID_IDirectDraw3, NULL, E_NOINTERFACE},
2080 {&IID_IDirectDraw2, NULL, E_NOINTERFACE},
2081 {&IID_IDirectDraw, NULL, E_NOINTERFACE},
2082 {&IID_IDirect3DLight, NULL, E_NOINTERFACE},
2083 {&IID_IDirect3DMaterial, NULL, E_NOINTERFACE},
2084 {&IID_IDirect3DMaterial2, NULL, E_NOINTERFACE},
2085 {&IID_IDirect3DMaterial3, NULL, E_NOINTERFACE},
2086 {&IID_IDirect3DExecuteBuffer, NULL, E_NOINTERFACE},
2087 {&IID_IDirect3DViewport, NULL, E_NOINTERFACE},
2088 {&IID_IDirect3DViewport2, NULL, E_NOINTERFACE},
2089 {&IID_IDirect3DViewport3, NULL, E_NOINTERFACE},
2090 {&IID_IDirect3DVertexBuffer, NULL, E_NOINTERFACE},
2091 {&IID_IDirect3DVertexBuffer7, NULL, E_NOINTERFACE},
2092 {&IID_IDirectDrawPalette, NULL, E_NOINTERFACE},
2093 {&IID_IDirectDrawClipper, NULL, E_NOINTERFACE},
2094 {&IID_IUnknown, &IID_IDirect3DDevice7, S_OK },
2097 IDirect3DDevice7 *device;
2098 HWND window;
2100 window = create_window();
2101 if (!(device = create_device(window, DDSCL_NORMAL)))
2103 skip("Failed to create a 3D device, skipping test.\n");
2104 DestroyWindow(window);
2105 return;
2108 test_qi("device_qi", (IUnknown *)device, &IID_IDirect3DDevice7, tests, ARRAY_SIZE(tests));
2110 IDirect3DDevice7_Release(device);
2111 DestroyWindow(window);
2114 static void test_wndproc(void)
2116 LONG_PTR proc, ddraw_proc;
2117 IDirectDraw7 *ddraw;
2118 WNDCLASSA wc = {0};
2119 HWND window;
2120 HRESULT hr;
2121 ULONG ref;
2123 static struct message messages[] =
2125 {WM_WINDOWPOSCHANGING, FALSE, 0},
2126 {WM_MOVE, FALSE, 0},
2127 {WM_SIZE, FALSE, 0},
2128 {WM_WINDOWPOSCHANGING, FALSE, 0},
2129 {WM_ACTIVATE, FALSE, 0},
2130 {WM_SETFOCUS, FALSE, 0},
2131 {0, FALSE, 0},
2134 /* DDSCL_EXCLUSIVE replaces the window's window proc. */
2135 ddraw = create_ddraw();
2136 ok(!!ddraw, "Failed to create a ddraw object.\n");
2138 wc.lpfnWndProc = test_proc;
2139 wc.lpszClassName = "ddraw_test_wndproc_wc";
2140 ok(RegisterClassA(&wc), "Failed to register window class.\n");
2142 window = CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
2143 WS_MAXIMIZE | WS_CAPTION , 0, 0, 640, 480, 0, 0, 0, 0);
2145 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2146 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2147 (LONG_PTR)test_proc, proc);
2148 expect_messages = messages;
2149 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2150 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2151 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2152 expect_messages = NULL;
2153 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2154 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
2155 (LONG_PTR)test_proc, proc);
2156 ref = IDirectDraw7_Release(ddraw);
2157 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2158 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2159 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2160 (LONG_PTR)test_proc, proc);
2162 /* DDSCL_NORMAL doesn't. */
2163 ddraw = create_ddraw();
2164 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2165 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2166 (LONG_PTR)test_proc, proc);
2167 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL | DDSCL_FULLSCREEN);
2168 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2169 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2170 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2171 (LONG_PTR)test_proc, proc);
2172 ref = IDirectDraw7_Release(ddraw);
2173 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2174 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2175 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2176 (LONG_PTR)test_proc, proc);
2178 /* The original window proc is only restored by ddraw if the current
2179 * window proc matches the one ddraw set. This also affects switching
2180 * from DDSCL_NORMAL to DDSCL_EXCLUSIVE. */
2181 ddraw = create_ddraw();
2182 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2183 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2184 (LONG_PTR)test_proc, proc);
2185 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2186 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2187 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2188 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
2189 (LONG_PTR)test_proc, proc);
2190 ddraw_proc = proc;
2191 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2192 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2193 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2194 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2195 (LONG_PTR)test_proc, proc);
2196 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2197 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2198 proc = SetWindowLongPtrA(window, GWLP_WNDPROC, (LONG_PTR)DefWindowProcA);
2199 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
2200 (LONG_PTR)test_proc, proc);
2201 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2202 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2203 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2204 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#lx, got %#lx.\n",
2205 (LONG_PTR)DefWindowProcA, proc);
2206 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2207 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2208 proc = SetWindowLongPtrA(window, GWLP_WNDPROC, (LONG_PTR)ddraw_proc);
2209 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#lx, got %#lx.\n",
2210 (LONG_PTR)DefWindowProcA, proc);
2211 ref = IDirectDraw7_Release(ddraw);
2212 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2213 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2214 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2215 (LONG_PTR)test_proc, proc);
2217 ddraw = create_ddraw();
2218 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2219 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2220 (LONG_PTR)test_proc, proc);
2221 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2222 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2223 proc = SetWindowLongPtrA(window, GWLP_WNDPROC, (LONG_PTR)DefWindowProcA);
2224 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
2225 (LONG_PTR)test_proc, proc);
2226 ref = IDirectDraw7_Release(ddraw);
2227 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2228 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2229 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#lx, got %#lx.\n",
2230 (LONG_PTR)DefWindowProcA, proc);
2232 fix_wndproc(window, (LONG_PTR)test_proc);
2233 expect_messages = NULL;
2234 DestroyWindow(window);
2235 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL));
2238 static void test_window_style(void)
2240 LONG style, exstyle, tmp, expected_style;
2241 RECT fullscreen_rect, r;
2242 IDirectDraw7 *ddraw;
2243 HWND window;
2244 HRESULT hr;
2245 ULONG ref;
2246 BOOL ret;
2248 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
2249 0, 0, 100, 100, 0, 0, 0, 0);
2250 ddraw = create_ddraw();
2251 ok(!!ddraw, "Failed to create a ddraw object.\n");
2253 style = GetWindowLongA(window, GWL_STYLE);
2254 exstyle = GetWindowLongA(window, GWL_EXSTYLE);
2255 SetRect(&fullscreen_rect, 0, 0, registry_mode.dmPelsWidth, registry_mode.dmPelsHeight);
2257 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2258 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2260 tmp = GetWindowLongA(window, GWL_STYLE);
2261 todo_wine ok(tmp == style, "Expected window style %#x, got %#x.\n", style, tmp);
2262 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2263 todo_wine ok(tmp == exstyle, "Expected window extended style %#x, got %#x.\n", exstyle, tmp);
2265 GetWindowRect(window, &r);
2266 ok(EqualRect(&r, &fullscreen_rect), "Expected %s, got %s.\n",
2267 wine_dbgstr_rect(&fullscreen_rect), wine_dbgstr_rect(&r));
2268 GetClientRect(window, &r);
2269 todo_wine ok(!EqualRect(&r, &fullscreen_rect), "Client rect and window rect are equal.\n");
2271 ret = SetForegroundWindow(GetDesktopWindow());
2272 ok(ret, "Failed to set foreground window.\n");
2274 tmp = GetWindowLongA(window, GWL_STYLE);
2275 todo_wine ok(tmp == style, "Expected window style %#x, got %#x.\n", style, tmp);
2276 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2277 todo_wine ok(tmp == exstyle, "Expected window extended style %#x, got %#x.\n", exstyle, tmp);
2279 ret = SetForegroundWindow(window);
2280 ok(ret, "Failed to set foreground window.\n");
2281 /* Windows 7 (but not Vista and XP) shows the window when it receives focus. Hide it again,
2282 * the next tests expect this. */
2283 ShowWindow(window, SW_HIDE);
2285 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2286 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2288 tmp = GetWindowLongA(window, GWL_STYLE);
2289 todo_wine ok(tmp == style, "Expected window style %#x, got %#x.\n", style, tmp);
2290 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2291 todo_wine ok(tmp == exstyle, "Expected window extended style %#x, got %#x.\n", exstyle, tmp);
2293 ShowWindow(window, SW_SHOW);
2294 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2295 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2297 tmp = GetWindowLongA(window, GWL_STYLE);
2298 expected_style = style | WS_VISIBLE;
2299 todo_wine ok(tmp == expected_style, "Expected window style %#x, got %#x.\n", expected_style, tmp);
2300 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2301 expected_style = exstyle | WS_EX_TOPMOST;
2302 todo_wine ok(tmp == expected_style, "Expected window extended style %#x, got %#x.\n", expected_style, tmp);
2304 ret = SetForegroundWindow(GetDesktopWindow());
2305 ok(ret, "Failed to set foreground window.\n");
2306 tmp = GetWindowLongA(window, GWL_STYLE);
2307 expected_style = style | WS_VISIBLE | WS_MINIMIZE;
2308 todo_wine ok(tmp == expected_style, "Expected window style %#x, got %#x.\n", expected_style, tmp);
2309 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2310 expected_style = exstyle | WS_EX_TOPMOST;
2311 todo_wine ok(tmp == expected_style, "Expected window extended style %#x, got %#x.\n", expected_style, tmp);
2313 ref = IDirectDraw7_Release(ddraw);
2314 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2316 DestroyWindow(window);
2319 static void test_redundant_mode_set(void)
2321 DDSURFACEDESC2 surface_desc = {0};
2322 IDirectDraw7 *ddraw;
2323 RECT q, r, s;
2324 HWND window;
2325 HRESULT hr;
2326 ULONG ref;
2328 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
2329 0, 0, 100, 100, 0, 0, 0, 0);
2330 ddraw = create_ddraw();
2331 ok(!!ddraw, "Failed to create a ddraw object.\n");
2332 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2333 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2335 surface_desc.dwSize = sizeof(surface_desc);
2336 hr = IDirectDraw7_GetDisplayMode(ddraw, &surface_desc);
2337 ok(SUCCEEDED(hr), "GetDisplayMode failed, hr %#x.\n", hr);
2339 hr = IDirectDraw7_SetDisplayMode(ddraw, surface_desc.dwWidth, surface_desc.dwHeight,
2340 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount, 0, 0);
2341 ok(SUCCEEDED(hr), "SetDisplayMode failed, hr %#x.\n", hr);
2343 GetWindowRect(window, &q);
2344 r = q;
2345 r.right /= 2;
2346 r.bottom /= 2;
2347 SetWindowPos(window, HWND_TOP, r.left, r.top, r.right, r.bottom, 0);
2348 GetWindowRect(window, &s);
2349 ok(EqualRect(&r, &s), "Expected %s, got %s.\n", wine_dbgstr_rect(&r), wine_dbgstr_rect(&s));
2351 hr = IDirectDraw7_SetDisplayMode(ddraw, surface_desc.dwWidth, surface_desc.dwHeight,
2352 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount, 0, 0);
2353 ok(SUCCEEDED(hr), "SetDisplayMode failed, hr %#x.\n", hr);
2355 GetWindowRect(window, &s);
2356 ok(EqualRect(&r, &s) || broken(EqualRect(&q, &s) /* Windows 10 */),
2357 "Expected %s, got %s.\n", wine_dbgstr_rect(&r), wine_dbgstr_rect(&s));
2359 ref = IDirectDraw7_Release(ddraw);
2360 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2362 DestroyWindow(window);
2365 static SIZE screen_size, screen_size2;
2367 static LRESULT CALLBACK mode_set_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
2369 if (message == WM_SIZE)
2371 screen_size.cx = GetSystemMetrics(SM_CXSCREEN);
2372 screen_size.cy = GetSystemMetrics(SM_CYSCREEN);
2375 return test_proc(hwnd, message, wparam, lparam);
2378 static LRESULT CALLBACK mode_set_proc2(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
2380 if (message == WM_SIZE)
2382 screen_size2.cx = GetSystemMetrics(SM_CXSCREEN);
2383 screen_size2.cy = GetSystemMetrics(SM_CYSCREEN);
2386 return test_proc(hwnd, message, wparam, lparam);
2389 struct test_coop_level_mode_set_enum_param
2391 DWORD ddraw_width, ddraw_height, user32_width, user32_height;
2394 static HRESULT CALLBACK test_coop_level_mode_set_enum_cb(DDSURFACEDESC2 *surface_desc, void *context)
2396 struct test_coop_level_mode_set_enum_param *param = context;
2398 if (U1(U4(*surface_desc).ddpfPixelFormat).dwRGBBitCount != registry_mode.dmBitsPerPel)
2399 return DDENUMRET_OK;
2400 if (surface_desc->dwWidth == registry_mode.dmPelsWidth
2401 && surface_desc->dwHeight == registry_mode.dmPelsHeight)
2402 return DDENUMRET_OK;
2404 if (!param->ddraw_width)
2406 param->ddraw_width = surface_desc->dwWidth;
2407 param->ddraw_height = surface_desc->dwHeight;
2408 return DDENUMRET_OK;
2410 if (surface_desc->dwWidth == param->ddraw_width && surface_desc->dwHeight == param->ddraw_height)
2411 return DDENUMRET_OK;
2413 param->user32_width = surface_desc->dwWidth;
2414 param->user32_height = surface_desc->dwHeight;
2415 return DDENUMRET_CANCEL;
2418 static void test_coop_level_mode_set(void)
2420 IDirectDrawSurface7 *primary;
2421 RECT registry_rect, ddraw_rect, user32_rect, r;
2422 IDirectDraw7 *ddraw;
2423 DDSURFACEDESC2 ddsd;
2424 WNDCLASSA wc = {0};
2425 HWND window, window2;
2426 HRESULT hr;
2427 ULONG ref;
2428 MSG msg;
2429 struct test_coop_level_mode_set_enum_param param;
2430 DEVMODEW devmode;
2431 BOOL ret;
2432 LONG change_ret;
2434 static const struct message exclusive_messages[] =
2436 {WM_WINDOWPOSCHANGING, FALSE, 0},
2437 {WM_WINDOWPOSCHANGED, FALSE, 0},
2438 {WM_SIZE, FALSE, 0},
2439 {WM_DISPLAYCHANGE, FALSE, 0},
2440 {0, FALSE, 0},
2442 static const struct message exclusive_focus_loss_messages[] =
2444 {WM_ACTIVATE, TRUE, WA_INACTIVE},
2445 {WM_DISPLAYCHANGE, FALSE, 0},
2446 {WM_WINDOWPOSCHANGING, FALSE, 0},
2447 /* Like d3d8 and d3d9 ddraw seems to use SW_SHOWMINIMIZED instead of
2448 * SW_MINIMIZED, causing a recursive window activation that does not
2449 * produce the same result in Wine yet. Ignore the difference for now.
2450 * {WM_ACTIVATE, TRUE, 0x200000 | WA_ACTIVE}, */
2451 {WM_WINDOWPOSCHANGED, FALSE, 0},
2452 {WM_MOVE, FALSE, 0},
2453 {WM_SIZE, TRUE, SIZE_MINIMIZED},
2454 {WM_ACTIVATEAPP, TRUE, FALSE},
2455 {0, FALSE, 0},
2457 static const struct message exclusive_focus_restore_messages[] =
2459 {WM_WINDOWPOSCHANGING, FALSE, 0}, /* From the ShowWindow(SW_RESTORE). */
2460 {WM_WINDOWPOSCHANGING, FALSE, 0}, /* Generated by ddraw, matches d3d9 behavior. */
2461 {WM_WINDOWPOSCHANGED, FALSE, 0}, /* Matching previous message. */
2462 {WM_SIZE, FALSE, 0}, /* DefWindowProc. */
2463 {WM_DISPLAYCHANGE, FALSE, 0}, /* Ddraw restores mode. */
2464 /* Native redundantly sets the window size here. */
2465 {WM_ACTIVATEAPP, TRUE, TRUE}, /* End of ddraw's hooks. */
2466 {WM_WINDOWPOSCHANGED, FALSE, 0}, /* Matching the one from ShowWindow. */
2467 {WM_MOVE, FALSE, 0}, /* DefWindowProc. */
2468 {WM_SIZE, TRUE, SIZE_RESTORED}, /* DefWindowProc. */
2469 {0, FALSE, 0},
2471 static const struct message sc_restore_messages[] =
2473 {WM_SYSCOMMAND, TRUE, SC_RESTORE},
2474 {WM_WINDOWPOSCHANGING, FALSE, 0},
2475 {WM_WINDOWPOSCHANGED, FALSE, 0},
2476 {WM_SIZE, TRUE, SIZE_RESTORED},
2477 {0, FALSE, 0},
2479 static const struct message sc_minimize_messages[] =
2481 {WM_SYSCOMMAND, TRUE, SC_MINIMIZE},
2482 {WM_WINDOWPOSCHANGING, FALSE, 0},
2483 {WM_WINDOWPOSCHANGED, FALSE, 0},
2484 {WM_SIZE, TRUE, SIZE_MINIMIZED},
2485 {0, FALSE, 0},
2487 static const struct message sc_maximize_messages[] =
2489 {WM_SYSCOMMAND, TRUE, SC_MAXIMIZE},
2490 {WM_WINDOWPOSCHANGING, FALSE, 0},
2491 {WM_WINDOWPOSCHANGED, FALSE, 0},
2492 {WM_SIZE, TRUE, SIZE_MAXIMIZED},
2493 {0, FALSE, 0},
2496 static const struct message normal_messages[] =
2498 {WM_DISPLAYCHANGE, FALSE, 0},
2499 {0, FALSE, 0},
2502 ddraw = create_ddraw();
2503 ok(!!ddraw, "Failed to create a ddraw object.\n");
2505 memset(&param, 0, sizeof(param));
2506 hr = IDirectDraw7_EnumDisplayModes(ddraw, 0, NULL, &param, test_coop_level_mode_set_enum_cb);
2507 ok(SUCCEEDED(hr), "Failed to enumerate display mode, hr %#x.\n", hr);
2508 ref = IDirectDraw7_Release(ddraw);
2509 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2511 if (!param.user32_height)
2513 skip("Fewer than 3 different modes supported, skipping mode restore test.\n");
2514 return;
2517 SetRect(&registry_rect, 0, 0, registry_mode.dmPelsWidth, registry_mode.dmPelsHeight);
2518 SetRect(&ddraw_rect, 0, 0, param.ddraw_width, param.ddraw_height);
2519 SetRect(&user32_rect, 0, 0, param.user32_width, param.user32_height);
2521 memset(&devmode, 0, sizeof(devmode));
2522 devmode.dmSize = sizeof(devmode);
2523 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
2524 devmode.dmPelsWidth = param.user32_width;
2525 devmode.dmPelsHeight = param.user32_height;
2526 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
2527 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2529 ddraw = create_ddraw();
2530 ok(!!ddraw, "Failed to create a ddraw object.\n");
2532 wc.lpfnWndProc = mode_set_proc;
2533 wc.lpszClassName = "ddraw_test_wndproc_wc";
2534 ok(RegisterClassA(&wc), "Failed to register window class.\n");
2535 wc.lpfnWndProc = mode_set_proc2;
2536 wc.lpszClassName = "ddraw_test_wndproc_wc2";
2537 ok(RegisterClassA(&wc), "Failed to register window class.\n");
2539 window = CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test", WS_OVERLAPPEDWINDOW,
2540 0, 0, 100, 100, 0, 0, 0, 0);
2541 window2 = CreateWindowA("ddraw_test_wndproc_wc2", "ddraw_test", WS_OVERLAPPEDWINDOW,
2542 0, 0, 100, 100, 0, 0, 0, 0);
2544 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2545 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2547 GetWindowRect(window, &r);
2548 ok(EqualRect(&r, &user32_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&user32_rect),
2549 wine_dbgstr_rect(&r));
2551 memset(&ddsd, 0, sizeof(ddsd));
2552 ddsd.dwSize = sizeof(ddsd);
2553 ddsd.dwFlags = DDSD_CAPS;
2554 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2556 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2557 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2558 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2559 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2560 ok(ddsd.dwWidth == param.user32_width, "Expected surface width %u, got %u.\n",
2561 param.user32_width, ddsd.dwWidth);
2562 ok(ddsd.dwHeight == param.user32_height, "Expected surface height %u, got %u.\n",
2563 param.user32_height, ddsd.dwHeight);
2565 GetWindowRect(window, &r);
2566 ok(EqualRect(&r, &user32_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&user32_rect),
2567 wine_dbgstr_rect(&r));
2569 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2570 expect_messages = exclusive_messages;
2571 screen_size.cx = 0;
2572 screen_size.cy = 0;
2574 hr = IDirectDrawSurface7_IsLost(primary);
2575 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
2576 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
2577 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2578 hr = IDirectDrawSurface7_IsLost(primary);
2579 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2581 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2582 expect_messages = NULL;
2583 ok(screen_size.cx == param.ddraw_width && screen_size.cy == param.ddraw_height,
2584 "Expected screen size %ux%u, got %ux%u.\n",
2585 param.ddraw_width, param.ddraw_height, screen_size.cx, screen_size.cy);
2587 GetWindowRect(window, &r);
2588 ok(EqualRect(&r, &ddraw_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect),
2589 wine_dbgstr_rect(&r));
2591 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2592 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2593 ok(ddsd.dwWidth == param.user32_width, "Expected surface width %u, got %u.\n",
2594 param.user32_width, ddsd.dwWidth);
2595 ok(ddsd.dwHeight == param.user32_height, "Expected surface height %u, got %u.\n",
2596 param.user32_height, ddsd.dwHeight);
2597 IDirectDrawSurface7_Release(primary);
2599 memset(&ddsd, 0, sizeof(ddsd));
2600 ddsd.dwSize = sizeof(ddsd);
2601 ddsd.dwFlags = DDSD_CAPS;
2602 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2604 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2605 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2606 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2607 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2608 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2609 param.ddraw_width, ddsd.dwWidth);
2610 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2611 param.ddraw_height, ddsd.dwHeight);
2613 GetWindowRect(window, &r);
2614 ok(EqualRect(&r, &ddraw_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect),
2615 wine_dbgstr_rect(&r));
2617 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2618 expect_messages = exclusive_messages;
2619 screen_size.cx = 0;
2620 screen_size.cy = 0;
2622 hr = IDirectDrawSurface7_IsLost(primary);
2623 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
2624 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
2625 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2626 hr = IDirectDrawSurface7_IsLost(primary);
2627 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2629 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2630 expect_messages = NULL;
2631 ok(screen_size.cx == param.user32_width && screen_size.cy == param.user32_height,
2632 "Expected screen size %ux%u, got %ux%u.\n",
2633 param.user32_width, param.user32_height, screen_size.cx, screen_size.cy);
2635 GetWindowRect(window, &r);
2636 ok(EqualRect(&r, &user32_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&user32_rect),
2637 wine_dbgstr_rect(&r));
2639 expect_messages = exclusive_focus_loss_messages;
2640 ret = SetForegroundWindow(GetDesktopWindow());
2641 ok(ret, "Failed to set foreground window.\n");
2642 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2643 memset(&devmode, 0, sizeof(devmode));
2644 devmode.dmSize = sizeof(devmode);
2645 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
2646 ok(ret, "Failed to get display mode.\n");
2647 ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth
2648 && devmode.dmPelsHeight == registry_mode.dmPelsHeight, "Got unexpect screen size %ux%u.\n",
2649 devmode.dmPelsWidth, devmode.dmPelsHeight);
2651 expect_messages = exclusive_focus_restore_messages;
2652 ShowWindow(window, SW_RESTORE);
2653 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2655 GetWindowRect(window, &r);
2656 ok(EqualRect(&r, &ddraw_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect),
2657 wine_dbgstr_rect(&r));
2658 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
2659 ok(ret, "Failed to get display mode.\n");
2660 ok(devmode.dmPelsWidth == param.ddraw_width
2661 && devmode.dmPelsHeight == param.ddraw_height, "Got unexpect screen size %ux%u.\n",
2662 devmode.dmPelsWidth, devmode.dmPelsHeight);
2664 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2665 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2666 /* Normally the primary should be restored here. Unfortunately this causes the
2667 * GetSurfaceDesc call after the next display mode change to crash on the Windows 8
2668 * testbot. Another Restore call would presumably avoid the crash, but it also moots
2669 * the point of the GetSurfaceDesc call. */
2671 expect_messages = sc_minimize_messages;
2672 SendMessageA(window, WM_SYSCOMMAND, SC_MINIMIZE, 0);
2673 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2674 expect_messages = NULL;
2676 expect_messages = sc_restore_messages;
2677 SendMessageA(window, WM_SYSCOMMAND, SC_RESTORE, 0);
2678 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2679 expect_messages = NULL;
2681 expect_messages = sc_maximize_messages;
2682 SendMessageA(window, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
2683 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2684 expect_messages = NULL;
2686 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2687 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2689 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2690 expect_messages = exclusive_messages;
2691 screen_size.cx = 0;
2692 screen_size.cy = 0;
2694 hr = IDirectDrawSurface7_IsLost(primary);
2695 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2696 hr = IDirectDraw7_RestoreDisplayMode(ddraw);
2697 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
2698 hr = IDirectDrawSurface7_IsLost(primary);
2699 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2701 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2702 expect_messages = NULL;
2703 ok(screen_size.cx == registry_mode.dmPelsWidth
2704 && screen_size.cy == registry_mode.dmPelsHeight,
2705 "Expected screen size %ux%u, got %ux%u.\n",
2706 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight, screen_size.cx, screen_size.cy);
2708 GetWindowRect(window, &r);
2709 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2710 wine_dbgstr_rect(&r));
2712 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2713 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2714 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2715 param.ddraw_width, ddsd.dwWidth);
2716 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2717 param.ddraw_height, ddsd.dwHeight);
2718 IDirectDrawSurface7_Release(primary);
2720 /* For Wine. */
2721 change_ret = ChangeDisplaySettingsW(NULL, CDS_FULLSCREEN);
2722 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2724 memset(&ddsd, 0, sizeof(ddsd));
2725 ddsd.dwSize = sizeof(ddsd);
2726 ddsd.dwFlags = DDSD_CAPS;
2727 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2729 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2730 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2731 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2732 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2733 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2734 registry_mode.dmPelsWidth, ddsd.dwWidth);
2735 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2736 registry_mode.dmPelsHeight, ddsd.dwHeight);
2738 GetWindowRect(window, &r);
2739 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2740 wine_dbgstr_rect(&r));
2742 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2743 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2745 GetWindowRect(window, &r);
2746 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2747 wine_dbgstr_rect(&r));
2749 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2750 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2751 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2752 registry_mode.dmPelsWidth, ddsd.dwWidth);
2753 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2754 registry_mode.dmPelsHeight, ddsd.dwHeight);
2755 IDirectDrawSurface7_Release(primary);
2757 memset(&ddsd, 0, sizeof(ddsd));
2758 ddsd.dwSize = sizeof(ddsd);
2759 ddsd.dwFlags = DDSD_CAPS;
2760 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2762 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2763 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2764 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2765 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2766 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2767 registry_mode.dmPelsWidth, ddsd.dwWidth);
2768 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2769 registry_mode.dmPelsHeight, ddsd.dwHeight);
2771 GetWindowRect(window, &r);
2772 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2773 wine_dbgstr_rect(&r));
2775 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2776 expect_messages = normal_messages;
2777 screen_size.cx = 0;
2778 screen_size.cy = 0;
2780 hr = IDirectDrawSurface7_IsLost(primary);
2781 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
2782 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
2783 devmode.dmPelsWidth = param.user32_width;
2784 devmode.dmPelsHeight = param.user32_height;
2785 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
2786 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2787 hr = IDirectDrawSurface7_IsLost(primary);
2788 todo_wine ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2790 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2791 expect_messages = NULL;
2792 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2794 GetWindowRect(window, &r);
2795 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2796 wine_dbgstr_rect(&r));
2798 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2799 expect_messages = normal_messages;
2800 screen_size.cx = 0;
2801 screen_size.cy = 0;
2803 hr = IDirectDrawSurface7_Restore(primary);
2804 ok(hr == DDERR_WRONGMODE, "Got unexpected hr %#x.\n", hr);
2805 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
2806 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2807 hr = IDirectDrawSurface7_Restore(primary);
2808 ok(hr == DDERR_WRONGMODE, "Got unexpected hr %#x.\n", hr);
2809 hr = IDirectDrawSurface7_IsLost(primary);
2810 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2812 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2813 expect_messages = NULL;
2814 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2816 GetWindowRect(window, &r);
2817 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2818 wine_dbgstr_rect(&r));
2820 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2821 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2822 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2823 registry_mode.dmPelsWidth, ddsd.dwWidth);
2824 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2825 registry_mode.dmPelsHeight, ddsd.dwHeight);
2826 IDirectDrawSurface7_Release(primary);
2828 memset(&ddsd, 0, sizeof(ddsd));
2829 ddsd.dwSize = sizeof(ddsd);
2830 ddsd.dwFlags = DDSD_CAPS;
2831 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2833 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2834 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2835 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2836 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2837 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2838 param.ddraw_width, ddsd.dwWidth);
2839 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2840 param.ddraw_height, ddsd.dwHeight);
2842 GetWindowRect(window, &r);
2843 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2844 wine_dbgstr_rect(&r));
2846 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2847 expect_messages = normal_messages;
2848 screen_size.cx = 0;
2849 screen_size.cy = 0;
2851 hr = IDirectDrawSurface7_IsLost(primary);
2852 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
2853 hr = IDirectDraw7_RestoreDisplayMode(ddraw);
2854 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
2855 hr = IDirectDrawSurface7_IsLost(primary);
2856 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2858 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2859 expect_messages = NULL;
2860 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2862 GetWindowRect(window, &r);
2863 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2864 wine_dbgstr_rect(&r));
2866 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2867 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2868 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2869 param.ddraw_width, ddsd.dwWidth);
2870 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2871 param.ddraw_height, ddsd.dwHeight);
2872 IDirectDrawSurface7_Release(primary);
2874 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
2875 ok(ret, "Failed to get display mode.\n");
2876 ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth
2877 && devmode.dmPelsHeight == registry_mode.dmPelsHeight,
2878 "Expected resolution %ux%u, got %ux%u.\n",
2879 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight,
2880 devmode.dmPelsWidth, devmode.dmPelsHeight);
2881 change_ret = ChangeDisplaySettingsW(NULL, CDS_FULLSCREEN);
2882 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2884 memset(&ddsd, 0, sizeof(ddsd));
2885 ddsd.dwSize = sizeof(ddsd);
2886 ddsd.dwFlags = DDSD_CAPS;
2887 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2889 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2890 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2891 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2892 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2893 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2894 registry_mode.dmPelsWidth, ddsd.dwWidth);
2895 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2896 registry_mode.dmPelsHeight, ddsd.dwHeight);
2898 GetWindowRect(window, &r);
2899 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2900 wine_dbgstr_rect(&r));
2902 /* DDSCL_NORMAL | DDSCL_FULLSCREEN behaves the same as just DDSCL_NORMAL.
2903 * Resizing the window on mode changes is a property of DDSCL_EXCLUSIVE,
2904 * not DDSCL_FULLSCREEN. */
2905 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL | DDSCL_FULLSCREEN);
2906 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2908 GetWindowRect(window, &r);
2909 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2910 wine_dbgstr_rect(&r));
2912 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2913 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2914 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2915 registry_mode.dmPelsWidth, ddsd.dwWidth);
2916 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2917 registry_mode.dmPelsHeight, ddsd.dwHeight);
2918 IDirectDrawSurface7_Release(primary);
2920 memset(&ddsd, 0, sizeof(ddsd));
2921 ddsd.dwSize = sizeof(ddsd);
2922 ddsd.dwFlags = DDSD_CAPS;
2923 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2925 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2926 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2927 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2928 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2929 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2930 registry_mode.dmPelsWidth, ddsd.dwWidth);
2931 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2932 registry_mode.dmPelsHeight, ddsd.dwHeight);
2934 GetWindowRect(window, &r);
2935 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2936 wine_dbgstr_rect(&r));
2938 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2939 expect_messages = normal_messages;
2940 screen_size.cx = 0;
2941 screen_size.cy = 0;
2943 hr = IDirectDrawSurface7_IsLost(primary);
2944 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
2945 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
2946 devmode.dmPelsWidth = param.user32_width;
2947 devmode.dmPelsHeight = param.user32_height;
2948 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
2949 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2950 hr = IDirectDrawSurface7_IsLost(primary);
2951 todo_wine ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2953 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2954 expect_messages = NULL;
2955 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2957 GetWindowRect(window, &r);
2958 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2959 wine_dbgstr_rect(&r));
2961 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2962 expect_messages = normal_messages;
2963 screen_size.cx = 0;
2964 screen_size.cy = 0;
2966 hr = IDirectDrawSurface7_Restore(primary);
2967 ok(hr == DDERR_WRONGMODE, "Got unexpected hr %#x.\n", hr);
2968 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
2969 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2970 hr = IDirectDrawSurface7_Restore(primary);
2971 ok(hr == DDERR_WRONGMODE, "Got unexpected hr %#x.\n", hr);
2972 hr = IDirectDrawSurface7_IsLost(primary);
2973 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2975 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2976 expect_messages = NULL;
2977 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2979 GetWindowRect(window, &r);
2980 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2981 wine_dbgstr_rect(&r));
2983 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2984 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2985 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2986 registry_mode.dmPelsWidth, ddsd.dwWidth);
2987 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2988 registry_mode.dmPelsHeight, ddsd.dwHeight);
2989 IDirectDrawSurface7_Release(primary);
2991 memset(&ddsd, 0, sizeof(ddsd));
2992 ddsd.dwSize = sizeof(ddsd);
2993 ddsd.dwFlags = DDSD_CAPS;
2994 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2996 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2997 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2998 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2999 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
3000 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
3001 param.ddraw_width, ddsd.dwWidth);
3002 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
3003 param.ddraw_height, ddsd.dwHeight);
3005 GetWindowRect(window, &r);
3006 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
3007 wine_dbgstr_rect(&r));
3009 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
3010 expect_messages = normal_messages;
3011 screen_size.cx = 0;
3012 screen_size.cy = 0;
3014 hr = IDirectDrawSurface7_IsLost(primary);
3015 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
3016 hr = IDirectDraw7_RestoreDisplayMode(ddraw);
3017 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
3018 hr = IDirectDrawSurface7_IsLost(primary);
3019 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
3021 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
3022 expect_messages = NULL;
3023 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
3025 GetWindowRect(window, &r);
3026 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
3027 wine_dbgstr_rect(&r));
3029 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
3030 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
3031 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
3032 param.ddraw_width, ddsd.dwWidth);
3033 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
3034 param.ddraw_height, ddsd.dwHeight);
3035 IDirectDrawSurface7_Release(primary);
3037 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
3038 ok(ret, "Failed to get display mode.\n");
3039 ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth
3040 && devmode.dmPelsHeight == registry_mode.dmPelsHeight,
3041 "Expected resolution %ux%u, got %ux%u.\n",
3042 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight,
3043 devmode.dmPelsWidth, devmode.dmPelsHeight);
3044 change_ret = ChangeDisplaySettingsW(NULL, CDS_FULLSCREEN);
3045 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
3047 memset(&ddsd, 0, sizeof(ddsd));
3048 ddsd.dwSize = sizeof(ddsd);
3049 ddsd.dwFlags = DDSD_CAPS;
3050 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3052 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
3053 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
3054 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
3055 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
3056 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
3057 registry_mode.dmPelsWidth, ddsd.dwWidth);
3058 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
3059 registry_mode.dmPelsHeight, ddsd.dwHeight);
3060 IDirectDrawSurface7_Release(primary);
3062 GetWindowRect(window, &r);
3063 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
3064 wine_dbgstr_rect(&r));
3066 /* Changing the coop level from EXCLUSIVE to NORMAL restores the screen resolution */
3067 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | 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 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
3073 expect_messages = exclusive_messages;
3074 screen_size.cx = 0;
3075 screen_size.cy = 0;
3077 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
3078 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3080 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
3081 expect_messages = NULL;
3082 ok(screen_size.cx == registry_mode.dmPelsWidth
3083 && screen_size.cy == registry_mode.dmPelsHeight,
3084 "Expected screen size %ux%u, got %ux%u.\n",
3085 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight,
3086 screen_size.cx, screen_size.cy);
3088 GetWindowRect(window, &r);
3089 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
3090 wine_dbgstr_rect(&r));
3092 memset(&ddsd, 0, sizeof(ddsd));
3093 ddsd.dwSize = sizeof(ddsd);
3094 ddsd.dwFlags = DDSD_CAPS;
3095 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3097 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
3098 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
3099 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
3100 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
3101 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
3102 registry_mode.dmPelsWidth, ddsd.dwWidth);
3103 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
3104 registry_mode.dmPelsHeight, ddsd.dwHeight);
3105 IDirectDrawSurface7_Release(primary);
3107 /* The screen restore is a property of DDSCL_EXCLUSIVE */
3108 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL | DDSCL_FULLSCREEN);
3109 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3110 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
3111 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3113 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
3114 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3116 memset(&ddsd, 0, sizeof(ddsd));
3117 ddsd.dwSize = sizeof(ddsd);
3118 ddsd.dwFlags = DDSD_CAPS;
3119 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3121 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
3122 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
3123 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
3124 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
3125 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
3126 param.ddraw_width, ddsd.dwWidth);
3127 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
3128 param.ddraw_height, ddsd.dwHeight);
3129 IDirectDrawSurface7_Release(primary);
3131 hr = IDirectDraw7_RestoreDisplayMode(ddraw);
3132 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
3134 /* If the window is changed at the same time, messages are sent to the new window. */
3135 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3136 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3137 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
3138 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3140 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
3141 expect_messages = exclusive_messages;
3142 screen_size.cx = 0;
3143 screen_size.cy = 0;
3144 screen_size2.cx = 0;
3145 screen_size2.cy = 0;
3147 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window2, DDSCL_NORMAL);
3148 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3150 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
3151 expect_messages = NULL;
3152 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n",
3153 screen_size.cx, screen_size.cy);
3154 ok(screen_size2.cx == registry_mode.dmPelsWidth && screen_size2.cy == registry_mode.dmPelsHeight,
3155 "Expected screen size 2 %ux%u, got %ux%u.\n",
3156 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight, screen_size2.cx, screen_size2.cy);
3158 GetWindowRect(window, &r);
3159 ok(EqualRect(&r, &ddraw_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect),
3160 wine_dbgstr_rect(&r));
3161 GetWindowRect(window2, &r);
3162 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
3163 wine_dbgstr_rect(&r));
3165 memset(&ddsd, 0, sizeof(ddsd));
3166 ddsd.dwSize = sizeof(ddsd);
3167 ddsd.dwFlags = DDSD_CAPS;
3168 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3170 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
3171 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
3172 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
3173 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
3174 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
3175 registry_mode.dmPelsWidth, ddsd.dwWidth);
3176 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
3177 registry_mode.dmPelsHeight, ddsd.dwHeight);
3178 IDirectDrawSurface7_Release(primary);
3180 ref = IDirectDraw7_Release(ddraw);
3181 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3183 GetWindowRect(window, &r);
3184 ok(EqualRect(&r, &ddraw_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect),
3185 wine_dbgstr_rect(&r));
3187 expect_messages = NULL;
3188 DestroyWindow(window);
3189 DestroyWindow(window2);
3190 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL));
3191 UnregisterClassA("ddraw_test_wndproc_wc2", GetModuleHandleA(NULL));
3194 static void test_coop_level_mode_set_multi(void)
3196 IDirectDraw7 *ddraw1, *ddraw2;
3197 UINT w, h;
3198 HWND window;
3199 HRESULT hr;
3200 ULONG ref;
3202 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
3203 0, 0, 100, 100, 0, 0, 0, 0);
3204 ddraw1 = create_ddraw();
3205 ok(!!ddraw1, "Failed to create a ddraw object.\n");
3207 /* With just a single ddraw object, the display mode is restored on
3208 * release. */
3209 hr = set_display_mode(ddraw1, 800, 600);
3210 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3211 w = GetSystemMetrics(SM_CXSCREEN);
3212 ok(w == 800, "Got unexpected screen width %u.\n", w);
3213 h = GetSystemMetrics(SM_CYSCREEN);
3214 ok(h == 600, "Got unexpected screen height %u.\n", h);
3216 ref = IDirectDraw7_Release(ddraw1);
3217 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3218 w = GetSystemMetrics(SM_CXSCREEN);
3219 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3220 h = GetSystemMetrics(SM_CYSCREEN);
3221 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3223 /* When there are multiple ddraw objects, the display mode is restored to
3224 * the initial mode, before the first SetDisplayMode() call. */
3225 ddraw1 = create_ddraw();
3226 hr = set_display_mode(ddraw1, 800, 600);
3227 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3228 w = GetSystemMetrics(SM_CXSCREEN);
3229 ok(w == 800, "Got unexpected screen width %u.\n", w);
3230 h = GetSystemMetrics(SM_CYSCREEN);
3231 ok(h == 600, "Got unexpected screen height %u.\n", h);
3233 ddraw2 = create_ddraw();
3234 hr = set_display_mode(ddraw2, 640, 480);
3235 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3236 w = GetSystemMetrics(SM_CXSCREEN);
3237 ok(w == 640, "Got unexpected screen width %u.\n", w);
3238 h = GetSystemMetrics(SM_CYSCREEN);
3239 ok(h == 480, "Got unexpected screen height %u.\n", h);
3241 ref = IDirectDraw7_Release(ddraw2);
3242 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3243 w = GetSystemMetrics(SM_CXSCREEN);
3244 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3245 h = GetSystemMetrics(SM_CYSCREEN);
3246 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3248 ref = IDirectDraw7_Release(ddraw1);
3249 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3250 w = GetSystemMetrics(SM_CXSCREEN);
3251 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3252 h = GetSystemMetrics(SM_CYSCREEN);
3253 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3255 /* Regardless of release ordering. */
3256 ddraw1 = create_ddraw();
3257 hr = set_display_mode(ddraw1, 800, 600);
3258 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3259 w = GetSystemMetrics(SM_CXSCREEN);
3260 ok(w == 800, "Got unexpected screen width %u.\n", w);
3261 h = GetSystemMetrics(SM_CYSCREEN);
3262 ok(h == 600, "Got unexpected screen height %u.\n", h);
3264 ddraw2 = create_ddraw();
3265 hr = set_display_mode(ddraw2, 640, 480);
3266 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3267 w = GetSystemMetrics(SM_CXSCREEN);
3268 ok(w == 640, "Got unexpected screen width %u.\n", w);
3269 h = GetSystemMetrics(SM_CYSCREEN);
3270 ok(h == 480, "Got unexpected screen height %u.\n", h);
3272 ref = IDirectDraw7_Release(ddraw1);
3273 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3274 w = GetSystemMetrics(SM_CXSCREEN);
3275 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3276 h = GetSystemMetrics(SM_CYSCREEN);
3277 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3279 ref = IDirectDraw7_Release(ddraw2);
3280 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3281 w = GetSystemMetrics(SM_CXSCREEN);
3282 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3283 h = GetSystemMetrics(SM_CYSCREEN);
3284 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3286 /* But only for ddraw objects that called SetDisplayMode(). */
3287 ddraw1 = create_ddraw();
3288 ddraw2 = create_ddraw();
3289 hr = set_display_mode(ddraw2, 640, 480);
3290 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3291 w = GetSystemMetrics(SM_CXSCREEN);
3292 ok(w == 640, "Got unexpected screen width %u.\n", w);
3293 h = GetSystemMetrics(SM_CYSCREEN);
3294 ok(h == 480, "Got unexpected screen height %u.\n", h);
3296 ref = IDirectDraw7_Release(ddraw1);
3297 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3298 w = GetSystemMetrics(SM_CXSCREEN);
3299 ok(w == 640, "Got unexpected screen width %u.\n", w);
3300 h = GetSystemMetrics(SM_CYSCREEN);
3301 ok(h == 480, "Got unexpected screen height %u.\n", h);
3303 ref = IDirectDraw7_Release(ddraw2);
3304 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3305 w = GetSystemMetrics(SM_CXSCREEN);
3306 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3307 h = GetSystemMetrics(SM_CYSCREEN);
3308 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3310 /* If there's a ddraw object that's currently in exclusive mode, it blocks
3311 * restoring the display mode. */
3312 ddraw1 = create_ddraw();
3313 hr = set_display_mode(ddraw1, 800, 600);
3314 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3315 w = GetSystemMetrics(SM_CXSCREEN);
3316 ok(w == 800, "Got unexpected screen width %u.\n", w);
3317 h = GetSystemMetrics(SM_CYSCREEN);
3318 ok(h == 600, "Got unexpected screen height %u.\n", h);
3320 ddraw2 = create_ddraw();
3321 hr = set_display_mode(ddraw2, 640, 480);
3322 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3323 w = GetSystemMetrics(SM_CXSCREEN);
3324 ok(w == 640, "Got unexpected screen width %u.\n", w);
3325 h = GetSystemMetrics(SM_CYSCREEN);
3326 ok(h == 480, "Got unexpected screen height %u.\n", h);
3328 hr = IDirectDraw7_SetCooperativeLevel(ddraw2, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3329 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3331 ref = IDirectDraw7_Release(ddraw1);
3332 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3333 w = GetSystemMetrics(SM_CXSCREEN);
3334 ok(w == 640, "Got unexpected screen width %u.\n", w);
3335 h = GetSystemMetrics(SM_CYSCREEN);
3336 ok(h == 480, "Got unexpected screen height %u.\n", h);
3338 ref = IDirectDraw7_Release(ddraw2);
3339 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3340 w = GetSystemMetrics(SM_CXSCREEN);
3341 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3342 h = GetSystemMetrics(SM_CYSCREEN);
3343 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3345 /* Exclusive mode blocks mode setting on other ddraw objects in general. */
3346 ddraw1 = create_ddraw();
3347 hr = set_display_mode(ddraw1, 800, 600);
3348 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3349 w = GetSystemMetrics(SM_CXSCREEN);
3350 ok(w == 800, "Got unexpected screen width %u.\n", w);
3351 h = GetSystemMetrics(SM_CYSCREEN);
3352 ok(h == 600, "Got unexpected screen height %u.\n", h);
3354 hr = IDirectDraw7_SetCooperativeLevel(ddraw1, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3355 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3357 ddraw2 = create_ddraw();
3358 hr = set_display_mode(ddraw2, 640, 480);
3359 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
3361 ref = IDirectDraw7_Release(ddraw1);
3362 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3363 w = GetSystemMetrics(SM_CXSCREEN);
3364 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3365 h = GetSystemMetrics(SM_CYSCREEN);
3366 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3368 ref = IDirectDraw7_Release(ddraw2);
3369 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3370 w = GetSystemMetrics(SM_CXSCREEN);
3371 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3372 h = GetSystemMetrics(SM_CYSCREEN);
3373 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3375 DestroyWindow(window);
3378 static void test_initialize(void)
3380 IDirectDraw7 *ddraw;
3381 HRESULT hr;
3383 ddraw = create_ddraw();
3384 ok(!!ddraw, "Failed to create a ddraw object.\n");
3386 hr = IDirectDraw7_Initialize(ddraw, NULL);
3387 ok(hr == DDERR_ALREADYINITIALIZED, "Initialize returned hr %#x.\n", hr);
3388 IDirectDraw7_Release(ddraw);
3390 CoInitialize(NULL);
3391 hr = CoCreateInstance(&CLSID_DirectDraw, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectDraw7, (void **)&ddraw);
3392 ok(SUCCEEDED(hr), "Failed to create IDirectDraw7 instance, hr %#x.\n", hr);
3393 hr = IDirectDraw7_Initialize(ddraw, NULL);
3394 ok(hr == DD_OK, "Initialize returned hr %#x, expected DD_OK.\n", hr);
3395 hr = IDirectDraw7_Initialize(ddraw, NULL);
3396 ok(hr == DDERR_ALREADYINITIALIZED, "Initialize returned hr %#x, expected DDERR_ALREADYINITIALIZED.\n", hr);
3397 IDirectDraw7_Release(ddraw);
3398 CoUninitialize();
3401 static void test_coop_level_surf_create(void)
3403 IDirectDrawSurface7 *surface;
3404 IDirectDraw7 *ddraw;
3405 DDSURFACEDESC2 ddsd;
3406 HRESULT hr;
3408 ddraw = create_ddraw();
3409 ok(!!ddraw, "Failed to create a ddraw object.\n");
3411 memset(&ddsd, 0, sizeof(ddsd));
3412 ddsd.dwSize = sizeof(ddsd);
3413 ddsd.dwFlags = DDSD_CAPS;
3414 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3415 surface = (void *)0xdeadbeef;
3416 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
3417 ok(hr == DDERR_NOCOOPERATIVELEVELSET, "Surface creation returned hr %#x.\n", hr);
3418 ok(surface == (void *)0xdeadbeef, "Got unexpected surface %p.\n", surface);
3420 surface = (void *)0xdeadbeef;
3421 hr = IDirectDraw7_CreateSurface(ddraw, NULL, &surface, NULL);
3422 ok(hr == DDERR_NOCOOPERATIVELEVELSET, "Surface creation returned hr %#x.\n", hr);
3423 ok(surface == (void *)0xdeadbeef, "Got unexpected surface %p.\n", surface);
3425 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3426 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3428 surface = (void *)0xdeadbeef;
3429 hr = IDirectDraw7_CreateSurface(ddraw, NULL, &surface, NULL);
3430 ok(hr == DDERR_INVALIDPARAMS, "Unexpected hr %#x.\n", hr);
3431 ok(surface == (void *)0xdeadbeef, "Got unexpected surface %p.\n", surface);
3433 IDirectDraw7_Release(ddraw);
3436 static void test_vb_discard(void)
3438 static const struct vec4 quad[] =
3440 { 0.0f, 480.0f, 0.0f, 1.0f},
3441 { 0.0f, 0.0f, 0.0f, 1.0f},
3442 {640.0f, 480.0f, 0.0f, 1.0f},
3443 {640.0f, 0.0f, 0.0f, 1.0f},
3446 IDirect3DDevice7 *device;
3447 IDirect3D7 *d3d;
3448 IDirect3DVertexBuffer7 *buffer;
3449 HWND window;
3450 HRESULT hr;
3451 D3DVERTEXBUFFERDESC desc;
3452 BYTE *data;
3453 static const unsigned int vbsize = 16;
3454 unsigned int i;
3456 window = create_window();
3457 if (!(device = create_device(window, DDSCL_NORMAL)))
3459 skip("Failed to create a 3D device, skipping test.\n");
3460 DestroyWindow(window);
3461 return;
3464 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
3465 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
3467 memset(&desc, 0, sizeof(desc));
3468 desc.dwSize = sizeof(desc);
3469 desc.dwCaps = D3DVBCAPS_WRITEONLY;
3470 desc.dwFVF = D3DFVF_XYZRHW;
3471 desc.dwNumVertices = vbsize;
3472 hr = IDirect3D7_CreateVertexBuffer(d3d, &desc, &buffer, 0);
3473 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
3475 hr = IDirect3DVertexBuffer7_Lock(buffer, DDLOCK_DISCARDCONTENTS, (void **)&data, NULL);
3476 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
3477 memcpy(data, quad, sizeof(quad));
3478 hr = IDirect3DVertexBuffer7_Unlock(buffer);
3479 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
3481 hr = IDirect3DDevice7_BeginScene(device);
3482 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
3483 hr = IDirect3DDevice7_DrawPrimitiveVB(device, D3DPT_TRIANGLESTRIP, buffer, 0, 4, 0);
3484 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3485 hr = IDirect3DDevice7_EndScene(device);
3486 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
3488 hr = IDirect3DVertexBuffer7_Lock(buffer, DDLOCK_DISCARDCONTENTS, (void **)&data, NULL);
3489 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
3490 memset(data, 0xaa, sizeof(struct vec4) * vbsize);
3491 hr = IDirect3DVertexBuffer7_Unlock(buffer);
3492 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
3494 hr = IDirect3DVertexBuffer7_Lock(buffer, DDLOCK_DISCARDCONTENTS, (void **)&data, NULL);
3495 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
3496 for (i = 0; i < sizeof(struct vec4) * vbsize; i++)
3498 if (data[i] != 0xaa)
3500 ok(FALSE, "Vertex buffer data byte %u is 0x%02x, expected 0xaa\n", i, data[i]);
3501 break;
3504 hr = IDirect3DVertexBuffer7_Unlock(buffer);
3505 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
3507 IDirect3DVertexBuffer7_Release(buffer);
3508 IDirect3D7_Release(d3d);
3509 IDirect3DDevice7_Release(device);
3510 DestroyWindow(window);
3513 static void test_coop_level_multi_window(void)
3515 HWND window1, window2;
3516 IDirectDraw7 *ddraw;
3517 HRESULT hr;
3519 window1 = create_window();
3520 window2 = create_window();
3521 ddraw = create_ddraw();
3522 ok(!!ddraw, "Failed to create a ddraw object.\n");
3524 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window1, DDSCL_NORMAL);
3525 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3526 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window2, DDSCL_NORMAL);
3527 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3528 ok(IsWindow(window1), "Window 1 was destroyed.\n");
3529 ok(IsWindow(window2), "Window 2 was destroyed.\n");
3531 IDirectDraw7_Release(ddraw);
3532 DestroyWindow(window2);
3533 DestroyWindow(window1);
3536 static void test_draw_strided(void)
3538 static struct vec3 position[] =
3540 {-1.0, -1.0, 0.0},
3541 {-1.0, 1.0, 0.0},
3542 { 1.0, 1.0, 0.0},
3543 { 1.0, -1.0, 0.0},
3545 static DWORD diffuse[] =
3547 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00,
3549 static WORD indices[] =
3551 0, 1, 2, 2, 3, 0
3554 IDirectDrawSurface7 *rt;
3555 IDirect3DDevice7 *device;
3556 D3DCOLOR color;
3557 HWND window;
3558 HRESULT hr;
3559 D3DDRAWPRIMITIVESTRIDEDDATA strided;
3561 window = create_window();
3562 if (!(device = create_device(window, DDSCL_NORMAL)))
3564 skip("Failed to create a 3D device, skipping test.\n");
3565 DestroyWindow(window);
3566 return;
3569 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
3570 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
3572 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
3573 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
3574 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00000000, 1.0f, 0);
3575 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
3576 hr = IDirect3DDevice7_BeginScene(device);
3577 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
3579 memset(&strided, 0x55, sizeof(strided));
3580 strided.position.lpvData = position;
3581 strided.position.dwStride = sizeof(*position);
3582 strided.diffuse.lpvData = diffuse;
3583 strided.diffuse.dwStride = sizeof(*diffuse);
3584 hr = IDirect3DDevice7_DrawIndexedPrimitiveStrided(device, D3DPT_TRIANGLELIST, D3DFVF_XYZ | D3DFVF_DIFFUSE,
3585 &strided, 4, indices, 6, 0);
3586 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3588 hr = IDirect3DDevice7_EndScene(device);
3589 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
3591 color = get_surface_color(rt, 320, 240);
3592 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
3594 IDirectDrawSurface7_Release(rt);
3595 IDirect3DDevice7_Release(device);
3596 DestroyWindow(window);
3599 static void test_lighting(void)
3601 static D3DMATRIX mat =
3603 1.0f, 0.0f, 0.0f, 0.0f,
3604 0.0f, 1.0f, 0.0f, 0.0f,
3605 0.0f, 0.0f, 1.0f, 0.0f,
3606 0.0f, 0.0f, 0.0f, 1.0f,
3608 mat_singular =
3610 1.0f, 0.0f, 1.0f, 0.0f,
3611 0.0f, 1.0f, 0.0f, 0.0f,
3612 1.0f, 0.0f, 1.0f, 0.0f,
3613 0.0f, 0.0f, 0.5f, 1.0f,
3615 mat_transf =
3617 0.0f, 0.0f, 1.0f, 0.0f,
3618 0.0f, 1.0f, 0.0f, 0.0f,
3619 -1.0f, 0.0f, 0.0f, 0.0f,
3620 10.f, 10.0f, 10.0f, 1.0f,
3622 mat_nonaffine =
3624 1.0f, 0.0f, 0.0f, 0.0f,
3625 0.0f, 1.0f, 0.0f, 0.0f,
3626 0.0f, 0.0f, 1.0f, -1.0f,
3627 10.f, 10.0f, 10.0f, 0.0f,
3629 static struct
3631 struct vec3 position;
3632 DWORD diffuse;
3634 unlitquad[] =
3636 {{-1.0f, -1.0f, 0.1f}, 0xffff0000},
3637 {{-1.0f, 0.0f, 0.1f}, 0xffff0000},
3638 {{ 0.0f, 0.0f, 0.1f}, 0xffff0000},
3639 {{ 0.0f, -1.0f, 0.1f}, 0xffff0000},
3641 litquad[] =
3643 {{-1.0f, 0.0f, 0.1f}, 0xff00ff00},
3644 {{-1.0f, 1.0f, 0.1f}, 0xff00ff00},
3645 {{ 0.0f, 1.0f, 0.1f}, 0xff00ff00},
3646 {{ 0.0f, 0.0f, 0.1f}, 0xff00ff00},
3648 static struct
3650 struct vec3 position;
3651 struct vec3 normal;
3652 DWORD diffuse;
3654 unlitnquad[] =
3656 {{0.0f, -1.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xff0000ff},
3657 {{0.0f, 0.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xff0000ff},
3658 {{1.0f, 0.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xff0000ff},
3659 {{1.0f, -1.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xff0000ff},
3661 litnquad[] =
3663 {{0.0f, 0.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xffffff00},
3664 {{0.0f, 1.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xffffff00},
3665 {{1.0f, 1.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xffffff00},
3666 {{1.0f, 0.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xffffff00},
3668 nquad[] =
3670 {{-1.0f, -1.0f, 0.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
3671 {{-1.0f, 1.0f, 0.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
3672 {{ 1.0f, 1.0f, 0.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
3673 {{ 1.0f, -1.0f, 0.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
3675 rotatedquad[] =
3677 {{-10.0f, -11.0f, 11.0f}, {-1.0f, 0.0f, 0.0f}, 0xff0000ff},
3678 {{-10.0f, -9.0f, 11.0f}, {-1.0f, 0.0f, 0.0f}, 0xff0000ff},
3679 {{-10.0f, -9.0f, 9.0f}, {-1.0f, 0.0f, 0.0f}, 0xff0000ff},
3680 {{-10.0f, -11.0f, 9.0f}, {-1.0f, 0.0f, 0.0f}, 0xff0000ff},
3682 translatedquad[] =
3684 {{-11.0f, -11.0f, -10.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
3685 {{-11.0f, -9.0f, -10.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
3686 {{ -9.0f, -9.0f, -10.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
3687 {{ -9.0f, -11.0f, -10.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
3689 static WORD indices[] = {0, 1, 2, 2, 3, 0};
3690 static const struct
3692 D3DMATRIX *world_matrix;
3693 void *quad;
3694 DWORD expected;
3695 const char *message;
3697 tests[] =
3699 {&mat, nquad, 0x000000ff, "Lit quad with light"},
3700 {&mat_singular, nquad, 0x000000ff, "Lit quad with singular world matrix"},
3701 {&mat_transf, rotatedquad, 0x000000ff, "Lit quad with transformation matrix"},
3702 {&mat_nonaffine, translatedquad, 0x00000000, "Lit quad with non-affine matrix"},
3705 HWND window;
3706 IDirect3DDevice7 *device;
3707 IDirectDrawSurface7 *rt;
3708 HRESULT hr;
3709 DWORD fvf = D3DFVF_XYZ | D3DFVF_DIFFUSE;
3710 DWORD nfvf = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_NORMAL;
3711 D3DCOLOR color;
3712 ULONG refcount;
3713 unsigned int i;
3715 window = create_window();
3716 if (!(device = create_device(window, DDSCL_NORMAL)))
3718 skip("Failed to create a 3D device, skipping test.\n");
3719 DestroyWindow(window);
3720 return;
3723 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
3724 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
3726 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
3727 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
3729 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &mat);
3730 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#x.\n", hr);
3731 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_VIEW, &mat);
3732 ok(SUCCEEDED(hr), "Failed to set view transform, hr %#x.\n", hr);
3733 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &mat);
3734 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
3735 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CLIPPING, FALSE);
3736 ok(SUCCEEDED(hr), "Failed to disable clipping, hr %#x.\n", hr);
3737 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, FALSE);
3738 ok(SUCCEEDED(hr), "Failed to disable z-buffering, hr %#x.\n", hr);
3739 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, FALSE);
3740 ok(SUCCEEDED(hr), "Failed to disable fog, hr %#x.\n", hr);
3741 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_STENCILENABLE, FALSE);
3742 ok(SUCCEEDED(hr), "Failed to disable stencil buffering, hr %#x.\n", hr);
3743 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CULLMODE, D3DCULL_NONE);
3744 ok(SUCCEEDED(hr), "Failed to disable culling, hr %#x.\n", hr);
3746 hr = IDirect3DDevice7_BeginScene(device);
3747 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
3749 /* No lights are defined... That means, lit vertices should be entirely black. */
3750 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
3751 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
3752 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, fvf, unlitquad, 4,
3753 indices, 6, 0);
3754 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3756 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, TRUE);
3757 ok(SUCCEEDED(hr), "Failed to enable lighting, hr %#x.\n", hr);
3758 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, fvf, litquad, 4,
3759 indices, 6, 0);
3760 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3762 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
3763 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
3764 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, nfvf, unlitnquad, 4,
3765 indices, 6, 0);
3766 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3768 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, TRUE);
3769 ok(SUCCEEDED(hr), "Failed to enable lighting, hr %#x.\n", hr);
3770 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, nfvf, litnquad, 4,
3771 indices, 6, 0);
3772 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3774 hr = IDirect3DDevice7_EndScene(device);
3775 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
3777 color = get_surface_color(rt, 160, 360);
3778 ok(color == 0x00ff0000, "Unlit quad without normals has color 0x%08x, expected 0x00ff0000.\n", color);
3779 color = get_surface_color(rt, 160, 120);
3780 ok(color == 0x00000000, "Lit quad without normals has color 0x%08x, expected 0x00000000.\n", color);
3781 color = get_surface_color(rt, 480, 360);
3782 ok(color == 0x000000ff, "Unlit quad with normals has color 0x%08x, expected 0x000000ff.\n", color);
3783 color = get_surface_color(rt, 480, 120);
3784 ok(color == 0x00000000, "Lit quad with normals has color 0x%08x, expected 0x00000000.\n", color);
3786 hr = IDirect3DDevice7_LightEnable(device, 0, TRUE);
3787 ok(SUCCEEDED(hr), "Failed to enable light 0, hr %#x.\n", hr);
3789 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3791 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_WORLD, tests[i].world_matrix);
3792 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#x.\n", hr);
3794 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
3795 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
3797 hr = IDirect3DDevice7_BeginScene(device);
3798 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
3800 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, nfvf, tests[i].quad,
3801 4, indices, 6, 0);
3802 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3804 hr = IDirect3DDevice7_EndScene(device);
3805 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
3807 color = get_surface_color(rt, 320, 240);
3808 ok(color == tests[i].expected, "%s has color 0x%08x.\n", tests[i].message, color);
3811 IDirectDrawSurface7_Release(rt);
3813 refcount = IDirect3DDevice7_Release(device);
3814 ok(!refcount, "Device has %u references left.\n", refcount);
3815 DestroyWindow(window);
3818 static void test_specular_lighting(void)
3820 static const unsigned int vertices_side = 5;
3821 const unsigned int indices_count = (vertices_side - 1) * (vertices_side - 1) * 2 * 3;
3822 static const DWORD fvf = D3DFVF_XYZ | D3DFVF_NORMAL;
3823 static D3DMATRIX mat =
3825 1.0f, 0.0f, 0.0f, 0.0f,
3826 0.0f, 1.0f, 0.0f, 0.0f,
3827 0.0f, 0.0f, 1.0f, 0.0f,
3828 0.0f, 0.0f, 0.0f, 1.0f,
3830 static D3DLIGHT7 directional =
3832 D3DLIGHT_DIRECTIONAL,
3833 {{0.0f}, {0.0f}, {0.0f}, {0.0f}},
3834 {{1.0f}, {1.0f}, {1.0f}, {0.0f}},
3835 {{0.0f}, {0.0f}, {0.0f}, {0.0f}},
3836 {{0.0f}, {0.0f}, {0.0f}},
3837 {{0.0f}, {0.0f}, {1.0f}},
3839 point =
3841 D3DLIGHT_POINT,
3842 {{0.0f}, {0.0f}, {0.0f}, {0.0f}},
3843 {{1.0f}, {1.0f}, {1.0f}, {0.0f}},
3844 {{0.0f}, {0.0f}, {0.0f}, {0.0f}},
3845 {{0.0f}, {0.0f}, {0.0f}},
3846 {{0.0f}, {0.0f}, {0.0f}},
3847 100.0f,
3848 0.0f,
3849 0.0f, 0.0f, 1.0f,
3851 spot =
3853 D3DLIGHT_SPOT,
3854 {{0.0f}, {0.0f}, {0.0f}, {0.0f}},
3855 {{1.0f}, {1.0f}, {1.0f}, {0.0f}},
3856 {{0.0f}, {0.0f}, {0.0f}, {0.0f}},
3857 {{0.0f}, {0.0f}, {0.0f}},
3858 {{0.0f}, {0.0f}, {1.0f}},
3859 100.0f,
3860 1.0f,
3861 0.0f, 0.0f, 1.0f,
3862 M_PI / 12.0f, M_PI / 3.0f
3864 /* The chosen range value makes the test fail when using a manhattan
3865 * distance metric vs the correct euclidean distance. */
3866 point_range =
3868 D3DLIGHT_POINT,
3869 {{0.0f}, {0.0f}, {0.0f}, {0.0f}},
3870 {{1.0f}, {1.0f}, {1.0f}, {0.0f}},
3871 {{0.0f}, {0.0f}, {0.0f}, {0.0f}},
3872 {{0.0f}, {0.0f}, {0.0f}},
3873 {{0.0f}, {0.0f}, {0.0f}},
3874 1.2f,
3875 0.0f,
3876 0.0f, 0.0f, 1.0f,
3878 point_side =
3880 D3DLIGHT_POINT,
3881 {{0.0f}, {0.0f}, {0.0f}, {0.0f}},
3882 {{1.0f}, {1.0f}, {1.0f}, {0.0f}},
3883 {{0.0f}, {0.0f}, {0.0f}, {0.0f}},
3884 {{-1.1f}, {0.0f}, {1.1f}},
3885 {{0.0f}, {0.0f}, {0.0f}},
3886 100.0f,
3887 0.0f,
3888 1.0f, 0.0f, 0.0f,
3890 static const struct expected_color
3892 unsigned int x, y;
3893 D3DCOLOR color;
3895 expected_directional[] =
3897 {160, 120, 0x00ffffff},
3898 {320, 120, 0x00ffffff},
3899 {480, 120, 0x00ffffff},
3900 {160, 240, 0x00ffffff},
3901 {320, 240, 0x00ffffff},
3902 {480, 240, 0x00ffffff},
3903 {160, 360, 0x00ffffff},
3904 {320, 360, 0x00ffffff},
3905 {480, 360, 0x00ffffff},
3907 expected_directional_local[] =
3909 {160, 120, 0x003c3c3c},
3910 {320, 120, 0x00717171},
3911 {480, 120, 0x003c3c3c},
3912 {160, 240, 0x00717171},
3913 {320, 240, 0x00ffffff},
3914 {480, 240, 0x00717171},
3915 {160, 360, 0x003c3c3c},
3916 {320, 360, 0x00717171},
3917 {480, 360, 0x003c3c3c},
3919 expected_point[] =
3921 {160, 120, 0x00282828},
3922 {320, 120, 0x005a5a5a},
3923 {480, 120, 0x00282828},
3924 {160, 240, 0x005a5a5a},
3925 {320, 240, 0x00ffffff},
3926 {480, 240, 0x005a5a5a},
3927 {160, 360, 0x00282828},
3928 {320, 360, 0x005a5a5a},
3929 {480, 360, 0x00282828},
3931 expected_point_local[] =
3933 {160, 120, 0x00000000},
3934 {320, 120, 0x00070707},
3935 {480, 120, 0x00000000},
3936 {160, 240, 0x00070707},
3937 {320, 240, 0x00ffffff},
3938 {480, 240, 0x00070707},
3939 {160, 360, 0x00000000},
3940 {320, 360, 0x00070707},
3941 {480, 360, 0x00000000},
3943 expected_spot[] =
3945 {160, 120, 0x00000000},
3946 {320, 120, 0x00141414},
3947 {480, 120, 0x00000000},
3948 {160, 240, 0x00141414},
3949 {320, 240, 0x00ffffff},
3950 {480, 240, 0x00141414},
3951 {160, 360, 0x00000000},
3952 {320, 360, 0x00141414},
3953 {480, 360, 0x00000000},
3955 expected_spot_local[] =
3957 {160, 120, 0x00000000},
3958 {320, 120, 0x00020202},
3959 {480, 120, 0x00000000},
3960 {160, 240, 0x00020202},
3961 {320, 240, 0x00ffffff},
3962 {480, 240, 0x00020202},
3963 {160, 360, 0x00000000},
3964 {320, 360, 0x00020202},
3965 {480, 360, 0x00000000},
3967 expected_point_range[] =
3969 {160, 120, 0x00000000},
3970 {320, 120, 0x005a5a5a},
3971 {480, 120, 0x00000000},
3972 {160, 240, 0x005a5a5a},
3973 {320, 240, 0x00ffffff},
3974 {480, 240, 0x005a5a5a},
3975 {160, 360, 0x00000000},
3976 {320, 360, 0x005a5a5a},
3977 {480, 360, 0x00000000},
3979 expected_point_side[] =
3981 {160, 120, 0x00000000},
3982 {320, 120, 0x00000000},
3983 {480, 120, 0x00000000},
3984 {160, 240, 0x00000000},
3985 {320, 240, 0x00000000},
3986 {480, 240, 0x00000000},
3987 {160, 360, 0x00000000},
3988 {320, 360, 0x00000000},
3989 {480, 360, 0x00000000},
3991 static const struct
3993 D3DLIGHT7 *light;
3994 BOOL local_viewer;
3995 float specular_power;
3996 const struct expected_color *expected;
3997 unsigned int expected_count;
3999 tests[] =
4001 {&directional, FALSE, 30.0f, expected_directional, ARRAY_SIZE(expected_directional)},
4002 {&directional, TRUE, 30.0f, expected_directional_local, ARRAY_SIZE(expected_directional_local)},
4003 {&point, FALSE, 30.0f, expected_point, ARRAY_SIZE(expected_point)},
4004 {&point, TRUE, 30.0f, expected_point_local, ARRAY_SIZE(expected_point_local)},
4005 {&spot, FALSE, 30.0f, expected_spot, ARRAY_SIZE(expected_spot)},
4006 {&spot, TRUE, 30.0f, expected_spot_local, ARRAY_SIZE(expected_spot_local)},
4007 {&point_range, FALSE, 30.0f, expected_point_range, ARRAY_SIZE(expected_point_range)},
4008 {&point_side, TRUE, 0.0f, expected_point_side, ARRAY_SIZE(expected_point_side)},
4010 IDirect3DDevice7 *device;
4011 IDirectDrawSurface7 *rt;
4012 D3DMATERIAL7 material;
4013 D3DCOLOR color;
4014 ULONG refcount;
4015 HWND window;
4016 HRESULT hr;
4017 unsigned int i, j, x, y;
4018 struct
4020 struct vec3 position;
4021 struct vec3 normal;
4022 } *quad;
4023 WORD *indices;
4025 window = create_window();
4026 if (!(device = create_device(window, DDSCL_NORMAL)))
4028 skip("Failed to create a 3D device, skipping test.\n");
4029 DestroyWindow(window);
4030 return;
4033 quad = HeapAlloc(GetProcessHeap(), 0, vertices_side * vertices_side * sizeof(*quad));
4034 indices = HeapAlloc(GetProcessHeap(), 0, indices_count * sizeof(*indices));
4035 for (i = 0, y = 0; y < vertices_side; ++y)
4037 for (x = 0; x < vertices_side; ++x)
4039 quad[i].position.x = x * 2.0f / (vertices_side - 1) - 1.0f;
4040 quad[i].position.y = y * 2.0f / (vertices_side - 1) - 1.0f;
4041 quad[i].position.z = 1.0f;
4042 quad[i].normal.x = 0.0f;
4043 quad[i].normal.y = 0.0f;
4044 quad[i++].normal.z = -1.0f;
4047 for (i = 0, y = 0; y < (vertices_side - 1); ++y)
4049 for (x = 0; x < (vertices_side - 1); ++x)
4051 indices[i++] = y * vertices_side + x + 1;
4052 indices[i++] = y * vertices_side + x;
4053 indices[i++] = (y + 1) * vertices_side + x;
4054 indices[i++] = y * vertices_side + x + 1;
4055 indices[i++] = (y + 1) * vertices_side + x;
4056 indices[i++] = (y + 1) * vertices_side + x + 1;
4060 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
4061 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
4063 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &mat);
4064 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#x.\n", hr);
4065 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_VIEW, &mat);
4066 ok(SUCCEEDED(hr), "Failed to set view transform, hr %#x.\n", hr);
4067 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &mat);
4068 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
4069 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CLIPPING, FALSE);
4070 ok(SUCCEEDED(hr), "Failed to disable clipping, hr %#x.\n", hr);
4071 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, FALSE);
4072 ok(SUCCEEDED(hr), "Failed to disable z-buffering, hr %#x.\n", hr);
4073 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, FALSE);
4074 ok(SUCCEEDED(hr), "Failed to disable fog, hr %#x.\n", hr);
4076 hr = IDirect3DDevice7_LightEnable(device, 0, TRUE);
4077 ok(SUCCEEDED(hr), "Failed to enable light 0, hr %#x.\n", hr);
4078 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_SPECULARENABLE, TRUE);
4079 ok(SUCCEEDED(hr), "Failed to enable specular lighting, hr %#x.\n", hr);
4081 for (i = 0; i < ARRAY_SIZE(tests); ++i)
4083 hr = IDirect3DDevice7_SetLight(device, 0, tests[i].light);
4084 ok(SUCCEEDED(hr), "Failed to set light parameters, hr %#x.\n", hr);
4086 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LOCALVIEWER, tests[i].local_viewer);
4087 ok(SUCCEEDED(hr), "Failed to set local viewer state, hr %#x.\n", hr);
4089 memset(&material, 0, sizeof(material));
4090 U1(U2(material).specular).r = 1.0f;
4091 U2(U2(material).specular).g = 1.0f;
4092 U3(U2(material).specular).b = 1.0f;
4093 U4(U2(material).specular).a = 1.0f;
4094 U4(material).power = tests[i].specular_power;
4095 hr = IDirect3DDevice7_SetMaterial(device, &material);
4096 ok(SUCCEEDED(hr), "Failed to set material, hr %#x.\n", hr);
4098 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
4099 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
4101 hr = IDirect3DDevice7_BeginScene(device);
4102 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
4104 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, fvf, quad,
4105 vertices_side * vertices_side, indices, indices_count, 0);
4106 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
4108 hr = IDirect3DDevice7_EndScene(device);
4109 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
4111 for (j = 0; j < tests[i].expected_count; ++j)
4113 color = get_surface_color(rt, tests[i].expected[j].x, tests[i].expected[j].y);
4114 ok(compare_color(color, tests[i].expected[j].color, 1),
4115 "Expected color 0x%08x at location (%u, %u), got 0x%08x, case %u.\n",
4116 tests[i].expected[j].color, tests[i].expected[j].x,
4117 tests[i].expected[j].y, color, i);
4121 IDirectDrawSurface7_Release(rt);
4123 refcount = IDirect3DDevice7_Release(device);
4124 ok(!refcount, "Device has %u references left.\n", refcount);
4125 DestroyWindow(window);
4126 HeapFree(GetProcessHeap(), 0, indices);
4127 HeapFree(GetProcessHeap(), 0, quad);
4130 static void test_clear_rect_count(void)
4132 IDirectDrawSurface7 *rt;
4133 IDirect3DDevice7 *device;
4134 D3DCOLOR color;
4135 HWND window;
4136 HRESULT hr;
4137 D3DRECT rect = {{0}, {0}, {640}, {480}};
4139 window = create_window();
4140 if (!(device = create_device(window, DDSCL_NORMAL)))
4142 skip("Failed to create a 3D device, skipping test.\n");
4143 DestroyWindow(window);
4144 return;
4147 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
4148 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
4150 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00ffffff, 1.0f, 0);
4151 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
4152 hr = IDirect3DDevice7_Clear(device, 0, &rect, D3DCLEAR_TARGET, 0x00ff0000, 1.0f, 0);
4153 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
4155 color = get_surface_color(rt, 320, 240);
4156 ok(compare_color(color, 0x00ffffff, 1) || broken(compare_color(color, 0x00ff0000, 1)),
4157 "Clear with count = 0, rect != NULL has color %#08x.\n", color);
4159 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00ffffff, 1.0f, 0);
4160 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
4161 hr = IDirect3DDevice7_Clear(device, 1, NULL, D3DCLEAR_TARGET, 0x0000ff00, 1.0f, 0);
4162 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
4164 color = get_surface_color(rt, 320, 240);
4165 ok(compare_color(color, 0x0000ff00, 1),
4166 "Clear with count = 1, rect = NULL has color %#08x.\n", color);
4168 IDirectDrawSurface7_Release(rt);
4169 IDirect3DDevice7_Release(device);
4170 DestroyWindow(window);
4173 static BOOL test_mode_restored(IDirectDraw7 *ddraw, HWND window)
4175 DDSURFACEDESC2 ddsd1, ddsd2;
4176 HRESULT hr;
4178 memset(&ddsd1, 0, sizeof(ddsd1));
4179 ddsd1.dwSize = sizeof(ddsd1);
4180 hr = IDirectDraw7_GetDisplayMode(ddraw, &ddsd1);
4181 ok(SUCCEEDED(hr), "GetDisplayMode failed, hr %#x.\n", hr);
4183 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
4184 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
4185 hr = set_display_mode(ddraw, 640, 480);
4186 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
4187 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
4188 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
4190 memset(&ddsd2, 0, sizeof(ddsd2));
4191 ddsd2.dwSize = sizeof(ddsd2);
4192 hr = IDirectDraw7_GetDisplayMode(ddraw, &ddsd2);
4193 ok(SUCCEEDED(hr), "GetDisplayMode failed, hr %#x.\n", hr);
4194 hr = IDirectDraw7_RestoreDisplayMode(ddraw);
4195 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
4197 return ddsd1.dwWidth == ddsd2.dwWidth && ddsd1.dwHeight == ddsd2.dwHeight;
4200 static void test_coop_level_versions(void)
4202 HWND window;
4203 IDirectDraw *ddraw;
4204 HRESULT hr;
4205 BOOL restored;
4206 IDirectDrawSurface *surface;
4207 IDirectDraw7 *ddraw7;
4208 DDSURFACEDESC ddsd;
4210 window = create_window();
4211 ddraw7 = create_ddraw();
4212 ok(!!ddraw7, "Failed to create a ddraw object.\n");
4213 /* Newly created ddraw objects restore the mode on ddraw2+::SetCooperativeLevel(NORMAL) */
4214 restored = test_mode_restored(ddraw7, window);
4215 ok(restored, "Display mode not restored in new ddraw object\n");
4217 /* A failing ddraw1::SetCooperativeLevel call does not have an effect */
4218 hr = IDirectDraw7_QueryInterface(ddraw7, &IID_IDirectDraw, (void **)&ddraw);
4219 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#x.\n", hr);
4221 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
4222 ok(FAILED(hr), "SetCooperativeLevel returned %#x, expected failure.\n", hr);
4223 restored = test_mode_restored(ddraw7, window);
4224 ok(restored, "Display mode not restored after bad ddraw1::SetCooperativeLevel call\n");
4226 /* A successful one does */
4227 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
4228 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
4229 restored = test_mode_restored(ddraw7, window);
4230 ok(!restored, "Display mode restored after good ddraw1::SetCooperativeLevel call\n");
4232 IDirectDraw_Release(ddraw);
4233 IDirectDraw7_Release(ddraw7);
4235 ddraw7 = create_ddraw();
4236 ok(!!ddraw7, "Failed to create a ddraw object.\n");
4237 hr = IDirectDraw7_QueryInterface(ddraw7, &IID_IDirectDraw, (void **)&ddraw);
4238 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#x.\n", hr);
4240 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_SETFOCUSWINDOW);
4241 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
4242 restored = test_mode_restored(ddraw7, window);
4243 ok(!restored, "Display mode restored after ddraw1::SetCooperativeLevel(SETFOCUSWINDOW) call\n");
4245 IDirectDraw_Release(ddraw);
4246 IDirectDraw7_Release(ddraw7);
4248 /* A failing call does not restore the ddraw2+ behavior */
4249 ddraw7 = create_ddraw();
4250 ok(!!ddraw7, "Failed to create a ddraw object.\n");
4251 hr = IDirectDraw7_QueryInterface(ddraw7, &IID_IDirectDraw, (void **)&ddraw);
4252 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#x.\n", hr);
4254 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
4255 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
4256 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
4257 ok(FAILED(hr), "SetCooperativeLevel returned %#x, expected failure.\n", hr);
4258 restored = test_mode_restored(ddraw7, window);
4259 ok(!restored, "Display mode restored after good-bad ddraw1::SetCooperativeLevel() call sequence\n");
4261 IDirectDraw_Release(ddraw);
4262 IDirectDraw7_Release(ddraw7);
4264 /* Neither does a sequence of successful calls with the new interface */
4265 ddraw7 = create_ddraw();
4266 ok(!!ddraw7, "Failed to create a ddraw object.\n");
4267 hr = IDirectDraw7_QueryInterface(ddraw7, &IID_IDirectDraw, (void **)&ddraw);
4268 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#x.\n", hr);
4270 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
4271 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
4272 hr = IDirectDraw7_SetCooperativeLevel(ddraw7, window, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
4273 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
4274 hr = IDirectDraw7_SetCooperativeLevel(ddraw7, window, DDSCL_NORMAL);
4275 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
4277 restored = test_mode_restored(ddraw7, window);
4278 ok(!restored, "Display mode restored after ddraw1-ddraw7 SetCooperativeLevel() call sequence\n");
4279 IDirectDraw_Release(ddraw);
4280 IDirectDraw7_Release(ddraw7);
4282 /* ddraw1::CreateSurface does not triger the ddraw1 behavior */
4283 ddraw7 = create_ddraw();
4284 ok(!!ddraw7, "Failed to create a ddraw object.\n");
4285 hr = IDirectDraw7_QueryInterface(ddraw7, &IID_IDirectDraw, (void **)&ddraw);
4286 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#x.\n", hr);
4288 hr = IDirectDraw7_SetCooperativeLevel(ddraw7, window, DDSCL_NORMAL);
4289 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
4291 memset(&ddsd, 0, sizeof(ddsd));
4292 ddsd.dwSize = sizeof(ddsd);
4293 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
4294 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
4295 ddsd.dwWidth = ddsd.dwHeight = 8;
4296 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &surface, NULL);
4297 ok(SUCCEEDED(hr), "CreateSurface failed, hr %#x.\n", hr);
4298 IDirectDrawSurface_Release(surface);
4299 restored = test_mode_restored(ddraw7, window);
4300 ok(restored, "Display mode not restored after ddraw1::CreateSurface() call\n");
4302 IDirectDraw_Release(ddraw);
4303 IDirectDraw7_Release(ddraw7);
4304 DestroyWindow(window);
4307 static void test_fog_special(void)
4309 static struct
4311 struct vec3 position;
4312 D3DCOLOR diffuse;
4314 quad[] =
4316 {{ -1.0f, 1.0f, 0.0f}, 0xff00ff00},
4317 {{ 1.0f, 1.0f, 1.0f}, 0xff00ff00},
4318 {{ -1.0f, -1.0f, 0.0f}, 0xff00ff00},
4319 {{ 1.0f, -1.0f, 1.0f}, 0xff00ff00},
4321 static const struct
4323 DWORD vertexmode, tablemode;
4324 D3DCOLOR color_left, color_right;
4326 tests[] =
4328 {D3DFOG_LINEAR, D3DFOG_NONE, 0x00ff0000, 0x00ff0000},
4329 {D3DFOG_NONE, D3DFOG_LINEAR, 0x0000ff00, 0x00ff0000},
4331 union
4333 float f;
4334 DWORD d;
4335 } conv;
4336 D3DCOLOR color;
4337 HRESULT hr;
4338 unsigned int i;
4339 HWND window;
4340 IDirect3DDevice7 *device;
4341 IDirectDrawSurface7 *rt;
4343 window = create_window();
4344 if (!(device = create_device(window, DDSCL_NORMAL)))
4346 skip("Failed to create a 3D device, skipping test.\n");
4347 DestroyWindow(window);
4348 return;
4351 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
4352 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
4354 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, TRUE);
4355 ok(SUCCEEDED(hr), "Failed to enable fog, hr %#x.\n", hr);
4356 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGCOLOR, 0xffff0000);
4357 ok(SUCCEEDED(hr), "Failed to set fog color, hr %#x.\n", hr);
4358 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
4359 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
4360 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
4361 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
4363 conv.f = 0.5f;
4364 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGSTART, conv.d);
4365 ok(SUCCEEDED(hr), "Failed to set fog start, hr %#x.\n", hr);
4366 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGEND, conv.d);
4367 ok(SUCCEEDED(hr), "Failed to set fog end, hr %#x.\n", hr);
4369 for (i = 0; i < ARRAY_SIZE(tests); ++i)
4371 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x000000ff, 1.0f, 0);
4372 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
4374 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGVERTEXMODE, tests[i].vertexmode);
4375 ok(SUCCEEDED(hr), "Failed to set fogvertexmode, hr %#x.\n", hr);
4376 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGTABLEMODE, tests[i].tablemode);
4377 ok(SUCCEEDED(hr), "Failed to set fogtablemode, hr %#x.\n", hr);
4379 hr = IDirect3DDevice7_BeginScene(device);
4380 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
4381 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE, quad, 4, 0);
4382 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
4383 hr = IDirect3DDevice7_EndScene(device);
4384 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
4386 color = get_surface_color(rt, 310, 240);
4387 ok(compare_color(color, tests[i].color_left, 1),
4388 "Expected left color 0x%08x, got 0x%08x, case %u.\n", tests[i].color_left, color, i);
4389 color = get_surface_color(rt, 330, 240);
4390 ok(compare_color(color, tests[i].color_right, 1),
4391 "Expected right color 0x%08x, got 0x%08x, case %u.\n", tests[i].color_right, color, i);
4394 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, FALSE);
4395 ok(SUCCEEDED(hr), "Failed to disable fog, hr %#x.\n", hr);
4397 IDirectDrawSurface7_Release(rt);
4398 IDirect3DDevice7_Release(device);
4399 DestroyWindow(window);
4402 static void test_lighting_interface_versions(void)
4404 IDirect3DDevice7 *device;
4405 IDirectDrawSurface7 *rt;
4406 D3DCOLOR color;
4407 HWND window;
4408 HRESULT hr;
4409 DWORD rs;
4410 unsigned int i;
4411 ULONG ref;
4412 D3DMATERIAL7 material;
4413 static D3DVERTEX quad[] =
4415 {{-1.0f}, { 1.0f}, {0.0f}, {1.0f}, {0.0f}, {0.0f}},
4416 {{ 1.0f}, { 1.0f}, {0.0f}, {1.0f}, {0.0f}, {0.0f}},
4417 {{-1.0f}, {-1.0f}, {0.0f}, {1.0f}, {0.0f}, {0.0f}},
4418 {{ 1.0f}, {-1.0f}, {0.0f}, {1.0f}, {0.0f}, {0.0f}},
4421 #define FVF_COLORVERTEX (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE | D3DFVF_SPECULAR)
4422 static struct
4424 struct vec3 position;
4425 struct vec3 normal;
4426 DWORD diffuse, specular;
4428 quad2[] =
4430 {{-1.0f, 1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000, 0xff808080},
4431 {{ 1.0f, 1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000, 0xff808080},
4432 {{-1.0f, -1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000, 0xff808080},
4433 {{ 1.0f, -1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000, 0xff808080},
4436 static D3DLVERTEX lquad[] =
4438 {{-1.0f}, { 1.0f}, {0.0f}, 0, {0xffff0000}, {0xff808080}},
4439 {{ 1.0f}, { 1.0f}, {0.0f}, 0, {0xffff0000}, {0xff808080}},
4440 {{-1.0f}, {-1.0f}, {0.0f}, 0, {0xffff0000}, {0xff808080}},
4441 {{ 1.0f}, {-1.0f}, {0.0f}, 0, {0xffff0000}, {0xff808080}},
4444 #define FVF_LVERTEX2 (D3DFVF_LVERTEX & ~D3DFVF_RESERVED1)
4445 static struct
4447 struct vec3 position;
4448 DWORD diffuse, specular;
4449 struct vec2 texcoord;
4451 lquad2[] =
4453 {{-1.0f, 1.0f, 0.0f}, 0xffff0000, 0xff808080},
4454 {{ 1.0f, 1.0f, 0.0f}, 0xffff0000, 0xff808080},
4455 {{-1.0f, -1.0f, 0.0f}, 0xffff0000, 0xff808080},
4456 {{ 1.0f, -1.0f, 0.0f}, 0xffff0000, 0xff808080},
4459 static D3DTLVERTEX tlquad[] =
4461 {{ 0.0f}, { 480.0f}, {0.0f}, {1.0f}, {0xff0000ff}, {0xff808080}},
4462 {{ 0.0f}, { 0.0f}, {0.0f}, {1.0f}, {0xff0000ff}, {0xff808080}},
4463 {{ 640.0f}, { 480.0f}, {0.0f}, {1.0f}, {0xff0000ff}, {0xff808080}},
4464 {{ 640.0f}, { 0.0f}, {0.0f}, {1.0f}, {0xff0000ff}, {0xff808080}},
4467 static const struct
4469 DWORD vertextype;
4470 void *data;
4471 DWORD d3drs_lighting, d3drs_specular;
4472 DWORD draw_flags;
4473 D3DCOLOR color;
4475 tests[] =
4477 /* Lighting is enabled when D3DFVF_XYZ is used and D3DRENDERSTATE_LIGHTING is
4478 * enabled. D3DDP_DONOTLIGHT is ignored. Lighting is also enabled when normals
4479 * are not available
4481 * Note that the specular result is 0x00000000 when lighting is on even if the
4482 * input vertex has specular color because D3DRENDERSTATE_COLORVERTEX is not
4483 * enabled */
4485 /* 0 */
4486 { D3DFVF_VERTEX, quad, FALSE, FALSE, 0, 0x00ffffff},
4487 { D3DFVF_VERTEX, quad, TRUE, FALSE, 0, 0x0000ff00},
4488 { D3DFVF_VERTEX, quad, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x00ffffff},
4489 { D3DFVF_VERTEX, quad, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x0000ff00},
4490 { D3DFVF_VERTEX, quad, FALSE, TRUE, 0, 0x00ffffff},
4491 { D3DFVF_VERTEX, quad, TRUE, TRUE, 0, 0x0000ff00},
4492 { D3DFVF_VERTEX, quad, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x00ffffff},
4493 { D3DFVF_VERTEX, quad, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x0000ff00},
4495 /* 8 */
4496 { FVF_COLORVERTEX, quad2, FALSE, FALSE, 0, 0x00ff0000},
4497 { FVF_COLORVERTEX, quad2, TRUE, FALSE, 0, 0x0000ff00},
4498 { FVF_COLORVERTEX, quad2, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x00ff0000},
4499 { FVF_COLORVERTEX, quad2, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x0000ff00},
4500 { FVF_COLORVERTEX, quad2, FALSE, TRUE, 0, 0x00ff8080},
4501 { FVF_COLORVERTEX, quad2, TRUE, TRUE, 0, 0x0000ff00},
4502 { FVF_COLORVERTEX, quad2, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x00ff8080},
4503 { FVF_COLORVERTEX, quad2, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x0000ff00},
4505 /* 16 */
4506 { D3DFVF_LVERTEX, lquad, FALSE, FALSE, 0, 0x00ff0000},
4507 { D3DFVF_LVERTEX, lquad, TRUE, FALSE, 0, 0x0000ff00},
4508 { D3DFVF_LVERTEX, lquad, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x00ff0000},
4509 { D3DFVF_LVERTEX, lquad, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x0000ff00},
4510 { D3DFVF_LVERTEX, lquad, FALSE, TRUE, 0, 0x00ff8080},
4511 { D3DFVF_LVERTEX, lquad, TRUE, TRUE, 0, 0x0000ff00},
4512 { D3DFVF_LVERTEX, lquad, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x00ff8080},
4513 { D3DFVF_LVERTEX, lquad, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x0000ff00},
4515 /* 24 */
4516 { FVF_LVERTEX2, lquad2, FALSE, FALSE, 0, 0x00ff0000},
4517 { FVF_LVERTEX2, lquad2, TRUE, FALSE, 0, 0x0000ff00},
4518 { FVF_LVERTEX2, lquad2, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x00ff0000},
4519 { FVF_LVERTEX2, lquad2, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x0000ff00},
4520 { FVF_LVERTEX2, lquad2, FALSE, TRUE, 0, 0x00ff8080},
4521 { FVF_LVERTEX2, lquad2, TRUE, TRUE, 0, 0x0000ff00},
4522 { FVF_LVERTEX2, lquad2, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x00ff8080},
4523 { FVF_LVERTEX2, lquad2, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x0000ff00},
4525 /* 32 */
4526 { D3DFVF_TLVERTEX, tlquad, FALSE, FALSE, 0, 0x000000ff},
4527 { D3DFVF_TLVERTEX, tlquad, TRUE, FALSE, 0, 0x000000ff},
4528 { D3DFVF_TLVERTEX, tlquad, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x000000ff},
4529 { D3DFVF_TLVERTEX, tlquad, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x000000ff},
4530 { D3DFVF_TLVERTEX, tlquad, FALSE, TRUE, 0, 0x008080ff},
4531 { D3DFVF_TLVERTEX, tlquad, TRUE, TRUE, 0, 0x008080ff},
4532 { D3DFVF_TLVERTEX, tlquad, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x008080ff},
4533 { D3DFVF_TLVERTEX, tlquad, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x008080ff},
4536 window = create_window();
4537 if (!(device = create_device(window, DDSCL_NORMAL)))
4539 skip("Failed to create a 3D device, skipping test.\n");
4540 DestroyWindow(window);
4541 return;
4544 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
4545 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
4547 memset(&material, 0, sizeof(material));
4548 U2(U3(material).emissive).g = 1.0f;
4549 hr = IDirect3DDevice7_SetMaterial(device, &material);
4550 ok(SUCCEEDED(hr), "Failed set material, hr %#x.\n", hr);
4551 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
4552 ok(SUCCEEDED(hr), "Failed to disable z test, hr %#x.\n", hr);
4554 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_LIGHTING, &rs);
4555 ok(SUCCEEDED(hr), "Failed to get lighting render state, hr %#x.\n", hr);
4556 ok(rs == TRUE, "Initial D3DRENDERSTATE_LIGHTING is %#x, expected TRUE.\n", rs);
4557 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_SPECULARENABLE, &rs);
4558 ok(SUCCEEDED(hr), "Failed to get specularenable render state, hr %#x.\n", hr);
4559 ok(rs == FALSE, "Initial D3DRENDERSTATE_SPECULARENABLE is %#x, expected FALSE.\n", rs);
4561 for (i = 0; i < ARRAY_SIZE(tests); ++i)
4563 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff202020, 0.0f, 0);
4564 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
4566 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, tests[i].d3drs_lighting);
4567 ok(SUCCEEDED(hr), "Failed to set lighting render state, hr %#x.\n", hr);
4568 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_SPECULARENABLE,
4569 tests[i].d3drs_specular);
4570 ok(SUCCEEDED(hr), "Failed to set specularenable render state, hr %#x.\n", hr);
4572 hr = IDirect3DDevice7_BeginScene(device);
4573 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
4574 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
4575 tests[i].vertextype, tests[i].data, 4, tests[i].draw_flags | D3DDP_WAIT);
4576 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
4577 hr = IDirect3DDevice7_EndScene(device);
4578 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
4580 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_LIGHTING, &rs);
4581 ok(SUCCEEDED(hr), "Failed to get lighting render state, hr %#x.\n", hr);
4582 ok(rs == tests[i].d3drs_lighting, "D3DRENDERSTATE_LIGHTING is %#x, expected %#x.\n",
4583 rs, tests[i].d3drs_lighting);
4585 color = get_surface_color(rt, 320, 240);
4586 ok(compare_color(color, tests[i].color, 1),
4587 "Got unexpected color 0x%08x, expected 0x%08x, test %u.\n",
4588 color, tests[i].color, i);
4591 IDirectDrawSurface7_Release(rt);
4592 ref = IDirect3DDevice7_Release(device);
4593 ok(ref == 0, "Device not properly released, refcount %u.\n", ref);
4594 DestroyWindow(window);
4597 static struct
4599 BOOL received;
4600 IDirectDraw7 *ddraw;
4601 HWND window;
4602 DWORD coop_level;
4603 } activateapp_testdata;
4605 static LRESULT CALLBACK activateapp_test_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
4607 if (message == WM_ACTIVATEAPP)
4609 if (activateapp_testdata.ddraw)
4611 HRESULT hr;
4612 activateapp_testdata.received = FALSE;
4613 hr = IDirectDraw7_SetCooperativeLevel(activateapp_testdata.ddraw,
4614 activateapp_testdata.window, activateapp_testdata.coop_level);
4615 ok(SUCCEEDED(hr), "Recursive SetCooperativeLevel call failed, hr %#x.\n", hr);
4616 ok(!activateapp_testdata.received, "Received WM_ACTIVATEAPP during recursive SetCooperativeLevel call.\n");
4618 activateapp_testdata.received = TRUE;
4621 return DefWindowProcA(hwnd, message, wparam, lparam);
4624 static void test_coop_level_activateapp(void)
4626 IDirectDraw7 *ddraw;
4627 HRESULT hr;
4628 HWND window;
4629 WNDCLASSA wc = {0};
4630 DDSURFACEDESC2 ddsd;
4631 IDirectDrawSurface7 *surface;
4633 ddraw = create_ddraw();
4634 ok(!!ddraw, "Failed to create a ddraw object.\n");
4636 wc.lpfnWndProc = activateapp_test_proc;
4637 wc.lpszClassName = "ddraw_test_wndproc_wc";
4638 ok(RegisterClassA(&wc), "Failed to register window class.\n");
4640 window = CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
4641 WS_MAXIMIZE | WS_CAPTION , 0, 0, 640, 480, 0, 0, 0, 0);
4643 /* Exclusive with window already active. */
4644 SetForegroundWindow(window);
4645 activateapp_testdata.received = FALSE;
4646 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
4647 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4648 ok(!activateapp_testdata.received, "Received WM_ACTIVATEAPP although window was already active.\n");
4649 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
4650 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4652 /* Exclusive with window not active. */
4653 SetForegroundWindow(GetDesktopWindow());
4654 activateapp_testdata.received = FALSE;
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");
4658 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
4659 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4661 /* Normal with window not active, then exclusive with the same window. */
4662 SetForegroundWindow(GetDesktopWindow());
4663 activateapp_testdata.received = FALSE;
4664 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
4665 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4666 ok(!activateapp_testdata.received, "Received WM_ACTIVATEAPP when setting DDSCL_NORMAL.\n");
4667 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
4668 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4669 ok(activateapp_testdata.received, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
4670 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
4671 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4673 /* Recursive set of DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN. */
4674 SetForegroundWindow(GetDesktopWindow());
4675 activateapp_testdata.received = FALSE;
4676 activateapp_testdata.ddraw = ddraw;
4677 activateapp_testdata.window = window;
4678 activateapp_testdata.coop_level = DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN;
4679 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
4680 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4681 ok(activateapp_testdata.received, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
4682 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
4683 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4685 /* The recursive call seems to have some bad effect on native ddraw, despite (apparently)
4686 * succeeding. Another switch to exclusive and back to normal is needed to release the
4687 * window properly. Without doing this, SetCooperativeLevel(EXCLUSIVE) will not send
4688 * WM_ACTIVATEAPP messages. */
4689 activateapp_testdata.ddraw = NULL;
4690 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
4691 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4692 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
4693 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4695 /* Setting DDSCL_NORMAL with recursive invocation. */
4696 SetForegroundWindow(GetDesktopWindow());
4697 activateapp_testdata.received = FALSE;
4698 activateapp_testdata.ddraw = ddraw;
4699 activateapp_testdata.window = window;
4700 activateapp_testdata.coop_level = DDSCL_NORMAL;
4701 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
4702 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4703 ok(activateapp_testdata.received, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
4705 /* DDraw is in exclusive mode now. */
4706 memset(&ddsd, 0, sizeof(ddsd));
4707 ddsd.dwSize = sizeof(ddsd);
4708 ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
4709 U5(ddsd).dwBackBufferCount = 1;
4710 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
4711 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
4712 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4713 IDirectDrawSurface7_Release(surface);
4715 /* Recover again, just to be sure. */
4716 activateapp_testdata.ddraw = NULL;
4717 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
4718 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4719 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
4720 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4722 DestroyWindow(window);
4723 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL));
4724 IDirectDraw7_Release(ddraw);
4727 static void test_texturemanage(void)
4729 IDirectDraw7 *ddraw;
4730 HRESULT hr;
4731 DDSURFACEDESC2 ddsd;
4732 IDirectDrawSurface7 *surface;
4733 unsigned int i;
4734 DDCAPS hal_caps, hel_caps;
4735 DWORD needed_caps = DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY;
4736 static const struct
4738 DWORD caps_in, caps2_in;
4739 HRESULT hr;
4740 DWORD caps_out, caps2_out;
4742 tests[] =
4744 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
4745 ~0U, ~0U},
4746 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, DDERR_INVALIDCAPS,
4747 ~0U, ~0U},
4748 {DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
4749 ~0U, ~0U},
4750 {DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, DDERR_INVALIDCAPS,
4751 ~0U, ~0U},
4752 {DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, DD_OK,
4753 DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE},
4754 {DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, DD_OK,
4755 DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE},
4756 {DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE, 0, DD_OK,
4757 DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE | DDSCAPS_LOCALVIDMEM, 0},
4758 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, 0, DD_OK,
4759 DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, 0},
4761 {0, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
4762 ~0U, ~0U},
4763 {0, DDSCAPS2_D3DTEXTUREMANAGE, DDERR_INVALIDCAPS,
4764 ~0U, ~0U},
4765 {DDSCAPS_SYSTEMMEMORY, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
4766 ~0U, ~0U},
4767 {DDSCAPS_SYSTEMMEMORY, DDSCAPS2_D3DTEXTUREMANAGE, DDERR_INVALIDCAPS,
4768 ~0U, ~0U},
4769 {DDSCAPS_VIDEOMEMORY, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
4770 ~0U, ~0U},
4771 {DDSCAPS_VIDEOMEMORY, DDSCAPS2_D3DTEXTUREMANAGE, DDERR_INVALIDCAPS,
4772 ~0U, ~0U},
4773 {DDSCAPS_VIDEOMEMORY, 0, DD_OK,
4774 DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY, 0},
4775 {DDSCAPS_SYSTEMMEMORY, 0, DD_OK,
4776 DDSCAPS_SYSTEMMEMORY, 0},
4779 ddraw = create_ddraw();
4780 ok(!!ddraw, "Failed to create a ddraw object.\n");
4781 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
4782 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4784 memset(&hal_caps, 0, sizeof(hal_caps));
4785 hal_caps.dwSize = sizeof(hal_caps);
4786 memset(&hel_caps, 0, sizeof(hel_caps));
4787 hel_caps.dwSize = sizeof(hel_caps);
4788 hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, &hel_caps);
4789 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
4790 if ((hal_caps.ddsCaps.dwCaps & needed_caps) != needed_caps)
4792 skip("Managed textures not supported, skipping managed texture test.\n");
4793 IDirectDraw7_Release(ddraw);
4794 return;
4797 for (i = 0; i < ARRAY_SIZE(tests); ++i)
4799 memset(&ddsd, 0, sizeof(ddsd));
4800 ddsd.dwSize = sizeof(ddsd);
4801 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
4802 ddsd.ddsCaps.dwCaps = tests[i].caps_in;
4803 ddsd.ddsCaps.dwCaps2 = tests[i].caps2_in;
4804 ddsd.dwWidth = 4;
4805 ddsd.dwHeight = 4;
4807 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
4808 if (tests[i].hr == DD_OK && is_ddraw64 && (tests[i].caps_in & DDSCAPS_TEXTURE))
4809 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Got unexpected hr %#x.\n", i, hr);
4810 else
4811 ok(hr == tests[i].hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, tests[i].hr);
4812 if (FAILED(hr))
4813 continue;
4815 memset(&ddsd, 0, sizeof(ddsd));
4816 ddsd.dwSize = sizeof(ddsd);
4817 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd);
4818 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
4820 ok(ddsd.ddsCaps.dwCaps == tests[i].caps_out,
4821 "Input caps %#x, %#x, expected output caps %#x, got %#x, case %u.\n",
4822 tests[i].caps_in, tests[i].caps2_in, tests[i].caps_out, ddsd.ddsCaps.dwCaps, i);
4823 ok(ddsd.ddsCaps.dwCaps2 == tests[i].caps2_out,
4824 "Input caps %#x, %#x, expected output caps %#x, got %#x, case %u.\n",
4825 tests[i].caps_in, tests[i].caps2_in, tests[i].caps2_out, ddsd.ddsCaps.dwCaps2, i);
4827 IDirectDrawSurface7_Release(surface);
4830 IDirectDraw7_Release(ddraw);
4833 #define SUPPORT_DXT1 0x01
4834 #define SUPPORT_DXT2 0x02
4835 #define SUPPORT_DXT3 0x04
4836 #define SUPPORT_DXT4 0x08
4837 #define SUPPORT_DXT5 0x10
4838 #define SUPPORT_YUY2 0x20
4839 #define SUPPORT_UYVY 0x40
4841 static HRESULT WINAPI test_block_formats_creation_cb(DDPIXELFORMAT *fmt, void *ctx)
4843 DWORD *supported_fmts = ctx;
4845 if (!(fmt->dwFlags & DDPF_FOURCC))
4846 return DDENUMRET_OK;
4848 switch (fmt->dwFourCC)
4850 case MAKEFOURCC('D','X','T','1'):
4851 *supported_fmts |= SUPPORT_DXT1;
4852 break;
4853 case MAKEFOURCC('D','X','T','2'):
4854 *supported_fmts |= SUPPORT_DXT2;
4855 break;
4856 case MAKEFOURCC('D','X','T','3'):
4857 *supported_fmts |= SUPPORT_DXT3;
4858 break;
4859 case MAKEFOURCC('D','X','T','4'):
4860 *supported_fmts |= SUPPORT_DXT4;
4861 break;
4862 case MAKEFOURCC('D','X','T','5'):
4863 *supported_fmts |= SUPPORT_DXT5;
4864 break;
4865 case MAKEFOURCC('Y','U','Y','2'):
4866 *supported_fmts |= SUPPORT_YUY2;
4867 break;
4868 case MAKEFOURCC('U','Y','V','Y'):
4869 *supported_fmts |= SUPPORT_UYVY;
4870 break;
4871 default:
4872 break;
4875 return DDENUMRET_OK;
4878 static void test_block_formats_creation(void)
4880 HRESULT hr, expect_hr;
4881 unsigned int i, j, w, h;
4882 HWND window;
4883 IDirectDraw7 *ddraw;
4884 IDirect3D7 *d3d;
4885 IDirect3DDevice7 *device;
4886 IDirectDrawSurface7 *surface;
4887 DWORD supported_fmts = 0, supported_overlay_fmts = 0;
4888 DWORD num_fourcc_codes = 0, *fourcc_codes;
4889 DDSURFACEDESC2 ddsd;
4890 DDCAPS hal_caps;
4891 void *mem;
4893 static const struct
4895 DWORD fourcc;
4896 const char *name;
4897 DWORD support_flag;
4898 unsigned int block_width;
4899 unsigned int block_height;
4900 unsigned int block_size;
4901 BOOL create_size_checked, overlay;
4903 formats[] =
4905 {MAKEFOURCC('D','X','T','1'), "D3DFMT_DXT1", SUPPORT_DXT1, 4, 4, 8, TRUE, FALSE},
4906 {MAKEFOURCC('D','X','T','2'), "D3DFMT_DXT2", SUPPORT_DXT2, 4, 4, 16, TRUE, FALSE},
4907 {MAKEFOURCC('D','X','T','3'), "D3DFMT_DXT3", SUPPORT_DXT3, 4, 4, 16, TRUE, FALSE},
4908 {MAKEFOURCC('D','X','T','4'), "D3DFMT_DXT4", SUPPORT_DXT4, 4, 4, 16, TRUE, FALSE},
4909 {MAKEFOURCC('D','X','T','5'), "D3DFMT_DXT5", SUPPORT_DXT5, 4, 4, 16, TRUE, FALSE},
4910 {MAKEFOURCC('Y','U','Y','2'), "D3DFMT_YUY2", SUPPORT_YUY2, 2, 1, 4, FALSE, TRUE },
4911 {MAKEFOURCC('U','Y','V','Y'), "D3DFMT_UYVY", SUPPORT_UYVY, 2, 1, 4, FALSE, TRUE },
4913 static const struct
4915 DWORD caps, caps2;
4916 const char *name;
4917 BOOL overlay;
4919 types[] =
4921 /* DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY fails to create any fourcc
4922 * surface with DDERR_INVALIDPIXELFORMAT. Don't care about it for now.
4924 * Nvidia returns E_FAIL on DXTN DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY.
4925 * Other hw / drivers successfully create those surfaces. Ignore them, this
4926 * suggests that no game uses this, otherwise Nvidia would support it. */
4928 DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE, 0,
4929 "videomemory texture", FALSE
4932 DDSCAPS_VIDEOMEMORY | DDSCAPS_OVERLAY, 0,
4933 "videomemory overlay", TRUE
4936 DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, 0,
4937 "systemmemory texture", FALSE
4940 DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE,
4941 "managed texture", FALSE
4944 enum size_type
4946 SIZE_TYPE_ZERO,
4947 SIZE_TYPE_PITCH,
4948 SIZE_TYPE_SIZE,
4950 static const struct
4952 DWORD flags;
4953 enum size_type size_type;
4954 int rel_size;
4955 HRESULT hr;
4957 user_mem_tests[] =
4959 {DDSD_LINEARSIZE, SIZE_TYPE_ZERO, 0, DD_OK},
4960 {DDSD_LINEARSIZE, SIZE_TYPE_SIZE, 0, DD_OK},
4961 {DDSD_PITCH, SIZE_TYPE_ZERO, 0, DD_OK},
4962 {DDSD_PITCH, SIZE_TYPE_PITCH, 0, DD_OK},
4963 {DDSD_LPSURFACE, SIZE_TYPE_ZERO, 0, DDERR_INVALIDPARAMS},
4964 {DDSD_LPSURFACE | DDSD_LINEARSIZE, SIZE_TYPE_ZERO, 0, DDERR_INVALIDPARAMS},
4965 {DDSD_LPSURFACE | DDSD_LINEARSIZE, SIZE_TYPE_PITCH, 0, DDERR_INVALIDPARAMS},
4966 {DDSD_LPSURFACE | DDSD_LINEARSIZE, SIZE_TYPE_SIZE, 0, DD_OK},
4967 {DDSD_LPSURFACE | DDSD_LINEARSIZE, SIZE_TYPE_SIZE, 1, DD_OK},
4968 {DDSD_LPSURFACE | DDSD_LINEARSIZE, SIZE_TYPE_SIZE, -1, DDERR_INVALIDPARAMS},
4969 {DDSD_LPSURFACE | DDSD_PITCH, SIZE_TYPE_ZERO, 0, DDERR_INVALIDPARAMS},
4970 {DDSD_LPSURFACE | DDSD_PITCH, SIZE_TYPE_PITCH, 0, DDERR_INVALIDPARAMS},
4971 {DDSD_LPSURFACE | DDSD_PITCH, SIZE_TYPE_SIZE, 0, DDERR_INVALIDPARAMS},
4972 {DDSD_LPSURFACE | DDSD_PITCH | DDSD_LINEARSIZE, SIZE_TYPE_SIZE, 0, DDERR_INVALIDPARAMS},
4975 window = create_window();
4976 if (!(device = create_device(window, DDSCL_NORMAL)))
4978 skip("Failed to create a 3D device, skipping test.\n");
4979 DestroyWindow(window);
4980 return;
4983 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
4984 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
4985 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **) &ddraw);
4986 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
4987 IDirect3D7_Release(d3d);
4989 hr = IDirect3DDevice7_EnumTextureFormats(device, test_block_formats_creation_cb,
4990 &supported_fmts);
4991 ok(SUCCEEDED(hr), "Failed to enumerate texture formats %#x.\n", hr);
4993 hr = IDirectDraw7_GetFourCCCodes(ddraw, &num_fourcc_codes, NULL);
4994 ok(SUCCEEDED(hr), "Failed to get fourcc codes %#x.\n", hr);
4995 fourcc_codes = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
4996 num_fourcc_codes * sizeof(*fourcc_codes));
4997 if (!fourcc_codes)
4998 goto cleanup;
4999 hr = IDirectDraw7_GetFourCCCodes(ddraw, &num_fourcc_codes, fourcc_codes);
5000 ok(SUCCEEDED(hr), "Failed to get fourcc codes %#x.\n", hr);
5001 for (i = 0; i < num_fourcc_codes; i++)
5003 for (j = 0; j < ARRAY_SIZE(formats); ++j)
5005 if (fourcc_codes[i] == formats[j].fourcc)
5006 supported_overlay_fmts |= formats[j].support_flag;
5009 HeapFree(GetProcessHeap(), 0, fourcc_codes);
5011 memset(&hal_caps, 0, sizeof(hal_caps));
5012 hal_caps.dwSize = sizeof(hal_caps);
5013 hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, NULL);
5014 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
5016 mem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 2 * 2 * 16 + 1);
5018 for (i = 0; i < ARRAY_SIZE(formats); ++i)
5020 for (j = 0; j < ARRAY_SIZE(types); ++j)
5022 BOOL support;
5024 if (formats[i].overlay != types[j].overlay
5025 || (types[j].overlay && !(hal_caps.dwCaps & DDCAPS_OVERLAY)))
5026 continue;
5028 if (formats[i].overlay)
5029 support = supported_overlay_fmts & formats[i].support_flag;
5030 else
5031 support = supported_fmts & formats[i].support_flag;
5033 for (w = 1; w <= 8; w++)
5035 for (h = 1; h <= 8; h++)
5037 BOOL block_aligned = TRUE;
5038 BOOL todo = FALSE;
5040 if (w & (formats[i].block_width - 1) || h & (formats[i].block_height - 1))
5041 block_aligned = FALSE;
5043 memset(&ddsd, 0, sizeof(ddsd));
5044 ddsd.dwSize = sizeof(ddsd);
5045 ddsd.dwFlags = DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
5046 ddsd.ddsCaps.dwCaps = types[j].caps;
5047 ddsd.ddsCaps.dwCaps2 = types[j].caps2;
5048 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
5049 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_FOURCC;
5050 U4(ddsd).ddpfPixelFormat.dwFourCC = formats[i].fourcc;
5051 ddsd.dwWidth = w;
5052 ddsd.dwHeight = h;
5054 /* TODO: Handle power of two limitations. I cannot test the pow2
5055 * behavior on windows because I have no hardware that doesn't at
5056 * least support np2_conditional. There's probably no HW that
5057 * supports DXTN textures but no conditional np2 textures. */
5058 if (!support && !(types[j].caps & DDSCAPS_SYSTEMMEMORY))
5059 expect_hr = DDERR_INVALIDPARAMS;
5060 else if (formats[i].create_size_checked && !block_aligned)
5062 expect_hr = DDERR_INVALIDPARAMS;
5063 if (!(types[j].caps & DDSCAPS_TEXTURE))
5064 todo = TRUE;
5066 else
5067 expect_hr = D3D_OK;
5069 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
5070 todo_wine_if (todo)
5071 ok(hr == expect_hr,
5072 "Got unexpected hr %#x for format %s, resource type %s, size %ux%u, expected %#x.\n",
5073 hr, formats[i].name, types[j].name, w, h, expect_hr);
5075 if (SUCCEEDED(hr))
5076 IDirectDrawSurface7_Release(surface);
5081 if (formats[i].overlay)
5082 continue;
5084 for (j = 0; j < ARRAY_SIZE(user_mem_tests); ++j)
5086 memset(&ddsd, 0, sizeof(ddsd));
5087 ddsd.dwSize = sizeof(ddsd);
5088 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | user_mem_tests[j].flags;
5089 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE;
5091 switch (user_mem_tests[j].size_type)
5093 case SIZE_TYPE_ZERO:
5094 U1(ddsd).dwLinearSize = 0;
5095 break;
5097 case SIZE_TYPE_PITCH:
5098 U1(ddsd).dwLinearSize = 2 * formats[i].block_size;
5099 break;
5101 case SIZE_TYPE_SIZE:
5102 U1(ddsd).dwLinearSize = 2 * 2 * formats[i].block_size;
5103 break;
5105 U1(ddsd).dwLinearSize += user_mem_tests[j].rel_size;
5107 ddsd.lpSurface = mem;
5108 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
5109 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_FOURCC;
5110 U4(ddsd).ddpfPixelFormat.dwFourCC = formats[i].fourcc;
5111 ddsd.dwWidth = 8;
5112 ddsd.dwHeight = 8;
5114 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
5115 ok(hr == user_mem_tests[j].hr, "Test %u: Got unexpected hr %#x, format %s.\n", j, hr, formats[i].name);
5117 if (FAILED(hr))
5118 continue;
5120 memset(&ddsd, 0, sizeof(ddsd));
5121 ddsd.dwSize = sizeof(ddsd);
5122 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd);
5123 ok(SUCCEEDED(hr), "Test %u: Failed to get surface desc, hr %#x.\n", j, hr);
5124 ok(ddsd.dwFlags == (DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_LINEARSIZE),
5125 "Test %u: Got unexpected flags %#x.\n", j, ddsd.dwFlags);
5126 if (user_mem_tests[j].flags & DDSD_LPSURFACE)
5127 ok(U1(ddsd).dwLinearSize == ~0u, "Test %u: Got unexpected linear size %#x.\n",
5128 j, U1(ddsd).dwLinearSize);
5129 else
5130 ok(U1(ddsd).dwLinearSize == 2 * 2 * formats[i].block_size,
5131 "Test %u: Got unexpected linear size %#x, expected %#x.\n",
5132 j, U1(ddsd).dwLinearSize, 2 * 2 * formats[i].block_size);
5133 IDirectDrawSurface7_Release(surface);
5137 HeapFree(GetProcessHeap(), 0, mem);
5138 cleanup:
5139 IDirectDraw7_Release(ddraw);
5140 IDirect3DDevice7_Release(device);
5141 DestroyWindow(window);
5144 struct format_support_check
5146 const DDPIXELFORMAT *format;
5147 BOOL supported;
5150 static HRESULT WINAPI test_unsupported_formats_cb(DDPIXELFORMAT *fmt, void *ctx)
5152 struct format_support_check *format = ctx;
5154 if (!memcmp(format->format, fmt, sizeof(*fmt)))
5156 format->supported = TRUE;
5157 return DDENUMRET_CANCEL;
5160 return DDENUMRET_OK;
5163 static void test_unsupported_formats(void)
5165 HRESULT hr;
5166 BOOL expect_success;
5167 HWND window;
5168 IDirectDraw7 *ddraw;
5169 IDirect3D7 *d3d;
5170 IDirect3DDevice7 *device;
5171 IDirectDrawSurface7 *surface;
5172 DDSURFACEDESC2 ddsd;
5173 unsigned int i, j;
5174 DWORD expected_caps;
5175 static const struct
5177 const char *name;
5178 DDPIXELFORMAT fmt;
5180 formats[] =
5183 "D3DFMT_A8R8G8B8",
5185 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
5186 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
5190 "D3DFMT_P8",
5192 sizeof(DDPIXELFORMAT), DDPF_PALETTEINDEXED8 | DDPF_RGB, 0,
5193 {8 }, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}
5197 static const DWORD caps[] = {0, DDSCAPS_SYSTEMMEMORY, DDSCAPS_VIDEOMEMORY};
5199 window = create_window();
5200 if (!(device = create_device(window, DDSCL_NORMAL)))
5202 skip("Failed to create a 3D device, skipping test.\n");
5203 DestroyWindow(window);
5204 return;
5207 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
5208 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
5209 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **) &ddraw);
5210 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
5211 IDirect3D7_Release(d3d);
5213 for (i = 0; i < ARRAY_SIZE(formats); ++i)
5215 struct format_support_check check = {&formats[i].fmt, FALSE};
5216 hr = IDirect3DDevice7_EnumTextureFormats(device, test_unsupported_formats_cb, &check);
5217 ok(SUCCEEDED(hr), "Failed to enumerate texture formats %#x.\n", hr);
5219 for (j = 0; j < ARRAY_SIZE(caps); ++j)
5221 memset(&ddsd, 0, sizeof(ddsd));
5222 ddsd.dwSize = sizeof(ddsd);
5223 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
5224 U4(ddsd).ddpfPixelFormat = formats[i].fmt;
5225 ddsd.dwWidth = 4;
5226 ddsd.dwHeight = 4;
5227 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | caps[j];
5229 if (caps[j] & DDSCAPS_VIDEOMEMORY && !check.supported)
5230 expect_success = FALSE;
5231 else
5232 expect_success = TRUE;
5234 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
5235 ok(SUCCEEDED(hr) == expect_success,
5236 "Got unexpected hr %#x for format %s, caps %#x, expected %s.\n",
5237 hr, formats[i].name, caps[j], expect_success ? "success" : "failure");
5238 if (FAILED(hr))
5239 continue;
5241 memset(&ddsd, 0, sizeof(ddsd));
5242 ddsd.dwSize = sizeof(ddsd);
5243 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd);
5244 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
5246 if (caps[j] & DDSCAPS_VIDEOMEMORY)
5247 expected_caps = DDSCAPS_VIDEOMEMORY;
5248 else if (caps[j] & DDSCAPS_SYSTEMMEMORY)
5249 expected_caps = DDSCAPS_SYSTEMMEMORY;
5250 else if (check.supported)
5251 expected_caps = DDSCAPS_VIDEOMEMORY;
5252 else
5253 expected_caps = DDSCAPS_SYSTEMMEMORY;
5255 ok(ddsd.ddsCaps.dwCaps & expected_caps,
5256 "Expected capability %#x, format %s, input cap %#x.\n",
5257 expected_caps, formats[i].name, caps[j]);
5259 IDirectDrawSurface7_Release(surface);
5263 IDirectDraw7_Release(ddraw);
5264 IDirect3DDevice7_Release(device);
5265 DestroyWindow(window);
5268 static void test_rt_caps(void)
5270 const GUID *devtype = &IID_IDirect3DHALDevice;
5271 PALETTEENTRY palette_entries[256];
5272 IDirectDrawPalette *palette;
5273 IDirectDraw7 *ddraw;
5274 BOOL hal_ok = FALSE;
5275 DDPIXELFORMAT z_fmt;
5276 IDirect3D7 *d3d;
5277 unsigned int i;
5278 ULONG refcount;
5279 HWND window;
5280 HRESULT hr;
5282 static const DDPIXELFORMAT p8_fmt =
5284 sizeof(DDPIXELFORMAT), DDPF_PALETTEINDEXED8 | DDPF_RGB, 0,
5285 {8}, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000},
5288 const struct
5290 const DDPIXELFORMAT *pf;
5291 DWORD caps_in;
5292 DWORD caps_out;
5293 HRESULT create_device_hr;
5294 HRESULT set_rt_hr, alternative_set_rt_hr;
5296 test_data[] =
5299 NULL,
5300 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY,
5301 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
5302 D3D_OK,
5303 D3D_OK,
5304 D3D_OK,
5307 NULL,
5308 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE,
5309 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
5310 D3D_OK,
5311 D3D_OK,
5312 D3D_OK,
5315 NULL,
5316 DDSCAPS_OFFSCREENPLAIN,
5317 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
5318 DDERR_INVALIDCAPS,
5319 DDERR_INVALIDCAPS,
5320 DDERR_INVALIDCAPS,
5323 NULL,
5324 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
5325 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
5326 D3DERR_SURFACENOTINVIDMEM,
5327 DDERR_INVALIDPARAMS,
5328 D3D_OK,
5331 NULL,
5332 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
5333 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
5334 DDERR_INVALIDCAPS,
5335 DDERR_INVALIDCAPS,
5336 DDERR_INVALIDCAPS,
5339 NULL,
5340 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY,
5341 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
5342 D3D_OK,
5343 D3D_OK,
5344 D3D_OK,
5347 NULL,
5348 DDSCAPS_3DDEVICE,
5349 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
5350 D3D_OK,
5351 D3D_OK,
5352 D3D_OK,
5355 NULL,
5357 DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
5358 DDERR_INVALIDCAPS,
5359 DDERR_INVALIDCAPS,
5360 DDERR_INVALIDCAPS,
5363 NULL,
5364 DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
5365 DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
5366 D3DERR_SURFACENOTINVIDMEM,
5367 DDERR_INVALIDPARAMS,
5368 D3D_OK,
5371 NULL,
5372 DDSCAPS_SYSTEMMEMORY,
5373 DDSCAPS_SYSTEMMEMORY,
5374 DDERR_INVALIDCAPS,
5375 DDERR_INVALIDCAPS,
5376 DDERR_INVALIDCAPS,
5379 &p8_fmt,
5381 DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
5382 DDERR_INVALIDCAPS,
5383 DDERR_INVALIDCAPS,
5384 DDERR_INVALIDCAPS,
5387 &p8_fmt,
5388 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE,
5389 ~0U /* AMD r200 */,
5390 DDERR_NOPALETTEATTACHED,
5391 DDERR_INVALIDCAPS,
5392 DDERR_INVALIDCAPS,
5395 &p8_fmt,
5396 DDSCAPS_OFFSCREENPLAIN,
5397 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
5398 DDERR_INVALIDCAPS,
5399 DDERR_INVALIDCAPS,
5400 DDERR_INVALIDCAPS,
5403 &p8_fmt,
5404 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
5405 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
5406 DDERR_NOPALETTEATTACHED,
5407 DDERR_INVALIDCAPS,
5408 DDERR_INVALIDCAPS,
5411 &p8_fmt,
5412 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
5413 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
5414 DDERR_INVALIDCAPS,
5415 DDERR_INVALIDCAPS,
5416 DDERR_INVALIDCAPS,
5419 &z_fmt,
5420 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_ZBUFFER,
5421 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_ZBUFFER | DDSCAPS_LOCALVIDMEM,
5422 DDERR_INVALIDCAPS,
5423 DDERR_INVALIDPIXELFORMAT,
5424 DDERR_INVALIDPIXELFORMAT,
5427 &z_fmt,
5428 DDSCAPS_3DDEVICE | DDSCAPS_ZBUFFER,
5429 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_ZBUFFER | DDSCAPS_LOCALVIDMEM,
5430 DDERR_INVALIDCAPS,
5431 DDERR_INVALIDPIXELFORMAT,
5432 DDERR_INVALIDPIXELFORMAT,
5435 &z_fmt,
5436 DDSCAPS_ZBUFFER,
5437 DDSCAPS_VIDEOMEMORY | DDSCAPS_ZBUFFER | DDSCAPS_LOCALVIDMEM,
5438 DDERR_INVALIDCAPS,
5439 DDERR_INVALIDCAPS,
5440 DDERR_INVALIDCAPS,
5443 &z_fmt,
5444 DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE | DDSCAPS_ZBUFFER,
5445 DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE | DDSCAPS_ZBUFFER,
5446 DDERR_INVALIDCAPS,
5447 DDERR_INVALIDPARAMS,
5448 DDERR_INVALIDPIXELFORMAT,
5451 &z_fmt,
5452 DDSCAPS_SYSTEMMEMORY | DDSCAPS_ZBUFFER,
5453 DDSCAPS_SYSTEMMEMORY | DDSCAPS_ZBUFFER,
5454 DDERR_INVALIDCAPS,
5455 DDERR_INVALIDCAPS,
5456 DDERR_INVALIDCAPS,
5460 window = create_window();
5461 ddraw = create_ddraw();
5462 ok(!!ddraw, "Failed to create a ddraw object.\n");
5463 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
5464 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5466 if (FAILED(IDirectDraw7_QueryInterface(ddraw, &IID_IDirect3D7, (void **)&d3d)))
5468 skip("D3D interface is not available, skipping test.\n");
5469 goto done;
5472 hr = IDirect3D7_EnumDevices(d3d, enum_devtype_cb, &hal_ok);
5473 ok(SUCCEEDED(hr), "Failed to enumerate devices, hr %#x.\n", hr);
5474 if (hal_ok)
5475 devtype = &IID_IDirect3DTnLHalDevice;
5477 memset(&z_fmt, 0, sizeof(z_fmt));
5478 hr = IDirect3D7_EnumZBufferFormats(d3d, devtype, enum_z_fmt, &z_fmt);
5479 if (FAILED(hr) || !z_fmt.dwSize)
5481 skip("No depth buffer formats available, skipping test.\n");
5482 IDirect3D7_Release(d3d);
5483 goto done;
5486 memset(palette_entries, 0, sizeof(palette_entries));
5487 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, palette_entries, &palette, NULL);
5488 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
5490 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
5492 IDirectDrawSurface7 *surface, *rt, *expected_rt, *tmp;
5493 DDSURFACEDESC2 surface_desc;
5494 IDirect3DDevice7 *device;
5496 memset(&surface_desc, 0, sizeof(surface_desc));
5497 surface_desc.dwSize = sizeof(surface_desc);
5498 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
5499 surface_desc.ddsCaps.dwCaps = test_data[i].caps_in;
5500 if (test_data[i].pf)
5502 surface_desc.dwFlags |= DDSD_PIXELFORMAT;
5503 U4(surface_desc).ddpfPixelFormat = *test_data[i].pf;
5505 surface_desc.dwWidth = 640;
5506 surface_desc.dwHeight = 480;
5507 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
5508 ok(SUCCEEDED(hr), "Test %u: Failed to create surface with caps %#x, hr %#x.\n",
5509 i, test_data[i].caps_in, hr);
5511 memset(&surface_desc, 0, sizeof(surface_desc));
5512 surface_desc.dwSize = sizeof(surface_desc);
5513 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &surface_desc);
5514 ok(SUCCEEDED(hr), "Test %u: Failed to get surface desc, hr %#x.\n", i, hr);
5515 ok(test_data[i].caps_out == ~0U || surface_desc.ddsCaps.dwCaps == test_data[i].caps_out,
5516 "Test %u: Got unexpected caps %#x, expected %#x.\n",
5517 i, surface_desc.ddsCaps.dwCaps, test_data[i].caps_out);
5519 hr = IDirect3D7_CreateDevice(d3d, devtype, surface, &device);
5520 ok(hr == test_data[i].create_device_hr, "Test %u: Got unexpected hr %#x, expected %#x.\n",
5521 i, hr, test_data[i].create_device_hr);
5522 if (FAILED(hr))
5524 if (hr == DDERR_NOPALETTEATTACHED)
5526 hr = IDirectDrawSurface7_SetPalette(surface, palette);
5527 ok(SUCCEEDED(hr), "Test %u: Failed to set palette, hr %#x.\n", i, hr);
5528 hr = IDirect3D7_CreateDevice(d3d, devtype, surface, &device);
5529 if (surface_desc.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY)
5530 ok(hr == DDERR_INVALIDPIXELFORMAT, "Test %u: Got unexpected hr %#x.\n", i, hr);
5531 else
5532 ok(hr == D3DERR_SURFACENOTINVIDMEM, "Test %u: Got unexpected hr %#x.\n", i, hr);
5534 IDirectDrawSurface7_Release(surface);
5536 memset(&surface_desc, 0, sizeof(surface_desc));
5537 surface_desc.dwSize = sizeof(surface_desc);
5538 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
5539 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
5540 surface_desc.dwWidth = 640;
5541 surface_desc.dwHeight = 480;
5542 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
5543 ok(SUCCEEDED(hr), "Test %u: Failed to create surface, hr %#x.\n", i, hr);
5545 hr = IDirect3D7_CreateDevice(d3d, devtype, surface, &device);
5546 ok(SUCCEEDED(hr), "Test %u: Failed to create device, hr %#x.\n", i, hr);
5549 memset(&surface_desc, 0, sizeof(surface_desc));
5550 surface_desc.dwSize = sizeof(surface_desc);
5551 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
5552 surface_desc.ddsCaps.dwCaps = test_data[i].caps_in;
5553 if (test_data[i].pf)
5555 surface_desc.dwFlags |= DDSD_PIXELFORMAT;
5556 U4(surface_desc).ddpfPixelFormat = *test_data[i].pf;
5558 surface_desc.dwWidth = 640;
5559 surface_desc.dwHeight = 480;
5560 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &rt, NULL);
5561 ok(SUCCEEDED(hr), "Test %u: Failed to create surface with caps %#x, hr %#x.\n",
5562 i, test_data[i].caps_in, hr);
5564 hr = IDirect3DDevice7_SetRenderTarget(device, rt, 0);
5565 ok(hr == test_data[i].set_rt_hr || broken(hr == test_data[i].alternative_set_rt_hr),
5566 "Test %u: Got unexpected hr %#x, expected %#x.\n",
5567 i, hr, test_data[i].set_rt_hr);
5568 if (SUCCEEDED(hr) || hr == DDERR_INVALIDPIXELFORMAT)
5569 expected_rt = rt;
5570 else
5571 expected_rt = surface;
5573 hr = IDirect3DDevice7_GetRenderTarget(device, &tmp);
5574 ok(SUCCEEDED(hr), "Test %u: Failed to get render target, hr %#x.\n", i, hr);
5575 ok(tmp == expected_rt, "Test %u: Got unexpected rt %p.\n", i, tmp);
5577 IDirectDrawSurface7_Release(tmp);
5578 IDirectDrawSurface7_Release(rt);
5579 refcount = IDirect3DDevice7_Release(device);
5580 ok(refcount == 0, "Test %u: The device was not properly freed, refcount %u.\n", i, refcount);
5581 refcount = IDirectDrawSurface7_Release(surface);
5582 ok(refcount == 0, "Test %u: The surface was not properly freed, refcount %u.\n", i, refcount);
5585 IDirectDrawPalette_Release(palette);
5586 IDirect3D7_Release(d3d);
5588 done:
5589 refcount = IDirectDraw7_Release(ddraw);
5590 ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount);
5591 DestroyWindow(window);
5594 static void test_primary_caps(void)
5596 const DWORD placement = DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY | DDSCAPS_SYSTEMMEMORY;
5597 IDirectDrawSurface7 *surface;
5598 DDSURFACEDESC2 surface_desc;
5599 IDirectDraw7 *ddraw;
5600 unsigned int i;
5601 ULONG refcount;
5602 HWND window;
5603 HRESULT hr;
5605 static const struct
5607 DWORD coop_level;
5608 DWORD caps_in;
5609 DWORD back_buffer_count;
5610 HRESULT hr;
5611 DWORD caps_out;
5613 test_data[] =
5616 DDSCL_NORMAL,
5617 DDSCAPS_PRIMARYSURFACE,
5618 ~0u,
5619 DD_OK,
5620 DDSCAPS_VISIBLE | DDSCAPS_PRIMARYSURFACE,
5623 DDSCL_NORMAL,
5624 DDSCAPS_PRIMARYSURFACE | DDSCAPS_TEXTURE,
5625 ~0u,
5626 DDERR_INVALIDCAPS,
5627 ~0u,
5630 DDSCL_NORMAL,
5631 DDSCAPS_PRIMARYSURFACE | DDSCAPS_FRONTBUFFER,
5632 ~0u,
5633 DDERR_INVALIDCAPS,
5634 ~0u,
5637 DDSCL_NORMAL,
5638 DDSCAPS_PRIMARYSURFACE | DDSCAPS_BACKBUFFER,
5639 ~0u,
5640 DDERR_INVALIDCAPS,
5641 ~0u,
5644 DDSCL_NORMAL,
5645 DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP,
5646 ~0u,
5647 DDERR_INVALIDCAPS,
5648 ~0u,
5651 DDSCL_NORMAL,
5652 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX,
5653 ~0u,
5654 DDERR_INVALIDCAPS,
5655 ~0u,
5658 DDSCL_NORMAL,
5659 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
5660 ~0u,
5661 DDERR_INVALIDCAPS,
5662 ~0u,
5665 DDSCL_NORMAL,
5666 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
5668 DDERR_INVALIDCAPS,
5669 ~0u,
5672 DDSCL_NORMAL,
5673 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
5675 DDERR_NOEXCLUSIVEMODE,
5676 ~0u,
5679 DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN,
5680 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
5682 DDERR_INVALIDCAPS,
5683 ~0u,
5686 DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN,
5687 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
5689 DD_OK,
5690 DDSCAPS_VISIBLE | DDSCAPS_PRIMARYSURFACE | DDSCAPS_FRONTBUFFER | DDSCAPS_FLIP | DDSCAPS_COMPLEX,
5693 DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN,
5694 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP | DDSCAPS_FRONTBUFFER,
5696 DDERR_INVALIDCAPS,
5697 ~0u,
5700 DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN,
5701 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP | DDSCAPS_BACKBUFFER,
5703 DDERR_INVALIDCAPS,
5704 ~0u,
5708 window = create_window();
5709 ddraw = create_ddraw();
5710 ok(!!ddraw, "Failed to create a ddraw object.\n");
5712 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
5714 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, test_data[i].coop_level);
5715 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5717 memset(&surface_desc, 0, sizeof(surface_desc));
5718 surface_desc.dwSize = sizeof(surface_desc);
5719 surface_desc.dwFlags = DDSD_CAPS;
5720 if (test_data[i].back_buffer_count != ~0u)
5721 surface_desc.dwFlags |= DDSD_BACKBUFFERCOUNT;
5722 surface_desc.ddsCaps.dwCaps = test_data[i].caps_in;
5723 U5(surface_desc).dwBackBufferCount = test_data[i].back_buffer_count;
5724 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
5725 ok(hr == test_data[i].hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, test_data[i].hr);
5726 if (FAILED(hr))
5727 continue;
5729 memset(&surface_desc, 0, sizeof(surface_desc));
5730 surface_desc.dwSize = sizeof(surface_desc);
5731 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &surface_desc);
5732 ok(SUCCEEDED(hr), "Test %u: Failed to get surface desc, hr %#x.\n", i, hr);
5733 ok((surface_desc.ddsCaps.dwCaps & ~placement) == test_data[i].caps_out,
5734 "Test %u: Got unexpected caps %#x, expected %#x.\n",
5735 i, surface_desc.ddsCaps.dwCaps, test_data[i].caps_out);
5737 IDirectDrawSurface7_Release(surface);
5740 refcount = IDirectDraw7_Release(ddraw);
5741 ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount);
5742 DestroyWindow(window);
5745 static void test_surface_lock(void)
5747 IDirectDraw7 *ddraw;
5748 IDirect3D7 *d3d = NULL;
5749 IDirectDrawSurface7 *surface;
5750 IDirect3DDevice7 *device;
5751 HRESULT hr, expected_hr;
5752 HWND window;
5753 unsigned int i;
5754 DDSURFACEDESC2 ddsd;
5755 ULONG refcount;
5756 DDPIXELFORMAT z_fmt;
5757 BOOL hal_ok = FALSE;
5758 const GUID *devtype = &IID_IDirect3DHALDevice;
5759 D3DDEVICEDESC7 device_desc;
5760 BOOL cubemap_supported;
5761 static const struct
5763 DWORD caps;
5764 DWORD caps2;
5765 const char *name;
5767 tests[] =
5770 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY,
5772 "videomemory offscreenplain"
5775 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
5777 "systemmemory offscreenplain"
5780 DDSCAPS_PRIMARYSURFACE,
5782 "primary"
5785 DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY,
5787 "videomemory texture"
5790 DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY,
5791 DDSCAPS2_OPAQUE,
5792 "opaque videomemory texture"
5795 DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY,
5797 "systemmemory texture"
5800 DDSCAPS_TEXTURE,
5801 DDSCAPS2_TEXTUREMANAGE,
5802 "managed texture"
5805 DDSCAPS_TEXTURE,
5806 DDSCAPS2_D3DTEXTUREMANAGE,
5807 "managed texture"
5810 DDSCAPS_TEXTURE,
5811 DDSCAPS2_TEXTUREMANAGE | DDSCAPS2_OPAQUE,
5812 "opaque managed texture"
5815 DDSCAPS_TEXTURE,
5816 DDSCAPS2_D3DTEXTUREMANAGE | DDSCAPS2_OPAQUE,
5817 "opaque managed texture"
5820 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE,
5822 "render target"
5825 DDSCAPS_ZBUFFER,
5827 "Z buffer"
5830 DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_VIDEOMEMORY,
5831 DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES,
5832 "videomemory cube"
5835 DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_VIDEOMEMORY,
5836 DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES | DDSCAPS2_OPAQUE,
5837 "opaque videomemory cube"
5840 DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_SYSTEMMEMORY,
5841 DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES,
5842 "systemmemory cube"
5845 DDSCAPS_TEXTURE | DDSCAPS_COMPLEX,
5846 DDSCAPS2_TEXTUREMANAGE | DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES,
5847 "managed cube"
5850 DDSCAPS_TEXTURE | DDSCAPS_COMPLEX,
5851 DDSCAPS2_D3DTEXTUREMANAGE | DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES,
5852 "managed cube"
5855 DDSCAPS_TEXTURE | DDSCAPS_COMPLEX,
5856 DDSCAPS2_TEXTUREMANAGE | DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES | DDSCAPS2_OPAQUE,
5857 "opaque managed cube"
5860 DDSCAPS_TEXTURE | DDSCAPS_COMPLEX,
5861 DDSCAPS2_D3DTEXTUREMANAGE | DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES | DDSCAPS2_OPAQUE,
5862 "opaque managed cube"
5866 window = create_window();
5867 ddraw = create_ddraw();
5868 ok(!!ddraw, "Failed to create a ddraw object.\n");
5869 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
5870 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5872 if (FAILED(IDirectDraw7_QueryInterface(ddraw, &IID_IDirect3D7, (void **)&d3d)))
5874 skip("D3D interface is not available, skipping test.\n");
5875 goto done;
5878 hr = IDirect3D7_EnumDevices(d3d, enum_devtype_cb, &hal_ok);
5879 ok(SUCCEEDED(hr), "Failed to enumerate devices, hr %#x.\n", hr);
5880 if (hal_ok)
5881 devtype = &IID_IDirect3DTnLHalDevice;
5883 memset(&z_fmt, 0, sizeof(z_fmt));
5884 hr = IDirect3D7_EnumZBufferFormats(d3d, devtype, enum_z_fmt, &z_fmt);
5885 if (FAILED(hr) || !z_fmt.dwSize)
5887 skip("No depth buffer formats available, skipping test.\n");
5888 goto done;
5891 memset(&ddsd, 0, sizeof(ddsd));
5892 ddsd.dwSize = sizeof(ddsd);
5893 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
5894 ddsd.dwWidth = 64;
5895 ddsd.dwHeight = 64;
5896 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
5897 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
5898 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5900 hr = IDirect3D7_CreateDevice(d3d, devtype, surface, &device);
5901 ok(SUCCEEDED(hr), "Failed to create device, hr %#x.\n", hr);
5902 hr = IDirect3DDevice7_GetCaps(device, &device_desc);
5903 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
5904 cubemap_supported = !!(device_desc.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_CUBEMAP);
5905 IDirect3DDevice7_Release(device);
5907 IDirectDrawSurface7_Release(surface);
5909 for (i = 0; i < ARRAY_SIZE(tests); ++i)
5911 if (!cubemap_supported && tests[i].caps2 & DDSCAPS2_CUBEMAP)
5912 continue;
5914 memset(&ddsd, 0, sizeof(ddsd));
5915 ddsd.dwSize = sizeof(ddsd);
5916 ddsd.dwFlags = DDSD_CAPS;
5917 if (!(tests[i].caps & DDSCAPS_PRIMARYSURFACE))
5919 ddsd.dwFlags |= DDSD_WIDTH | DDSD_HEIGHT;
5920 ddsd.dwWidth = 64;
5921 ddsd.dwHeight = 64;
5923 if (tests[i].caps & DDSCAPS_ZBUFFER)
5925 ddsd.dwFlags |= DDSD_PIXELFORMAT;
5926 U4(ddsd).ddpfPixelFormat = z_fmt;
5928 ddsd.ddsCaps.dwCaps = tests[i].caps;
5929 ddsd.ddsCaps.dwCaps2 = tests[i].caps2;
5931 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
5932 ok(SUCCEEDED(hr), "Failed to create surface, type %s, hr %#x.\n", tests[i].name, hr);
5934 memset(&ddsd, 0, sizeof(ddsd));
5935 ddsd.dwSize = sizeof(ddsd);
5936 hr = IDirectDrawSurface7_Lock(surface, NULL, &ddsd, DDLOCK_WAIT, NULL);
5937 ok(SUCCEEDED(hr), "Failed to lock surface, type %s, hr %#x.\n", tests[i].name, hr);
5938 if (SUCCEEDED(hr))
5940 ok(ddsd.dwSize == sizeof(ddsd), "Got unexpected dwSize %u, type %s.\n", ddsd.dwSize, tests[i].name);
5941 hr = IDirectDrawSurface7_Unlock(surface, NULL);
5942 ok(SUCCEEDED(hr), "Failed to unlock surface, type %s, hr %#x.\n", tests[i].name, hr);
5945 memset(&ddsd, 0, sizeof(ddsd));
5946 expected_hr = tests[i].caps & DDSCAPS_TEXTURE && !(tests[i].caps & DDSCAPS_VIDEOMEMORY)
5947 ? DD_OK : DDERR_INVALIDPARAMS;
5948 hr = IDirectDrawSurface7_Lock(surface, NULL, &ddsd, DDLOCK_WAIT, NULL);
5949 ok(hr == expected_hr, "Got hr %#x, expected %#x, type %s.\n", hr, expected_hr, tests[i].name);
5950 if (SUCCEEDED(hr))
5952 ok(!ddsd.dwSize, "Got unexpected dwSize %u, type %s.\n", ddsd.dwSize, tests[i].name);
5953 ok(!!ddsd.lpSurface, "Got NULL lpSurface, type %s.\n", tests[i].name);
5954 hr = IDirectDrawSurface7_Unlock(surface, NULL);
5955 ok(SUCCEEDED(hr), "Failed to unlock surface, type %s, hr %#x.\n", tests[i].name, hr);
5958 IDirectDrawSurface7_Release(surface);
5961 done:
5962 if (d3d)
5963 IDirect3D7_Release(d3d);
5964 refcount = IDirectDraw7_Release(ddraw);
5965 ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount);
5966 DestroyWindow(window);
5969 static void test_surface_discard(void)
5971 IDirect3DDevice7 *device;
5972 IDirect3D7 *d3d;
5973 IDirectDraw7 *ddraw;
5974 HRESULT hr;
5975 HWND window;
5976 DDSURFACEDESC2 ddsd;
5977 IDirectDrawSurface7 *surface, *target;
5978 void *addr;
5979 static const struct
5981 DWORD caps, caps2;
5982 BOOL discard;
5984 tests[] =
5986 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0, TRUE},
5987 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY, 0, FALSE},
5988 {DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, 0, TRUE},
5989 {DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, 0, FALSE},
5990 {DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, FALSE},
5991 {DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE | DDSCAPS2_HINTDYNAMIC, FALSE},
5992 {DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, FALSE},
5993 {DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE | DDSCAPS2_HINTDYNAMIC, FALSE},
5995 unsigned int i;
5997 window = create_window();
5998 if (!(device = create_device(window, DDSCL_NORMAL)))
6000 skip("Failed to create a 3D device, skipping test.\n");
6001 DestroyWindow(window);
6002 return;
6004 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
6005 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
6006 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
6007 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
6008 hr = IDirect3DDevice7_GetRenderTarget(device, &target);
6009 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
6011 for (i = 0; i < ARRAY_SIZE(tests); ++i)
6013 BOOL discarded;
6015 memset(&ddsd, 0, sizeof(ddsd));
6016 ddsd.dwSize = sizeof(ddsd);
6017 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
6018 ddsd.ddsCaps.dwCaps = tests[i].caps;
6019 ddsd.ddsCaps.dwCaps2 = tests[i].caps2;
6020 ddsd.dwWidth = 64;
6021 ddsd.dwHeight = 64;
6022 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
6023 ok(SUCCEEDED(hr), "Failed to create offscreen surface, hr %#x, case %u.\n", hr, i);
6025 memset(&ddsd, 0, sizeof(ddsd));
6026 ddsd.dwSize = sizeof(ddsd);
6027 hr = IDirectDrawSurface7_Lock(surface, NULL, &ddsd, 0, NULL);
6028 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
6029 addr = ddsd.lpSurface;
6030 hr = IDirectDrawSurface7_Unlock(surface, NULL);
6031 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
6033 memset(&ddsd, 0, sizeof(ddsd));
6034 ddsd.dwSize = sizeof(ddsd);
6035 hr = IDirectDrawSurface7_Lock(surface, NULL, &ddsd, DDLOCK_DISCARDCONTENTS, NULL);
6036 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
6037 discarded = ddsd.lpSurface != addr;
6038 hr = IDirectDrawSurface7_Unlock(surface, NULL);
6039 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
6041 hr = IDirectDrawSurface7_Blt(target, NULL, surface, NULL, DDBLT_WAIT, NULL);
6042 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
6044 memset(&ddsd, 0, sizeof(ddsd));
6045 ddsd.dwSize = sizeof(ddsd);
6046 hr = IDirectDrawSurface7_Lock(surface, NULL, &ddsd, DDLOCK_DISCARDCONTENTS, NULL);
6047 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
6048 discarded |= ddsd.lpSurface != addr;
6049 hr = IDirectDrawSurface7_Unlock(surface, NULL);
6050 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
6052 IDirectDrawSurface7_Release(surface);
6054 /* Windows 7 reliably changes the address of surfaces that are discardable (Nvidia Kepler,
6055 * AMD r500, evergreen). Windows XP, at least on AMD r200, does not. */
6056 ok(!discarded || tests[i].discard, "Expected surface not to be discarded, case %u\n", i);
6059 IDirectDrawSurface7_Release(target);
6060 IDirectDraw7_Release(ddraw);
6061 IDirect3D7_Release(d3d);
6062 IDirect3DDevice7_Release(device);
6063 DestroyWindow(window);
6066 static void fill_surface(IDirectDrawSurface7 *surface, D3DCOLOR color)
6068 DDSURFACEDESC2 surface_desc = {sizeof(surface_desc)};
6069 HRESULT hr;
6070 unsigned int x, y;
6071 DWORD *ptr;
6073 hr = IDirectDrawSurface7_Lock(surface, NULL, &surface_desc, DDLOCK_WAIT, NULL);
6074 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
6076 for (y = 0; y < surface_desc.dwHeight; ++y)
6078 ptr = (DWORD *)((BYTE *)surface_desc.lpSurface + y * surface_desc.lPitch);
6079 for (x = 0; x < surface_desc.dwWidth; ++x)
6081 ptr[x] = color;
6085 hr = IDirectDrawSurface7_Unlock(surface, NULL);
6086 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
6089 static void test_flip(void)
6091 const DWORD placement = DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY | DDSCAPS_SYSTEMMEMORY;
6092 IDirectDrawSurface7 *frontbuffer, *backbuffer1, *backbuffer2, *backbuffer3, *surface;
6093 DDSCAPS2 caps = {DDSCAPS_FLIP, 0, 0, {0}};
6094 DDSURFACEDESC2 surface_desc;
6095 D3DDEVICEDESC7 device_desc;
6096 IDirect3DDevice7 *device;
6097 BOOL sysmem_primary;
6098 IDirectDraw7 *ddraw;
6099 DWORD expected_caps;
6100 unsigned int i;
6101 D3DCOLOR color;
6102 ULONG refcount;
6103 HWND window;
6104 HRESULT hr;
6106 static const struct
6108 const char *name;
6109 DWORD caps;
6111 test_data[] =
6113 {"PRIMARYSURFACE", DDSCAPS_PRIMARYSURFACE},
6114 {"OFFSCREENPLAIN", DDSCAPS_OFFSCREENPLAIN},
6115 {"TEXTURE", DDSCAPS_TEXTURE},
6118 window = create_window();
6119 ddraw = create_ddraw();
6120 ok(!!ddraw, "Failed to create a ddraw object.\n");
6122 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
6123 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6125 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
6127 /* Creating a flippable texture induces a BSoD on some versions of the
6128 * Intel graphics driver. At least Intel GMA 950 with driver version
6129 * 6.14.10.4926 on Windows XP SP3 is affected. */
6130 if ((test_data[i].caps & DDSCAPS_TEXTURE) && ddraw_is_intel(ddraw))
6132 win_skip("Skipping flippable texture test.\n");
6133 continue;
6136 memset(&surface_desc, 0, sizeof(surface_desc));
6137 surface_desc.dwSize = sizeof(surface_desc);
6138 surface_desc.dwFlags = DDSD_CAPS;
6139 if (!(test_data[i].caps & DDSCAPS_PRIMARYSURFACE))
6140 surface_desc.dwFlags |= DDSD_WIDTH | DDSD_HEIGHT;
6141 surface_desc.ddsCaps.dwCaps = DDSCAPS_COMPLEX | DDSCAPS_FLIP | test_data[i].caps;
6142 surface_desc.dwWidth = 512;
6143 surface_desc.dwHeight = 512;
6144 U5(surface_desc).dwBackBufferCount = 3;
6145 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &frontbuffer, NULL);
6146 ok(hr == DDERR_INVALIDCAPS, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
6148 surface_desc.ddsCaps.dwCaps &= ~DDSCAPS_FLIP;
6149 surface_desc.dwFlags |= DDSD_BACKBUFFERCOUNT;
6150 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &frontbuffer, NULL);
6151 ok(hr == DDERR_INVALIDCAPS, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
6153 surface_desc.ddsCaps.dwCaps &= ~DDSCAPS_COMPLEX;
6154 surface_desc.ddsCaps.dwCaps |= DDSCAPS_FLIP;
6155 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &frontbuffer, NULL);
6156 ok(hr == DDERR_INVALIDCAPS, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
6158 surface_desc.ddsCaps.dwCaps |= DDSCAPS_COMPLEX;
6159 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &frontbuffer, NULL);
6160 if (is_ddraw64 && test_data[i].caps & DDSCAPS_TEXTURE)
6161 todo_wine ok(hr == E_NOINTERFACE, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
6162 else todo_wine_if(test_data[i].caps & DDSCAPS_TEXTURE)
6163 ok(SUCCEEDED(hr), "%s: Failed to create surface, hr %#x.\n", test_data[i].name, hr);
6164 if (FAILED(hr))
6165 continue;
6167 memset(&surface_desc, 0, sizeof(surface_desc));
6168 surface_desc.dwSize = sizeof(surface_desc);
6169 hr = IDirectDrawSurface7_GetSurfaceDesc(frontbuffer, &surface_desc);
6170 ok(SUCCEEDED(hr), "%s: Failed to get surface desc, hr %#x.\n", test_data[i].name, hr);
6171 expected_caps = DDSCAPS_FRONTBUFFER | DDSCAPS_COMPLEX | DDSCAPS_FLIP | test_data[i].caps;
6172 if (test_data[i].caps & DDSCAPS_PRIMARYSURFACE)
6173 expected_caps |= DDSCAPS_VISIBLE;
6174 ok((surface_desc.ddsCaps.dwCaps & ~placement) == expected_caps,
6175 "%s: Got unexpected caps %#x.\n", test_data[i].name, surface_desc.ddsCaps.dwCaps);
6176 sysmem_primary = surface_desc.ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY;
6178 hr = IDirectDrawSurface7_GetAttachedSurface(frontbuffer, &caps, &backbuffer1);
6179 ok(SUCCEEDED(hr), "%s: Failed to get attached surface, hr %#x.\n", test_data[i].name, hr);
6180 memset(&surface_desc, 0, sizeof(surface_desc));
6181 surface_desc.dwSize = sizeof(surface_desc);
6182 hr = IDirectDrawSurface7_GetSurfaceDesc(backbuffer1, &surface_desc);
6183 ok(SUCCEEDED(hr), "%s: Failed to get surface desc, hr %#x.\n", test_data[i].name, hr);
6184 ok(!U5(surface_desc).dwBackBufferCount, "%s: Got unexpected back buffer count %u.\n",
6185 test_data[i].name, U5(surface_desc).dwBackBufferCount);
6186 expected_caps &= ~(DDSCAPS_VISIBLE | DDSCAPS_PRIMARYSURFACE | DDSCAPS_FRONTBUFFER);
6187 expected_caps |= DDSCAPS_BACKBUFFER;
6188 ok((surface_desc.ddsCaps.dwCaps & ~placement) == expected_caps,
6189 "%s: Got unexpected caps %#x.\n", test_data[i].name, surface_desc.ddsCaps.dwCaps);
6191 hr = IDirectDrawSurface7_GetAttachedSurface(backbuffer1, &caps, &backbuffer2);
6192 ok(SUCCEEDED(hr), "%s: Failed to get attached surface, hr %#x.\n", test_data[i].name, hr);
6193 memset(&surface_desc, 0, sizeof(surface_desc));
6194 surface_desc.dwSize = sizeof(surface_desc);
6195 hr = IDirectDrawSurface7_GetSurfaceDesc(backbuffer2, &surface_desc);
6196 ok(SUCCEEDED(hr), "%s: Failed to get surface desc, hr %#x.\n", test_data[i].name, hr);
6197 ok(!U5(surface_desc).dwBackBufferCount, "%s: Got unexpected back buffer count %u.\n",
6198 test_data[i].name, U5(surface_desc).dwBackBufferCount);
6199 expected_caps &= ~DDSCAPS_BACKBUFFER;
6200 ok((surface_desc.ddsCaps.dwCaps & ~placement) == expected_caps,
6201 "%s: Got unexpected caps %#x.\n", test_data[i].name, surface_desc.ddsCaps.dwCaps);
6203 hr = IDirectDrawSurface7_GetAttachedSurface(backbuffer2, &caps, &backbuffer3);
6204 ok(SUCCEEDED(hr), "%s: Failed to get attached surface, hr %#x.\n", test_data[i].name, hr);
6205 memset(&surface_desc, 0, sizeof(surface_desc));
6206 surface_desc.dwSize = sizeof(surface_desc);
6207 hr = IDirectDrawSurface7_GetSurfaceDesc(backbuffer3, &surface_desc);
6208 ok(SUCCEEDED(hr), "%s: Failed to get surface desc, hr %#x.\n", test_data[i].name, hr);
6209 ok(!U5(surface_desc).dwBackBufferCount, "%s: Got unexpected back buffer count %u.\n",
6210 test_data[i].name, U5(surface_desc).dwBackBufferCount);
6211 ok((surface_desc.ddsCaps.dwCaps & ~placement) == expected_caps,
6212 "%s: Got unexpected caps %#x.\n", test_data[i].name, surface_desc.ddsCaps.dwCaps);
6214 hr = IDirectDrawSurface7_GetAttachedSurface(backbuffer3, &caps, &surface);
6215 ok(SUCCEEDED(hr), "%s: Failed to get attached surface, hr %#x.\n", test_data[i].name, hr);
6216 ok(surface == frontbuffer, "%s: Got unexpected surface %p, expected %p.\n",
6217 test_data[i].name, surface, frontbuffer);
6218 IDirectDrawSurface7_Release(surface);
6220 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL | DDSCL_FULLSCREEN);
6221 ok(SUCCEEDED(hr), "%s: Failed to set cooperative level, hr %#x.\n", test_data[i].name, hr);
6222 hr = IDirectDrawSurface7_IsLost(frontbuffer);
6223 ok(hr == DD_OK, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
6224 hr = IDirectDrawSurface7_Flip(frontbuffer, NULL, DDFLIP_WAIT);
6225 if (test_data[i].caps & DDSCAPS_PRIMARYSURFACE)
6226 ok(hr == DDERR_NOEXCLUSIVEMODE, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
6227 else
6228 ok(SUCCEEDED(hr), "%s: Failed to flip, hr %#x.\n", test_data[i].name, hr);
6229 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
6230 ok(SUCCEEDED(hr), "%s: Failed to set cooperative level, hr %#x.\n", test_data[i].name, hr);
6231 hr = IDirectDrawSurface7_IsLost(frontbuffer);
6232 todo_wine ok(hr == DDERR_SURFACELOST, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
6233 hr = IDirectDraw7_RestoreAllSurfaces(ddraw);
6234 ok(SUCCEEDED(hr), "%s: Failed to restore surfaces, hr %#x.\n", test_data[i].name, hr);
6236 memset(&surface_desc, 0, sizeof(surface_desc));
6237 surface_desc.dwSize = sizeof(surface_desc);
6238 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
6239 surface_desc.ddsCaps.dwCaps = 0;
6240 surface_desc.dwWidth = 640;
6241 surface_desc.dwHeight = 480;
6242 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
6243 ok(SUCCEEDED(hr), "%s: Failed to create surface, hr %#x.\n", test_data[i].name, hr);
6244 hr = IDirectDrawSurface7_Flip(frontbuffer, surface, DDFLIP_WAIT);
6245 ok(hr == DDERR_NOTFLIPPABLE, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
6246 IDirectDrawSurface7_Release(surface);
6248 hr = IDirectDrawSurface7_Flip(frontbuffer, frontbuffer, DDFLIP_WAIT);
6249 ok(hr == DDERR_NOTFLIPPABLE, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
6250 hr = IDirectDrawSurface7_Flip(backbuffer1, NULL, DDFLIP_WAIT);
6251 ok(hr == DDERR_NOTFLIPPABLE, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
6252 hr = IDirectDrawSurface7_Flip(backbuffer2, NULL, DDFLIP_WAIT);
6253 ok(hr == DDERR_NOTFLIPPABLE, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
6254 hr = IDirectDrawSurface7_Flip(backbuffer3, NULL, DDFLIP_WAIT);
6255 ok(hr == DDERR_NOTFLIPPABLE, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
6257 /* The Nvidia Geforce 7 driver cannot do a color fill on a texture backbuffer after
6258 * the backbuffer has been locked. Do it ourselves as a workaround. Unlike ddraw1
6259 * and 2 GetSurfaceDesc does not cause issues in ddraw4 and ddraw7. */
6260 fill_surface(backbuffer1, 0xffff0000);
6261 fill_surface(backbuffer2, 0xff00ff00);
6262 fill_surface(backbuffer3, 0xff0000ff);
6264 hr = IDirectDrawSurface7_Flip(frontbuffer, NULL, DDFLIP_WAIT);
6265 ok(SUCCEEDED(hr), "%s: Failed to flip, hr %#x.\n", test_data[i].name, hr);
6266 color = get_surface_color(backbuffer1, 320, 240);
6267 /* The testbot seems to just copy the contents of one surface to all the
6268 * others, instead of properly flipping. */
6269 ok(compare_color(color, 0x0000ff00, 1) || broken(sysmem_primary && compare_color(color, 0x000000ff, 1)),
6270 "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
6271 color = get_surface_color(backbuffer2, 320, 240);
6272 ok(compare_color(color, 0x000000ff, 1), "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
6273 fill_surface(backbuffer3, 0xffff0000);
6275 hr = IDirectDrawSurface7_Flip(frontbuffer, NULL, DDFLIP_WAIT);
6276 ok(SUCCEEDED(hr), "%s: Failed to flip, hr %#x.\n", test_data[i].name, hr);
6277 color = get_surface_color(backbuffer1, 320, 240);
6278 ok(compare_color(color, 0x000000ff, 1) || broken(sysmem_primary && compare_color(color, 0x00ff0000, 1)),
6279 "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
6280 color = get_surface_color(backbuffer2, 320, 240);
6281 ok(compare_color(color, 0x00ff0000, 1), "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
6282 fill_surface(backbuffer3, 0xff00ff00);
6284 hr = IDirectDrawSurface7_Flip(frontbuffer, NULL, DDFLIP_WAIT);
6285 ok(SUCCEEDED(hr), "%s: Failed to flip, hr %#x.\n", test_data[i].name, hr);
6286 color = get_surface_color(backbuffer1, 320, 240);
6287 ok(compare_color(color, 0x00ff0000, 1) || broken(sysmem_primary && compare_color(color, 0x0000ff00, 1)),
6288 "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
6289 color = get_surface_color(backbuffer2, 320, 240);
6290 ok(compare_color(color, 0x0000ff00, 1), "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
6291 fill_surface(backbuffer3, 0xff0000ff);
6293 hr = IDirectDrawSurface7_Flip(frontbuffer, backbuffer1, DDFLIP_WAIT);
6294 ok(SUCCEEDED(hr), "%s: Failed to flip, hr %#x.\n", test_data[i].name, hr);
6295 color = get_surface_color(backbuffer2, 320, 240);
6296 ok(compare_color(color, 0x0000ff00, 1) || broken(sysmem_primary && compare_color(color, 0x000000ff, 1)),
6297 "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
6298 color = get_surface_color(backbuffer3, 320, 240);
6299 ok(compare_color(color, 0x000000ff, 1), "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
6300 fill_surface(backbuffer1, 0xffff0000);
6302 hr = IDirectDrawSurface7_Flip(frontbuffer, backbuffer2, DDFLIP_WAIT);
6303 ok(SUCCEEDED(hr), "%s: Failed to flip, hr %#x.\n", test_data[i].name, hr);
6304 color = get_surface_color(backbuffer1, 320, 240);
6305 ok(compare_color(color, 0x00ff0000, 1), "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
6306 color = get_surface_color(backbuffer3, 320, 240);
6307 ok(compare_color(color, 0x000000ff, 1) || broken(sysmem_primary && compare_color(color, 0x00ff0000, 1)),
6308 "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
6309 fill_surface(backbuffer2, 0xff00ff00);
6311 hr = IDirectDrawSurface7_Flip(frontbuffer, backbuffer3, DDFLIP_WAIT);
6312 ok(SUCCEEDED(hr), "%s: Failed to flip, hr %#x.\n", test_data[i].name, hr);
6313 color = get_surface_color(backbuffer1, 320, 240);
6314 ok(compare_color(color, 0x00ff0000, 1) || broken(sysmem_primary && compare_color(color, 0x0000ff00, 1)),
6315 "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
6316 color = get_surface_color(backbuffer2, 320, 240);
6317 ok(compare_color(color, 0x0000ff00, 1), "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
6319 IDirectDrawSurface7_Release(backbuffer3);
6320 IDirectDrawSurface7_Release(backbuffer2);
6321 IDirectDrawSurface7_Release(backbuffer1);
6322 IDirectDrawSurface7_Release(frontbuffer);
6325 if (!(device = create_device(window, DDSCL_NORMAL)))
6327 skip("Failed to create 3D device.\n");
6328 goto done;
6330 hr = IDirect3DDevice7_GetCaps(device, &device_desc);
6331 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
6332 IDirect3DDevice7_Release(device);
6333 if (!(device_desc.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_CUBEMAP))
6335 skip("Cubemaps are not supported.\n");
6336 goto done;
6339 memset(&surface_desc, 0, sizeof(surface_desc));
6340 surface_desc.dwSize = sizeof(surface_desc);
6341 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
6342 surface_desc.ddsCaps.dwCaps = DDSCAPS_COMPLEX | DDSCAPS_FLIP | DDSCAPS_TEXTURE;
6343 surface_desc.ddsCaps.dwCaps2 = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES;
6344 surface_desc.dwWidth = 128;
6345 surface_desc.dwHeight = 128;
6346 U5(surface_desc).dwBackBufferCount = 3;
6347 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &frontbuffer, NULL);
6348 ok(hr == DDERR_INVALIDCAPS, "Got unexpected hr %#x.\n", hr);
6350 surface_desc.ddsCaps.dwCaps &= ~DDSCAPS_FLIP;
6351 surface_desc.dwFlags |= DDSD_BACKBUFFERCOUNT;
6352 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &frontbuffer, NULL);
6353 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
6355 surface_desc.ddsCaps.dwCaps &= ~DDSCAPS_COMPLEX;
6356 surface_desc.ddsCaps.dwCaps |= DDSCAPS_FLIP;
6357 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &frontbuffer, NULL);
6358 ok(hr == DDERR_INVALIDCAPS, "Got unexpected hr %#x.\n", hr);
6360 surface_desc.ddsCaps.dwCaps |= DDSCAPS_COMPLEX;
6361 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &frontbuffer, NULL);
6362 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
6364 U5(surface_desc).dwBackBufferCount = 1;
6365 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &frontbuffer, NULL);
6366 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
6368 U5(surface_desc).dwBackBufferCount = 0;
6369 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &frontbuffer, NULL);
6370 ok(hr == DDERR_INVALIDCAPS, "Got unexpected hr %#x.\n", hr);
6372 done:
6373 refcount = IDirectDraw7_Release(ddraw);
6374 ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount);
6375 DestroyWindow(window);
6378 static void reset_ddsd(DDSURFACEDESC2 *ddsd)
6380 memset(ddsd, 0, sizeof(*ddsd));
6381 ddsd->dwSize = sizeof(*ddsd);
6384 static void test_set_surface_desc(void)
6386 IDirectDraw7 *ddraw;
6387 HWND window;
6388 HRESULT hr;
6389 DDSURFACEDESC2 ddsd;
6390 IDirectDrawSurface7 *surface;
6391 BYTE data[16*16*4];
6392 ULONG ref;
6393 unsigned int i;
6394 static const struct
6396 DWORD caps, caps2;
6397 BOOL supported;
6398 const char *name;
6400 invalid_caps_tests[] =
6402 {DDSCAPS_VIDEOMEMORY, 0, FALSE, "videomemory plain"},
6403 {DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, 0, TRUE, "systemmemory texture"},
6404 {DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, FALSE, "managed texture"},
6405 {DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, FALSE, "managed texture"},
6406 {DDSCAPS_PRIMARYSURFACE | DDSCAPS_SYSTEMMEMORY, 0, FALSE, "systemmemory primary"},
6409 window = create_window();
6410 ddraw = create_ddraw();
6411 ok(!!ddraw, "Failed to create a ddraw object.\n");
6412 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6413 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6415 reset_ddsd(&ddsd);
6416 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_PIXELFORMAT;
6417 ddsd.dwWidth = 8;
6418 ddsd.dwHeight = 8;
6419 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
6420 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
6421 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
6422 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
6423 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
6424 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000ff;
6425 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
6427 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
6428 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6430 reset_ddsd(&ddsd);
6431 ddsd.dwFlags = DDSD_LPSURFACE;
6432 ddsd.lpSurface = data;
6433 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6434 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
6436 /* Redundantly setting the same lpSurface is not an error. */
6437 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6438 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
6440 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd);
6441 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
6442 ok(!(ddsd.dwFlags & DDSD_LPSURFACE), "DDSD_LPSURFACE is set.\n");
6443 ok(ddsd.lpSurface == NULL, "lpSurface is %p, expected NULL.\n", ddsd.lpSurface);
6445 hr = IDirectDrawSurface7_Lock(surface, NULL, &ddsd, 0, NULL);
6446 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
6447 ok(!(ddsd.dwFlags & DDSD_LPSURFACE), "DDSD_LPSURFACE is set.\n");
6448 ok(ddsd.lpSurface == data, "lpSurface is %p, expected %p.\n", data, data);
6449 hr = IDirectDrawSurface7_Unlock(surface, NULL);
6450 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
6452 reset_ddsd(&ddsd);
6453 ddsd.dwFlags = DDSD_LPSURFACE;
6454 ddsd.lpSurface = data;
6455 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 1);
6456 ok(hr == DDERR_INVALIDPARAMS, "SetSurfaceDesc with flags=1 returned %#x.\n", hr);
6458 ddsd.lpSurface = NULL;
6459 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6460 ok(hr == DDERR_INVALIDPARAMS, "Setting lpSurface=NULL returned %#x.\n", hr);
6462 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, NULL, 0);
6463 ok(hr == DDERR_INVALIDPARAMS, "SetSurfaceDesc with NULL desc returned %#x.\n", hr);
6465 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd);
6466 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
6467 ok(ddsd.ddsCaps.dwCaps == (DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN),
6468 "Got unexpected caps %#x.\n", ddsd.ddsCaps.dwCaps);
6469 ok(ddsd.ddsCaps.dwCaps2 == 0, "Got unexpected caps2 %#x.\n", 0);
6471 /* Setting the caps is an error. This also means the original description cannot be reapplied. */
6472 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6473 ok(hr == DDERR_INVALIDPARAMS, "Setting the original desc returned %#x.\n", hr);
6475 ddsd.dwFlags = DDSD_CAPS;
6476 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6477 ok(hr == DDERR_INVALIDPARAMS, "Setting DDSD_CAPS returned %#x.\n", hr);
6479 /* dwCaps = 0 is allowed, but ignored. Caps2 can be anything and is ignored too. */
6480 ddsd.dwFlags = DDSD_CAPS | DDSD_LPSURFACE;
6481 ddsd.lpSurface = data;
6482 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6483 ok(hr == DDERR_INVALIDCAPS, "Setting DDSD_CAPS returned %#x.\n", hr);
6484 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
6485 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6486 ok(hr == DDERR_INVALIDCAPS, "Setting DDSD_CAPS returned %#x.\n", hr);
6487 ddsd.ddsCaps.dwCaps = 0;
6488 ddsd.ddsCaps.dwCaps2 = 0xdeadbeef;
6489 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6490 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
6492 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd);
6493 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
6494 ok(ddsd.ddsCaps.dwCaps == (DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN),
6495 "Got unexpected caps %#x.\n", ddsd.ddsCaps.dwCaps);
6496 ok(ddsd.ddsCaps.dwCaps2 == 0, "Got unexpected caps2 %#x.\n", 0);
6498 /* Setting the height is allowed, but it cannot be set to 0, and only if LPSURFACE is set too. */
6499 reset_ddsd(&ddsd);
6500 ddsd.dwFlags = DDSD_HEIGHT;
6501 ddsd.dwHeight = 16;
6502 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6503 ok(hr == DDERR_INVALIDPARAMS, "Setting height without lpSurface returned %#x.\n", hr);
6505 ddsd.lpSurface = data;
6506 ddsd.dwFlags = DDSD_HEIGHT | DDSD_LPSURFACE;
6507 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6508 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
6510 ddsd.dwHeight = 0;
6511 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6512 ok(hr == DDERR_INVALIDPARAMS, "Setting height=0 returned %#x.\n", hr);
6514 reset_ddsd(&ddsd);
6515 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd);
6516 ok(SUCCEEDED(hr), "GetSurfaceDesc failed, hr %#x.\n", hr);
6517 ok(ddsd.dwWidth == 8, "SetSurfaceDesc: Expected width 8, got %u.\n", ddsd.dwWidth);
6518 ok(ddsd.dwHeight == 16, "SetSurfaceDesc: Expected height 16, got %u.\n", ddsd.dwHeight);
6520 /* Pitch and width can be set, but only together, and only with LPSURFACE. They must not be 0. */
6521 reset_ddsd(&ddsd);
6522 ddsd.dwFlags = DDSD_PITCH;
6523 U1(ddsd).lPitch = 8 * 4;
6524 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6525 ok(hr == DDERR_INVALIDPARAMS, "Setting pitch without lpSurface or width returned %#x.\n", hr);
6527 ddsd.dwFlags = DDSD_WIDTH;
6528 ddsd.dwWidth = 16;
6529 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6530 ok(hr == DDERR_INVALIDPARAMS, "Setting width without lpSurface or pitch returned %#x.\n", hr);
6532 ddsd.dwFlags = DDSD_PITCH | DDSD_LPSURFACE;
6533 ddsd.lpSurface = data;
6534 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6535 ok(hr == DDERR_INVALIDPARAMS, "Setting pitch and lpSurface without width returned %#x.\n", hr);
6537 ddsd.dwFlags = DDSD_WIDTH | DDSD_LPSURFACE;
6538 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6539 ok(hr == DDERR_INVALIDPARAMS, "Setting width and lpSurface without pitch returned %#x.\n", hr);
6541 ddsd.dwFlags = DDSD_WIDTH | DDSD_PITCH | DDSD_LPSURFACE;
6542 U1(ddsd).lPitch = 16 * 4;
6543 ddsd.dwWidth = 16;
6544 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6545 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
6547 reset_ddsd(&ddsd);
6548 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd);
6549 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
6550 ok(ddsd.dwWidth == 16, "SetSurfaceDesc: Expected width 8, got %u.\n", ddsd.dwWidth);
6551 ok(ddsd.dwHeight == 16, "SetSurfaceDesc: Expected height 16, got %u.\n", ddsd.dwHeight);
6552 ok(U1(ddsd).lPitch == 16 * 4, "SetSurfaceDesc: Expected pitch 64, got %u.\n", U1(ddsd).lPitch);
6554 /* The pitch must be 32 bit aligned and > 0, but is not verified for sanity otherwise.
6556 * VMware rejects those calls, but all real drivers accept it. Mark the VMware behavior broken. */
6557 ddsd.dwFlags = DDSD_WIDTH | DDSD_PITCH | DDSD_LPSURFACE;
6558 U1(ddsd).lPitch = 4 * 4;
6559 ddsd.lpSurface = data;
6560 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6561 ok(SUCCEEDED(hr) || broken(hr == DDERR_INVALIDPARAMS), "Failed to set surface desc, hr %#x.\n", hr);
6563 U1(ddsd).lPitch = 4;
6564 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6565 ok(SUCCEEDED(hr) || broken(hr == DDERR_INVALIDPARAMS), "Failed to set surface desc, hr %#x.\n", hr);
6567 U1(ddsd).lPitch = 16 * 4 + 1;
6568 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6569 ok(hr == DDERR_INVALIDPARAMS, "Setting misaligned pitch returned %#x.\n", hr);
6571 U1(ddsd).lPitch = 16 * 4 + 3;
6572 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6573 ok(hr == DDERR_INVALIDPARAMS, "Setting misaligned pitch returned %#x.\n", hr);
6575 U1(ddsd).lPitch = -4;
6576 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6577 ok(hr == DDERR_INVALIDPARAMS, "Setting negative pitch returned %#x.\n", hr);
6579 U1(ddsd).lPitch = 16 * 4;
6580 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6581 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
6583 reset_ddsd(&ddsd);
6584 ddsd.dwFlags = DDSD_WIDTH | DDSD_PITCH | DDSD_LPSURFACE;
6585 U1(ddsd).lPitch = 0;
6586 ddsd.dwWidth = 16;
6587 ddsd.lpSurface = data;
6588 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6589 ok(hr == DDERR_INVALIDPARAMS, "Setting zero pitch returned %#x.\n", hr);
6591 ddsd.dwFlags = DDSD_WIDTH | DDSD_PITCH | DDSD_LPSURFACE;
6592 U1(ddsd).lPitch = 16 * 4;
6593 ddsd.dwWidth = 0;
6594 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6595 ok(hr == DDERR_INVALIDPARAMS, "Setting zero width returned %#x.\n", hr);
6597 /* Setting the pixelformat without LPSURFACE is an error, but with LPSURFACE it works. */
6598 ddsd.dwFlags = DDSD_PIXELFORMAT;
6599 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
6600 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
6601 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
6602 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
6603 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
6604 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000ff;
6605 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6606 ok(hr == DDERR_INVALIDPARAMS, "Setting the pixel format returned %#x.\n", hr);
6608 ddsd.dwFlags = DDSD_PIXELFORMAT | DDSD_LPSURFACE;
6609 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6610 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
6612 /* Can't set color keys. */
6613 reset_ddsd(&ddsd);
6614 ddsd.dwFlags = DDSD_CKSRCBLT;
6615 ddsd.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00ff0000;
6616 ddsd.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00ff0000;
6617 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6618 ok(hr == DDERR_INVALIDPARAMS, "Setting ddckCKSrcBlt returned %#x.\n", hr);
6620 ddsd.dwFlags = DDSD_CKSRCBLT | DDSD_LPSURFACE;
6621 ddsd.lpSurface = data;
6622 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6623 ok(hr == DDERR_INVALIDPARAMS, "Setting ddckCKSrcBlt returned %#x.\n", hr);
6625 IDirectDrawSurface7_Release(surface);
6627 /* SetSurfaceDesc needs systemmemory surfaces.
6629 * As a sidenote, fourcc surfaces aren't allowed in sysmem, thus testing
6630 * DDSD_LINEARSIZE is moot. */
6631 for (i = 0; i < ARRAY_SIZE(invalid_caps_tests); ++i)
6633 reset_ddsd(&ddsd);
6634 ddsd.dwFlags = DDSD_CAPS;
6635 ddsd.ddsCaps.dwCaps = invalid_caps_tests[i].caps;
6636 ddsd.ddsCaps.dwCaps2 = invalid_caps_tests[i].caps2;
6637 if (!(invalid_caps_tests[i].caps & DDSCAPS_PRIMARYSURFACE))
6639 ddsd.dwFlags |= DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
6640 ddsd.dwWidth = 8;
6641 ddsd.dwHeight = 8;
6642 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
6643 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
6644 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
6645 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
6646 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
6647 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000ff;
6650 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
6651 if (is_ddraw64 && (invalid_caps_tests[i].caps & DDSCAPS_TEXTURE))
6652 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Got unexpected hr %#x.\n", i, hr);
6653 else
6654 ok(hr == DD_OK || hr == DDERR_NODIRECTDRAWHW, "Test %u: Got unexpected hr %#x.\n", i, hr);
6655 if (FAILED(hr))
6656 continue;
6658 reset_ddsd(&ddsd);
6659 ddsd.dwFlags = DDSD_LPSURFACE;
6660 ddsd.lpSurface = data;
6661 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6662 if (invalid_caps_tests[i].supported)
6664 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
6666 else
6668 ok(hr == DDERR_INVALIDSURFACETYPE, "SetSurfaceDesc on a %s surface returned %#x.\n",
6669 invalid_caps_tests[i].name, hr);
6671 /* Check priority of error conditions. */
6672 ddsd.dwFlags = DDSD_WIDTH;
6673 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6674 ok(hr == DDERR_INVALIDSURFACETYPE, "SetSurfaceDesc on a %s surface returned %#x.\n",
6675 invalid_caps_tests[i].name, hr);
6678 IDirectDrawSurface7_Release(surface);
6681 ref = IDirectDraw7_Release(ddraw);
6682 ok(ref == 0, "Ddraw object not properly released, refcount %u.\n", ref);
6683 DestroyWindow(window);
6686 static void test_user_memory_getdc(void)
6688 IDirectDraw7 *ddraw;
6689 HWND window;
6690 HRESULT hr;
6691 DDSURFACEDESC2 ddsd;
6692 IDirectDrawSurface7 *surface;
6693 DWORD data[16][16];
6694 HGDIOBJ *bitmap;
6695 DIBSECTION dib;
6696 ULONG ref;
6697 int size;
6698 HDC dc;
6699 unsigned int x, y;
6701 window = create_window();
6702 ddraw = create_ddraw();
6703 ok(!!ddraw, "Failed to create a ddraw object.\n");
6704 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6705 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6707 reset_ddsd(&ddsd);
6708 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_PIXELFORMAT;
6709 ddsd.dwWidth = 16;
6710 ddsd.dwHeight = 16;
6711 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
6712 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
6713 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
6714 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
6715 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
6716 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000ff;
6717 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
6718 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
6719 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6721 memset(data, 0xaa, sizeof(data));
6722 reset_ddsd(&ddsd);
6723 ddsd.dwFlags = DDSD_LPSURFACE;
6724 ddsd.lpSurface = data;
6725 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6726 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
6728 hr = IDirectDrawSurface7_GetDC(surface, &dc);
6729 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
6730 bitmap = GetCurrentObject(dc, OBJ_BITMAP);
6731 ok(!!bitmap, "Failed to get bitmap.\n");
6732 size = GetObjectA(bitmap, sizeof(dib), &dib);
6733 ok(size == sizeof(dib), "Got unexpected size %d.\n", size);
6734 ok(dib.dsBm.bmBits == data, "Got unexpected bits %p, expected %p.\n", dib.dsBm.bmBits, data);
6735 BitBlt(dc, 0, 0, 16, 8, NULL, 0, 0, WHITENESS);
6736 BitBlt(dc, 0, 8, 16, 8, NULL, 0, 0, BLACKNESS);
6737 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
6738 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
6740 ok(data[0][0] == 0xffffffff, "Expected color 0xffffffff, got %#x.\n", data[0][0]);
6741 ok(data[15][15] == 0x00000000, "Expected color 0x00000000, got %#x.\n", data[15][15]);
6743 ddsd.dwFlags = DDSD_LPSURFACE | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PITCH;
6744 ddsd.lpSurface = data;
6745 ddsd.dwWidth = 4;
6746 ddsd.dwHeight = 8;
6747 U1(ddsd).lPitch = sizeof(*data);
6748 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6749 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
6751 memset(data, 0xaa, sizeof(data));
6752 hr = IDirectDrawSurface7_GetDC(surface, &dc);
6753 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
6754 BitBlt(dc, 0, 0, 4, 8, NULL, 0, 0, BLACKNESS);
6755 BitBlt(dc, 1, 1, 2, 2, NULL, 0, 0, WHITENESS);
6756 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
6757 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
6759 for (y = 0; y < 4; y++)
6761 for (x = 0; x < 4; x++)
6763 if ((x == 1 || x == 2) && (y == 1 || y == 2))
6764 ok(data[y][x] == 0xffffffff, "Expected color 0xffffffff on position %ux%u, got %#x.\n",
6765 x, y, data[y][x]);
6766 else
6767 ok(data[y][x] == 0x00000000, "Expected color 0x00000000 on position %ux%u, got %#x.\n",
6768 x, y, data[y][x]);
6771 ok(data[0][5] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 5x0, got %#x.\n",
6772 data[0][5]);
6773 ok(data[7][3] == 0x00000000, "Expected color 0x00000000 on position 3x7, got %#x.\n",
6774 data[7][3]);
6775 ok(data[7][4] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 4x7, got %#x.\n",
6776 data[7][4]);
6777 ok(data[8][0] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 0x8, got %#x.\n",
6778 data[8][0]);
6780 IDirectDrawSurface7_Release(surface);
6781 ref = IDirectDraw7_Release(ddraw);
6782 ok(ref == 0, "Ddraw object not properly released, refcount %u.\n", ref);
6783 DestroyWindow(window);
6786 static void test_sysmem_overlay(void)
6788 IDirectDraw7 *ddraw;
6789 HWND window;
6790 HRESULT hr;
6791 DDSURFACEDESC2 ddsd;
6792 IDirectDrawSurface7 *surface;
6793 ULONG ref;
6795 window = create_window();
6796 ddraw = create_ddraw();
6797 ok(!!ddraw, "Failed to create a ddraw object.\n");
6798 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6799 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6801 reset_ddsd(&ddsd);
6802 ddsd.dwFlags = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT;
6803 ddsd.dwWidth = 16;
6804 ddsd.dwHeight = 16;
6805 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OVERLAY;
6806 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
6807 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
6808 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
6809 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
6810 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
6811 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000ff;
6812 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
6813 ok(hr == DDERR_NOOVERLAYHW, "Got unexpected hr %#x.\n", hr);
6815 ref = IDirectDraw7_Release(ddraw);
6816 ok(ref == 0, "Ddraw object not properly released, refcount %u.\n", ref);
6817 DestroyWindow(window);
6820 static void test_primary_palette(void)
6822 DDSCAPS2 surface_caps = {DDSCAPS_FLIP, 0, 0, {0}};
6823 IDirectDrawSurface7 *primary, *backbuffer;
6824 PALETTEENTRY palette_entries[256];
6825 IDirectDrawPalette *palette, *tmp;
6826 DDSURFACEDESC2 surface_desc;
6827 IDirectDraw7 *ddraw;
6828 DWORD palette_caps;
6829 ULONG refcount;
6830 HWND window;
6831 HRESULT hr;
6833 window = create_window();
6834 ddraw = create_ddraw();
6835 ok(!!ddraw, "Failed to create a ddraw object.\n");
6836 if (FAILED(IDirectDraw7_SetDisplayMode(ddraw, 640, 480, 8, 0, 0)))
6838 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
6839 IDirectDraw7_Release(ddraw);
6840 DestroyWindow(window);
6841 return;
6843 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
6844 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6846 memset(&surface_desc, 0, sizeof(surface_desc));
6847 surface_desc.dwSize = sizeof(surface_desc);
6848 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
6849 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
6850 U5(surface_desc).dwBackBufferCount = 1;
6851 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &primary, NULL);
6852 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6853 hr = IDirectDrawSurface7_GetAttachedSurface(primary, &surface_caps, &backbuffer);
6854 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
6856 memset(palette_entries, 0, sizeof(palette_entries));
6857 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256, palette_entries, &palette, NULL);
6858 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
6859 refcount = get_refcount((IUnknown *)palette);
6860 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
6862 hr = IDirectDrawPalette_GetCaps(palette, &palette_caps);
6863 ok(SUCCEEDED(hr), "Failed to get palette caps, hr %#x.\n", hr);
6864 ok(palette_caps == (DDPCAPS_8BIT | DDPCAPS_ALLOW256), "Got unexpected palette caps %#x.\n", palette_caps);
6866 hr = IDirectDrawSurface7_SetPalette(primary, palette);
6867 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
6869 /* The Windows 8 testbot attaches the palette to the backbuffer as well,
6870 * and is generally somewhat broken with respect to 8 bpp / palette
6871 * handling. */
6872 if (SUCCEEDED(IDirectDrawSurface7_GetPalette(backbuffer, &tmp)))
6874 win_skip("Broken palette handling detected, skipping tests.\n");
6875 IDirectDrawPalette_Release(tmp);
6876 IDirectDrawPalette_Release(palette);
6877 /* The Windows 8 testbot keeps extra references to the primary and
6878 * backbuffer while in 8 bpp mode. */
6879 hr = IDirectDraw7_RestoreDisplayMode(ddraw);
6880 ok(SUCCEEDED(hr), "Failed to restore display mode, hr %#x.\n", hr);
6881 goto done;
6884 refcount = get_refcount((IUnknown *)palette);
6885 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
6887 hr = IDirectDrawPalette_GetCaps(palette, &palette_caps);
6888 ok(SUCCEEDED(hr), "Failed to get palette caps, hr %#x.\n", hr);
6889 ok(palette_caps == (DDPCAPS_8BIT | DDPCAPS_PRIMARYSURFACE | DDPCAPS_ALLOW256),
6890 "Got unexpected palette caps %#x.\n", palette_caps);
6892 hr = IDirectDrawSurface7_SetPalette(primary, NULL);
6893 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
6894 refcount = get_refcount((IUnknown *)palette);
6895 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
6897 hr = IDirectDrawPalette_GetCaps(palette, &palette_caps);
6898 ok(SUCCEEDED(hr), "Failed to get palette caps, hr %#x.\n", hr);
6899 ok(palette_caps == (DDPCAPS_8BIT | DDPCAPS_ALLOW256), "Got unexpected palette caps %#x.\n", palette_caps);
6901 hr = IDirectDrawSurface7_SetPalette(primary, palette);
6902 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
6903 refcount = get_refcount((IUnknown *)palette);
6904 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
6906 hr = IDirectDrawSurface7_GetPalette(primary, &tmp);
6907 ok(SUCCEEDED(hr), "Failed to get palette, hr %#x.\n", hr);
6908 ok(tmp == palette, "Got unexpected palette %p, expected %p.\n", tmp, palette);
6909 IDirectDrawPalette_Release(tmp);
6910 hr = IDirectDrawSurface7_GetPalette(backbuffer, &tmp);
6911 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x.\n", hr);
6913 refcount = IDirectDrawPalette_Release(palette);
6914 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
6915 refcount = IDirectDrawPalette_Release(palette);
6916 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6918 /* Note that this only seems to work when the palette is attached to the
6919 * primary surface. When attached to a regular surface, attempting to get
6920 * the palette here will cause an access violation. */
6921 hr = IDirectDrawSurface7_GetPalette(primary, &tmp);
6922 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x.\n", hr);
6924 hr = IDirectDrawSurface7_IsLost(primary);
6925 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6927 memset(&surface_desc, 0, sizeof(surface_desc));
6928 surface_desc.dwSize = sizeof(surface_desc);
6929 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &surface_desc);
6930 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
6931 ok(surface_desc.dwWidth == 640, "Got unexpected surface width %u.\n", surface_desc.dwWidth);
6932 ok(surface_desc.dwHeight == 480, "Got unexpected surface height %u.\n", surface_desc.dwHeight);
6933 ok(U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount == 8, "Got unexpected bit count %u.\n",
6934 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount);
6936 hr = set_display_mode(ddraw, 640, 480);
6937 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
6939 memset(&surface_desc, 0, sizeof(surface_desc));
6940 surface_desc.dwSize = sizeof(surface_desc);
6941 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &surface_desc);
6942 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
6943 ok(surface_desc.dwWidth == 640, "Got unexpected surface width %u.\n", surface_desc.dwWidth);
6944 ok(surface_desc.dwHeight == 480, "Got unexpected surface height %u.\n", surface_desc.dwHeight);
6945 ok(U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount == 32
6946 || U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount == 24,
6947 "Got unexpected bit count %u.\n", U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount);
6949 hr = IDirectDrawSurface7_IsLost(primary);
6950 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
6951 hr = IDirectDrawSurface7_Restore(primary);
6952 ok(hr == DDERR_WRONGMODE, "Got unexpected hr %#x.\n", hr);
6953 hr = IDirectDrawSurface7_IsLost(primary);
6954 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
6956 memset(&surface_desc, 0, sizeof(surface_desc));
6957 surface_desc.dwSize = sizeof(surface_desc);
6958 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &surface_desc);
6959 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
6960 ok(surface_desc.dwWidth == 640, "Got unexpected surface width %u.\n", surface_desc.dwWidth);
6961 ok(surface_desc.dwHeight == 480, "Got unexpected surface height %u.\n", surface_desc.dwHeight);
6962 ok(U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount == 32
6963 || U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount == 24,
6964 "Got unexpected bit count %u.\n", U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount);
6966 done:
6967 refcount = IDirectDrawSurface7_Release(backbuffer);
6968 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
6969 refcount = IDirectDrawSurface7_Release(primary);
6970 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6971 refcount = IDirectDraw7_Release(ddraw);
6972 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6973 DestroyWindow(window);
6976 static HRESULT WINAPI surface_counter(IDirectDrawSurface7 *surface, DDSURFACEDESC2 *desc, void *context)
6978 UINT *surface_count = context;
6980 ++(*surface_count);
6981 IDirectDrawSurface_Release(surface);
6983 return DDENUMRET_OK;
6986 static void test_surface_attachment(void)
6988 IDirectDrawSurface7 *surface1, *surface2, *surface3, *surface4;
6989 IDirectDrawSurface *surface1v1, *surface2v1;
6990 DDSCAPS2 caps = {DDSCAPS_TEXTURE, 0, 0, {0}};
6991 DDSURFACEDESC2 surface_desc;
6992 IDirectDraw7 *ddraw;
6993 UINT surface_count;
6994 ULONG refcount;
6995 HWND window;
6996 HRESULT hr;
6998 window = create_window();
6999 ddraw = create_ddraw();
7000 ok(!!ddraw, "Failed to create a ddraw object.\n");
7001 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
7002 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
7004 memset(&surface_desc, 0, sizeof(surface_desc));
7005 surface_desc.dwSize = sizeof(surface_desc);
7006 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_MIPMAPCOUNT;
7007 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
7008 U2(surface_desc).dwMipMapCount = 3;
7009 surface_desc.dwWidth = 128;
7010 surface_desc.dwHeight = 128;
7011 if (FAILED(IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface1, NULL)))
7013 skip("Failed to create a texture, skipping tests.\n");
7014 IDirectDraw7_Release(ddraw);
7015 DestroyWindow(window);
7016 return;
7019 hr = IDirectDrawSurface7_GetAttachedSurface(surface1, &caps, &surface2);
7020 ok(SUCCEEDED(hr), "Failed to get mip level, hr %#x.\n", hr);
7021 hr = IDirectDrawSurface7_GetAttachedSurface(surface2, &caps, &surface3);
7022 ok(SUCCEEDED(hr), "Failed to get mip level, hr %#x.\n", hr);
7023 hr = IDirectDrawSurface7_GetAttachedSurface(surface3, &caps, &surface4);
7024 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
7026 surface_count = 0;
7027 IDirectDrawSurface7_EnumAttachedSurfaces(surface1, &surface_count, surface_counter);
7028 ok(surface_count == 1, "Got unexpected surface_count %u.\n", surface_count);
7029 surface_count = 0;
7030 IDirectDrawSurface7_EnumAttachedSurfaces(surface2, &surface_count, surface_counter);
7031 ok(surface_count == 1, "Got unexpected surface_count %u.\n", surface_count);
7032 surface_count = 0;
7033 IDirectDrawSurface7_EnumAttachedSurfaces(surface3, &surface_count, surface_counter);
7034 ok(!surface_count, "Got unexpected surface_count %u.\n", surface_count);
7036 memset(&surface_desc, 0, sizeof(surface_desc));
7037 surface_desc.dwSize = sizeof(surface_desc);
7038 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
7039 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
7040 surface_desc.dwWidth = 16;
7041 surface_desc.dwHeight = 16;
7042 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface4, NULL);
7043 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7045 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface4);
7046 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7047 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface1);
7048 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7049 hr = IDirectDrawSurface7_AddAttachedSurface(surface3, surface4);
7050 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7051 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface3);
7052 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7053 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface4);
7054 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7055 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface2);
7056 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7058 IDirectDrawSurface7_Release(surface4);
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_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
7064 surface_desc.dwWidth = 16;
7065 surface_desc.dwHeight = 16;
7066 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface4, NULL);
7067 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7069 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface4);
7070 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7071 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface1);
7072 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7073 hr = IDirectDrawSurface7_AddAttachedSurface(surface3, surface4);
7074 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7075 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface3);
7076 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7077 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface4);
7078 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7079 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface2);
7080 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7082 IDirectDrawSurface7_Release(surface4);
7083 IDirectDrawSurface7_Release(surface3);
7084 IDirectDrawSurface7_Release(surface2);
7085 IDirectDrawSurface7_Release(surface1);
7087 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
7088 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
7090 /* Try a single primary and two offscreen plain surfaces. */
7091 memset(&surface_desc, 0, sizeof(surface_desc));
7092 surface_desc.dwSize = sizeof(surface_desc);
7093 surface_desc.dwFlags = DDSD_CAPS;
7094 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
7095 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface1, NULL);
7096 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7098 memset(&surface_desc, 0, sizeof(surface_desc));
7099 surface_desc.dwSize = sizeof(surface_desc);
7100 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
7101 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
7102 surface_desc.dwWidth = registry_mode.dmPelsWidth;
7103 surface_desc.dwHeight = registry_mode.dmPelsHeight;
7104 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface2, NULL);
7105 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7107 memset(&surface_desc, 0, sizeof(surface_desc));
7108 surface_desc.dwSize = sizeof(surface_desc);
7109 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
7110 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
7111 surface_desc.dwWidth = registry_mode.dmPelsWidth;
7112 surface_desc.dwHeight = registry_mode.dmPelsHeight;
7113 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface3, NULL);
7114 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7116 /* This one has a different size. */
7117 memset(&surface_desc, 0, sizeof(surface_desc));
7118 surface_desc.dwSize = sizeof(surface_desc);
7119 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
7120 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
7121 surface_desc.dwWidth = 128;
7122 surface_desc.dwHeight = 128;
7123 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface4, NULL);
7124 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7126 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface2);
7127 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7128 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface1);
7129 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7130 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface3);
7131 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7132 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface4);
7133 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7134 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface1);
7135 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7137 IDirectDrawSurface7_Release(surface4);
7138 IDirectDrawSurface7_Release(surface3);
7139 IDirectDrawSurface7_Release(surface2);
7140 IDirectDrawSurface7_Release(surface1);
7142 /* Test DeleteAttachedSurface() and automatic detachment of attached surfaces on release. */
7143 memset(&surface_desc, 0, sizeof(surface_desc));
7144 surface_desc.dwSize = sizeof(surface_desc);
7145 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
7146 surface_desc.dwWidth = 64;
7147 surface_desc.dwHeight = 64;
7148 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
7149 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
7150 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB; /* D3DFMT_R5G6B5 */
7151 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 16;
7152 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0xf800;
7153 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x07e0;
7154 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x001f;
7155 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface1, NULL);
7156 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7157 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface3, NULL);
7158 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7160 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
7161 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_ZBUFFER;
7162 U1(U4(surface_desc).ddpfPixelFormat).dwZBufferBitDepth = 16;
7163 U3(U4(surface_desc).ddpfPixelFormat).dwZBitMask = 0x0000ffff;
7164 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface2, NULL);
7165 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7167 hr = IDirectDrawSurface7_QueryInterface(surface1, &IID_IDirectDrawSurface, (void **)&surface1v1);
7168 ok(SUCCEEDED(hr), "Failed to get interface, hr %#x.\n", hr);
7169 hr = IDirectDrawSurface7_QueryInterface(surface2, &IID_IDirectDrawSurface, (void **)&surface2v1);
7170 ok(SUCCEEDED(hr), "Failed to get interface, hr %#x.\n", hr);
7172 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface2);
7173 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
7174 refcount = get_refcount((IUnknown *)surface2);
7175 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
7176 refcount = get_refcount((IUnknown *)surface2v1);
7177 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
7178 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface2);
7179 ok(hr == DDERR_SURFACEALREADYATTACHED, "Got unexpected hr %#x.\n", hr);
7180 hr = IDirectDrawSurface_AddAttachedSurface(surface1v1, surface2v1);
7181 todo_wine ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7182 hr = IDirectDrawSurface_DeleteAttachedSurface(surface1v1, 0, surface2v1);
7183 ok(hr == DDERR_SURFACENOTATTACHED, "Got unexpected hr %#x.\n", hr);
7185 /* Attaching while already attached to other surface. */
7186 hr = IDirectDrawSurface7_AddAttachedSurface(surface3, surface2);
7187 todo_wine ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
7188 hr = IDirectDrawSurface7_DeleteAttachedSurface(surface3, 0, surface2);
7189 todo_wine ok(SUCCEEDED(hr), "Failed to detach surface, hr %#x.\n", hr);
7190 IDirectDrawSurface7_Release(surface3);
7192 hr = IDirectDrawSurface7_DeleteAttachedSurface(surface1, 0, surface2);
7193 ok(SUCCEEDED(hr), "Failed to detach surface, hr %#x.\n", hr);
7194 refcount = get_refcount((IUnknown *)surface2);
7195 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
7196 refcount = get_refcount((IUnknown *)surface2v1);
7197 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
7199 /* DeleteAttachedSurface() when attaching via IDirectDrawSurface. */
7200 hr = IDirectDrawSurface_AddAttachedSurface(surface1v1, surface2v1);
7201 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
7202 hr = IDirectDrawSurface7_DeleteAttachedSurface(surface1, 0, surface2);
7203 ok(hr == DDERR_SURFACENOTATTACHED, "Got unexpected hr %#x.\n", hr);
7204 hr = IDirectDrawSurface_DeleteAttachedSurface(surface1v1, 0, surface2v1);
7205 ok(SUCCEEDED(hr), "Failed to detach surface, hr %#x.\n", hr);
7206 refcount = IDirectDrawSurface7_Release(surface2);
7207 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7208 refcount = IDirectDrawSurface7_Release(surface1);
7209 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7211 /* Automatic detachment on release. */
7212 hr = IDirectDrawSurface_AddAttachedSurface(surface1v1, surface2v1);
7213 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
7214 refcount = get_refcount((IUnknown *)surface2v1);
7215 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
7216 refcount = IDirectDrawSurface_Release(surface1v1);
7217 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7218 refcount = IDirectDrawSurface_Release(surface2v1);
7219 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7220 refcount = IDirectDraw7_Release(ddraw);
7221 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7222 DestroyWindow(window);
7225 static void test_private_data(void)
7227 IDirectDraw7 *ddraw;
7228 IDirectDrawSurface7 *surface, *surface2;
7229 DDSURFACEDESC2 surface_desc;
7230 ULONG refcount, refcount2, refcount3;
7231 IUnknown *ptr;
7232 DWORD size = sizeof(ptr);
7233 HRESULT hr;
7234 HWND window;
7235 DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, {0}};
7236 DWORD data[] = {1, 2, 3, 4};
7237 DDCAPS hal_caps;
7238 static const GUID ddraw_private_data_test_guid =
7240 0xfdb37466,
7241 0x428f,
7242 0x4edf,
7243 {0xa3,0x7f,0x9b,0x1d,0xf4,0x88,0xc5,0xfc}
7245 static const GUID ddraw_private_data_test_guid2 =
7247 0x2e5afac2,
7248 0x87b5,
7249 0x4c10,
7250 {0x9b,0x4b,0x89,0xd7,0xd1,0x12,0xe7,0x2b}
7253 window = create_window();
7254 ddraw = create_ddraw();
7255 ok(!!ddraw, "Failed to create a ddraw object.\n");
7256 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
7257 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
7259 reset_ddsd(&surface_desc);
7260 surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
7261 surface_desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
7262 surface_desc.dwHeight = 4;
7263 surface_desc.dwWidth = 4;
7264 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7265 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7267 /* NULL pointers are not valid, but don't cause a crash. */
7268 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, NULL,
7269 sizeof(IUnknown *), DDSPD_IUNKNOWNPOINTER);
7270 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7271 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, NULL, 0, 0);
7272 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7273 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, NULL, 1, 0);
7274 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7276 /* DDSPD_IUNKNOWNPOINTER needs sizeof(IUnknown *) bytes of data. */
7277 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
7278 0, DDSPD_IUNKNOWNPOINTER);
7279 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7280 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
7281 5, DDSPD_IUNKNOWNPOINTER);
7282 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7283 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
7284 sizeof(ddraw) * 2, DDSPD_IUNKNOWNPOINTER);
7285 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7287 /* Note that with a size != 0 and size != sizeof(IUnknown *) and
7288 * DDSPD_IUNKNOWNPOINTER set SetPrivateData in ddraw4 and ddraw7
7289 * erases the old content and returns an error. This behavior has
7290 * been fixed in d3d8 and d3d9. Unless an application is found
7291 * that depends on this we don't care about this behavior. */
7292 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
7293 sizeof(ddraw), DDSPD_IUNKNOWNPOINTER);
7294 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
7295 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
7296 0, DDSPD_IUNKNOWNPOINTER);
7297 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7298 size = sizeof(ptr);
7299 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid, &ptr, &size);
7300 ok(SUCCEEDED(hr), "Failed to get private data, hr %#x.\n", hr);
7301 hr = IDirectDrawSurface7_FreePrivateData(surface, &ddraw_private_data_test_guid);
7302 ok(SUCCEEDED(hr), "Failed to free private data, hr %#x.\n", hr);
7304 refcount = get_refcount((IUnknown *)ddraw);
7305 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
7306 sizeof(ddraw), DDSPD_IUNKNOWNPOINTER);
7307 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
7308 refcount2 = get_refcount((IUnknown *)ddraw);
7309 ok(refcount2 == refcount + 1, "Got unexpected refcount %u.\n", refcount2);
7311 hr = IDirectDrawSurface7_FreePrivateData(surface, &ddraw_private_data_test_guid);
7312 ok(SUCCEEDED(hr), "Failed to free private data, hr %#x.\n", hr);
7313 refcount2 = get_refcount((IUnknown *)ddraw);
7314 ok(refcount2 == refcount, "Got unexpected refcount %u.\n", refcount2);
7316 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
7317 sizeof(ddraw), DDSPD_IUNKNOWNPOINTER);
7318 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
7319 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, surface,
7320 sizeof(surface), DDSPD_IUNKNOWNPOINTER);
7321 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
7322 refcount2 = get_refcount((IUnknown *)ddraw);
7323 ok(refcount2 == refcount, "Got unexpected refcount %u.\n", refcount2);
7325 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
7326 sizeof(ddraw), DDSPD_IUNKNOWNPOINTER);
7327 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
7328 size = 2 * sizeof(ptr);
7329 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid, &ptr, &size);
7330 ok(SUCCEEDED(hr), "Failed to get private data, hr %#x.\n", hr);
7331 ok(size == sizeof(ddraw), "Got unexpected size %u.\n", size);
7332 refcount2 = get_refcount(ptr);
7333 /* Object is NOT addref'ed by the getter. */
7334 ok(ptr == (IUnknown *)ddraw, "Returned interface pointer is %p, expected %p.\n", ptr, ddraw);
7335 ok(refcount2 == refcount + 1, "Got unexpected refcount %u.\n", refcount2);
7337 ptr = (IUnknown *)0xdeadbeef;
7338 size = 1;
7339 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid, NULL, &size);
7340 ok(hr == DDERR_MOREDATA, "Got unexpected hr %#x.\n", hr);
7341 ok(size == sizeof(ddraw), "Got unexpected size %u.\n", size);
7342 size = 2 * sizeof(ptr);
7343 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid, NULL, &size);
7344 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7345 ok(size == 2 * sizeof(ptr), "Got unexpected size %u.\n", size);
7346 size = 1;
7347 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid, &ptr, &size);
7348 ok(hr == DDERR_MOREDATA, "Got unexpected hr %#x.\n", hr);
7349 ok(size == sizeof(ddraw), "Got unexpected size %u.\n", size);
7350 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
7351 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid2, NULL, NULL);
7352 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
7353 size = 0xdeadbabe;
7354 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid2, &ptr, &size);
7355 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
7356 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
7357 ok(size == 0xdeadbabe, "Got unexpected size %u.\n", size);
7358 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid, NULL, NULL);
7359 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7361 refcount3 = IDirectDrawSurface7_Release(surface);
7362 ok(!refcount3, "Got unexpected refcount %u.\n", refcount3);
7364 /* Destroying the surface frees the reference held on the private data. It also frees
7365 * the reference the surface is holding on its creating object. */
7366 refcount2 = get_refcount((IUnknown *)ddraw);
7367 ok(refcount2 == refcount - 1, "Got unexpected refcount %u.\n", refcount2);
7369 memset(&hal_caps, 0, sizeof(hal_caps));
7370 hal_caps.dwSize = sizeof(hal_caps);
7371 hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, NULL);
7372 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
7373 if ((hal_caps.ddsCaps.dwCaps & (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP)) == (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP)
7374 && !is_ddraw64)
7376 reset_ddsd(&surface_desc);
7377 surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_MIPMAPCOUNT;
7378 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
7379 surface_desc.dwHeight = 4;
7380 surface_desc.dwWidth = 4;
7381 U2(surface_desc).dwMipMapCount = 2;
7382 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7383 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7384 hr = IDirectDrawSurface7_GetAttachedSurface(surface, &caps, &surface2);
7385 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
7387 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, data, sizeof(data), 0);
7388 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
7389 hr = IDirectDrawSurface7_GetPrivateData(surface2, &ddraw_private_data_test_guid, NULL, NULL);
7390 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
7392 IDirectDrawSurface7_Release(surface2);
7393 IDirectDrawSurface7_Release(surface);
7395 else
7396 skip("Mipmapped textures not supported, skipping mipmap private data test.\n");
7398 refcount = IDirectDraw7_Release(ddraw);
7399 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7400 DestroyWindow(window);
7403 static void test_pixel_format(void)
7405 HWND window, window2 = NULL;
7406 HDC hdc, hdc2 = NULL;
7407 HMODULE gl = NULL;
7408 int format, test_format;
7409 PIXELFORMATDESCRIPTOR pfd;
7410 IDirectDraw7 *ddraw = NULL;
7411 IDirectDrawClipper *clipper = NULL;
7412 DDSURFACEDESC2 ddsd;
7413 IDirectDrawSurface7 *primary = NULL;
7414 DDBLTFX fx;
7415 HRESULT hr;
7417 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
7418 100, 100, 160, 160, NULL, NULL, NULL, NULL);
7419 if (!window)
7421 skip("Failed to create window\n");
7422 return;
7425 window2 = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
7426 100, 100, 160, 160, NULL, NULL, NULL, NULL);
7428 hdc = GetDC(window);
7429 if (!hdc)
7431 skip("Failed to get DC\n");
7432 goto cleanup;
7435 if (window2)
7436 hdc2 = GetDC(window2);
7438 gl = LoadLibraryA("opengl32.dll");
7439 ok(!!gl, "failed to load opengl32.dll; SetPixelFormat()/GetPixelFormat() may not work right\n");
7441 format = GetPixelFormat(hdc);
7442 ok(format == 0, "new window has pixel format %d\n", format);
7444 ZeroMemory(&pfd, sizeof(pfd));
7445 pfd.nSize = sizeof(pfd);
7446 pfd.nVersion = 1;
7447 pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
7448 pfd.iPixelType = PFD_TYPE_RGBA;
7449 pfd.iLayerType = PFD_MAIN_PLANE;
7450 format = ChoosePixelFormat(hdc, &pfd);
7451 if (format <= 0)
7453 skip("no pixel format available\n");
7454 goto cleanup;
7457 if (!SetPixelFormat(hdc, format, &pfd) || GetPixelFormat(hdc) != format)
7459 skip("failed to set pixel format\n");
7460 goto cleanup;
7463 if (!hdc2 || !SetPixelFormat(hdc2, format, &pfd) || GetPixelFormat(hdc2) != format)
7465 skip("failed to set pixel format on second window\n");
7466 if (hdc2)
7468 ReleaseDC(window2, hdc2);
7469 hdc2 = NULL;
7473 ddraw = create_ddraw();
7474 ok(!!ddraw, "Failed to create a ddraw object.\n");
7476 test_format = GetPixelFormat(hdc);
7477 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
7479 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
7480 if (FAILED(hr))
7482 skip("Failed to set cooperative level, hr %#x.\n", hr);
7483 goto cleanup;
7486 test_format = GetPixelFormat(hdc);
7487 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
7489 if (hdc2)
7491 hr = IDirectDraw7_CreateClipper(ddraw, 0, &clipper, NULL);
7492 ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr);
7493 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window2);
7494 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
7496 test_format = GetPixelFormat(hdc);
7497 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
7499 test_format = GetPixelFormat(hdc2);
7500 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
7503 memset(&ddsd, 0, sizeof(ddsd));
7504 ddsd.dwSize = sizeof(ddsd);
7505 ddsd.dwFlags = DDSD_CAPS;
7506 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
7508 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
7509 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
7511 test_format = GetPixelFormat(hdc);
7512 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
7514 if (hdc2)
7516 test_format = GetPixelFormat(hdc2);
7517 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
7520 if (clipper)
7522 hr = IDirectDrawSurface7_SetClipper(primary, clipper);
7523 ok(SUCCEEDED(hr), "Failed to set clipper, hr %#x.\n", hr);
7525 test_format = GetPixelFormat(hdc);
7526 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
7528 test_format = GetPixelFormat(hdc2);
7529 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
7532 memset(&fx, 0, sizeof(fx));
7533 fx.dwSize = sizeof(fx);
7534 hr = IDirectDrawSurface7_Blt(primary, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
7535 ok(SUCCEEDED(hr), "Failed to clear source surface, hr %#x.\n", hr);
7537 test_format = GetPixelFormat(hdc);
7538 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
7540 if (hdc2)
7542 test_format = GetPixelFormat(hdc2);
7543 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
7546 cleanup:
7547 if (primary) IDirectDrawSurface7_Release(primary);
7548 if (clipper) IDirectDrawClipper_Release(clipper);
7549 if (ddraw) IDirectDraw7_Release(ddraw);
7550 if (gl) FreeLibrary(gl);
7551 if (hdc) ReleaseDC(window, hdc);
7552 if (hdc2) ReleaseDC(window2, hdc2);
7553 if (window) DestroyWindow(window);
7554 if (window2) DestroyWindow(window2);
7557 static void test_create_surface_pitch(void)
7559 IDirectDrawSurface7 *surface;
7560 DDSURFACEDESC2 surface_desc;
7561 IDirectDraw7 *ddraw;
7562 unsigned int i;
7563 ULONG refcount;
7564 HWND window;
7565 HRESULT hr;
7566 void *mem;
7568 static const struct
7570 DWORD caps;
7571 DWORD flags_in;
7572 DWORD pitch_in;
7573 HRESULT hr;
7574 DWORD flags_out;
7575 DWORD pitch_out32;
7576 DWORD pitch_out64;
7578 test_data[] =
7580 /* 0 */
7581 {DDSCAPS_VIDEOMEMORY | DDSCAPS_OFFSCREENPLAIN,
7582 0, 0, DD_OK,
7583 DDSD_PITCH, 0x100, 0x100},
7584 {DDSCAPS_VIDEOMEMORY | DDSCAPS_OFFSCREENPLAIN,
7585 DDSD_PITCH, 0x104, DD_OK,
7586 DDSD_PITCH, 0x100, 0x100},
7587 {DDSCAPS_VIDEOMEMORY | DDSCAPS_OFFSCREENPLAIN,
7588 DDSD_PITCH, 0x0f8, DD_OK,
7589 DDSD_PITCH, 0x100, 0x100},
7590 {DDSCAPS_VIDEOMEMORY | DDSCAPS_OFFSCREENPLAIN,
7591 DDSD_LPSURFACE | DDSD_PITCH, 0x100, DDERR_INVALIDCAPS,
7592 0, 0, 0 },
7593 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
7594 0, 0, DD_OK,
7595 DDSD_PITCH, 0x100, 0x0fc},
7596 /* 5 */
7597 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
7598 DDSD_PITCH, 0x104, DD_OK,
7599 DDSD_PITCH, 0x100, 0x0fc},
7600 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
7601 DDSD_PITCH, 0x0f8, DD_OK,
7602 DDSD_PITCH, 0x100, 0x0fc},
7603 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
7604 DDSD_PITCH | DDSD_LINEARSIZE, 0, DD_OK,
7605 DDSD_PITCH, 0x100, 0x0fc},
7606 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
7607 DDSD_LPSURFACE, 0, DDERR_INVALIDPARAMS,
7608 0, 0, 0 },
7609 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
7610 DDSD_LPSURFACE | DDSD_PITCH, 0x100, DD_OK,
7611 DDSD_PITCH, 0x100, 0x100},
7612 /* 10 */
7613 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
7614 DDSD_LPSURFACE | DDSD_PITCH, 0x0fe, DDERR_INVALIDPARAMS,
7615 0, 0, 0 },
7616 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
7617 DDSD_LPSURFACE | DDSD_PITCH, 0x0fc, DD_OK,
7618 DDSD_PITCH, 0x0fc, 0x0fc},
7619 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
7620 DDSD_LPSURFACE | DDSD_PITCH, 0x0f8, DDERR_INVALIDPARAMS,
7621 0, 0, 0 },
7622 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
7623 DDSD_LPSURFACE | DDSD_LINEARSIZE, 0x100, DDERR_INVALIDPARAMS,
7624 0, 0, 0 },
7625 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
7626 DDSD_LPSURFACE | DDSD_LINEARSIZE, 0x3f00, DDERR_INVALIDPARAMS,
7627 0, 0, 0 },
7628 /* 15 */
7629 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
7630 DDSD_LPSURFACE | DDSD_PITCH | DDSD_LINEARSIZE, 0x100, DD_OK,
7631 DDSD_PITCH, 0x100, 0x100},
7632 {DDSCAPS_VIDEOMEMORY | DDSCAPS_OFFSCREENPLAIN | DDSCAPS_ALLOCONLOAD,
7633 0, 0, DDERR_INVALIDCAPS,
7634 0, 0, 0 },
7635 {DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD,
7636 0, 0, DD_OK,
7637 DDSD_PITCH, 0x100, 0 },
7638 {DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD,
7639 DDSD_LPSURFACE | DDSD_PITCH, 0x100, DDERR_INVALIDCAPS,
7640 0, 0, 0 },
7641 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN | DDSCAPS_ALLOCONLOAD,
7642 0, 0, DDERR_INVALIDCAPS,
7643 0, 0, 0 },
7644 /* 20 */
7645 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD,
7646 0, 0, DD_OK,
7647 DDSD_PITCH, 0x100, 0 },
7648 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD,
7649 DDSD_LPSURFACE | DDSD_PITCH, 0x100, DD_OK,
7650 DDSD_PITCH, 0x100, 0 },
7652 DWORD flags_mask = DDSD_PITCH | DDSD_LPSURFACE | DDSD_LINEARSIZE;
7654 window = create_window();
7655 ddraw = create_ddraw();
7656 ok(!!ddraw, "Failed to create a ddraw object.\n");
7657 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
7658 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
7660 mem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ((63 * 4) + 8) * 63);
7662 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
7664 memset(&surface_desc, 0, sizeof(surface_desc));
7665 surface_desc.dwSize = sizeof(surface_desc);
7666 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | test_data[i].flags_in;
7667 surface_desc.ddsCaps.dwCaps = test_data[i].caps;
7668 surface_desc.dwWidth = 63;
7669 surface_desc.dwHeight = 63;
7670 U1(surface_desc).lPitch = test_data[i].pitch_in;
7671 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
7672 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
7673 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
7674 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
7675 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
7676 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
7677 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7678 if (test_data[i].flags_in & DDSD_LPSURFACE)
7680 HRESULT expected_hr = SUCCEEDED(test_data[i].hr) ? DDERR_INVALIDPARAMS : test_data[i].hr;
7681 ok(hr == expected_hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, expected_hr);
7682 surface_desc.lpSurface = mem;
7683 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7685 if ((test_data[i].caps & DDSCAPS_VIDEOMEMORY) && hr == DDERR_NODIRECTDRAWHW)
7686 continue;
7687 if (is_ddraw64 && (test_data[i].caps & DDSCAPS_TEXTURE) && SUCCEEDED(test_data[i].hr))
7688 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Got unexpected hr %#x.\n", i, hr);
7689 else
7690 ok(hr == test_data[i].hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, test_data[i].hr);
7691 if (FAILED(hr))
7692 continue;
7694 memset(&surface_desc, 0, sizeof(surface_desc));
7695 surface_desc.dwSize = sizeof(surface_desc);
7696 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &surface_desc);
7697 ok(SUCCEEDED(hr), "Test %u: Failed to get surface desc, hr %#x.\n", i, hr);
7698 ok((surface_desc.dwFlags & flags_mask) == test_data[i].flags_out,
7699 "Test %u: Got unexpected flags %#x, expected %#x.\n",
7700 i, surface_desc.dwFlags & flags_mask, test_data[i].flags_out);
7701 /* The pitch for textures seems to be implementation specific. */
7702 if (!(test_data[i].caps & DDSCAPS_TEXTURE))
7704 if (is_ddraw64 && test_data[i].pitch_out32 != test_data[i].pitch_out64)
7705 todo_wine ok(U1(surface_desc).lPitch == test_data[i].pitch_out64,
7706 "Test %u: Got unexpected pitch %u, expected %u.\n",
7707 i, U1(surface_desc).lPitch, test_data[i].pitch_out64);
7708 else
7709 ok(U1(surface_desc).lPitch == test_data[i].pitch_out32,
7710 "Test %u: Got unexpected pitch %u, expected %u.\n",
7711 i, U1(surface_desc).lPitch, test_data[i].pitch_out32);
7713 ok(!surface_desc.lpSurface, "Test %u: Got unexpected lpSurface %p.\n", i, surface_desc.lpSurface);
7715 IDirectDrawSurface7_Release(surface);
7718 HeapFree(GetProcessHeap(), 0, mem);
7719 refcount = IDirectDraw7_Release(ddraw);
7720 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7721 DestroyWindow(window);
7724 static void test_mipmap(void)
7726 IDirectDrawSurface7 *surface, *surface2;
7727 DDSURFACEDESC2 surface_desc;
7728 IDirectDraw7 *ddraw;
7729 unsigned int i;
7730 ULONG refcount;
7731 HWND window;
7732 HRESULT hr;
7733 DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, {0}};
7734 DDCAPS hal_caps;
7736 static const struct
7738 DWORD flags;
7739 DWORD caps;
7740 DWORD width;
7741 DWORD height;
7742 DWORD mipmap_count_in;
7743 HRESULT hr;
7744 DWORD mipmap_count_out;
7746 tests[] =
7748 {DDSD_MIPMAPCOUNT, DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP, 128, 32, 3, DD_OK, 3},
7749 {DDSD_MIPMAPCOUNT, DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP, 128, 32, 0, DDERR_INVALIDPARAMS, 0},
7750 {0, DDSCAPS_TEXTURE | DDSCAPS_MIPMAP, 128, 32, 0, DD_OK, 1},
7751 {0, DDSCAPS_MIPMAP, 128, 32, 0, DDERR_INVALIDCAPS, 0},
7752 {0, DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP, 128, 32, 0, DD_OK, 8},
7753 {0, DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP, 32, 64, 0, DD_OK, 7},
7756 window = create_window();
7757 ddraw = create_ddraw();
7758 ok(!!ddraw, "Failed to create a ddraw object.\n");
7759 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
7760 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
7762 memset(&hal_caps, 0, sizeof(hal_caps));
7763 hal_caps.dwSize = sizeof(hal_caps);
7764 hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, NULL);
7765 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
7766 if ((hal_caps.ddsCaps.dwCaps & (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP)) != (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP)
7767 || is_ddraw64)
7769 skip("Mipmapped textures not supported, skipping tests.\n");
7770 IDirectDraw7_Release(ddraw);
7771 DestroyWindow(window);
7772 return;
7775 for (i = 0; i < ARRAY_SIZE(tests); ++i)
7777 memset(&surface_desc, 0, sizeof(surface_desc));
7778 surface_desc.dwSize = sizeof(surface_desc);
7779 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | tests[i].flags;
7780 surface_desc.ddsCaps.dwCaps = tests[i].caps;
7781 surface_desc.dwWidth = tests[i].width;
7782 surface_desc.dwHeight = tests[i].height;
7783 if (tests[i].flags & DDSD_MIPMAPCOUNT)
7784 U2(surface_desc).dwMipMapCount = tests[i].mipmap_count_in;
7785 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7786 ok(hr == tests[i].hr, "Test %u: Got unexpected hr %#x.\n", i, hr);
7787 if (FAILED(hr))
7788 continue;
7790 memset(&surface_desc, 0, sizeof(surface_desc));
7791 surface_desc.dwSize = sizeof(surface_desc);
7792 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &surface_desc);
7793 ok(SUCCEEDED(hr), "Test %u: Failed to get surface desc, hr %#x.\n", i, hr);
7794 ok(surface_desc.dwFlags & DDSD_MIPMAPCOUNT,
7795 "Test %u: Got unexpected flags %#x.\n", i, surface_desc.dwFlags);
7796 ok(U2(surface_desc).dwMipMapCount == tests[i].mipmap_count_out,
7797 "Test %u: Got unexpected mipmap count %u.\n", i, U2(surface_desc).dwMipMapCount);
7799 if (U2(surface_desc).dwMipMapCount > 1)
7801 hr = IDirectDrawSurface7_GetAttachedSurface(surface, &caps, &surface2);
7802 ok(SUCCEEDED(hr), "Test %u: Failed to get attached surface, hr %#x.\n", i, hr);
7804 memset(&surface_desc, 0, sizeof(surface_desc));
7805 surface_desc.dwSize = sizeof(surface_desc);
7806 hr = IDirectDrawSurface7_Lock(surface, NULL, &surface_desc, 0, NULL);
7807 ok(SUCCEEDED(hr), "Test %u: Failed to lock surface, hr %#x.\n", i, hr);
7808 memset(&surface_desc, 0, sizeof(surface_desc));
7809 surface_desc.dwSize = sizeof(surface_desc);
7810 hr = IDirectDrawSurface7_Lock(surface2, NULL, &surface_desc, 0, NULL);
7811 ok(SUCCEEDED(hr), "Test %u: Failed to lock surface, hr %#x.\n", i, hr);
7812 IDirectDrawSurface7_Unlock(surface2, NULL);
7813 IDirectDrawSurface7_Unlock(surface, NULL);
7815 IDirectDrawSurface7_Release(surface2);
7818 IDirectDrawSurface7_Release(surface);
7821 refcount = IDirectDraw7_Release(ddraw);
7822 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7823 DestroyWindow(window);
7826 static void test_palette_complex(void)
7828 IDirectDrawSurface7 *surface, *mipmap, *tmp;
7829 DDSURFACEDESC2 surface_desc;
7830 IDirectDraw7 *ddraw;
7831 IDirectDrawPalette *palette, *palette2;
7832 ULONG refcount;
7833 HWND window;
7834 HRESULT hr;
7835 DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, {0}};
7836 DDCAPS hal_caps;
7837 PALETTEENTRY palette_entries[256];
7838 unsigned int i;
7840 window = create_window();
7841 ddraw = create_ddraw();
7842 ok(!!ddraw, "Failed to create a ddraw object.\n");
7843 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
7844 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
7846 memset(&hal_caps, 0, sizeof(hal_caps));
7847 hal_caps.dwSize = sizeof(hal_caps);
7848 hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, NULL);
7849 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
7850 if ((hal_caps.ddsCaps.dwCaps & (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP)) != (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP)
7851 || is_ddraw64)
7853 skip("Mipmapped textures not supported, skipping mipmap palette test.\n");
7854 IDirectDraw7_Release(ddraw);
7855 DestroyWindow(window);
7856 return;
7859 memset(&surface_desc, 0, sizeof(surface_desc));
7860 surface_desc.dwSize = sizeof(surface_desc);
7861 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
7862 surface_desc.dwWidth = 128;
7863 surface_desc.dwHeight = 128;
7864 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
7865 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
7866 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
7867 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 8;
7868 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7869 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7871 memset(palette_entries, 0, sizeof(palette_entries));
7872 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
7873 palette_entries, &palette, NULL);
7874 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
7876 palette2 = (void *)0xdeadbeef;
7877 hr = IDirectDrawSurface7_GetPalette(surface, &palette2);
7878 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x.\n", hr);
7879 ok(!palette2, "Got unexpected palette %p.\n", palette2);
7880 hr = IDirectDrawSurface7_SetPalette(surface, palette);
7881 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
7882 hr = IDirectDrawSurface7_GetPalette(surface, &palette2);
7883 ok(SUCCEEDED(hr), "Failed to get palette, hr %#x.\n", hr);
7884 ok(palette == palette2, "Got unexpected palette %p.\n", palette2);
7885 IDirectDrawPalette_Release(palette2);
7887 mipmap = surface;
7888 IDirectDrawSurface7_AddRef(mipmap);
7889 for (i = 0; i < 7; ++i)
7891 hr = IDirectDrawSurface7_GetAttachedSurface(mipmap, &caps, &tmp);
7892 ok(SUCCEEDED(hr), "Failed to get attached surface, i %u, hr %#x.\n", i, hr);
7893 palette2 = (void *)0xdeadbeef;
7894 hr = IDirectDrawSurface7_GetPalette(tmp, &palette2);
7895 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x, i %u.\n", hr, i);
7896 ok(!palette2, "Got unexpected palette %p, i %u.\n", palette2, i);
7898 hr = IDirectDrawSurface7_SetPalette(tmp, palette);
7899 ok(hr == DDERR_NOTONMIPMAPSUBLEVEL, "Got unexpected hr %#x, i %u.\n", hr, i);
7901 hr = IDirectDrawSurface7_GetPalette(tmp, &palette2);
7902 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x, i %u.\n", hr, i);
7903 ok(!palette2, "Got unexpected palette %p, i %u.\n", palette2, i);
7905 /* Ddraw7 uses the palette of the mipmap for GetDC, just like previous
7906 * ddraw versions. Combined with the test results above this means no
7907 * palette is available. So depending on the driver either GetDC fails
7908 * or the DIB color table contains random data. */
7910 IDirectDrawSurface7_Release(mipmap);
7911 mipmap = tmp;
7914 hr = IDirectDrawSurface7_GetAttachedSurface(mipmap, &caps, &tmp);
7915 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
7916 IDirectDrawSurface7_Release(mipmap);
7917 refcount = IDirectDrawSurface7_Release(surface);
7918 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7920 /* Test DDERR_INVALIDPIXELFORMAT vs DDERR_NOTONMIPMAPSUBLEVEL. */
7921 memset(&surface_desc, 0, sizeof(surface_desc));
7922 surface_desc.dwSize = sizeof(surface_desc);
7923 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
7924 surface_desc.dwWidth = 128;
7925 surface_desc.dwHeight = 128;
7926 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
7927 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
7928 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
7929 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
7930 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
7931 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
7932 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
7933 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7934 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7936 hr = IDirectDrawSurface7_GetAttachedSurface(surface, &caps, &mipmap);
7937 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
7938 hr = IDirectDrawSurface7_SetPalette(mipmap, palette);
7939 ok(hr == DDERR_NOTONMIPMAPSUBLEVEL, "Got unexpected hr %#x.\n", hr);
7941 IDirectDrawSurface7_Release(mipmap);
7942 refcount = IDirectDrawSurface7_Release(surface);
7943 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7944 refcount = IDirectDrawPalette_Release(palette);
7945 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7947 refcount = IDirectDraw7_Release(ddraw);
7948 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7949 DestroyWindow(window);
7952 static void test_p8_blit(void)
7954 IDirectDrawSurface7 *src, *dst, *dst_p8;
7955 DDSURFACEDESC2 surface_desc;
7956 IDirectDraw7 *ddraw;
7957 IDirectDrawPalette *palette, *palette2;
7958 ULONG refcount;
7959 HWND window;
7960 HRESULT hr;
7961 PALETTEENTRY palette_entries[256];
7962 unsigned int x;
7963 DDBLTFX fx;
7964 BOOL is_warp;
7965 static const BYTE src_data[] = {0x10, 0x1, 0x2, 0x3, 0x4, 0x5, 0xff, 0x80};
7966 static const BYTE src_data2[] = {0x10, 0x5, 0x4, 0x3, 0x2, 0x1, 0xff, 0x80};
7967 static const BYTE expected_p8[] = {0x10, 0x1, 0x4, 0x3, 0x4, 0x5, 0xff, 0x80};
7968 static const D3DCOLOR expected[] =
7970 0x00101010, 0x00010101, 0x00020202, 0x00030303,
7971 0x00040404, 0x00050505, 0x00ffffff, 0x00808080,
7973 D3DCOLOR color;
7975 window = create_window();
7976 ddraw = create_ddraw();
7977 ok(!!ddraw, "Failed to create a ddraw object.\n");
7978 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
7979 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
7980 is_warp = ddraw_is_warp(ddraw);
7982 memset(palette_entries, 0, sizeof(palette_entries));
7983 palette_entries[1].peGreen = 0xff;
7984 palette_entries[2].peBlue = 0xff;
7985 palette_entries[3].peFlags = 0xff;
7986 palette_entries[4].peRed = 0xff;
7987 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
7988 palette_entries, &palette, NULL);
7989 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
7990 palette_entries[1].peBlue = 0xff;
7991 palette_entries[2].peGreen = 0xff;
7992 palette_entries[3].peRed = 0xff;
7993 palette_entries[4].peFlags = 0x0;
7994 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
7995 palette_entries, &palette2, NULL);
7996 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
7998 memset(&surface_desc, 0, sizeof(surface_desc));
7999 surface_desc.dwSize = sizeof(surface_desc);
8000 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
8001 surface_desc.dwWidth = 8;
8002 surface_desc.dwHeight = 1;
8003 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
8004 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
8005 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
8006 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 8;
8007 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &src, NULL);
8008 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8009 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &dst_p8, NULL);
8010 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8011 hr = IDirectDrawSurface7_SetPalette(dst_p8, palette2);
8012 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
8014 memset(&surface_desc, 0, sizeof(surface_desc));
8015 surface_desc.dwSize = sizeof(surface_desc);
8016 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
8017 surface_desc.dwWidth = 8;
8018 surface_desc.dwHeight = 1;
8019 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
8020 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
8021 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
8022 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
8023 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
8024 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
8025 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
8026 U5(U4(surface_desc).ddpfPixelFormat).dwRGBAlphaBitMask = 0xff000000;
8027 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &dst, NULL);
8028 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8030 memset(&surface_desc, 0, sizeof(surface_desc));
8031 surface_desc.dwSize = sizeof(surface_desc);
8032 hr = IDirectDrawSurface7_Lock(src, NULL, &surface_desc, DDLOCK_WAIT, NULL);
8033 ok(SUCCEEDED(hr), "Failed to lock source surface, hr %#x.\n", hr);
8034 memcpy(surface_desc.lpSurface, src_data, sizeof(src_data));
8035 hr = IDirectDrawSurface7_Unlock(src, NULL);
8036 ok(SUCCEEDED(hr), "Failed to unlock source surface, hr %#x.\n", hr);
8038 hr = IDirectDrawSurface7_Lock(dst_p8, NULL, &surface_desc, DDLOCK_WAIT, NULL);
8039 ok(SUCCEEDED(hr), "Failed to lock destination surface, hr %#x.\n", hr);
8040 memcpy(surface_desc.lpSurface, src_data2, sizeof(src_data2));
8041 hr = IDirectDrawSurface7_Unlock(dst_p8, NULL);
8042 ok(SUCCEEDED(hr), "Failed to unlock destination surface, hr %#x.\n", hr);
8044 hr = IDirectDrawSurface7_SetPalette(src, palette);
8045 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
8046 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_WAIT, NULL);
8047 /* The r500 Windows 7 driver returns E_NOTIMPL. r200 on Windows XP works.
8048 * The Geforce 7 driver on Windows Vista returns E_FAIL. Newer Nvidia GPUs work. */
8049 ok(SUCCEEDED(hr) || broken(hr == E_NOTIMPL) || broken(hr == E_FAIL),
8050 "Failed to blit, hr %#x.\n", hr);
8052 if (SUCCEEDED(hr))
8054 for (x = 0; x < ARRAY_SIZE(expected); ++x)
8056 color = get_surface_color(dst, x, 0);
8057 todo_wine ok(compare_color(color, expected[x], 0),
8058 "Pixel %u: Got color %#x, expected %#x.\n",
8059 x, color, expected[x]);
8063 memset(&fx, 0, sizeof(fx));
8064 fx.dwSize = sizeof(fx);
8065 fx.ddckSrcColorkey.dwColorSpaceHighValue = 0x2;
8066 fx.ddckSrcColorkey.dwColorSpaceLowValue = 0x2;
8067 hr = IDirectDrawSurface7_Blt(dst_p8, NULL, src, NULL, DDBLT_WAIT | DDBLT_KEYSRCOVERRIDE, &fx);
8068 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
8070 hr = IDirectDrawSurface7_Lock(dst_p8, NULL, &surface_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
8071 ok(SUCCEEDED(hr), "Failed to lock destination surface, hr %#x.\n", hr);
8072 /* A color keyed P8 blit doesn't do anything on WARP - it just leaves the data in the destination
8073 * surface untouched. P8 blits without color keys work. Error checking (DDBLT_KEYSRC without a key
8074 * for example) also works as expected.
8076 * Using DDBLT_KEYSRC instead of DDBLT_KEYSRCOVERRIDE doesn't change this. Doing this blit with
8077 * the display mode set to P8 doesn't help either. */
8078 ok(!memcmp(surface_desc.lpSurface, expected_p8, sizeof(expected_p8))
8079 || broken(is_warp && !memcmp(surface_desc.lpSurface, src_data2, sizeof(src_data2))),
8080 "Got unexpected P8 color key blit result.\n");
8081 hr = IDirectDrawSurface7_Unlock(dst_p8, NULL);
8082 ok(SUCCEEDED(hr), "Failed to unlock destination surface, hr %#x.\n", hr);
8084 IDirectDrawSurface7_Release(src);
8085 IDirectDrawSurface7_Release(dst);
8086 IDirectDrawSurface7_Release(dst_p8);
8087 IDirectDrawPalette_Release(palette);
8088 IDirectDrawPalette_Release(palette2);
8090 refcount = IDirectDraw7_Release(ddraw);
8091 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8092 DestroyWindow(window);
8095 static void test_material(void)
8097 static const D3DCOLORVALUE null_color;
8098 IDirect3DDevice7 *device;
8099 D3DMATERIAL7 material;
8100 ULONG refcount;
8101 HWND window;
8102 HRESULT hr;
8104 window = create_window();
8105 if (!(device = create_device(window, DDSCL_NORMAL)))
8107 skip("Failed to create a 3D device, skipping test.\n");
8108 DestroyWindow(window);
8109 return;
8112 hr = IDirect3DDevice7_GetMaterial(device, &material);
8113 ok(SUCCEEDED(hr), "Failed to get material, hr %#x.\n", hr);
8114 ok(!memcmp(&U(material).diffuse, &null_color, sizeof(null_color)),
8115 "Got unexpected diffuse color {%.8e, %.8e, %.8e, %.8e}.\n",
8116 U1(U(material).diffuse).r, U2(U(material).diffuse).g,
8117 U3(U(material).diffuse).b, U4(U(material).diffuse).a);
8118 ok(!memcmp(&U1(material).ambient, &null_color, sizeof(null_color)),
8119 "Got unexpected ambient color {%.8e, %.8e, %.8e, %.8e}.\n",
8120 U1(U1(material).ambient).r, U2(U1(material).ambient).g,
8121 U3(U1(material).ambient).b, U4(U1(material).ambient).a);
8122 ok(!memcmp(&U2(material).specular, &null_color, sizeof(null_color)),
8123 "Got unexpected specular color {%.8e, %.8e, %.8e, %.8e}.\n",
8124 U1(U2(material).specular).r, U2(U2(material).specular).g,
8125 U3(U2(material).specular).b, U4(U2(material).specular).a);
8126 ok(!memcmp(&U3(material).emissive, &null_color, sizeof(null_color)),
8127 "Got unexpected emissive color {%.8e, %.8e, %.8e, %.8e}.\n",
8128 U1(U3(material).emissive).r, U2(U3(material).emissive).g,
8129 U3(U3(material).emissive).b, U4(U3(material).emissive).a);
8130 ok(U4(material).power == 0.0f, "Got unexpected power %.8e.\n", U4(material).power);
8132 refcount = IDirect3DDevice7_Release(device);
8133 ok(!refcount, "Device has %u references left.\n", refcount);
8134 DestroyWindow(window);
8137 static void test_palette_gdi(void)
8139 IDirectDrawSurface7 *surface, *primary;
8140 DDSURFACEDESC2 surface_desc;
8141 IDirectDraw7 *ddraw;
8142 IDirectDrawPalette *palette, *palette2;
8143 ULONG refcount;
8144 HWND window;
8145 HRESULT hr;
8146 PALETTEENTRY palette_entries[256];
8147 UINT i;
8148 HDC dc;
8149 DDBLTFX fx;
8150 RECT r;
8151 COLORREF color;
8152 /* On the Windows 8 testbot palette index 0 of the onscreen palette is forced to
8153 * r = 0, g = 0, b = 0. Do not attempt to set it to something else as this is
8154 * not the point of this test. */
8155 static const RGBQUAD expected1[] =
8157 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
8158 {0x03, 0x00, 0x00, 0x00}, {0x15, 0x14, 0x13, 0x00},
8160 static const RGBQUAD expected2[] =
8162 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
8163 {0x03, 0x00, 0x00, 0x00}, {0x25, 0x24, 0x23, 0x00},
8165 static const RGBQUAD expected3[] =
8167 {0x00, 0x00, 0x00, 0x00}, {0x40, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x40, 0x00},
8168 {0x00, 0x40, 0x00, 0x00}, {0x56, 0x34, 0x12, 0x00},
8170 HPALETTE ddraw_palette_handle;
8171 /* Similar to index 0, index 255 is r = 0xff, g = 0xff, b = 0xff on the Win8 VMs. */
8172 RGBQUAD rgbquad[255];
8173 static const RGBQUAD rgb_zero = {0, 0, 0, 0};
8175 window = create_window();
8176 ddraw = create_ddraw();
8177 ok(!!ddraw, "Failed to create a ddraw object.\n");
8178 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
8179 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
8181 memset(&surface_desc, 0, sizeof(surface_desc));
8182 surface_desc.dwSize = sizeof(surface_desc);
8183 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
8184 surface_desc.dwWidth = 16;
8185 surface_desc.dwHeight = 16;
8186 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
8187 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
8188 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
8189 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 8;
8190 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8191 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8193 /* Avoid colors from the Windows default palette. */
8194 memset(palette_entries, 0, sizeof(palette_entries));
8195 palette_entries[1].peRed = 0x01;
8196 palette_entries[2].peGreen = 0x02;
8197 palette_entries[3].peBlue = 0x03;
8198 palette_entries[4].peRed = 0x13;
8199 palette_entries[4].peGreen = 0x14;
8200 palette_entries[4].peBlue = 0x15;
8201 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
8202 palette_entries, &palette, NULL);
8203 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
8205 /* If there is no palette assigned and the display mode is not 8 bpp, some
8206 * drivers refuse to create a DC while others allow it. If a DC is created,
8207 * the DIB color table is uninitialized and contains random colors. No error
8208 * is generated when trying to read pixels and random garbage is returned.
8210 * The most likely explanation is that if the driver creates a DC, it (or
8211 * the higher-level runtime) uses GetSystemPaletteEntries to find the
8212 * palette, but GetSystemPaletteEntries fails when bpp > 8 and the palette
8213 * contains uninitialized garbage. See comments below for the P8 case. */
8215 hr = IDirectDrawSurface7_SetPalette(surface, palette);
8216 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
8217 hr = IDirectDrawSurface7_GetDC(surface, &dc);
8218 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
8219 ddraw_palette_handle = SelectPalette(dc, GetStockObject(DEFAULT_PALETTE), FALSE);
8220 ok(ddraw_palette_handle == GetStockObject(DEFAULT_PALETTE),
8221 "Got unexpected palette %p, expected %p.\n",
8222 ddraw_palette_handle, GetStockObject(DEFAULT_PALETTE));
8224 i = GetDIBColorTable(dc, 0, ARRAY_SIZE(rgbquad), rgbquad);
8225 ok(i == ARRAY_SIZE(rgbquad), "Expected count 255, got %u.\n", i);
8226 for (i = 0; i < ARRAY_SIZE(expected1); ++i)
8228 ok(!memcmp(&rgbquad[i], &expected1[i], sizeof(rgbquad[i])),
8229 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8230 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
8231 expected1[i].rgbRed, expected1[i].rgbGreen, expected1[i].rgbBlue);
8233 for (; i < ARRAY_SIZE(rgbquad); ++i)
8235 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
8236 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
8237 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
8240 /* Update the palette while the DC is in use. This does not modify the DC. */
8241 palette_entries[4].peRed = 0x23;
8242 palette_entries[4].peGreen = 0x24;
8243 palette_entries[4].peBlue = 0x25;
8244 hr = IDirectDrawPalette_SetEntries(palette, 0, 4, 1, &palette_entries[4]);
8245 ok(SUCCEEDED(hr), "Failed to set palette entries, hr %#x.\n", hr);
8247 i = GetDIBColorTable(dc, 4, 1, &rgbquad[4]);
8248 ok(i == 1, "Expected count 1, got %u.\n", i);
8249 ok(!memcmp(&rgbquad[4], &expected1[4], sizeof(rgbquad[4])),
8250 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8251 i, rgbquad[4].rgbRed, rgbquad[4].rgbGreen, rgbquad[4].rgbBlue,
8252 expected1[4].rgbRed, expected1[4].rgbGreen, expected1[4].rgbBlue);
8254 /* Neither does re-setting the palette. */
8255 hr = IDirectDrawSurface7_SetPalette(surface, NULL);
8256 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
8257 hr = IDirectDrawSurface7_SetPalette(surface, palette);
8258 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
8260 i = GetDIBColorTable(dc, 4, 1, &rgbquad[4]);
8261 ok(i == 1, "Expected count 1, got %u.\n", i);
8262 ok(!memcmp(&rgbquad[4], &expected1[4], sizeof(rgbquad[4])),
8263 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8264 i, rgbquad[4].rgbRed, rgbquad[4].rgbGreen, rgbquad[4].rgbBlue,
8265 expected1[4].rgbRed, expected1[4].rgbGreen, expected1[4].rgbBlue);
8267 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
8268 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
8270 /* Refresh the DC. This updates the palette. */
8271 hr = IDirectDrawSurface7_GetDC(surface, &dc);
8272 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
8273 i = GetDIBColorTable(dc, 0, ARRAY_SIZE(rgbquad), rgbquad);
8274 ok(i == ARRAY_SIZE(rgbquad), "Expected count 255, got %u.\n", i);
8275 for (i = 0; i < ARRAY_SIZE(expected2); ++i)
8277 ok(!memcmp(&rgbquad[i], &expected2[i], sizeof(rgbquad[i])),
8278 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8279 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
8280 expected2[i].rgbRed, expected2[i].rgbGreen, expected2[i].rgbBlue);
8282 for (; i < ARRAY_SIZE(rgbquad); ++i)
8284 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
8285 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
8286 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
8288 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
8289 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
8291 refcount = IDirectDrawSurface7_Release(surface);
8292 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8294 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
8295 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
8296 if (FAILED(IDirectDraw7_SetDisplayMode(ddraw, 640, 480, 8, 0, 0)))
8298 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
8299 IDirectDrawPalette_Release(palette);
8300 IDirectDraw7_Release(ddraw);
8301 DestroyWindow(window);
8302 return;
8304 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
8306 memset(&surface_desc, 0, sizeof(surface_desc));
8307 surface_desc.dwSize = sizeof(surface_desc);
8308 surface_desc.dwFlags = DDSD_CAPS;
8309 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
8310 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &primary, NULL);
8311 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8313 memset(&fx, 0, sizeof(fx));
8314 fx.dwSize = sizeof(fx);
8315 U5(fx).dwFillColor = 3;
8316 SetRect(&r, 0, 0, 319, 479);
8317 hr = IDirectDrawSurface7_Blt(primary, &r, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
8318 ok(SUCCEEDED(hr), "Failed to clear surface, hr %#x.\n", hr);
8319 SetRect(&r, 320, 0, 639, 479);
8320 U5(fx).dwFillColor = 4;
8321 hr = IDirectDrawSurface7_Blt(primary, &r, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
8322 ok(SUCCEEDED(hr), "Failed to clear surface, hr %#x.\n", hr);
8324 hr = IDirectDrawSurface7_SetPalette(primary, palette);
8325 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
8326 hr = IDirectDrawSurface7_GetDC(primary, &dc);
8327 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
8329 color = GetPixel(dc, 160, 240);
8330 ok(color == 0x00030000, "Clear index 3: Got unexpected color 0x%08x.\n", color);
8331 color = GetPixel(dc, 480, 240);
8332 ok(color == 0x00252423, "Clear index 4: Got unexpected color 0x%08x.\n", color);
8334 ddraw_palette_handle = SelectPalette(dc, GetStockObject(DEFAULT_PALETTE), FALSE);
8335 ok(ddraw_palette_handle == GetStockObject(DEFAULT_PALETTE),
8336 "Got unexpected palette %p, expected %p.\n",
8337 ddraw_palette_handle, GetStockObject(DEFAULT_PALETTE));
8338 SelectPalette(dc, ddraw_palette_handle, FALSE);
8340 /* The primary uses the system palette. In exclusive mode, the system palette matches
8341 * the ddraw palette attached to the primary, so the result is what you would expect
8342 * from a regular surface. Tests for the interaction between the ddraw palette and
8343 * the system palette are not included pending an application that depends on this.
8344 * The relation between those causes problems on Windows Vista and newer for games
8345 * like Age of Empires or StarcCaft. Don't emulate it without a real need. */
8346 i = GetDIBColorTable(dc, 0, ARRAY_SIZE(rgbquad), rgbquad);
8347 ok(i == ARRAY_SIZE(rgbquad), "Expected count 255, got %u.\n", i);
8348 for (i = 0; i < ARRAY_SIZE(expected2); ++i)
8350 ok(!memcmp(&rgbquad[i], &expected2[i], sizeof(rgbquad[i])),
8351 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8352 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
8353 expected2[i].rgbRed, expected2[i].rgbGreen, expected2[i].rgbBlue);
8355 for (; i < ARRAY_SIZE(rgbquad); ++i)
8357 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
8358 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
8359 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
8361 hr = IDirectDrawSurface7_ReleaseDC(primary, dc);
8362 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
8364 memset(&surface_desc, 0, sizeof(surface_desc));
8365 surface_desc.dwSize = sizeof(surface_desc);
8366 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
8367 surface_desc.dwWidth = 16;
8368 surface_desc.dwHeight = 16;
8369 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
8370 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8371 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8373 /* Here the offscreen surface appears to use the primary's palette,
8374 * but in all likelihood it is actually the system palette. */
8375 hr = IDirectDrawSurface7_GetDC(surface, &dc);
8376 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
8377 i = GetDIBColorTable(dc, 0, ARRAY_SIZE(rgbquad), rgbquad);
8378 ok(i == ARRAY_SIZE(rgbquad), "Expected count 255, got %u.\n", i);
8379 for (i = 0; i < ARRAY_SIZE(expected2); ++i)
8381 ok(!memcmp(&rgbquad[i], &expected2[i], sizeof(rgbquad[i])),
8382 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8383 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
8384 expected2[i].rgbRed, expected2[i].rgbGreen, expected2[i].rgbBlue);
8386 for (; i < ARRAY_SIZE(rgbquad); ++i)
8388 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
8389 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
8390 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
8392 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
8393 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
8395 /* On real hardware a change to the primary surface's palette applies immediately,
8396 * even on device contexts from offscreen surfaces that do not have their own
8397 * palette. On the testbot VMs this is not the case. Don't test this until we
8398 * know of an application that depends on this. */
8400 memset(palette_entries, 0, sizeof(palette_entries));
8401 palette_entries[1].peBlue = 0x40;
8402 palette_entries[2].peRed = 0x40;
8403 palette_entries[3].peGreen = 0x40;
8404 palette_entries[4].peRed = 0x12;
8405 palette_entries[4].peGreen = 0x34;
8406 palette_entries[4].peBlue = 0x56;
8407 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
8408 palette_entries, &palette2, NULL);
8409 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
8410 hr = IDirectDrawSurface7_SetPalette(surface, palette2);
8411 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
8413 /* A palette assigned to the offscreen surface overrides the primary / system
8414 * palette. */
8415 hr = IDirectDrawSurface7_GetDC(surface, &dc);
8416 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
8417 i = GetDIBColorTable(dc, 0, ARRAY_SIZE(rgbquad), rgbquad);
8418 ok(i == ARRAY_SIZE(rgbquad), "Expected count 255, got %u.\n", i);
8419 for (i = 0; i < ARRAY_SIZE(expected3); ++i)
8421 ok(!memcmp(&rgbquad[i], &expected3[i], sizeof(rgbquad[i])),
8422 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8423 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
8424 expected3[i].rgbRed, expected3[i].rgbGreen, expected3[i].rgbBlue);
8426 for (; i < ARRAY_SIZE(rgbquad); ++i)
8428 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
8429 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
8430 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
8432 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
8433 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
8435 refcount = IDirectDrawSurface7_Release(surface);
8436 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8438 /* The Windows 8 testbot keeps extra references to the primary and
8439 * backbuffer while in 8 bpp mode. */
8440 hr = IDirectDraw7_RestoreDisplayMode(ddraw);
8441 ok(SUCCEEDED(hr), "Failed to restore display mode, hr %#x.\n", hr);
8443 refcount = IDirectDrawSurface7_Release(primary);
8444 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8445 refcount = IDirectDrawPalette_Release(palette2);
8446 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8447 refcount = IDirectDrawPalette_Release(palette);
8448 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8449 refcount = IDirectDraw7_Release(ddraw);
8450 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8451 DestroyWindow(window);
8454 static void test_palette_alpha(void)
8456 IDirectDrawSurface7 *surface;
8457 DDSURFACEDESC2 surface_desc;
8458 IDirectDraw7 *ddraw;
8459 IDirectDrawPalette *palette;
8460 ULONG refcount;
8461 HWND window;
8462 HRESULT hr;
8463 PALETTEENTRY palette_entries[256];
8464 unsigned int i;
8465 static const struct
8467 DWORD caps, flags;
8468 BOOL attach_allowed;
8469 const char *name;
8471 test_data[] =
8473 {DDSCAPS_OFFSCREENPLAIN, DDSD_WIDTH | DDSD_HEIGHT, FALSE, "offscreenplain"},
8474 {DDSCAPS_TEXTURE, DDSD_WIDTH | DDSD_HEIGHT, TRUE, "texture"},
8475 {DDSCAPS_PRIMARYSURFACE, 0, FALSE, "primary"}
8478 window = create_window();
8479 ddraw = create_ddraw();
8480 ok(!!ddraw, "Failed to create a ddraw object.\n");
8481 if (FAILED(IDirectDraw7_SetDisplayMode(ddraw, 640, 480, 8, 0, 0)))
8483 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
8484 IDirectDraw7_Release(ddraw);
8485 DestroyWindow(window);
8486 return;
8488 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
8489 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
8491 memset(palette_entries, 0, sizeof(palette_entries));
8492 palette_entries[1].peFlags = 0x42;
8493 palette_entries[2].peFlags = 0xff;
8494 palette_entries[3].peFlags = 0x80;
8495 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, palette_entries, &palette, NULL);
8496 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
8498 memset(palette_entries, 0x66, sizeof(palette_entries));
8499 hr = IDirectDrawPalette_GetEntries(palette, 0, 1, 4, palette_entries);
8500 ok(SUCCEEDED(hr), "Failed to get palette entries, hr %#x.\n", hr);
8501 ok(palette_entries[0].peFlags == 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
8502 palette_entries[0].peFlags);
8503 ok(palette_entries[1].peFlags == 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
8504 palette_entries[1].peFlags);
8505 ok(palette_entries[2].peFlags == 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
8506 palette_entries[2].peFlags);
8507 ok(palette_entries[3].peFlags == 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
8508 palette_entries[3].peFlags);
8510 IDirectDrawPalette_Release(palette);
8512 memset(palette_entries, 0, sizeof(palette_entries));
8513 palette_entries[1].peFlags = 0x42;
8514 palette_entries[1].peRed = 0xff;
8515 palette_entries[2].peFlags = 0xff;
8516 palette_entries[3].peFlags = 0x80;
8517 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_ALLOW256 | DDPCAPS_8BIT | DDPCAPS_ALPHA,
8518 palette_entries, &palette, NULL);
8519 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
8521 memset(palette_entries, 0x66, sizeof(palette_entries));
8522 hr = IDirectDrawPalette_GetEntries(palette, 0, 1, 4, palette_entries);
8523 ok(SUCCEEDED(hr), "Failed to get palette entries, hr %#x.\n", hr);
8524 ok(palette_entries[0].peFlags == 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
8525 palette_entries[0].peFlags);
8526 ok(palette_entries[1].peFlags == 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
8527 palette_entries[1].peFlags);
8528 ok(palette_entries[2].peFlags == 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
8529 palette_entries[2].peFlags);
8530 ok(palette_entries[3].peFlags == 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
8531 palette_entries[3].peFlags);
8533 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
8535 memset(&surface_desc, 0, sizeof(surface_desc));
8536 surface_desc.dwSize = sizeof(surface_desc);
8537 surface_desc.dwFlags = DDSD_CAPS | test_data[i].flags;
8538 surface_desc.dwWidth = 128;
8539 surface_desc.dwHeight = 128;
8540 surface_desc.ddsCaps.dwCaps = test_data[i].caps;
8541 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8542 ok(SUCCEEDED(hr), "Failed to create %s surface, hr %#x.\n", test_data[i].name, hr);
8544 hr = IDirectDrawSurface7_SetPalette(surface, palette);
8545 if (test_data[i].attach_allowed)
8546 ok(SUCCEEDED(hr), "Failed to attach palette to %s surface, hr %#x.\n", test_data[i].name, hr);
8547 else
8548 ok(hr == DDERR_INVALIDSURFACETYPE, "Got unexpected hr %#x, %s surface.\n", hr, test_data[i].name);
8550 if (SUCCEEDED(hr))
8552 HDC dc;
8553 RGBQUAD rgbquad;
8554 UINT retval;
8556 hr = IDirectDrawSurface7_GetDC(surface, &dc);
8557 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x, %s surface.\n", hr, test_data[i].name);
8558 retval = GetDIBColorTable(dc, 1, 1, &rgbquad);
8559 ok(retval == 1, "GetDIBColorTable returned unexpected result %u.\n", retval);
8560 ok(rgbquad.rgbRed == 0xff, "Expected rgbRed = 0xff, got %#x, %s surface.\n",
8561 rgbquad.rgbRed, test_data[i].name);
8562 ok(rgbquad.rgbGreen == 0, "Expected rgbGreen = 0, got %#x, %s surface.\n",
8563 rgbquad.rgbGreen, test_data[i].name);
8564 ok(rgbquad.rgbBlue == 0, "Expected rgbBlue = 0, got %#x, %s surface.\n",
8565 rgbquad.rgbBlue, test_data[i].name);
8566 ok(rgbquad.rgbReserved == 0, "Expected rgbReserved = 0, got %u, %s surface.\n",
8567 rgbquad.rgbReserved, test_data[i].name);
8568 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
8569 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
8571 IDirectDrawSurface7_Release(surface);
8574 /* Test INVALIDSURFACETYPE vs INVALIDPIXELFORMAT. */
8575 memset(&surface_desc, 0, sizeof(surface_desc));
8576 surface_desc.dwSize = sizeof(surface_desc);
8577 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
8578 surface_desc.dwWidth = 128;
8579 surface_desc.dwHeight = 128;
8580 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
8581 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
8582 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
8583 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
8584 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
8585 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
8586 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
8587 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8588 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8589 hr = IDirectDrawSurface7_SetPalette(surface, palette);
8590 ok(hr == DDERR_INVALIDSURFACETYPE, "Got unexpected hr %#x.\n", hr);
8591 IDirectDrawSurface7_Release(surface);
8593 /* The Windows 8 testbot keeps extra references to the primary
8594 * while in 8 bpp mode. */
8595 hr = IDirectDraw7_RestoreDisplayMode(ddraw);
8596 ok(SUCCEEDED(hr), "Failed to restore display mode, hr %#x.\n", hr);
8598 refcount = IDirectDrawPalette_Release(palette);
8599 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8600 refcount = IDirectDraw7_Release(ddraw);
8601 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8602 DestroyWindow(window);
8605 static void test_vb_writeonly(void)
8607 IDirect3DDevice7 *device;
8608 IDirect3D7 *d3d;
8609 IDirect3DVertexBuffer7 *buffer;
8610 HWND window;
8611 HRESULT hr;
8612 D3DVERTEXBUFFERDESC desc;
8613 void *ptr;
8614 static const struct vec4 quad[] =
8616 { 0.0f, 480.0f, 0.0f, 1.0f},
8617 { 0.0f, 0.0f, 0.0f, 1.0f},
8618 {640.0f, 480.0f, 0.0f, 1.0f},
8619 {640.0f, 0.0f, 0.0f, 1.0f},
8622 window = create_window();
8623 if (!(device = create_device(window, DDSCL_NORMAL)))
8625 skip("Failed to create a 3D device, skipping test.\n");
8626 DestroyWindow(window);
8627 return;
8630 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
8631 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
8633 memset(&desc, 0, sizeof(desc));
8634 desc.dwSize = sizeof(desc);
8635 desc.dwCaps = D3DVBCAPS_WRITEONLY;
8636 desc.dwFVF = D3DFVF_XYZRHW;
8637 desc.dwNumVertices = ARRAY_SIZE(quad);
8638 hr = IDirect3D7_CreateVertexBuffer(d3d, &desc, &buffer, 0);
8639 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
8641 hr = IDirect3DVertexBuffer7_Lock(buffer, DDLOCK_DISCARDCONTENTS, &ptr, NULL);
8642 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
8643 memcpy(ptr, quad, sizeof(quad));
8644 hr = IDirect3DVertexBuffer7_Unlock(buffer);
8645 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
8647 hr = IDirect3DDevice7_BeginScene(device);
8648 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
8649 hr = IDirect3DDevice7_DrawPrimitiveVB(device, D3DPT_TRIANGLESTRIP, buffer, 0, 4, 0);
8650 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
8651 hr = IDirect3DDevice7_EndScene(device);
8652 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
8654 hr = IDirect3DVertexBuffer7_Lock(buffer, 0, &ptr, NULL);
8655 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
8656 ok (!memcmp(ptr, quad, sizeof(quad)), "Got unexpected vertex buffer data.\n");
8657 hr = IDirect3DVertexBuffer7_Unlock(buffer);
8658 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
8660 hr = IDirect3DVertexBuffer7_Lock(buffer, DDLOCK_READONLY, &ptr, NULL);
8661 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
8662 ok (!memcmp(ptr, quad, sizeof(quad)), "Got unexpected vertex buffer data.\n");
8663 hr = IDirect3DVertexBuffer7_Unlock(buffer);
8664 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
8666 IDirect3DVertexBuffer7_Release(buffer);
8667 IDirect3D7_Release(d3d);
8668 IDirect3DDevice7_Release(device);
8669 DestroyWindow(window);
8672 static void test_lost_device(void)
8674 IDirectDrawSurface7 *surface;
8675 DDSURFACEDESC2 surface_desc;
8676 HWND window1, window2;
8677 IDirectDraw7 *ddraw;
8678 ULONG refcount;
8679 HRESULT hr;
8680 BOOL ret;
8682 window1 = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
8683 0, 0, 640, 480, 0, 0, 0, 0);
8684 window2 = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
8685 0, 0, 640, 480, 0, 0, 0, 0);
8686 ddraw = create_ddraw();
8687 ok(!!ddraw, "Failed to create a ddraw object.\n");
8688 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window1, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
8689 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
8691 memset(&surface_desc, 0, sizeof(surface_desc));
8692 surface_desc.dwSize = sizeof(surface_desc);
8693 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
8694 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
8695 U5(surface_desc).dwBackBufferCount = 1;
8696 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8697 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8699 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8700 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8701 hr = IDirectDrawSurface7_IsLost(surface);
8702 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8703 hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
8704 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8706 ret = SetForegroundWindow(GetDesktopWindow());
8707 ok(ret, "Failed to set foreground window.\n");
8708 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8709 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
8710 hr = IDirectDrawSurface7_IsLost(surface);
8711 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
8712 hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
8713 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
8715 ret = SetForegroundWindow(window1);
8716 ok(ret, "Failed to set foreground window.\n");
8717 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8718 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8719 hr = IDirectDrawSurface7_IsLost(surface);
8720 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
8721 hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
8722 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
8724 hr = IDirectDraw7_RestoreAllSurfaces(ddraw);
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 == DD_OK, "Got unexpected hr %#x.\n", hr);
8730 hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
8731 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8733 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window1, DDSCL_NORMAL);
8734 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8735 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8736 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8737 hr = IDirectDrawSurface7_IsLost(surface);
8738 todo_wine ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
8739 hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
8740 todo_wine ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
8742 /* Trying to restore the primary will crash, probably because flippable
8743 * surfaces can't exist in DDSCL_NORMAL. */
8744 IDirectDrawSurface7_Release(surface);
8745 memset(&surface_desc, 0, sizeof(surface_desc));
8746 surface_desc.dwSize = sizeof(surface_desc);
8747 surface_desc.dwFlags = DDSD_CAPS;
8748 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
8749 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8750 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8752 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8753 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8754 hr = IDirectDrawSurface7_IsLost(surface);
8755 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8757 ret = SetForegroundWindow(GetDesktopWindow());
8758 ok(ret, "Failed to set foreground window.\n");
8759 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8760 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8761 hr = IDirectDrawSurface7_IsLost(surface);
8762 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8764 ret = SetForegroundWindow(window1);
8765 ok(ret, "Failed to set foreground window.\n");
8766 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8767 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8768 hr = IDirectDrawSurface7_IsLost(surface);
8769 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8771 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window1, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
8772 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8773 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8774 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8775 hr = IDirectDrawSurface7_IsLost(surface);
8776 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
8778 hr = IDirectDraw7_RestoreAllSurfaces(ddraw);
8779 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8780 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8781 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8782 hr = IDirectDrawSurface7_IsLost(surface);
8783 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8785 IDirectDrawSurface7_Release(surface);
8786 memset(&surface_desc, 0, sizeof(surface_desc));
8787 surface_desc.dwSize = sizeof(surface_desc);
8788 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
8789 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
8790 U5(surface_desc).dwBackBufferCount = 1;
8791 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8792 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8794 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window1, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
8795 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8796 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8797 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8798 hr = IDirectDrawSurface7_IsLost(surface);
8799 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8800 hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
8801 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8803 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window1, DDSCL_NORMAL | DDSCL_FULLSCREEN);
8804 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8805 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8806 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8807 hr = IDirectDrawSurface7_IsLost(surface);
8808 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8809 hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
8810 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
8812 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window1, DDSCL_NORMAL);
8813 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8814 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8815 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8816 hr = IDirectDrawSurface7_IsLost(surface);
8817 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8818 hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
8819 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
8821 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window2, DDSCL_NORMAL);
8822 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8823 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8824 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8825 hr = IDirectDrawSurface7_IsLost(surface);
8826 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8827 hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
8828 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
8830 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window2, DDSCL_NORMAL | DDSCL_FULLSCREEN);
8831 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8832 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8833 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8834 hr = IDirectDrawSurface7_IsLost(surface);
8835 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8836 hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
8837 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
8839 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window2, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
8840 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8841 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8842 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8843 hr = IDirectDrawSurface7_IsLost(surface);
8844 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
8845 hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
8846 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
8848 IDirectDrawSurface7_Release(surface);
8849 refcount = IDirectDraw7_Release(ddraw);
8850 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8851 DestroyWindow(window2);
8852 DestroyWindow(window1);
8855 static void test_resource_priority(void)
8857 IDirectDrawSurface7 *surface, *mipmap;
8858 DDSURFACEDESC2 surface_desc;
8859 IDirectDraw7 *ddraw;
8860 ULONG refcount;
8861 HWND window;
8862 HRESULT hr;
8863 DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, {0}};
8864 DDCAPS hal_caps;
8865 DWORD needed_caps = DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_MIPMAP;
8866 unsigned int i;
8867 DWORD priority;
8868 static const struct
8870 DWORD caps, caps2;
8871 const char *name;
8872 HRESULT hr;
8873 /* SetPriority on offscreenplain surfaces crashes on AMD GPUs on Win7. */
8874 BOOL crash;
8876 test_data[] =
8878 {DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, 0, "vidmem texture", DDERR_INVALIDPARAMS, FALSE},
8879 {DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, 0, "sysmem texture", DDERR_INVALIDPARAMS, FALSE},
8880 {DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, "managed texture", DD_OK, FALSE},
8881 {DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, "managed texture", DD_OK, FALSE},
8882 {DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP,
8883 DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES | DDSCAPS2_TEXTUREMANAGE,
8884 "cubemap", DD_OK, FALSE},
8885 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0, "vidmem offscreenplain", DDERR_INVALIDOBJECT, TRUE},
8886 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY, 0, "sysmem offscreenplain", DDERR_INVALIDOBJECT, TRUE},
8889 window = create_window();
8890 ddraw = create_ddraw();
8891 ok(!!ddraw, "Failed to create a ddraw object.\n");
8892 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
8893 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
8895 memset(&hal_caps, 0, sizeof(hal_caps));
8896 hal_caps.dwSize = sizeof(hal_caps);
8897 hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, NULL);
8898 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
8899 if ((hal_caps.ddsCaps.dwCaps & needed_caps) != needed_caps
8900 || !(hal_caps.ddsCaps.dwCaps & DDSCAPS2_TEXTUREMANAGE))
8902 skip("Required surface types not supported, skipping test.\n");
8903 goto done;
8906 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
8908 memset(&surface_desc, 0, sizeof(surface_desc));
8909 surface_desc.dwSize = sizeof(surface_desc);
8910 surface_desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
8911 surface_desc.dwWidth = 32;
8912 surface_desc.dwHeight = 32;
8913 surface_desc.ddsCaps.dwCaps = test_data[i].caps;
8914 surface_desc.ddsCaps.dwCaps2 = test_data[i].caps2;
8915 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8916 if (is_ddraw64 && (test_data[i].caps & DDSCAPS_TEXTURE))
8918 todo_wine ok(hr == E_NOINTERFACE, "Got unexpected hr %#x, type %s.\n", hr, test_data[i].name);
8919 if (SUCCEEDED(hr))
8920 IDirectDrawSurface7_Release(surface);
8921 continue;
8923 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x, type %s.\n", hr, test_data[i].name);
8925 /* Priority == NULL segfaults. */
8926 priority = 0xdeadbeef;
8927 hr = IDirectDrawSurface7_GetPriority(surface, &priority);
8928 ok(hr == test_data[i].hr, "Got unexpected hr %#x, type %s.\n", hr, test_data[i].name);
8929 if (SUCCEEDED(test_data[i].hr))
8930 ok(priority == 0, "Got unexpected priority %u, type %s.\n", priority, test_data[i].name);
8931 else
8932 ok(priority == 0xdeadbeef, "Got unexpected priority %u, type %s.\n", priority, test_data[i].name);
8934 if (!test_data[i].crash)
8936 hr = IDirectDrawSurface7_SetPriority(surface, 1);
8937 ok(hr == test_data[i].hr, "Got unexpected hr %#x, type %s.\n", hr, test_data[i].name);
8938 hr = IDirectDrawSurface7_GetPriority(surface, &priority);
8939 ok(hr == test_data[i].hr, "Got unexpected hr %#x, type %s.\n", hr, test_data[i].name);
8940 if (SUCCEEDED(test_data[i].hr))
8942 ok(priority == 1, "Got unexpected priority %u, type %s.\n", priority, test_data[i].name);
8943 hr = IDirectDrawSurface7_SetPriority(surface, 2);
8944 ok(hr == test_data[i].hr, "Got unexpected hr %#x, type %s.\n", hr, test_data[i].name);
8946 else
8947 ok(priority == 0xdeadbeef, "Got unexpected priority %u, type %s.\n", priority, test_data[i].name);
8950 if (test_data[i].caps2 & DDSCAPS2_CUBEMAP)
8952 caps.dwCaps2 = DDSCAPS2_CUBEMAP_NEGATIVEZ;
8953 hr = IDirectDrawSurface7_GetAttachedSurface(surface, &caps, &mipmap);
8954 ok(SUCCEEDED(hr), "Failed to get attached surface, i %u, hr %#x.\n", i, hr);
8955 /* IDirectDrawSurface7_SetPriority crashes when called on non-positive X surfaces on Windows */
8956 priority = 0xdeadbeef;
8957 hr = IDirectDrawSurface7_GetPriority(mipmap, &priority);
8958 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x, type %s.\n", hr, test_data[i].name);
8959 ok(priority == 0xdeadbeef, "Got unexpected priority %u, type %s.\n", priority, test_data[i].name);
8961 IDirectDrawSurface7_Release(mipmap);
8964 IDirectDrawSurface7_Release(surface);
8967 if (is_ddraw64)
8968 goto done;
8970 memset(&surface_desc, 0, sizeof(surface_desc));
8971 surface_desc.dwSize = sizeof(surface_desc);
8972 surface_desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_MIPMAPCOUNT;
8973 surface_desc.dwWidth = 32;
8974 surface_desc.dwHeight = 32;
8975 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
8976 surface_desc.ddsCaps.dwCaps2 = DDSCAPS2_TEXTUREMANAGE;
8977 U2(surface_desc).dwMipMapCount = 2;
8978 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8979 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8980 caps.dwCaps2 = 0;
8981 hr = IDirectDrawSurface7_GetAttachedSurface(surface, &caps, &mipmap);
8982 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
8984 priority = 0xdeadbeef;
8985 hr = IDirectDrawSurface7_GetPriority(mipmap, &priority);
8986 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x, type managed mipmap.\n", hr);
8987 ok(priority == 0xdeadbeef, "Got unexpected priority %u, type managed mipmap.\n", priority);
8988 /* SetPriority on the mipmap surface crashes. */
8989 hr = IDirectDrawSurface7_GetPriority(surface, &priority);
8990 ok(SUCCEEDED(hr), "Failed to get priority, hr %#x.\n", hr);
8991 ok(priority == 0, "Got unexpected priority %u, type managed mipmap.\n", priority);
8993 IDirectDrawSurface7_Release(mipmap);
8994 refcount = IDirectDrawSurface7_Release(surface);
8995 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8997 done:
8998 refcount = IDirectDraw7_Release(ddraw);
8999 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
9000 DestroyWindow(window);
9003 static void test_surface_desc_lock(void)
9005 IDirectDrawSurface7 *surface;
9006 DDSURFACEDESC2 surface_desc;
9007 IDirectDraw7 *ddraw;
9008 ULONG refcount;
9009 HWND window;
9010 HRESULT hr;
9012 window = create_window();
9013 ddraw = create_ddraw();
9014 ok(!!ddraw, "Failed to create a ddraw object.\n");
9015 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
9016 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
9018 memset(&surface_desc, 0, sizeof(surface_desc));
9019 surface_desc.dwSize = sizeof(surface_desc);
9020 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
9021 surface_desc.dwWidth = 16;
9022 surface_desc.dwHeight = 16;
9023 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
9024 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
9025 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
9027 memset(&surface_desc, 0xaa, sizeof(surface_desc));
9028 surface_desc.dwSize = sizeof(surface_desc);
9029 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &surface_desc);
9030 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
9031 ok(!surface_desc.lpSurface, "Got unexpected lpSurface %p.\n", surface_desc.lpSurface);
9033 memset(&surface_desc, 0xaa, sizeof(surface_desc));
9034 surface_desc.dwSize = sizeof(surface_desc);
9035 hr = IDirectDrawSurface7_Lock(surface, NULL, &surface_desc, 0, NULL);
9036 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
9037 ok(surface_desc.lpSurface != NULL, "Got unexpected lpSurface %p.\n", surface_desc.lpSurface);
9038 memset(&surface_desc, 0xaa, sizeof(surface_desc));
9039 surface_desc.dwSize = sizeof(surface_desc);
9040 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &surface_desc);
9041 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
9042 ok(!surface_desc.lpSurface, "Got unexpected lpSurface %p.\n", surface_desc.lpSurface);
9043 hr = IDirectDrawSurface7_Unlock(surface, NULL);
9044 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
9046 memset(&surface_desc, 0xaa, sizeof(surface_desc));
9047 surface_desc.dwSize = sizeof(surface_desc);
9048 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &surface_desc);
9049 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
9050 ok(!surface_desc.lpSurface, "Got unexpected lpSurface %p.\n", surface_desc.lpSurface);
9052 IDirectDrawSurface7_Release(surface);
9053 refcount = IDirectDraw7_Release(ddraw);
9054 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
9055 DestroyWindow(window);
9058 static void test_fog_interpolation(void)
9060 HRESULT hr;
9061 IDirect3DDevice7 *device;
9062 IDirectDrawSurface7 *rt;
9063 ULONG refcount;
9064 HWND window;
9065 D3DCOLOR color;
9066 static struct
9068 struct vec3 position;
9069 D3DCOLOR diffuse;
9070 D3DCOLOR specular;
9072 quad[] =
9074 {{-1.0f, -1.0f, 0.0f}, 0xffff0000, 0xff000000},
9075 {{-1.0f, 1.0f, 0.0f}, 0xffff0000, 0xff000000},
9076 {{ 1.0f, -1.0f, 1.0f}, 0xffff0000, 0x00000000},
9077 {{ 1.0f, 1.0f, 1.0f}, 0xffff0000, 0x00000000},
9079 union
9081 DWORD d;
9082 float f;
9083 } conv;
9084 unsigned int i;
9085 static const struct
9087 D3DFOGMODE vfog, tfog;
9088 D3DSHADEMODE shade;
9089 D3DCOLOR middle_color;
9090 BOOL todo;
9092 tests[] =
9094 {D3DFOG_NONE, D3DFOG_NONE, D3DSHADE_FLAT, 0x00007f80, FALSE},
9095 {D3DFOG_NONE, D3DFOG_NONE, D3DSHADE_GOURAUD, 0x00007f80, FALSE},
9096 {D3DFOG_EXP, D3DFOG_NONE, D3DSHADE_FLAT, 0x00007f80, TRUE},
9097 {D3DFOG_EXP, D3DFOG_NONE, D3DSHADE_GOURAUD, 0x00007f80, TRUE},
9098 {D3DFOG_NONE, D3DFOG_EXP, D3DSHADE_FLAT, 0x0000ea15, FALSE},
9099 {D3DFOG_NONE, D3DFOG_EXP, D3DSHADE_GOURAUD, 0x0000ea15, FALSE},
9100 {D3DFOG_EXP, D3DFOG_EXP, D3DSHADE_FLAT, 0x0000ea15, FALSE},
9101 {D3DFOG_EXP, D3DFOG_EXP, D3DSHADE_GOURAUD, 0x0000ea15, FALSE},
9103 D3DDEVICEDESC7 caps;
9105 window = create_window();
9106 if (!(device = create_device(window, DDSCL_NORMAL)))
9108 skip("Failed to create a 3D device, skipping test.\n");
9109 DestroyWindow(window);
9110 return;
9113 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
9114 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
9115 hr = IDirect3DDevice7_GetCaps(device, &caps);
9116 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
9117 if (!(caps.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGTABLE))
9118 skip("D3DPRASTERCAPS_FOGTABLE not supported, skipping some fog tests\n");
9120 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
9121 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9122 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, FALSE);
9123 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9124 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, TRUE);
9125 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9126 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGCOLOR, 0x0000ff00);
9127 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9128 conv.f = 5.0;
9129 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGDENSITY, conv.d);
9130 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9132 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
9133 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
9134 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TFACTOR);
9135 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
9136 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_TEXTUREFACTOR, 0x000000ff);
9137 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9139 for (i = 0; i < ARRAY_SIZE(tests); ++i)
9141 if (!(caps.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGTABLE) && tests[i].tfog)
9142 continue;
9144 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00808080, 0.0f, 0);
9145 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
9147 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_SHADEMODE, tests[i].shade);
9148 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9149 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGVERTEXMODE, tests[i].vfog);
9150 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9151 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGTABLEMODE, tests[i].tfog);
9152 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9153 hr = IDirect3DDevice7_BeginScene(device);
9154 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
9155 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
9156 D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_SPECULAR, quad, 4, 0);
9157 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9158 hr = IDirect3DDevice7_EndScene(device);
9159 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
9161 color = get_surface_color(rt, 0, 240);
9162 ok(compare_color(color, 0x000000ff, 2), "Got unexpected color 0x%08x, case %u.\n", color, i);
9163 color = get_surface_color(rt, 320, 240);
9164 todo_wine_if (tests[i].todo)
9165 ok(compare_color(color, tests[i].middle_color, 2),
9166 "Got unexpected color 0x%08x, case %u.\n", color, i);
9167 color = get_surface_color(rt, 639, 240);
9168 ok(compare_color(color, 0x0000fd02, 2), "Got unexpected color 0x%08x, case %u.\n", color, i);
9171 IDirectDrawSurface7_Release(rt);
9172 refcount = IDirect3DDevice7_Release(device);
9173 ok(!refcount, "Device has %u references left.\n", refcount);
9174 DestroyWindow(window);
9177 static void test_negative_fixedfunction_fog(void)
9179 HRESULT hr;
9180 IDirect3DDevice7 *device;
9181 IDirectDrawSurface7 *rt;
9182 ULONG refcount;
9183 HWND window;
9184 D3DCOLOR color;
9185 static struct
9187 struct vec3 position;
9188 D3DCOLOR diffuse;
9190 quad[] =
9192 {{-1.0f, -1.0f, -0.5f}, 0xffff0000},
9193 {{-1.0f, 1.0f, -0.5f}, 0xffff0000},
9194 {{ 1.0f, -1.0f, -0.5f}, 0xffff0000},
9195 {{ 1.0f, 1.0f, -0.5f}, 0xffff0000},
9197 static struct
9199 struct vec4 position;
9200 D3DCOLOR diffuse;
9202 tquad[] =
9204 {{ 0.0f, 0.0f, -0.5f, 1.0f}, 0xffff0000},
9205 {{640.0f, 0.0f, -0.5f, 1.0f}, 0xffff0000},
9206 {{ 0.0f, 480.0f, -0.5f, 1.0f}, 0xffff0000},
9207 {{640.0f, 480.0f, -0.5f, 1.0f}, 0xffff0000},
9209 unsigned int i;
9210 static D3DMATRIX zero =
9212 1.0f, 0.0f, 0.0f, 0.0f,
9213 0.0f, 1.0f, 0.0f, 0.0f,
9214 0.0f, 0.0f, 0.0f, 0.0f,
9215 0.0f, 0.0f, 0.0f, 1.0f
9217 static D3DMATRIX identity =
9219 1.0f, 0.0f, 0.0f, 0.0f,
9220 0.0f, 1.0f, 0.0f, 0.0f,
9221 0.0f, 0.0f, 1.0f, 0.0f,
9222 0.0f, 0.0f, 0.0f, 1.0f
9224 static const struct
9226 DWORD pos_type;
9227 void *quad;
9228 D3DMATRIX *matrix;
9229 union
9231 float f;
9232 DWORD d;
9233 } start, end;
9234 D3DFOGMODE vfog, tfog;
9235 DWORD color, color_broken, color_broken2;
9237 tests[] =
9239 /* Run the XYZRHW tests first. Depth clamping is broken after RHW draws on the testbot.
9241 * Geforce8+ GPUs on Windows abs() table fog, everything else does not. */
9242 {D3DFVF_XYZRHW, tquad, &identity, { 0.0f}, {1.0f}, D3DFOG_NONE, D3DFOG_LINEAR,
9243 0x00ff0000, 0x00808000, 0x00808000},
9244 /* r200 GPUs and presumably all d3d8 and older HW clamp the fog
9245 * parameters to 0.0 and 1.0 in the table fog case. */
9246 {D3DFVF_XYZRHW, tquad, &identity, {-1.0f}, {0.0f}, D3DFOG_NONE, D3DFOG_LINEAR,
9247 0x00808000, 0x00ff0000, 0x0000ff00},
9248 /* test_fog_interpolation shows that vertex fog evaluates the fog
9249 * equation in the vertex pipeline. Start = -1.0 && end = 0.0 shows
9250 * that the abs happens before the fog equation is evaluated.
9252 * Vertex fog abs() behavior is the same on all GPUs. */
9253 {D3DFVF_XYZ, quad, &zero, { 0.0f}, {1.0f}, D3DFOG_LINEAR, D3DFOG_NONE,
9254 0x00808000, 0x00808000, 0x00808000},
9255 {D3DFVF_XYZ, quad, &zero, {-1.0f}, {0.0f}, D3DFOG_LINEAR, D3DFOG_NONE,
9256 0x0000ff00, 0x0000ff00, 0x0000ff00},
9257 {D3DFVF_XYZ, quad, &zero, { 0.0f}, {1.0f}, D3DFOG_EXP, D3DFOG_NONE,
9258 0x009b6400, 0x009b6400, 0x009b6400},
9260 D3DDEVICEDESC7 caps;
9262 window = create_window();
9263 if (!(device = create_device(window, DDSCL_NORMAL)))
9265 skip("Failed to create a 3D device, skipping test.\n");
9266 DestroyWindow(window);
9267 return;
9270 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
9271 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
9272 hr = IDirect3DDevice7_GetCaps(device, &caps);
9273 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
9274 if (!(caps.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGTABLE))
9275 skip("D3DPRASTERCAPS_FOGTABLE not supported, skipping some fog tests.\n");
9277 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
9278 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9279 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
9280 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9281 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, TRUE);
9282 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9283 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGCOLOR, 0x0000ff00);
9284 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9285 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CLIPPING, FALSE);
9286 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
9288 for (i = 0; i < ARRAY_SIZE(tests); ++i)
9290 if (!(caps.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGTABLE) && tests[i].tfog)
9291 continue;
9293 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x000000ff, 0.0f, 0);
9294 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
9296 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, tests[i].matrix);
9297 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
9298 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGSTART, tests[i].start.d);
9299 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9300 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGEND, tests[i].end.d);
9301 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9302 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGVERTEXMODE, tests[i].vfog);
9303 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9304 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGTABLEMODE, tests[i].tfog);
9305 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9307 hr = IDirect3DDevice7_BeginScene(device);
9308 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
9309 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
9310 tests[i].pos_type | D3DFVF_DIFFUSE, tests[i].quad, 4, 0);
9311 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9312 hr = IDirect3DDevice7_EndScene(device);
9313 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
9315 color = get_surface_color(rt, 0, 240);
9316 ok(compare_color(color, tests[i].color, 2) || broken(compare_color(color, tests[i].color_broken, 2))
9317 || broken(compare_color(color, tests[i].color_broken2, 2)),
9318 "Got unexpected color 0x%08x, case %u.\n", color, i);
9321 IDirectDrawSurface7_Release(rt);
9322 refcount = IDirect3DDevice7_Release(device);
9323 ok(!refcount, "Device has %u references left.\n", refcount);
9324 DestroyWindow(window);
9327 static void test_table_fog_zw(void)
9329 HRESULT hr;
9330 IDirect3DDevice7 *device;
9331 IDirectDrawSurface7 *rt;
9332 ULONG refcount;
9333 HWND window;
9334 D3DCOLOR color;
9335 static struct
9337 struct vec4 position;
9338 D3DCOLOR diffuse;
9340 quad[] =
9342 {{ 0.0f, 0.0f, 0.0f, 0.0f}, 0xffff0000},
9343 {{640.0f, 0.0f, 0.0f, 0.0f}, 0xffff0000},
9344 {{ 0.0f, 480.0f, 0.0f, 0.0f}, 0xffff0000},
9345 {{640.0f, 480.0f, 0.0f, 0.0f}, 0xffff0000},
9347 static D3DMATRIX identity =
9349 1.0f, 0.0f, 0.0f, 0.0f,
9350 0.0f, 1.0f, 0.0f, 0.0f,
9351 0.0f, 0.0f, 1.0f, 0.0f,
9352 0.0f, 0.0f, 0.0f, 1.0f
9354 D3DDEVICEDESC7 caps;
9355 static const struct
9357 float z, w;
9358 D3DZBUFFERTYPE z_test;
9359 D3DCOLOR color;
9361 tests[] =
9363 {0.7f, 0.0f, D3DZB_TRUE, 0x004cb200},
9364 {0.7f, 0.0f, D3DZB_FALSE, 0x004cb200},
9365 {0.7f, 0.3f, D3DZB_TRUE, 0x004cb200},
9366 {0.7f, 0.3f, D3DZB_FALSE, 0x004cb200},
9367 {0.7f, 3.0f, D3DZB_TRUE, 0x004cb200},
9368 {0.7f, 3.0f, D3DZB_FALSE, 0x004cb200},
9369 {0.3f, 0.0f, D3DZB_TRUE, 0x00b24c00},
9370 {0.3f, 0.0f, D3DZB_FALSE, 0x00b24c00},
9372 unsigned int i;
9374 window = create_window();
9375 if (!(device = create_device(window, DDSCL_NORMAL)))
9377 skip("Failed to create a 3D device, skipping test.\n");
9378 DestroyWindow(window);
9379 return;
9382 hr = IDirect3DDevice7_GetCaps(device, &caps);
9383 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
9384 if (!(caps.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGTABLE))
9386 skip("D3DPRASTERCAPS_FOGTABLE not supported, skipping POSITIONT table fog test.\n");
9387 goto done;
9389 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
9390 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
9392 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
9393 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9394 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, TRUE);
9395 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9396 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGCOLOR, 0x0000ff00);
9397 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9398 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CLIPPING, FALSE);
9399 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
9400 /* Work around an AMD Windows driver bug. Needs a proj matrix applied redundantly. */
9401 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &identity);
9402 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
9403 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGTABLEMODE, D3DFOG_LINEAR);
9404 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9406 for (i = 0; i < ARRAY_SIZE(tests); ++i)
9408 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x000000ff, 1.0f, 0);
9409 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
9411 quad[0].position.z = tests[i].z;
9412 quad[1].position.z = tests[i].z;
9413 quad[2].position.z = tests[i].z;
9414 quad[3].position.z = tests[i].z;
9415 quad[0].position.w = tests[i].w;
9416 quad[1].position.w = tests[i].w;
9417 quad[2].position.w = tests[i].w;
9418 quad[3].position.w = tests[i].w;
9419 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, tests[i].z_test);
9420 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9422 hr = IDirect3DDevice7_BeginScene(device);
9423 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
9424 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
9425 D3DFVF_XYZRHW | D3DFVF_DIFFUSE, quad, 4, 0);
9426 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9427 hr = IDirect3DDevice7_EndScene(device);
9428 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
9430 color = get_surface_color(rt, 0, 240);
9431 ok(compare_color(color, tests[i].color, 2),
9432 "Got unexpected color 0x%08x, expected 0x%8x, case %u.\n", color, tests[i].color, i);
9435 IDirectDrawSurface7_Release(rt);
9436 done:
9437 refcount = IDirect3DDevice7_Release(device);
9438 ok(!refcount, "Device has %u references left.\n", refcount);
9439 DestroyWindow(window);
9442 static void test_signed_formats(void)
9444 HRESULT hr;
9445 IDirect3DDevice7 *device;
9446 IDirect3D7 *d3d;
9447 IDirectDraw7 *ddraw;
9448 IDirectDrawSurface7 *surface, *rt;
9449 DDSURFACEDESC2 surface_desc;
9450 ULONG refcount;
9451 HWND window;
9452 D3DCOLOR color, expected_color;
9453 static struct
9455 struct vec3 position;
9456 struct vec2 texcoord;
9458 quad[] =
9460 {{-1.0f, -1.0f, 0.0f}, {0.0f, 1.0f}},
9461 {{-1.0f, 1.0f, 0.0f}, {0.0f, 0.0f}},
9462 {{ 1.0f, -1.0f, 0.0f}, {1.0f, 1.0f}},
9463 {{ 1.0f, 1.0f, 0.0f}, {1.0f, 0.0f}},
9465 /* See test_signed_formats() in dlls/d3d9/tests/visual.c for an explanation
9466 * of these values. */
9467 static const USHORT content_v8u8[4][4] =
9469 {0x0000, 0x7f7f, 0x8880, 0x0000},
9470 {0x0080, 0x8000, 0x7f00, 0x007f},
9471 {0x193b, 0xe8c8, 0x0808, 0xf8f8},
9472 {0x4444, 0xc0c0, 0xa066, 0x22e0},
9474 static const DWORD content_x8l8v8u8[4][4] =
9476 {0x00000000, 0x00ff7f7f, 0x00008880, 0x00ff0000},
9477 {0x00000080, 0x00008000, 0x00007f00, 0x0000007f},
9478 {0x0041193b, 0x0051e8c8, 0x00040808, 0x00fff8f8},
9479 {0x00824444, 0x0000c0c0, 0x00c2a066, 0x009222e0},
9481 static const USHORT content_l6v5u5[4][4] =
9483 {0x0000, 0xfdef, 0x0230, 0xfc00},
9484 {0x0010, 0x0200, 0x01e0, 0x000f},
9485 {0x4067, 0x53b9, 0x0421, 0xffff},
9486 {0x8108, 0x0318, 0xc28c, 0x909c},
9488 static const struct
9490 const char *name;
9491 const void *content;
9492 SIZE_T pixel_size;
9493 BOOL blue;
9494 unsigned int slop, slop_broken;
9495 DDPIXELFORMAT format;
9497 formats[] =
9500 "D3DFMT_V8U8", content_v8u8, sizeof(WORD), FALSE, 1, 0,
9502 sizeof(DDPIXELFORMAT), DDPF_BUMPDUDV, 0,
9503 {16}, {0x000000ff}, {0x0000ff00}, {0x00000000}, {0x00000000}
9507 "D3DFMT_X8L8V8U8", content_x8l8v8u8, sizeof(DWORD), TRUE, 1, 0,
9509 sizeof(DDPIXELFORMAT), DDPF_BUMPDUDV | DDPF_BUMPLUMINANCE, 0,
9510 {32}, {0x000000ff}, {0x0000ff00}, {0x00ff0000}, {0x00000000}
9514 "D3DFMT_L6V5U5", content_l6v5u5, sizeof(WORD), TRUE, 4, 7,
9516 sizeof(DDPIXELFORMAT), DDPF_BUMPDUDV | DDPF_BUMPLUMINANCE, 0,
9517 {16}, {0x0000001f}, {0x000003e0}, {0x0000fc00}, {0x00000000}
9521 /* No V16U16 or Q8W8V8U8 support in ddraw. */
9523 static const D3DCOLOR expected_colors[4][4] =
9525 {0x00808080, 0x00fefeff, 0x00010780, 0x008080ff},
9526 {0x00018080, 0x00800180, 0x0080fe80, 0x00fe8080},
9527 {0x00ba98a0, 0x004767a8, 0x00888881, 0x007878ff},
9528 {0x00c3c3c0, 0x003f3f80, 0x00e51fe1, 0x005fa2c8},
9530 unsigned int i, width, x, y;
9531 D3DDEVICEDESC7 device_desc;
9533 window = create_window();
9534 if (!(device = create_device(window, DDSCL_NORMAL)))
9536 skip("Failed to create a 3D device, skipping test.\n");
9537 DestroyWindow(window);
9538 return;
9541 hr = IDirect3DDevice7_GetCaps(device, &device_desc);
9542 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
9543 if (!(device_desc.dwTextureOpCaps & D3DTEXOPCAPS_BLENDFACTORALPHA))
9545 skip("D3DTOP_BLENDFACTORALPHA not supported, skipping bumpmap format tests.\n");
9546 goto done;
9549 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
9550 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
9551 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
9552 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
9553 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
9554 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
9556 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
9557 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9559 /* dst = tex * 0.5 + 1.0 * (1.0 - 0.5) = tex * 0.5 + 0.5 */
9560 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_TEXTUREFACTOR, 0x80ffffff);
9561 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9562 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_BLENDFACTORALPHA);
9563 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
9564 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
9565 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
9566 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLORARG2, D3DTA_TFACTOR);
9567 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
9569 for (i = 0; i < ARRAY_SIZE(formats); ++i)
9571 for (width = 1; width < 5; width += 3)
9573 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00000000, 0.0f, 0);
9574 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
9576 memset(&surface_desc, 0, sizeof(surface_desc));
9577 surface_desc.dwSize = sizeof(surface_desc);
9578 surface_desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS;
9579 surface_desc.dwWidth = width;
9580 surface_desc.dwHeight = 4;
9581 U4(surface_desc).ddpfPixelFormat = formats[i].format;
9582 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY;
9583 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
9584 if (FAILED(hr))
9586 skip("%s textures not supported, skipping.\n", formats[i].name);
9587 continue;
9589 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x, format %s.\n", hr, formats[i].name);
9590 hr = IDirect3DDevice7_SetTexture(device, 0, surface);
9591 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x, format %s.\n", hr, formats[i].name);
9593 memset(&surface_desc, 0, sizeof(surface_desc));
9594 surface_desc.dwSize = sizeof(surface_desc);
9595 hr = IDirectDrawSurface7_Lock(surface, NULL, &surface_desc, 0, NULL);
9596 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x, format %s.\n", hr, formats[i].name);
9597 for (y = 0; y < 4; y++)
9599 memcpy((char *)surface_desc.lpSurface + y * U1(surface_desc).lPitch,
9600 (char *)formats[i].content + y * 4 * formats[i].pixel_size,
9601 width * formats[i].pixel_size);
9603 hr = IDirectDrawSurface7_Unlock(surface, NULL);
9604 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, format %s.\n", hr, formats[i].name);
9606 hr = IDirect3DDevice7_BeginScene(device);
9607 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
9608 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
9609 D3DFVF_XYZ | D3DFVF_TEX1, quad, 4, 0);
9610 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9611 hr = IDirect3DDevice7_EndScene(device);
9612 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
9614 for (y = 0; y < 4; y++)
9616 for (x = 0; x < width; x++)
9618 expected_color = expected_colors[y][x];
9619 if (!formats[i].blue)
9620 expected_color |= 0x000000ff;
9622 color = get_surface_color(rt, 80 + 160 * x, 60 + 120 * y);
9623 ok(compare_color(color, expected_color, formats[i].slop)
9624 || broken(compare_color(color, expected_color, formats[i].slop_broken)),
9625 "Expected color 0x%08x, got 0x%08x, format %s, location %ux%u.\n",
9626 expected_color, color, formats[i].name, x, y);
9630 IDirectDrawSurface7_Release(surface);
9635 IDirectDrawSurface7_Release(rt);
9636 IDirectDraw7_Release(ddraw);
9637 IDirect3D7_Release(d3d);
9639 done:
9640 refcount = IDirect3DDevice7_Release(device);
9641 ok(!refcount, "Device has %u references left.\n", refcount);
9642 DestroyWindow(window);
9645 static void test_color_fill(void)
9647 HRESULT hr;
9648 IDirect3DDevice7 *device;
9649 IDirect3D7 *d3d;
9650 IDirectDraw7 *ddraw;
9651 IDirectDrawSurface7 *surface, *surface2;
9652 DDSURFACEDESC2 surface_desc;
9653 DDPIXELFORMAT z_fmt;
9654 ULONG refcount;
9655 HWND window;
9656 unsigned int i;
9657 DDBLTFX fx;
9658 RECT rect = {5, 5, 7, 7};
9659 DWORD *color;
9660 DWORD supported_fmts = 0, num_fourcc_codes, *fourcc_codes;
9661 DDCAPS hal_caps;
9662 static const struct
9664 DWORD caps, caps2;
9665 HRESULT colorfill_hr, depthfill_hr;
9666 BOOL rop_success;
9667 const char *name;
9668 DWORD result;
9669 BOOL check_result;
9670 DDPIXELFORMAT format;
9672 tests[] =
9675 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0,
9676 DD_OK, DDERR_INVALIDPARAMS, TRUE, "vidmem offscreenplain RGB", 0xdeadbeef, TRUE,
9678 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
9679 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9683 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY, 0,
9684 DD_OK, DDERR_INVALIDPARAMS, TRUE, "sysmem offscreenplain RGB", 0xdeadbeef, TRUE,
9686 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
9687 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9691 DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, 0,
9692 DD_OK, DDERR_INVALIDPARAMS, TRUE, "vidmem texture RGB", 0xdeadbeef, TRUE,
9694 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
9695 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9699 DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, 0,
9700 DD_OK, DDERR_INVALIDPARAMS, TRUE, "sysmem texture RGB", 0xdeadbeef, TRUE,
9702 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
9703 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9707 DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE,
9708 DD_OK, DDERR_INVALIDPARAMS, TRUE, "managed texture RGB", 0xdeadbeef, TRUE,
9710 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
9711 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9715 DDSCAPS_ZBUFFER | DDSCAPS_VIDEOMEMORY, 0,
9716 DDERR_INVALIDPARAMS, DD_OK, TRUE, "vidmem zbuffer", 0xdeadbeef, TRUE,
9717 {0, 0, 0, {0}, {0}, {0}, {0}, {0}}
9720 DDSCAPS_ZBUFFER | DDSCAPS_SYSTEMMEMORY, 0,
9721 DDERR_INVALIDPARAMS, DD_OK, TRUE, "sysmem zbuffer", 0xdeadbeef, TRUE,
9722 {0, 0, 0, {0}, {0}, {0}, {0}, {0}}
9725 /* Colorfill on YUV surfaces always returns DD_OK, but the content is
9726 * different afterwards. DX9+ GPUs set one of the two luminance values
9727 * in each block, but AMD and Nvidia GPUs disagree on which luminance
9728 * value they set. r200 (dx8) just sets the entire block to the clear
9729 * value. */
9730 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0,
9731 DD_OK, DDERR_INVALIDPARAMS, FALSE, "vidmem offscreenplain YUY2", 0, FALSE,
9733 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y', 'U', 'Y', '2'),
9734 {0}, {0}, {0}, {0}, {0}
9738 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0,
9739 DD_OK, DDERR_INVALIDPARAMS, FALSE, "vidmem offscreenplain UYVY", 0, FALSE,
9741 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('U', 'Y', 'V', 'Y'),
9742 {0}, {0}, {0}, {0}, {0}
9746 DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY, 0,
9747 DD_OK, DDERR_INVALIDPARAMS, FALSE, "vidmem overlay YUY2", 0, FALSE,
9749 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y', 'U', 'Y', '2'),
9750 {0}, {0}, {0}, {0}, {0}
9754 DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY, 0,
9755 DD_OK, DDERR_INVALIDPARAMS, FALSE, "vidmem overlay UYVY", 0, FALSE,
9757 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('U', 'Y', 'V', 'Y'),
9758 {0}, {0}, {0}, {0}, {0}
9762 DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, 0,
9763 E_NOTIMPL, DDERR_INVALIDPARAMS, FALSE, "vidmem texture DXT1", 0, FALSE,
9765 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('D', 'X', 'T', '1'),
9766 {0}, {0}, {0}, {0}, {0}
9770 DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, 0,
9771 E_NOTIMPL, DDERR_INVALIDPARAMS, FALSE, "sysmem texture DXT1", 0, FALSE,
9773 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('D', 'X', 'T', '1'),
9774 {0}, {0}, {0}, {0}, {0}
9778 /* The testbot fills this with 0x00 instead of the blue channel. The sysmem
9779 * surface works, presumably because it is handled by the runtime instead of
9780 * the driver. */
9781 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0,
9782 DD_OK, DDERR_INVALIDPARAMS, TRUE, "vidmem offscreenplain P8", 0xefefefef, FALSE,
9784 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_PALETTEINDEXED8, 0,
9785 {8}, {0}, {0}, {0}, {0}
9789 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY, 0,
9790 DD_OK, DDERR_INVALIDPARAMS, TRUE, "sysmem offscreenplain P8", 0xefefefef, TRUE,
9792 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_PALETTEINDEXED8, 0,
9793 {8}, {0}, {0}, {0}, {0}
9797 static const struct
9799 DWORD rop;
9800 const char *name;
9801 HRESULT hr;
9803 rops[] =
9805 {SRCCOPY, "SRCCOPY", DD_OK},
9806 {SRCPAINT, "SRCPAINT", DDERR_NORASTEROPHW},
9807 {SRCAND, "SRCAND", DDERR_NORASTEROPHW},
9808 {SRCINVERT, "SRCINVERT", DDERR_NORASTEROPHW},
9809 {SRCERASE, "SRCERASE", DDERR_NORASTEROPHW},
9810 {NOTSRCCOPY, "NOTSRCCOPY", DDERR_NORASTEROPHW},
9811 {NOTSRCERASE, "NOTSRCERASE", DDERR_NORASTEROPHW},
9812 {MERGECOPY, "MERGECOPY", DDERR_NORASTEROPHW},
9813 {MERGEPAINT, "MERGEPAINT", DDERR_NORASTEROPHW},
9814 {PATCOPY, "PATCOPY", DDERR_NORASTEROPHW},
9815 {PATPAINT, "PATPAINT", DDERR_NORASTEROPHW},
9816 {PATINVERT, "PATINVERT", DDERR_NORASTEROPHW},
9817 {DSTINVERT, "DSTINVERT", DDERR_NORASTEROPHW},
9818 {BLACKNESS, "BLACKNESS", DD_OK},
9819 {WHITENESS, "WHITENESS", DD_OK},
9820 {0xaa0029, "0xaa0029", DDERR_NORASTEROPHW} /* noop */
9823 window = create_window();
9824 if (!(device = create_device(window, DDSCL_NORMAL)))
9826 skip("Failed to create a 3D device, skipping test.\n");
9827 DestroyWindow(window);
9828 return;
9831 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
9832 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
9833 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
9834 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
9836 memset(&z_fmt, 0, sizeof(z_fmt));
9837 IDirect3D7_EnumZBufferFormats(d3d, &IID_IDirect3DHALDevice, enum_z_fmt, &z_fmt);
9838 if (!z_fmt.dwSize)
9839 skip("No Z buffer formats supported, skipping Z buffer colorfill test.\n");
9841 IDirect3DDevice7_EnumTextureFormats(device, test_block_formats_creation_cb, &supported_fmts);
9842 if (!(supported_fmts & SUPPORT_DXT1))
9843 skip("DXT1 textures not supported, skipping DXT1 colorfill test.\n");
9845 IDirect3D7_Release(d3d);
9847 hr = IDirectDraw7_GetFourCCCodes(ddraw, &num_fourcc_codes, NULL);
9848 ok(SUCCEEDED(hr), "Failed to get fourcc codes %#x.\n", hr);
9849 fourcc_codes = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
9850 num_fourcc_codes * sizeof(*fourcc_codes));
9851 if (!fourcc_codes)
9852 goto done;
9853 hr = IDirectDraw7_GetFourCCCodes(ddraw, &num_fourcc_codes, fourcc_codes);
9854 ok(SUCCEEDED(hr), "Failed to get fourcc codes %#x.\n", hr);
9855 for (i = 0; i < num_fourcc_codes; i++)
9857 if (fourcc_codes[i] == MAKEFOURCC('Y', 'U', 'Y', '2'))
9858 supported_fmts |= SUPPORT_YUY2;
9859 else if (fourcc_codes[i] == MAKEFOURCC('U', 'Y', 'V', 'Y'))
9860 supported_fmts |= SUPPORT_UYVY;
9862 HeapFree(GetProcessHeap(), 0, fourcc_codes);
9864 memset(&hal_caps, 0, sizeof(hal_caps));
9865 hal_caps.dwSize = sizeof(hal_caps);
9866 hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, NULL);
9867 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
9869 if (!(supported_fmts & (SUPPORT_YUY2 | SUPPORT_UYVY)) || !(hal_caps.dwCaps & DDCAPS_OVERLAY))
9870 skip("Overlays or some YUV formats not supported, skipping YUV colorfill tests.\n");
9872 for (i = 0; i < ARRAY_SIZE(tests); ++i)
9874 DWORD expected_broken = tests[i].result;
9876 /* Some Windows drivers modify dwFillColor when it is used on P8 or FourCC formats. */
9877 memset(&fx, 0, sizeof(fx));
9878 fx.dwSize = sizeof(fx);
9879 U5(fx).dwFillColor = 0xdeadbeef;
9881 memset(&surface_desc, 0, sizeof(surface_desc));
9882 surface_desc.dwSize = sizeof(surface_desc);
9883 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
9884 surface_desc.dwWidth = 64;
9885 surface_desc.dwHeight = 64;
9886 U4(surface_desc).ddpfPixelFormat = tests[i].format;
9887 surface_desc.ddsCaps.dwCaps = tests[i].caps;
9888 surface_desc.ddsCaps.dwCaps2 = tests[i].caps2;
9890 if (tests[i].format.dwFourCC == MAKEFOURCC('D','X','T','1') && !(supported_fmts & SUPPORT_DXT1))
9891 continue;
9892 if (tests[i].format.dwFourCC == MAKEFOURCC('Y','U','Y','2') && !(supported_fmts & SUPPORT_YUY2))
9893 continue;
9894 if (tests[i].format.dwFourCC == MAKEFOURCC('U','Y','V','Y') && !(supported_fmts & SUPPORT_UYVY))
9895 continue;
9896 if (tests[i].caps & DDSCAPS_OVERLAY && !(hal_caps.dwCaps & DDCAPS_OVERLAY))
9897 continue;
9899 if (tests[i].caps & DDSCAPS_ZBUFFER)
9901 if (!z_fmt.dwSize)
9902 continue;
9904 U4(surface_desc).ddpfPixelFormat = z_fmt;
9905 /* Some drivers seem to convert depth values incorrectly or not at
9906 * all. Affects at least AMD PALM, 8.17.10.1247. */
9907 if (tests[i].caps & DDSCAPS_VIDEOMEMORY)
9909 DWORD expected;
9910 float f, g;
9912 expected = tests[i].result & U3(z_fmt).dwZBitMask;
9913 f = ceilf(log2f(expected + 1.0f));
9914 g = (f + 1.0f) / 2.0f;
9915 g -= (int)g;
9916 expected_broken = (expected / exp2f(f) - g) * 256;
9917 expected_broken *= 0x01010101;
9921 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
9922 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x, surface %s.\n", hr, tests[i].name);
9924 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
9925 todo_wine_if (tests[i].format.dwFourCC)
9926 ok(hr == tests[i].colorfill_hr, "Blt returned %#x, expected %#x, surface %s.\n",
9927 hr, tests[i].colorfill_hr, tests[i].name);
9929 hr = IDirectDrawSurface7_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
9930 todo_wine_if (tests[i].format.dwFourCC)
9931 ok(hr == tests[i].colorfill_hr, "Blt returned %#x, expected %#x, surface %s.\n",
9932 hr, tests[i].colorfill_hr, tests[i].name);
9934 if (SUCCEEDED(hr) && tests[i].check_result)
9936 memset(&surface_desc, 0, sizeof(surface_desc));
9937 surface_desc.dwSize = sizeof(surface_desc);
9938 hr = IDirectDrawSurface7_Lock(surface, NULL, &surface_desc, DDLOCK_READONLY, 0);
9939 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x, surface %s.\n", hr, tests[i].name);
9940 color = surface_desc.lpSurface;
9941 ok(*color == tests[i].result, "Got clear result 0x%08x, expected 0x%08x, surface %s.\n",
9942 *color, tests[i].result, tests[i].name);
9943 hr = IDirectDrawSurface7_Unlock(surface, NULL);
9944 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, surface %s.\n", hr, tests[i].name);
9947 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
9948 ok(hr == tests[i].depthfill_hr, "Blt returned %#x, expected %#x, surface %s.\n",
9949 hr, tests[i].depthfill_hr, tests[i].name);
9950 hr = IDirectDrawSurface7_Blt(surface, &rect, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
9951 ok(hr == tests[i].depthfill_hr, "Blt returned %#x, expected %#x, surface %s.\n",
9952 hr, tests[i].depthfill_hr, tests[i].name);
9954 if (SUCCEEDED(hr) && tests[i].check_result)
9956 memset(&surface_desc, 0, sizeof(surface_desc));
9957 surface_desc.dwSize = sizeof(surface_desc);
9958 hr = IDirectDrawSurface7_Lock(surface, NULL, &surface_desc, DDLOCK_READONLY, 0);
9959 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x, surface %s.\n", hr, tests[i].name);
9960 color = surface_desc.lpSurface;
9961 ok((*color & U3(z_fmt).dwZBitMask) == (tests[i].result & U3(z_fmt).dwZBitMask)
9962 || broken((*color & U3(z_fmt).dwZBitMask) == (expected_broken & U3(z_fmt).dwZBitMask)),
9963 "Got clear result 0x%08x, expected 0x%08x, surface %s.\n",
9964 *color & U3(z_fmt).dwZBitMask, tests[i].result & U3(z_fmt).dwZBitMask, tests[i].name);
9965 hr = IDirectDrawSurface7_Unlock(surface, NULL);
9966 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, surface %s.\n", hr, tests[i].name);
9969 U5(fx).dwFillColor = 0xdeadbeef;
9970 fx.dwROP = BLACKNESS;
9971 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_ROP | DDBLT_WAIT, &fx);
9972 ok(FAILED(hr) == !tests[i].rop_success, "Blt returned %#x, expected %s, surface %s.\n",
9973 hr, tests[i].rop_success ? "success" : "failure", tests[i].name);
9974 ok(U5(fx).dwFillColor == 0xdeadbeef, "dwFillColor was set to 0x%08x, surface %s\n",
9975 U5(fx).dwFillColor, tests[i].name);
9977 if (SUCCEEDED(hr) && tests[i].check_result)
9979 memset(&surface_desc, 0, sizeof(surface_desc));
9980 surface_desc.dwSize = sizeof(surface_desc);
9981 hr = IDirectDrawSurface7_Lock(surface, NULL, &surface_desc, DDLOCK_READONLY, 0);
9982 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x, surface %s.\n", hr, tests[i].name);
9983 color = surface_desc.lpSurface;
9984 ok(*color == 0, "Got clear result 0x%08x, expected 0x00000000, surface %s.\n",
9985 *color, tests[i].name);
9986 hr = IDirectDrawSurface7_Unlock(surface, NULL);
9987 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, surface %s.\n", hr, tests[i].name);
9990 fx.dwROP = WHITENESS;
9991 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_ROP | DDBLT_WAIT, &fx);
9992 ok(FAILED(hr) == !tests[i].rop_success, "Blt returned %#x, expected %s, surface %s.\n",
9993 hr, tests[i].rop_success ? "success" : "failure", tests[i].name);
9994 ok(U5(fx).dwFillColor == 0xdeadbeef, "dwFillColor was set to 0x%08x, surface %s\n",
9995 U5(fx).dwFillColor, tests[i].name);
9997 if (SUCCEEDED(hr) && tests[i].check_result)
9999 memset(&surface_desc, 0, sizeof(surface_desc));
10000 surface_desc.dwSize = sizeof(surface_desc);
10001 hr = IDirectDrawSurface7_Lock(surface, NULL, &surface_desc, DDLOCK_READONLY, 0);
10002 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x, surface %s.\n", hr, tests[i].name);
10003 color = surface_desc.lpSurface;
10004 /* WHITENESS sets the alpha channel to 0x00. Ignore this for now. */
10005 ok((*color & 0x00ffffff) == 0x00ffffff, "Got clear result 0x%08x, expected 0xffffffff, surface %s.\n",
10006 *color, tests[i].name);
10007 hr = IDirectDrawSurface7_Unlock(surface, NULL);
10008 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, surface %s.\n", hr, tests[i].name);
10011 IDirectDrawSurface7_Release(surface);
10014 memset(&fx, 0, sizeof(fx));
10015 fx.dwSize = sizeof(fx);
10016 U5(fx).dwFillColor = 0xdeadbeef;
10017 fx.dwROP = WHITENESS;
10019 memset(&surface_desc, 0, sizeof(surface_desc));
10020 surface_desc.dwSize = sizeof(surface_desc);
10021 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
10022 surface_desc.dwWidth = 64;
10023 surface_desc.dwHeight = 64;
10024 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
10025 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
10026 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
10027 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
10028 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
10029 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
10030 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
10031 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
10032 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
10033 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface2, NULL);
10034 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
10036 /* No DDBLTFX. */
10037 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_COLORFILL | DDBLT_WAIT, NULL);
10038 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10039 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_ROP | DDBLT_WAIT, NULL);
10040 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10042 /* Unused source rectangle. */
10043 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
10044 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10045 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_ROP | DDBLT_WAIT, &fx);
10046 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10048 /* Unused source surface. */
10049 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
10050 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10051 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, NULL, DDBLT_ROP | DDBLT_WAIT, &fx);
10052 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10053 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
10054 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10055 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, &rect, DDBLT_ROP | DDBLT_WAIT, &fx);
10056 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10058 /* Inverted destination or source rectangle. */
10059 SetRect(&rect, 5, 7, 7, 5);
10060 hr = IDirectDrawSurface7_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
10061 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
10062 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
10063 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10064 hr = IDirectDrawSurface7_Blt(surface, &rect, surface2, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
10065 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10066 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
10067 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10068 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, &rect, DDBLT_ROP | DDBLT_WAIT, &fx);
10069 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
10071 /* Negative rectangle. */
10072 SetRect(&rect, -1, -1, 5, 5);
10073 hr = IDirectDrawSurface7_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
10074 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
10075 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
10076 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10077 hr = IDirectDrawSurface7_Blt(surface, &rect, surface2, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
10078 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10079 hr = IDirectDrawSurface7_Blt(surface, &rect, surface2, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
10080 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10081 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, &rect, DDBLT_ROP | DDBLT_WAIT, &fx);
10082 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
10084 /* Out of bounds rectangle. */
10085 SetRect(&rect, 0, 0, 65, 65);
10086 hr = IDirectDrawSurface7_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
10087 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
10088 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, &rect, DDBLT_ROP | DDBLT_WAIT, &fx);
10089 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
10091 /* Combine multiple flags. */
10092 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
10093 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10094 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_ROP | DDBLT_WAIT, &fx);
10095 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10096 hr = IDirectDrawSurface7_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_ROP | DDBLT_WAIT, &fx);
10097 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10099 for (i = 0; i < ARRAY_SIZE(rops); ++i)
10101 fx.dwROP = rops[i].rop;
10102 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, NULL, DDBLT_ROP | DDBLT_WAIT, &fx);
10103 ok(hr == rops[i].hr, "Got unexpected hr %#x for rop %s.\n", hr, rops[i].name);
10106 IDirectDrawSurface7_Release(surface2);
10107 IDirectDrawSurface7_Release(surface);
10109 if (!z_fmt.dwSize)
10110 goto done;
10112 memset(&surface_desc, 0, sizeof(surface_desc));
10113 surface_desc.dwSize = sizeof(surface_desc);
10114 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
10115 surface_desc.dwWidth = 64;
10116 surface_desc.dwHeight = 64;
10117 U4(surface_desc).ddpfPixelFormat = z_fmt;
10118 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
10119 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
10120 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
10121 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface2, NULL);
10122 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
10124 /* No DDBLTFX. */
10125 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, NULL);
10126 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10128 /* Unused source rectangle. */
10129 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
10130 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10132 /* Unused source surface. */
10133 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
10134 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10135 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
10136 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10138 /* Inverted destination or source rectangle. */
10139 SetRect(&rect, 5, 7, 7, 5);
10140 hr = IDirectDrawSurface7_Blt(surface, &rect, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
10141 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
10142 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
10143 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10144 hr = IDirectDrawSurface7_Blt(surface, &rect, surface2, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
10145 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10146 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
10147 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10149 /* Negative rectangle. */
10150 SetRect(&rect, -1, -1, 5, 5);
10151 hr = IDirectDrawSurface7_Blt(surface, &rect, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
10152 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
10153 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
10154 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10155 hr = IDirectDrawSurface7_Blt(surface, &rect, surface2, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
10156 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10157 hr = IDirectDrawSurface7_Blt(surface, &rect, surface2, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
10158 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10160 /* Out of bounds rectangle. */
10161 SetRect(&rect, 0, 0, 65, 65);
10162 hr = IDirectDrawSurface7_Blt(surface, &rect, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
10163 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
10165 /* Combine multiple flags. */
10166 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
10167 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10169 IDirectDrawSurface7_Release(surface2);
10170 IDirectDrawSurface7_Release(surface);
10172 done:
10173 IDirectDraw7_Release(ddraw);
10174 refcount = IDirect3DDevice7_Release(device);
10175 ok(!refcount, "Device has %u references left.\n", refcount);
10176 DestroyWindow(window);
10179 static void test_texcoordindex(void)
10181 static D3DMATRIX mat =
10183 1.0f, 0.0f, 0.0f, 0.0f,
10184 0.0f, 0.0f, 0.0f, 0.0f,
10185 0.0f, 0.0f, 0.0f, 0.0f,
10186 0.0f, 0.0f, 0.0f, 0.0f,
10188 static struct
10190 struct vec3 pos;
10191 struct vec2 texcoord1;
10192 struct vec2 texcoord2;
10193 struct vec2 texcoord3;
10195 quad[] =
10197 {{-1.0f, -1.0f, 0.0f}, {0.0f, 1.0f}, {0.0f, 0.0f}, {1.0f, 1.0f}},
10198 {{-1.0f, 1.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 1.0f}, {1.0f, 0.0f}},
10199 {{ 1.0f, -1.0f, 0.0f}, {1.0f, 1.0f}, {1.0f, 0.0f}, {0.0f, 1.0f}},
10200 {{ 1.0f, 1.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 0.0f}},
10202 static const DWORD fvf = D3DFVF_XYZ | D3DFVF_TEX3;
10203 IDirect3DDevice7 *device;
10204 IDirect3D7 *d3d;
10205 IDirectDraw7 *ddraw;
10206 IDirectDrawSurface7 *rt;
10207 HWND window;
10208 HRESULT hr;
10209 IDirectDrawSurface7 *texture1, *texture2;
10210 DDSURFACEDESC2 surface_desc;
10211 ULONG refcount;
10212 D3DCOLOR color;
10213 DWORD *ptr;
10215 window = create_window();
10216 if (!(device = create_device(window, DDSCL_NORMAL)))
10218 skip("Failed to create a 3D device, skipping test.\n");
10219 DestroyWindow(window);
10220 return;
10223 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
10224 ok(SUCCEEDED(hr), "Failed to get Direct3D7 interface, hr %#x.\n", hr);
10225 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
10226 ok(SUCCEEDED(hr), "Failed to get DirectDraw7 interface, hr %#x.\n", hr);
10227 IDirect3D7_Release(d3d);
10229 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
10230 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
10232 memset(&surface_desc, 0, sizeof(surface_desc));
10233 surface_desc.dwSize = sizeof(surface_desc);
10234 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
10235 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
10236 surface_desc.dwWidth = 2;
10237 surface_desc.dwHeight = 2;
10238 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
10239 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
10240 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
10241 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
10242 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
10243 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
10244 U5(U4(surface_desc).ddpfPixelFormat).dwRGBAlphaBitMask = 0xff000000;
10245 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &texture1, NULL);
10246 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
10247 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &texture2, NULL);
10248 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
10250 memset(&surface_desc, 0, sizeof(surface_desc));
10251 surface_desc.dwSize = sizeof(surface_desc);
10252 hr = IDirectDrawSurface7_Lock(texture1, 0, &surface_desc, 0, NULL);
10253 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
10254 ptr = surface_desc.lpSurface;
10255 ptr[0] = 0xff000000;
10256 ptr[1] = 0xff00ff00;
10257 ptr += U1(surface_desc).lPitch / sizeof(*ptr);
10258 ptr[0] = 0xff0000ff;
10259 ptr[1] = 0xff00ffff;
10260 hr = IDirectDrawSurface7_Unlock(texture1, NULL);
10261 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
10263 memset(&surface_desc, 0, sizeof(surface_desc));
10264 surface_desc.dwSize = sizeof(surface_desc);
10265 hr = IDirectDrawSurface7_Lock(texture2, 0, &surface_desc, 0, NULL);
10266 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
10267 ptr = surface_desc.lpSurface;
10268 ptr[0] = 0xff000000;
10269 ptr[1] = 0xff0000ff;
10270 ptr += U1(surface_desc).lPitch / sizeof(*ptr);
10271 ptr[0] = 0xffff0000;
10272 ptr[1] = 0xffff00ff;
10273 hr = IDirectDrawSurface7_Unlock(texture2, 0);
10274 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
10276 hr = IDirect3DDevice7_SetTexture(device, 0, texture1);
10277 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
10278 hr = IDirect3DDevice7_SetTexture(device, 1, texture2);
10279 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
10280 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
10281 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
10282 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
10283 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
10284 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
10285 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
10286 hr = IDirect3DDevice7_SetTextureStageState(device, 1, D3DTSS_COLOROP, D3DTOP_ADD);
10287 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
10288 hr = IDirect3DDevice7_SetTextureStageState(device, 1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
10289 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
10290 hr = IDirect3DDevice7_SetTextureStageState(device, 1, D3DTSS_COLORARG2, D3DTA_CURRENT);
10291 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
10292 hr = IDirect3DDevice7_SetTextureStageState(device, 2, D3DTSS_COLOROP, D3DTOP_DISABLE);
10293 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
10295 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_TEXCOORDINDEX, 1);
10296 ok(SUCCEEDED(hr), "Failed to set texcoord index, hr %#x.\n", hr);
10297 hr = IDirect3DDevice7_SetTextureStageState(device, 1, D3DTSS_TEXCOORDINDEX, 0);
10298 ok(SUCCEEDED(hr), "Failed to set texcoord index, hr %#x.\n", hr);
10300 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, FALSE);
10301 ok(SUCCEEDED(hr), "Failed to disable z-buffering, hr %#x.\n", hr);
10303 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffff00, 1.0f, 0);
10304 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
10306 hr = IDirect3DDevice7_BeginScene(device);
10307 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
10308 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, fvf, quad, 4, 0);
10309 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10310 hr = IDirect3DDevice7_EndScene(device);
10311 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
10313 color = get_surface_color(rt, 160, 120);
10314 ok(compare_color(color, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color);
10315 color = get_surface_color(rt, 480, 120);
10316 ok(compare_color(color, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color);
10317 color = get_surface_color(rt, 160, 360);
10318 ok(compare_color(color, 0x00ff0000, 2), "Got unexpected color 0x%08x.\n", color);
10319 color = get_surface_color(rt, 480, 360);
10320 ok(compare_color(color, 0x00ffffff, 2), "Got unexpected color 0x%08x.\n", color);
10322 hr = IDirect3DDevice7_SetTextureStageState(device, 1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);
10323 ok(SUCCEEDED(hr), "Failed to set texture transform flags, hr %#x.\n", hr);
10324 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_TEXTURE1, &mat);
10325 ok(SUCCEEDED(hr), "Failed to set transformation matrix, hr %#x.\n", hr);
10327 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffff00, 1.0f, 0);
10328 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
10330 hr = IDirect3DDevice7_BeginScene(device);
10331 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
10332 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, fvf, quad, 4, 0);
10333 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10334 hr = IDirect3DDevice7_EndScene(device);
10335 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
10337 color = get_surface_color(rt, 160, 120);
10338 ok(compare_color(color, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color);
10339 color = get_surface_color(rt, 480, 120);
10340 ok(compare_color(color, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color);
10341 color = get_surface_color(rt, 160, 360);
10342 ok(compare_color(color, 0x00000000, 2), "Got unexpected color 0x%08x.\n", color);
10343 color = get_surface_color(rt, 480, 360);
10344 ok(compare_color(color, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color);
10346 hr = IDirect3DDevice7_SetTextureStageState(device, 1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE);
10347 ok(SUCCEEDED(hr), "Failed to set texture transform flags, hr %#x.\n", hr);
10348 hr = IDirect3DDevice7_SetTextureStageState(device, 1, D3DTSS_TEXCOORDINDEX, 2);
10349 ok(SUCCEEDED(hr), "Failed to set texcoord index, hr %#x.\n", hr);
10351 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffff00, 1.0f, 0);
10352 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
10354 hr = IDirect3DDevice7_BeginScene(device);
10355 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
10356 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, fvf, quad, 4, 0);
10357 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10358 hr = IDirect3DDevice7_EndScene(device);
10359 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
10361 color = get_surface_color(rt, 160, 120);
10362 ok(compare_color(color, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color);
10363 color = get_surface_color(rt, 480, 120);
10364 ok(compare_color(color, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color);
10365 color = get_surface_color(rt, 160, 360);
10366 ok(compare_color(color, 0x00ff00ff, 2), "Got unexpected color 0x%08x.\n", color);
10367 color = get_surface_color(rt, 480, 360);
10368 ok(compare_color(color, 0x00ffff00, 2), "Got unexpected color 0x%08x.\n", color);
10370 IDirectDrawSurface7_Release(texture1);
10371 IDirectDrawSurface7_Release(texture2);
10373 IDirectDrawSurface7_Release(rt);
10374 IDirectDraw_Release(ddraw);
10375 refcount = IDirect3DDevice7_Release(device);
10376 ok(!refcount, "Device has %u references left.\n", refcount);
10377 DestroyWindow(window);
10380 static void test_colorkey_precision(void)
10382 static struct
10384 struct vec3 pos;
10385 struct vec2 texcoord;
10387 quad[] =
10389 {{-1.0f, -1.0f, 0.0f}, {0.0f, 1.0f}},
10390 {{-1.0f, 1.0f, 0.0f}, {0.0f, 0.0f}},
10391 {{ 1.0f, -1.0f, 0.0f}, {1.0f, 1.0f}},
10392 {{ 1.0f, 1.0f, 0.0f}, {1.0f, 0.0f}},
10394 IDirect3DDevice7 *device;
10395 IDirect3D7 *d3d;
10396 IDirectDraw7 *ddraw;
10397 IDirectDrawSurface7 *rt;
10398 HWND window;
10399 HRESULT hr;
10400 IDirectDrawSurface7 *src, *dst, *texture;
10401 DDSURFACEDESC2 surface_desc, lock_desc;
10402 ULONG refcount;
10403 D3DCOLOR color;
10404 unsigned int t, c;
10405 DDCOLORKEY ckey;
10406 DDBLTFX fx;
10407 DWORD data[4] = {0}, color_mask;
10408 BOOL is_nvidia, is_warp;
10409 static const struct
10411 unsigned int max, shift, bpp, clear;
10412 const char *name;
10413 BOOL skip_nv;
10414 DDPIXELFORMAT fmt;
10416 tests[] =
10419 255, 0, 4, 0x00345678, "D3DFMT_X8R8G8B8", FALSE,
10421 sizeof(DDPIXELFORMAT), DDPF_RGB, 0,
10422 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0x00000000}
10427 63, 5, 2, 0x5678, "D3DFMT_R5G6B5, G channel", FALSE,
10429 sizeof(DDPIXELFORMAT), DDPF_RGB, 0,
10430 {16}, {0xf800}, {0x07e0}, {0x001f}, {0x0000}
10435 31, 0, 2, 0x5678, "D3DFMT_R5G6B5, B channel", FALSE,
10437 sizeof(DDPIXELFORMAT), DDPF_RGB, 0,
10438 {16}, {0xf800}, {0x07e0}, {0x001f}, {0x0000}
10443 15, 0, 2, 0x0678, "D3DFMT_A4R4G4B4", TRUE,
10445 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
10446 {16}, {0x0f00}, {0x00f0}, {0x000f}, {0xf000}
10451 window = create_window();
10452 if (!(device = create_device(window, DDSCL_NORMAL)))
10454 skip("Failed to create a 3D device, skipping test.\n");
10455 DestroyWindow(window);
10456 return;
10459 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
10460 ok(SUCCEEDED(hr), "Failed to get Direct3D7 interface, hr %#x.\n", hr);
10461 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
10462 ok(SUCCEEDED(hr), "Failed to get DirectDraw7 interface, hr %#x.\n", hr);
10463 IDirect3D7_Release(d3d);
10464 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
10465 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
10467 is_nvidia = ddraw_is_nvidia(ddraw);
10468 /* The Windows 8 WARP driver has plenty of false negatives in X8R8G8B8
10469 * (color key doesn't match although the values are equal), and a false
10470 * positive when the color key is 0 and the texture contains the value 1.
10471 * I don't want to mark this broken unconditionally since this would
10472 * essentially disable the test on Windows. Also on random occasions
10473 * 254 == 255 and 255 != 255.*/
10474 is_warp = ddraw_is_warp(ddraw);
10476 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
10477 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
10478 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
10479 ok(SUCCEEDED(hr), "Failed to disable z-buffering, hr %#x.\n", hr);
10480 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, TRUE);
10481 ok(SUCCEEDED(hr), "Failed to enable color keying, hr %#x.\n", hr);
10482 /* Multiply the texture read result with 0, that way the result color if the key doesn't
10483 * match is constant. In theory color keying works without reading the texture result
10484 * (meaning we could just op=arg1, arg1=tfactor), but the Geforce7 Windows driver begs
10485 * to differ. */
10486 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_MODULATE);
10487 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
10488 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
10489 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
10490 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLORARG2, D3DTA_TFACTOR);
10491 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
10492 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_TEXTUREFACTOR, 0x00000000);
10493 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
10495 memset(&fx, 0, sizeof(fx));
10496 fx.dwSize = sizeof(fx);
10497 memset(&lock_desc, 0, sizeof(lock_desc));
10498 lock_desc.dwSize = sizeof(lock_desc);
10500 for (t = 0; t < ARRAY_SIZE(tests); ++t)
10502 if (is_nvidia && tests[t].skip_nv)
10504 win_skip("Skipping test %s on Nvidia Windows drivers.\n", tests[t].name);
10505 continue;
10508 memset(&surface_desc, 0, sizeof(surface_desc));
10509 surface_desc.dwSize = sizeof(surface_desc);
10510 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
10511 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
10512 surface_desc.dwWidth = 4;
10513 surface_desc.dwHeight = 1;
10514 U4(surface_desc).ddpfPixelFormat = tests[t].fmt;
10515 /* Windows XP (at least with the r200 driver, other drivers untested) produces
10516 * garbage when doing color keyed texture->texture blits. */
10517 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &src, NULL);
10518 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
10519 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &dst, NULL);
10520 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
10522 U5(fx).dwFillColor = tests[t].clear;
10523 /* On the w8 testbot (WARP driver) the blit result has different values in the
10524 * X channel. */
10525 color_mask = U2(tests[t].fmt).dwRBitMask
10526 | U3(tests[t].fmt).dwGBitMask
10527 | U4(tests[t].fmt).dwBBitMask;
10529 for (c = 0; c <= tests[t].max; ++c)
10531 /* The idiotic Nvidia Windows driver can't change the color key on a d3d
10532 * texture after it has been set once... */
10533 surface_desc.dwFlags |= DDSD_CKSRCBLT;
10534 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
10535 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = c << tests[t].shift;
10536 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = c << tests[t].shift;
10537 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &texture, NULL);
10538 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
10539 hr = IDirect3DDevice7_SetTexture(device, 0, texture);
10540 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
10542 hr = IDirectDrawSurface7_Blt(dst, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
10543 ok(SUCCEEDED(hr), "Failed to clear destination surface, hr %#x.\n", hr);
10545 hr = IDirectDrawSurface7_Lock(src, NULL, &lock_desc, DDLOCK_WAIT, NULL);
10546 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
10547 switch (tests[t].bpp)
10549 case 4:
10550 ((DWORD *)lock_desc.lpSurface)[0] = (c ? c - 1 : 0) << tests[t].shift;
10551 ((DWORD *)lock_desc.lpSurface)[1] = c << tests[t].shift;
10552 ((DWORD *)lock_desc.lpSurface)[2] = min(c + 1, tests[t].max) << tests[t].shift;
10553 ((DWORD *)lock_desc.lpSurface)[3] = 0xffffffff;
10554 break;
10556 case 2:
10557 ((WORD *)lock_desc.lpSurface)[0] = (c ? c - 1 : 0) << tests[t].shift;
10558 ((WORD *)lock_desc.lpSurface)[1] = c << tests[t].shift;
10559 ((WORD *)lock_desc.lpSurface)[2] = min(c + 1, tests[t].max) << tests[t].shift;
10560 ((WORD *)lock_desc.lpSurface)[3] = 0xffff;
10561 break;
10563 hr = IDirectDrawSurface7_Unlock(src, 0);
10564 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
10565 hr = IDirectDrawSurface7_Blt(texture, NULL, src, NULL, DDBLT_WAIT, NULL);
10566 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
10568 ckey.dwColorSpaceLowValue = c << tests[t].shift;
10569 ckey.dwColorSpaceHighValue = c << tests[t].shift;
10570 hr = IDirectDrawSurface7_SetColorKey(src, DDCKEY_SRCBLT, &ckey);
10571 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
10573 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_KEYSRC | DDBLT_WAIT, NULL);
10574 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
10576 /* Don't make this read only, it somehow breaks the detection of the Nvidia bug below. */
10577 hr = IDirectDrawSurface7_Lock(dst, NULL, &lock_desc, DDLOCK_WAIT, NULL);
10578 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
10579 switch (tests[t].bpp)
10581 case 4:
10582 data[0] = ((DWORD *)lock_desc.lpSurface)[0] & color_mask;
10583 data[1] = ((DWORD *)lock_desc.lpSurface)[1] & color_mask;
10584 data[2] = ((DWORD *)lock_desc.lpSurface)[2] & color_mask;
10585 data[3] = ((DWORD *)lock_desc.lpSurface)[3] & color_mask;
10586 break;
10588 case 2:
10589 data[0] = ((WORD *)lock_desc.lpSurface)[0] & color_mask;
10590 data[1] = ((WORD *)lock_desc.lpSurface)[1] & color_mask;
10591 data[2] = ((WORD *)lock_desc.lpSurface)[2] & color_mask;
10592 data[3] = ((WORD *)lock_desc.lpSurface)[3] & color_mask;
10593 break;
10595 hr = IDirectDrawSurface7_Unlock(dst, 0);
10596 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
10598 if (!c)
10600 ok(data[0] == tests[t].clear, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10601 tests[t].clear, data[0], tests[t].name, c);
10603 if (data[3] == tests[t].clear)
10605 /* My Geforce GTX 460 on Windows 7 misbehaves when A4R4G4B4 is blitted with color
10606 * keying: The blit takes ~0.5 seconds, and subsequent color keying draws are broken,
10607 * even when a different surface is used. The blit itself doesn't draw anything,
10608 * so we can detect the bug by looking at the otherwise unused 4th texel. It should
10609 * never be masked out by the key.
10611 * On Windows 10 the problem is worse, Blt just hangs. For this reason the ARGB4444
10612 * test is disabled on Nvidia.
10614 * Also appears to affect the testbot in some way with R5G6B5. Color keying is
10615 * terrible on WARP. */
10616 skip("Nvidia A4R4G4B4 color keying blit bug detected, skipping.\n");
10617 IDirectDrawSurface7_Release(texture);
10618 IDirectDrawSurface7_Release(src);
10619 IDirectDrawSurface7_Release(dst);
10620 goto done;
10623 else
10624 ok(data[0] == (c - 1) << tests[t].shift, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10625 (c - 1) << tests[t].shift, data[0], tests[t].name, c);
10627 ok(data[1] == tests[t].clear, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10628 tests[t].clear, data[1], tests[t].name, c);
10630 if (c == tests[t].max)
10631 ok(data[2] == tests[t].clear, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10632 tests[t].clear, data[2], tests[t].name, c);
10633 else
10634 ok(data[2] == (c + 1) << tests[t].shift, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10635 (c + 1) << tests[t].shift, data[2], tests[t].name, c);
10637 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x0000ff00, 1.0f, 0);
10638 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
10640 hr = IDirect3DDevice7_BeginScene(device);
10641 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
10642 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_TEX1, quad, 4, 0);
10643 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10644 hr = IDirect3DDevice7_EndScene(device);
10645 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
10647 color = get_surface_color(rt, 80, 240);
10648 if (!c)
10649 ok(compare_color(color, 0x0000ff00, 1) || broken(is_warp && compare_color(color, 0x00000000, 1)),
10650 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10651 color, tests[t].name, c);
10652 else
10653 ok(compare_color(color, 0x00000000, 1) || broken(is_warp && compare_color(color, 0x0000ff00, 1)),
10654 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10655 color, tests[t].name, c);
10657 color = get_surface_color(rt, 240, 240);
10658 ok(compare_color(color, 0x0000ff00, 1) || broken(is_warp && compare_color(color, 0x00000000, 1)),
10659 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10660 color, tests[t].name, c);
10662 color = get_surface_color(rt, 400, 240);
10663 if (c == tests[t].max)
10664 ok(compare_color(color, 0x0000ff00, 1) || broken(is_warp && compare_color(color, 0x00000000, 1)),
10665 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10666 color, tests[t].name, c);
10667 else
10668 ok(compare_color(color, 0x00000000, 1) || broken(is_warp && compare_color(color, 0x0000ff00, 1)),
10669 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10670 color, tests[t].name, c);
10672 IDirectDrawSurface7_Release(texture);
10674 IDirectDrawSurface7_Release(src);
10675 IDirectDrawSurface7_Release(dst);
10677 done:
10679 IDirectDrawSurface7_Release(rt);
10680 IDirectDraw7_Release(ddraw);
10681 refcount = IDirect3DDevice7_Release(device);
10682 ok(!refcount, "Device has %u references left.\n", refcount);
10683 DestroyWindow(window);
10686 static void test_range_colorkey(void)
10688 IDirectDraw7 *ddraw;
10689 HWND window;
10690 HRESULT hr;
10691 IDirectDrawSurface7 *surface;
10692 DDSURFACEDESC2 surface_desc;
10693 ULONG refcount;
10694 DDCOLORKEY ckey;
10696 window = create_window();
10697 ddraw = create_ddraw();
10698 ok(!!ddraw, "Failed to create a ddraw object.\n");
10699 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
10700 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
10702 memset(&surface_desc, 0, sizeof(surface_desc));
10703 surface_desc.dwSize = sizeof(surface_desc);
10704 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CKSRCBLT;
10705 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
10706 surface_desc.dwWidth = 1;
10707 surface_desc.dwHeight = 1;
10708 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
10709 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
10710 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
10711 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
10712 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
10713 U5(U4(surface_desc).ddpfPixelFormat).dwRGBAlphaBitMask = 0x00000000;
10715 /* Creating a surface with a range color key fails with DDERR_NOCOLORKEY. */
10716 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00000000;
10717 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00000001;
10718 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
10719 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
10721 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00000001;
10722 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00000000;
10723 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
10724 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
10726 /* Same for DDSCAPS_OFFSCREENPLAIN. */
10727 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
10728 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00000000;
10729 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00000001;
10730 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
10731 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
10733 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00000001;
10734 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00000000;
10735 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
10736 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
10738 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00000000;
10739 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00000000;
10740 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
10741 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
10743 /* Setting a range color key without DDCKEY_COLORSPACE collapses the key. */
10744 ckey.dwColorSpaceLowValue = 0x00000000;
10745 ckey.dwColorSpaceHighValue = 0x00000001;
10746 hr = IDirectDrawSurface7_SetColorKey(surface, DDCKEY_SRCBLT, &ckey);
10747 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
10749 hr = IDirectDrawSurface7_GetColorKey(surface, DDCKEY_SRCBLT, &ckey);
10750 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
10751 ok(!ckey.dwColorSpaceLowValue, "Got unexpected value 0x%08x.\n", ckey.dwColorSpaceLowValue);
10752 ok(!ckey.dwColorSpaceHighValue, "Got unexpected value 0x%08x.\n", ckey.dwColorSpaceHighValue);
10754 ckey.dwColorSpaceLowValue = 0x00000001;
10755 ckey.dwColorSpaceHighValue = 0x00000000;
10756 hr = IDirectDrawSurface7_SetColorKey(surface, DDCKEY_SRCBLT, &ckey);
10757 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
10759 hr = IDirectDrawSurface7_GetColorKey(surface, DDCKEY_SRCBLT, &ckey);
10760 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
10761 ok(ckey.dwColorSpaceLowValue == 0x00000001, "Got unexpected value 0x%08x.\n", ckey.dwColorSpaceLowValue);
10762 ok(ckey.dwColorSpaceHighValue == 0x00000001, "Got unexpected value 0x%08x.\n", ckey.dwColorSpaceHighValue);
10764 /* DDCKEY_COLORSPACE is ignored if the key is a single value. */
10765 ckey.dwColorSpaceLowValue = 0x00000000;
10766 ckey.dwColorSpaceHighValue = 0x00000000;
10767 hr = IDirectDrawSurface7_SetColorKey(surface, DDCKEY_SRCBLT | DDCKEY_COLORSPACE, &ckey);
10768 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
10770 /* Using it with a range key results in DDERR_NOCOLORKEYHW. */
10771 ckey.dwColorSpaceLowValue = 0x00000001;
10772 ckey.dwColorSpaceHighValue = 0x00000000;
10773 hr = IDirectDrawSurface7_SetColorKey(surface, DDCKEY_SRCBLT | DDCKEY_COLORSPACE, &ckey);
10774 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
10775 ckey.dwColorSpaceLowValue = 0x00000000;
10776 ckey.dwColorSpaceHighValue = 0x00000001;
10777 hr = IDirectDrawSurface7_SetColorKey(surface, DDCKEY_SRCBLT | DDCKEY_COLORSPACE, &ckey);
10778 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
10779 /* Range destination keys don't work either. */
10780 hr = IDirectDrawSurface7_SetColorKey(surface, DDCKEY_DESTBLT | DDCKEY_COLORSPACE, &ckey);
10781 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
10783 /* Just to show it's not because of A, R, and G having equal values. */
10784 ckey.dwColorSpaceLowValue = 0x00000000;
10785 ckey.dwColorSpaceHighValue = 0x01010101;
10786 hr = IDirectDrawSurface7_SetColorKey(surface, DDCKEY_SRCBLT | DDCKEY_COLORSPACE, &ckey);
10787 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
10789 /* None of these operations modified the key. */
10790 hr = IDirectDrawSurface7_GetColorKey(surface, DDCKEY_SRCBLT, &ckey);
10791 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
10792 ok(!ckey.dwColorSpaceLowValue, "Got unexpected value 0x%08x.\n", ckey.dwColorSpaceLowValue);
10793 ok(!ckey.dwColorSpaceHighValue, "Got unexpected value 0x%08x.\n", ckey.dwColorSpaceHighValue);
10795 IDirectDrawSurface7_Release(surface),
10796 refcount = IDirectDraw7_Release(ddraw);
10797 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
10798 DestroyWindow(window);
10801 static void test_shademode(void)
10803 IDirect3DVertexBuffer7 *vb_strip, *vb_list, *buffer;
10804 IDirect3DDevice7 *device;
10805 D3DVERTEXBUFFERDESC desc;
10806 IDirectDrawSurface7 *rt;
10807 DWORD color0, color1;
10808 void *data = NULL;
10809 IDirect3D7 *d3d;
10810 ULONG refcount;
10811 UINT i, count;
10812 HWND window;
10813 HRESULT hr;
10814 static const struct
10816 struct vec3 position;
10817 DWORD diffuse;
10819 quad_strip[] =
10821 {{-1.0f, -1.0f, 0.0f}, 0xffff0000},
10822 {{-1.0f, 1.0f, 0.0f}, 0xff00ff00},
10823 {{ 1.0f, -1.0f, 0.0f}, 0xff0000ff},
10824 {{ 1.0f, 1.0f, 0.0f}, 0xffffffff},
10826 quad_list[] =
10828 {{-1.0f, -1.0f, 0.0f}, 0xffff0000},
10829 {{-1.0f, 1.0f, 0.0f}, 0xff00ff00},
10830 {{ 1.0f, -1.0f, 0.0f}, 0xff0000ff},
10832 {{ 1.0f, -1.0f, 0.0f}, 0xff0000ff},
10833 {{-1.0f, 1.0f, 0.0f}, 0xff00ff00},
10834 {{ 1.0f, 1.0f, 0.0f}, 0xffffffff},
10836 static const struct
10838 DWORD primtype;
10839 DWORD shademode;
10840 DWORD color0, color1;
10842 tests[] =
10844 {D3DPT_TRIANGLESTRIP, D3DSHADE_FLAT, 0x00ff0000, 0x0000ff00},
10845 {D3DPT_TRIANGLESTRIP, D3DSHADE_PHONG, 0x000dca28, 0x000d45c7},
10846 {D3DPT_TRIANGLESTRIP, D3DSHADE_GOURAUD, 0x000dca28, 0x000d45c7},
10847 {D3DPT_TRIANGLESTRIP, D3DSHADE_PHONG, 0x000dca28, 0x000d45c7},
10848 {D3DPT_TRIANGLELIST, D3DSHADE_FLAT, 0x00ff0000, 0x000000ff},
10849 {D3DPT_TRIANGLELIST, D3DSHADE_GOURAUD, 0x000dca28, 0x000d45c7},
10852 window = create_window();
10853 if (!(device = create_device(window, DDSCL_NORMAL)))
10855 skip("Failed to create a 3D device, skipping test.\n");
10856 DestroyWindow(window);
10857 return;
10860 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
10861 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
10862 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
10863 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
10865 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
10866 ok(hr == D3D_OK, "Failed to disable lighting, hr %#x.\n", hr);
10867 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, FALSE);
10868 ok(SUCCEEDED(hr), "Failed to disable fog, hr %#x.\n", hr);
10870 memset(&desc, 0, sizeof(desc));
10871 desc.dwSize = sizeof(desc);
10872 desc.dwCaps = D3DVBCAPS_WRITEONLY;
10873 desc.dwFVF = D3DFVF_XYZ | D3DFVF_DIFFUSE;
10874 desc.dwNumVertices = ARRAY_SIZE(quad_strip);
10875 hr = IDirect3D7_CreateVertexBuffer(d3d, &desc, &vb_strip, 0);
10876 ok(hr == D3D_OK, "Failed to create vertex buffer, hr %#x.\n", hr);
10877 hr = IDirect3DVertexBuffer7_Lock(vb_strip, 0, &data, NULL);
10878 ok(hr == D3D_OK, "Failed to lock vertex buffer, hr %#x.\n", hr);
10879 memcpy(data, quad_strip, sizeof(quad_strip));
10880 hr = IDirect3DVertexBuffer7_Unlock(vb_strip);
10881 ok(hr == D3D_OK, "Failed to unlock vertex buffer, hr %#x.\n", hr);
10883 desc.dwNumVertices = ARRAY_SIZE(quad_list);
10884 hr = IDirect3D7_CreateVertexBuffer(d3d, &desc, &vb_list, 0);
10885 ok(hr == D3D_OK, "Failed to create vertex buffer, hr %#x.\n", hr);
10886 hr = IDirect3DVertexBuffer7_Lock(vb_list, 0, &data, NULL);
10887 ok(hr == D3D_OK, "Failed to lock vertex buffer, hr %#x.\n", hr);
10888 memcpy(data, quad_list, sizeof(quad_list));
10889 hr = IDirect3DVertexBuffer7_Unlock(vb_list);
10890 ok(hr == D3D_OK, "Failed to unlock vertex buffer, hr %#x.\n", hr);
10892 /* Try it first with a TRIANGLESTRIP. Do it with different geometry because
10893 * the color fixups we have to do for FLAT shading will be dependent on that. */
10895 for (i = 0; i < ARRAY_SIZE(tests); ++i)
10897 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0f, 0);
10898 ok(hr == D3D_OK, "Failed to clear, hr %#x.\n", hr);
10900 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_SHADEMODE, tests[i].shademode);
10901 ok(hr == D3D_OK, "Failed to set shade mode, hr %#x.\n", hr);
10903 hr = IDirect3DDevice7_BeginScene(device);
10904 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
10905 buffer = tests[i].primtype == D3DPT_TRIANGLESTRIP ? vb_strip : vb_list;
10906 count = tests[i].primtype == D3DPT_TRIANGLESTRIP ? 4 : 6;
10907 hr = IDirect3DDevice7_DrawPrimitiveVB(device, tests[i].primtype, buffer, 0, count, 0);
10908 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10909 hr = IDirect3DDevice7_EndScene(device);
10910 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
10912 color0 = get_surface_color(rt, 100, 100); /* Inside first triangle */
10913 color1 = get_surface_color(rt, 500, 350); /* Inside second triangle */
10915 /* For D3DSHADE_FLAT it should take the color of the first vertex of
10916 * each triangle. This requires EXT_provoking_vertex or similar
10917 * functionality being available. */
10918 /* PHONG should be the same as GOURAUD, since no hardware implements
10919 * this. */
10920 ok(compare_color(color0, tests[i].color0, 1), "Test %u shading has color0 %08x, expected %08x.\n",
10921 i, color0, tests[i].color0);
10922 ok(compare_color(color1, tests[i].color1, 1), "Test %u shading has color1 %08x, expected %08x.\n",
10923 i, color1, tests[i].color1);
10926 IDirect3DVertexBuffer7_Release(vb_strip);
10927 IDirect3DVertexBuffer7_Release(vb_list);
10928 IDirectDrawSurface7_Release(rt);
10929 IDirect3D7_Release(d3d);
10930 refcount = IDirect3DDevice7_Release(device);
10931 ok(!refcount, "Device has %u references left.\n", refcount);
10932 DestroyWindow(window);
10935 static void test_lockrect_invalid(void)
10937 unsigned int i, r;
10938 IDirectDraw7 *ddraw;
10939 IDirectDrawSurface7 *surface;
10940 HWND window;
10941 HRESULT hr;
10942 DDSURFACEDESC2 surface_desc;
10943 DDSURFACEDESC2 locked_desc;
10944 DDCAPS hal_caps;
10945 DWORD needed_caps = DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY;
10946 static RECT valid[] =
10948 {60, 60, 68, 68},
10949 {60, 60, 60, 68},
10950 {60, 60, 68, 60},
10951 {120, 60, 128, 68},
10952 {60, 120, 68, 128},
10954 static RECT invalid[] =
10956 {68, 60, 60, 68}, /* left > right */
10957 {60, 68, 68, 60}, /* top > bottom */
10958 {-8, 60, 0, 68}, /* left < surface */
10959 {60, -8, 68, 0}, /* top < surface */
10960 {-16, 60, -8, 68}, /* right < surface */
10961 {60, -16, 68, -8}, /* bottom < surface */
10962 {60, 60, 136, 68}, /* right > surface */
10963 {60, 60, 68, 136}, /* bottom > surface */
10964 {136, 60, 144, 68}, /* left > surface */
10965 {60, 136, 68, 144}, /* top > surface */
10967 static const struct
10969 DWORD caps, caps2;
10970 const char *name;
10971 HRESULT hr;
10973 resources[] =
10975 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY, 0, "sysmem offscreenplain", DDERR_INVALIDPARAMS},
10976 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0, "vidmem offscreenplain", DDERR_INVALIDPARAMS},
10977 {DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, 0, "sysmem texture", DD_OK},
10978 {DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, 0, "vidmem texture", DDERR_INVALIDPARAMS},
10979 {DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, "managed texture", DD_OK},
10982 window = create_window();
10983 ddraw = create_ddraw();
10984 ok(!!ddraw, "Failed to create a ddraw object.\n");
10985 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
10986 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
10988 memset(&hal_caps, 0, sizeof(hal_caps));
10989 hal_caps.dwSize = sizeof(hal_caps);
10990 hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, NULL);
10991 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
10992 if ((hal_caps.ddsCaps.dwCaps & needed_caps) != needed_caps
10993 || !(hal_caps.ddsCaps.dwCaps & DDSCAPS2_TEXTUREMANAGE))
10995 skip("Required surface types not supported, skipping test.\n");
10996 goto done;
10999 for (r = 0; r < ARRAY_SIZE(resources); ++r)
11001 memset(&surface_desc, 0, sizeof(surface_desc));
11002 surface_desc.dwSize = sizeof(surface_desc);
11003 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
11004 surface_desc.ddsCaps.dwCaps = resources[r].caps;
11005 surface_desc.ddsCaps.dwCaps2 = resources[r].caps2;
11006 surface_desc.dwWidth = 128;
11007 surface_desc.dwHeight = 128;
11008 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
11009 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
11010 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
11011 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0xff0000;
11012 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x00ff00;
11013 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x0000ff;
11015 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
11016 if (is_ddraw64 && (resources[r].caps & DDSCAPS_TEXTURE))
11018 todo_wine ok(hr == E_NOINTERFACE, "Got unexpected hr %#x, type %s.\n", hr, resources[r].name);
11019 if (SUCCEEDED(hr))
11020 IDirectDrawSurface7_Release(surface);
11021 continue;
11023 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x, type %s.\n", hr, resources[r].name);
11025 /* Crashes in ddraw7
11026 hr = IDirectDrawSurface7_Lock(surface, NULL, NULL, DDLOCK_WAIT, NULL);
11027 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x, type %s.\n", hr, resources[r].name);
11030 for (i = 0; i < ARRAY_SIZE(valid); ++i)
11032 RECT *rect = &valid[i];
11034 memset(&locked_desc, 0, sizeof(locked_desc));
11035 locked_desc.dwSize = sizeof(locked_desc);
11037 hr = IDirectDrawSurface7_Lock(surface, rect, &locked_desc, DDLOCK_WAIT, NULL);
11038 ok(SUCCEEDED(hr), "Lock failed (%#x) for rect %s, type %s.\n",
11039 hr, wine_dbgstr_rect(rect), resources[r].name);
11041 hr = IDirectDrawSurface7_Unlock(surface, NULL);
11042 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
11045 for (i = 0; i < ARRAY_SIZE(invalid); ++i)
11047 RECT *rect = &invalid[i];
11049 memset(&locked_desc, 1, sizeof(locked_desc));
11050 locked_desc.dwSize = sizeof(locked_desc);
11052 hr = IDirectDrawSurface7_Lock(surface, rect, &locked_desc, DDLOCK_WAIT, NULL);
11053 todo_wine_if (SUCCEEDED(resources[r].hr))
11054 ok(hr == resources[r].hr, "Lock returned %#x for rect %s, type %s.\n",
11055 hr, wine_dbgstr_rect(rect), resources[r].name);
11056 if (SUCCEEDED(hr))
11058 hr = IDirectDrawSurface7_Unlock(surface, NULL);
11059 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
11061 else
11062 ok(!locked_desc.lpSurface, "Got unexpected lpSurface %p.\n", locked_desc.lpSurface);
11065 hr = IDirectDrawSurface7_Lock(surface, NULL, &locked_desc, DDLOCK_WAIT, NULL);
11066 ok(SUCCEEDED(hr), "Lock(rect = NULL) failed, hr %#x, type %s.\n",
11067 hr, resources[r].name);
11068 hr = IDirectDrawSurface7_Lock(surface, NULL, &locked_desc, DDLOCK_WAIT, NULL);
11069 ok(hr == DDERR_SURFACEBUSY, "Double lock(rect = NULL) returned %#x, type %s.\n",
11070 hr, resources[r].name);
11071 hr = IDirectDrawSurface7_Unlock(surface, NULL);
11072 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
11074 hr = IDirectDrawSurface7_Lock(surface, &valid[0], &locked_desc, DDLOCK_WAIT, NULL);
11075 ok(SUCCEEDED(hr), "Lock(rect = %s) failed (%#x).\n", wine_dbgstr_rect(&valid[0]), hr);
11076 hr = IDirectDrawSurface7_Lock(surface, &valid[0], &locked_desc, DDLOCK_WAIT, NULL);
11077 ok(hr == DDERR_SURFACEBUSY, "Double lock(rect = %s) failed (%#x).\n",
11078 wine_dbgstr_rect(&valid[0]), hr);
11080 /* Locking a different rectangle returns DD_OK, but it seems to break the surface.
11081 * Afterwards unlocking the surface fails(NULL rectangle or both locked rectangles) */
11083 hr = IDirectDrawSurface7_Unlock(surface, NULL);
11084 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
11086 IDirectDrawSurface7_Release(surface);
11089 done:
11090 IDirectDraw7_Release(ddraw);
11091 DestroyWindow(window);
11094 static void test_yv12_overlay(void)
11096 IDirectDrawSurface7 *src_surface, *dst_surface;
11097 RECT rect = {13, 17, 14, 18};
11098 unsigned int offset, y;
11099 DDSURFACEDESC2 desc;
11100 unsigned char *base;
11101 IDirectDraw7 *ddraw;
11102 HWND window;
11103 HRESULT hr;
11105 window = create_window();
11106 ddraw = create_ddraw();
11107 ok(!!ddraw, "Failed to create a ddraw object.\n");
11108 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
11109 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
11111 if (!(src_surface = create_overlay(ddraw, 256, 256, MAKEFOURCC('Y','V','1','2'))))
11113 skip("Failed to create a YV12 overlay, skipping test.\n");
11114 goto done;
11117 memset(&desc, 0, sizeof(desc));
11118 desc.dwSize = sizeof(desc);
11119 hr = IDirectDrawSurface7_Lock(src_surface, NULL, &desc, DDLOCK_WAIT, NULL);
11120 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
11122 ok(desc.dwFlags == (DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_PITCH),
11123 "Got unexpected flags %#x.\n", desc.dwFlags);
11124 ok(desc.ddsCaps.dwCaps == (DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM | DDSCAPS_HWCODEC)
11125 || desc.ddsCaps.dwCaps == (DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM),
11126 "Got unexpected caps %#x.\n", desc.ddsCaps.dwCaps);
11127 ok(desc.dwWidth == 256, "Got unexpected width %u.\n", desc.dwWidth);
11128 ok(desc.dwHeight == 256, "Got unexpected height %u.\n", desc.dwHeight);
11129 /* The overlay pitch seems to have 256 byte alignment. */
11130 ok(!(U1(desc).lPitch & 0xff), "Got unexpected pitch %u.\n", U1(desc).lPitch);
11132 /* Fill the surface with some data for the blit test. */
11133 base = desc.lpSurface;
11134 /* Luminance */
11135 for (y = 0; y < desc.dwHeight; ++y)
11137 memset(base + U1(desc).lPitch * y, 0x10, desc.dwWidth);
11139 /* V */
11140 for (; y < desc.dwHeight + desc.dwHeight / 4; ++y)
11142 memset(base + U1(desc).lPitch * y, 0x20, desc.dwWidth);
11144 /* U */
11145 for (; y < desc.dwHeight + desc.dwHeight / 2; ++y)
11147 memset(base + U1(desc).lPitch * y, 0x30, desc.dwWidth);
11150 hr = IDirectDrawSurface7_Unlock(src_surface, NULL);
11151 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
11153 /* YV12 uses 2x2 blocks with 6 bytes per block (4*Y, 1*U, 1*V). Unlike
11154 * other block-based formats like DXT the entire Y channel is stored in
11155 * one big chunk of memory, followed by the chroma channels. So partial
11156 * locks do not really make sense. Show that they are allowed nevertheless
11157 * and the offset points into the luminance data. */
11158 hr = IDirectDrawSurface7_Lock(src_surface, &rect, &desc, DDLOCK_WAIT, NULL);
11159 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
11160 offset = ((const unsigned char *)desc.lpSurface - base);
11161 ok(offset == rect.top * U1(desc).lPitch + rect.left, "Got unexpected offset %u, expected %u.\n",
11162 offset, rect.top * U1(desc).lPitch + rect.left);
11163 hr = IDirectDrawSurface7_Unlock(src_surface, NULL);
11164 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
11166 if (!(dst_surface = create_overlay(ddraw, 256, 256, MAKEFOURCC('Y','V','1','2'))))
11168 /* Windows XP with a Radeon X1600 GPU refuses to create a second
11169 * overlay surface, DDERR_NOOVERLAYHW, making the blit tests moot. */
11170 skip("Failed to create a second YV12 surface, skipping blit test.\n");
11171 IDirectDrawSurface7_Release(src_surface);
11172 goto done;
11175 hr = IDirectDrawSurface7_Blt(dst_surface, NULL, src_surface, NULL, DDBLT_WAIT, NULL);
11176 /* VMware rejects YV12 blits. This behavior has not been seen on real
11177 * hardware yet, so mark it broken. */
11178 ok(SUCCEEDED(hr) || broken(hr == E_NOTIMPL), "Failed to blit, hr %#x.\n", hr);
11180 if (SUCCEEDED(hr))
11182 memset(&desc, 0, sizeof(desc));
11183 desc.dwSize = sizeof(desc);
11184 hr = IDirectDrawSurface7_Lock(dst_surface, NULL, &desc, DDLOCK_WAIT, NULL);
11185 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
11187 base = desc.lpSurface;
11188 ok(base[0] == 0x10, "Got unexpected Y data 0x%02x.\n", base[0]);
11189 base += desc.dwHeight * U1(desc).lPitch;
11190 todo_wine ok(base[0] == 0x20, "Got unexpected V data 0x%02x.\n", base[0]);
11191 base += desc.dwHeight / 4 * U1(desc).lPitch;
11192 todo_wine ok(base[0] == 0x30, "Got unexpected U data 0x%02x.\n", base[0]);
11194 hr = IDirectDrawSurface7_Unlock(dst_surface, NULL);
11195 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
11198 IDirectDrawSurface7_Release(dst_surface);
11199 IDirectDrawSurface7_Release(src_surface);
11200 done:
11201 IDirectDraw7_Release(ddraw);
11202 DestroyWindow(window);
11205 static BOOL dwm_enabled(void)
11207 BOOL ret = FALSE;
11209 if (!strcmp(winetest_platform, "wine"))
11210 return FALSE;
11211 if (!pDwmIsCompositionEnabled)
11212 return FALSE;
11213 if (FAILED(pDwmIsCompositionEnabled(&ret)))
11214 return FALSE;
11215 return ret;
11218 static void test_offscreen_overlay(void)
11220 IDirectDrawSurface7 *overlay, *offscreen, *primary;
11221 DDSURFACEDESC2 surface_desc;
11222 IDirectDraw7 *ddraw;
11223 HWND window;
11224 HRESULT hr;
11225 HDC dc;
11227 window = create_window();
11228 ddraw = create_ddraw();
11229 ok(!!ddraw, "Failed to create a ddraw object.\n");
11230 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
11231 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
11233 if (!(overlay = create_overlay(ddraw, 64, 64, MAKEFOURCC('U','Y','V','Y'))))
11235 skip("Failed to create a UYVY overlay, skipping test.\n");
11236 goto done;
11239 memset(&surface_desc, 0, sizeof(surface_desc));
11240 surface_desc.dwSize = sizeof(surface_desc);
11241 surface_desc.dwFlags = DDSD_CAPS;
11242 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
11243 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &primary, NULL);
11244 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
11246 /* On Windows 7, and probably Vista, UpdateOverlay() will return
11247 * DDERR_OUTOFCAPS if the dwm is active. Calling GetDC() on the primary
11248 * surface prevents this by disabling the dwm. */
11249 hr = IDirectDrawSurface7_GetDC(primary, &dc);
11250 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
11251 hr = IDirectDrawSurface7_ReleaseDC(primary, dc);
11252 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
11254 /* Try to overlay a NULL surface. */
11255 hr = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, NULL, NULL, DDOVER_SHOW, NULL);
11256 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
11257 hr = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, NULL, NULL, DDOVER_HIDE, NULL);
11258 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
11260 /* Try to overlay an offscreen surface. */
11261 memset(&surface_desc, 0, sizeof(surface_desc));
11262 surface_desc.dwSize = sizeof(surface_desc);
11263 surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
11264 surface_desc.dwWidth = 64;
11265 surface_desc.dwHeight = 64;
11266 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
11267 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
11268 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
11269 U4(surface_desc).ddpfPixelFormat.dwFourCC = 0;
11270 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 16;
11271 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0xf800;
11272 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x07e0;
11273 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x001f;
11274 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &offscreen, NULL);
11275 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
11277 hr = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, offscreen, NULL, DDOVER_SHOW, NULL);
11278 ok(SUCCEEDED(hr) || broken(hr == DDERR_OUTOFCAPS && dwm_enabled())
11279 || broken(hr == E_NOTIMPL && ddraw_is_vmware(ddraw)),
11280 "Failed to update overlay, hr %#x.\n", hr);
11282 /* Try to overlay the primary with a non-overlay surface. */
11283 hr = IDirectDrawSurface7_UpdateOverlay(offscreen, NULL, primary, NULL, DDOVER_SHOW, NULL);
11284 ok(hr == DDERR_NOTAOVERLAYSURFACE, "Got unexpected hr %#x.\n", hr);
11285 hr = IDirectDrawSurface7_UpdateOverlay(offscreen, NULL, primary, NULL, DDOVER_HIDE, NULL);
11286 ok(hr == DDERR_NOTAOVERLAYSURFACE, "Got unexpected hr %#x.\n", hr);
11288 IDirectDrawSurface7_Release(offscreen);
11289 IDirectDrawSurface7_Release(primary);
11290 IDirectDrawSurface7_Release(overlay);
11291 done:
11292 IDirectDraw7_Release(ddraw);
11293 DestroyWindow(window);
11296 static void test_overlay_rect(void)
11298 IDirectDrawSurface7 *overlay, *primary = NULL;
11299 DDSURFACEDESC2 surface_desc;
11300 RECT rect = {0, 0, 64, 64};
11301 IDirectDraw7 *ddraw;
11302 LONG pos_x, pos_y;
11303 HRESULT hr, hr2;
11304 HWND window;
11305 HDC dc;
11307 window = create_window();
11308 ddraw = create_ddraw();
11309 ok(!!ddraw, "Failed to create a ddraw object.\n");
11310 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
11311 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
11313 if (!(overlay = create_overlay(ddraw, 64, 64, MAKEFOURCC('U','Y','V','Y'))))
11315 skip("Failed to create a UYVY overlay, skipping test.\n");
11316 goto done;
11319 memset(&surface_desc, 0, sizeof(surface_desc));
11320 surface_desc.dwSize = sizeof(surface_desc);
11321 surface_desc.dwFlags = DDSD_CAPS;
11322 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
11323 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &primary, NULL);
11324 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
11326 /* On Windows 7, and probably Vista, UpdateOverlay() will return
11327 * DDERR_OUTOFCAPS if the dwm is active. Calling GetDC() on the primary
11328 * surface prevents this by disabling the dwm. */
11329 hr = IDirectDrawSurface7_GetDC(primary, &dc);
11330 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
11331 hr = IDirectDrawSurface7_ReleaseDC(primary, dc);
11332 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
11334 /* On Windows 8 and newer DWM can't be turned off, making overlays unusable. */
11335 if (dwm_enabled())
11337 win_skip("Cannot disable DWM, skipping overlay test.\n");
11338 goto done;
11341 /* The dx sdk sort of implies that rect must be set when DDOVER_SHOW is
11342 * used. This is not true in Windows Vista and earlier, but changed in
11343 * Windows 7. */
11344 hr = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, primary, &rect, DDOVER_SHOW, NULL);
11345 ok(SUCCEEDED(hr), "Failed to update overlay, hr %#x.\n", hr);
11346 hr = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, primary, NULL, DDOVER_HIDE, NULL);
11347 ok(SUCCEEDED(hr), "Failed to update overlay, hr %#x.\n", hr);
11348 hr = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, primary, NULL, DDOVER_SHOW, NULL);
11349 ok(hr == DD_OK || hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
11351 /* Show that the overlay position is the (top, left) coordinate of the
11352 * destination rectangle. */
11353 OffsetRect(&rect, 32, 16);
11354 hr = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, primary, &rect, DDOVER_SHOW, NULL);
11355 ok(SUCCEEDED(hr), "Failed to update overlay, hr %#x.\n", hr);
11356 pos_x = -1; pos_y = -1;
11357 hr = IDirectDrawSurface7_GetOverlayPosition(overlay, &pos_x, &pos_y);
11358 ok(SUCCEEDED(hr), "Failed to get overlay position, hr %#x.\n", hr);
11359 ok(pos_x == rect.left, "Got unexpected pos_x %d, expected %d.\n", pos_x, rect.left);
11360 ok(pos_y == rect.top, "Got unexpected pos_y %d, expected %d.\n", pos_y, rect.top);
11362 /* Passing a NULL dest rect sets the position to 0/0. Visually it can be
11363 * seen that the overlay overlays the whole primary(==screen). */
11364 hr2 = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, primary, NULL, 0, NULL);
11365 ok(hr2 == DD_OK || hr2 == DDERR_INVALIDPARAMS || hr2 == DDERR_OUTOFCAPS, "Got unexpected hr %#x.\n", hr2);
11366 hr = IDirectDrawSurface7_GetOverlayPosition(overlay, &pos_x, &pos_y);
11367 ok(SUCCEEDED(hr), "Failed to get overlay position, hr %#x.\n", hr);
11368 if (SUCCEEDED(hr2))
11370 ok(!pos_x, "Got unexpected pos_x %d.\n", pos_x);
11371 ok(!pos_y, "Got unexpected pos_y %d.\n", pos_y);
11373 else
11375 ok(pos_x == 32, "Got unexpected pos_x %d.\n", pos_x);
11376 ok(pos_y == 16, "Got unexpected pos_y %d.\n", pos_y);
11379 /* The position cannot be retrieved when the overlay is not shown. */
11380 hr = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, primary, &rect, DDOVER_HIDE, NULL);
11381 ok(SUCCEEDED(hr), "Failed to update overlay, hr %#x.\n", hr);
11382 pos_x = -1; pos_y = -1;
11383 hr = IDirectDrawSurface7_GetOverlayPosition(overlay, &pos_x, &pos_y);
11384 ok(hr == DDERR_OVERLAYNOTVISIBLE, "Got unexpected hr %#x.\n", hr);
11385 ok(!pos_x, "Got unexpected pos_x %d.\n", pos_x);
11386 ok(!pos_y, "Got unexpected pos_y %d.\n", pos_y);
11388 IDirectDrawSurface7_Release(overlay);
11389 done:
11390 if (primary)
11391 IDirectDrawSurface7_Release(primary);
11392 IDirectDraw7_Release(ddraw);
11393 DestroyWindow(window);
11396 static void test_blt(void)
11398 IDirectDrawSurface7 *surface, *rt;
11399 DDSURFACEDESC2 surface_desc;
11400 IDirect3DDevice7 *device;
11401 IDirectDraw7 *ddraw;
11402 IDirect3D7 *d3d;
11403 unsigned int i;
11404 ULONG refcount;
11405 HWND window;
11406 HRESULT hr;
11408 static struct
11410 RECT src_rect;
11411 RECT dst_rect;
11412 HRESULT hr;
11414 test_data[] =
11416 {{160, 0, 640, 480}, { 0, 0, 480, 480}, DD_OK}, /* Overlapped blit. */
11417 {{160, 480, 640, 0}, { 0, 0, 480, 480}, DDERR_INVALIDRECT}, /* Overlapped blit, flipped source. */
11418 {{640, 0, 160, 480}, { 0, 0, 480, 480}, DDERR_INVALIDRECT}, /* Overlapped blit, mirrored source. */
11419 {{160, 0, 480, 480}, { 0, 0, 480, 480}, DD_OK}, /* Overlapped blit, stretched x. */
11420 {{160, 160, 640, 480}, { 0, 0, 480, 480}, DD_OK}, /* Overlapped blit, stretched y. */
11421 {{ 0, 0, 640, 480}, { 0, 0, 640, 480}, DD_OK}, /* Full surface blit. */
11422 {{ 0, 0, 640, 480}, { 0, 480, 640, 0}, DDERR_INVALIDRECT}, /* Full surface, flipped destination. */
11423 {{ 0, 0, 640, 480}, {640, 0, 0, 480}, DDERR_INVALIDRECT}, /* Full surface, mirrored destination. */
11424 {{ 0, 480, 640, 0}, { 0, 0, 640, 480}, DDERR_INVALIDRECT}, /* Full surface, flipped source. */
11425 {{640, 0, 0, 480}, { 0, 0, 640, 480}, DDERR_INVALIDRECT}, /* Full surface, mirrored source. */
11428 window = create_window();
11429 if (!(device = create_device(window, DDSCL_NORMAL)))
11431 skip("Failed to create a 3D device, skipping test.\n");
11432 DestroyWindow(window);
11433 return;
11436 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
11437 ok(SUCCEEDED(hr), "Failed to get Direct3D7 interface, hr %#x.\n", hr);
11438 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
11439 ok(SUCCEEDED(hr), "Failed to get DirectDraw7 interface, hr %#x.\n", hr);
11440 IDirect3D7_Release(d3d);
11441 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
11442 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
11444 memset(&surface_desc, 0, sizeof(surface_desc));
11445 surface_desc.dwSize = sizeof(surface_desc);
11446 surface_desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
11447 surface_desc.dwWidth = 640;
11448 surface_desc.dwHeight = 480;
11449 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
11450 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
11451 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
11453 hr = IDirectDrawSurface7_Blt(surface, NULL, surface, NULL, 0, NULL);
11454 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
11456 hr = IDirectDrawSurface7_Blt(surface, NULL, rt, NULL, 0, NULL);
11457 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
11459 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
11461 hr = IDirectDrawSurface7_Blt(surface, &test_data[i].dst_rect,
11462 surface, &test_data[i].src_rect, DDBLT_WAIT, NULL);
11463 ok(hr == test_data[i].hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, test_data[i].hr);
11465 hr = IDirectDrawSurface7_Blt(surface, &test_data[i].dst_rect,
11466 rt, &test_data[i].src_rect, DDBLT_WAIT, NULL);
11467 ok(hr == test_data[i].hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, test_data[i].hr);
11469 hr = IDirectDrawSurface7_Blt(surface, &test_data[i].dst_rect,
11470 NULL, &test_data[i].src_rect, DDBLT_WAIT, NULL);
11471 ok(hr == DDERR_INVALIDPARAMS, "Test %u: Got unexpected hr %#x.\n", i, hr);
11473 hr = IDirectDrawSurface7_Blt(surface, &test_data[i].dst_rect, NULL, NULL, DDBLT_WAIT, NULL);
11474 ok(hr == DDERR_INVALIDPARAMS, "Test %u: Got unexpected hr %#x.\n", i, hr);
11477 IDirectDrawSurface7_Release(surface);
11478 IDirectDrawSurface7_Release(rt);
11479 IDirectDraw7_Release(ddraw);
11480 refcount = IDirect3DDevice7_Release(device);
11481 ok(!refcount, "Device has %u references left.\n", refcount);
11482 DestroyWindow(window);
11485 static void test_blt_z_alpha(void)
11487 DWORD blt_flags[] =
11489 /* 0 */
11490 DDBLT_ALPHADEST,
11491 DDBLT_ALPHADESTCONSTOVERRIDE,
11492 DDBLT_ALPHADESTNEG,
11493 DDBLT_ALPHADESTSURFACEOVERRIDE,
11494 DDBLT_ALPHAEDGEBLEND,
11495 /* 5 */
11496 DDBLT_ALPHASRC,
11497 DDBLT_ALPHASRCCONSTOVERRIDE,
11498 DDBLT_ALPHASRCNEG,
11499 DDBLT_ALPHASRCSURFACEOVERRIDE,
11500 DDBLT_ZBUFFER,
11501 /* 10 */
11502 DDBLT_ZBUFFERDESTCONSTOVERRIDE,
11503 DDBLT_ZBUFFERDESTOVERRIDE,
11504 DDBLT_ZBUFFERSRCCONSTOVERRIDE,
11505 DDBLT_ZBUFFERSRCOVERRIDE,
11507 IDirectDrawSurface7 *src_surface, *dst_surface;
11508 DDSURFACEDESC2 surface_desc;
11509 IDirectDraw7 *ddraw;
11510 DDPIXELFORMAT pf;
11511 ULONG refcount;
11512 unsigned int i;
11513 D3DCOLOR color;
11514 HWND window;
11515 HRESULT hr;
11516 DDBLTFX fx;
11518 window = create_window();
11519 ddraw = create_ddraw();
11520 ok(!!ddraw, "Failed to create a ddraw object.\n");
11521 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
11522 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
11524 memset(&pf, 0, sizeof(pf));
11525 pf.dwSize = sizeof(pf);
11526 pf.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
11527 U1(pf).dwRGBBitCount = 32;
11528 U2(pf).dwRBitMask = 0x00ff0000;
11529 U3(pf).dwGBitMask = 0x0000ff00;
11530 U4(pf).dwBBitMask = 0x000000ff;
11531 U5(pf).dwRGBAlphaBitMask = 0xff000000;
11533 memset(&surface_desc, 0, sizeof(surface_desc));
11534 surface_desc.dwSize = sizeof(surface_desc);
11535 surface_desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_PIXELFORMAT;
11536 surface_desc.dwWidth = 64;
11537 surface_desc.dwHeight = 64;
11538 U4(surface_desc).ddpfPixelFormat = pf;
11539 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
11541 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &src_surface, NULL);
11542 ok(SUCCEEDED(hr), "Failed to create source surface, hr %#x.\n", hr);
11543 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &dst_surface, NULL);
11544 ok(SUCCEEDED(hr), "Failed to create destination surface, hr %#x.\n", hr);
11546 memset(&fx, 0, sizeof(fx));
11547 fx.dwSize = sizeof(fx);
11548 fx.dwZBufferOpCode = D3DCMP_NEVER;
11549 fx.dwZDestConstBitDepth = 32;
11550 U1(fx).dwZDestConst = 0x11111111;
11551 fx.dwZSrcConstBitDepth = 32;
11552 U2(fx).dwZSrcConst = 0xeeeeeeee;
11553 fx.dwAlphaEdgeBlendBitDepth = 8;
11554 fx.dwAlphaEdgeBlend = 0x7f;
11555 fx.dwAlphaDestConstBitDepth = 8;
11556 U3(fx).dwAlphaDestConst = 0xdd;
11557 fx.dwAlphaSrcConstBitDepth = 8;
11558 U4(fx).dwAlphaSrcConst = 0x22;
11560 for (i = 0; i < ARRAY_SIZE(blt_flags); ++i)
11562 fx.dwFillColor = 0x3300ff00;
11563 hr = IDirectDrawSurface7_Blt(src_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
11564 ok(SUCCEEDED(hr), "Test %u: Got unexpected hr %#x.\n", i, hr);
11566 fx.dwFillColor = 0xccff0000;
11567 hr = IDirectDrawSurface7_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
11568 ok(SUCCEEDED(hr), "Test %u: Got unexpected hr %#x.\n", i, hr);
11570 hr = IDirectDrawSurface7_Blt(dst_surface, NULL, src_surface, NULL, blt_flags[i] | DDBLT_WAIT, &fx);
11571 ok(SUCCEEDED(hr), "Test %u: Got unexpected hr %#x.\n", i, hr);
11573 color = get_surface_color(dst_surface, 32, 32);
11574 ok(compare_color(color, 0x0000ff00, 0), "Test %u: Got unexpected color 0x%08x.\n", i, color);
11577 IDirectDrawSurface7_Release(dst_surface);
11578 IDirectDrawSurface7_Release(src_surface);
11579 refcount = IDirectDraw7_Release(ddraw);
11580 ok(!refcount, "DirectDraw has %u references left.\n", refcount);
11581 DestroyWindow(window);
11584 static void test_color_clamping(void)
11586 static D3DMATRIX mat =
11588 1.0f, 0.0f, 0.0f, 0.0f,
11589 0.0f, 1.0f, 0.0f, 0.0f,
11590 0.0f, 0.0f, 1.0f, 0.0f,
11591 0.0f, 0.0f, 0.0f, 1.0f,
11593 static struct vec3 quad[] =
11595 {-1.0f, -1.0f, 0.1f},
11596 {-1.0f, 1.0f, 0.1f},
11597 { 1.0f, -1.0f, 0.1f},
11598 { 1.0f, 1.0f, 0.1f},
11600 IDirect3DDevice7 *device;
11601 IDirectDrawSurface7 *rt;
11602 ULONG refcount;
11603 D3DCOLOR color;
11604 HWND window;
11605 HRESULT hr;
11607 window = create_window();
11608 if (!(device = create_device(window, DDSCL_NORMAL)))
11610 skip("Failed to create a 3D device, skipping test.\n");
11611 DestroyWindow(window);
11612 return;
11615 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
11616 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
11618 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &mat);
11619 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#x.\n", hr);
11620 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_VIEW, &mat);
11621 ok(SUCCEEDED(hr), "Failed to set view transform, hr %#x.\n", hr);
11622 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &mat);
11623 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
11624 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CLIPPING, FALSE);
11625 ok(SUCCEEDED(hr), "Failed to disable clipping, hr %#x.\n", hr);
11626 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, FALSE);
11627 ok(SUCCEEDED(hr), "Failed to disable Z test, hr %#x.\n", hr);
11628 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, FALSE);
11629 ok(SUCCEEDED(hr), "Failed to disable fog, hr %#x.\n", hr);
11630 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_STENCILENABLE, FALSE);
11631 ok(SUCCEEDED(hr), "Failed to disable stencil test, hr %#x.\n", hr);
11632 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CULLMODE, D3DCULL_NONE);
11633 ok(SUCCEEDED(hr), "Failed to disable culling, hr %#x.\n", hr);
11634 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
11635 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
11637 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_TEXTUREFACTOR, 0xff404040);
11638 ok(SUCCEEDED(hr), "Failed to set texture factor, hr %#x.\n", hr);
11639 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_ADD);
11640 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
11641 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);
11642 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
11643 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLORARG2, D3DTA_SPECULAR);
11644 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
11645 hr = IDirect3DDevice7_SetTextureStageState(device, 1, D3DTSS_COLOROP, D3DTOP_MODULATE);
11646 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
11647 hr = IDirect3DDevice7_SetTextureStageState(device, 1, D3DTSS_COLORARG1, D3DTA_TFACTOR);
11648 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
11649 hr = IDirect3DDevice7_SetTextureStageState(device, 1, D3DTSS_COLORARG2, D3DTA_CURRENT);
11650 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
11652 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff00ff00, 0.0f, 0);
11653 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
11655 hr = IDirect3DDevice7_BeginScene(device);
11656 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
11658 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, quad, 4, 0);
11659 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
11661 hr = IDirect3DDevice7_EndScene(device);
11662 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
11664 color = get_surface_color(rt, 320, 240);
11665 ok(compare_color(color, 0x00404040, 1), "Got unexpected color 0x%08x.\n", color);
11667 IDirectDrawSurface7_Release(rt);
11668 refcount = IDirect3DDevice7_Release(device);
11669 ok(!refcount, "Device has %u references left.\n", refcount);
11670 DestroyWindow(window);
11673 static void test_getdc(void)
11675 DDSCAPS2 caps = {DDSCAPS_COMPLEX, DDSCAPS2_CUBEMAP_NEGATIVEZ, 0, {0}};
11676 IDirectDrawSurface7 *surface, *surface2, *tmp;
11677 DDSURFACEDESC2 surface_desc, map_desc;
11678 IDirectDraw7 *ddraw;
11679 unsigned int i;
11680 HWND window;
11681 HDC dc, dc2;
11682 HRESULT hr;
11684 static const struct
11686 const char *name;
11687 DDPIXELFORMAT format;
11688 BOOL getdc_supported;
11689 HRESULT alt_result;
11691 test_data[] =
11693 {"D3DFMT_A8R8G8B8", {sizeof(test_data->format), DDPF_RGB | DDPF_ALPHAPIXELS, 0, {32},
11694 {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}}, TRUE},
11695 {"D3DFMT_X8R8G8B8", {sizeof(test_data->format), DDPF_RGB, 0, {32},
11696 {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0x00000000}}, TRUE},
11697 {"D3DFMT_R5G6B5", {sizeof(test_data->format), DDPF_RGB, 0, {16},
11698 {0x0000f800}, {0x000007e0}, {0x0000001f}, {0x00000000}}, TRUE},
11699 {"D3DFMT_X1R5G5B5", {sizeof(test_data->format), DDPF_RGB, 0, {16},
11700 {0x00007c00}, {0x000003e0}, {0x0000001f}, {0x00000000}}, TRUE},
11701 {"D3DFMT_A1R5G5B5", {sizeof(test_data->format), DDPF_RGB | DDPF_ALPHAPIXELS, 0, {16},
11702 {0x00007c00}, {0x000003e0}, {0x0000001f}, {0x00008000}}, TRUE},
11703 {"D3DFMT_A4R4G4B4", {sizeof(test_data->format), DDPF_RGB | DDPF_ALPHAPIXELS, 0, {16},
11704 {0x00000f00}, {0x000000f0}, {0x0000000f}, {0x0000f000}}, TRUE, DDERR_CANTCREATEDC /* Vista+ */},
11705 {"D3DFMT_X4R4G4B4", {sizeof(test_data->format), DDPF_RGB, 0, {16},
11706 {0x00000f00}, {0x000000f0}, {0x0000000f}, {0x00000000}}, TRUE, DDERR_CANTCREATEDC /* Vista+ */},
11707 {"D3DFMT_A2R10G10B10", {sizeof(test_data->format), DDPF_RGB | DDPF_ALPHAPIXELS, 0, {32},
11708 {0xc0000000}, {0x3ff00000}, {0x000ffc00}, {0x000003ff}}, TRUE},
11709 {"D3DFMT_A8B8G8R8", {sizeof(test_data->format), DDPF_RGB | DDPF_ALPHAPIXELS, 0, {32},
11710 {0x000000ff}, {0x0000ff00}, {0x00ff0000}, {0xff000000}}, TRUE, DDERR_CANTCREATEDC /* Vista+ */},
11711 {"D3DFMT_X8B8G8R8", {sizeof(test_data->format), DDPF_RGB, 0, {32},
11712 {0x000000ff}, {0x0000ff00}, {0x00ff0000}, {0x00000000}}, TRUE, DDERR_CANTCREATEDC /* Vista+ */},
11713 {"D3DFMT_R3G3B2", {sizeof(test_data->format), DDPF_RGB, 0, {8},
11714 {0x000000e0}, {0x0000001c}, {0x00000003}, {0x00000000}}, FALSE},
11715 /* GetDC() on a P8 surface fails unless the display mode is 8 bpp.
11716 * This is not implemented in wine yet, so disable the test for now.
11717 * Succeeding P8 GetDC() calls are tested in the ddraw:visual test.
11718 {"D3DFMT_P8", {sizeof(test_data->format), DDPF_PALETTEINDEXED8 | DDPF_RGB, 0, {8 },
11719 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
11721 {"D3DFMT_L8", {sizeof(test_data->format), DDPF_LUMINANCE, 0, {8},
11722 {0x000000ff}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
11723 {"D3DFMT_A8L8", {sizeof(test_data->format), DDPF_ALPHAPIXELS | DDPF_LUMINANCE, 0, {16},
11724 {0x000000ff}, {0x00000000}, {0x00000000}, {0x0000ff00}}, FALSE},
11725 {"D3DFMT_DXT1", {sizeof(test_data->format), DDPF_FOURCC, MAKEFOURCC('D','X','T','1'), {0},
11726 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
11727 {"D3DFMT_DXT2", {sizeof(test_data->format), DDPF_FOURCC, MAKEFOURCC('D','X','T','2'), {0},
11728 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
11729 {"D3DFMT_DXT3", {sizeof(test_data->format), DDPF_FOURCC, MAKEFOURCC('D','X','T','3'), {0},
11730 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
11731 {"D3DFMT_DXT4", {sizeof(test_data->format), DDPF_FOURCC, MAKEFOURCC('D','X','T','4'), {0},
11732 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
11733 {"D3DFMT_DXT5", {sizeof(test_data->format), DDPF_FOURCC, MAKEFOURCC('D','X','T','5'), {0},
11734 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
11737 window = create_window();
11738 ddraw = create_ddraw();
11739 ok(!!ddraw, "Failed to create a ddraw object.\n");
11740 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
11741 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
11743 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
11745 memset(&surface_desc, 0, sizeof(surface_desc));
11746 surface_desc.dwSize = sizeof(surface_desc);
11747 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
11748 surface_desc.dwWidth = 64;
11749 surface_desc.dwHeight = 64;
11750 U4(surface_desc).ddpfPixelFormat = test_data[i].format;
11751 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
11753 if (FAILED(IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL)))
11755 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
11756 surface_desc.ddsCaps.dwCaps2 = DDSCAPS2_TEXTUREMANAGE;
11757 if (FAILED(hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL)))
11759 skip("Failed to create surface for format %s (hr %#x), skipping tests.\n", test_data[i].name, hr);
11760 continue;
11764 dc = (void *)0x1234;
11765 hr = IDirectDrawSurface7_GetDC(surface, &dc);
11766 if (test_data[i].getdc_supported)
11767 ok(SUCCEEDED(hr) || broken(hr == test_data[i].alt_result),
11768 "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11769 else
11770 ok(FAILED(hr), "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11772 if (SUCCEEDED(hr))
11774 unsigned int width_bytes;
11775 DIBSECTION dib;
11776 HBITMAP bitmap;
11777 DWORD type;
11778 int size;
11780 type = GetObjectType(dc);
11781 ok(type == OBJ_MEMDC, "Got unexpected object type %#x for format %s.\n", type, test_data[i].name);
11782 bitmap = GetCurrentObject(dc, OBJ_BITMAP);
11783 type = GetObjectType(bitmap);
11784 ok(type == OBJ_BITMAP, "Got unexpected object type %#x for format %s.\n", type, test_data[i].name);
11786 size = GetObjectA(bitmap, sizeof(dib), &dib);
11787 ok(size == sizeof(dib), "Got unexpected size %d for format %s.\n", size, test_data[i].name);
11788 ok(!dib.dsBm.bmType, "Got unexpected type %#x for format %s.\n",
11789 dib.dsBm.bmType, test_data[i].name);
11790 ok(dib.dsBm.bmWidth == surface_desc.dwWidth, "Got unexpected width %d for format %s.\n",
11791 dib.dsBm.bmWidth, test_data[i].name);
11792 ok(dib.dsBm.bmHeight == surface_desc.dwHeight, "Got unexpected height %d for format %s.\n",
11793 dib.dsBm.bmHeight, test_data[i].name);
11794 width_bytes = ((dib.dsBm.bmWidth * U1(test_data[i].format).dwRGBBitCount + 31) >> 3) & ~3;
11795 ok(dib.dsBm.bmWidthBytes == width_bytes, "Got unexpected width bytes %d for format %s.\n",
11796 dib.dsBm.bmWidthBytes, test_data[i].name);
11797 ok(dib.dsBm.bmPlanes == 1, "Got unexpected plane count %d for format %s.\n",
11798 dib.dsBm.bmPlanes, test_data[i].name);
11799 ok(dib.dsBm.bmBitsPixel == U1(test_data[i].format).dwRGBBitCount,
11800 "Got unexpected bit count %d for format %s.\n",
11801 dib.dsBm.bmBitsPixel, test_data[i].name);
11802 ok(!!dib.dsBm.bmBits, "Got unexpected bits %p for format %s.\n",
11803 dib.dsBm.bmBits, test_data[i].name);
11805 ok(dib.dsBmih.biSize == sizeof(dib.dsBmih), "Got unexpected size %u for format %s.\n",
11806 dib.dsBmih.biSize, test_data[i].name);
11807 ok(dib.dsBmih.biWidth == surface_desc.dwWidth, "Got unexpected width %d for format %s.\n",
11808 dib.dsBmih.biHeight, test_data[i].name);
11809 ok(dib.dsBmih.biHeight == surface_desc.dwHeight, "Got unexpected height %d for format %s.\n",
11810 dib.dsBmih.biHeight, test_data[i].name);
11811 ok(dib.dsBmih.biPlanes == 1, "Got unexpected plane count %u for format %s.\n",
11812 dib.dsBmih.biPlanes, test_data[i].name);
11813 ok(dib.dsBmih.biBitCount == U1(test_data[i].format).dwRGBBitCount,
11814 "Got unexpected bit count %u for format %s.\n",
11815 dib.dsBmih.biBitCount, test_data[i].name);
11816 ok(dib.dsBmih.biCompression == (U1(test_data[i].format).dwRGBBitCount == 16 ? BI_BITFIELDS : BI_RGB)
11817 || broken(U1(test_data[i].format).dwRGBBitCount == 32 && dib.dsBmih.biCompression == BI_BITFIELDS),
11818 "Got unexpected compression %#x for format %s.\n",
11819 dib.dsBmih.biCompression, test_data[i].name);
11820 ok(!dib.dsBmih.biSizeImage, "Got unexpected image size %u for format %s.\n",
11821 dib.dsBmih.biSizeImage, test_data[i].name);
11822 ok(!dib.dsBmih.biXPelsPerMeter, "Got unexpected horizontal resolution %d for format %s.\n",
11823 dib.dsBmih.biXPelsPerMeter, test_data[i].name);
11824 ok(!dib.dsBmih.biYPelsPerMeter, "Got unexpected vertical resolution %d for format %s.\n",
11825 dib.dsBmih.biYPelsPerMeter, test_data[i].name);
11826 ok(!dib.dsBmih.biClrUsed, "Got unexpected used colour count %u for format %s.\n",
11827 dib.dsBmih.biClrUsed, test_data[i].name);
11828 ok(!dib.dsBmih.biClrImportant, "Got unexpected important colour count %u for format %s.\n",
11829 dib.dsBmih.biClrImportant, test_data[i].name);
11831 if (dib.dsBmih.biCompression == BI_BITFIELDS)
11833 ok((dib.dsBitfields[0] == U2(test_data[i].format).dwRBitMask
11834 && dib.dsBitfields[1] == U3(test_data[i].format).dwGBitMask
11835 && dib.dsBitfields[2] == U4(test_data[i].format).dwBBitMask)
11836 || broken(!dib.dsBitfields[0] && !dib.dsBitfields[1] && !dib.dsBitfields[2]),
11837 "Got unexpected colour masks 0x%08x 0x%08x 0x%08x for format %s.\n",
11838 dib.dsBitfields[0], dib.dsBitfields[1], dib.dsBitfields[2], test_data[i].name);
11840 else
11842 ok(!dib.dsBitfields[0] && !dib.dsBitfields[1] && !dib.dsBitfields[2],
11843 "Got unexpected colour masks 0x%08x 0x%08x 0x%08x for format %s.\n",
11844 dib.dsBitfields[0], dib.dsBitfields[1], dib.dsBitfields[2], test_data[i].name);
11846 ok(!dib.dshSection, "Got unexpected section %p for format %s.\n", dib.dshSection, test_data[i].name);
11847 ok(!dib.dsOffset, "Got unexpected offset %u for format %s.\n", dib.dsOffset, test_data[i].name);
11849 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
11850 ok(hr == DD_OK, "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11852 else
11854 ok(!dc, "Got unexpected dc %p for format %s.\n", dc, test_data[i].name);
11857 IDirectDrawSurface7_Release(surface);
11859 if (FAILED(hr))
11860 continue;
11862 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
11863 surface_desc.ddsCaps.dwCaps2 = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES | DDSCAPS2_TEXTUREMANAGE;
11864 if (FAILED(hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL)))
11866 skip("Failed to create cube texture for format %s (hr %#x), skipping tests.\n", test_data[i].name, hr);
11867 continue;
11870 hr = IDirectDrawSurface7_GetAttachedSurface(surface, &caps, &surface2);
11871 ok(SUCCEEDED(hr), "Failed to get attached surface for format %s, hr %#x.\n", test_data[i].name, hr);
11872 hr = IDirectDrawSurface7_GetAttachedSurface(surface2, &caps, &tmp);
11873 ok(SUCCEEDED(hr), "Failed to get attached surface for format %s, hr %#x.\n", test_data[i].name, hr);
11874 IDirectDrawSurface7_Release(surface2);
11875 hr = IDirectDrawSurface7_GetAttachedSurface(tmp, &caps, &surface2);
11876 ok(SUCCEEDED(hr), "Failed to get attached surface for format %s, hr %#x.\n", test_data[i].name, hr);
11877 IDirectDrawSurface7_Release(tmp);
11879 hr = IDirectDrawSurface7_GetDC(surface, &dc);
11880 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11881 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
11882 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11883 hr = IDirectDrawSurface7_GetDC(surface2, &dc);
11884 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11885 hr = IDirectDrawSurface7_ReleaseDC(surface2, dc);
11886 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11888 hr = IDirectDrawSurface7_GetDC(surface, &dc);
11889 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11890 dc2 = (void *)0x1234;
11891 hr = IDirectDrawSurface7_GetDC(surface, &dc2);
11892 ok(hr == DDERR_DCALREADYCREATED, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11893 ok(dc2 == (void *)0x1234, "Got unexpected dc %p for format %s.\n", dc, test_data[i].name);
11894 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
11895 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11896 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
11897 ok(hr == DDERR_NODC, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11899 map_desc.dwSize = sizeof(map_desc);
11900 hr = IDirectDrawSurface7_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
11901 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
11902 hr = IDirectDrawSurface7_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
11903 ok(hr == DDERR_SURFACEBUSY, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11904 hr = IDirectDrawSurface7_Unlock(surface, NULL);
11905 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
11906 hr = IDirectDrawSurface7_Unlock(surface, NULL);
11907 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11909 hr = IDirectDrawSurface7_GetDC(surface, &dc);
11910 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11911 hr = IDirectDrawSurface7_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
11912 ok(hr == DDERR_SURFACEBUSY, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11913 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
11914 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11916 hr = IDirectDrawSurface7_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
11917 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
11918 hr = IDirectDrawSurface7_GetDC(surface, &dc);
11919 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11920 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
11921 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11922 hr = IDirectDrawSurface7_Unlock(surface, NULL);
11923 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
11925 hr = IDirectDrawSurface7_GetDC(surface, &dc);
11926 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11927 hr = IDirectDrawSurface7_GetDC(surface2, &dc2);
11928 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11929 hr = IDirectDrawSurface7_ReleaseDC(surface2, dc2);
11930 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11931 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
11932 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11934 hr = IDirectDrawSurface7_GetDC(surface2, &dc);
11935 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11936 hr = IDirectDrawSurface7_GetDC(surface, &dc2);
11937 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11938 hr = IDirectDrawSurface7_ReleaseDC(surface, dc2);
11939 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11940 hr = IDirectDrawSurface7_ReleaseDC(surface2, dc);
11941 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11943 hr = IDirectDrawSurface7_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
11944 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
11945 hr = IDirectDrawSurface7_Lock(surface2, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
11946 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
11947 hr = IDirectDrawSurface7_Unlock(surface2, NULL);
11948 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
11949 hr = IDirectDrawSurface7_Unlock(surface, NULL);
11950 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
11952 hr = IDirectDrawSurface7_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
11953 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
11954 hr = IDirectDrawSurface7_GetDC(surface, &dc);
11955 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11956 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
11957 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11958 hr = IDirectDrawSurface7_Unlock(surface, NULL);
11959 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
11961 hr = IDirectDrawSurface7_Lock(surface2, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
11962 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
11963 hr = IDirectDrawSurface7_GetDC(surface, &dc);
11964 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11965 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
11966 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11967 hr = IDirectDrawSurface7_Unlock(surface2, NULL);
11968 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
11970 hr = IDirectDrawSurface7_GetDC(surface, &dc);
11971 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11972 hr = IDirectDrawSurface7_Lock(surface2, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
11973 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
11974 hr = IDirectDrawSurface7_Unlock(surface2, NULL);
11975 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
11976 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
11977 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11979 hr = IDirectDrawSurface7_GetDC(surface2, &dc);
11980 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11981 hr = IDirectDrawSurface7_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
11982 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
11983 hr = IDirectDrawSurface7_Unlock(surface, NULL);
11984 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
11985 hr = IDirectDrawSurface7_ReleaseDC(surface2, dc);
11986 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11988 hr = IDirectDrawSurface7_Unlock(surface, NULL);
11989 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11990 hr = IDirectDrawSurface7_GetDC(surface2, &dc);
11991 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11992 hr = IDirectDrawSurface7_Unlock(surface, NULL);
11993 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11994 hr = IDirectDrawSurface7_ReleaseDC(surface2, dc);
11995 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11996 hr = IDirectDrawSurface7_Unlock(surface, NULL);
11997 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11999 hr = IDirectDrawSurface7_Unlock(surface2, NULL);
12000 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
12001 hr = IDirectDrawSurface7_GetDC(surface, &dc);
12002 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
12003 hr = IDirectDrawSurface7_Unlock(surface2, NULL);
12004 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
12005 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
12006 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
12007 hr = IDirectDrawSurface7_Unlock(surface2, NULL);
12008 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
12010 IDirectDrawSurface7_Release(surface2);
12011 IDirectDrawSurface7_Release(surface);
12014 IDirectDraw7_Release(ddraw);
12015 DestroyWindow(window);
12018 static void test_draw_primitive(void)
12020 static WORD indices[] = {0, 1, 2, 3};
12021 static struct vec3 quad[] =
12023 {-1.0f, -1.0f, 0.0f},
12024 {-1.0f, 1.0f, 0.0f},
12025 { 1.0f, -1.0f, 0.0f},
12026 { 1.0f, 1.0f, 0.0f},
12028 D3DDRAWPRIMITIVESTRIDEDDATA strided;
12029 D3DVERTEXBUFFERDESC vb_desc;
12030 IDirect3DVertexBuffer7 *vb;
12031 IDirect3DDevice7 *device;
12032 IDirect3D7 *d3d;
12033 ULONG refcount;
12034 HWND window;
12035 HRESULT hr;
12036 void *data;
12038 window = create_window();
12039 if (!(device = create_device(window, DDSCL_NORMAL)))
12041 skip("Failed to create a 3D device, skipping test.\n");
12042 DestroyWindow(window);
12043 return;
12046 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
12047 ok(SUCCEEDED(hr), "Failed to get D3D interface, hr %#x.\n", hr);
12049 memset(&vb_desc, 0, sizeof(vb_desc));
12050 vb_desc.dwSize = sizeof(vb_desc);
12051 vb_desc.dwFVF = D3DFVF_XYZ;
12052 vb_desc.dwNumVertices = 4;
12053 hr = IDirect3D7_CreateVertexBuffer(d3d, &vb_desc, &vb, 0);
12054 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
12056 IDirect3D7_Release(d3d);
12058 memset(&strided, 0, sizeof(strided));
12060 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, NULL, 0, NULL, 0, 0);
12061 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12062 hr = IDirect3DDevice7_DrawIndexedPrimitiveStrided(device,
12063 D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, &strided, 0, NULL, 0, 0);
12064 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12065 hr = IDirect3DDevice7_DrawIndexedPrimitiveVB(device, D3DPT_TRIANGLESTRIP, vb, 0, 0, NULL, 0, 0);
12066 todo_wine ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
12067 hr = IDirect3DDevice7_DrawIndexedPrimitiveVB(device, D3DPT_TRIANGLESTRIP, vb, 0, 0, NULL, 0, 0);
12068 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12069 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, NULL, 0, 0);
12070 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12071 hr = IDirect3DDevice7_DrawPrimitiveStrided(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, &strided, 0, 0);
12072 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12073 hr = IDirect3DDevice7_DrawPrimitiveVB(device, D3DPT_TRIANGLESTRIP, vb, 0, 0, 0);
12074 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12076 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, NULL, 0, indices, 4, 0);
12077 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12078 hr = IDirect3DDevice7_DrawIndexedPrimitiveStrided(device,
12079 D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, &strided, 0, indices, 4, 0);
12080 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12081 hr = IDirect3DDevice7_DrawIndexedPrimitiveVB(device, D3DPT_TRIANGLESTRIP, vb, 0, 0, indices, 4, 0);
12082 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12084 strided.position.lpvData = quad;
12085 strided.position.dwStride = sizeof(*quad);
12086 hr = IDirect3DVertexBuffer7_Lock(vb, 0, &data, NULL);
12087 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
12088 memcpy(data, quad, sizeof(quad));
12089 hr = IDirect3DVertexBuffer7_Unlock(vb);
12090 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
12092 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, quad, 4, NULL, 0, 0);
12093 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12094 hr = IDirect3DDevice7_DrawIndexedPrimitiveStrided(device,
12095 D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, &strided, 4, NULL, 0, 0);
12096 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12097 hr = IDirect3DDevice7_DrawIndexedPrimitiveVB(device, D3DPT_TRIANGLESTRIP, vb, 0, 4, NULL, 0, 0);
12098 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12099 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, quad, 4, 0);
12100 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12101 hr = IDirect3DDevice7_DrawPrimitiveStrided(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, &strided, 4, 0);
12102 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12103 hr = IDirect3DDevice7_DrawPrimitiveVB(device, D3DPT_TRIANGLESTRIP, vb, 0, 4, 0);
12104 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12106 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, quad, 4, indices, 4, 0);
12107 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12108 hr = IDirect3DDevice7_DrawIndexedPrimitiveStrided(device,
12109 D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, &strided, 4, indices, 4, 0);
12110 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12111 hr = IDirect3DDevice7_DrawIndexedPrimitiveVB(device, D3DPT_TRIANGLESTRIP, vb, 0, 4, indices, 4, 0);
12112 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12114 IDirect3DVertexBuffer7_Release(vb);
12115 refcount = IDirect3DDevice7_Release(device);
12116 ok(!refcount, "Device has %u references left.\n", refcount);
12117 DestroyWindow(window);
12120 static void test_edge_antialiasing_blending(void)
12122 IDirectDrawSurface7 *offscreen;
12123 DDSURFACEDESC2 surface_desc;
12124 D3DDEVICEDESC7 device_desc;
12125 IDirect3DDevice7 *device;
12126 IDirectDraw7 *ddraw;
12127 IDirect3D7 *d3d;
12128 ULONG refcount;
12129 D3DCOLOR color;
12130 HWND window;
12131 HRESULT hr;
12133 static D3DMATRIX mat =
12135 1.0f, 0.0f, 0.0f, 0.0f,
12136 0.0f, 1.0f, 0.0f, 0.0f,
12137 0.0f, 0.0f, 1.0f, 0.0f,
12138 0.0f, 0.0f, 0.0f, 1.0f,
12140 static struct
12142 struct vec3 position;
12143 DWORD diffuse;
12145 green_quad[] =
12147 {{-1.0f, -1.0f, 0.1f}, 0x7f00ff00},
12148 {{-1.0f, 1.0f, 0.1f}, 0x7f00ff00},
12149 {{ 1.0f, -1.0f, 0.1f}, 0x7f00ff00},
12150 {{ 1.0f, 1.0f, 0.1f}, 0x7f00ff00},
12152 static struct
12154 struct vec3 position;
12155 DWORD diffuse;
12157 red_quad[] =
12159 {{-1.0f, -1.0f, 0.1f}, 0xccff0000},
12160 {{-1.0f, 1.0f, 0.1f}, 0xccff0000},
12161 {{ 1.0f, -1.0f, 0.1f}, 0xccff0000},
12162 {{ 1.0f, 1.0f, 0.1f}, 0xccff0000},
12165 window = create_window();
12166 if (!(device = create_device(window, DDSCL_NORMAL)))
12168 skip("Failed to create a 3D device.\n");
12169 DestroyWindow(window);
12170 return;
12173 hr = IDirect3DDevice7_GetCaps(device, &device_desc);
12174 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
12175 trace("Line edge antialiasing support: %#x.\n",
12176 device_desc.dpcLineCaps.dwRasterCaps & D3DPRASTERCAPS_ANTIALIASEDGES);
12177 trace("Triangle edge antialiasing support: %#x.\n",
12178 device_desc.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_ANTIALIASEDGES);
12180 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
12181 ok(SUCCEEDED(hr), "Failed to get D3D interface, hr %#x.\n", hr);
12182 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
12183 ok(SUCCEEDED(hr), "Failed to get DirectDraw7 interface, hr %#x.\n", hr);
12184 IDirect3D7_Release(d3d);
12186 memset(&surface_desc, 0, sizeof(surface_desc));
12187 surface_desc.dwSize = sizeof(surface_desc);
12188 surface_desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_PIXELFORMAT;
12189 surface_desc.dwWidth = 640;
12190 surface_desc.dwHeight = 480;
12191 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_3DDEVICE;
12192 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
12193 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
12194 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
12195 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
12196 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
12197 U5(U4(surface_desc).ddpfPixelFormat).dwRGBAlphaBitMask = 0xff000000;
12198 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &offscreen, NULL);
12199 ok(hr == D3D_OK, "Creating the offscreen render target failed, hr %#x.\n", hr);
12201 hr = IDirect3DDevice7_SetRenderTarget(device, offscreen, 0);
12202 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
12204 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &mat);
12205 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#x.\n", hr);
12206 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_VIEW, &mat);
12207 ok(SUCCEEDED(hr), "Failed to set view transform, hr %#x.\n", hr);
12208 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &mat);
12209 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
12210 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CLIPPING, FALSE);
12211 ok(SUCCEEDED(hr), "Failed to disable clipping, hr %#x.\n", hr);
12212 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, FALSE);
12213 ok(SUCCEEDED(hr), "Failed to disable Z test, hr %#x.\n", hr);
12214 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, FALSE);
12215 ok(SUCCEEDED(hr), "Failed to disable fog, hr %#x.\n", hr);
12216 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_STENCILENABLE, FALSE);
12217 ok(SUCCEEDED(hr), "Failed to disable stencil test, hr %#x.\n", hr);
12218 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CULLMODE, D3DCULL_NONE);
12219 ok(SUCCEEDED(hr), "Failed to disable culling, hr %#x.\n", hr);
12220 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
12221 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
12223 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);
12224 ok(SUCCEEDED(hr), "Failed to enable blending, hr %#x.\n", hr);
12225 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);
12226 ok(SUCCEEDED(hr), "Failed to set src blend, hr %#x.\n", hr);
12227 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_DESTBLEND, D3DBLEND_DESTALPHA);
12228 ok(SUCCEEDED(hr), "Failed to set dest blend, hr %#x.\n", hr);
12230 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
12231 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
12232 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);
12233 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
12234 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
12235 ok(SUCCEEDED(hr), "Failed to set alpha op, hr %#x.\n", hr);
12236 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);
12237 ok(SUCCEEDED(hr), "Failed to set alpha arg, hr %#x.\n", hr);
12239 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xccff0000, 0.0f, 0);
12240 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
12241 hr = IDirect3DDevice7_BeginScene(device);
12242 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
12243 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE,
12244 green_quad, 4, 0);
12245 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12246 hr = IDirect3DDevice7_EndScene(device);
12247 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
12248 color = get_surface_color(offscreen, 320, 240);
12249 ok(compare_color(color, 0x00cc7f00, 1), "Got unexpected color 0x%08x.\n", color);
12251 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x7f00ff00, 0.0f, 0);
12252 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
12253 hr = IDirect3DDevice7_BeginScene(device);
12254 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
12255 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE,
12256 red_quad, 4, 0);
12257 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12258 hr = IDirect3DDevice7_EndScene(device);
12259 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
12260 color = get_surface_color(offscreen, 320, 240);
12261 ok(compare_color(color, 0x00cc7f00, 1), "Got unexpected color 0x%08x.\n", color);
12263 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, FALSE);
12264 ok(SUCCEEDED(hr), "Failed to disable blending, hr %#x.\n", hr);
12266 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xccff0000, 0.0f, 0);
12267 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
12268 hr = IDirect3DDevice7_BeginScene(device);
12269 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
12270 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE,
12271 green_quad, 4, 0);
12272 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12273 hr = IDirect3DDevice7_EndScene(device);
12274 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
12275 color = get_surface_color(offscreen, 320, 240);
12276 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
12278 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x7f00ff00, 0.0f, 0);
12279 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
12280 hr = IDirect3DDevice7_BeginScene(device);
12281 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
12282 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE,
12283 red_quad, 4, 0);
12284 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12285 hr = IDirect3DDevice7_EndScene(device);
12286 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
12287 color = get_surface_color(offscreen, 320, 240);
12288 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
12290 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_EDGEANTIALIAS, TRUE);
12291 ok(SUCCEEDED(hr), "Failed to enable edge antialiasing, hr %#x.\n", hr);
12293 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xccff0000, 0.0f, 0);
12294 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
12295 hr = IDirect3DDevice7_BeginScene(device);
12296 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
12297 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE,
12298 green_quad, 4, 0);
12299 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12300 hr = IDirect3DDevice7_EndScene(device);
12301 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
12302 color = get_surface_color(offscreen, 320, 240);
12303 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
12305 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x7f00ff00, 0.0f, 0);
12306 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
12307 hr = IDirect3DDevice7_BeginScene(device);
12308 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
12309 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE,
12310 red_quad, 4, 0);
12311 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12312 hr = IDirect3DDevice7_EndScene(device);
12313 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
12314 color = get_surface_color(offscreen, 320, 240);
12315 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
12317 IDirectDrawSurface7_Release(offscreen);
12318 IDirectDraw7_Release(ddraw);
12319 refcount = IDirect3DDevice7_Release(device);
12320 ok(!refcount, "Device has %u references left.\n", refcount);
12321 DestroyWindow(window);
12324 static void test_display_mode_surface_pixel_format(void)
12326 unsigned int width, height, bpp;
12327 IDirectDrawSurface7 *surface;
12328 DDSURFACEDESC2 surface_desc;
12329 IDirectDraw7 *ddraw;
12330 ULONG refcount;
12331 HWND window;
12332 HRESULT hr;
12334 if (!(ddraw = create_ddraw()))
12336 skip("Failed to create ddraw.\n");
12337 return;
12340 surface_desc.dwSize = sizeof(surface_desc);
12341 hr = IDirectDraw7_GetDisplayMode(ddraw, &surface_desc);
12342 ok(SUCCEEDED(hr), "Failed to get display mode, hr %#x.\n", hr);
12343 width = surface_desc.dwWidth;
12344 height = surface_desc.dwHeight;
12346 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
12347 0, 0, width, height, NULL, NULL, NULL, NULL);
12348 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
12349 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
12351 bpp = 0;
12352 if (SUCCEEDED(IDirectDraw7_SetDisplayMode(ddraw, width, height, 16, 0, 0)))
12353 bpp = 16;
12354 if (SUCCEEDED(IDirectDraw7_SetDisplayMode(ddraw, width, height, 24, 0, 0)))
12355 bpp = 24;
12356 if (SUCCEEDED(IDirectDraw7_SetDisplayMode(ddraw, width, height, 32, 0, 0)))
12357 bpp = 32;
12358 ok(bpp, "Set display mode failed.\n");
12360 surface_desc.dwSize = sizeof(surface_desc);
12361 hr = IDirectDraw7_GetDisplayMode(ddraw, &surface_desc);
12362 ok(SUCCEEDED(hr), "Failed to get display mode, hr %#x.\n", hr);
12363 ok(surface_desc.dwWidth == width, "Got width %u, expected %u.\n", surface_desc.dwWidth, width);
12364 ok(surface_desc.dwHeight == height, "Got height %u, expected %u.\n", surface_desc.dwHeight, height);
12365 ok(U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount == bpp, "Got bpp %u, expected %u.\n",
12366 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount, bpp);
12368 memset(&surface_desc, 0, sizeof(surface_desc));
12369 surface_desc.dwSize = sizeof(surface_desc);
12370 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
12371 U5(surface_desc).dwBackBufferCount = 1;
12372 surface_desc.ddsCaps.dwCaps = DDSCAPS_COMPLEX | DDSCAPS_FLIP | DDSCAPS_PRIMARYSURFACE;
12373 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
12374 ok(hr == D3D_OK, "Failed to create surface, hr %#x.\n", hr);
12375 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &surface_desc);
12376 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
12377 ok(surface_desc.dwWidth == width, "Got width %u, expected %u.\n", surface_desc.dwWidth, width);
12378 ok(surface_desc.dwHeight == height, "Got height %u, expected %u.\n", surface_desc.dwHeight, height);
12379 ok(U4(surface_desc).ddpfPixelFormat.dwFlags == DDPF_RGB, "Got unexpected pixel format flags %#x.\n",
12380 U4(surface_desc).ddpfPixelFormat.dwFlags);
12381 ok(U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount == bpp, "Got bpp %u, expected %u.\n",
12382 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount, bpp);
12383 IDirectDrawSurface7_Release(surface);
12385 memset(&surface_desc, 0, sizeof(surface_desc));
12386 surface_desc.dwSize = sizeof(surface_desc);
12387 surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
12388 surface_desc.dwWidth = width;
12389 surface_desc.dwHeight = height;
12390 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
12391 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
12392 ok(hr == D3D_OK, "Failed to create surface, hr %#x.\n", hr);
12393 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &surface_desc);
12394 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
12395 ok(U4(surface_desc).ddpfPixelFormat.dwFlags == DDPF_RGB, "Got unexpected pixel format flags %#x.\n",
12396 U4(surface_desc).ddpfPixelFormat.dwFlags);
12397 ok(U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount == bpp, "Got bpp %u, expected %u.\n",
12398 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount, bpp);
12399 IDirectDrawSurface7_Release(surface);
12401 refcount = IDirectDraw7_Release(ddraw);
12402 ok(!refcount, "DirectDraw has %u references left.\n", refcount);
12403 DestroyWindow(window);
12406 static void test_surface_desc_size(void)
12408 union
12410 DWORD dwSize;
12411 DDSURFACEDESC desc1;
12412 DDSURFACEDESC2 desc2;
12413 BYTE blob[1024];
12414 } desc;
12415 IDirectDrawSurface7 *surface7;
12416 IDirectDrawSurface3 *surface3;
12417 IDirectDrawSurface *surface;
12418 DDSURFACEDESC2 surface_desc;
12419 HRESULT expected_hr, hr;
12420 IDirectDraw7 *ddraw;
12421 unsigned int i, j;
12422 ULONG refcount;
12424 static const struct
12426 unsigned int caps;
12427 const char *name;
12429 surface_caps[] =
12431 {DDSCAPS_OFFSCREENPLAIN, "offscreenplain"},
12432 {DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, "systemmemory texture"},
12433 {DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, "videomemory texture"},
12435 static const unsigned int desc_sizes[] =
12437 sizeof(DDSURFACEDESC),
12438 sizeof(DDSURFACEDESC2),
12439 sizeof(DDSURFACEDESC) + 1,
12440 sizeof(DDSURFACEDESC2) + 1,
12441 2 * sizeof(DDSURFACEDESC),
12442 2 * sizeof(DDSURFACEDESC2),
12443 sizeof(DDSURFACEDESC) - 1,
12444 sizeof(DDSURFACEDESC2) - 1,
12445 sizeof(DDSURFACEDESC) / 2,
12446 sizeof(DDSURFACEDESC2) / 2,
12450 sizeof(desc) / 2,
12451 sizeof(desc) - 100,
12454 if (!(ddraw = create_ddraw()))
12456 skip("Failed to create ddraw.\n");
12457 return;
12459 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
12460 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
12462 for (i = 0; i < ARRAY_SIZE(surface_caps); ++i)
12464 memset(&surface_desc, 0, sizeof(surface_desc));
12465 surface_desc.dwSize = sizeof(surface_desc);
12466 surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
12467 surface_desc.ddsCaps.dwCaps = surface_caps[i].caps;
12468 surface_desc.dwHeight = 128;
12469 surface_desc.dwWidth = 128;
12470 if (FAILED(IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface7, NULL)))
12472 skip("Failed to create surface, type %s.\n", surface_caps[i].name);
12473 continue;
12475 hr = IDirectDrawSurface_QueryInterface(surface7, &IID_IDirectDrawSurface, (void **)&surface);
12476 ok(hr == DD_OK, "Failed to query IDirectDrawSurface, hr %#x, type %s.\n", hr, surface_caps[i].name);
12477 hr = IDirectDrawSurface_QueryInterface(surface7, &IID_IDirectDrawSurface3, (void **)&surface3);
12478 ok(hr == DD_OK, "Failed to query IDirectDrawSurface3, hr %#x, type %s.\n", hr, surface_caps[i].name);
12480 /* GetSurfaceDesc() */
12481 for (j = 0; j < ARRAY_SIZE(desc_sizes); ++j)
12483 memset(&desc, 0, sizeof(desc));
12484 desc.dwSize = desc_sizes[j];
12485 expected_hr = desc.dwSize == sizeof(DDSURFACEDESC) ? DD_OK : DDERR_INVALIDPARAMS;
12486 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &desc.desc1);
12487 ok(hr == expected_hr, "Got hr %#x, expected %#x, dwSize %u, type %s.\n",
12488 hr, expected_hr, desc_sizes[j], surface_caps[i].name);
12490 memset(&desc, 0, sizeof(desc));
12491 desc.dwSize = desc_sizes[j];
12492 expected_hr = desc.dwSize == sizeof(DDSURFACEDESC) ? DD_OK : DDERR_INVALIDPARAMS;
12493 hr = IDirectDrawSurface3_GetSurfaceDesc(surface3, &desc.desc1);
12494 ok(hr == expected_hr, "Got hr %#x, expected %#x, dwSize %u, type %s.\n",
12495 hr, expected_hr, desc_sizes[j], surface_caps[i].name);
12497 memset(&desc, 0, sizeof(desc));
12498 desc.dwSize = desc_sizes[j];
12499 expected_hr = desc.dwSize == sizeof(DDSURFACEDESC2) ? DD_OK : DDERR_INVALIDPARAMS;
12500 hr = IDirectDrawSurface7_GetSurfaceDesc(surface7, &desc.desc2);
12501 ok(hr == expected_hr, "Got hr %#x, expected %#x, dwSize %u, type %s.\n",
12502 hr, expected_hr, desc_sizes[j], surface_caps[i].name);
12505 /* Lock() */
12506 for (j = 0; j < ARRAY_SIZE(desc_sizes); ++j)
12508 const BOOL ignore_size = surface_caps[i].caps & DDSCAPS_TEXTURE
12509 && !(surface_caps[i].caps & DDSCAPS_VIDEOMEMORY);
12510 const BOOL valid_size = desc_sizes[j] == sizeof(DDSURFACEDESC)
12511 || desc_sizes[j] == sizeof(DDSURFACEDESC2);
12512 DWORD expected_texture_stage;
12514 memset(&desc, 0, sizeof(desc));
12515 desc.dwSize = desc_sizes[j];
12516 desc.desc2.dwTextureStage = 0xdeadbeef;
12517 desc.blob[sizeof(DDSURFACEDESC2)] = 0xef;
12518 hr = IDirectDrawSurface_Lock(surface, NULL, &desc.desc1, 0, 0);
12519 expected_hr = ignore_size || valid_size ? DD_OK : DDERR_INVALIDPARAMS;
12520 ok(hr == expected_hr, "Got hr %#x, expected %#x, dwSize %u, type %s.\n",
12521 hr, expected_hr, desc_sizes[j], surface_caps[i].name);
12522 ok(desc.dwSize == desc_sizes[j], "dwSize was changed from %u to %u, type %s.\n",
12523 desc_sizes[j], desc.dwSize, surface_caps[i].name);
12524 ok(desc.blob[sizeof(DDSURFACEDESC2)] == 0xef, "Got unexpected byte %02x, dwSize %u, type %s.\n",
12525 desc.blob[sizeof(DDSURFACEDESC2)], desc_sizes[j], surface_caps[i].name);
12526 if (SUCCEEDED(hr))
12528 ok(desc.desc1.dwWidth == 128, "Got unexpected width %u, dwSize %u, type %s.\n",
12529 desc.desc1.dwWidth, desc_sizes[j], surface_caps[i].name);
12530 ok(desc.desc1.dwHeight == 128, "Got unexpected height %u, dwSize %u, type %s.\n",
12531 desc.desc1.dwHeight, desc_sizes[j], surface_caps[i].name);
12532 expected_texture_stage = desc_sizes[j] >= sizeof(DDSURFACEDESC2) ? 0 : 0xdeadbeef;
12533 todo_wine_if(!expected_texture_stage)
12534 ok(desc.desc2.dwTextureStage == expected_texture_stage,
12535 "Got unexpected texture stage %#x, dwSize %u, type %s.\n",
12536 desc.desc2.dwTextureStage, desc_sizes[j], surface_caps[i].name);
12537 IDirectDrawSurface_Unlock(surface, NULL);
12540 memset(&desc, 0, sizeof(desc));
12541 desc.dwSize = desc_sizes[j];
12542 desc.desc2.dwTextureStage = 0xdeadbeef;
12543 desc.blob[sizeof(DDSURFACEDESC2)] = 0xef;
12544 hr = IDirectDrawSurface3_Lock(surface3, NULL, &desc.desc1, 0, 0);
12545 expected_hr = ignore_size || valid_size ? DD_OK : DDERR_INVALIDPARAMS;
12546 ok(hr == expected_hr, "Got hr %#x, expected %#x, dwSize %u, type %s.\n",
12547 hr, expected_hr, desc_sizes[j], surface_caps[i].name);
12548 ok(desc.dwSize == desc_sizes[j], "dwSize was changed from %u to %u, type %s.\n",
12549 desc_sizes[j], desc.dwSize, surface_caps[i].name);
12550 ok(desc.blob[sizeof(DDSURFACEDESC2)] == 0xef, "Got unexpected byte %02x, dwSize %u, type %s.\n",
12551 desc.blob[sizeof(DDSURFACEDESC2)], desc_sizes[j], surface_caps[i].name);
12552 if (SUCCEEDED(hr))
12554 ok(desc.desc1.dwWidth == 128, "Got unexpected width %u, dwSize %u, type %s.\n",
12555 desc.desc1.dwWidth, desc_sizes[j], surface_caps[i].name);
12556 ok(desc.desc1.dwHeight == 128, "Got unexpected height %u, dwSize %u, type %s.\n",
12557 desc.desc1.dwHeight, desc_sizes[j], surface_caps[i].name);
12558 expected_texture_stage = desc_sizes[j] >= sizeof(DDSURFACEDESC2) ? 0 : 0xdeadbeef;
12559 todo_wine_if(!expected_texture_stage)
12560 ok(desc.desc2.dwTextureStage == expected_texture_stage,
12561 "Got unexpected texture stage %#x, dwSize %u, type %s.\n",
12562 desc.desc2.dwTextureStage, desc_sizes[j], surface_caps[i].name);
12563 IDirectDrawSurface3_Unlock(surface3, NULL);
12566 memset(&desc, 0, sizeof(desc));
12567 desc.dwSize = desc_sizes[j];
12568 desc.desc2.dwTextureStage = 0xdeadbeef;
12569 desc.blob[sizeof(DDSURFACEDESC2)] = 0xef;
12570 hr = IDirectDrawSurface7_Lock(surface7, NULL, &desc.desc2, 0, 0);
12571 expected_hr = ignore_size || valid_size ? DD_OK : DDERR_INVALIDPARAMS;
12572 ok(hr == expected_hr, "Got hr %#x, expected %#x, dwSize %u, type %s.\n",
12573 hr, expected_hr, desc_sizes[j], surface_caps[i].name);
12574 ok(desc.dwSize == desc_sizes[j], "dwSize was changed from %u to %u, type %s.\n",
12575 desc_sizes[j], desc.dwSize, surface_caps[i].name);
12576 ok(desc.blob[sizeof(DDSURFACEDESC2)] == 0xef, "Got unexpected byte %02x, dwSize %u, type %s.\n",
12577 desc.blob[sizeof(DDSURFACEDESC2)], desc_sizes[j], surface_caps[i].name);
12578 if (SUCCEEDED(hr))
12580 ok(desc.desc2.dwWidth == 128, "Got unexpected width %u, dwSize %u, type %s.\n",
12581 desc.desc2.dwWidth, desc_sizes[j], surface_caps[i].name);
12582 ok(desc.desc2.dwHeight == 128, "Got unexpected height %u, dwSize %u, type %s.\n",
12583 desc.desc2.dwHeight, desc_sizes[j], surface_caps[i].name);
12584 expected_texture_stage = desc_sizes[j] >= sizeof(DDSURFACEDESC2) ? 0 : 0xdeadbeef;
12585 ok(desc.desc2.dwTextureStage == expected_texture_stage,
12586 "Got unexpected texture stage %#x, dwSize %u, type %s.\n",
12587 desc.desc2.dwTextureStage, desc_sizes[j], surface_caps[i].name);
12588 IDirectDrawSurface7_Unlock(surface7, NULL);
12592 IDirectDrawSurface7_Release(surface7);
12593 IDirectDrawSurface3_Release(surface3);
12594 IDirectDrawSurface_Release(surface);
12597 /* GetDisplayMode() */
12598 for (j = 0; j < ARRAY_SIZE(desc_sizes); ++j)
12600 memset(&desc, 0xcc, sizeof(desc));
12601 desc.dwSize = desc_sizes[j];
12602 expected_hr = (desc.dwSize == sizeof(DDSURFACEDESC) || desc.dwSize == sizeof(DDSURFACEDESC2))
12603 ? DD_OK : DDERR_INVALIDPARAMS;
12604 hr = IDirectDraw7_GetDisplayMode(ddraw, &desc.desc2);
12605 ok(hr == expected_hr, "Got hr %#x, expected %#x, size %u.\n", hr, expected_hr, desc_sizes[j]);
12606 if (SUCCEEDED(hr))
12608 ok(desc.dwSize == sizeof(DDSURFACEDESC2), "Wrong size %u for %u.\n", desc.dwSize, desc_sizes[j]);
12609 ok(desc.blob[desc_sizes[j]] == 0xcc, "Overflow for size %u.\n", desc_sizes[j]);
12610 ok(desc.blob[desc_sizes[j] - 1] != 0xcc, "Struct not cleared for size %u.\n", desc_sizes[j]);
12614 refcount = IDirectDraw7_Release(ddraw);
12615 ok(!refcount, "DirectDraw has %u references left.\n", refcount);
12618 static void test_get_surface_from_dc(void)
12620 IDirectDrawSurface *surface1, *tmp1;
12621 IDirectDrawSurface7 *surface, *tmp;
12622 DDSURFACEDESC2 surface_desc;
12623 IDirectDraw7 *ddraw;
12624 HDC dc, device_dc;
12625 ULONG refcount;
12626 HWND window;
12627 HRESULT hr;
12628 DWORD ret;
12630 window = create_window();
12631 ddraw = create_ddraw();
12632 ok(!!ddraw, "Failed to create a ddraw object.\n");
12633 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
12634 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
12636 memset(&surface_desc, 0, sizeof(surface_desc));
12637 surface_desc.dwSize = sizeof(surface_desc);
12638 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
12639 surface_desc.dwWidth = 64;
12640 surface_desc.dwHeight = 64;
12641 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
12643 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
12644 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
12645 hr = IDirectDrawSurface7_QueryInterface(surface, &IID_IDirectDrawSurface, (void **)&surface1);
12646 ok(SUCCEEDED(hr), "Failed to query IDirectDrawSurface interface, hr %#x.\n", hr);
12648 refcount = get_refcount((IUnknown *)surface1);
12649 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
12650 refcount = get_refcount((IUnknown *)surface);
12651 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
12653 hr = IDirectDrawSurface7_GetDC(surface, &dc);
12654 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
12656 tmp1 = (void *)0xdeadbeef;
12657 device_dc = (void *)0xdeadbeef;
12658 hr = GetSurfaceFromDC(NULL, &tmp1, &device_dc);
12659 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
12660 ok(!tmp1, "Got unexpected surface %p.\n", tmp1);
12661 ok(!device_dc, "Got unexpected device_dc %p.\n", device_dc);
12663 device_dc = (void *)0xdeadbeef;
12664 hr = GetSurfaceFromDC(dc, NULL, &device_dc);
12665 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
12666 ok(device_dc == (void *)0xdeadbeef, "Got unexpected device_dc %p.\n", device_dc);
12668 tmp1 = (void *)0xdeadbeef;
12669 hr = GetSurfaceFromDC(dc, &tmp1, NULL);
12670 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
12671 ok(!tmp1, "Got unexpected surface %p.\n", tmp1);
12673 hr = GetSurfaceFromDC(dc, &tmp1, &device_dc);
12674 ok(SUCCEEDED(hr), "GetSurfaceFromDC failed, hr %#x.\n", hr);
12675 ok(tmp1 == surface1, "Got unexpected surface %p, expected %p.\n", tmp1, surface1);
12676 IDirectDrawSurface_Release(tmp1);
12678 ret = GetObjectType(device_dc);
12679 todo_wine ok(ret == OBJ_DC, "Got unexpected object type %#x.\n", ret);
12680 ret = GetDeviceCaps(device_dc, TECHNOLOGY);
12681 todo_wine ok(ret == DT_RASDISPLAY, "Got unexpected technology %#x.\n", ret);
12683 hr = IDirectDraw7_GetSurfaceFromDC(ddraw, dc, NULL);
12684 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
12686 hr = IDirectDraw7_GetSurfaceFromDC(ddraw, dc, &tmp);
12687 ok(SUCCEEDED(hr), "GetSurfaceFromDC failed, hr %#x.\n", hr);
12688 ok(tmp == surface, "Got unexpected surface %p, expected %p.\n", tmp, surface);
12690 refcount = get_refcount((IUnknown *)surface1);
12691 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
12692 refcount = get_refcount((IUnknown *)surface);
12693 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
12695 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
12696 ok(SUCCEEDED(hr), "ReleaseDC failed, hr %#x.\n", hr);
12698 IDirectDrawSurface_Release(tmp);
12700 dc = CreateCompatibleDC(NULL);
12701 ok(!!dc, "CreateCompatibleDC failed.\n");
12703 tmp1 = (void *)0xdeadbeef;
12704 device_dc = (void *)0xdeadbeef;
12705 hr = GetSurfaceFromDC(dc, &tmp1, &device_dc);
12706 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
12707 ok(!tmp1, "Got unexpected surface %p.\n", tmp1);
12708 ok(!device_dc, "Got unexpected device_dc %p.\n", device_dc);
12710 tmp = (void *)0xdeadbeef;
12711 hr = IDirectDraw7_GetSurfaceFromDC(ddraw, dc, &tmp);
12712 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
12713 ok(!tmp, "Got unexpected surface %p.\n", tmp);
12715 ok(DeleteDC(dc), "DeleteDC failed.\n");
12717 tmp = (void *)0xdeadbeef;
12718 hr = IDirectDraw7_GetSurfaceFromDC(ddraw, NULL, &tmp);
12719 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
12720 ok(!tmp, "Got unexpected surface %p.\n", tmp);
12722 IDirectDrawSurface7_Release(surface);
12723 IDirectDrawSurface_Release(surface1);
12724 IDirectDraw7_Release(ddraw);
12725 DestroyWindow(window);
12728 static void test_ck_operation(void)
12730 IDirectDrawSurface7 *src, *dst;
12731 IDirectDrawSurface *src1, *dst1;
12732 DDSURFACEDESC2 surface_desc;
12733 IDirectDraw7 *ddraw;
12734 ULONG refcount;
12735 HWND window;
12736 HRESULT hr;
12737 D3DCOLOR *color;
12738 unsigned int i;
12739 DDCOLORKEY ckey;
12740 DDBLTFX fx;
12742 window = create_window();
12743 ddraw = create_ddraw();
12744 ok(!!ddraw, "Failed to create a ddraw object.\n");
12745 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
12746 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
12748 memset(&surface_desc, 0, sizeof(surface_desc));
12749 surface_desc.dwSize = sizeof(surface_desc);
12750 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
12751 surface_desc.dwWidth = 4;
12752 surface_desc.dwHeight = 1;
12753 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
12754 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
12755 U1(U4(surface_desc.ddpfPixelFormat)).dwRGBBitCount = 32;
12756 U2(U4(surface_desc.ddpfPixelFormat)).dwRBitMask = 0x00ff0000;
12757 U3(U4(surface_desc.ddpfPixelFormat)).dwGBitMask = 0x0000ff00;
12758 U4(U4(surface_desc.ddpfPixelFormat)).dwBBitMask = 0x000000ff;
12759 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &dst, NULL);
12760 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
12762 surface_desc.dwFlags |= DDSD_CKSRCBLT;
12763 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00ff00ff;
12764 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00ff00ff;
12765 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &src, NULL);
12766 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
12768 hr = IDirectDrawSurface7_Lock(src, NULL, &surface_desc, DDLOCK_WAIT, NULL);
12769 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
12770 ok(!(surface_desc.dwFlags & DDSD_LPSURFACE), "Surface desc has LPSURFACE Flags set.\n");
12771 color = surface_desc.lpSurface;
12772 color[0] = 0x77010203;
12773 color[1] = 0x00010203;
12774 color[2] = 0x77ff00ff;
12775 color[3] = 0x00ff00ff;
12776 hr = IDirectDrawSurface7_Unlock(src, NULL);
12777 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
12779 for (i = 0; i < 2; ++i)
12781 hr = IDirectDrawSurface7_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
12782 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
12783 color = surface_desc.lpSurface;
12784 color[0] = 0xcccccccc;
12785 color[1] = 0xcccccccc;
12786 color[2] = 0xcccccccc;
12787 color[3] = 0xcccccccc;
12788 hr = IDirectDrawSurface7_Unlock(dst, NULL);
12789 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
12791 if (i)
12793 hr = IDirectDrawSurface7_BltFast(dst, 0, 0, src, NULL, DDBLTFAST_SRCCOLORKEY);
12794 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
12796 else
12798 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_KEYSRC, NULL);
12799 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
12802 hr = IDirectDrawSurface7_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT | DDLOCK_READONLY, NULL);
12803 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
12804 ok(!(surface_desc.dwFlags & DDSD_LPSURFACE), "Surface desc has LPSURFACE Flags set.\n");
12805 color = surface_desc.lpSurface;
12806 /* Different behavior on some drivers / windows versions. Some versions ignore the X channel when
12807 * color keying, but copy it to the destination surface. Others (sysmem surfaces) apply it for
12808 * color keying, but do not copy it into the destination surface. Nvidia neither uses it for
12809 * color keying nor copies it. */
12810 ok((color[0] == 0x77010203 && color[1] == 0x00010203
12811 && color[2] == 0xcccccccc && color[3] == 0xcccccccc) /* AMD, Wine */
12812 || broken(color[0] == 0x00010203 && color[1] == 0x00010203
12813 && color[2] == 0x00ff00ff && color[3] == 0xcccccccc) /* Sysmem surfaces? */
12814 || broken(color[0] == 0x00010203 && color[1] == 0x00010203
12815 && color[2] == 0xcccccccc && color[3] == 0xcccccccc) /* Nvidia */
12816 || broken(color[0] == 0xff010203 && color[1] == 0xff010203
12817 && color[2] == 0xcccccccc && color[3] == 0xcccccccc) /* Testbot */,
12818 "Destination data after blitting is %08x %08x %08x %08x, i=%u.\n",
12819 color[0], color[1], color[2], color[3], i);
12820 hr = IDirectDrawSurface7_Unlock(dst, NULL);
12821 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
12824 hr = IDirectDrawSurface7_GetColorKey(src, DDCKEY_SRCBLT, &ckey);
12825 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
12826 ok(ckey.dwColorSpaceLowValue == 0x00ff00ff && ckey.dwColorSpaceHighValue == 0x00ff00ff,
12827 "Got unexpected color key low=%08x high=%08x.\n", ckey.dwColorSpaceLowValue, ckey.dwColorSpaceHighValue);
12829 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0x0000ff00;
12830 hr = IDirectDrawSurface7_SetColorKey(src, DDCKEY_SRCBLT, &ckey);
12831 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
12833 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0;
12834 hr = IDirectDrawSurface7_GetColorKey(src, DDCKEY_SRCBLT, &ckey);
12835 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
12836 ok(ckey.dwColorSpaceLowValue == 0x0000ff00 && ckey.dwColorSpaceHighValue == 0x0000ff00,
12837 "Got unexpected color key low=%08x high=%08x.\n", ckey.dwColorSpaceLowValue, ckey.dwColorSpaceHighValue);
12839 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0;
12840 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0;
12841 hr = IDirectDrawSurface7_GetSurfaceDesc(src, &surface_desc);
12842 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
12843 ok(surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue == 0x0000ff00
12844 && surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue == 0x0000ff00,
12845 "Got unexpected color key low=%08x high=%08x.\n", surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue,
12846 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue);
12848 /* Test SetColorKey with dwColorSpaceHighValue < dwColorSpaceLowValue */
12849 ckey.dwColorSpaceLowValue = 0x000000ff;
12850 ckey.dwColorSpaceHighValue = 0x00000000;
12851 hr = IDirectDrawSurface7_SetColorKey(src, DDCKEY_SRCBLT, &ckey);
12852 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
12854 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0;
12855 hr = IDirectDrawSurface7_GetColorKey(src, DDCKEY_SRCBLT, &ckey);
12856 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
12857 ok(ckey.dwColorSpaceLowValue == 0x000000ff && ckey.dwColorSpaceHighValue == 0x000000ff,
12858 "Got unexpected color key low=%08x high=%08x.\n", ckey.dwColorSpaceLowValue, ckey.dwColorSpaceHighValue);
12860 ckey.dwColorSpaceLowValue = 0x000000ff;
12861 ckey.dwColorSpaceHighValue = 0x00000001;
12862 hr = IDirectDrawSurface7_SetColorKey(src, DDCKEY_SRCBLT, &ckey);
12863 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
12865 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0;
12866 hr = IDirectDrawSurface7_GetColorKey(src, DDCKEY_SRCBLT, &ckey);
12867 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
12868 ok(ckey.dwColorSpaceLowValue == 0x000000ff && ckey.dwColorSpaceHighValue == 0x000000ff,
12869 "Got unexpected color key low=%08x high=%08x.\n", ckey.dwColorSpaceLowValue, ckey.dwColorSpaceHighValue);
12871 ckey.dwColorSpaceLowValue = 0x000000fe;
12872 ckey.dwColorSpaceHighValue = 0x000000fd;
12873 hr = IDirectDrawSurface7_SetColorKey(src, DDCKEY_SRCBLT, &ckey);
12874 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
12876 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0;
12877 hr = IDirectDrawSurface7_GetColorKey(src, DDCKEY_SRCBLT, &ckey);
12878 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
12879 ok(ckey.dwColorSpaceLowValue == 0x000000fe && ckey.dwColorSpaceHighValue == 0x000000fe,
12880 "Got unexpected color key low=%08x high=%08x.\n", ckey.dwColorSpaceLowValue, ckey.dwColorSpaceHighValue);
12882 IDirectDrawSurface7_Release(src);
12883 IDirectDrawSurface7_Release(dst);
12885 /* Test source and destination keys and where they are read from. Use a surface with alpha
12886 * to avoid driver-dependent content in the X channel. */
12887 memset(&surface_desc, 0, sizeof(surface_desc));
12888 surface_desc.dwSize = sizeof(surface_desc);
12889 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
12890 surface_desc.dwWidth = 6;
12891 surface_desc.dwHeight = 1;
12892 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
12893 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
12894 U1(U4(surface_desc.ddpfPixelFormat)).dwRGBBitCount = 32;
12895 U2(U4(surface_desc.ddpfPixelFormat)).dwRBitMask = 0x00ff0000;
12896 U3(U4(surface_desc.ddpfPixelFormat)).dwGBitMask = 0x0000ff00;
12897 U4(U4(surface_desc.ddpfPixelFormat)).dwBBitMask = 0x000000ff;
12898 U5(U4(surface_desc.ddpfPixelFormat)).dwRGBAlphaBitMask = 0xff000000;
12899 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &dst, NULL);
12900 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
12901 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &src, NULL);
12902 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
12904 ckey.dwColorSpaceLowValue = 0x0000ff00;
12905 ckey.dwColorSpaceHighValue = 0x0000ff00;
12906 hr = IDirectDrawSurface7_SetColorKey(dst, DDCKEY_SRCBLT, &ckey);
12907 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
12908 ckey.dwColorSpaceLowValue = 0x00ff0000;
12909 ckey.dwColorSpaceHighValue = 0x00ff0000;
12910 hr = IDirectDrawSurface7_SetColorKey(dst, DDCKEY_DESTBLT, &ckey);
12911 ok(SUCCEEDED(hr) || hr == DDERR_NOCOLORKEYHW, "Failed to set color key, hr %#x.\n", hr);
12912 if (FAILED(hr))
12914 /* Nvidia reject dest keys, AMD allows them. This applies to vidmem and sysmem surfaces. */
12915 skip("Failed to set destination color key, skipping related tests.\n");
12916 goto done;
12919 ckey.dwColorSpaceLowValue = 0x000000ff;
12920 ckey.dwColorSpaceHighValue = 0x000000ff;
12921 hr = IDirectDrawSurface7_SetColorKey(src, DDCKEY_SRCBLT, &ckey);
12922 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
12923 ckey.dwColorSpaceLowValue = 0x000000aa;
12924 ckey.dwColorSpaceHighValue = 0x000000aa;
12925 hr = IDirectDrawSurface7_SetColorKey(src, DDCKEY_DESTBLT, &ckey);
12926 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
12928 memset(&fx, 0, sizeof(fx));
12929 fx.dwSize = sizeof(fx);
12930 fx.ddckSrcColorkey.dwColorSpaceHighValue = 0x00110000;
12931 fx.ddckSrcColorkey.dwColorSpaceLowValue = 0x00110000;
12932 fx.ddckDestColorkey.dwColorSpaceHighValue = 0x00001100;
12933 fx.ddckDestColorkey.dwColorSpaceLowValue = 0x00001100;
12935 hr = IDirectDrawSurface7_Lock(src, NULL, &surface_desc, DDLOCK_WAIT, NULL);
12936 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
12937 color = surface_desc.lpSurface;
12938 color[0] = 0x000000ff; /* Applies to src blt key in src surface. */
12939 color[1] = 0x000000aa; /* Applies to dst blt key in src surface. */
12940 color[2] = 0x00ff0000; /* Dst color key in dst surface. */
12941 color[3] = 0x0000ff00; /* Src color key in dst surface. */
12942 color[4] = 0x00001100; /* Src color key in ddbltfx. */
12943 color[5] = 0x00110000; /* Dst color key in ddbltfx. */
12944 hr = IDirectDrawSurface7_Unlock(src, NULL);
12945 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
12947 hr = IDirectDrawSurface7_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
12948 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
12949 color = surface_desc.lpSurface;
12950 color[0] = color[1] = color[2] = color[3] = color[4] = color[5] = 0x55555555;
12951 hr = IDirectDrawSurface7_Unlock(dst, NULL);
12952 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
12954 /* Test a blit without keying. */
12955 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, 0, &fx);
12956 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
12958 hr = IDirectDrawSurface7_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
12959 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
12960 color = surface_desc.lpSurface;
12961 /* Should have copied src data unmodified to dst. */
12962 ok(color[0] == 0x000000ff && color[1] == 0x000000aa && color[2] == 0x00ff0000 &&
12963 color[3] == 0x0000ff00 && color[4] == 0x00001100 && color[5] == 0x00110000,
12964 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
12965 color[0], color[1], color[2], color[3], color[4], color[5]);
12967 color[0] = color[1] = color[2] = color[3] = color[4] = color[5] = 0x55555555;
12968 hr = IDirectDrawSurface7_Unlock(dst, NULL);
12969 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
12971 /* Src key. */
12972 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_KEYSRC, &fx);
12973 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
12975 hr = IDirectDrawSurface7_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
12976 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
12977 color = surface_desc.lpSurface;
12978 /* Src key applied to color[0]. It is unmodified, the others are copied. */
12979 ok(color[0] == 0x55555555 && color[1] == 0x000000aa && color[2] == 0x00ff0000 &&
12980 color[3] == 0x0000ff00 && color[4] == 0x00001100 && color[5] == 0x00110000,
12981 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
12982 color[0], color[1], color[2], color[3], color[4], color[5]);
12984 color[0] = color[1] = color[2] = color[3] = color[4] = color[5] = 0x55555555;
12985 hr = IDirectDrawSurface7_Unlock(dst, NULL);
12986 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
12988 /* Src override. */
12989 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_KEYSRCOVERRIDE, &fx);
12990 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
12992 hr = IDirectDrawSurface7_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
12993 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
12994 color = surface_desc.lpSurface;
12995 /* Override key applied to color[5]. It is unmodified, the others are copied. */
12996 ok(color[0] == 0x000000ff && color[1] == 0x000000aa && color[2] == 0x00ff0000 &&
12997 color[3] == 0x0000ff00 && color[4] == 0x00001100 && color[5] == 0x55555555,
12998 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
12999 color[0], color[1], color[2], color[3], color[4], color[5]);
13001 color[0] = color[1] = color[2] = color[3] = color[4] = color[5] = 0x55555555;
13002 hr = IDirectDrawSurface7_Unlock(dst, NULL);
13003 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
13005 /* Src override AND src key. That is not supposed to work. */
13006 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_KEYSRC | DDBLT_KEYSRCOVERRIDE, &fx);
13007 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
13009 hr = IDirectDrawSurface7_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
13010 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
13011 color = surface_desc.lpSurface;
13012 /* Ensure the destination was not changed. */
13013 ok(color[0] == 0x55555555 && color[1] == 0x55555555 && color[2] == 0x55555555 &&
13014 color[3] == 0x55555555 && color[4] == 0x55555555 && color[5] == 0x55555555,
13015 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
13016 color[0], color[1], color[2], color[3], color[4], color[5]);
13018 /* Use different dst colors for the dst key test. */
13019 color[0] = 0x00ff0000; /* Dest key in dst surface. */
13020 color[1] = 0x00ff0000; /* Dest key in dst surface. */
13021 color[2] = 0x00001100; /* Dest key in override. */
13022 color[3] = 0x00001100; /* Dest key in override. */
13023 color[4] = 0x000000aa; /* Dest key in src surface. */
13024 color[5] = 0x000000aa; /* Dest key in src surface. */
13025 hr = IDirectDrawSurface7_Unlock(dst, NULL);
13026 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
13028 /* Dest key blit. The key is taken from the DESTINATION surface in v7! */
13029 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_KEYDEST, &fx);
13030 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
13032 hr = IDirectDrawSurface7_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
13033 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
13034 color = surface_desc.lpSurface;
13035 /* Dst key applied to color[0,1], they are the only changed pixels. */
13036 todo_wine ok(color[0] == 0x000000ff && color[1] == 0x000000aa && color[2] == 0x00001100 &&
13037 color[3] == 0x00001100 && color[4] == 0x000000aa && color[5] == 0x000000aa,
13038 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
13039 color[0], color[1], color[2], color[3], color[4], color[5]);
13041 color[0] = 0x00ff0000; /* Dest key in dst surface. */
13042 color[1] = 0x00ff0000; /* Dest key in dst surface. */
13043 color[2] = 0x00001100; /* Dest key in override. */
13044 color[3] = 0x00001100; /* Dest key in override. */
13045 color[4] = 0x000000aa; /* Dest key in src surface. */
13046 color[5] = 0x000000aa; /* Dest key in src surface. */
13047 hr = IDirectDrawSurface7_Unlock(dst, NULL);
13048 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
13050 /* What happens with a QI'd older version of the interface? It takes the key
13051 * from the source surface. */
13052 hr = IDirectDrawSurface7_QueryInterface(src, &IID_IDirectDrawSurface, (void **)&src1);
13053 ok(SUCCEEDED(hr), "Failed to query IDirectDrawSurface interface, hr %#x.\n", hr);
13054 hr = IDirectDrawSurface7_QueryInterface(dst, &IID_IDirectDrawSurface, (void **)&dst1);
13055 ok(SUCCEEDED(hr), "Failed to query IDirectDrawSurface interface, hr %#x.\n", hr);
13057 hr = IDirectDrawSurface_Blt(dst1, NULL, src1, NULL, DDBLT_KEYDEST, &fx);
13058 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
13060 IDirectDrawSurface_Release(dst1);
13061 IDirectDrawSurface_Release(src1);
13063 hr = IDirectDrawSurface7_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
13064 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
13065 color = surface_desc.lpSurface;
13066 /* Dst key applied to color[4,5], they are the only changed pixels. */
13067 ok(color[0] == 0x00ff0000 && color[1] == 0x00ff0000 && color[2] == 0x00001100 &&
13068 color[3] == 0x00001100 && color[4] == 0x00001100 && color[5] == 0x00110000,
13069 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
13070 color[0], color[1], color[2], color[3], color[4], color[5]);
13072 color[0] = 0x00ff0000; /* Dest key in dst surface. */
13073 color[1] = 0x00ff0000; /* Dest key in dst surface. */
13074 color[2] = 0x00001100; /* Dest key in override. */
13075 color[3] = 0x00001100; /* Dest key in override. */
13076 color[4] = 0x000000aa; /* Dest key in src surface. */
13077 color[5] = 0x000000aa; /* Dest key in src surface. */
13078 hr = IDirectDrawSurface7_Unlock(dst, NULL);
13079 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
13081 /* Dest override key blit. */
13082 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_KEYDESTOVERRIDE, &fx);
13083 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
13085 hr = IDirectDrawSurface7_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
13086 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
13087 color = surface_desc.lpSurface;
13088 /* Dst key applied to color[2,3], they are the only changed pixels. */
13089 ok(color[0] == 0x00ff0000 && color[1] == 0x00ff0000 && color[2] == 0x00ff0000 &&
13090 color[3] == 0x0000ff00 && color[4] == 0x000000aa && color[5] == 0x000000aa,
13091 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
13092 color[0], color[1], color[2], color[3], color[4], color[5]);
13094 color[0] = 0x00ff0000; /* Dest key in dst surface. */
13095 color[1] = 0x00ff0000; /* Dest key in dst surface. */
13096 color[2] = 0x00001100; /* Dest key in override. */
13097 color[3] = 0x00001100; /* Dest key in override. */
13098 color[4] = 0x000000aa; /* Dest key in src surface. */
13099 color[5] = 0x000000aa; /* Dest key in src surface. */
13100 hr = IDirectDrawSurface7_Unlock(dst, NULL);
13101 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
13103 /* Dest override together with surface key. Supposed to fail. */
13104 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_KEYDEST | DDBLT_KEYDESTOVERRIDE, &fx);
13105 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
13107 hr = IDirectDrawSurface7_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
13108 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
13109 color = surface_desc.lpSurface;
13110 /* Destination is unchanged. */
13111 ok(color[0] == 0x00ff0000 && color[1] == 0x00ff0000 && color[2] == 0x00001100 &&
13112 color[3] == 0x00001100 && color[4] == 0x000000aa && color[5] == 0x000000aa,
13113 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
13114 color[0], color[1], color[2], color[3], color[4], color[5]);
13115 hr = IDirectDrawSurface7_Unlock(dst, NULL);
13116 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
13118 /* Source and destination key. This is driver dependent. New HW treats it like
13119 * DDBLT_KEYSRC. Older HW and some software renderers apply both keys. */
13120 if (0)
13122 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_KEYDEST | DDBLT_KEYSRC, &fx);
13123 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
13125 hr = IDirectDrawSurface7_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
13126 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
13127 color = surface_desc.lpSurface;
13128 /* Color[0] is filtered by the src key, 2-5 are filtered by the dst key, if
13129 * the driver applies it. */
13130 ok(color[0] == 0x00ff0000 && color[1] == 0x000000aa && color[2] == 0x00ff0000 &&
13131 color[3] == 0x0000ff00 && color[4] == 0x00001100 && color[5] == 0x00110000,
13132 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
13133 color[0], color[1], color[2], color[3], color[4], color[5]);
13135 color[0] = 0x00ff0000; /* Dest key in dst surface. */
13136 color[1] = 0x00ff0000; /* Dest key in dst surface. */
13137 color[2] = 0x00001100; /* Dest key in override. */
13138 color[3] = 0x00001100; /* Dest key in override. */
13139 color[4] = 0x000000aa; /* Dest key in src surface. */
13140 color[5] = 0x000000aa; /* Dest key in src surface. */
13141 hr = IDirectDrawSurface7_Unlock(dst, NULL);
13142 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
13145 /* Override keys without ddbltfx parameter fail */
13146 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_KEYDESTOVERRIDE, NULL);
13147 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
13148 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_KEYSRCOVERRIDE, NULL);
13149 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
13151 /* Try blitting without keys in the source surface. */
13152 hr = IDirectDrawSurface7_SetColorKey(src, DDCKEY_SRCBLT, NULL);
13153 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
13154 hr = IDirectDrawSurface7_SetColorKey(src, DDCKEY_DESTBLT, NULL);
13155 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
13157 /* That fails now. Do not bother to check that the data is unmodified. */
13158 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_KEYSRC, &fx);
13159 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
13161 /* Dest key blit still works, the destination surface key is used in v7. */
13162 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_KEYDEST, &fx);
13163 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
13165 hr = IDirectDrawSurface7_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
13166 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
13167 color = surface_desc.lpSurface;
13168 /* Dst key applied to color[0,1], they are the only changed pixels. */
13169 todo_wine ok(color[0] == 0x000000ff && color[1] == 0x000000aa && color[2] == 0x00001100 &&
13170 color[3] == 0x00001100 && color[4] == 0x000000aa && color[5] == 0x000000aa,
13171 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
13172 color[0], color[1], color[2], color[3], color[4], color[5]);
13173 hr = IDirectDrawSurface7_Unlock(dst, NULL);
13174 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
13176 /* Try blitting without keys in the destination surface. */
13177 hr = IDirectDrawSurface7_SetColorKey(dst, DDCKEY_SRCBLT, NULL);
13178 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
13179 hr = IDirectDrawSurface7_SetColorKey(dst, DDCKEY_DESTBLT, NULL);
13180 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
13182 /* This fails, as sanity would dictate. */
13183 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_KEYDEST, &fx);
13184 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
13186 done:
13187 IDirectDrawSurface7_Release(src);
13188 IDirectDrawSurface7_Release(dst);
13189 refcount = IDirectDraw7_Release(ddraw);
13190 ok(!refcount, "DirectDraw has %u references left.\n", refcount);
13191 DestroyWindow(window);
13194 static void test_vb_refcount(void)
13196 ULONG prev_d3d_refcount, prev_device_refcount;
13197 ULONG cur_d3d_refcount, cur_device_refcount;
13198 IDirect3DVertexBuffer7 *vb, *vb7;
13199 D3DVERTEXBUFFERDESC vb_desc;
13200 IDirect3DVertexBuffer *vb1;
13201 IDirect3DDevice7 *device;
13202 IDirect3D7 *d3d;
13203 ULONG refcount;
13204 IUnknown *unk;
13205 HWND window;
13206 HRESULT hr;
13208 window = create_window();
13209 if (!(device = create_device(window, DDSCL_NORMAL)))
13211 skip("Failed to create a 3D device, skipping test.\n");
13212 DestroyWindow(window);
13213 return;
13216 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
13217 ok(SUCCEEDED(hr), "Failed to get Direct3D7 interface, hr %#x.\n", hr);
13219 prev_d3d_refcount = get_refcount((IUnknown *)d3d);
13220 prev_device_refcount = get_refcount((IUnknown *)device);
13222 memset(&vb_desc, 0, sizeof(vb_desc));
13223 vb_desc.dwSize = sizeof(vb_desc);
13224 vb_desc.dwFVF = D3DFVF_XYZ;
13225 vb_desc.dwNumVertices = 4;
13226 hr = IDirect3D7_CreateVertexBuffer(d3d, &vb_desc, &vb, 0);
13227 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
13229 cur_d3d_refcount = get_refcount((IUnknown *)d3d);
13230 cur_device_refcount = get_refcount((IUnknown *)device);
13231 ok(cur_d3d_refcount > prev_d3d_refcount, "D3D object refcount didn't change from %u.\n", prev_d3d_refcount);
13232 ok(cur_device_refcount == prev_device_refcount, "Device refcount changed from %u to %u.\n",
13233 prev_device_refcount, cur_device_refcount);
13235 prev_d3d_refcount = cur_d3d_refcount;
13236 hr = IDirect3DVertexBuffer7_QueryInterface(vb, &IID_IDirect3DVertexBuffer7, (void **)&vb7);
13237 ok(hr == DD_OK, "Failed to query IDirect3DVertexBuffer7, hr %#x.\n", hr);
13238 cur_d3d_refcount = get_refcount((IUnknown *)d3d);
13239 ok(cur_d3d_refcount == prev_d3d_refcount, "D3D object refcount changed from %u to %u.\n",
13240 prev_d3d_refcount, cur_d3d_refcount);
13241 IDirect3DVertexBuffer7_Release(vb7);
13243 hr = IDirect3DVertexBuffer7_QueryInterface(vb, &IID_IDirect3DVertexBuffer, (void **)&vb1);
13244 ok(hr == E_NOINTERFACE, "Querying IDirect3DVertexBuffer returned unexpected hr %#x.\n", hr);
13246 hr = IDirect3DVertexBuffer_QueryInterface(vb, &IID_IUnknown, (void **)&unk);
13247 ok(hr == DD_OK, "Failed to query IUnknown, hr %#x.\n", hr);
13248 ok((IUnknown *)vb == unk,
13249 "IDirect3DVertexBuffer7 and IUnknown interface pointers don't match, %p != %p.\n", vb, unk);
13250 IUnknown_Release(unk);
13252 refcount = IDirect3DVertexBuffer7_Release(vb);
13253 ok(!refcount, "Vertex buffer has %u references left.\n", refcount);
13255 IDirect3D7_Release(d3d);
13256 refcount = IDirect3DDevice7_Release(device);
13257 ok(!refcount, "Device has %u references left.\n", refcount);
13258 DestroyWindow(window);
13261 static void test_compute_sphere_visibility(void)
13263 static D3DVALUE clip_plane[4] = {1.0f, 0.0f, 0.0f, 0.5f};
13264 static D3DMATRIX proj_1 =
13266 1.810660f, 0.000000f, 0.000000f, 0.000000f,
13267 0.000000f, 2.414213f, 0.000000f, 0.000000f,
13268 0.000000f, 0.000000f, 1.020408f, 1.000000f,
13269 0.000000f, 0.000000f, -0.102041f, 0.000000f,
13271 static D3DMATRIX proj_2 =
13273 10.0f, 0.0f, 0.0f, 0.0f,
13274 0.0f, 10.0f, 0.0f, 0.0f,
13275 0.0f, 0.0f, 10.0f, 0.0f,
13276 0.0f, 0.0f, 0.0f, 1.0f,
13278 static D3DMATRIX view_1 =
13280 1.000000f, 0.000000f, 0.000000f, 0.000000f,
13281 0.000000f, 0.768221f, -0.640185f, 0.000000f,
13282 -0.000000f, 0.640185f, 0.768221f, 0.000000f,
13283 -14.852037f, 9.857489f, 11.600972f, 1.000000f,
13285 static D3DMATRIX identity =
13287 1.0f, 0.0f, 0.0f, 0.0f,
13288 0.0f, 1.0f, 0.0f, 0.0f,
13289 0.0f, 0.0f, 1.0f, 0.0f,
13290 0.0f, 0.0f, 0.0f, 1.0f,
13292 static struct
13294 D3DMATRIX *view, *proj;
13295 unsigned int sphere_count;
13296 D3DVECTOR center[3];
13297 D3DVALUE radius[3];
13298 DWORD enable_planes;
13299 const DWORD expected[3];
13301 tests[] =
13303 {&view_1, &proj_1, 1, {{{11.461533f}, {-4.761727f}, {-1.171646f}}}, {38.252632f}, 0, {0x3f}},
13304 {&view_1, &proj_1, 3, {{{-3.515620f}, {-1.560661f}, {-12.464638f}},
13305 {{14.290396f}, {-2.981143f}, {-24.311312f}},
13306 {{1.461626f}, {-6.093709f}, {-13.901010f}}},
13307 {4.354097f, 12.500704f, 17.251318f}, 0, {0x103d, 0x3f, 0x3f}},
13308 {&identity, &proj_2, 1, {{{0.0f}, {0.0f}, {0.05f}}}, {0.04f}, 0, {0}},
13309 {&identity, &identity, 1, {{{0.0f}, {0.0f}, {0.5f}}}, {0.5f}, 0, {0}},
13310 {&identity, &identity, 1, {{{0.0f}, {0.0f}, {0.0f}}}, {0.0f}, 0, {0}},
13311 {&identity, &identity, 1, {{{-1.0f}, {-1.0f}, {0.5f}}}, {0.25f}, 0, {0x9}}, /* 5 */
13312 {&identity, &identity, 1, {{{-20.0f}, {0.0f}, {0.5f}}}, {3.0f}, 0, {0x103d}},
13313 {&identity, &identity, 1, {{{20.0f}, {0.0f}, {0.5f}}}, {3.0f}, 0, {0x203e}},
13314 {&identity, &identity, 1, {{{0.0f}, {-20.0f}, {0.5f}}}, {3.0f}, 0, {0x803b}},
13315 {&identity, &identity, 1, {{{0.0f}, {20.0f}, {0.5f}}}, {3.0f}, 0, {0x4037}},
13316 {&identity, &identity, 1, {{{0.0f}, {0.0f}, {-20.0f}}}, {3.0f}, 0, {0x1001f}}, /* 10 */
13317 {&identity, &identity, 1, {{{0.0f}, {0.0f}, {20.0f}}}, {3.0f}, 0, {0x2002f}},
13318 {&identity, &identity, 1, {{{0.0f}, {0.0f}, {0.0f}}}, {5.0f}, 1, {0x7f}},
13319 {&identity, &identity, 1, {{{-0.5f}, {0.0f}, {0.0f}}}, {5.0f}, 1, {0x7f}},
13320 {&identity, &identity, 1, {{{-0.5f}, {0.0f}, {0.0f}}}, {1.0f}, 1, {0x51}},
13321 {&identity, &identity, 1, {{{-2.5f}, {0.0f}, {0.0f}}}, {1.0f}, 1, {0x41051}}, /* 15 */
13323 IDirect3DDevice7 *device;
13324 unsigned int i, j;
13325 DWORD result[3];
13326 ULONG refcount;
13327 HWND window;
13328 HRESULT hr;
13330 window = create_window();
13331 if (!(device = create_device(window, DDSCL_NORMAL)))
13333 skip("Failed to create a 3D device, skipping test.\n");
13334 DestroyWindow(window);
13335 return;
13338 hr = IDirect3DDevice7_SetClipPlane(device, 0, clip_plane);
13339 ok(SUCCEEDED(hr), "Failed to set user clip plane, hr %#x.\n", hr);
13341 IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &identity);
13343 for (i = 0; i < ARRAY_SIZE(tests); ++i)
13345 IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_VIEW, tests[i].view);
13346 IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, tests[i].proj);
13348 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CLIPPLANEENABLE,
13349 tests[i].enable_planes);
13350 ok(SUCCEEDED(hr), "Failed to enable / disable user clip planes, hr %#x.\n", hr);
13352 hr = IDirect3DDevice7_ComputeSphereVisibility(device, tests[i].center, tests[i].radius,
13353 tests[i].sphere_count, 0, result);
13354 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
13356 for (j = 0; j < tests[i].sphere_count; ++j)
13357 ok(result[j] == tests[i].expected[j], "Test %u sphere %u: expected %#x, got %#x.\n",
13358 i, j, tests[i].expected[j], result[j]);
13361 refcount = IDirect3DDevice7_Release(device);
13362 ok(!refcount, "Device has %u references left.\n", refcount);
13363 DestroyWindow(window);
13366 static void test_clip_planes_limits(void)
13368 IDirect3DDevice7 *device;
13369 D3DDEVICEDESC7 caps;
13370 unsigned int i;
13371 ULONG refcount;
13372 float plane[4];
13373 HWND window;
13374 DWORD state;
13375 HRESULT hr;
13377 window = create_window();
13378 if (!(device = create_device(window, DDSCL_NORMAL)))
13380 skip("Failed to create 3D device.\n");
13381 DestroyWindow(window);
13382 return;
13385 memset(&caps, 0, sizeof(caps));
13386 hr = IDirect3DDevice7_GetCaps(device, &caps);
13387 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
13389 trace("Max user clip planes: %u.\n", caps.wMaxUserClipPlanes);
13391 for (i = 0; i < caps.wMaxUserClipPlanes; ++i)
13393 memset(plane, 0xff, sizeof(plane));
13394 hr = IDirect3DDevice7_GetClipPlane(device, i, plane);
13395 ok(hr == D3D_OK, "Failed to get clip plane %u, hr %#x.\n", i, hr);
13396 ok(!plane[0] && !plane[1] && !plane[2] && !plane[3],
13397 "Got unexpected plane %u: %.8e, %.8e, %.8e, %.8e.\n",
13398 i, plane[0], plane[1], plane[2], plane[3]);
13401 plane[0] = 2.0f;
13402 plane[1] = 8.0f;
13403 plane[2] = 5.0f;
13404 for (i = 0; i < caps.wMaxUserClipPlanes; ++i)
13406 plane[3] = i;
13407 hr = IDirect3DDevice7_SetClipPlane(device, i, plane);
13408 ok(hr == D3D_OK, "Failed to set clip plane %u, hr %#x.\n", i, hr);
13410 for (i = 0; i < caps.wMaxUserClipPlanes; ++i)
13412 memset(plane, 0xff, sizeof(plane));
13413 hr = IDirect3DDevice7_GetClipPlane(device, i, plane);
13414 ok(hr == D3D_OK, "Failed to get clip plane %u, hr %#x.\n", i, hr);
13415 ok(plane[0] == 2.0f && plane[1] == 8.0f && plane[2] == 5.0f && plane[3] == i,
13416 "Got unexpected plane %u: %.8e, %.8e, %.8e, %.8e.\n",
13417 i, plane[0], plane[1], plane[2], plane[3]);
13420 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CLIPPLANEENABLE, 0xffffffff);
13421 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
13422 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_CLIPPLANEENABLE, &state);
13423 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
13424 ok(state == 0xffffffff, "Got unexpected state %#x.\n", state);
13425 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CLIPPLANEENABLE, 0x80000000);
13426 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
13427 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_CLIPPLANEENABLE, &state);
13428 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
13429 ok(state == 0x80000000, "Got unexpected state %#x.\n", state);
13431 refcount = IDirect3DDevice7_Release(device);
13432 ok(!refcount, "Device has %u references left.\n", refcount);
13433 DestroyWindow(window);
13436 static void test_texture_stages_limits(void)
13438 IDirectDrawSurface7 *texture;
13439 DDSURFACEDESC2 surface_desc;
13440 IDirect3DDevice7 *device;
13441 IDirectDraw7 *ddraw;
13442 IDirect3D7 *d3d;
13443 unsigned int i;
13444 ULONG refcount;
13445 HWND window;
13446 HRESULT hr;
13448 window = create_window();
13449 if (!(device = create_device(window, DDSCL_NORMAL)))
13451 skip("Failed to create 3D device.\n");
13452 DestroyWindow(window);
13453 return;
13455 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
13456 ok(SUCCEEDED(hr), "Failed to get Direct3D interface, hr %#x.\n", hr);
13457 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
13458 ok(SUCCEEDED(hr), "Failed to get DirectDraw interface, hr %#x.\n", hr);
13459 IDirect3D7_Release(d3d);
13461 memset(&surface_desc, 0, sizeof(surface_desc));
13462 surface_desc.dwSize = sizeof(surface_desc);
13463 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
13464 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
13465 surface_desc.dwWidth = 16;
13466 surface_desc.dwHeight = 16;
13467 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &texture, NULL);
13468 ok(hr == DD_OK, "Failed to create surface, hr %#x.\n", hr);
13470 for (i = 0; i < 8; ++i)
13472 hr = IDirect3DDevice7_SetTexture(device, i, texture);
13473 ok(hr == D3D_OK, "Failed to set texture %u, hr %#x.\n", i, hr);
13474 hr = IDirect3DDevice7_SetTexture(device, i, NULL);
13475 ok(hr == D3D_OK, "Failed to set texture %u, hr %#x.\n", i, hr);
13476 hr = IDirect3DDevice7_SetTextureStageState(device, i, D3DTSS_COLOROP, D3DTOP_ADD);
13477 ok(hr == D3D_OK, "Failed to set texture stage state %u, hr %#x.\n", i, hr);
13480 IDirectDrawSurface7_Release(texture);
13481 IDirectDraw7_Release(ddraw);
13482 refcount = IDirect3DDevice7_Release(device);
13483 ok(!refcount, "Device has %u references left.\n", refcount);
13484 DestroyWindow(window);
13487 static void test_set_render_state(void)
13489 IDirect3DDevice7 *device;
13490 ULONG refcount;
13491 HWND window;
13492 DWORD state;
13493 HRESULT hr;
13495 window = create_window();
13496 if (!(device = create_device(window, DDSCL_NORMAL)))
13498 skip("Failed to create 3D device.\n");
13499 DestroyWindow(window);
13500 return;
13503 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZVISIBLE, TRUE);
13504 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
13505 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZVISIBLE, FALSE);
13506 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
13508 /* States deprecated in D3D7 */
13509 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_TEXTUREHANDLE, 0);
13510 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
13511 state = 0xdeadbeef;
13512 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_TEXTUREHANDLE, &state);
13513 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
13514 ok(state == 0xdeadbeef, "Got unexpected render state %#x.\n", state);
13515 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_TEXTUREMAPBLEND, D3DTBLEND_MODULATE);
13516 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
13517 state = 0xdeadbeef;
13518 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_TEXTUREMAPBLEND, &state);
13519 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
13520 ok(state == 0xdeadbeef, "Got unexpected render state %#x.\n", state);
13522 refcount = IDirect3DDevice7_Release(device);
13523 ok(!refcount, "Device has %u references left.\n", refcount);
13524 DestroyWindow(window);
13527 static void test_map_synchronisation(void)
13529 LARGE_INTEGER frequency, diff, ts[3];
13530 IDirect3DVertexBuffer7 *buffer;
13531 unsigned int i, j, tri_count;
13532 D3DVERTEXBUFFERDESC vb_desc;
13533 IDirect3DDevice7 *device;
13534 BOOL unsynchronised, ret;
13535 IDirectDrawSurface7 *rt;
13536 IDirectDraw7 *ddraw;
13537 IDirect3D7 *d3d;
13538 D3DCOLOR colour;
13539 ULONG refcount;
13540 HWND window;
13541 HRESULT hr;
13543 static const struct
13545 unsigned int flags;
13546 BOOL unsynchronised;
13548 tests[] =
13550 {0, FALSE},
13551 {DDLOCK_NOOVERWRITE, TRUE},
13552 {DDLOCK_DISCARDCONTENTS, FALSE},
13553 {DDLOCK_NOOVERWRITE | DDLOCK_DISCARDCONTENTS, TRUE},
13556 static const struct quad
13558 struct
13560 struct vec3 position;
13561 DWORD diffuse;
13562 } strip[4];
13564 quad1 =
13567 {{-1.0f, -1.0f, 0.0f}, 0xffff0000},
13568 {{-1.0f, 1.0f, 0.0f}, 0xff00ff00},
13569 {{ 1.0f, -1.0f, 0.0f}, 0xff0000ff},
13570 {{ 1.0f, 1.0f, 0.0f}, 0xffffffff},
13573 quad2 =
13576 {{-1.0f, -1.0f, 0.0f}, 0xffffff00},
13577 {{-1.0f, 1.0f, 0.0f}, 0xffffff00},
13578 {{ 1.0f, -1.0f, 0.0f}, 0xffffff00},
13579 {{ 1.0f, 1.0f, 0.0f}, 0xffffff00},
13582 struct quad *quads;
13584 window = create_window();
13585 ok(!!window, "Failed to create a window.\n");
13587 if (!(device = create_device(window, DDSCL_NORMAL)))
13589 skip("Failed to create a D3D device, skipping tests.\n");
13590 DestroyWindow(window);
13591 return;
13594 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
13595 ok(SUCCEEDED(hr), "Failed to get Direct3D7 interface, hr %#x.\n", hr);
13596 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
13597 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
13598 /* Maps are always synchronised on WARP. */
13599 if (ddraw_is_warp(ddraw))
13601 skip("Running on WARP, skipping test.\n");
13602 goto done;
13605 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
13606 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
13608 tri_count = 0x1000;
13610 ret = QueryPerformanceFrequency(&frequency);
13611 ok(ret, "Failed to get performance counter frequency.\n");
13613 vb_desc.dwSize = sizeof(vb_desc);
13614 vb_desc.dwCaps = D3DVBCAPS_WRITEONLY;
13615 vb_desc.dwFVF = D3DFVF_XYZ | D3DFVF_DIFFUSE;
13616 vb_desc.dwNumVertices = tri_count + 2;
13617 hr = IDirect3D7_CreateVertexBuffer(d3d, &vb_desc, &buffer, 0);
13618 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
13619 hr = IDirect3DVertexBuffer7_Lock(buffer, DDLOCK_DISCARDCONTENTS, (void **)&quads, NULL);
13620 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
13621 for (j = 0; j < vb_desc.dwNumVertices / 4; ++j)
13623 quads[j] = quad1;
13625 hr = IDirect3DVertexBuffer7_Unlock(buffer);
13626 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
13628 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
13629 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
13631 /* Initial draw to initialise states, compile shaders, etc. */
13632 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff0000ff, 0.0f, 0);
13633 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
13634 hr = IDirect3DDevice7_BeginScene(device);
13635 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
13636 hr = IDirect3DDevice7_DrawPrimitiveVB(device, D3DPT_TRIANGLESTRIP, buffer, 0, vb_desc.dwNumVertices, 0);
13637 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
13638 hr = IDirect3DDevice7_EndScene(device);
13639 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
13640 /* Read the result to ensure the GPU has finished drawing. */
13641 colour = get_surface_color(rt, 320, 240);
13643 /* Time drawing tri_count triangles. */
13644 ret = QueryPerformanceCounter(&ts[0]);
13645 ok(ret, "Failed to read performance counter.\n");
13646 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff0000ff, 0.0f, 0);
13647 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
13648 hr = IDirect3DDevice7_BeginScene(device);
13649 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
13650 hr = IDirect3DDevice7_DrawPrimitiveVB(device, D3DPT_TRIANGLESTRIP, buffer, 0, vb_desc.dwNumVertices, 0);
13651 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
13652 hr = IDirect3DDevice7_EndScene(device);
13653 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
13654 colour = get_surface_color(rt, 320, 240);
13655 /* Time drawing a single triangle. */
13656 ret = QueryPerformanceCounter(&ts[1]);
13657 ok(ret, "Failed to read performance counter.\n");
13658 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff0000ff, 0.0f, 0);
13659 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
13660 hr = IDirect3DDevice7_BeginScene(device);
13661 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
13662 hr = IDirect3DDevice7_DrawPrimitiveVB(device, D3DPT_TRIANGLESTRIP, buffer, 0, 3, 0);
13663 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
13664 hr = IDirect3DDevice7_EndScene(device);
13665 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
13666 colour = get_surface_color(rt, 320, 240);
13667 ret = QueryPerformanceCounter(&ts[2]);
13668 ok(ret, "Failed to read performance counter.\n");
13670 IDirect3DVertexBuffer7_Release(buffer);
13672 /* Estimate the number of triangles we can draw in 100ms. */
13673 diff.QuadPart = ts[1].QuadPart - ts[0].QuadPart + ts[1].QuadPart - ts[2].QuadPart;
13674 tri_count = (tri_count * frequency.QuadPart) / (diff.QuadPart * 10);
13675 tri_count = ((tri_count + 2 + 3) & ~3) - 2;
13676 vb_desc.dwNumVertices = tri_count + 2;
13678 for (i = 0; i < ARRAY_SIZE(tests); ++i)
13680 hr = IDirect3D7_CreateVertexBuffer(d3d, &vb_desc, &buffer, 0);
13681 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
13682 hr = IDirect3DVertexBuffer7_Lock(buffer, DDLOCK_DISCARDCONTENTS, (void **)&quads, NULL);
13683 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
13684 for (j = 0; j < vb_desc.dwNumVertices / 4; ++j)
13686 quads[j] = quad1;
13688 hr = IDirect3DVertexBuffer7_Unlock(buffer);
13689 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
13691 /* Start a draw operation. */
13692 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff0000ff, 0.0f, 0);
13693 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
13694 hr = IDirect3DDevice7_BeginScene(device);
13695 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
13696 hr = IDirect3DDevice7_DrawPrimitiveVB(device, D3DPT_TRIANGLESTRIP, buffer, 0, vb_desc.dwNumVertices, 0);
13697 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
13698 hr = IDirect3DDevice7_EndScene(device);
13699 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
13701 /* Map the last quad while the draw is in progress. */
13702 hr = IDirect3DVertexBuffer7_Lock(buffer, DDLOCK_WAIT | tests[i].flags, (void **)&quads, NULL);
13703 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
13704 quads[(vb_desc.dwNumVertices / 4) - 1] = quad2;
13705 hr = IDirect3DVertexBuffer7_Unlock(buffer);
13706 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
13708 colour = get_surface_color(rt, 320, 240);
13709 unsynchronised = compare_color(colour, 0x00ffff00, 1);
13710 ok(tests[i].unsynchronised == unsynchronised, "Expected %s map for flags %#x.\n",
13711 tests[i].unsynchronised ? "unsynchronised" : "synchronised", tests[i].flags);
13713 IDirect3DVertexBuffer7_Release(buffer);
13716 IDirectDrawSurface7_Release(rt);
13717 done:
13718 IDirectDraw7_Release(ddraw);
13719 IDirect3D7_Release(d3d);
13720 refcount = IDirect3DDevice7_Release(device);
13721 ok(!refcount, "Device has %u references left.\n", refcount);
13722 DestroyWindow(window);
13725 static void test_depth_readback(void)
13727 DWORD depth, expected_depth, max_diff, raw_value, passed_fmts = 0;
13728 IDirectDrawSurface7 *rt, *ds;
13729 DDSURFACEDESC2 surface_desc;
13730 IDirect3DDevice7 *device;
13731 unsigned int i, x, y;
13732 IDirectDraw7 *ddraw;
13733 IDirect3D7 *d3d;
13734 ULONG refcount;
13735 HWND window;
13736 HRESULT hr;
13737 RECT r;
13738 BOOL all_zero, all_one, all_pass;
13740 static struct
13742 struct vec3 position;
13743 DWORD diffuse;
13745 quad[] =
13747 {{-1.0f, -1.0f, 0.1f}, 0xff00ff00},
13748 {{-1.0f, 1.0f, 0.0f}, 0xff00ff00},
13749 {{ 1.0f, -1.0f, 1.0f}, 0xff00ff00},
13750 {{ 1.0f, 1.0f, 0.9f}, 0xff00ff00},
13753 static const struct
13755 unsigned int z_depth, s_depth, z_mask, s_mask;
13756 BOOL todo;
13758 tests[] =
13760 {16, 0, 0x0000ffff, 0x00000000},
13761 {24, 0, 0x00ffffff, 0x00000000},
13762 {32, 0, 0x00ffffff, 0x00000000},
13763 {32, 8, 0x00ffffff, 0xff000000, TRUE},
13764 {32, 0, 0xffffffff, 0x00000000},
13767 window = create_window();
13768 ok(!!window, "Failed to create a window.\n");
13770 if (!(device = create_device(window, DDSCL_NORMAL)))
13772 skip("Failed to create a D3D device, skipping tests.\n");
13773 DestroyWindow(window);
13774 return;
13777 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
13778 ok(SUCCEEDED(hr), "Failed to get Direct3D7 interface, hr %#x.\n", hr);
13779 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
13780 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
13782 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
13783 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
13785 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
13786 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
13788 ds = get_depth_stencil(device);
13789 hr = IDirectDrawSurface7_DeleteAttachedSurface(rt, 0, ds);
13790 ok(SUCCEEDED(hr), "Failed to detach depth buffer, hr %#x.\n", hr);
13791 IDirectDrawSurface7_Release(ds);
13793 for (i = 0; i < ARRAY_SIZE(tests); ++i)
13795 memset(&surface_desc, 0, sizeof(surface_desc));
13796 surface_desc.dwSize = sizeof(surface_desc);
13797 surface_desc.dwFlags = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT;
13798 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | DDSCAPS_VIDEOMEMORY;
13799 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
13800 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_ZBUFFER;
13801 if (tests[i].s_depth)
13802 U4(surface_desc).ddpfPixelFormat.dwFlags |= DDPF_STENCILBUFFER;
13803 U1(U4(surface_desc).ddpfPixelFormat).dwZBufferBitDepth = tests[i].z_depth;
13804 U2(U4(surface_desc).ddpfPixelFormat).dwStencilBitDepth = tests[i].s_depth;
13805 U3(U4(surface_desc).ddpfPixelFormat).dwZBitMask = tests[i].z_mask;
13806 U4(U4(surface_desc).ddpfPixelFormat).dwStencilBitMask = tests[i].s_mask;
13807 surface_desc.dwWidth = 640;
13808 surface_desc.dwHeight = 480;
13809 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &ds, NULL);
13810 if (FAILED(hr))
13812 skip("Format %u not supported, skipping test.\n", i);
13813 continue;
13816 hr = IDirectDrawSurface_AddAttachedSurface(rt, ds);
13817 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
13818 hr = IDirect3DDevice7_SetRenderTarget(device, rt, 0);
13819 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
13821 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff0000ff, 1.0f, 0);
13822 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
13823 hr = IDirect3DDevice7_BeginScene(device);
13824 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
13825 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE, quad, 4, 0);
13826 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
13827 hr = IDirect3DDevice7_EndScene(device);
13828 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
13830 all_zero = all_one = all_pass = TRUE;
13831 for (y = 60; y < 480; y += 120)
13833 for (x = 80; x < 640; x += 160)
13835 SetRect(&r, x, y, x + 1, y + 1);
13836 memset(&surface_desc, 0, sizeof(surface_desc));
13837 surface_desc.dwSize = sizeof(surface_desc);
13838 hr = IDirectDrawSurface7_Lock(ds, &r, &surface_desc, DDLOCK_READONLY, NULL);
13839 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
13841 raw_value = *((DWORD *)surface_desc.lpSurface);
13842 if (raw_value)
13843 all_zero = FALSE;
13844 if (raw_value != 0x00ffffff)
13845 all_one = FALSE;
13847 depth = raw_value & tests[i].z_mask;
13848 expected_depth = (x * (0.9 / 640.0) + y * (0.1 / 480.0)) * tests[i].z_mask;
13849 max_diff = ((0.5f * 0.9f) / 640.0f) * tests[i].z_mask;
13850 /* This test is very reliably on AMD, but fails in a number of interesting ways on Nvidia GPUs:
13852 * Geforce 7 GPUs work only with D16. D24 and D24S8 return 0, D24X8 broken data.
13854 * Geforce 9 GPUs return return broken data for D16 that resembles the expected data in
13855 * the lower 8 bits and has 0xff in the upper 8 bits. D24X8 works, D24 and D24S8 return
13856 * 0x00ffffff.
13858 * Geforce GTX 650 has working D16 and D24, but D24S8 returns 0.
13860 * Arx Fatalis is broken on the Geforce 9 in the same way it was broken in Wine (bug 43654).
13861 * The !tests[i].s_depth is supposed to rule out D16 on GF9 and D24X8 on GF7. */
13862 todo_wine_if(tests[i].todo)
13863 ok(abs(expected_depth - depth) <= max_diff
13864 || (ddraw_is_nvidia(ddraw) && (all_zero || all_one || !tests[i].s_depth)),
13865 "Test %u: Got depth 0x%08x (diff %d), expected 0x%08x+/-%u, at %u, %u.\n",
13866 i, depth, expected_depth - depth, expected_depth, max_diff, x, y);
13867 if (abs(expected_depth - depth) > max_diff)
13868 all_pass = FALSE;
13870 hr = IDirectDrawSurface7_Unlock(ds, &r);
13871 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
13874 if (all_pass)
13875 passed_fmts++;
13877 hr = IDirectDrawSurface7_DeleteAttachedSurface(rt, 0, ds);
13878 ok(SUCCEEDED(hr), "Failed to detach depth buffer, hr %#x.\n", hr);
13879 IDirectDrawSurface7_Release(ds);
13882 ok(passed_fmts, "Not a single format passed the tests, this is bad even by Nvidia's standards.\n");
13884 IDirectDrawSurface7_Release(rt);
13885 IDirectDraw7_Release(ddraw);
13886 IDirect3D7_Release(d3d);
13887 refcount = IDirect3DDevice7_Release(device);
13888 ok(!refcount, "Device has %u references left.\n", refcount);
13889 DestroyWindow(window);
13892 static void test_clear(void)
13894 IDirect3DDevice7 *device;
13895 IDirectDrawSurface7 *rt;
13896 D3DVIEWPORT7 vp, old_vp;
13897 IDirectDraw7 *ddraw;
13898 D3DRECT rect_negneg;
13899 IDirect3D7 *d3d;
13900 D3DRECT rect[2];
13901 D3DCOLOR color;
13902 ULONG refcount;
13903 HWND window;
13904 HRESULT hr;
13906 window = create_window();
13907 if (!(device = create_device(window, DDSCL_NORMAL)))
13909 skip("Failed to create 3D device.\n");
13910 DestroyWindow(window);
13911 return;
13914 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
13915 ok(SUCCEEDED(hr), "Failed to get Direct3D7 interface, hr %#x.\n", hr);
13916 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
13917 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
13919 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
13920 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
13922 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0f, 0);
13923 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
13925 /* Positive x, negative y. */
13926 U1(rect[0]).x1 = 0;
13927 U2(rect[0]).y1 = 480;
13928 U3(rect[0]).x2 = 320;
13929 U4(rect[0]).y2 = 240;
13931 /* Positive x, positive y. */
13932 U1(rect[1]).x1 = 0;
13933 U2(rect[1]).y1 = 0;
13934 U3(rect[1]).x2 = 320;
13935 U4(rect[1]).y2 = 240;
13937 /* Clear 2 rectangles with one call. Unlike d3d8/9, the refrast does not
13938 * refuse negative rectangles, but it will not clear them either. */
13939 hr = IDirect3DDevice7_Clear(device, 2, rect, D3DCLEAR_TARGET, 0xffff0000, 0.0f, 0);
13940 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
13942 color = get_surface_color(rt, 160, 360);
13943 ok(compare_color(color, 0x00ffffff, 0), "Clear rectangle 3 (pos, neg) has color 0x%08x.\n", color);
13944 color = get_surface_color(rt, 160, 120);
13945 ok(compare_color(color, 0x00ff0000, 0), "Clear rectangle 1 (pos, pos) has color 0x%08x.\n", color);
13946 color = get_surface_color(rt, 480, 360);
13947 ok(compare_color(color, 0x00ffffff, 0), "Clear rectangle 4 (NULL) has color 0x%08x.\n", color);
13948 color = get_surface_color(rt, 480, 120);
13949 ok(compare_color(color, 0x00ffffff, 0), "Clear rectangle 4 (neg, neg) has color 0x%08x.\n", color);
13951 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
13952 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
13953 /* negative x, negative y.
13954 * Also ignored, except on WARP, which clears the entire screen. */
13955 rect_negneg.x1 = 640;
13956 rect_negneg.y1 = 240;
13957 rect_negneg.x2 = 320;
13958 rect_negneg.y2 = 0;
13959 hr = IDirect3DDevice7_Clear(device, 1, &rect_negneg, D3DCLEAR_TARGET, 0xff00ff00, 0.0f, 0);
13960 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
13962 color = get_surface_color(rt, 160, 360);
13963 ok(compare_color(color, 0x00ffffff, 0)
13964 || broken(ddraw_is_warp(ddraw) && compare_color(color, 0x0000ff00, 0)),
13965 "Got unexpected color 0x%08x.\n", color);
13966 color = get_surface_color(rt, 160, 120);
13967 ok(compare_color(color, 0x00ffffff, 0)
13968 || broken(ddraw_is_warp(ddraw) && compare_color(color, 0x0000ff00, 0)),
13969 "Got unexpected color 0x%08x.\n", color);
13970 color = get_surface_color(rt, 480, 360);
13971 ok(compare_color(color, 0x00ffffff, 0)
13972 || broken(ddraw_is_warp(ddraw) && compare_color(color, 0x0000ff00, 0)),
13973 "Got unexpected color 0x%08x.\n", color);
13974 color = get_surface_color(rt, 480, 120);
13975 ok(compare_color(color, 0x00ffffff, 0)
13976 || broken(ddraw_is_warp(ddraw) && compare_color(color, 0x0000ff00, 0)),
13977 "Got unexpected color 0x%08x.\n", color);
13979 /* Test how the viewport affects clears. */
13980 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0f, 0);
13981 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
13982 hr = IDirect3DDevice7_GetViewport(device, &old_vp);
13983 ok(SUCCEEDED(hr), "Failed to get viewport, hr %#x.\n", hr);
13985 vp.dwX = 160;
13986 vp.dwY = 120;
13987 vp.dwWidth = 160;
13988 vp.dwHeight = 120;
13989 vp.dvMinZ = 0.0f;
13990 vp.dvMaxZ = 1.0f;
13991 hr = IDirect3DDevice7_SetViewport(device, &vp);
13992 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#x.\n", hr);
13993 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff0000ff, 0.0f, 0);
13994 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
13996 vp.dwX = 320;
13997 vp.dwY = 240;
13998 vp.dwWidth = 320;
13999 vp.dwHeight = 240;
14000 vp.dvMinZ = 0.0f;
14001 vp.dvMaxZ = 1.0f;
14002 hr = IDirect3DDevice7_SetViewport(device, &vp);
14003 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#x.\n", hr);
14005 U1(rect[0]).x1 = 160;
14006 U2(rect[0]).y1 = 120;
14007 U3(rect[0]).x2 = 480;
14008 U4(rect[0]).y2 = 360;
14009 hr = IDirect3DDevice7_Clear(device, 1, &rect[0], D3DCLEAR_TARGET, 0xff00ff00, 0.0f, 0);
14010 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
14012 hr = IDirect3DDevice7_SetViewport(device, &old_vp);
14013 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#x.\n", hr);
14015 color = get_surface_color(rt, 158, 118);
14016 ok(compare_color(color, 0x00ffffff, 0), "(158, 118) has color 0x%08x.\n", color);
14017 color = get_surface_color(rt, 162, 118);
14018 ok(compare_color(color, 0x00ffffff, 0), "(162, 118) has color 0x%08x.\n", color);
14019 color = get_surface_color(rt, 158, 122);
14020 ok(compare_color(color, 0x00ffffff, 0), "(158, 122) has color 0x%08x.\n", color);
14021 color = get_surface_color(rt, 162, 122);
14022 ok(compare_color(color, 0x000000ff, 0), "(162, 122) has color 0x%08x.\n", color);
14024 color = get_surface_color(rt, 318, 238);
14025 ok(compare_color(color, 0x000000ff, 0), "(318, 238) has color 0x%08x.\n", color);
14026 color = get_surface_color(rt, 322, 238);
14027 ok(compare_color(color, 0x00ffffff, 0), "(322, 328) has color 0x%08x.\n", color);
14028 color = get_surface_color(rt, 318, 242);
14029 ok(compare_color(color, 0x00ffffff, 0), "(318, 242) has color 0x%08x.\n", color);
14030 color = get_surface_color(rt, 322, 242);
14031 ok(compare_color(color, 0x0000ff00, 0), "(322, 242) has color 0x%08x.\n", color);
14033 color = get_surface_color(rt, 478, 358);
14034 ok(compare_color(color, 0x0000ff00, 0), "(478, 358) has color 0x%08x.\n", color);
14035 color = get_surface_color(rt, 482, 358);
14036 ok(compare_color(color, 0x00ffffff, 0), "(482, 358) has color 0x%08x.\n", color);
14037 color = get_surface_color(rt, 478, 362);
14038 ok(compare_color(color, 0x00ffffff, 0), "(478, 362) has color 0x%08x.\n", color);
14039 color = get_surface_color(rt, 482, 362);
14040 ok(compare_color(color, 0x00ffffff, 0), "(482, 362) has color 0x%08x.\n", color);
14042 /* COLORWRITEENABLE, SRGBWRITEENABLE and scissor rectangles do not exist
14043 * in d3d7. */
14045 IDirectDrawSurface7_Release(rt);
14046 IDirectDraw7_Release(ddraw);
14047 IDirect3D7_Release(d3d);
14048 refcount = IDirect3DDevice7_Release(device);
14049 ok(!refcount, "Device has %u references left.\n", refcount);
14050 DestroyWindow(window);
14053 struct enum_surfaces_param
14055 IDirectDrawSurface7 *surfaces[8];
14056 unsigned int count;
14059 static HRESULT WINAPI enum_surfaces_cb(IDirectDrawSurface7 *surface, DDSURFACEDESC2 *desc, void *context)
14061 struct enum_surfaces_param *param = context;
14062 BOOL found = FALSE;
14063 unsigned int i;
14065 for (i = 0; i < ARRAY_SIZE(param->surfaces); ++i)
14067 if (param->surfaces[i] == surface)
14069 found = TRUE;
14070 break;
14074 ok(found, "Unexpected surface %p enumerated.\n", surface);
14075 IDirectDrawSurface7_Release(surface);
14076 ++param->count;
14078 return DDENUMRET_OK;
14081 static void test_enum_surfaces(void)
14083 struct enum_surfaces_param param = {{0}};
14084 DDSURFACEDESC2 desc;
14085 IDirectDraw7 *ddraw;
14086 HRESULT hr;
14088 ddraw = create_ddraw();
14089 ok(!!ddraw, "Failed to create a ddraw object.\n");
14091 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
14092 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
14094 memset(&desc, 0, sizeof(desc));
14095 desc.dwSize = sizeof(desc);
14096 desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_MIPMAPCOUNT;
14097 desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
14098 U2(desc).dwMipMapCount = 3;
14099 desc.dwWidth = 32;
14100 desc.dwHeight = 32;
14101 if (FAILED(IDirectDraw7_CreateSurface(ddraw, &desc, &param.surfaces[0], NULL)))
14103 win_skip("Failed to create a texture, skipping tests.\n");
14104 IDirectDraw7_Release(ddraw);
14105 return;
14108 hr = IDirectDrawSurface7_GetAttachedSurface(param.surfaces[0], &desc.ddsCaps, &param.surfaces[1]);
14109 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
14110 hr = IDirectDrawSurface7_GetAttachedSurface(param.surfaces[1], &desc.ddsCaps, &param.surfaces[2]);
14111 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
14112 hr = IDirectDrawSurface7_GetAttachedSurface(param.surfaces[2], &desc.ddsCaps, &param.surfaces[3]);
14113 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
14114 ok(!param.surfaces[3], "Got unexpected pointer %p.\n", param.surfaces[3]);
14116 hr = IDirectDraw7_EnumSurfaces(ddraw, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_ALL,
14117 &desc, &param, enum_surfaces_cb);
14118 ok(SUCCEEDED(hr), "Failed to enumerate surfaces, hr %#x.\n", hr);
14119 ok(param.count == 3, "Got unexpected number of enumerated surfaces %u.\n", param.count);
14121 param.count = 0;
14122 hr = IDirectDraw7_EnumSurfaces(ddraw, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_ALL,
14123 NULL, &param, enum_surfaces_cb);
14124 ok(SUCCEEDED(hr), "Failed to enumerate surfaces, hr %#x.\n", hr);
14125 ok(param.count == 3, "Got unexpected number of enumerated surfaces %u.\n", param.count);
14127 IDirectDrawSurface7_Release(param.surfaces[2]);
14128 IDirectDrawSurface7_Release(param.surfaces[1]);
14129 IDirectDrawSurface7_Release(param.surfaces[0]);
14130 IDirectDraw7_Release(ddraw);
14133 static void test_viewport(void)
14135 static struct
14137 D3DVIEWPORT7 vp;
14138 RECT expected_rect;
14139 const char *message;
14141 tests[] =
14143 {{ 0, 0, 640, 480}, { 0, 120, 479, 359}, "Viewport (0, 0) - (640, 480)"},
14144 {{ 0, 0, 320, 240}, { 0, 60, 239, 179}, "Viewport (0, 0) - (320, 240)"},
14145 {{ 0, 0, 1280, 960}, { 0, 240, 639, 479}, "Viewport (0, 0) - (1280, 960)"},
14146 {{ 0, 0, 2000, 1600}, {-10, -10, -10, -10}, "Viewport (0, 0) - (2000, 1600)"},
14147 {{100, 100, 640, 480}, {100, 220, 579, 459}, "Viewport (100, 100) - (640, 480)"},
14148 {{ 0, 0, 8192, 8192}, {-10, -10, -10, -10}, "Viewport (0, 0) - (8192, 8192)"},
14150 static struct vec3 quad[] =
14152 {-1.5f, -0.5f, 0.1f},
14153 {-1.5f, 0.5f, 0.1f},
14154 { 0.5f, -0.5f, 0.1f},
14155 { 0.5f, 0.5f, 0.1f},
14157 static const struct vec2 rt_sizes[] =
14159 {640, 480}, {1280, 960}, {320, 240}, {800, 600},
14161 IDirectDrawSurface7 *rt, *ds;
14162 DDSURFACEDESC2 surface_desc;
14163 IDirect3DDevice7 *device;
14164 IDirectDraw7 *ddraw;
14165 DDPIXELFORMAT z_fmt;
14166 unsigned int i, j;
14167 IDirect3D7 *d3d;
14168 ULONG refcount;
14169 HWND window;
14170 HRESULT hr;
14172 window = CreateWindowA("static", "d3d7_test", WS_OVERLAPPEDWINDOW,
14173 0, 0, 640, 480, 0, 0, 0, 0);
14174 if (!(device = create_device(window, DDSCL_NORMAL)))
14176 skip("Failed to create a 3D device, skipping test.\n");
14177 DestroyWindow(window);
14178 return;
14181 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
14182 ok(SUCCEEDED(hr), "Failed to get Direct3D7 interface, hr %#x.\n", hr);
14183 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
14184 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
14185 IDirect3D7_Release(d3d);
14187 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
14188 ok(SUCCEEDED(hr), "Failed to disable depth test, hr %#x.\n", hr);
14189 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
14190 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
14192 hr = IDirect3DDevice7_SetViewport(device, NULL);
14193 ok(hr == E_INVALIDARG, "Setting NULL viewport data returned unexpected hr %#x.\n", hr);
14195 ds = get_depth_stencil(device);
14196 memset(&surface_desc, 0, sizeof(surface_desc));
14197 surface_desc.dwSize = sizeof(surface_desc);
14198 hr = IDirectDrawSurface7_GetSurfaceDesc(ds, &surface_desc);
14199 z_fmt = U4(surface_desc).ddpfPixelFormat;
14201 for (i = 0; i < ARRAY_SIZE(rt_sizes); ++i)
14203 if (i)
14205 memset(&surface_desc, 0, sizeof(surface_desc));
14206 surface_desc.dwSize = sizeof(surface_desc);
14207 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
14208 surface_desc.dwWidth = rt_sizes[i].x;
14209 surface_desc.dwHeight = rt_sizes[i].y;
14210 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
14211 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &rt, NULL);
14212 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x (i %u).\n", hr, i);
14214 surface_desc.dwFlags = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT;
14215 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
14216 U4(surface_desc).ddpfPixelFormat = z_fmt;
14217 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &ds, NULL);
14218 ok(SUCCEEDED(hr), "Failed to create depth buffer, hr %#x (i %u).\n", hr, i);
14219 hr = IDirectDrawSurface7_AddAttachedSurface(rt, ds);
14220 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x (i %u).\n", hr, i);
14222 hr = IDirect3DDevice7_SetRenderTarget(device, rt, 0);
14223 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x (i %u).\n", hr, i);
14225 else
14227 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
14228 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
14231 for (j = 0; j < ARRAY_SIZE(tests); ++j)
14233 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff000000, 1.0f, 0);
14234 ok(SUCCEEDED(hr), "Failed to clear, hr %#x (i %u, j %u).\n", hr, i, j);
14236 hr = IDirect3DDevice7_SetViewport(device, &tests[j].vp);
14237 if (tests[j].vp.dwX + tests[j].vp.dwWidth > rt_sizes[i].x
14238 || tests[j].vp.dwY + tests[j].vp.dwHeight > rt_sizes[i].y)
14240 ok(hr == E_INVALIDARG, "Setting the viewport returned unexpected hr %#x (i %u, j %u).\n", hr, i, j);
14241 continue;
14243 else
14245 ok(SUCCEEDED(hr), "Failed to set the viewport, hr %#x (i %u, j %u).\n", hr, i, j);
14248 hr = IDirect3DDevice7_BeginScene(device);
14249 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x (i %u, j %u).\n", hr, i, j);
14250 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, quad, 4, 0);
14251 ok(SUCCEEDED(hr), "Got unexpected hr %#x (i %u, j %u).\n", hr, i, j);
14252 hr = IDirect3DDevice7_EndScene(device);
14253 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x (i %u, j %u).\n", hr, i, j);
14255 check_rect(rt, tests[j].expected_rect, tests[j].message);
14258 hr = IDirectDrawSurface7_DeleteAttachedSurface(rt, 0, ds);
14259 ok(SUCCEEDED(hr), "Failed to detach surface, hr %#x (i %u).\n", hr, i);
14260 IDirectDrawSurface7_Release(ds);
14262 IDirectDrawSurface7_Release(rt);
14265 refcount = IDirect3DDevice7_Release(device);
14266 ok(!refcount, "Device has %u references left.\n", refcount);
14267 DestroyWindow(window);
14270 START_TEST(ddraw7)
14272 DDDEVICEIDENTIFIER2 identifier;
14273 HMODULE module, dwmapi;
14274 DEVMODEW current_mode;
14275 IDirectDraw7 *ddraw;
14277 module = GetModuleHandleA("ddraw.dll");
14278 if (!(pDirectDrawCreateEx = (void *)GetProcAddress(module, "DirectDrawCreateEx")))
14280 win_skip("DirectDrawCreateEx not available, skipping tests.\n");
14281 return;
14284 if (!(ddraw = create_ddraw()))
14286 skip("Failed to create a ddraw object, skipping tests.\n");
14287 return;
14290 if (ddraw_get_identifier(ddraw, &identifier))
14292 trace("Driver string: \"%s\"\n", identifier.szDriver);
14293 trace("Description string: \"%s\"\n", identifier.szDescription);
14294 trace("Driver version %d.%d.%d.%d\n",
14295 HIWORD(U(identifier.liDriverVersion).HighPart), LOWORD(U(identifier.liDriverVersion).HighPart),
14296 HIWORD(U(identifier.liDriverVersion).LowPart), LOWORD(U(identifier.liDriverVersion).LowPart));
14298 IDirectDraw7_Release(ddraw);
14300 memset(&current_mode, 0, sizeof(current_mode));
14301 current_mode.dmSize = sizeof(current_mode);
14302 ok(EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &current_mode), "Failed to get display mode.\n");
14303 registry_mode.dmSize = sizeof(registry_mode);
14304 ok(EnumDisplaySettingsW(NULL, ENUM_REGISTRY_SETTINGS, &registry_mode), "Failed to get display mode.\n");
14305 if (registry_mode.dmPelsWidth != current_mode.dmPelsWidth
14306 || registry_mode.dmPelsHeight != current_mode.dmPelsHeight)
14308 skip("Current mode does not match registry mode, skipping test.\n");
14309 return;
14312 if ((dwmapi = LoadLibraryA("dwmapi.dll")))
14313 pDwmIsCompositionEnabled = (void *)GetProcAddress(dwmapi, "DwmIsCompositionEnabled");
14315 test_process_vertices();
14316 test_coop_level_create_device_window();
14317 test_clipper_blt();
14318 test_coop_level_d3d_state();
14319 test_surface_interface_mismatch();
14320 test_coop_level_threaded();
14321 test_depth_blit();
14322 test_texture_load_ckey();
14323 test_zenable();
14324 test_ck_rgba();
14325 test_ck_default();
14326 test_ck_complex();
14327 test_surface_qi();
14328 test_device_qi();
14329 test_wndproc();
14330 test_window_style();
14331 test_redundant_mode_set();
14332 test_coop_level_mode_set();
14333 test_coop_level_mode_set_multi();
14334 test_initialize();
14335 test_coop_level_surf_create();
14336 test_vb_discard();
14337 test_coop_level_multi_window();
14338 test_draw_strided();
14339 test_lighting();
14340 test_specular_lighting();
14341 test_clear_rect_count();
14342 test_coop_level_versions();
14343 test_fog_special();
14344 test_lighting_interface_versions();
14345 test_coop_level_activateapp();
14346 test_texturemanage();
14347 test_block_formats_creation();
14348 test_unsupported_formats();
14349 test_rt_caps();
14350 test_primary_caps();
14351 test_surface_lock();
14352 test_surface_discard();
14353 test_flip();
14354 test_set_surface_desc();
14355 test_user_memory_getdc();
14356 test_sysmem_overlay();
14357 test_primary_palette();
14358 test_surface_attachment();
14359 test_private_data();
14360 test_pixel_format();
14361 test_create_surface_pitch();
14362 test_mipmap();
14363 test_palette_complex();
14364 test_p8_blit();
14365 test_material();
14366 test_palette_gdi();
14367 test_palette_alpha();
14368 test_vb_writeonly();
14369 test_lost_device();
14370 test_resource_priority();
14371 test_surface_desc_lock();
14372 test_fog_interpolation();
14373 test_negative_fixedfunction_fog();
14374 test_table_fog_zw();
14375 test_signed_formats();
14376 test_color_fill();
14377 test_texcoordindex();
14378 test_colorkey_precision();
14379 test_range_colorkey();
14380 test_shademode();
14381 test_lockrect_invalid();
14382 test_yv12_overlay();
14383 test_offscreen_overlay();
14384 test_overlay_rect();
14385 test_blt();
14386 test_blt_z_alpha();
14387 test_color_clamping();
14388 test_getdc();
14389 test_draw_primitive();
14390 test_edge_antialiasing_blending();
14391 test_display_mode_surface_pixel_format();
14392 test_surface_desc_size();
14393 test_get_surface_from_dc();
14394 test_ck_operation();
14395 test_vb_refcount();
14396 test_compute_sphere_visibility();
14397 test_clip_planes_limits();
14398 test_texture_stages_limits();
14399 test_set_render_state();
14400 test_map_synchronisation();
14401 test_depth_readback();
14402 test_clear();
14403 test_enum_surfaces();
14404 test_viewport();