comctl32: Update thumb position on WM_MOUSEMOVE instead of deferring it.
[wine/multimedia.git] / dlls / ddraw / tests / ddraw1.c
blob9ba428f01eb7c44ab618087a5c1a95b7effc0c65
1 /*
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
18 #define COBJMACROS
20 #include "wine/test.h"
21 #include "d3d.h"
23 struct create_window_thread_param
25 HWND window;
26 HANDLE window_created;
27 HANDLE destroy_window;
28 HANDLE thread;
31 static BOOL compare_color(D3DCOLOR c1, D3DCOLOR c2, BYTE max_diff)
33 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
34 c1 >>= 8; c2 >>= 8;
35 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
36 c1 >>= 8; c2 >>= 8;
37 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
38 c1 >>= 8; c2 >>= 8;
39 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
40 return TRUE;
43 static DWORD WINAPI create_window_thread_proc(void *param)
45 struct create_window_thread_param *p = param;
46 DWORD res;
47 BOOL ret;
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());
54 for (;;)
56 MSG msg;
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)
62 break;
63 if (res != WAIT_TIMEOUT)
65 ok(0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
66 break;
70 DestroyWindow(p->window);
72 return 0;
75 static void create_window_thread(struct create_window_thread_param *p)
77 DWORD res, tid;
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;
102 D3DCOLOR color;
103 HRESULT hr;
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);
110 if (FAILED(hr))
111 return 0xdeadbeef;
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);
118 return color;
121 static void emit_process_vertices(void **ptr, WORD base_idx, DWORD vertex_count)
123 D3DINSTRUCTION *inst = *ptr;
124 D3DPROCESSVERTICES *pv = (D3DPROCESSVERTICES *)(inst + 1);
126 inst->bOpcode = D3DOP_PROCESSVERTICES;
127 inst->bSize = sizeof(*pv);
128 inst->wCount = 1;
130 pv->dwFlags = D3DPROCESSVERTICES_COPY;
131 pv->wStart = base_idx;
132 pv->wDest = 0;
133 pv->dwCount = vertex_count;
134 pv->dwReserved = 0;
136 *ptr = pv + 1;
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);
146 inst->wCount = 1;
148 U1(*rs).drstRenderStateType = state;
149 U2(*rs).dwArg[0] = value;
151 *ptr = rs + 1;
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);
161 inst->wCount = 2;
163 U1(*tri).v1 = base_idx;
164 U2(*tri).v2 = base_idx + 1;
165 U3(*tri).v3 = base_idx + 2;
166 tri->wFlags = D3DTRIFLAG_START;
167 ++tri;
169 U1(*tri).v1 = base_idx + 2;
170 U2(*tri).v2 = base_idx + 1;
171 U3(*tri).v3 = base_idx + 3;
172 tri->wFlags = D3DTRIFLAG_ODD;
173 ++tri;
175 *ptr = tri;
178 static void emit_end(void **ptr)
180 D3DINSTRUCTION *inst = *ptr;
182 inst->bOpcode = D3DOP_EXIT;
183 inst->bSize = 0;
184 inst->wCount = 0;
186 *ptr = inst + 1;
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)
198 *z_depth = 32;
199 else if (hal_desc->dwDeviceZBufferBitDepth & DDBD_24)
200 *z_depth = 24;
201 else if (hal_desc->dwDeviceZBufferBitDepth & DDBD_16)
202 *z_depth = 16;
204 return DDENUMRET_OK;
207 static IDirectDraw *create_ddraw(void)
209 IDirectDraw *ddraw;
211 if (FAILED(DirectDrawCreate(NULL, &ddraw, NULL)))
212 return NULL;
214 return ddraw;
217 static IDirect3DDevice *create_device(IDirectDraw *ddraw, HWND window, DWORD coop_level)
219 IDirectDrawSurface *surface, *ds;
220 IDirect3DDevice *device = NULL;
221 DDSURFACEDESC surface_desc;
222 DWORD z_depth = 0;
223 IDirect3D *d3d;
224 HRESULT hr;
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);
253 if (FAILED(hr))
255 IDirectDrawSurface_Release(surface);
256 return NULL;
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);
265 return NULL;
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);
277 if (FAILED(hr))
279 IDirectDrawSurface_Release(surface);
280 return NULL;
283 hr = IDirectDrawSurface_AddAttachedSurface(surface, ds);
284 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
285 IDirectDrawSurface_Release(ds);
286 if (FAILED(hr))
288 IDirectDrawSurface_Release(surface);
289 return NULL;
292 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirect3DHALDevice, (void **)&device);
293 IDirectDrawSurface_Release(surface);
294 if (FAILED(hr))
295 return NULL;
297 return device;
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);
306 return DDENUMRET_OK;
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;
318 IDirectDraw *ddraw;
319 HRESULT hr;
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);
327 return;
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);
357 return;
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;
417 IDirectDraw *ddraw;
418 RGNDATA *rgn_data;
419 D3DCOLOR color;
420 HRGN r1, r2;
421 HWND window;
422 DDBLTFX fx;
423 HRESULT hr;
424 DWORD *ptr;
425 DWORD ret;
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);
455 return;
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");
504 DeleteObject(r2);
505 DeleteObject(r1);
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;
620 IDirectDraw *ddraw;
621 D3DVIEWPORT vp;
622 IDirect3D *d3d;
623 D3DCOLOR color;
624 HWND window;
625 HRESULT hr;
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);
633 return;
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);
640 return;
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);
655 vp.dwX = 0;
656 vp.dwY = 0;
657 vp.dwWidth = 640;
658 vp.dwHeight = 480;
659 vp.dvScaleX = 320.0f;
660 vp.dvScaleY = 240.0f;
661 vp.dvMaxX = 1.0f;
662 vp.dvMaxY = 1.0f;
663 vp.dvMinZ = 0.0f;
664 vp.dvMaxZ = 1.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;
733 DWORD z_depth = 0;
734 ULONG refcount;
735 HRESULT hr;
736 D3DCOLOR color;
737 HWND window;
738 D3DVIEWPORT vp;
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");
749 goto cleanup;
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);
766 if (FAILED(hr))
768 skip("Failed to get the IDirectDrawSurface3 interface, skipping test.\n");
769 goto cleanup;
772 hr = IDirectDraw_QueryInterface(ddraw, &IID_IDirect3D, (void **)&d3d);
773 if (FAILED(hr))
775 skip("Failed to get the IDirect3D interface, skipping test.\n");
776 goto cleanup;
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");
783 goto cleanup;
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);
795 if (FAILED(hr))
796 goto cleanup;
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);
803 if (FAILED(hr))
804 goto cleanup;
806 /* Here too */
807 hr = IDirectDrawSurface3_QueryInterface(surface3, &IID_IDirect3DHALDevice, (void **)&device);
808 ok(SUCCEEDED(hr), "Failed to create d3d device.\n");
809 if (FAILED(hr))
810 goto cleanup;
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);
821 vp.dwX = 0;
822 vp.dwY = 0;
823 vp.dwWidth = 640;
824 vp.dwHeight = 480;
825 vp.dvScaleX = 320.0f;
826 vp.dvScaleY = 240.0f;
827 vp.dvMaxX = 1.0f;
828 vp.dvMaxY = 1.0f;
829 vp.dvMinZ = 0.0f;
830 vp.dvMaxZ = 1.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);
852 cleanup:
853 if (viewport)
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;
870 IDirectDraw *ddraw;
871 HRESULT hr;
873 if (!(ddraw = create_ddraw()))
875 skip("Failed to create a ddraw object, skipping test.\n");
876 return;
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 ULONG get_refcount(IUnknown *test_iface)
889 IUnknown_AddRef(test_iface);
890 return IUnknown_Release(test_iface);
893 static void test_viewport_interfaces(void)
895 IDirectDraw *ddraw;
896 IDirect3D *d3d;
897 HRESULT hr;
898 ULONG ref;
899 IDirect3DViewport *viewport;
900 IDirect3DViewport2 *viewport2;
901 IDirect3DViewport3 *viewport3;
902 IDirectDrawGammaControl *gamma;
903 IUnknown *unknown;
905 if (!(ddraw = create_ddraw()))
907 skip("Failed to create ddraw object, skipping test.\n");
908 return;
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);
912 if (FAILED(hr))
914 skip("Direct3D not available, skipping tests\n");
915 IDirectDraw_Release(ddraw);
916 return;
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 %u\n", ref);
925 ref = get_refcount((IUnknown *)d3d);
926 ok(ref == 2, "IDirect3D refcount is %u\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) || hr == E_NOINTERFACE || broken(hr == E_FAIL),
940 "Failed to QI IDirect3DViewport2, hr %#x.\n", hr);
941 if (viewport2)
943 ref = get_refcount((IUnknown *)viewport);
944 ok(ref == 2, "IDirect3DViewport refcount is %u\n", ref);
945 ref = get_refcount((IUnknown *)viewport2);
946 ok(ref == 2, "IDirect3DViewport2 refcount is %u\n", ref);
947 IDirect3DViewport2_Release(viewport2);
948 viewport2 = NULL;
951 hr = IDirect3DViewport_QueryInterface(viewport, &IID_IDirect3DViewport3, (void **)&viewport3);
952 ok(SUCCEEDED(hr) || hr == E_NOINTERFACE || broken(hr == E_FAIL),
953 "Failed to QI IDirect3DViewport3, hr %#x.\n", hr);
954 if (viewport3)
956 ref = get_refcount((IUnknown *)viewport);
957 ok(ref == 2, "IDirect3DViewport refcount is %u\n", ref);
958 ref = get_refcount((IUnknown *)viewport3);
959 ok(ref == 2, "IDirect3DViewport3 refcount is %u\n", ref);
960 IDirect3DViewport3_Release(viewport3);
963 hr = IDirect3DViewport_QueryInterface(viewport, &IID_IUnknown, (void **)&unknown);
964 ok(SUCCEEDED(hr), "Failed to QI IUnknown, hr %#x.\n", hr);
965 if (unknown)
967 ref = get_refcount((IUnknown *)viewport);
968 ok(ref == 2, "IDirect3DViewport refcount is %u\n", ref);
969 ref = get_refcount(unknown);
970 ok(ref == 2, "IUnknown refcount is %u\n", ref);
971 IUnknown_Release(unknown);
974 IDirect3DViewport_Release(viewport);
975 IDirect3D_Release(d3d);
976 IDirectDraw_Release(ddraw);
979 static void test_zenable(void)
981 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
982 static D3DTLVERTEX tquad[] =
984 {{ 0.0f}, {480.0f}, {-0.5f}, {1.0f}, {0xff00ff00}, {0x00000000}, {0.0f}, {0.0f}},
985 {{ 0.0f}, { 0.0f}, {-0.5f}, {1.0f}, {0xff00ff00}, {0x00000000}, {0.0f}, {0.0f}},
986 {{640.0f}, {480.0f}, { 1.5f}, {1.0f}, {0xff00ff00}, {0x00000000}, {0.0f}, {0.0f}},
987 {{640.0f}, { 0.0f}, { 1.5f}, {1.0f}, {0xff00ff00}, {0x00000000}, {0.0f}, {0.0f}},
989 IDirect3DExecuteBuffer *execute_buffer;
990 D3DMATERIALHANDLE background_handle;
991 D3DEXECUTEBUFFERDESC exec_desc;
992 IDirect3DMaterial *background;
993 IDirect3DViewport *viewport;
994 D3DEXECUTEDATA exec_data;
995 IDirect3DDevice *device;
996 IDirectDrawSurface *rt;
997 D3DMATERIAL material;
998 IDirectDraw *ddraw;
999 UINT inst_length;
1000 D3DVIEWPORT vp;
1001 IDirect3D *d3d;
1002 D3DCOLOR color;
1003 HWND window;
1004 HRESULT hr;
1005 UINT x, y;
1006 UINT i, j;
1007 void *ptr;
1009 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1010 0, 0, 640, 480, 0, 0, 0, 0);
1011 if (!(ddraw = create_ddraw()))
1013 skip("Failed to create ddraw object, skipping test.\n");
1014 DestroyWindow(window);
1015 return;
1017 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
1019 skip("Failed to create D3D device, skipping test.\n");
1020 IDirectDraw_Release(ddraw);
1021 DestroyWindow(window);
1022 return;
1025 hr = IDirect3DDevice_GetDirect3D(device, &d3d);
1026 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
1027 hr = IDirect3D_CreateMaterial(d3d, &background, NULL);
1028 ok(SUCCEEDED(hr), "Failed to create material, hr %#x.\n", hr);
1029 hr = IDirect3D_CreateViewport(d3d, &viewport, NULL);
1030 ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
1032 hr = IDirect3DDevice_AddViewport(device, viewport);
1033 ok(SUCCEEDED(hr), "Failed to add viewport, hr %#x.\n", hr);
1034 memset(&vp, 0, sizeof(vp));
1035 vp.dwSize = sizeof(vp);
1036 vp.dwX = 0;
1037 vp.dwY = 0;
1038 vp.dwWidth = 640;
1039 vp.dwHeight = 480;
1040 vp.dvScaleX = 320.0f;
1041 vp.dvScaleY = 240.0f;
1042 vp.dvMaxX = 1.0f;
1043 vp.dvMaxY = 1.0f;
1044 vp.dvMinZ = 0.0f;
1045 vp.dvMaxZ = 1.0f;
1046 hr = IDirect3DViewport_SetViewport(viewport, &vp);
1047 ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
1049 memset(&material, 0, sizeof(material));
1050 material.dwSize = sizeof(material);
1051 U1(U(material).diffuse).r = 1.0f;
1052 U2(U(material).diffuse).g = 0.0f;
1053 U3(U(material).diffuse).b = 0.0f;
1054 U4(U(material).diffuse).a = 1.0f;
1055 hr = IDirect3DMaterial_SetMaterial(background, &material);
1056 ok(SUCCEEDED(hr), "Failed to set material data, hr %#x.\n", hr);
1057 hr = IDirect3DMaterial_GetHandle(background, device, &background_handle);
1058 ok(SUCCEEDED(hr), "Failed to get material handle, hr %#x.\n", hr);
1059 hr = IDirect3DViewport_SetBackground(viewport, background_handle);
1060 ok(SUCCEEDED(hr), "Failed to set viewport background, hr %#x.\n", hr);
1062 memset(&exec_desc, 0, sizeof(exec_desc));
1063 exec_desc.dwSize = sizeof(exec_desc);
1064 exec_desc.dwFlags = D3DDEB_BUFSIZE | D3DDEB_CAPS;
1065 exec_desc.dwBufferSize = 1024;
1066 exec_desc.dwCaps = D3DDEBCAPS_SYSTEMMEMORY;
1068 hr = IDirect3DDevice_CreateExecuteBuffer(device, &exec_desc, &execute_buffer, NULL);
1069 ok(SUCCEEDED(hr), "Failed to create execute buffer, hr %#x.\n", hr);
1070 hr = IDirect3DExecuteBuffer_Lock(execute_buffer, &exec_desc);
1071 ok(SUCCEEDED(hr), "Failed to lock execute buffer, hr %#x.\n", hr);
1072 memcpy(exec_desc.lpData, tquad, sizeof(tquad));
1073 ptr = ((BYTE *)exec_desc.lpData) + sizeof(tquad);
1074 emit_process_vertices(&ptr, 0, 4);
1075 emit_set_rs(&ptr, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
1076 emit_tquad(&ptr, 0);
1077 emit_end(&ptr);
1078 inst_length = (BYTE *)ptr - (BYTE *)exec_desc.lpData;
1079 inst_length -= sizeof(tquad);
1080 hr = IDirect3DExecuteBuffer_Unlock(execute_buffer);
1081 ok(SUCCEEDED(hr), "Failed to unlock execute buffer, hr %#x.\n", hr);
1083 memset(&exec_data, 0, sizeof(exec_data));
1084 exec_data.dwSize = sizeof(exec_data);
1085 exec_data.dwVertexCount = 4;
1086 exec_data.dwInstructionOffset = sizeof(tquad);
1087 exec_data.dwInstructionLength = inst_length;
1088 hr = IDirect3DExecuteBuffer_SetExecuteData(execute_buffer, &exec_data);
1089 ok(SUCCEEDED(hr), "Failed to set execute data, hr %#x.\n", hr);
1091 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
1092 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
1093 hr = IDirect3DDevice_BeginScene(device);
1094 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1095 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
1096 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
1097 hr = IDirect3DDevice_EndScene(device);
1098 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1100 hr = IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&rt);
1101 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1102 for (i = 0; i < 4; ++i)
1104 for (j = 0; j < 4; ++j)
1106 x = 80 * ((2 * j) + 1);
1107 y = 60 * ((2 * i) + 1);
1108 color = get_surface_color(rt, x, y);
1109 ok(compare_color(color, 0x0000ff00, 1),
1110 "Expected color 0x0000ff00 at %u, %u, got 0x%08x.\n", x, y, color);
1113 IDirectDrawSurface_Release(rt);
1115 IDirect3DExecuteBuffer_Release(execute_buffer);
1116 IDirect3DMaterial_Release(background);
1117 IDirect3DViewport_Release(viewport);
1118 IDirect3D_Release(d3d);
1119 IDirect3DDevice_Release(device);
1120 IDirectDraw_Release(ddraw);
1121 DestroyWindow(window);
1124 static void test_ck_rgba(void)
1126 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
1127 static D3DTLVERTEX tquad[] =
1129 {{ 0.0f}, {480.0f}, {0.25f}, {1.0f}, {0xffffffff}, {0x00000000}, {0.0f}, {0.0f}},
1130 {{ 0.0f}, { 0.0f}, {0.25f}, {1.0f}, {0xffffffff}, {0x00000000}, {0.0f}, {1.0f}},
1131 {{640.0f}, {480.0f}, {0.25f}, {1.0f}, {0xffffffff}, {0x00000000}, {1.0f}, {0.0f}},
1132 {{640.0f}, { 0.0f}, {0.25f}, {1.0f}, {0xffffffff}, {0x00000000}, {1.0f}, {1.0f}},
1133 {{ 0.0f}, {480.0f}, {0.75f}, {1.0f}, {0xffffffff}, {0x00000000}, {0.0f}, {0.0f}},
1134 {{ 0.0f}, { 0.0f}, {0.75f}, {1.0f}, {0xffffffff}, {0x00000000}, {0.0f}, {1.0f}},
1135 {{640.0f}, {480.0f}, {0.75f}, {1.0f}, {0xffffffff}, {0x00000000}, {1.0f}, {0.0f}},
1136 {{640.0f}, { 0.0f}, {0.75f}, {1.0f}, {0xffffffff}, {0x00000000}, {1.0f}, {1.0f}},
1138 static const struct
1140 D3DCOLOR fill_color;
1141 BOOL color_key;
1142 BOOL blend;
1143 D3DCOLOR result1;
1144 D3DCOLOR result2;
1146 tests[] =
1148 {0xff00ff00, TRUE, TRUE, 0x00ff0000, 0x000000ff},
1149 {0xff00ff00, TRUE, FALSE, 0x00ff0000, 0x000000ff},
1150 {0xff00ff00, FALSE, TRUE, 0x0000ff00, 0x0000ff00},
1151 {0xff00ff00, FALSE, FALSE, 0x0000ff00, 0x0000ff00},
1152 {0x7f00ff00, TRUE, TRUE, 0x00807f00, 0x00807f00},
1153 {0x7f00ff00, TRUE, FALSE, 0x0000ff00, 0x0000ff00},
1154 {0x7f00ff00, FALSE, TRUE, 0x00807f00, 0x00807f00},
1155 {0x7f00ff00, FALSE, FALSE, 0x0000ff00, 0x0000ff00},
1158 IDirect3DExecuteBuffer *execute_buffer;
1159 D3DMATERIALHANDLE background_handle;
1160 D3DTEXTUREHANDLE texture_handle;
1161 D3DEXECUTEBUFFERDESC exec_desc;
1162 IDirect3DMaterial *background;
1163 IDirectDrawSurface *surface;
1164 IDirect3DViewport *viewport;
1165 DDSURFACEDESC surface_desc;
1166 IDirect3DTexture *texture;
1167 IDirect3DDevice *device;
1168 IDirectDrawSurface *rt;
1169 D3DMATERIAL material;
1170 IDirectDraw *ddraw;
1171 D3DVIEWPORT vp;
1172 IDirect3D *d3d;
1173 D3DCOLOR color;
1174 HWND window;
1175 DDBLTFX fx;
1176 HRESULT hr;
1177 UINT i;
1179 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1180 0, 0, 640, 480, 0, 0, 0, 0);
1181 if (!(ddraw = create_ddraw()))
1183 skip("Failed to create ddraw object, skipping test.\n");
1184 DestroyWindow(window);
1185 return;
1187 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
1189 skip("Failed to create D3D device, skipping test.\n");
1190 DestroyWindow(window);
1191 return;
1194 hr = IDirect3DDevice_GetDirect3D(device, &d3d);
1195 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
1197 hr = IDirect3D_CreateViewport(d3d, &viewport, NULL);
1198 ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
1199 hr = IDirect3DDevice_AddViewport(device, viewport);
1200 ok(SUCCEEDED(hr), "Failed to add viewport, hr %#x.\n", hr);
1201 memset(&vp, 0, sizeof(vp));
1202 vp.dwSize = sizeof(vp);
1203 vp.dwX = 0;
1204 vp.dwY = 0;
1205 vp.dwWidth = 640;
1206 vp.dwHeight = 480;
1207 vp.dvScaleX = 320.0f;
1208 vp.dvScaleY = 240.0f;
1209 vp.dvMaxX = 1.0f;
1210 vp.dvMaxY = 1.0f;
1211 vp.dvMinZ = 0.0f;
1212 vp.dvMaxZ = 1.0f;
1213 hr = IDirect3DViewport_SetViewport(viewport, &vp);
1214 ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
1216 hr = IDirect3D_CreateMaterial(d3d, &background, NULL);
1217 ok(SUCCEEDED(hr), "Failed to create material, hr %#x.\n", hr);
1218 memset(&material, 0, sizeof(material));
1219 material.dwSize = sizeof(material);
1220 U1(U(material).diffuse).r = 1.0f;
1221 U2(U(material).diffuse).g = 0.0f;
1222 U3(U(material).diffuse).b = 0.0f;
1223 U4(U(material).diffuse).a = 1.0f;
1224 hr = IDirect3DMaterial_SetMaterial(background, &material);
1225 ok(SUCCEEDED(hr), "Failed to set material data, hr %#x.\n", hr);
1226 hr = IDirect3DMaterial_GetHandle(background, device, &background_handle);
1227 ok(SUCCEEDED(hr), "Failed to get material handle, hr %#x.\n", hr);
1228 hr = IDirect3DViewport_SetBackground(viewport, background_handle);
1229 ok(SUCCEEDED(hr), "Failed to set viewport background, hr %#x.\n", hr);
1231 IDirect3D_Release(d3d);
1233 memset(&surface_desc, 0, sizeof(surface_desc));
1234 surface_desc.dwSize = sizeof(surface_desc);
1235 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CKSRCBLT;
1236 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1237 surface_desc.dwWidth = 256;
1238 surface_desc.dwHeight = 256;
1239 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
1240 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
1241 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount = 32;
1242 U2(surface_desc.ddpfPixelFormat).dwRBitMask = 0x00ff0000;
1243 U3(surface_desc.ddpfPixelFormat).dwGBitMask = 0x0000ff00;
1244 U4(surface_desc.ddpfPixelFormat).dwBBitMask = 0x000000ff;
1245 U5(surface_desc.ddpfPixelFormat).dwRGBAlphaBitMask = 0xff000000;
1246 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0xff00ff00;
1247 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0xff00ff00;
1248 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1249 ok(SUCCEEDED(hr), "Failed to create destination surface, hr %#x.\n", hr);
1250 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirect3DTexture, (void **)&texture);
1251 ok(SUCCEEDED(hr), "Failed to get texture interface, hr %#x.\n", hr);
1252 IDirect3DTexture_GetHandle(texture, device, &texture_handle);
1253 ok(SUCCEEDED(hr), "Failed to get texture handle, hr %#x.\n", hr);
1254 IDirect3DTexture_Release(texture);
1256 memset(&exec_desc, 0, sizeof(exec_desc));
1257 exec_desc.dwSize = sizeof(exec_desc);
1258 exec_desc.dwFlags = D3DDEB_BUFSIZE | D3DDEB_CAPS;
1259 exec_desc.dwBufferSize = 1024;
1260 exec_desc.dwCaps = D3DDEBCAPS_SYSTEMMEMORY;
1261 hr = IDirect3DDevice_CreateExecuteBuffer(device, &exec_desc, &execute_buffer, NULL);
1262 ok(SUCCEEDED(hr), "Failed to create execute buffer, hr %#x.\n", hr);
1264 hr = IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&rt);
1265 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1267 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
1269 UINT draw1_len, draw2_len;
1270 D3DEXECUTEDATA exec_data;
1271 void *ptr;
1273 hr = IDirect3DExecuteBuffer_Lock(execute_buffer, &exec_desc);
1274 ok(SUCCEEDED(hr), "Failed to lock execute buffer, hr %#x.\n", hr);
1275 memcpy(exec_desc.lpData, tquad, sizeof(tquad));
1276 ptr = ((BYTE *)exec_desc.lpData) + sizeof(tquad);
1277 emit_process_vertices(&ptr, 0, 4);
1278 emit_set_rs(&ptr, D3DRENDERSTATE_TEXTUREHANDLE, texture_handle);
1279 emit_set_rs(&ptr, D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);
1280 emit_set_rs(&ptr, D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA);
1281 emit_set_rs(&ptr, D3DRENDERSTATE_COLORKEYENABLE, tests[i].color_key);
1282 emit_set_rs(&ptr, D3DRENDERSTATE_ALPHABLENDENABLE, tests[i].blend);
1283 emit_tquad(&ptr, 0);
1284 emit_end(&ptr);
1285 draw1_len = (BYTE *)ptr - (BYTE *)exec_desc.lpData - sizeof(tquad);
1286 emit_process_vertices(&ptr, 4, 4);
1287 emit_tquad(&ptr, 0);
1288 emit_set_rs(&ptr, D3DRENDERSTATE_TEXTUREHANDLE, 0);
1289 emit_end(&ptr);
1290 draw2_len = (BYTE *)ptr - (BYTE *)exec_desc.lpData - draw1_len;
1291 hr = IDirect3DExecuteBuffer_Unlock(execute_buffer);
1292 ok(SUCCEEDED(hr), "Failed to unlock execute buffer, hr %#x.\n", hr);
1294 memset(&fx, 0, sizeof(fx));
1295 fx.dwSize = sizeof(fx);
1296 U5(fx).dwFillColor = tests[i].fill_color;
1297 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
1298 ok(SUCCEEDED(hr), "Failed to fill texture, hr %#x.\n", hr);
1300 memset(&exec_data, 0, sizeof(exec_data));
1301 exec_data.dwSize = sizeof(exec_data);
1302 exec_data.dwVertexCount = 8;
1303 exec_data.dwInstructionOffset = sizeof(tquad);
1304 exec_data.dwInstructionLength = draw1_len;
1305 hr = IDirect3DExecuteBuffer_SetExecuteData(execute_buffer, &exec_data);
1306 ok(SUCCEEDED(hr), "Failed to set execute data, hr %#x.\n", hr);
1308 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER);
1309 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
1310 hr = IDirect3DDevice_BeginScene(device);
1311 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1312 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
1313 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
1314 hr = IDirect3DDevice_EndScene(device);
1315 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1317 color = get_surface_color(rt, 320, 240);
1318 if (i == 2 || i == 3)
1319 todo_wine ok(compare_color(color, tests[i].result1, 1), "Expected color 0x%08x for test %u, got 0x%08x.\n",
1320 tests[i].result1, i, color);
1321 else
1322 ok(compare_color(color, tests[i].result1, 1), "Expected color 0x%08x for test %u, got 0x%08x.\n",
1323 tests[i].result1, i, color);
1325 U5(fx).dwFillColor = 0xff0000ff;
1326 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
1327 ok(SUCCEEDED(hr), "Failed to fill texture, hr %#x.\n", hr);
1329 exec_data.dwInstructionOffset = sizeof(tquad) + draw1_len;
1330 exec_data.dwInstructionLength = draw2_len;
1331 hr = IDirect3DExecuteBuffer_SetExecuteData(execute_buffer, &exec_data);
1332 ok(SUCCEEDED(hr), "Failed to set execute data, hr %#x.\n", hr);
1334 hr = IDirect3DDevice_BeginScene(device);
1335 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1336 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
1337 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
1338 hr = IDirect3DDevice_EndScene(device);
1339 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1341 /* This tests that fragments that are masked out by the color key are
1342 * discarded, instead of just fully transparent. */
1343 color = get_surface_color(rt, 320, 240);
1344 if (i == 2 || i == 3)
1345 todo_wine ok(compare_color(color, tests[i].result2, 1), "Expected color 0x%08x for test %u, got 0x%08x.\n",
1346 tests[i].result2, i, color);
1347 else
1348 ok(compare_color(color, tests[i].result2, 1), "Expected color 0x%08x for test %u, got 0x%08x.\n",
1349 tests[i].result2, i, color);
1352 IDirectDrawSurface_Release(rt);
1353 IDirect3DExecuteBuffer_Release(execute_buffer);
1354 IDirectDrawSurface_Release(surface);
1355 IDirect3DMaterial_Release(background);
1356 hr = IDirect3DDevice_DeleteViewport(device, viewport);
1357 ok(SUCCEEDED(hr), "Failed to delete viewport, hr %#x.\n", hr);
1358 IDirect3DViewport_Release(viewport);
1359 IDirect3DDevice_Release(device);
1360 IDirectDraw_Release(ddraw);
1361 DestroyWindow(window);
1364 START_TEST(ddraw1)
1366 test_coop_level_create_device_window();
1367 test_clipper_blt();
1368 test_coop_level_d3d_state();
1369 test_surface_interface_mismatch();
1370 test_coop_level_threaded();
1371 test_viewport_interfaces();
1372 test_zenable();
1373 test_ck_rgba();