2 * Copyright 2011-2012 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, 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);
130 pv->dwFlags = D3DPROCESSVERTICES_COPY;
131 pv->wStart = base_idx;
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);
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;
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;
178 static void emit_end(void **ptr)
180 D3DINSTRUCTION *inst = *ptr;
182 inst->bOpcode = D3DOP_EXIT;
189 static void set_execute_data(IDirect3DExecuteBuffer *execute_buffer, UINT vertex_count, UINT offset, UINT len)
191 D3DEXECUTEDATA exec_data;
194 memset(&exec_data, 0, sizeof(exec_data));
195 exec_data.dwSize = sizeof(exec_data);
196 exec_data.dwVertexCount = vertex_count;
197 exec_data.dwInstructionOffset = offset;
198 exec_data.dwInstructionLength = len;
199 hr = IDirect3DExecuteBuffer_SetExecuteData(execute_buffer, &exec_data);
200 ok(SUCCEEDED(hr), "Failed to set execute data, hr %#x.\n", hr);
203 static HRESULT CALLBACK enum_z_fmt(GUID *guid, char *description, char *name,
204 D3DDEVICEDESC *hal_desc, D3DDEVICEDESC *hel_desc, void *ctx)
206 DWORD *z_depth = ctx;
208 if (!IsEqualGUID(&IID_IDirect3DHALDevice, guid))
209 return D3DENUMRET_OK;
211 if (hal_desc->dwDeviceZBufferBitDepth & DDBD_32)
213 else if (hal_desc->dwDeviceZBufferBitDepth & DDBD_24)
215 else if (hal_desc->dwDeviceZBufferBitDepth & DDBD_16)
221 static IDirectDraw *create_ddraw(void)
225 if (FAILED(DirectDrawCreate(NULL, &ddraw, NULL)))
231 static IDirect3DDevice *create_device(IDirectDraw *ddraw, HWND window, DWORD coop_level)
233 IDirectDrawSurface *surface, *ds;
234 IDirect3DDevice *device = NULL;
235 DDSURFACEDESC surface_desc;
240 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, coop_level);
241 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
243 memset(&surface_desc, 0, sizeof(surface_desc));
244 surface_desc.dwSize = sizeof(surface_desc);
245 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
246 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
247 surface_desc.dwWidth = 640;
248 surface_desc.dwHeight = 480;
250 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
251 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
253 if (coop_level & DDSCL_NORMAL)
255 IDirectDrawClipper *clipper;
257 hr = IDirectDraw_CreateClipper(ddraw, 0, &clipper, NULL);
258 ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr);
259 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
260 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
261 hr = IDirectDrawSurface_SetClipper(surface, clipper);
262 ok(SUCCEEDED(hr), "Failed to set surface clipper, hr %#x.\n", hr);
263 IDirectDrawClipper_Release(clipper);
266 hr = IDirectDraw_QueryInterface(ddraw, &IID_IDirect3D, (void **)&d3d);
269 IDirectDrawSurface_Release(surface);
273 hr = IDirect3D_EnumDevices(d3d, enum_z_fmt, &z_depth);
274 ok(SUCCEEDED(hr), "Failed to enumerate z-formats, hr %#x.\n", hr);
275 IDirect3D_Release(d3d);
276 if (FAILED(hr) || !z_depth)
278 IDirectDrawSurface_Release(surface);
282 memset(&surface_desc, 0, sizeof(surface_desc));
283 surface_desc.dwSize = sizeof(surface_desc);
284 surface_desc.dwFlags = DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_WIDTH | DDSD_HEIGHT;
285 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
286 U2(surface_desc).dwZBufferBitDepth = z_depth;
287 surface_desc.dwWidth = 640;
288 surface_desc.dwHeight = 480;
289 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &ds, NULL);
290 ok(SUCCEEDED(hr), "Failed to create depth buffer, hr %#x.\n", hr);
293 IDirectDrawSurface_Release(surface);
297 hr = IDirectDrawSurface_AddAttachedSurface(surface, ds);
298 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
299 IDirectDrawSurface_Release(ds);
302 IDirectDrawSurface_Release(surface);
306 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirect3DHALDevice, (void **)&device);
307 IDirectDrawSurface_Release(surface);
314 static IDirect3DViewport *create_viewport(IDirect3DDevice *device, UINT x, UINT y, UINT w, UINT h)
316 IDirect3DViewport *viewport;
321 hr = IDirect3DDevice_GetDirect3D(device, &d3d);
322 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
323 hr = IDirect3D_CreateViewport(d3d, &viewport, NULL);
324 ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
325 hr = IDirect3DDevice_AddViewport(device, viewport);
326 ok(SUCCEEDED(hr), "Failed to add viewport, hr %#x.\n", hr);
327 memset(&vp, 0, sizeof(vp));
328 vp.dwSize = sizeof(vp);
333 vp.dvScaleX = (float)w / 2.0f;
334 vp.dvScaleY = (float)h / 2.0f;
339 hr = IDirect3DViewport_SetViewport(viewport, &vp);
340 ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
341 IDirect3D_Release(d3d);
346 static void viewport_set_background(IDirect3DDevice *device, IDirect3DViewport *viewport,
347 IDirect3DMaterial *material)
349 D3DMATERIALHANDLE material_handle;
352 hr = IDirect3DMaterial2_GetHandle(material, device, &material_handle);
353 ok(SUCCEEDED(hr), "Failed to get material handle, hr %#x.\n", hr);
354 hr = IDirect3DViewport2_SetBackground(viewport, material_handle);
355 ok(SUCCEEDED(hr), "Failed to set viewport background, hr %#x.\n", hr);
358 static void destroy_viewport(IDirect3DDevice *device, IDirect3DViewport *viewport)
362 hr = IDirect3DDevice_DeleteViewport(device, viewport);
363 ok(SUCCEEDED(hr), "Failed to delete viewport, hr %#x.\n", hr);
364 IDirect3DViewport_Release(viewport);
367 static IDirect3DMaterial *create_diffuse_material(IDirect3DDevice *device, float r, float g, float b, float a)
369 IDirect3DMaterial *material;
374 hr = IDirect3DDevice_GetDirect3D(device, &d3d);
375 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
376 hr = IDirect3D_CreateMaterial(d3d, &material, NULL);
377 ok(SUCCEEDED(hr), "Failed to create material, hr %#x.\n", hr);
378 memset(&mat, 0, sizeof(mat));
379 mat.dwSize = sizeof(mat);
380 U1(U(mat).diffuse).r = r;
381 U2(U(mat).diffuse).g = g;
382 U3(U(mat).diffuse).b = b;
383 U4(U(mat).diffuse).a = a;
384 hr = IDirect3DMaterial_SetMaterial(material, &mat);
385 ok(SUCCEEDED(hr), "Failed to set material data, hr %#x.\n", hr);
386 IDirect3D_Release(d3d);
391 static void destroy_material(IDirect3DMaterial *material)
393 IDirect3DMaterial_Release(material);
396 static const UINT *expect_messages;
398 static LRESULT CALLBACK test_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
400 if (expect_messages && message == *expect_messages)
403 return DefWindowProcA(hwnd, message, wparam, lparam);
406 /* Set the wndproc back to what ddraw expects it to be, and release the ddraw
407 * interface. This prevents subsequent SetCooperativeLevel() calls on a
408 * different window from failing with DDERR_HWNDALREADYSET. */
409 static void fix_wndproc(HWND window, LONG_PTR proc)
414 if (!(ddraw = create_ddraw()))
417 SetWindowLongPtrA(window, GWLP_WNDPROC, proc);
418 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
419 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
420 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
421 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
423 IDirectDraw_Release(ddraw);
426 static HRESULT CALLBACK restore_callback(IDirectDrawSurface *surface, DDSURFACEDESC *desc, void *context)
428 HRESULT hr = IDirectDrawSurface_Restore(surface);
429 ok(SUCCEEDED(hr), "Failed to restore surface, hr %#x.\n", hr);
430 IDirectDrawSurface_Release(surface);
435 static HRESULT restore_surfaces(IDirectDraw *ddraw)
437 return IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
438 NULL, NULL, restore_callback);
441 static void test_coop_level_create_device_window(void)
443 HWND focus_window, device_window;
447 focus_window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
448 0, 0, 640, 480, 0, 0, 0, 0);
449 if (!(ddraw = create_ddraw()))
451 skip("Failed to create a ddraw object, skipping test.\n");
452 DestroyWindow(focus_window);
456 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
457 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
458 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
459 ok(!device_window, "Unexpected device window found.\n");
460 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW);
461 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
462 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
463 ok(!device_window, "Unexpected device window found.\n");
464 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_NORMAL);
465 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
466 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
467 ok(!device_window, "Unexpected device window found.\n");
468 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_NORMAL | DDSCL_FULLSCREEN);
469 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
470 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
471 ok(!device_window, "Unexpected device window found.\n");
472 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
473 ok(hr == DDERR_NOFOCUSWINDOW || broken(hr == DDERR_INVALIDPARAMS), "Got unexpected hr %#x.\n", hr);
474 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
475 ok(!device_window, "Unexpected device window found.\n");
477 /* Windows versions before 98 / NT5 don't support DDSCL_CREATEDEVICEWINDOW. */
478 if (broken(hr == DDERR_INVALIDPARAMS))
480 win_skip("DDSCL_CREATEDEVICEWINDOW not supported, skipping test.\n");
481 IDirectDraw_Release(ddraw);
482 DestroyWindow(focus_window);
486 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
487 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
488 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
489 ok(!device_window, "Unexpected device window found.\n");
490 hr = IDirectDraw_SetCooperativeLevel(ddraw, focus_window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
491 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
492 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
493 ok(!device_window, "Unexpected device window found.\n");
495 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
496 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
497 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
498 ok(!device_window, "Unexpected device window found.\n");
499 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_SETFOCUSWINDOW
500 | DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
501 ok(hr == DDERR_NOHWND, "Got unexpected hr %#x.\n", hr);
502 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
503 ok(!!device_window, "Device window not found.\n");
505 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
506 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
507 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
508 ok(!device_window, "Unexpected device window found.\n");
509 hr = IDirectDraw_SetCooperativeLevel(ddraw, focus_window, DDSCL_SETFOCUSWINDOW
510 | DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
511 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
512 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
513 ok(!!device_window, "Device window not found.\n");
515 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
516 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
517 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
518 ok(!device_window, "Unexpected device window found.\n");
519 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
520 ok(hr == DDERR_NOFOCUSWINDOW, "Got unexpected hr %#x.\n", hr);
521 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
522 ok(!device_window, "Unexpected device window found.\n");
523 hr = IDirectDraw_SetCooperativeLevel(ddraw, focus_window, DDSCL_SETFOCUSWINDOW);
524 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
525 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
526 ok(!device_window, "Unexpected device window found.\n");
527 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
528 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
529 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
530 ok(!!device_window, "Device window not found.\n");
532 IDirectDraw_Release(ddraw);
533 DestroyWindow(focus_window);
536 static void test_clipper_blt(void)
538 IDirectDrawSurface *src_surface, *dst_surface;
539 RECT client_rect, src_rect, *rect;
540 IDirectDrawClipper *clipper;
541 DDSURFACEDESC surface_desc;
542 unsigned int i, j, x, y;
553 static const DWORD src_data[] =
555 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
556 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
557 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
559 static const D3DCOLOR expected1[] =
561 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
562 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
563 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
564 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
566 static const D3DCOLOR expected2[] =
568 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
569 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
570 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
571 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
574 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
575 10, 10, 640, 480, 0, 0, 0, 0);
576 ShowWindow(window, SW_SHOW);
577 if (!(ddraw = create_ddraw()))
579 skip("Failed to create a ddraw object, skipping test.\n");
580 DestroyWindow(window);
584 ret = GetClientRect(window, &client_rect);
585 ok(ret, "Failed to get client rect.\n");
586 ret = MapWindowPoints(window, NULL, (POINT *)&client_rect, 2);
587 ok(ret, "Failed to map client rect.\n");
589 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
590 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
592 hr = IDirectDraw_CreateClipper(ddraw, 0, &clipper, NULL);
593 ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr);
594 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
595 ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr);
596 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
597 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
598 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
599 ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr);
600 rgn_data = HeapAlloc(GetProcessHeap(), 0, ret);
601 hr = IDirectDrawClipper_GetClipList(clipper, NULL, rgn_data, &ret);
602 ok(SUCCEEDED(hr), "Failed to get clip list, hr %#x.\n", hr);
603 ok(rgn_data->rdh.dwSize == sizeof(rgn_data->rdh), "Got unexpected structure size %#x.\n", rgn_data->rdh.dwSize);
604 ok(rgn_data->rdh.iType == RDH_RECTANGLES, "Got unexpected type %#x.\n", rgn_data->rdh.iType);
605 ok(rgn_data->rdh.nCount == 1, "Got unexpected count %u.\n", rgn_data->rdh.nCount);
606 ok(rgn_data->rdh.nRgnSize == 16 || broken(rgn_data->rdh.nRgnSize == 168 /* NT4 */),
607 "Got unexpected region size %u.\n", rgn_data->rdh.nRgnSize);
608 ok(EqualRect(&rgn_data->rdh.rcBound, &client_rect),
609 "Got unexpected bounding rect {%d, %d, %d, %d}, expected {%d, %d, %d, %d}.\n",
610 rgn_data->rdh.rcBound.left, rgn_data->rdh.rcBound.top,
611 rgn_data->rdh.rcBound.right, rgn_data->rdh.rcBound.bottom,
612 client_rect.left, client_rect.top, client_rect.right, client_rect.bottom);
613 rect = (RECT *)&rgn_data->Buffer[0];
614 ok(EqualRect(rect, &client_rect),
615 "Got unexpected clip rect {%d, %d, %d, %d}, expected {%d, %d, %d, %d}.\n",
616 rect->left, rect->top, rect->right, rect->bottom,
617 client_rect.left, client_rect.top, client_rect.right, client_rect.bottom);
618 HeapFree(GetProcessHeap(), 0, rgn_data);
620 r1 = CreateRectRgn(0, 0, 320, 240);
621 ok(!!r1, "Failed to create region.\n");
622 r2 = CreateRectRgn(320, 240, 640, 480);
623 ok(!!r2, "Failed to create region.\n");
624 CombineRgn(r1, r1, r2, RGN_OR);
625 ret = GetRegionData(r1, 0, NULL);
626 rgn_data = HeapAlloc(GetProcessHeap(), 0, ret);
627 ret = GetRegionData(r1, ret, rgn_data);
628 ok(!!ret, "Failed to get region data.\n");
633 hr = IDirectDrawClipper_SetClipList(clipper, rgn_data, 0);
634 ok(hr == DDERR_CLIPPERISUSINGHWND, "Got unexpected hr %#x.\n", hr);
635 hr = IDirectDrawClipper_SetHWnd(clipper, 0, NULL);
636 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
637 hr = IDirectDrawClipper_SetClipList(clipper, rgn_data, 0);
638 ok(SUCCEEDED(hr), "Failed to set clip list, hr %#x.\n", hr);
640 HeapFree(GetProcessHeap(), 0, rgn_data);
642 memset(&surface_desc, 0, sizeof(surface_desc));
643 surface_desc.dwSize = sizeof(surface_desc);
644 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
645 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
646 surface_desc.dwWidth = 640;
647 surface_desc.dwHeight = 480;
648 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
649 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB;
650 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount = 32;
651 U2(surface_desc.ddpfPixelFormat).dwRBitMask = 0x00ff0000;
652 U3(surface_desc.ddpfPixelFormat).dwGBitMask = 0x0000ff00;
653 U4(surface_desc.ddpfPixelFormat).dwBBitMask = 0x000000ff;
655 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &src_surface, NULL);
656 ok(SUCCEEDED(hr), "Failed to create source surface, hr %#x.\n", hr);
657 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &dst_surface, NULL);
658 ok(SUCCEEDED(hr), "Failed to create destination surface, hr %#x.\n", hr);
660 memset(&fx, 0, sizeof(fx));
661 fx.dwSize = sizeof(fx);
662 hr = IDirectDrawSurface_Blt(src_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
663 ok(SUCCEEDED(hr), "Failed to clear source surface, hr %#x.\n", hr);
664 hr = IDirectDrawSurface_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
665 ok(SUCCEEDED(hr), "Failed to clear destination surface, hr %#x.\n", hr);
667 hr = IDirectDrawSurface_Lock(src_surface, NULL, &surface_desc, DDLOCK_WAIT, NULL);
668 ok(SUCCEEDED(hr), "Failed to lock source surface, hr %#x.\n", hr);
669 ok(U1(surface_desc).lPitch == 2560, "Got unexpected surface pitch %u.\n", U1(surface_desc).lPitch);
670 ptr = surface_desc.lpSurface;
671 memcpy(&ptr[ 0], &src_data[ 0], 6 * sizeof(DWORD));
672 memcpy(&ptr[ 640], &src_data[ 6], 6 * sizeof(DWORD));
673 memcpy(&ptr[1280], &src_data[12], 6 * sizeof(DWORD));
674 hr = IDirectDrawSurface_Unlock(src_surface, NULL);
675 ok(SUCCEEDED(hr), "Failed to unlock source surface, hr %#x.\n", hr);
677 hr = IDirectDrawSurface_SetClipper(dst_surface, clipper);
678 ok(SUCCEEDED(hr), "Failed to set clipper, hr %#x.\n", hr);
680 SetRect(&src_rect, 1, 1, 5, 2);
681 hr = IDirectDrawSurface_Blt(dst_surface, NULL, src_surface, &src_rect, DDBLT_WAIT, NULL);
682 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
683 for (i = 0; i < 4; ++i)
685 for (j = 0; j < 4; ++j)
687 x = 80 * ((2 * j) + 1);
688 y = 60 * ((2 * i) + 1);
689 color = get_surface_color(dst_surface, x, y);
690 ok(compare_color(color, expected1[i * 4 + j], 1),
691 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected1[i * 4 + j], x, y, color);
695 U5(fx).dwFillColor = 0xff0000ff;
696 hr = IDirectDrawSurface_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
697 ok(SUCCEEDED(hr), "Failed to clear destination surface, hr %#x.\n", hr);
698 for (i = 0; i < 4; ++i)
700 for (j = 0; j < 4; ++j)
702 x = 80 * ((2 * j) + 1);
703 y = 60 * ((2 * i) + 1);
704 color = get_surface_color(dst_surface, x, y);
705 ok(compare_color(color, expected2[i * 4 + j], 1),
706 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected2[i * 4 + j], x, y, color);
710 hr = IDirectDrawSurface_BltFast(dst_surface, 0, 0, src_surface, NULL, DDBLTFAST_WAIT);
711 ok(hr == DDERR_BLTFASTCANTCLIP || broken(hr == E_NOTIMPL /* NT4 */), "Got unexpected hr %#x.\n", hr);
713 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
714 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
715 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
716 ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr);
717 DestroyWindow(window);
718 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
719 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
720 hr = IDirectDrawClipper_SetHWnd(clipper, 0, NULL);
721 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
722 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
723 ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr);
724 hr = IDirectDrawClipper_SetClipList(clipper, NULL, 0);
725 ok(SUCCEEDED(hr), "Failed to set clip list, hr %#x.\n", hr);
726 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
727 ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr);
728 hr = IDirectDrawSurface_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
729 ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr);
731 IDirectDrawSurface_Release(dst_surface);
732 IDirectDrawSurface_Release(src_surface);
733 IDirectDrawClipper_Release(clipper);
734 IDirectDraw_Release(ddraw);
737 static void test_coop_level_d3d_state(void)
739 D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
740 IDirectDrawSurface *rt, *surface;
741 IDirect3DMaterial *background;
742 IDirect3DViewport *viewport;
743 IDirect3DDevice *device;
744 D3DMATERIAL material;
750 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
751 0, 0, 640, 480, 0, 0, 0, 0);
752 if (!(ddraw = create_ddraw()))
754 skip("Failed to create ddraw object, skipping test.\n");
755 DestroyWindow(window);
758 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
760 skip("Failed to create D3D device, skipping test.\n");
761 IDirectDraw_Release(ddraw);
762 DestroyWindow(window);
766 background = create_diffuse_material(device, 1.0f, 0.0f, 0.0f, 1.0f);
767 viewport = create_viewport(device, 0, 0, 640, 480);
768 viewport_set_background(device, viewport, background);
770 hr = IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&rt);
771 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
772 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
773 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
774 color = get_surface_color(rt, 320, 240);
775 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
777 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
778 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
779 hr = IDirectDrawSurface_IsLost(rt);
780 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
781 hr = restore_surfaces(ddraw);
782 ok(SUCCEEDED(hr), "Failed to restore surfaces, hr %#x.\n", hr);
784 memset(&material, 0, sizeof(material));
785 material.dwSize = sizeof(material);
786 U1(U(material).diffuse).r = 0.0f;
787 U2(U(material).diffuse).g = 1.0f;
788 U3(U(material).diffuse).b = 0.0f;
789 U4(U(material).diffuse).a = 1.0f;
790 hr = IDirect3DMaterial_SetMaterial(background, &material);
791 ok(SUCCEEDED(hr), "Failed to set material data, hr %#x.\n", hr);
793 hr = IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&surface);
794 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
795 ok(surface == rt, "Got unexpected surface %p.\n", surface);
796 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
797 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
798 color = get_surface_color(rt, 320, 240);
799 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
801 destroy_viewport(device, viewport);
802 destroy_material(background);
803 IDirectDrawSurface_Release(surface);
804 IDirectDrawSurface_Release(rt);
805 IDirect3DDevice_Release(device);
806 IDirectDraw_Release(ddraw);
807 DestroyWindow(window);
810 static void test_surface_interface_mismatch(void)
812 IDirectDraw *ddraw = NULL;
813 IDirect3D *d3d = NULL;
814 IDirectDrawSurface *surface = NULL, *ds;
815 IDirectDrawSurface3 *surface3 = NULL;
816 IDirect3DDevice *device = NULL;
817 IDirect3DViewport *viewport = NULL;
818 IDirect3DMaterial *background = NULL;
819 DDSURFACEDESC surface_desc;
825 D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
827 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
828 0, 0, 640, 480, 0, 0, 0, 0);
830 if (!(ddraw = create_ddraw()))
832 skip("Failed to create a ddraw object, skipping test.\n");
836 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
837 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
839 memset(&surface_desc, 0, sizeof(surface_desc));
840 surface_desc.dwSize = sizeof(surface_desc);
841 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
842 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
843 surface_desc.dwWidth = 640;
844 surface_desc.dwHeight = 480;
846 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
847 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
849 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirectDrawSurface3, (void **)&surface3);
852 skip("Failed to get the IDirectDrawSurface3 interface, skipping test.\n");
856 hr = IDirectDraw_QueryInterface(ddraw, &IID_IDirect3D, (void **)&d3d);
859 skip("Failed to get the IDirect3D interface, skipping test.\n");
863 hr = IDirect3D_EnumDevices(d3d, enum_z_fmt, &z_depth);
864 if (FAILED(hr) || !z_depth)
866 skip("No depth buffer formats available, skipping test.\n");
870 memset(&surface_desc, 0, sizeof(surface_desc));
871 surface_desc.dwSize = sizeof(surface_desc);
872 surface_desc.dwFlags = DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_WIDTH | DDSD_HEIGHT;
873 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
874 U2(surface_desc).dwZBufferBitDepth = z_depth;
875 surface_desc.dwWidth = 640;
876 surface_desc.dwHeight = 480;
877 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &ds, NULL);
878 ok(SUCCEEDED(hr), "Failed to create depth buffer, hr %#x.\n", hr);
882 /* Using a different surface interface version still works */
883 hr = IDirectDrawSurface3_AddAttachedSurface(surface3, (IDirectDrawSurface3 *)ds);
884 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
885 refcount = IDirectDrawSurface_Release(ds);
886 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
891 hr = IDirectDrawSurface3_QueryInterface(surface3, &IID_IDirect3DHALDevice, (void **)&device);
892 ok(SUCCEEDED(hr), "Failed to create d3d device.\n");
896 background = create_diffuse_material(device, 1.0f, 0.0f, 0.0f, 1.0f);
897 viewport = create_viewport(device, 0, 0, 640, 480);
898 viewport_set_background(device, viewport, background);
900 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
901 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
902 color = get_surface_color(surface, 320, 240);
903 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
907 destroy_viewport(device, viewport);
909 destroy_material(background);
910 if (surface3) IDirectDrawSurface3_Release(surface3);
911 if (surface) IDirectDrawSurface_Release(surface);
912 if (device) IDirect3DDevice_Release(device);
913 if (d3d) IDirect3D_Release(d3d);
914 if (ddraw) IDirectDraw_Release(ddraw);
915 DestroyWindow(window);
918 static void test_coop_level_threaded(void)
920 struct create_window_thread_param p;
924 if (!(ddraw = create_ddraw()))
926 skip("Failed to create a ddraw object, skipping test.\n");
929 create_window_thread(&p);
931 hr = IDirectDraw_SetCooperativeLevel(ddraw, p.window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
932 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
934 IDirectDraw_Release(ddraw);
935 destroy_window_thread(&p);
938 static ULONG get_refcount(IUnknown *test_iface)
940 IUnknown_AddRef(test_iface);
941 return IUnknown_Release(test_iface);
944 static void test_viewport_interfaces(void)
950 IDirect3DViewport *viewport;
951 IDirect3DViewport2 *viewport2;
952 IDirect3DViewport3 *viewport3;
953 IDirectDrawGammaControl *gamma;
956 if (!(ddraw = create_ddraw()))
958 skip("Failed to create ddraw object, skipping test.\n");
961 hr = IDirectDraw_QueryInterface(ddraw, &IID_IDirect3D, (void **)&d3d);
962 ok(SUCCEEDED(hr) || hr == E_NOINTERFACE, "Failed to get d3d interface, hr %#x.\n", hr);
965 skip("Direct3D not available, skipping tests\n");
966 IDirectDraw_Release(ddraw);
969 ref = get_refcount((IUnknown *)d3d);
970 ok(ref == 2, "IDirect3D refcount is %d\n", ref);
972 hr = IDirect3D_CreateViewport(d3d, &viewport, NULL);
973 ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
974 ref = get_refcount((IUnknown *)viewport);
975 ok(ref == 1, "Initial IDirect3DViewport refcount is %u\n", ref);
976 ref = get_refcount((IUnknown *)d3d);
977 ok(ref == 2, "IDirect3D refcount is %u\n", ref);
979 /* E_FAIL return values are returned by Winetestbot Windows NT machines. While not supporting
980 * newer interfaces is legitimate for old ddraw versions, E_FAIL violates Microsoft's rules
981 * for QueryInterface, hence the broken() */
982 gamma = (IDirectDrawGammaControl *)0xdeadbeef;
983 hr = IDirect3DViewport_QueryInterface(viewport, &IID_IDirectDrawGammaControl, (void **)&gamma);
984 ok(hr == E_NOINTERFACE || broken(hr == E_FAIL), "Got unexpected hr %#x.\n", hr);
985 ok(gamma == NULL, "Interface not set to NULL by failed QI call: %p\n", gamma);
986 if (SUCCEEDED(hr)) IDirectDrawGammaControl_Release(gamma);
987 /* NULL iid: Segfaults */
989 hr = IDirect3DViewport_QueryInterface(viewport, &IID_IDirect3DViewport2, (void **)&viewport2);
990 ok(SUCCEEDED(hr) || hr == E_NOINTERFACE || broken(hr == E_FAIL),
991 "Failed to QI IDirect3DViewport2, hr %#x.\n", hr);
994 ref = get_refcount((IUnknown *)viewport);
995 ok(ref == 2, "IDirect3DViewport refcount is %u\n", ref);
996 ref = get_refcount((IUnknown *)viewport2);
997 ok(ref == 2, "IDirect3DViewport2 refcount is %u\n", ref);
998 IDirect3DViewport2_Release(viewport2);
1002 hr = IDirect3DViewport_QueryInterface(viewport, &IID_IDirect3DViewport3, (void **)&viewport3);
1003 ok(SUCCEEDED(hr) || hr == E_NOINTERFACE || broken(hr == E_FAIL),
1004 "Failed to QI IDirect3DViewport3, hr %#x.\n", hr);
1007 ref = get_refcount((IUnknown *)viewport);
1008 ok(ref == 2, "IDirect3DViewport refcount is %u\n", ref);
1009 ref = get_refcount((IUnknown *)viewport3);
1010 ok(ref == 2, "IDirect3DViewport3 refcount is %u\n", ref);
1011 IDirect3DViewport3_Release(viewport3);
1014 hr = IDirect3DViewport_QueryInterface(viewport, &IID_IUnknown, (void **)&unknown);
1015 ok(SUCCEEDED(hr), "Failed to QI IUnknown, hr %#x.\n", hr);
1018 ref = get_refcount((IUnknown *)viewport);
1019 ok(ref == 2, "IDirect3DViewport refcount is %u\n", ref);
1020 ref = get_refcount(unknown);
1021 ok(ref == 2, "IUnknown refcount is %u\n", ref);
1022 IUnknown_Release(unknown);
1025 IDirect3DViewport_Release(viewport);
1026 IDirect3D_Release(d3d);
1027 IDirectDraw_Release(ddraw);
1030 static void test_zenable(void)
1032 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
1033 static D3DTLVERTEX tquad[] =
1035 {{ 0.0f}, {480.0f}, {-0.5f}, {1.0f}, {0xff00ff00}, {0x00000000}, {0.0f}, {0.0f}},
1036 {{ 0.0f}, { 0.0f}, {-0.5f}, {1.0f}, {0xff00ff00}, {0x00000000}, {0.0f}, {0.0f}},
1037 {{640.0f}, {480.0f}, { 1.5f}, {1.0f}, {0xff00ff00}, {0x00000000}, {0.0f}, {0.0f}},
1038 {{640.0f}, { 0.0f}, { 1.5f}, {1.0f}, {0xff00ff00}, {0x00000000}, {0.0f}, {0.0f}},
1040 IDirect3DExecuteBuffer *execute_buffer;
1041 D3DEXECUTEBUFFERDESC exec_desc;
1042 IDirect3DMaterial *background;
1043 IDirect3DViewport *viewport;
1044 IDirect3DDevice *device;
1045 IDirectDrawSurface *rt;
1055 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1056 0, 0, 640, 480, 0, 0, 0, 0);
1057 if (!(ddraw = create_ddraw()))
1059 skip("Failed to create ddraw object, skipping test.\n");
1060 DestroyWindow(window);
1063 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
1065 skip("Failed to create D3D device, skipping test.\n");
1066 IDirectDraw_Release(ddraw);
1067 DestroyWindow(window);
1071 background = create_diffuse_material(device, 1.0f, 0.0f, 0.0f, 1.0f);
1072 viewport = create_viewport(device, 0, 0, 640, 480);
1073 viewport_set_background(device, viewport, background);
1075 memset(&exec_desc, 0, sizeof(exec_desc));
1076 exec_desc.dwSize = sizeof(exec_desc);
1077 exec_desc.dwFlags = D3DDEB_BUFSIZE | D3DDEB_CAPS;
1078 exec_desc.dwBufferSize = 1024;
1079 exec_desc.dwCaps = D3DDEBCAPS_SYSTEMMEMORY;
1081 hr = IDirect3DDevice_CreateExecuteBuffer(device, &exec_desc, &execute_buffer, NULL);
1082 ok(SUCCEEDED(hr), "Failed to create execute buffer, hr %#x.\n", hr);
1083 hr = IDirect3DExecuteBuffer_Lock(execute_buffer, &exec_desc);
1084 ok(SUCCEEDED(hr), "Failed to lock execute buffer, hr %#x.\n", hr);
1085 memcpy(exec_desc.lpData, tquad, sizeof(tquad));
1086 ptr = ((BYTE *)exec_desc.lpData) + sizeof(tquad);
1087 emit_process_vertices(&ptr, 0, 4);
1088 emit_set_rs(&ptr, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
1089 emit_tquad(&ptr, 0);
1091 inst_length = (BYTE *)ptr - (BYTE *)exec_desc.lpData;
1092 inst_length -= sizeof(tquad);
1093 hr = IDirect3DExecuteBuffer_Unlock(execute_buffer);
1094 ok(SUCCEEDED(hr), "Failed to unlock execute buffer, hr %#x.\n", hr);
1096 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
1097 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
1098 hr = IDirect3DDevice_BeginScene(device);
1099 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1100 set_execute_data(execute_buffer, 4, sizeof(tquad), inst_length);
1101 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
1102 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
1103 hr = IDirect3DDevice_EndScene(device);
1104 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1106 hr = IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&rt);
1107 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1108 for (i = 0; i < 4; ++i)
1110 for (j = 0; j < 4; ++j)
1112 x = 80 * ((2 * j) + 1);
1113 y = 60 * ((2 * i) + 1);
1114 color = get_surface_color(rt, x, y);
1115 ok(compare_color(color, 0x0000ff00, 1),
1116 "Expected color 0x0000ff00 at %u, %u, got 0x%08x.\n", x, y, color);
1119 IDirectDrawSurface_Release(rt);
1121 destroy_viewport(device, viewport);
1122 IDirect3DExecuteBuffer_Release(execute_buffer);
1123 destroy_material(background);
1124 IDirect3DDevice_Release(device);
1125 IDirectDraw_Release(ddraw);
1126 DestroyWindow(window);
1129 static void test_ck_rgba(void)
1131 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
1132 static D3DTLVERTEX tquad[] =
1134 {{ 0.0f}, {480.0f}, {0.25f}, {1.0f}, {0xffffffff}, {0x00000000}, {0.0f}, {0.0f}},
1135 {{ 0.0f}, { 0.0f}, {0.25f}, {1.0f}, {0xffffffff}, {0x00000000}, {0.0f}, {1.0f}},
1136 {{640.0f}, {480.0f}, {0.25f}, {1.0f}, {0xffffffff}, {0x00000000}, {1.0f}, {0.0f}},
1137 {{640.0f}, { 0.0f}, {0.25f}, {1.0f}, {0xffffffff}, {0x00000000}, {1.0f}, {1.0f}},
1138 {{ 0.0f}, {480.0f}, {0.75f}, {1.0f}, {0xffffffff}, {0x00000000}, {0.0f}, {0.0f}},
1139 {{ 0.0f}, { 0.0f}, {0.75f}, {1.0f}, {0xffffffff}, {0x00000000}, {0.0f}, {1.0f}},
1140 {{640.0f}, {480.0f}, {0.75f}, {1.0f}, {0xffffffff}, {0x00000000}, {1.0f}, {0.0f}},
1141 {{640.0f}, { 0.0f}, {0.75f}, {1.0f}, {0xffffffff}, {0x00000000}, {1.0f}, {1.0f}},
1145 D3DCOLOR fill_color;
1153 {0xff00ff00, TRUE, TRUE, 0x00ff0000, 0x000000ff},
1154 {0xff00ff00, TRUE, FALSE, 0x00ff0000, 0x000000ff},
1155 {0xff00ff00, FALSE, TRUE, 0x0000ff00, 0x0000ff00},
1156 {0xff00ff00, FALSE, FALSE, 0x0000ff00, 0x0000ff00},
1157 {0x7f00ff00, TRUE, TRUE, 0x00807f00, 0x00807f00},
1158 {0x7f00ff00, TRUE, FALSE, 0x0000ff00, 0x0000ff00},
1159 {0x7f00ff00, FALSE, TRUE, 0x00807f00, 0x00807f00},
1160 {0x7f00ff00, FALSE, FALSE, 0x0000ff00, 0x0000ff00},
1163 IDirect3DExecuteBuffer *execute_buffer;
1164 D3DTEXTUREHANDLE texture_handle;
1165 D3DEXECUTEBUFFERDESC exec_desc;
1166 IDirect3DMaterial *background;
1167 IDirectDrawSurface *surface;
1168 IDirect3DViewport *viewport;
1169 DDSURFACEDESC surface_desc;
1170 IDirect3DTexture *texture;
1171 IDirect3DDevice *device;
1172 IDirectDrawSurface *rt;
1180 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1181 0, 0, 640, 480, 0, 0, 0, 0);
1182 if (!(ddraw = create_ddraw()))
1184 skip("Failed to create ddraw object, skipping test.\n");
1185 DestroyWindow(window);
1188 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
1190 skip("Failed to create D3D device, skipping test.\n");
1191 IDirectDraw_Release(ddraw);
1192 DestroyWindow(window);
1196 background = create_diffuse_material(device, 1.0, 0.0f, 0.0f, 1.0f);
1197 viewport = create_viewport(device, 0, 0, 640, 480);
1198 viewport_set_background(device, viewport, background);
1200 memset(&surface_desc, 0, sizeof(surface_desc));
1201 surface_desc.dwSize = sizeof(surface_desc);
1202 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CKSRCBLT;
1203 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1204 surface_desc.dwWidth = 256;
1205 surface_desc.dwHeight = 256;
1206 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
1207 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
1208 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount = 32;
1209 U2(surface_desc.ddpfPixelFormat).dwRBitMask = 0x00ff0000;
1210 U3(surface_desc.ddpfPixelFormat).dwGBitMask = 0x0000ff00;
1211 U4(surface_desc.ddpfPixelFormat).dwBBitMask = 0x000000ff;
1212 U5(surface_desc.ddpfPixelFormat).dwRGBAlphaBitMask = 0xff000000;
1213 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0xff00ff00;
1214 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0xff00ff00;
1215 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1216 ok(SUCCEEDED(hr), "Failed to create destination surface, hr %#x.\n", hr);
1217 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirect3DTexture, (void **)&texture);
1218 ok(SUCCEEDED(hr), "Failed to get texture interface, hr %#x.\n", hr);
1219 hr = IDirect3DTexture_GetHandle(texture, device, &texture_handle);
1220 ok(SUCCEEDED(hr), "Failed to get texture handle, hr %#x.\n", hr);
1221 IDirect3DTexture_Release(texture);
1223 memset(&exec_desc, 0, sizeof(exec_desc));
1224 exec_desc.dwSize = sizeof(exec_desc);
1225 exec_desc.dwFlags = D3DDEB_BUFSIZE | D3DDEB_CAPS;
1226 exec_desc.dwBufferSize = 1024;
1227 exec_desc.dwCaps = D3DDEBCAPS_SYSTEMMEMORY;
1228 hr = IDirect3DDevice_CreateExecuteBuffer(device, &exec_desc, &execute_buffer, NULL);
1229 ok(SUCCEEDED(hr), "Failed to create execute buffer, hr %#x.\n", hr);
1231 hr = IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&rt);
1232 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1234 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
1236 UINT draw1_len, draw2_len;
1239 hr = IDirect3DExecuteBuffer_Lock(execute_buffer, &exec_desc);
1240 ok(SUCCEEDED(hr), "Failed to lock execute buffer, hr %#x.\n", hr);
1241 memcpy(exec_desc.lpData, tquad, sizeof(tquad));
1242 ptr = ((BYTE *)exec_desc.lpData) + sizeof(tquad);
1243 emit_process_vertices(&ptr, 0, 4);
1244 emit_set_rs(&ptr, D3DRENDERSTATE_TEXTUREHANDLE, texture_handle);
1245 emit_set_rs(&ptr, D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);
1246 emit_set_rs(&ptr, D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA);
1247 emit_set_rs(&ptr, D3DRENDERSTATE_COLORKEYENABLE, tests[i].color_key);
1248 emit_set_rs(&ptr, D3DRENDERSTATE_ALPHABLENDENABLE, tests[i].blend);
1249 emit_tquad(&ptr, 0);
1251 draw1_len = (BYTE *)ptr - (BYTE *)exec_desc.lpData - sizeof(tquad);
1252 emit_process_vertices(&ptr, 4, 4);
1253 emit_tquad(&ptr, 0);
1254 emit_set_rs(&ptr, D3DRENDERSTATE_TEXTUREHANDLE, 0);
1256 draw2_len = (BYTE *)ptr - (BYTE *)exec_desc.lpData - draw1_len;
1257 hr = IDirect3DExecuteBuffer_Unlock(execute_buffer);
1258 ok(SUCCEEDED(hr), "Failed to unlock execute buffer, hr %#x.\n", hr);
1260 memset(&fx, 0, sizeof(fx));
1261 fx.dwSize = sizeof(fx);
1262 U5(fx).dwFillColor = tests[i].fill_color;
1263 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
1264 ok(SUCCEEDED(hr), "Failed to fill texture, hr %#x.\n", hr);
1266 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER);
1267 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
1268 hr = IDirect3DDevice_BeginScene(device);
1269 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1270 set_execute_data(execute_buffer, 8, sizeof(tquad), draw1_len);
1271 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
1272 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
1273 hr = IDirect3DDevice_EndScene(device);
1274 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1276 color = get_surface_color(rt, 320, 240);
1278 todo_wine ok(compare_color(color, tests[i].result1, 1), "Expected color 0x%08x for test %u, got 0x%08x.\n",
1279 tests[i].result1, i, color);
1281 ok(compare_color(color, tests[i].result1, 1), "Expected color 0x%08x for test %u, got 0x%08x.\n",
1282 tests[i].result1, i, color);
1284 U5(fx).dwFillColor = 0xff0000ff;
1285 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
1286 ok(SUCCEEDED(hr), "Failed to fill texture, hr %#x.\n", hr);
1288 hr = IDirect3DDevice_BeginScene(device);
1289 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1290 set_execute_data(execute_buffer, 8, sizeof(tquad) + draw1_len, draw2_len);
1291 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
1292 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
1293 hr = IDirect3DDevice_EndScene(device);
1294 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1296 /* This tests that fragments that are masked out by the color key are
1297 * discarded, instead of just fully transparent. */
1298 color = get_surface_color(rt, 320, 240);
1300 todo_wine ok(compare_color(color, tests[i].result2, 1), "Expected color 0x%08x for test %u, got 0x%08x.\n",
1301 tests[i].result2, i, color);
1303 ok(compare_color(color, tests[i].result2, 1), "Expected color 0x%08x for test %u, got 0x%08x.\n",
1304 tests[i].result2, i, color);
1307 IDirectDrawSurface_Release(rt);
1308 IDirect3DExecuteBuffer_Release(execute_buffer);
1309 IDirectDrawSurface_Release(surface);
1310 destroy_viewport(device, viewport);
1311 destroy_material(background);
1312 IDirect3DDevice_Release(device);
1313 IDirectDraw_Release(ddraw);
1314 DestroyWindow(window);
1317 static void test_ck_default(void)
1319 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
1320 static D3DTLVERTEX tquad[] =
1322 {{ 0.0f}, {480.0f}, {0.0f}, {1.0f}, {0xffffffff}, {0x00000000}, {0.0f}, {0.0f}},
1323 {{ 0.0f}, { 0.0f}, {0.0f}, {1.0f}, {0xffffffff}, {0x00000000}, {0.0f}, {1.0f}},
1324 {{640.0f}, {480.0f}, {0.0f}, {1.0f}, {0xffffffff}, {0x00000000}, {1.0f}, {0.0f}},
1325 {{640.0f}, { 0.0f}, {0.0f}, {1.0f}, {0xffffffff}, {0x00000000}, {1.0f}, {1.0f}},
1327 IDirect3DExecuteBuffer *execute_buffer;
1328 IDirectDrawSurface *surface, *rt;
1329 D3DTEXTUREHANDLE texture_handle;
1330 D3DEXECUTEBUFFERDESC exec_desc;
1331 IDirect3DMaterial *background;
1332 UINT draw1_offset, draw1_len;
1333 UINT draw2_offset, draw2_len;
1334 UINT draw3_offset, draw3_len;
1335 UINT draw4_offset, draw4_len;
1336 IDirect3DViewport *viewport;
1337 DDSURFACEDESC surface_desc;
1338 IDirect3DTexture *texture;
1339 IDirect3DDevice *device;
1347 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1348 0, 0, 640, 480, 0, 0, 0, 0);
1350 if (!(ddraw = create_ddraw()))
1352 skip("Failed to create ddraw object, skipping test.\n");
1353 DestroyWindow(window);
1356 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
1358 skip("Failed to create D3D device, skipping test.\n");
1359 IDirectDraw_Release(ddraw);
1360 DestroyWindow(window);
1364 hr = IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&rt);
1365 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1367 background = create_diffuse_material(device, 0.0, 1.0f, 0.0f, 1.0f);
1368 viewport = create_viewport(device, 0, 0, 640, 480);
1369 viewport_set_background(device, viewport, background);
1371 memset(&surface_desc, 0, sizeof(surface_desc));
1372 surface_desc.dwSize = sizeof(surface_desc);
1373 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CKSRCBLT;
1374 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1375 surface_desc.dwWidth = 256;
1376 surface_desc.dwHeight = 256;
1377 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
1378 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB;
1379 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount = 32;
1380 U2(surface_desc.ddpfPixelFormat).dwRBitMask = 0x00ff0000;
1381 U3(surface_desc.ddpfPixelFormat).dwGBitMask = 0x0000ff00;
1382 U4(surface_desc.ddpfPixelFormat).dwBBitMask = 0x000000ff;
1383 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x000000ff;
1384 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x000000ff;
1385 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1386 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1387 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirect3DTexture, (void **)&texture);
1388 ok(SUCCEEDED(hr), "Failed to get texture interface, hr %#x.\n", hr);
1389 hr = IDirect3DTexture_GetHandle(texture, device, &texture_handle);
1390 ok(SUCCEEDED(hr), "Failed to get texture handle, hr %#x.\n", hr);
1391 IDirect3DTexture_Release(texture);
1393 memset(&fx, 0, sizeof(fx));
1394 fx.dwSize = sizeof(fx);
1395 U5(fx).dwFillColor = 0x000000ff;
1396 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
1397 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
1399 memset(&exec_desc, 0, sizeof(exec_desc));
1400 exec_desc.dwSize = sizeof(exec_desc);
1401 exec_desc.dwFlags = D3DDEB_BUFSIZE | D3DDEB_CAPS;
1402 exec_desc.dwBufferSize = 1024;
1403 exec_desc.dwCaps = D3DDEBCAPS_SYSTEMMEMORY;
1404 hr = IDirect3DDevice_CreateExecuteBuffer(device, &exec_desc, &execute_buffer, NULL);
1405 ok(SUCCEEDED(hr), "Failed to create execute buffer, hr %#x.\n", hr);
1407 hr = IDirect3DExecuteBuffer_Lock(execute_buffer, &exec_desc);
1408 ok(SUCCEEDED(hr), "Failed to lock execute buffer, hr %#x.\n", hr);
1409 memcpy(exec_desc.lpData, tquad, sizeof(tquad));
1410 ptr = (BYTE *)exec_desc.lpData + sizeof(tquad);
1411 emit_process_vertices(&ptr, 0, 4);
1412 emit_set_rs(&ptr, D3DRENDERSTATE_TEXTUREHANDLE, texture_handle);
1413 emit_tquad(&ptr, 0);
1415 draw1_offset = sizeof(tquad);
1416 draw1_len = (BYTE *)ptr - (BYTE *)exec_desc.lpData - draw1_offset;
1417 emit_process_vertices(&ptr, 0, 4);
1418 emit_set_rs(&ptr, D3DRENDERSTATE_COLORKEYENABLE, FALSE);
1419 emit_tquad(&ptr, 0);
1421 draw2_offset = draw1_offset + draw1_len;
1422 draw2_len = (BYTE *)ptr - (BYTE *)exec_desc.lpData - draw2_offset;
1423 emit_process_vertices(&ptr, 0, 4);
1424 emit_tquad(&ptr, 0);
1426 draw3_offset = draw2_offset + draw2_len;
1427 draw3_len = (BYTE *)ptr - (BYTE *)exec_desc.lpData - draw3_offset;
1428 emit_process_vertices(&ptr, 0, 4);
1429 emit_set_rs(&ptr, D3DRENDERSTATE_COLORKEYENABLE, TRUE);
1430 emit_tquad(&ptr, 0);
1431 emit_set_rs(&ptr, D3DRENDERSTATE_TEXTUREHANDLE, 0);
1433 draw4_offset = draw3_offset + draw3_len;
1434 draw4_len = (BYTE *)ptr - (BYTE *)exec_desc.lpData - draw4_offset;
1435 hr = IDirect3DExecuteBuffer_Unlock(execute_buffer);
1436 ok(SUCCEEDED(hr), "Failed to unlock execute buffer, hr %#x.\n", hr);
1438 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
1439 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
1440 hr = IDirect3DDevice_BeginScene(device);
1441 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1442 set_execute_data(execute_buffer, 4, draw1_offset, draw1_len);
1443 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
1444 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
1445 hr = IDirect3DDevice_EndScene(device);
1446 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1447 color = get_surface_color(rt, 320, 240);
1448 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
1450 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
1451 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
1452 hr = IDirect3DDevice_BeginScene(device);
1453 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1454 set_execute_data(execute_buffer, 4, draw2_offset, draw2_len);
1455 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
1456 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
1457 hr = IDirect3DDevice_EndScene(device);
1458 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1459 color = get_surface_color(rt, 320, 240);
1460 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
1462 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
1463 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
1464 hr = IDirect3DDevice_BeginScene(device);
1465 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1466 set_execute_data(execute_buffer, 4, draw3_offset, draw3_len);
1467 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
1468 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
1469 hr = IDirect3DDevice_EndScene(device);
1470 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1471 color = get_surface_color(rt, 320, 240);
1472 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
1474 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
1475 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
1476 hr = IDirect3DDevice_BeginScene(device);
1477 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1478 set_execute_data(execute_buffer, 4, draw4_offset, draw4_len);
1479 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
1480 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
1481 hr = IDirect3DDevice_EndScene(device);
1482 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1483 color = get_surface_color(rt, 320, 240);
1484 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
1486 IDirect3DExecuteBuffer_Release(execute_buffer);
1487 IDirectDrawSurface_Release(surface);
1488 destroy_viewport(device, viewport);
1489 destroy_material(background);
1490 IDirectDrawSurface_Release(rt);
1491 IDirect3DDevice_Release(device);
1492 IDirectDraw_Release(ddraw);
1493 DestroyWindow(window);
1499 REFIID refcount_iid;
1503 static void test_qi(const char *test_name, IUnknown *base_iface,
1504 REFIID refcount_iid, const struct qi_test *tests, UINT entry_count)
1506 ULONG refcount, expected_refcount;
1507 IUnknown *iface1, *iface2;
1511 for (i = 0; i < entry_count; ++i)
1513 hr = IUnknown_QueryInterface(base_iface, tests[i].iid, (void **)&iface1);
1514 ok(hr == tests[i].hr, "Got hr %#x for test \"%s\" %u.\n", hr, test_name, i);
1517 for (j = 0; j < entry_count; ++j)
1519 hr = IUnknown_QueryInterface(iface1, tests[j].iid, (void **)&iface2);
1520 ok(hr == tests[j].hr, "Got hr %#x for test \"%s\" %u, %u.\n", hr, test_name, i, j);
1523 expected_refcount = 0;
1524 if (IsEqualGUID(refcount_iid, tests[j].refcount_iid))
1525 ++expected_refcount;
1526 if (IsEqualGUID(tests[i].refcount_iid, tests[j].refcount_iid))
1527 ++expected_refcount;
1528 refcount = IUnknown_Release(iface2);
1529 ok(refcount == expected_refcount, "Got refcount %u for test \"%s\" %u, %u, expected %u.\n",
1530 refcount, test_name, i, j, expected_refcount);
1534 expected_refcount = 0;
1535 if (IsEqualGUID(refcount_iid, tests[i].refcount_iid))
1536 ++expected_refcount;
1537 refcount = IUnknown_Release(iface1);
1538 ok(refcount == expected_refcount, "Got refcount %u for test \"%s\" %u, expected %u.\n",
1539 refcount, test_name, i, expected_refcount);
1544 static void test_surface_qi(void)
1546 static const struct qi_test tests[] =
1548 {&IID_IDirect3DTexture2, &IID_IDirectDrawSurface, S_OK },
1549 {&IID_IDirect3DTexture, &IID_IDirectDrawSurface, S_OK },
1550 {&IID_IDirectDrawGammaControl, &IID_IDirectDrawGammaControl, S_OK },
1551 {&IID_IDirectDrawColorControl, NULL, E_NOINTERFACE},
1552 {&IID_IDirectDrawSurface7, &IID_IDirectDrawSurface7, S_OK },
1553 {&IID_IDirectDrawSurface4, &IID_IDirectDrawSurface4, S_OK },
1554 {&IID_IDirectDrawSurface3, &IID_IDirectDrawSurface3, S_OK },
1555 {&IID_IDirectDrawSurface2, &IID_IDirectDrawSurface2, S_OK },
1556 {&IID_IDirectDrawSurface, &IID_IDirectDrawSurface, S_OK },
1557 {&IID_IDirect3DDevice7, NULL, E_INVALIDARG },
1558 {&IID_IDirect3DDevice3, NULL, E_INVALIDARG },
1559 {&IID_IDirect3DDevice2, NULL, E_INVALIDARG },
1560 {&IID_IDirect3DDevice, NULL, E_INVALIDARG },
1561 {&IID_IDirect3D7, NULL, E_INVALIDARG },
1562 {&IID_IDirect3D3, NULL, E_INVALIDARG },
1563 {&IID_IDirect3D2, NULL, E_INVALIDARG },
1564 {&IID_IDirect3D, NULL, E_INVALIDARG },
1565 {&IID_IDirectDraw7, NULL, E_INVALIDARG },
1566 {&IID_IDirectDraw4, NULL, E_INVALIDARG },
1567 {&IID_IDirectDraw3, NULL, E_INVALIDARG },
1568 {&IID_IDirectDraw2, NULL, E_INVALIDARG },
1569 {&IID_IDirectDraw, NULL, E_INVALIDARG },
1570 {&IID_IDirect3DLight, NULL, E_INVALIDARG },
1571 {&IID_IDirect3DMaterial, NULL, E_INVALIDARG },
1572 {&IID_IDirect3DMaterial2, NULL, E_INVALIDARG },
1573 {&IID_IDirect3DMaterial3, NULL, E_INVALIDARG },
1574 {&IID_IDirect3DExecuteBuffer, NULL, E_INVALIDARG },
1575 {&IID_IDirect3DViewport, NULL, E_INVALIDARG },
1576 {&IID_IDirect3DViewport2, NULL, E_INVALIDARG },
1577 {&IID_IDirect3DViewport3, NULL, E_INVALIDARG },
1578 {&IID_IDirect3DVertexBuffer, NULL, E_INVALIDARG },
1579 {&IID_IDirect3DVertexBuffer7, NULL, E_INVALIDARG },
1580 {&IID_IDirectDrawPalette, NULL, E_INVALIDARG },
1581 {&IID_IDirectDrawClipper, NULL, E_INVALIDARG },
1582 {&IID_IUnknown, &IID_IDirectDrawSurface, S_OK },
1585 IDirectDrawSurface *surface;
1586 DDSURFACEDESC surface_desc;
1587 IDirect3DDevice *device;
1592 if (!GetProcAddress(GetModuleHandleA("ddraw.dll"), "DirectDrawCreateEx"))
1594 win_skip("DirectDrawCreateEx not available, skipping test.\n");
1598 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1599 0, 0, 640, 480, 0, 0, 0, 0);
1600 if (!(ddraw = create_ddraw()))
1602 skip("Failed to create a ddraw object, skipping test.\n");
1603 DestroyWindow(window);
1606 /* Try to create a D3D device to see if the ddraw implementation supports
1607 * D3D. 64-bit ddraw in particular doesn't seem to support D3D, and
1608 * doesn't support e.g. the IDirect3DTexture interfaces. */
1609 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
1611 skip("Failed to create D3D device, skipping test.\n");
1612 IDirectDraw_Release(ddraw);
1613 DestroyWindow(window);
1616 IDirect3DDevice_Release(device);
1618 memset(&surface_desc, 0, sizeof(surface_desc));
1619 surface_desc.dwSize = sizeof(surface_desc);
1620 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1621 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1622 surface_desc.dwWidth = 512;
1623 surface_desc.dwHeight = 512;
1624 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1625 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1627 test_qi("surface_qi", (IUnknown *)surface, &IID_IDirectDrawSurface, tests, sizeof(tests) / sizeof(*tests));
1629 IDirectDrawSurface_Release(surface);
1630 IDirectDraw_Release(ddraw);
1631 DestroyWindow(window);
1634 static void test_device_qi(void)
1636 static const struct qi_test tests[] =
1638 {&IID_IDirect3DTexture2, &IID_IDirectDrawSurface, S_OK },
1639 {&IID_IDirect3DTexture, &IID_IDirectDrawSurface, S_OK },
1640 {&IID_IDirectDrawGammaControl, &IID_IDirectDrawGammaControl, S_OK },
1641 {&IID_IDirectDrawColorControl, NULL, E_NOINTERFACE},
1642 {&IID_IDirectDrawSurface7, &IID_IDirectDrawSurface7, S_OK },
1643 {&IID_IDirectDrawSurface4, &IID_IDirectDrawSurface4, S_OK },
1644 {&IID_IDirectDrawSurface3, &IID_IDirectDrawSurface3, S_OK },
1645 {&IID_IDirectDrawSurface2, &IID_IDirectDrawSurface2, S_OK },
1646 {&IID_IDirectDrawSurface, &IID_IDirectDrawSurface, S_OK },
1647 {&IID_IDirect3DDevice7, NULL, E_INVALIDARG },
1648 {&IID_IDirect3DDevice3, NULL, E_INVALIDARG },
1649 {&IID_IDirect3DDevice2, NULL, E_INVALIDARG },
1650 {&IID_IDirect3DDevice, NULL, E_INVALIDARG },
1651 {&IID_IDirect3DHALDevice, &IID_IDirectDrawSurface, S_OK },
1652 {&IID_IDirect3D7, NULL, E_INVALIDARG },
1653 {&IID_IDirect3D3, NULL, E_INVALIDARG },
1654 {&IID_IDirect3D2, NULL, E_INVALIDARG },
1655 {&IID_IDirect3D, NULL, E_INVALIDARG },
1656 {&IID_IDirectDraw7, NULL, E_INVALIDARG },
1657 {&IID_IDirectDraw4, NULL, E_INVALIDARG },
1658 {&IID_IDirectDraw3, NULL, E_INVALIDARG },
1659 {&IID_IDirectDraw2, NULL, E_INVALIDARG },
1660 {&IID_IDirectDraw, NULL, E_INVALIDARG },
1661 {&IID_IDirect3DLight, NULL, E_INVALIDARG },
1662 {&IID_IDirect3DMaterial, NULL, E_INVALIDARG },
1663 {&IID_IDirect3DMaterial2, NULL, E_INVALIDARG },
1664 {&IID_IDirect3DMaterial3, NULL, E_INVALIDARG },
1665 {&IID_IDirect3DExecuteBuffer, NULL, E_INVALIDARG },
1666 {&IID_IDirect3DViewport, NULL, E_INVALIDARG },
1667 {&IID_IDirect3DViewport2, NULL, E_INVALIDARG },
1668 {&IID_IDirect3DViewport3, NULL, E_INVALIDARG },
1669 {&IID_IDirect3DVertexBuffer, NULL, E_INVALIDARG },
1670 {&IID_IDirect3DVertexBuffer7, NULL, E_INVALIDARG },
1671 {&IID_IDirectDrawPalette, NULL, E_INVALIDARG },
1672 {&IID_IDirectDrawClipper, NULL, E_INVALIDARG },
1673 {&IID_IUnknown, &IID_IDirectDrawSurface, S_OK },
1677 IDirect3DDevice *device;
1681 if (!GetProcAddress(GetModuleHandleA("ddraw.dll"), "DirectDrawCreateEx"))
1683 win_skip("DirectDrawCreateEx not available, skipping test.\n");
1687 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1688 0, 0, 640, 480, 0, 0, 0, 0);
1689 if (!(ddraw = create_ddraw()))
1691 skip("Failed to create ddraw object, skipping test.\n");
1692 DestroyWindow(window);
1695 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
1697 skip("Failed to create D3D device, skipping test.\n");
1698 IDirectDraw_Release(ddraw);
1699 DestroyWindow(window);
1703 test_qi("device_qi", (IUnknown *)device, &IID_IDirectDrawSurface, tests, sizeof(tests) / sizeof(*tests));
1705 IDirect3DDevice_Release(device);
1706 IDirectDraw_Release(ddraw);
1707 DestroyWindow(window);
1710 static void test_wndproc(void)
1712 LONG_PTR proc, ddraw_proc;
1719 static const UINT messages[] =
1721 WM_WINDOWPOSCHANGING,
1724 WM_WINDOWPOSCHANGING,
1730 /* DDSCL_EXCLUSIVE replaces the window's window proc. */
1731 if (!(ddraw = create_ddraw()))
1733 skip("Failed to create IDirectDraw object, skipping tests.\n");
1737 wc.lpfnWndProc = test_proc;
1738 wc.lpszClassName = "ddraw_test_wndproc_wc";
1739 ok(RegisterClassA(&wc), "Failed to register window class.\n");
1741 window = CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
1742 WS_MAXIMIZE | WS_CAPTION , 0, 0, 640, 480, 0, 0, 0, 0);
1744 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
1745 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1746 (LONG_PTR)test_proc, proc);
1747 expect_messages = messages;
1748 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
1749 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
1750 ok(!*expect_messages, "Expected message %#x, but didn't receive it.\n", *expect_messages);
1751 expect_messages = NULL;
1752 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
1753 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
1754 (LONG_PTR)test_proc, proc);
1755 ref = IDirectDraw_Release(ddraw);
1756 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
1757 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
1758 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1759 (LONG_PTR)test_proc, proc);
1761 /* DDSCL_NORMAL doesn't. */
1762 ddraw = create_ddraw();
1763 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
1764 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1765 (LONG_PTR)test_proc, proc);
1766 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL | DDSCL_FULLSCREEN);
1767 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
1768 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
1769 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1770 (LONG_PTR)test_proc, proc);
1771 ref = IDirectDraw_Release(ddraw);
1772 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
1773 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
1774 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1775 (LONG_PTR)test_proc, proc);
1777 /* The original window proc is only restored by ddraw if the current
1778 * window proc matches the one ddraw set. This also affects switching
1779 * from DDSCL_NORMAL to DDSCL_EXCLUSIVE. */
1780 ddraw = create_ddraw();
1781 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
1782 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1783 (LONG_PTR)test_proc, proc);
1784 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
1785 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
1786 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
1787 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
1788 (LONG_PTR)test_proc, proc);
1790 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
1791 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
1792 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
1793 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1794 (LONG_PTR)test_proc, proc);
1795 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
1796 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
1797 proc = SetWindowLongPtrA(window, GWLP_WNDPROC, (LONG_PTR)DefWindowProcA);
1798 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
1799 (LONG_PTR)test_proc, proc);
1800 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
1801 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
1802 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
1803 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#lx, got %#lx.\n",
1804 (LONG_PTR)DefWindowProcA, proc);
1805 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
1806 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
1807 proc = SetWindowLongPtrA(window, GWLP_WNDPROC, (LONG_PTR)ddraw_proc);
1808 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#lx, got %#lx.\n",
1809 (LONG_PTR)DefWindowProcA, proc);
1810 ref = IDirectDraw_Release(ddraw);
1811 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
1812 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
1813 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1814 (LONG_PTR)test_proc, proc);
1816 ddraw = create_ddraw();
1817 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
1818 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1819 (LONG_PTR)test_proc, proc);
1820 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
1821 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
1822 proc = SetWindowLongPtrA(window, GWLP_WNDPROC, (LONG_PTR)DefWindowProcA);
1823 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
1824 (LONG_PTR)test_proc, proc);
1825 ref = IDirectDraw_Release(ddraw);
1826 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
1827 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
1828 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#lx, got %#lx.\n",
1829 (LONG_PTR)DefWindowProcA, proc);
1831 fix_wndproc(window, (LONG_PTR)test_proc);
1832 expect_messages = NULL;
1833 DestroyWindow(window);
1834 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL));
1837 static void test_window_style(void)
1839 LONG style, exstyle, tmp;
1840 RECT fullscreen_rect, r;
1846 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1847 0, 0, 100, 100, 0, 0, 0, 0);
1848 if (!(ddraw = create_ddraw()))
1850 skip("Failed to create a ddraw object, skipping test.\n");
1851 DestroyWindow(window);
1855 style = GetWindowLongA(window, GWL_STYLE);
1856 exstyle = GetWindowLongA(window, GWL_EXSTYLE);
1857 SetRect(&fullscreen_rect, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
1859 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
1860 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
1862 tmp = GetWindowLongA(window, GWL_STYLE);
1863 todo_wine ok(tmp == style, "Expected window style %#x, got %#x.\n", style, tmp);
1864 tmp = GetWindowLongA(window, GWL_EXSTYLE);
1865 todo_wine ok(tmp == exstyle, "Expected window extended style %#x, got %#x.\n", exstyle, tmp);
1867 GetWindowRect(window, &r);
1868 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
1869 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
1870 r.left, r.top, r.right, r.bottom);
1871 GetClientRect(window, &r);
1872 todo_wine ok(!EqualRect(&r, &fullscreen_rect), "Client rect and window rect are equal.\n");
1874 ref = IDirectDraw_Release(ddraw);
1875 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
1877 DestroyWindow(window);
1880 static void test_redundant_mode_set(void)
1882 DDSURFACEDESC surface_desc = {0};
1889 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1890 0, 0, 100, 100, 0, 0, 0, 0);
1891 if (!(ddraw = create_ddraw()))
1893 skip("Failed to create a ddraw object, skipping test.\n");
1894 DestroyWindow(window);
1898 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
1899 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
1901 surface_desc.dwSize = sizeof(surface_desc);
1902 hr = IDirectDraw_GetDisplayMode(ddraw, &surface_desc);
1903 ok(SUCCEEDED(hr), "GetDipslayMode failed, hr %#x.\n", hr);
1905 hr = IDirectDraw_SetDisplayMode(ddraw, surface_desc.dwWidth, surface_desc.dwHeight,
1906 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount);
1907 ok(SUCCEEDED(hr), "SetDipslayMode failed, hr %#x.\n", hr);
1909 GetWindowRect(window, &r);
1912 SetWindowPos(window, HWND_TOP, r.left, r.top, r.right, r.bottom, 0);
1913 GetWindowRect(window, &s);
1914 ok(EqualRect(&r, &s), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
1915 r.left, r.top, r.right, r.bottom,
1916 s.left, s.top, s.right, s.bottom);
1918 hr = IDirectDraw_SetDisplayMode(ddraw, surface_desc.dwWidth, surface_desc.dwHeight,
1919 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount);
1920 ok(SUCCEEDED(hr), "SetDipslayMode failed, hr %#x.\n", hr);
1922 GetWindowRect(window, &s);
1923 ok(EqualRect(&r, &s), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
1924 r.left, r.top, r.right, r.bottom,
1925 s.left, s.top, s.right, s.bottom);
1927 ref = IDirectDraw_Release(ddraw);
1928 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
1930 DestroyWindow(window);
1933 static SIZE screen_size;
1935 static LRESULT CALLBACK mode_set_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
1937 if (message == WM_SIZE)
1939 screen_size.cx = GetSystemMetrics(SM_CXSCREEN);
1940 screen_size.cy = GetSystemMetrics(SM_CYSCREEN);
1943 return test_proc(hwnd, message, wparam, lparam);
1946 static void test_coop_level_mode_set(void)
1948 IDirectDrawSurface *primary;
1949 RECT fullscreen_rect, r, s;
1957 static const UINT exclusive_messages[] =
1959 WM_WINDOWPOSCHANGING,
1960 WM_WINDOWPOSCHANGED,
1966 static const UINT normal_messages[] =
1972 if (!(ddraw = create_ddraw()))
1974 skip("Failed to create a ddraw object, skipping test.\n");
1978 wc.lpfnWndProc = mode_set_proc;
1979 wc.lpszClassName = "ddraw_test_wndproc_wc";
1980 ok(RegisterClassA(&wc), "Failed to register window class.\n");
1982 window = CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test", WS_OVERLAPPEDWINDOW,
1983 0, 0, 100, 100, 0, 0, 0, 0);
1985 SetRect(&fullscreen_rect, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
1986 SetRect(&s, 0, 0, 640, 480);
1988 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
1989 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
1991 GetWindowRect(window, &r);
1992 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
1993 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
1994 r.left, r.top, r.right, r.bottom);
1996 memset(&ddsd, 0, sizeof(ddsd));
1997 ddsd.dwSize = sizeof(ddsd);
1998 ddsd.dwFlags = DDSD_CAPS;
1999 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2001 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &primary, NULL);
2002 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2003 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2004 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2005 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2006 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2007 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2008 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2010 GetWindowRect(window, &r);
2011 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2012 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2013 r.left, r.top, r.right, r.bottom);
2015 expect_messages = exclusive_messages;
2019 hr = IDirectDraw_SetDisplayMode(ddraw, 640, 480, 32);
2020 ok(SUCCEEDED(hr), "SetDipslayMode failed, hr %#x.\n", hr);
2022 ok(!*expect_messages, "Expected message %#x, but didn't receive it.\n", *expect_messages);
2023 expect_messages = NULL;
2024 ok(screen_size.cx == s.right && screen_size.cy == s.bottom,
2025 "Expected screen size %ux%u, got %ux%u.\n",
2026 s.right, s.bottom, screen_size.cx, screen_size.cy);
2028 GetWindowRect(window, &r);
2029 ok(EqualRect(&r, &s), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2030 s.left, s.top, s.right, s.bottom,
2031 r.left, r.top, r.right, r.bottom);
2033 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2034 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2035 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2036 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2037 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2038 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2039 IDirectDrawSurface_Release(primary);
2041 memset(&ddsd, 0, sizeof(ddsd));
2042 ddsd.dwSize = sizeof(ddsd);
2043 ddsd.dwFlags = DDSD_CAPS;
2044 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2046 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &primary, NULL);
2047 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2048 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2049 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2050 ok(ddsd.dwWidth == s.right - s.left, "Expected surface width %u, got %u.\n",
2051 s.right - s.left, ddsd.dwWidth);
2052 ok(ddsd.dwHeight == s.bottom - s.top, "Expected surface height %u, got %u.\n",
2053 s.bottom - s.top, ddsd.dwHeight);
2055 GetWindowRect(window, &r);
2056 ok(EqualRect(&r, &s), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2057 s.left, s.top, s.right, s.bottom,
2058 r.left, r.top, r.right, r.bottom);
2060 expect_messages = exclusive_messages;
2064 hr = IDirectDraw_RestoreDisplayMode(ddraw);
2065 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
2067 ok(!*expect_messages, "Expected message %#x, but didn't receive it.\n", *expect_messages);
2068 expect_messages = NULL;
2069 ok(screen_size.cx == fullscreen_rect.right && screen_size.cy == fullscreen_rect.bottom,
2070 "Expected screen size %ux%u, got %ux%u.\n",
2071 fullscreen_rect.right, fullscreen_rect.bottom, screen_size.cx, screen_size.cy);
2073 GetWindowRect(window, &r);
2074 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2075 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2076 r.left, r.top, r.right, r.bottom);
2078 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2079 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2080 ok(ddsd.dwWidth == s.right - s.left, "Expected surface width %u, got %u.\n",
2081 s.right - s.left, ddsd.dwWidth);
2082 ok(ddsd.dwHeight == s.bottom - s.top, "Expected surface height %u, got %u.\n",
2083 s.bottom - s.top, ddsd.dwHeight);
2084 IDirectDrawSurface_Release(primary);
2086 memset(&ddsd, 0, sizeof(ddsd));
2087 ddsd.dwSize = sizeof(ddsd);
2088 ddsd.dwFlags = DDSD_CAPS;
2089 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2091 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &primary, NULL);
2092 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2093 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2094 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2095 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2096 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2097 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2098 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2100 GetWindowRect(window, &r);
2101 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2102 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2103 r.left, r.top, r.right, r.bottom);
2105 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2106 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2108 GetWindowRect(window, &r);
2109 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2110 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2111 r.left, r.top, r.right, r.bottom);
2113 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2114 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2115 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2116 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2117 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2118 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2119 IDirectDrawSurface_Release(primary);
2121 memset(&ddsd, 0, sizeof(ddsd));
2122 ddsd.dwSize = sizeof(ddsd);
2123 ddsd.dwFlags = DDSD_CAPS;
2124 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2126 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &primary, NULL);
2127 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2128 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2129 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2130 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2131 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2132 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2133 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2135 GetWindowRect(window, &r);
2136 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2137 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2138 r.left, r.top, r.right, r.bottom);
2140 expect_messages = normal_messages;
2144 hr = IDirectDraw_SetDisplayMode(ddraw, 640, 480, 32);
2145 ok(SUCCEEDED(hr) || broken(hr == DDERR_NOEXCLUSIVEMODE) /* NT4 testbot */,
2146 "SetDipslayMode failed, hr %#x.\n", hr);
2147 if (hr == DDERR_NOEXCLUSIVEMODE)
2149 win_skip("Broken SetDisplayMode(), skipping remaining tests.\n");
2150 IDirectDrawSurface_Release(primary);
2151 IDirectDraw_Release(ddraw);
2155 ok(!*expect_messages, "Expected message %#x, but didn't receive it.\n", *expect_messages);
2156 expect_messages = NULL;
2157 ok(!screen_size.cx && !screen_size.cy, "Got unxpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2159 GetWindowRect(window, &r);
2160 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2161 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2162 r.left, r.top, r.right, r.bottom);
2164 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2165 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2166 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2167 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2168 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2169 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2170 IDirectDrawSurface_Release(primary);
2172 memset(&ddsd, 0, sizeof(ddsd));
2173 ddsd.dwSize = sizeof(ddsd);
2174 ddsd.dwFlags = DDSD_CAPS;
2175 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2177 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &primary, NULL);
2178 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2179 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2180 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2181 ok(ddsd.dwWidth == s.right - s.left, "Expected surface width %u, got %u.\n",
2182 s.right - s.left, ddsd.dwWidth);
2183 ok(ddsd.dwHeight == s.bottom - s.top, "Expected surface height %u, got %u.\n",
2184 s.bottom - s.top, ddsd.dwHeight);
2186 GetWindowRect(window, &r);
2187 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2188 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2189 r.left, r.top, r.right, r.bottom);
2191 expect_messages = normal_messages;
2195 hr = IDirectDraw_RestoreDisplayMode(ddraw);
2196 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
2198 ok(!*expect_messages, "Expected message %#x, but didn't receive it.\n", *expect_messages);
2199 expect_messages = NULL;
2200 ok(!screen_size.cx && !screen_size.cy, "Got unxpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2202 GetWindowRect(window, &r);
2203 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2204 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2205 r.left, r.top, r.right, r.bottom);
2207 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2208 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2209 ok(ddsd.dwWidth == s.right - s.left, "Expected surface width %u, got %u.\n",
2210 s.right - s.left, ddsd.dwWidth);
2211 ok(ddsd.dwHeight == s.bottom - s.top, "Expected surface height %u, got %u.\n",
2212 s.bottom - s.top, ddsd.dwHeight);
2213 IDirectDrawSurface_Release(primary);
2215 memset(&ddsd, 0, sizeof(ddsd));
2216 ddsd.dwSize = sizeof(ddsd);
2217 ddsd.dwFlags = DDSD_CAPS;
2218 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2220 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &primary, NULL);
2221 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2222 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2223 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2224 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2225 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2226 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2227 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2229 GetWindowRect(window, &r);
2230 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2231 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2232 r.left, r.top, r.right, r.bottom);
2234 /* DDSCL_NORMAL | DDSCL_FULLSCREEN behaves the same as just DDSCL_NORMAL.
2235 * Resizing the window on mode changes is a property of DDSCL_EXCLUSIVE,
2236 * not DDSCL_FULLSCREEN. */
2237 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL | DDSCL_FULLSCREEN);
2238 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2240 GetWindowRect(window, &r);
2241 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2242 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2243 r.left, r.top, r.right, r.bottom);
2245 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2246 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2247 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2248 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2249 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2250 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2251 IDirectDrawSurface_Release(primary);
2253 memset(&ddsd, 0, sizeof(ddsd));
2254 ddsd.dwSize = sizeof(ddsd);
2255 ddsd.dwFlags = DDSD_CAPS;
2256 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2258 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &primary, NULL);
2259 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2260 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2261 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2262 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2263 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2264 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2265 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2267 GetWindowRect(window, &r);
2268 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2269 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2270 r.left, r.top, r.right, r.bottom);
2272 expect_messages = normal_messages;
2276 hr = IDirectDraw_SetDisplayMode(ddraw, 640, 480, 32);
2277 ok(SUCCEEDED(hr), "SetDipslayMode failed, hr %#x.\n", hr);
2279 ok(!*expect_messages, "Expected message %#x, but didn't receive it.\n", *expect_messages);
2280 expect_messages = NULL;
2281 ok(!screen_size.cx && !screen_size.cy, "Got unxpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2283 GetWindowRect(window, &r);
2284 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2285 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2286 r.left, r.top, r.right, r.bottom);
2288 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2289 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2290 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2291 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2292 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2293 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2294 IDirectDrawSurface_Release(primary);
2296 memset(&ddsd, 0, sizeof(ddsd));
2297 ddsd.dwSize = sizeof(ddsd);
2298 ddsd.dwFlags = DDSD_CAPS;
2299 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2301 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &primary, NULL);
2302 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2303 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2304 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2305 ok(ddsd.dwWidth == s.right - s.left, "Expected surface width %u, got %u.\n",
2306 s.right - s.left, ddsd.dwWidth);
2307 ok(ddsd.dwHeight == s.bottom - s.top, "Expected surface height %u, got %u.\n",
2308 s.bottom - s.top, ddsd.dwHeight);
2310 GetWindowRect(window, &r);
2311 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2312 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2313 r.left, r.top, r.right, r.bottom);
2315 expect_messages = normal_messages;
2319 hr = IDirectDraw_RestoreDisplayMode(ddraw);
2320 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
2322 ok(!*expect_messages, "Expected message %#x, but didn't receive it.\n", *expect_messages);
2323 expect_messages = NULL;
2324 ok(!screen_size.cx && !screen_size.cy, "Got unxpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2326 GetWindowRect(window, &r);
2327 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2328 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2329 r.left, r.top, r.right, r.bottom);
2331 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2332 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2333 ok(ddsd.dwWidth == s.right - s.left, "Expected surface width %u, got %u.\n",
2334 s.right - s.left, ddsd.dwWidth);
2335 ok(ddsd.dwHeight == s.bottom - s.top, "Expected surface height %u, got %u.\n",
2336 s.bottom - s.top, ddsd.dwHeight);
2337 IDirectDrawSurface_Release(primary);
2339 memset(&ddsd, 0, sizeof(ddsd));
2340 ddsd.dwSize = sizeof(ddsd);
2341 ddsd.dwFlags = DDSD_CAPS;
2342 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2344 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &primary, NULL);
2345 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2346 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2347 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2348 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2349 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2350 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2351 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2352 IDirectDrawSurface_Release(primary);
2354 GetWindowRect(window, &r);
2355 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2356 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2357 r.left, r.top, r.right, r.bottom);
2359 ref = IDirectDraw_Release(ddraw);
2360 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2362 GetWindowRect(window, &r);
2363 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2364 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2365 r.left, r.top, r.right, r.bottom);
2368 expect_messages = NULL;
2369 DestroyWindow(window);
2370 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL));
2373 static void test_initialize(void)
2379 if (!(ddraw = create_ddraw()))
2381 skip("Failed to create a ddraw object, skipping test.\n");
2385 hr = IDirectDraw_Initialize(ddraw, NULL);
2386 ok(hr == DDERR_ALREADYINITIALIZED, "Initialize returned hr %#x.\n", hr);
2387 IDirectDraw_Release(ddraw);
2390 hr = CoCreateInstance(&CLSID_DirectDraw, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectDraw, (void **)&ddraw);
2391 ok(SUCCEEDED(hr), "Failed to create IDirectDraw instance, hr %#x.\n", hr);
2392 hr = IDirectDraw_QueryInterface(ddraw, &IID_IDirect3D, (void **)&d3d);
2395 /* IDirect3D_Initialize() just returns DDERR_ALREADYINITIALIZED. */
2396 hr = IDirect3D_Initialize(d3d, NULL);
2397 ok(hr == DDERR_ALREADYINITIALIZED, "Initialize returned hr %#x, expected DDERR_ALREADYINITIALIZED.\n", hr);
2398 IDirect3D_Release(d3d);
2400 else skip("Failed to query IDirect3D interface, skipping tests.\n");
2401 hr = IDirectDraw_Initialize(ddraw, NULL);
2402 ok(hr == DD_OK, "Initialize returned hr %#x, expected DD_OK.\n", hr);
2403 hr = IDirectDraw_Initialize(ddraw, NULL);
2404 ok(hr == DDERR_ALREADYINITIALIZED, "Initialize returned hr %#x, expected DDERR_ALREADYINITIALIZED.\n", hr);
2405 IDirectDraw_Release(ddraw);
2408 if (0) /* This crashes on the W2KPROSP4 testbot. */
2411 hr = CoCreateInstance(&CLSID_DirectDraw, NULL, CLSCTX_INPROC_SERVER, &IID_IDirect3D, (void **)&d3d);
2412 ok(hr == E_NOINTERFACE, "CoCreateInstance returned hr %#x, expected E_NOINTERFACE.\n", hr);
2417 static void test_coop_level_surf_create(void)
2419 IDirectDrawSurface *surface;
2424 if (!(ddraw = create_ddraw()))
2426 skip("Failed to create a ddraw object, skipping test.\n");
2430 memset(&ddsd, 0, sizeof(ddsd));
2431 ddsd.dwSize = sizeof(ddsd);
2432 ddsd.dwFlags = DDSD_CAPS;
2433 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2434 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &surface, NULL);
2435 ok(hr == DDERR_NOCOOPERATIVELEVELSET, "Surface creation returned hr %#x.\n", hr);
2437 IDirectDraw_Release(ddraw);
2442 test_coop_level_create_device_window();
2444 test_coop_level_d3d_state();
2445 test_surface_interface_mismatch();
2446 test_coop_level_threaded();
2447 test_viewport_interfaces();
2454 test_window_style();
2455 test_redundant_mode_set();
2456 test_coop_level_mode_set();
2458 test_coop_level_surf_create();