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
20 #include "wine/test.h"
23 struct create_window_thread_param
26 HANDLE window_created;
27 HANDLE destroy_window;
31 static BOOL compare_color(D3DCOLOR c1, D3DCOLOR c2, BYTE max_diff)
33 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
35 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
37 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
39 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
43 static DWORD WINAPI create_window_thread_proc(void *param)
45 struct create_window_thread_param *p = param;
49 p->window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
50 0, 0, 640, 480, 0, 0, 0, 0);
51 ret = SetEvent(p->window_created);
52 ok(ret, "SetEvent failed, last error %#x.\n", GetLastError());
58 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
59 DispatchMessage(&msg);
60 res = WaitForSingleObject(p->destroy_window, 100);
61 if (res == WAIT_OBJECT_0)
63 if (res != WAIT_TIMEOUT)
65 ok(0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
70 DestroyWindow(p->window);
75 static void create_window_thread(struct create_window_thread_param *p)
79 p->window_created = CreateEvent(NULL, FALSE, FALSE, NULL);
80 ok(!!p->window_created, "CreateEvent failed, last error %#x.\n", GetLastError());
81 p->destroy_window = CreateEvent(NULL, FALSE, FALSE, NULL);
82 ok(!!p->destroy_window, "CreateEvent failed, last error %#x.\n", GetLastError());
83 p->thread = CreateThread(NULL, 0, create_window_thread_proc, p, 0, &tid);
84 ok(!!p->thread, "Failed to create thread, last error %#x.\n", GetLastError());
85 res = WaitForSingleObject(p->window_created, INFINITE);
86 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
89 static void destroy_window_thread(struct create_window_thread_param *p)
91 SetEvent(p->destroy_window);
92 WaitForSingleObject(p->thread, INFINITE);
93 CloseHandle(p->destroy_window);
94 CloseHandle(p->window_created);
95 CloseHandle(p->thread);
98 static D3DCOLOR get_surface_color(IDirectDrawSurface *surface, UINT x, UINT y)
100 RECT rect = {x, y, x + 1, y + 1};
101 DDSURFACEDESC surface_desc;
105 memset(&surface_desc, 0, sizeof(surface_desc));
106 surface_desc.dwSize = sizeof(surface_desc);
108 hr = IDirectDrawSurface_Lock(surface, &rect, &surface_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
109 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
113 color = *((DWORD *)surface_desc.lpSurface) & 0x00ffffff;
115 hr = IDirectDrawSurface_Unlock(surface, NULL);
116 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
121 static void emit_process_vertices(void **ptr, DWORD vertex_count)
123 D3DINSTRUCTION *inst = *ptr;
124 D3DPROCESSVERTICES *pv = (D3DPROCESSVERTICES *)(inst + 1);
126 inst->bOpcode = D3DOP_PROCESSVERTICES;
127 inst->bSize = sizeof(*pv);
130 pv->dwFlags = D3DPROCESSVERTICES_COPY;
133 pv->dwCount = vertex_count;
139 static void emit_set_rs(void **ptr, D3DRENDERSTATETYPE state, DWORD value)
141 D3DINSTRUCTION *inst = *ptr;
142 D3DSTATE *rs = (D3DSTATE *)(inst + 1);
144 inst->bOpcode = D3DOP_STATERENDER;
145 inst->bSize = sizeof(*rs);
148 U1(*rs).drstRenderStateType = state;
149 U2(*rs).dwArg[0] = value;
154 static void emit_tquad(void **ptr, WORD base_idx)
156 D3DINSTRUCTION *inst = *ptr;
157 D3DTRIANGLE *tri = (D3DTRIANGLE *)(inst + 1);
159 inst->bOpcode = D3DOP_TRIANGLE;
160 inst->bSize = sizeof(*tri);
164 tri->v2 = base_idx + 1;
165 tri->v3 = base_idx + 2;
166 tri->wFlags = D3DTRIFLAG_START;
169 tri->v1 = base_idx + 2;
170 tri->v2 = base_idx + 1;
171 tri->v3 = base_idx + 3;
172 tri->wFlags = D3DTRIFLAG_ODD;
178 static void emit_end(void **ptr)
180 D3DINSTRUCTION *inst = *ptr;
182 inst->bOpcode = D3DOP_EXIT;
189 static HRESULT CALLBACK enum_z_fmt(GUID *guid, char *description, char *name,
190 D3DDEVICEDESC *hal_desc, D3DDEVICEDESC *hel_desc, void *ctx)
192 DWORD *z_depth = ctx;
194 if (!IsEqualGUID(&IID_IDirect3DHALDevice, guid))
195 return D3DENUMRET_OK;
197 if (hal_desc->dwDeviceZBufferBitDepth & DDBD_32)
199 else if (hal_desc->dwDeviceZBufferBitDepth & DDBD_24)
201 else if (hal_desc->dwDeviceZBufferBitDepth & DDBD_16)
207 static IDirectDraw *create_ddraw(void)
211 if (FAILED(DirectDrawCreate(NULL, &ddraw, NULL)))
217 static IDirect3DDevice *create_device(IDirectDraw *ddraw, HWND window, DWORD coop_level)
219 IDirectDrawSurface *surface, *ds;
220 IDirect3DDevice *device = NULL;
221 DDSURFACEDESC surface_desc;
226 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, coop_level);
227 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
229 memset(&surface_desc, 0, sizeof(surface_desc));
230 surface_desc.dwSize = sizeof(surface_desc);
231 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
232 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
233 surface_desc.dwWidth = 640;
234 surface_desc.dwHeight = 480;
236 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
237 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
239 if (coop_level & DDSCL_NORMAL)
241 IDirectDrawClipper *clipper;
243 hr = IDirectDraw_CreateClipper(ddraw, 0, &clipper, NULL);
244 ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr);
245 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
246 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
247 hr = IDirectDrawSurface_SetClipper(surface, clipper);
248 ok(SUCCEEDED(hr), "Failed to set surface clipper, hr %#x.\n", hr);
249 IDirectDrawClipper_Release(clipper);
252 hr = IDirectDraw_QueryInterface(ddraw, &IID_IDirect3D, (void **)&d3d);
255 IDirectDrawSurface_Release(surface);
259 hr = IDirect3D_EnumDevices(d3d, enum_z_fmt, &z_depth);
260 ok(SUCCEEDED(hr), "Failed to enumerate z-formats, hr %#x.\n", hr);
261 IDirect3D_Release(d3d);
262 if (FAILED(hr) || !z_depth)
264 IDirectDrawSurface_Release(surface);
268 memset(&surface_desc, 0, sizeof(surface_desc));
269 surface_desc.dwSize = sizeof(surface_desc);
270 surface_desc.dwFlags = DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_WIDTH | DDSD_HEIGHT;
271 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
272 U2(surface_desc).dwZBufferBitDepth = z_depth;
273 surface_desc.dwWidth = 640;
274 surface_desc.dwHeight = 480;
275 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &ds, NULL);
276 ok(SUCCEEDED(hr), "Failed to create depth buffer, hr %#x.\n", hr);
279 IDirectDrawSurface_Release(surface);
283 hr = IDirectDrawSurface_AddAttachedSurface(surface, ds);
284 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
285 IDirectDrawSurface_Release(ds);
288 IDirectDrawSurface_Release(surface);
292 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirect3DHALDevice, (void **)&device);
293 IDirectDrawSurface_Release(surface);
300 static HRESULT CALLBACK restore_callback(IDirectDrawSurface *surface, DDSURFACEDESC *desc, void *context)
302 HRESULT hr = IDirectDrawSurface_Restore(surface);
303 ok(SUCCEEDED(hr), "Failed to restore surface, hr %#x.\n", hr);
304 IDirectDrawSurface_Release(surface);
309 static HRESULT restore_surfaces(IDirectDraw *ddraw)
311 return IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
312 NULL, NULL, restore_callback);
315 static void test_coop_level_create_device_window(void)
317 HWND focus_window, device_window;
321 focus_window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
322 0, 0, 640, 480, 0, 0, 0, 0);
323 if (!(ddraw = create_ddraw()))
325 skip("Failed to create a ddraw object, skipping test.\n");
326 DestroyWindow(focus_window);
330 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
331 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
332 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
333 ok(!device_window, "Unexpected device window found.\n");
334 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW);
335 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
336 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
337 ok(!device_window, "Unexpected device window found.\n");
338 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_NORMAL);
339 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
340 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
341 ok(!device_window, "Unexpected device window found.\n");
342 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_NORMAL | DDSCL_FULLSCREEN);
343 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
344 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
345 ok(!device_window, "Unexpected device window found.\n");
346 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
347 ok(hr == DDERR_NOFOCUSWINDOW || broken(hr == DDERR_INVALIDPARAMS), "Got unexpected hr %#x.\n", hr);
348 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
349 ok(!device_window, "Unexpected device window found.\n");
351 /* Windows versions before 98 / NT5 don't support DDSCL_CREATEDEVICEWINDOW. */
352 if (broken(hr == DDERR_INVALIDPARAMS))
354 win_skip("DDSCL_CREATEDEVICEWINDOW not supported, skipping test.\n");
355 IDirectDraw_Release(ddraw);
356 DestroyWindow(focus_window);
360 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
361 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
362 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
363 ok(!device_window, "Unexpected device window found.\n");
364 hr = IDirectDraw_SetCooperativeLevel(ddraw, focus_window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
365 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
366 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
367 ok(!device_window, "Unexpected device window found.\n");
369 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
370 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
371 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
372 ok(!device_window, "Unexpected device window found.\n");
373 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_SETFOCUSWINDOW
374 | DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
375 ok(hr == DDERR_NOHWND, "Got unexpected hr %#x.\n", hr);
376 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
377 ok(!!device_window, "Device window not found.\n");
379 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
380 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
381 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
382 ok(!device_window, "Unexpected device window found.\n");
383 hr = IDirectDraw_SetCooperativeLevel(ddraw, focus_window, DDSCL_SETFOCUSWINDOW
384 | DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
385 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
386 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
387 ok(!!device_window, "Device window not found.\n");
389 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
390 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
391 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
392 ok(!device_window, "Unexpected device window found.\n");
393 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
394 ok(hr == DDERR_NOFOCUSWINDOW, "Got unexpected hr %#x.\n", hr);
395 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
396 ok(!device_window, "Unexpected device window found.\n");
397 hr = IDirectDraw_SetCooperativeLevel(ddraw, focus_window, DDSCL_SETFOCUSWINDOW);
398 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
399 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
400 ok(!device_window, "Unexpected device window found.\n");
401 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
402 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
403 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
404 ok(!!device_window, "Device window not found.\n");
406 IDirectDraw_Release(ddraw);
407 DestroyWindow(focus_window);
410 static void test_clipper_blt(void)
412 IDirectDrawSurface *src_surface, *dst_surface;
413 RECT client_rect, src_rect, *rect;
414 IDirectDrawClipper *clipper;
415 DDSURFACEDESC surface_desc;
416 unsigned int i, j, x, y;
427 static const DWORD src_data[] =
429 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
430 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
431 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
433 static const D3DCOLOR expected1[] =
435 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
436 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
437 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
438 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
440 static const D3DCOLOR expected2[] =
442 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
443 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
444 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
445 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
448 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
449 10, 10, 640, 480, 0, 0, 0, 0);
450 ShowWindow(window, SW_SHOW);
451 if (!(ddraw = create_ddraw()))
453 skip("Failed to create a ddraw object, skipping test.\n");
454 DestroyWindow(window);
458 ret = GetClientRect(window, &client_rect);
459 ok(ret, "Failed to get client rect.\n");
460 ret = MapWindowPoints(window, NULL, (POINT *)&client_rect, 2);
461 ok(ret, "Failed to map client rect.\n");
463 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
464 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
466 hr = IDirectDraw_CreateClipper(ddraw, 0, &clipper, NULL);
467 ok(SUCCEEDED(hr), "Failed to create clipper, 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 = IDirectDrawClipper_SetHWnd(clipper, 0, window);
471 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
472 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
473 ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr);
474 rgn_data = HeapAlloc(GetProcessHeap(), 0, ret);
475 hr = IDirectDrawClipper_GetClipList(clipper, NULL, rgn_data, &ret);
476 ok(SUCCEEDED(hr), "Failed to get clip list, hr %#x.\n", hr);
477 ok(rgn_data->rdh.dwSize == sizeof(rgn_data->rdh), "Got unexpected structure size %#x.\n", rgn_data->rdh.dwSize);
478 ok(rgn_data->rdh.iType == RDH_RECTANGLES, "Got unexpected type %#x.\n", rgn_data->rdh.iType);
479 ok(rgn_data->rdh.nCount == 1, "Got unexpected count %u.\n", rgn_data->rdh.nCount);
480 ok(rgn_data->rdh.nRgnSize == 16 || broken(rgn_data->rdh.nRgnSize == 168 /* NT4 */),
481 "Got unexpected region size %u.\n", rgn_data->rdh.nRgnSize);
482 ok(EqualRect(&rgn_data->rdh.rcBound, &client_rect),
483 "Got unexpected bounding rect {%d, %d, %d, %d}, expected {%d, %d, %d, %d}.\n",
484 rgn_data->rdh.rcBound.left, rgn_data->rdh.rcBound.top,
485 rgn_data->rdh.rcBound.right, rgn_data->rdh.rcBound.bottom,
486 client_rect.left, client_rect.top, client_rect.right, client_rect.bottom);
487 rect = (RECT *)&rgn_data->Buffer[0];
488 ok(EqualRect(rect, &client_rect),
489 "Got unexpected clip rect {%d, %d, %d, %d}, expected {%d, %d, %d, %d}.\n",
490 rect->left, rect->top, rect->right, rect->bottom,
491 client_rect.left, client_rect.top, client_rect.right, client_rect.bottom);
492 HeapFree(GetProcessHeap(), 0, rgn_data);
494 r1 = CreateRectRgn(0, 0, 320, 240);
495 ok(!!r1, "Failed to create region.\n");
496 r2 = CreateRectRgn(320, 240, 640, 480);
497 ok(!!r2, "Failed to create region.\n");
498 CombineRgn(r1, r1, r2, RGN_OR);
499 ret = GetRegionData(r1, 0, NULL);
500 rgn_data = HeapAlloc(GetProcessHeap(), 0, ret);
501 ret = GetRegionData(r1, ret, rgn_data);
502 ok(!!ret, "Failed to get region data.\n");
507 hr = IDirectDrawClipper_SetClipList(clipper, rgn_data, 0);
508 ok(hr == DDERR_CLIPPERISUSINGHWND, "Got unexpected hr %#x.\n", hr);
509 hr = IDirectDrawClipper_SetHWnd(clipper, 0, NULL);
510 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
511 hr = IDirectDrawClipper_SetClipList(clipper, rgn_data, 0);
512 ok(SUCCEEDED(hr), "Failed to set clip list, hr %#x.\n", hr);
514 HeapFree(GetProcessHeap(), 0, rgn_data);
516 memset(&surface_desc, 0, sizeof(surface_desc));
517 surface_desc.dwSize = sizeof(surface_desc);
518 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
519 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
520 surface_desc.dwWidth = 640;
521 surface_desc.dwHeight = 480;
522 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
523 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB;
524 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount = 32;
525 U2(surface_desc.ddpfPixelFormat).dwRBitMask = 0x00ff0000;
526 U3(surface_desc.ddpfPixelFormat).dwGBitMask = 0x0000ff00;
527 U4(surface_desc.ddpfPixelFormat).dwBBitMask = 0x000000ff;
529 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &src_surface, NULL);
530 ok(SUCCEEDED(hr), "Failed to create source surface, hr %#x.\n", hr);
531 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &dst_surface, NULL);
532 ok(SUCCEEDED(hr), "Failed to create destination surface, hr %#x.\n", hr);
534 memset(&fx, 0, sizeof(fx));
535 fx.dwSize = sizeof(fx);
536 hr = IDirectDrawSurface_Blt(src_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
537 ok(SUCCEEDED(hr), "Failed to clear source surface, hr %#x.\n", hr);
538 hr = IDirectDrawSurface_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
539 ok(SUCCEEDED(hr), "Failed to clear destination surface, hr %#x.\n", hr);
541 hr = IDirectDrawSurface_Lock(src_surface, NULL, &surface_desc, DDLOCK_WAIT, NULL);
542 ok(SUCCEEDED(hr), "Failed to lock source surface, hr %#x.\n", hr);
543 ok(U1(surface_desc).lPitch == 2560, "Got unexpected surface pitch %u.\n", U1(surface_desc).lPitch);
544 ptr = surface_desc.lpSurface;
545 memcpy(&ptr[ 0], &src_data[ 0], 6 * sizeof(DWORD));
546 memcpy(&ptr[ 640], &src_data[ 6], 6 * sizeof(DWORD));
547 memcpy(&ptr[1280], &src_data[12], 6 * sizeof(DWORD));
548 hr = IDirectDrawSurface_Unlock(src_surface, NULL);
549 ok(SUCCEEDED(hr), "Failed to unlock source surface, hr %#x.\n", hr);
551 hr = IDirectDrawSurface_SetClipper(dst_surface, clipper);
552 ok(SUCCEEDED(hr), "Failed to set clipper, hr %#x.\n", hr);
554 SetRect(&src_rect, 1, 1, 5, 2);
555 hr = IDirectDrawSurface_Blt(dst_surface, NULL, src_surface, &src_rect, DDBLT_WAIT, NULL);
556 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
557 for (i = 0; i < 4; ++i)
559 for (j = 0; j < 4; ++j)
561 x = 80 * ((2 * j) + 1);
562 y = 60 * ((2 * i) + 1);
563 color = get_surface_color(dst_surface, x, y);
564 ok(compare_color(color, expected1[i * 4 + j], 1),
565 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected1[i * 4 + j], x, y, color);
569 U5(fx).dwFillColor = 0xff0000ff;
570 hr = IDirectDrawSurface_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
571 ok(SUCCEEDED(hr), "Failed to clear destination surface, hr %#x.\n", hr);
572 for (i = 0; i < 4; ++i)
574 for (j = 0; j < 4; ++j)
576 x = 80 * ((2 * j) + 1);
577 y = 60 * ((2 * i) + 1);
578 color = get_surface_color(dst_surface, x, y);
579 ok(compare_color(color, expected2[i * 4 + j], 1),
580 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected2[i * 4 + j], x, y, color);
584 hr = IDirectDrawSurface_BltFast(dst_surface, 0, 0, src_surface, NULL, DDBLTFAST_WAIT);
585 ok(hr == DDERR_BLTFASTCANTCLIP || broken(hr == E_NOTIMPL /* NT4 */), "Got unexpected hr %#x.\n", hr);
587 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
588 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
589 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
590 ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr);
591 DestroyWindow(window);
592 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
593 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
594 hr = IDirectDrawClipper_SetHWnd(clipper, 0, NULL);
595 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
596 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
597 ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr);
598 hr = IDirectDrawClipper_SetClipList(clipper, NULL, 0);
599 ok(SUCCEEDED(hr), "Failed to set clip list, hr %#x.\n", hr);
600 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
601 ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr);
602 hr = IDirectDrawSurface_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
603 ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr);
605 IDirectDrawSurface_Release(dst_surface);
606 IDirectDrawSurface_Release(src_surface);
607 IDirectDrawClipper_Release(clipper);
608 IDirectDraw_Release(ddraw);
611 static void test_coop_level_d3d_state(void)
613 D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
614 D3DMATERIALHANDLE background_handle;
615 IDirectDrawSurface *rt, *surface;
616 IDirect3DMaterial *background;
617 IDirect3DViewport *viewport;
618 IDirect3DDevice *device;
619 D3DMATERIAL material;
627 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
628 0, 0, 640, 480, 0, 0, 0, 0);
629 if (!(ddraw = create_ddraw()))
631 skip("Failed to create ddraw object, skipping test.\n");
632 DestroyWindow(window);
635 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
637 skip("Failed to create D3D device, skipping test.\n");
638 IDirectDraw_Release(ddraw);
639 DestroyWindow(window);
643 hr = IDirect3DDevice_GetDirect3D(device, &d3d);
644 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
645 hr = IDirect3D_CreateViewport(d3d, &viewport, NULL);
646 ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
647 hr = IDirect3D_CreateMaterial(d3d, &background, NULL);
648 ok(SUCCEEDED(hr), "Failed to create material, hr %#x.\n", hr);
649 IDirect3D_Release(d3d);
651 hr = IDirect3DDevice_AddViewport(device, viewport);
652 ok(SUCCEEDED(hr), "Failed to add viewport, hr %#x.\n", hr);
653 memset(&vp, 0, sizeof(vp));
654 vp.dwSize = sizeof(vp);
659 vp.dvScaleX = 320.0f;
660 vp.dvScaleY = 240.0f;
665 hr = IDirect3DViewport_SetViewport(viewport, &vp);
666 ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
668 memset(&material, 0, sizeof(material));
669 material.dwSize = sizeof(material);
670 U1(U(material).diffuse).r = 1.0f;
671 U2(U(material).diffuse).g = 0.0f;
672 U3(U(material).diffuse).b = 0.0f;
673 U4(U(material).diffuse).a = 1.0f;
674 hr = IDirect3DMaterial_SetMaterial(background, &material);
675 ok(SUCCEEDED(hr), "Failed to set material data, hr %#x.\n", hr);
676 hr = IDirect3DMaterial_GetHandle(background, device, &background_handle);
677 ok(SUCCEEDED(hr), "Failed to get material handle, hr %#x.\n", hr);
678 hr = IDirect3DViewport_SetBackground(viewport, background_handle);
679 ok(SUCCEEDED(hr), "Failed to set viewport background, hr %#x.\n", hr);
681 hr = IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&rt);
682 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
683 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
684 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
685 color = get_surface_color(rt, 320, 240);
686 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
688 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
689 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
690 hr = IDirectDrawSurface_IsLost(rt);
691 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
692 hr = restore_surfaces(ddraw);
693 ok(SUCCEEDED(hr), "Failed to restore surfaces, hr %#x.\n", hr);
695 memset(&material, 0, sizeof(material));
696 material.dwSize = sizeof(material);
697 U1(U(material).diffuse).r = 0.0f;
698 U2(U(material).diffuse).g = 1.0f;
699 U3(U(material).diffuse).b = 0.0f;
700 U4(U(material).diffuse).a = 1.0f;
701 hr = IDirect3DMaterial_SetMaterial(background, &material);
702 ok(SUCCEEDED(hr), "Failed to set material data, hr %#x.\n", hr);
704 hr = IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&surface);
705 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
706 ok(surface == rt, "Got unexpected surface %p.\n", surface);
707 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
708 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
709 color = get_surface_color(rt, 320, 240);
710 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
712 hr = IDirect3DDevice_DeleteViewport(device, viewport);
713 ok(SUCCEEDED(hr), "Failed to delete viewport, hr %#x.\n", hr);
714 IDirect3DMaterial_Release(background);
715 IDirect3DViewport_Release(viewport);
716 IDirectDrawSurface_Release(surface);
717 IDirectDrawSurface_Release(rt);
718 IDirect3DDevice_Release(device);
719 IDirectDraw_Release(ddraw);
720 DestroyWindow(window);
723 static void test_surface_interface_mismatch(void)
725 IDirectDraw *ddraw = NULL;
726 IDirect3D *d3d = NULL;
727 IDirectDrawSurface *surface = NULL, *ds;
728 IDirectDrawSurface3 *surface3 = NULL;
729 IDirect3DDevice *device = NULL;
730 IDirect3DViewport *viewport = NULL;
731 IDirect3DMaterial *background = NULL;
732 DDSURFACEDESC surface_desc;
739 D3DMATERIAL material;
740 D3DMATERIALHANDLE background_handle;
741 D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
743 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
744 0, 0, 640, 480, 0, 0, 0, 0);
746 if (!(ddraw = create_ddraw()))
748 skip("Failed to create a ddraw object, skipping test.\n");
752 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
753 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
755 memset(&surface_desc, 0, sizeof(surface_desc));
756 surface_desc.dwSize = sizeof(surface_desc);
757 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
758 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
759 surface_desc.dwWidth = 640;
760 surface_desc.dwHeight = 480;
762 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
763 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
765 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirectDrawSurface3, (void **)&surface3);
768 skip("Failed to get the IDirectDrawSurface3 interface, skipping test.\n");
772 hr = IDirectDraw_QueryInterface(ddraw, &IID_IDirect3D, (void **)&d3d);
775 skip("Failed to get the IDirect3D interface, skipping test.\n");
779 hr = IDirect3D_EnumDevices(d3d, enum_z_fmt, &z_depth);
780 if (FAILED(hr) || !z_depth)
782 skip("No depth buffer formats available, skipping test.\n");
786 memset(&surface_desc, 0, sizeof(surface_desc));
787 surface_desc.dwSize = sizeof(surface_desc);
788 surface_desc.dwFlags = DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_WIDTH | DDSD_HEIGHT;
789 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
790 U2(surface_desc).dwZBufferBitDepth = z_depth;
791 surface_desc.dwWidth = 640;
792 surface_desc.dwHeight = 480;
793 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &ds, NULL);
794 ok(SUCCEEDED(hr), "Failed to create depth buffer, hr %#x.\n", hr);
798 /* Using a different surface interface version still works */
799 hr = IDirectDrawSurface3_AddAttachedSurface(surface3, (IDirectDrawSurface3 *)ds);
800 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
801 refcount = IDirectDrawSurface_Release(ds);
802 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
807 hr = IDirectDrawSurface3_QueryInterface(surface3, &IID_IDirect3DHALDevice, (void **)&device);
808 ok(SUCCEEDED(hr), "Failed to create d3d device.\n");
812 hr = IDirect3D_CreateViewport(d3d, &viewport, NULL);
813 ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
814 hr = IDirect3D_CreateMaterial(d3d, &background, NULL);
815 ok(SUCCEEDED(hr), "Failed to create material, hr %#x.\n", hr);
817 hr = IDirect3DDevice_AddViewport(device, viewport);
818 ok(SUCCEEDED(hr), "Failed to add viewport, hr %#x.\n", hr);
819 memset(&vp, 0, sizeof(vp));
820 vp.dwSize = sizeof(vp);
825 vp.dvScaleX = 320.0f;
826 vp.dvScaleY = 240.0f;
831 hr = IDirect3DViewport_SetViewport(viewport, &vp);
832 ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
834 memset(&material, 0, sizeof(material));
835 material.dwSize = sizeof(material);
836 U1(U(material).diffuse).r = 1.0f;
837 U2(U(material).diffuse).g = 0.0f;
838 U3(U(material).diffuse).b = 0.0f;
839 U4(U(material).diffuse).a = 1.0f;
840 hr = IDirect3DMaterial_SetMaterial(background, &material);
841 ok(SUCCEEDED(hr), "Failed to set material data, hr %#x.\n", hr);
842 hr = IDirect3DMaterial_GetHandle(background, device, &background_handle);
843 ok(SUCCEEDED(hr), "Failed to get material handle, hr %#x.\n", hr);
844 hr = IDirect3DViewport_SetBackground(viewport, background_handle);
845 ok(SUCCEEDED(hr), "Failed to set viewport background, hr %#x.\n", hr);
847 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
848 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
849 color = get_surface_color(surface, 320, 240);
850 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
855 IDirect3DDevice_DeleteViewport(device, viewport);
856 IDirect3DViewport_Release(viewport);
858 if (background) IDirect3DMaterial_Release(background);
859 if (surface3) IDirectDrawSurface3_Release(surface3);
860 if (surface) IDirectDrawSurface_Release(surface);
861 if (device) IDirect3DDevice_Release(device);
862 if (d3d) IDirect3D_Release(d3d);
863 if (ddraw) IDirectDraw_Release(ddraw);
864 DestroyWindow(window);
867 static void test_coop_level_threaded(void)
869 struct create_window_thread_param p;
873 if (!(ddraw = create_ddraw()))
875 skip("Failed to create a ddraw object, skipping test.\n");
878 create_window_thread(&p);
880 hr = IDirectDraw_SetCooperativeLevel(ddraw, p.window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
881 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
883 IDirectDraw_Release(ddraw);
884 destroy_window_thread(&p);
887 static LONG get_refcount(IUnknown *test_iface)
889 IUnknown_AddRef(test_iface);
890 return IUnknown_Release(test_iface);
893 static void test_viewport_interfaces(void)
899 IDirect3DViewport *viewport;
900 IDirect3DViewport2 *viewport2;
901 IDirect3DViewport3 *viewport3;
902 IDirectDrawGammaControl *gamma;
905 if (!(ddraw = create_ddraw()))
907 skip("Failed to create ddraw object, skipping test.\n");
910 hr = IDirectDraw_QueryInterface(ddraw, &IID_IDirect3D, (void **)&d3d);
911 ok(SUCCEEDED(hr) || hr == E_NOINTERFACE, "Failed to get d3d interface, hr %#x.\n", hr);
914 skip("Direct3D not available, skipping tests\n");
915 IDirectDraw_Release(ddraw);
918 ref = get_refcount((IUnknown *)d3d);
919 ok(ref == 2, "IDirect3D refcount is %d\n", ref);
921 hr = IDirect3D_CreateViewport(d3d, &viewport, NULL);
922 ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
923 ref = get_refcount((IUnknown *)viewport);
924 ok(ref == 1, "Initial IDirect3DViewport refcount is %d\n", ref);
925 ref = get_refcount((IUnknown *)d3d);
926 ok(ref == 2, "IDirect3D refcount is %d\n", ref);
928 /* E_FAIL return values are returned by Winetestbot Windows NT machines. While not supporting
929 * newer interfaces is legitimate for old ddraw versions, E_FAIL violates Microsoft's rules
930 * for QueryInterface, hence the broken() */
931 gamma = (IDirectDrawGammaControl *)0xdeadbeef;
932 hr = IDirect3DViewport_QueryInterface(viewport, &IID_IDirectDrawGammaControl, (void **)&gamma);
933 ok(hr == E_NOINTERFACE || broken(hr == E_FAIL), "Got unexpected hr %#x.\n", hr);
934 ok(gamma == NULL, "Interface not set to NULL by failed QI call: %p\n", gamma);
935 if (SUCCEEDED(hr)) IDirectDrawGammaControl_Release(gamma);
936 /* NULL iid: Segfaults */
938 hr = IDirect3DViewport_QueryInterface(viewport, &IID_IDirect3DViewport2, (void **)&viewport2);
939 ok(SUCCEEDED(hr) || broken(hr == E_FAIL), "Failed to QI IDirect3DViewport2, hr %#x.\n", hr);
942 ref = get_refcount((IUnknown *)viewport);
943 ok(ref == 2, "IDirect3DViewport refcount is %d\n", ref);
944 ref = get_refcount((IUnknown *)viewport2);
945 ok(ref == 2, "IDirect3DViewport2 refcount is %d\n", ref);
946 IDirect3DViewport2_Release(viewport2);
950 hr = IDirect3DViewport_QueryInterface(viewport, &IID_IDirect3DViewport3, (void **)&viewport3);
951 ok(SUCCEEDED(hr) || broken(hr == E_FAIL), "Failed to QI IDirect3DViewport3, hr %#x.\n", hr);
954 ref = get_refcount((IUnknown *)viewport);
955 ok(ref == 2, "IDirect3DViewport refcount is %d\n", ref);
956 ref = get_refcount((IUnknown *)viewport3);
957 ok(ref == 2, "IDirect3DViewport3 refcount is %d\n", ref);
958 IDirect3DViewport3_Release(viewport3);
961 hr = IDirect3DViewport_QueryInterface(viewport, &IID_IUnknown, (void **)&unknown);
962 ok(SUCCEEDED(hr), "Failed to QI IUnknown, hr %#x.\n", hr);
965 ref = get_refcount((IUnknown *)viewport);
966 ok(ref == 2, "IDirect3DViewport refcount is %d\n", ref);
967 ref = get_refcount(unknown);
968 ok(ref == 2, "IUnknown refcount is %d\n", ref);
969 IUnknown_Release(unknown);
972 IDirect3DViewport_Release(viewport);
973 IDirect3D_Release(d3d);
974 IDirectDraw_Release(ddraw);
977 static void test_zenable(void)
979 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
980 static D3DTLVERTEX tquad[] =
982 {{ 0.0f}, {480.0f}, {-0.5f}, {1.0f}, {0xff00ff00}, {0x00000000}, {0.0f}, {0.0f}},
983 {{ 0.0f}, { 0.0f}, {-0.5f}, {1.0f}, {0xff00ff00}, {0x00000000}, {0.0f}, {0.0f}},
984 {{640.0f}, {480.0f}, { 1.5f}, {1.0f}, {0xff00ff00}, {0x00000000}, {0.0f}, {0.0f}},
985 {{640.0f}, { 0.0f}, { 1.5f}, {1.0f}, {0xff00ff00}, {0x00000000}, {0.0f}, {0.0f}},
987 IDirect3DExecuteBuffer *execute_buffer;
988 D3DMATERIALHANDLE background_handle;
989 D3DEXECUTEBUFFERDESC exec_desc;
990 IDirect3DMaterial *background;
991 IDirect3DViewport *viewport;
992 D3DEXECUTEDATA exec_data;
993 IDirect3DDevice *device;
994 IDirectDrawSurface *rt;
995 D3DMATERIAL material;
1007 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1008 0, 0, 640, 480, 0, 0, 0, 0);
1009 if (!(ddraw = create_ddraw()))
1011 skip("Failed to create ddraw object, skipping test.\n");
1012 DestroyWindow(window);
1015 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
1017 skip("Failed to create D3D device, skipping test.\n");
1018 IDirectDraw_Release(ddraw);
1019 DestroyWindow(window);
1023 hr = IDirect3DDevice_GetDirect3D(device, &d3d);
1024 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
1025 hr = IDirect3D_CreateMaterial(d3d, &background, NULL);
1026 ok(SUCCEEDED(hr), "Failed to create material, hr %#x.\n", hr);
1027 hr = IDirect3D_CreateViewport(d3d, &viewport, NULL);
1028 ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
1030 hr = IDirect3DDevice_AddViewport(device, viewport);
1031 ok(SUCCEEDED(hr), "Failed to add viewport, hr %#x.\n", hr);
1032 memset(&vp, 0, sizeof(vp));
1033 vp.dwSize = sizeof(vp);
1038 vp.dvScaleX = 320.0f;
1039 vp.dvScaleY = 240.0f;
1044 hr = IDirect3DViewport_SetViewport(viewport, &vp);
1045 ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
1047 memset(&material, 0, sizeof(material));
1048 material.dwSize = sizeof(material);
1049 U1(U(material).diffuse).r = 1.0f;
1050 U2(U(material).diffuse).g = 0.0f;
1051 U3(U(material).diffuse).b = 0.0f;
1052 U4(U(material).diffuse).a = 1.0f;
1053 hr = IDirect3DMaterial_SetMaterial(background, &material);
1054 ok(SUCCEEDED(hr), "Failed to set material data, hr %#x.\n", hr);
1055 hr = IDirect3DMaterial_GetHandle(background, device, &background_handle);
1056 ok(SUCCEEDED(hr), "Failed to get material handle, hr %#x.\n", hr);
1057 hr = IDirect3DViewport_SetBackground(viewport, background_handle);
1058 ok(SUCCEEDED(hr), "Failed to set viewport background, hr %#x.\n", hr);
1060 memset(&exec_desc, 0, sizeof(exec_desc));
1061 exec_desc.dwSize = sizeof(exec_desc);
1062 exec_desc.dwFlags = D3DDEB_BUFSIZE | D3DDEB_CAPS;
1063 exec_desc.dwBufferSize = 1024;
1064 exec_desc.dwCaps = D3DDEBCAPS_SYSTEMMEMORY;
1066 hr = IDirect3DDevice_CreateExecuteBuffer(device, &exec_desc, &execute_buffer, NULL);
1067 ok(SUCCEEDED(hr), "Failed to create execute buffer, hr %#x.\n", hr);
1068 hr = IDirect3DExecuteBuffer_Lock(execute_buffer, &exec_desc);
1069 ok(SUCCEEDED(hr), "Failed to lock execute buffer, hr %#x.\n", hr);
1070 memcpy(exec_desc.lpData, tquad, sizeof(tquad));
1071 ptr = ((BYTE *)exec_desc.lpData) + sizeof(tquad);
1072 emit_process_vertices(&ptr, 4);
1073 emit_set_rs(&ptr, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
1074 emit_tquad(&ptr, 0);
1076 inst_length = (BYTE *)ptr - (BYTE *)exec_desc.lpData;
1077 inst_length -= sizeof(tquad);
1078 hr = IDirect3DExecuteBuffer_Unlock(execute_buffer);
1079 ok(SUCCEEDED(hr), "Failed to unlock execute buffer, hr %#x.\n", hr);
1081 memset(&exec_data, 0, sizeof(exec_data));
1082 exec_data.dwSize = sizeof(exec_data);
1083 exec_data.dwVertexCount = 4;
1084 exec_data.dwInstructionOffset = sizeof(tquad);
1085 exec_data.dwInstructionLength = inst_length;
1086 hr = IDirect3DExecuteBuffer_SetExecuteData(execute_buffer, &exec_data);
1087 ok(SUCCEEDED(hr), "Failed to set execute data, hr %#x.\n", hr);
1089 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
1090 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
1091 hr = IDirect3DDevice_BeginScene(device);
1092 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1093 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
1094 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
1095 hr = IDirect3DDevice_EndScene(device);
1096 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1098 hr = IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&rt);
1099 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1100 for (i = 0; i < 4; ++i)
1102 for (j = 0; j < 4; ++j)
1104 x = 80 * ((2 * j) + 1);
1105 y = 60 * ((2 * i) + 1);
1106 color = get_surface_color(rt, x, y);
1107 ok(compare_color(color, 0x0000ff00, 1),
1108 "Expected color 0x0000ff00 at %u, %u, got 0x%08x.\n", x, y, color);
1111 IDirectDrawSurface_Release(rt);
1113 IDirect3DExecuteBuffer_Release(execute_buffer);
1114 IDirect3DMaterial_Release(background);
1115 IDirect3DViewport_Release(viewport);
1116 IDirect3D_Release(d3d);
1117 IDirect3DDevice_Release(device);
1118 IDirectDraw_Release(ddraw);
1119 DestroyWindow(window);
1124 test_coop_level_create_device_window();
1126 test_coop_level_d3d_state();
1127 test_surface_interface_mismatch();
1128 test_coop_level_threaded();
1129 test_viewport_interfaces();