2 * Copyright 2011 Henri Verbeet for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include "wine/test.h"
22 static BOOL compare_color(D3DCOLOR c1, D3DCOLOR c2, BYTE max_diff)
24 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
26 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
28 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
30 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
34 static D3DCOLOR get_surface_color(IDirectDrawSurface *surface, UINT x, UINT y)
36 RECT rect = {x, y, x + 1, y + 1};
37 DDSURFACEDESC surface_desc;
41 memset(&surface_desc, 0, sizeof(surface_desc));
42 surface_desc.dwSize = sizeof(surface_desc);
44 hr = IDirectDrawSurface_Lock(surface, &rect, &surface_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
45 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
49 color = *((DWORD *)surface_desc.lpSurface) & 0x00ffffff;
51 hr = IDirectDrawSurface_Unlock(surface, NULL);
52 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
57 static HRESULT CALLBACK enum_z_fmt(GUID *guid, char *description, char *name,
58 D3DDEVICEDESC *hal_desc, D3DDEVICEDESC *hel_desc, void *ctx)
62 if (!IsEqualGUID(&IID_IDirect3DHALDevice, guid))
65 if (hal_desc->dwDeviceZBufferBitDepth & DDBD_32)
67 else if (hal_desc->dwDeviceZBufferBitDepth & DDBD_24)
69 else if (hal_desc->dwDeviceZBufferBitDepth & DDBD_16)
75 static IDirectDraw *create_ddraw(void)
79 if (FAILED(DirectDrawCreate(NULL, &ddraw, NULL)))
85 static IDirect3DDevice *create_device(IDirectDraw *ddraw, HWND window, DWORD coop_level)
87 IDirectDrawSurface *surface, *ds;
88 IDirect3DDevice *device = NULL;
89 DDSURFACEDESC surface_desc;
94 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, coop_level);
95 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
97 memset(&surface_desc, 0, sizeof(surface_desc));
98 surface_desc.dwSize = sizeof(surface_desc);
99 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
100 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
101 surface_desc.dwWidth = 640;
102 surface_desc.dwHeight = 480;
104 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
105 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
107 if (coop_level & DDSCL_NORMAL)
109 IDirectDrawClipper *clipper;
111 hr = IDirectDraw_CreateClipper(ddraw, 0, &clipper, NULL);
112 ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr);
113 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
114 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
115 hr = IDirectDrawSurface_SetClipper(surface, clipper);
116 ok(SUCCEEDED(hr), "Failed to set surface clipper, hr %#x.\n", hr);
117 IDirectDrawClipper_Release(clipper);
120 hr = IDirectDraw_QueryInterface(ddraw, &IID_IDirect3D, (void **)&d3d);
123 IDirectDrawSurface_Release(surface);
127 hr = IDirect3D_EnumDevices(d3d, enum_z_fmt, &z_depth);
128 ok(SUCCEEDED(hr), "Failed to enumerate z-formats, hr %#x.\n", hr);
129 IDirect3D_Release(d3d);
130 if (FAILED(hr) || !z_depth)
132 IDirectDrawSurface_Release(surface);
136 memset(&surface_desc, 0, sizeof(surface_desc));
137 surface_desc.dwSize = sizeof(surface_desc);
138 surface_desc.dwFlags = DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_WIDTH | DDSD_HEIGHT;
139 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
140 U2(surface_desc).dwZBufferBitDepth = z_depth;
141 surface_desc.dwWidth = 640;
142 surface_desc.dwHeight = 480;
143 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &ds, NULL);
144 ok(SUCCEEDED(hr), "Failed to create depth buffer, hr %#x.\n", hr);
147 IDirectDrawSurface_Release(surface);
151 hr = IDirectDrawSurface_AddAttachedSurface(surface, ds);
152 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
153 IDirectDrawSurface_Release(ds);
156 IDirectDrawSurface_Release(surface);
160 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirect3DHALDevice, (void **)&device);
161 IDirectDrawSurface_Release(surface);
168 static HRESULT CALLBACK restore_callback(IDirectDrawSurface *surface, DDSURFACEDESC *desc, void *context)
170 HRESULT hr = IDirectDrawSurface_Restore(surface);
171 ok(SUCCEEDED(hr), "Failed to restore surface, hr %#x.\n", hr);
172 IDirectDrawSurface_Release(surface);
177 static HRESULT restore_surfaces(IDirectDraw *ddraw)
179 return IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
180 NULL, NULL, restore_callback);
183 static void test_coop_level_create_device_window(void)
185 HWND focus_window, device_window;
189 focus_window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
190 0, 0, 640, 480, 0, 0, 0, 0);
191 if (!(ddraw = create_ddraw()))
193 skip("Failed to create a ddraw object, skipping test.\n");
194 DestroyWindow(focus_window);
198 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
199 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
200 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
201 ok(!device_window, "Unexpected device window found.\n");
202 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW);
203 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
204 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
205 ok(!device_window, "Unexpected device window found.\n");
206 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_NORMAL);
207 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
208 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
209 ok(!device_window, "Unexpected device window found.\n");
210 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_NORMAL | DDSCL_FULLSCREEN);
211 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
212 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
213 ok(!device_window, "Unexpected device window found.\n");
214 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
215 ok(hr == DDERR_NOFOCUSWINDOW || broken(hr == DDERR_INVALIDPARAMS), "Got unexpected hr %#x.\n", hr);
216 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
217 ok(!device_window, "Unexpected device window found.\n");
219 /* Windows versions before 98 / NT5 don't support DDSCL_CREATEDEVICEWINDOW. */
220 if (broken(hr == DDERR_INVALIDPARAMS))
222 win_skip("DDSCL_CREATEDEVICEWINDOW not supported, skipping test.\n");
223 IDirectDraw_Release(ddraw);
224 DestroyWindow(focus_window);
228 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
229 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
230 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
231 ok(!device_window, "Unexpected device window found.\n");
232 hr = IDirectDraw_SetCooperativeLevel(ddraw, focus_window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
233 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
234 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
235 ok(!device_window, "Unexpected device window found.\n");
237 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
238 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
239 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
240 ok(!device_window, "Unexpected device window found.\n");
241 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_SETFOCUSWINDOW
242 | DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
243 ok(hr == DDERR_NOHWND, "Got unexpected hr %#x.\n", hr);
244 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
245 ok(!!device_window, "Device window not found.\n");
247 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
248 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
249 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
250 ok(!device_window, "Unexpected device window found.\n");
251 hr = IDirectDraw_SetCooperativeLevel(ddraw, focus_window, DDSCL_SETFOCUSWINDOW
252 | DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
253 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
254 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
255 ok(!!device_window, "Device window not found.\n");
257 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
258 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
259 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
260 ok(!device_window, "Unexpected device window found.\n");
261 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
262 ok(hr == DDERR_NOFOCUSWINDOW, "Got unexpected hr %#x.\n", hr);
263 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
264 ok(!device_window, "Unexpected device window found.\n");
265 hr = IDirectDraw_SetCooperativeLevel(ddraw, focus_window, DDSCL_SETFOCUSWINDOW);
266 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
267 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
268 ok(!device_window, "Unexpected device window found.\n");
269 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
270 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
271 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
272 ok(!!device_window, "Device window not found.\n");
274 IDirectDraw_Release(ddraw);
275 DestroyWindow(focus_window);
278 static void test_clipper_blt(void)
280 IDirectDrawSurface *src_surface, *dst_surface;
281 RECT client_rect, src_rect, *rect;
282 IDirectDrawClipper *clipper;
283 DDSURFACEDESC surface_desc;
284 unsigned int i, j, x, y;
295 static const DWORD src_data[] =
297 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
298 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
299 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
301 static const D3DCOLOR expected1[] =
303 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
304 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
305 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
306 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
308 static const D3DCOLOR expected2[] =
310 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
311 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
312 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
313 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
316 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
317 10, 10, 640, 480, 0, 0, 0, 0);
318 ShowWindow(window, SW_SHOW);
319 if (!(ddraw = create_ddraw()))
321 skip("Failed to create a ddraw object, skipping test.\n");
322 DestroyWindow(window);
326 ret = GetClientRect(window, &client_rect);
327 ok(ret, "Failed to get client rect.\n");
328 ret = MapWindowPoints(window, NULL, (POINT *)&client_rect, 2);
329 ok(ret, "Failed to map client rect.\n");
331 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
332 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
334 hr = IDirectDraw_CreateClipper(ddraw, 0, &clipper, NULL);
335 ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr);
336 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
337 ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr);
338 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
339 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
340 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
341 ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr);
342 rgn_data = HeapAlloc(GetProcessHeap(), 0, ret);
343 hr = IDirectDrawClipper_GetClipList(clipper, NULL, rgn_data, &ret);
344 ok(SUCCEEDED(hr), "Failed to get clip list, hr %#x.\n", hr);
345 ok(rgn_data->rdh.dwSize == sizeof(rgn_data->rdh), "Got unexpected structure size %#x.\n", rgn_data->rdh.dwSize);
346 ok(rgn_data->rdh.iType == RDH_RECTANGLES, "Got unexpected type %#x.\n", rgn_data->rdh.iType);
347 ok(rgn_data->rdh.nCount == 1, "Got unexpected count %u.\n", rgn_data->rdh.nCount);
348 ok(rgn_data->rdh.nRgnSize == 16 || broken(rgn_data->rdh.nRgnSize == 168 /* NT4 */),
349 "Got unexpected region size %u.\n", rgn_data->rdh.nRgnSize);
350 ok(EqualRect(&rgn_data->rdh.rcBound, &client_rect),
351 "Got unexpected bounding rect {%d, %d, %d, %d}, expected {%d, %d, %d, %d}.\n",
352 rgn_data->rdh.rcBound.left, rgn_data->rdh.rcBound.top,
353 rgn_data->rdh.rcBound.right, rgn_data->rdh.rcBound.bottom,
354 client_rect.left, client_rect.top, client_rect.right, client_rect.bottom);
355 rect = (RECT *)&rgn_data->Buffer[0];
356 ok(EqualRect(rect, &client_rect),
357 "Got unexpected clip rect {%d, %d, %d, %d}, expected {%d, %d, %d, %d}.\n",
358 rect->left, rect->top, rect->right, rect->bottom,
359 client_rect.left, client_rect.top, client_rect.right, client_rect.bottom);
360 HeapFree(GetProcessHeap(), 0, rgn_data);
362 r1 = CreateRectRgn(0, 0, 320, 240);
363 ok(!!r1, "Failed to create region.\n");
364 r2 = CreateRectRgn(320, 240, 640, 480);
365 ok(!!r2, "Failed to create region.\n");
366 CombineRgn(r1, r1, r2, RGN_OR);
367 ret = GetRegionData(r1, 0, NULL);
368 rgn_data = HeapAlloc(GetProcessHeap(), 0, ret);
369 ret = GetRegionData(r1, ret, rgn_data);
370 ok(!!ret, "Failed to get region data.\n");
375 hr = IDirectDrawClipper_SetClipList(clipper, rgn_data, 0);
376 ok(hr == DDERR_CLIPPERISUSINGHWND, "Got unexpected hr %#x.\n", hr);
377 hr = IDirectDrawClipper_SetHWnd(clipper, 0, NULL);
378 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
379 hr = IDirectDrawClipper_SetClipList(clipper, rgn_data, 0);
380 ok(SUCCEEDED(hr), "Failed to set clip list, hr %#x.\n", hr);
382 HeapFree(GetProcessHeap(), 0, rgn_data);
384 memset(&surface_desc, 0, sizeof(surface_desc));
385 surface_desc.dwSize = sizeof(surface_desc);
386 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
387 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
388 surface_desc.dwWidth = 640;
389 surface_desc.dwHeight = 480;
390 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
391 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB;
392 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount = 32;
393 U2(surface_desc.ddpfPixelFormat).dwRBitMask = 0x00ff0000;
394 U3(surface_desc.ddpfPixelFormat).dwGBitMask = 0x0000ff00;
395 U4(surface_desc.ddpfPixelFormat).dwBBitMask = 0x000000ff;
397 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &src_surface, NULL);
398 ok(SUCCEEDED(hr), "Failed to create source surface, hr %#x.\n", hr);
399 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &dst_surface, NULL);
400 ok(SUCCEEDED(hr), "Failed to create destination surface, hr %#x.\n", hr);
402 memset(&fx, 0, sizeof(fx));
403 fx.dwSize = sizeof(fx);
404 hr = IDirectDrawSurface_Blt(src_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
405 ok(SUCCEEDED(hr), "Failed to clear source surface, hr %#x.\n", hr);
406 hr = IDirectDrawSurface_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
407 ok(SUCCEEDED(hr), "Failed to clear destination surface, hr %#x.\n", hr);
409 hr = IDirectDrawSurface_Lock(src_surface, NULL, &surface_desc, DDLOCK_WAIT, NULL);
410 ok(SUCCEEDED(hr), "Failed to lock source surface, hr %#x.\n", hr);
411 ok(U1(surface_desc).lPitch == 2560, "Got unexpected surface pitch %u.\n", U1(surface_desc).lPitch);
412 ptr = surface_desc.lpSurface;
413 memcpy(&ptr[ 0], &src_data[ 0], 6 * sizeof(DWORD));
414 memcpy(&ptr[ 640], &src_data[ 6], 6 * sizeof(DWORD));
415 memcpy(&ptr[1280], &src_data[12], 6 * sizeof(DWORD));
416 hr = IDirectDrawSurface_Unlock(src_surface, NULL);
417 ok(SUCCEEDED(hr), "Failed to unlock source surface, hr %#x.\n", hr);
419 hr = IDirectDrawSurface_SetClipper(dst_surface, clipper);
420 ok(SUCCEEDED(hr), "Failed to set clipper, hr %#x.\n", hr);
422 SetRect(&src_rect, 1, 1, 5, 2);
423 hr = IDirectDrawSurface_Blt(dst_surface, NULL, src_surface, &src_rect, DDBLT_WAIT, NULL);
424 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
425 for (i = 0; i < 4; ++i)
427 for (j = 0; j < 4; ++j)
429 x = 80 * ((2 * j) + 1);
430 y = 60 * ((2 * i) + 1);
431 color = get_surface_color(dst_surface, x, y);
432 ok(compare_color(color, expected1[i * 4 + j], 1),
433 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected1[i * 4 + j], x, y, color);
437 U5(fx).dwFillColor = 0xff0000ff;
438 hr = IDirectDrawSurface_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
439 ok(SUCCEEDED(hr), "Failed to clear destination surface, hr %#x.\n", hr);
440 for (i = 0; i < 4; ++i)
442 for (j = 0; j < 4; ++j)
444 x = 80 * ((2 * j) + 1);
445 y = 60 * ((2 * i) + 1);
446 color = get_surface_color(dst_surface, x, y);
447 ok(compare_color(color, expected2[i * 4 + j], 1),
448 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected2[i * 4 + j], x, y, color);
452 hr = IDirectDrawSurface_BltFast(dst_surface, 0, 0, src_surface, NULL, DDBLTFAST_WAIT);
453 ok(hr == DDERR_BLTFASTCANTCLIP || broken(hr == E_NOTIMPL /* NT4 */), "Got unexpected hr %#x.\n", hr);
455 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
456 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
457 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
458 ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr);
459 DestroyWindow(window);
460 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
461 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
462 hr = IDirectDrawClipper_SetHWnd(clipper, 0, NULL);
463 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
464 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
465 ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr);
466 hr = IDirectDrawClipper_SetClipList(clipper, NULL, 0);
467 ok(SUCCEEDED(hr), "Failed to set clip list, hr %#x.\n", hr);
468 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
469 ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr);
470 hr = IDirectDrawSurface_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
471 ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr);
473 IDirectDrawSurface_Release(dst_surface);
474 IDirectDrawSurface_Release(src_surface);
475 IDirectDrawClipper_Release(clipper);
476 IDirectDraw_Release(ddraw);
479 static void test_coop_level_d3d_state(void)
481 D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
482 D3DMATERIALHANDLE background_handle;
483 IDirectDrawSurface *rt, *surface;
484 IDirect3DMaterial *background;
485 IDirect3DViewport *viewport;
486 IDirect3DDevice *device;
487 D3DMATERIAL material;
495 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
496 0, 0, 640, 480, 0, 0, 0, 0);
497 if (!(ddraw = create_ddraw()))
499 skip("Failed to create ddraw object, skipping test.\n");
500 DestroyWindow(window);
503 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
505 skip("Failed to create D3D device, skipping test.\n");
506 IDirectDraw_Release(ddraw);
507 DestroyWindow(window);
511 hr = IDirect3DDevice_GetDirect3D(device, &d3d);
512 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
513 hr = IDirect3D_CreateViewport(d3d, &viewport, NULL);
514 ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
515 hr = IDirect3D_CreateMaterial(d3d, &background, NULL);
516 ok(SUCCEEDED(hr), "Failed to create material, hr %#x.\n", hr);
517 IDirect3D_Release(d3d);
519 hr = IDirect3DDevice_AddViewport(device, viewport);
520 ok(SUCCEEDED(hr), "Failed to add viewport, hr %#x.\n", hr);
521 memset(&vp, 0, sizeof(vp));
522 vp.dwSize = sizeof(vp);
527 vp.dvScaleX = 320.0f;
528 vp.dvScaleY = 240.0f;
533 hr = IDirect3DViewport_SetViewport(viewport, &vp);
534 ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
536 memset(&material, 0, sizeof(material));
537 material.dwSize = sizeof(material);
538 U1(U(material).diffuse).r = 1.0f;
539 U2(U(material).diffuse).g = 0.0f;
540 U3(U(material).diffuse).b = 0.0f;
541 U4(U(material).diffuse).a = 1.0f;
542 hr = IDirect3DMaterial_SetMaterial(background, &material);
543 ok(SUCCEEDED(hr), "Failed to set material data, hr %#x.\n", hr);
544 hr = IDirect3DMaterial_GetHandle(background, device, &background_handle);
545 ok(SUCCEEDED(hr), "Failed to get material handle, hr %#x.\n", hr);
546 hr = IDirect3DViewport_SetBackground(viewport, background_handle);
547 ok(SUCCEEDED(hr), "Failed to set viewport background, hr %#x.\n", hr);
549 hr = IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&rt);
550 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
551 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
552 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
553 color = get_surface_color(rt, 320, 240);
554 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
556 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
557 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
558 hr = IDirectDrawSurface_IsLost(rt);
559 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
560 hr = restore_surfaces(ddraw);
561 ok(SUCCEEDED(hr), "Failed to restore surfaces, hr %#x.\n", hr);
563 memset(&material, 0, sizeof(material));
564 material.dwSize = sizeof(material);
565 U1(U(material).diffuse).r = 0.0f;
566 U2(U(material).diffuse).g = 1.0f;
567 U3(U(material).diffuse).b = 0.0f;
568 U4(U(material).diffuse).a = 1.0f;
569 hr = IDirect3DMaterial_SetMaterial(background, &material);
570 ok(SUCCEEDED(hr), "Failed to set material data, hr %#x.\n", hr);
572 hr = IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&surface);
573 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
574 ok(surface == rt, "Got unexpected surface %p.\n", surface);
575 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
576 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
577 color = get_surface_color(rt, 320, 240);
578 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
580 hr = IDirect3DDevice_DeleteViewport(device, viewport);
581 ok(SUCCEEDED(hr), "Failed to delete viewport, hr %#x.\n", hr);
582 IDirect3DMaterial_Release(background);
583 IDirect3DViewport_Release(viewport);
584 IDirectDrawSurface_Release(surface);
585 IDirectDrawSurface_Release(rt);
586 IDirect3DDevice_Release(device);
587 IDirectDraw_Release(ddraw);
588 DestroyWindow(window);
591 static void test_surface_interface_mismatch(void)
593 IDirectDraw *ddraw = NULL;
594 IDirect3D *d3d = NULL;
595 IDirectDrawSurface *surface = NULL, *ds;
596 IDirectDrawSurface3 *surface3 = NULL;
597 IDirect3DDevice *device = NULL;
598 IDirect3DViewport *viewport = NULL;
599 IDirect3DMaterial *background = NULL;
600 DDSURFACEDESC surface_desc;
606 D3DMATERIAL material;
607 D3DMATERIALHANDLE background_handle;
608 D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
610 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
611 0, 0, 640, 480, 0, 0, 0, 0);
613 if (!(ddraw = create_ddraw()))
615 skip("Failed to create a ddraw object, skipping test.\n");
619 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
620 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
622 memset(&surface_desc, 0, sizeof(surface_desc));
623 surface_desc.dwSize = sizeof(surface_desc);
624 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
625 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
626 surface_desc.dwWidth = 640;
627 surface_desc.dwHeight = 480;
629 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
630 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
632 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirectDrawSurface3, (void **)&surface3);
635 skip("Failed to get the IDirectDrawSurface3 interface, skipping test.\n");
639 hr = IDirectDraw_QueryInterface(ddraw, &IID_IDirect3D, (void **)&d3d);
642 skip("Failed to get the IDirect3D interface, skipping test.\n");
646 hr = IDirect3D_EnumDevices(d3d, enum_z_fmt, &z_depth);
647 if (FAILED(hr) || !z_depth)
649 skip("No depth buffer formats available, skipping test.\n");
653 memset(&surface_desc, 0, sizeof(surface_desc));
654 surface_desc.dwSize = sizeof(surface_desc);
655 surface_desc.dwFlags = DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_WIDTH | DDSD_HEIGHT;
656 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
657 surface_desc.dwZBufferBitDepth = z_depth;
658 surface_desc.dwWidth = 640;
659 surface_desc.dwHeight = 480;
660 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &ds, NULL);
661 ok(SUCCEEDED(hr), "Failed to create depth buffer, hr %#x.\n", hr);
665 /* Using a different surface interface version still works */
666 hr = IDirectDrawSurface3_AddAttachedSurface(surface3, (IDirectDrawSurface3 *)ds);
667 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
668 IDirectDrawSurface_Release(ds);
673 hr = IDirectDrawSurface3_QueryInterface(surface3, &IID_IDirect3DHALDevice, (void **)&device);
674 ok(SUCCEEDED(hr), "Failed to create d3d device.\n");
678 hr = IDirect3D_CreateViewport(d3d, &viewport, NULL);
679 ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
680 hr = IDirect3D_CreateMaterial(d3d, &background, NULL);
681 ok(SUCCEEDED(hr), "Failed to create material, hr %#x.\n", hr);
683 hr = IDirect3DDevice_AddViewport(device, viewport);
684 ok(SUCCEEDED(hr), "Failed to add viewport, hr %#x.\n", hr);
685 memset(&vp, 0, sizeof(vp));
686 vp.dwSize = sizeof(vp);
691 vp.dvScaleX = 320.0f;
692 vp.dvScaleY = 240.0f;
697 hr = IDirect3DViewport_SetViewport(viewport, &vp);
698 ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
700 memset(&material, 0, sizeof(material));
701 material.dwSize = sizeof(material);
702 U1(U(material).diffuse).r = 1.0f;
703 U2(U(material).diffuse).g = 0.0f;
704 U3(U(material).diffuse).b = 0.0f;
705 U4(U(material).diffuse).a = 1.0f;
706 hr = IDirect3DMaterial_SetMaterial(background, &material);
707 ok(SUCCEEDED(hr), "Failed to set material data, hr %#x.\n", hr);
708 hr = IDirect3DMaterial_GetHandle(background, device, &background_handle);
709 ok(SUCCEEDED(hr), "Failed to get material handle, hr %#x.\n", hr);
710 hr = IDirect3DViewport_SetBackground(viewport, background_handle);
711 ok(SUCCEEDED(hr), "Failed to set viewport background, hr %#x.\n", hr);
713 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
714 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
715 color = get_surface_color(surface, 320, 240);
716 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
721 IDirect3DDevice2_DeleteViewport(device, viewport);
722 IDirect3DViewport2_Release(viewport);
724 if (background) IDirect3DMaterial2_Release(background);
725 if (surface3) IDirectDrawSurface3_Release(surface3);
726 if (surface) IDirectDrawSurface7_Release(surface);
727 if (device) IDirect3DDevice2_Release(device);
728 if (d3d) IDirect3D7_Release(d3d);
729 if (ddraw) IDirectDraw7_Release(ddraw);
730 DestroyWindow(window);
735 test_coop_level_create_device_window();
737 test_coop_level_d3d_state();
738 test_surface_interface_mismatch();