ddraw: Allow DDSCAPS_FLIP without DDSCAPS_PRIMARYSURFACE.
[wine.git] / dlls / ddraw / tests / ddraw1.c
bloba9ba1b1d09872ecd6c430da29d2539be8878b460
1 /*
2 * Copyright 2005 Antoine Chavasse (a.chavasse@gmail.com)
3 * Copyright 2008, 2011, 2012-2013 Stefan Dösinger for CodeWeavers
4 * Copyright 2011-2014 Henri Verbeet for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #define COBJMACROS
22 #include "wine/test.h"
23 #include "d3d.h"
25 static BOOL is_ddraw64 = sizeof(DWORD) != sizeof(DWORD *);
26 static DEVMODEW registry_mode;
28 struct create_window_thread_param
30 HWND window;
31 HANDLE window_created;
32 HANDLE destroy_window;
33 HANDLE thread;
36 static BOOL compare_color(D3DCOLOR c1, D3DCOLOR c2, BYTE max_diff)
38 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
39 c1 >>= 8; c2 >>= 8;
40 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
41 c1 >>= 8; c2 >>= 8;
42 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
43 c1 >>= 8; c2 >>= 8;
44 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
45 return TRUE;
48 static IDirectDrawSurface *create_overlay(IDirectDraw *ddraw,
49 unsigned int width, unsigned int height, DWORD format)
51 IDirectDrawSurface *surface;
52 DDSURFACEDESC desc;
54 memset(&desc, 0, sizeof(desc));
55 desc.dwSize = sizeof(desc);
56 desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
57 desc.dwWidth = width;
58 desc.dwHeight = height;
59 desc.ddsCaps.dwCaps = DDSCAPS_OVERLAY;
60 desc.ddpfPixelFormat.dwSize = sizeof(desc.ddpfPixelFormat);
61 desc.ddpfPixelFormat.dwFlags = DDPF_FOURCC;
62 desc.ddpfPixelFormat.dwFourCC = format;
64 if (FAILED(IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL)))
65 return NULL;
66 return surface;
69 static DWORD WINAPI create_window_thread_proc(void *param)
71 struct create_window_thread_param *p = param;
72 DWORD res;
73 BOOL ret;
75 p->window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
76 0, 0, 640, 480, 0, 0, 0, 0);
77 ret = SetEvent(p->window_created);
78 ok(ret, "SetEvent failed, last error %#x.\n", GetLastError());
80 for (;;)
82 MSG msg;
84 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
85 DispatchMessageA(&msg);
86 res = WaitForSingleObject(p->destroy_window, 100);
87 if (res == WAIT_OBJECT_0)
88 break;
89 if (res != WAIT_TIMEOUT)
91 ok(0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
92 break;
96 DestroyWindow(p->window);
98 return 0;
101 static void create_window_thread(struct create_window_thread_param *p)
103 DWORD res, tid;
105 p->window_created = CreateEventA(NULL, FALSE, FALSE, NULL);
106 ok(!!p->window_created, "CreateEvent failed, last error %#x.\n", GetLastError());
107 p->destroy_window = CreateEventA(NULL, FALSE, FALSE, NULL);
108 ok(!!p->destroy_window, "CreateEvent failed, last error %#x.\n", GetLastError());
109 p->thread = CreateThread(NULL, 0, create_window_thread_proc, p, 0, &tid);
110 ok(!!p->thread, "Failed to create thread, last error %#x.\n", GetLastError());
111 res = WaitForSingleObject(p->window_created, INFINITE);
112 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
115 static void destroy_window_thread(struct create_window_thread_param *p)
117 SetEvent(p->destroy_window);
118 WaitForSingleObject(p->thread, INFINITE);
119 CloseHandle(p->destroy_window);
120 CloseHandle(p->window_created);
121 CloseHandle(p->thread);
124 static HRESULT set_display_mode(IDirectDraw *ddraw, DWORD width, DWORD height)
126 if (SUCCEEDED(IDirectDraw_SetDisplayMode(ddraw, width, height, 32)))
127 return DD_OK;
128 return IDirectDraw_SetDisplayMode(ddraw, width, height, 24);
131 static D3DCOLOR get_surface_color(IDirectDrawSurface *surface, UINT x, UINT y)
133 RECT rect = {x, y, x + 1, y + 1};
134 DDSURFACEDESC surface_desc;
135 D3DCOLOR color;
136 HRESULT hr;
138 memset(&surface_desc, 0, sizeof(surface_desc));
139 surface_desc.dwSize = sizeof(surface_desc);
141 hr = IDirectDrawSurface_Lock(surface, &rect, &surface_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
142 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
143 if (FAILED(hr))
144 return 0xdeadbeef;
146 color = *((DWORD *)surface_desc.lpSurface) & 0x00ffffff;
148 hr = IDirectDrawSurface_Unlock(surface, NULL);
149 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
151 return color;
154 static void emit_process_vertices(void **ptr, DWORD flags, WORD base_idx, DWORD vertex_count)
156 D3DINSTRUCTION *inst = *ptr;
157 D3DPROCESSVERTICES *pv = (D3DPROCESSVERTICES *)(inst + 1);
159 inst->bOpcode = D3DOP_PROCESSVERTICES;
160 inst->bSize = sizeof(*pv);
161 inst->wCount = 1;
163 pv->dwFlags = flags;
164 pv->wStart = base_idx;
165 pv->wDest = 0;
166 pv->dwCount = vertex_count;
167 pv->dwReserved = 0;
169 *ptr = pv + 1;
172 static void emit_set_ts(void **ptr, D3DTRANSFORMSTATETYPE state, DWORD value)
174 D3DINSTRUCTION *inst = *ptr;
175 D3DSTATE *ts = (D3DSTATE *)(inst + 1);
177 inst->bOpcode = D3DOP_STATETRANSFORM;
178 inst->bSize = sizeof(*ts);
179 inst->wCount = 1;
181 U1(*ts).dtstTransformStateType = state;
182 U2(*ts).dwArg[0] = value;
184 *ptr = ts + 1;
187 static void emit_set_ls(void **ptr, D3DLIGHTSTATETYPE state, DWORD value)
189 D3DINSTRUCTION *inst = *ptr;
190 D3DSTATE *ls = (D3DSTATE *)(inst + 1);
192 inst->bOpcode = D3DOP_STATELIGHT;
193 inst->bSize = sizeof(*ls);
194 inst->wCount = 1;
196 U1(*ls).dlstLightStateType = state;
197 U2(*ls).dwArg[0] = value;
199 *ptr = ls + 1;
202 static void emit_set_rs(void **ptr, D3DRENDERSTATETYPE state, DWORD value)
204 D3DINSTRUCTION *inst = *ptr;
205 D3DSTATE *rs = (D3DSTATE *)(inst + 1);
207 inst->bOpcode = D3DOP_STATERENDER;
208 inst->bSize = sizeof(*rs);
209 inst->wCount = 1;
211 U1(*rs).drstRenderStateType = state;
212 U2(*rs).dwArg[0] = value;
214 *ptr = rs + 1;
217 static void emit_tquad(void **ptr, WORD base_idx)
219 D3DINSTRUCTION *inst = *ptr;
220 D3DTRIANGLE *tri = (D3DTRIANGLE *)(inst + 1);
222 inst->bOpcode = D3DOP_TRIANGLE;
223 inst->bSize = sizeof(*tri);
224 inst->wCount = 2;
226 U1(*tri).v1 = base_idx;
227 U2(*tri).v2 = base_idx + 1;
228 U3(*tri).v3 = base_idx + 2;
229 tri->wFlags = D3DTRIFLAG_START;
230 ++tri;
232 U1(*tri).v1 = base_idx + 2;
233 U2(*tri).v2 = base_idx + 1;
234 U3(*tri).v3 = base_idx + 3;
235 tri->wFlags = D3DTRIFLAG_ODD;
236 ++tri;
238 *ptr = tri;
241 static void emit_tquad_tlist(void **ptr, WORD base_idx)
243 D3DINSTRUCTION *inst = *ptr;
244 D3DTRIANGLE *tri = (D3DTRIANGLE *)(inst + 1);
246 inst->bOpcode = D3DOP_TRIANGLE;
247 inst->bSize = sizeof(*tri);
248 inst->wCount = 2;
250 U1(*tri).v1 = base_idx;
251 U2(*tri).v2 = base_idx + 1;
252 U3(*tri).v3 = base_idx + 2;
253 tri->wFlags = D3DTRIFLAG_START;
254 ++tri;
256 U1(*tri).v1 = base_idx + 2;
257 U2(*tri).v2 = base_idx + 3;
258 U3(*tri).v3 = base_idx;
259 tri->wFlags = D3DTRIFLAG_START;
260 ++tri;
262 *ptr = tri;
265 static void emit_end(void **ptr)
267 D3DINSTRUCTION *inst = *ptr;
269 inst->bOpcode = D3DOP_EXIT;
270 inst->bSize = 0;
271 inst->wCount = 0;
273 *ptr = inst + 1;
276 static void set_execute_data(IDirect3DExecuteBuffer *execute_buffer, UINT vertex_count, UINT offset, UINT len)
278 D3DEXECUTEDATA exec_data;
279 HRESULT hr;
281 memset(&exec_data, 0, sizeof(exec_data));
282 exec_data.dwSize = sizeof(exec_data);
283 exec_data.dwVertexCount = vertex_count;
284 exec_data.dwInstructionOffset = offset;
285 exec_data.dwInstructionLength = len;
286 hr = IDirect3DExecuteBuffer_SetExecuteData(execute_buffer, &exec_data);
287 ok(SUCCEEDED(hr), "Failed to set execute data, hr %#x.\n", hr);
290 static DWORD get_device_z_depth(IDirect3DDevice *device)
292 DDSCAPS caps = {DDSCAPS_ZBUFFER};
293 IDirectDrawSurface *ds, *rt;
294 DDSURFACEDESC desc;
295 HRESULT hr;
297 if (FAILED(IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&rt)))
298 return 0;
300 hr = IDirectDrawSurface_GetAttachedSurface(rt, &caps, &ds);
301 IDirectDrawSurface_Release(rt);
302 if (FAILED(hr))
303 return 0;
305 desc.dwSize = sizeof(desc);
306 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
307 IDirectDrawSurface_Release(ds);
308 if (FAILED(hr))
309 return 0;
311 return U2(desc).dwZBufferBitDepth;
314 static IDirectDraw *create_ddraw(void)
316 IDirectDraw *ddraw;
318 if (FAILED(DirectDrawCreate(NULL, &ddraw, NULL)))
319 return NULL;
321 return ddraw;
324 static IDirect3DDevice *create_device(IDirectDraw *ddraw, HWND window, DWORD coop_level)
326 static const DWORD z_depths[] = {32, 24, 16};
327 IDirectDrawSurface *surface, *ds;
328 IDirect3DDevice *device = NULL;
329 DDSURFACEDESC surface_desc;
330 unsigned int i;
331 HRESULT hr;
333 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, coop_level);
334 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
336 memset(&surface_desc, 0, sizeof(surface_desc));
337 surface_desc.dwSize = sizeof(surface_desc);
338 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
339 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
340 surface_desc.dwWidth = 640;
341 surface_desc.dwHeight = 480;
343 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
344 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
346 if (coop_level & DDSCL_NORMAL)
348 IDirectDrawClipper *clipper;
350 hr = IDirectDraw_CreateClipper(ddraw, 0, &clipper, NULL);
351 ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr);
352 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
353 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
354 hr = IDirectDrawSurface_SetClipper(surface, clipper);
355 ok(SUCCEEDED(hr), "Failed to set surface clipper, hr %#x.\n", hr);
356 IDirectDrawClipper_Release(clipper);
359 /* We used to use EnumDevices() for this, but it seems
360 * D3DDEVICEDESC.dwDeviceZBufferBitDepth only has a very casual
361 * relationship with reality. */
362 for (i = 0; i < sizeof(z_depths) / sizeof(*z_depths); ++i)
364 memset(&surface_desc, 0, sizeof(surface_desc));
365 surface_desc.dwSize = sizeof(surface_desc);
366 surface_desc.dwFlags = DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_WIDTH | DDSD_HEIGHT;
367 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
368 U2(surface_desc).dwZBufferBitDepth = z_depths[i];
369 surface_desc.dwWidth = 640;
370 surface_desc.dwHeight = 480;
371 if (FAILED(IDirectDraw_CreateSurface(ddraw, &surface_desc, &ds, NULL)))
372 continue;
374 hr = IDirectDrawSurface_AddAttachedSurface(surface, ds);
375 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
376 IDirectDrawSurface_Release(ds);
377 if (FAILED(hr))
378 continue;
380 if (SUCCEEDED(IDirectDrawSurface_QueryInterface(surface, &IID_IDirect3DHALDevice, (void **)&device)))
381 break;
383 IDirectDrawSurface_DeleteAttachedSurface(surface, 0, ds);
386 IDirectDrawSurface_Release(surface);
387 return device;
390 static IDirect3DViewport *create_viewport(IDirect3DDevice *device, UINT x, UINT y, UINT w, UINT h)
392 IDirect3DViewport *viewport;
393 D3DVIEWPORT vp;
394 IDirect3D *d3d;
395 HRESULT hr;
397 hr = IDirect3DDevice_GetDirect3D(device, &d3d);
398 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
399 hr = IDirect3D_CreateViewport(d3d, &viewport, NULL);
400 ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
401 hr = IDirect3DDevice_AddViewport(device, viewport);
402 ok(SUCCEEDED(hr), "Failed to add viewport, hr %#x.\n", hr);
403 memset(&vp, 0, sizeof(vp));
404 vp.dwSize = sizeof(vp);
405 vp.dwX = x;
406 vp.dwY = y;
407 vp.dwWidth = w;
408 vp.dwHeight = h;
409 vp.dvScaleX = (float)w / 2.0f;
410 vp.dvScaleY = (float)h / 2.0f;
411 vp.dvMaxX = 1.0f;
412 vp.dvMaxY = 1.0f;
413 vp.dvMinZ = 0.0f;
414 vp.dvMaxZ = 1.0f;
415 hr = IDirect3DViewport_SetViewport(viewport, &vp);
416 ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
417 IDirect3D_Release(d3d);
419 return viewport;
422 static void viewport_set_background(IDirect3DDevice *device, IDirect3DViewport *viewport,
423 IDirect3DMaterial *material)
425 D3DMATERIALHANDLE material_handle;
426 HRESULT hr;
428 hr = IDirect3DMaterial2_GetHandle(material, device, &material_handle);
429 ok(SUCCEEDED(hr), "Failed to get material handle, hr %#x.\n", hr);
430 hr = IDirect3DViewport2_SetBackground(viewport, material_handle);
431 ok(SUCCEEDED(hr), "Failed to set viewport background, hr %#x.\n", hr);
434 static void destroy_viewport(IDirect3DDevice *device, IDirect3DViewport *viewport)
436 HRESULT hr;
438 hr = IDirect3DDevice_DeleteViewport(device, viewport);
439 ok(SUCCEEDED(hr), "Failed to delete viewport, hr %#x.\n", hr);
440 IDirect3DViewport_Release(viewport);
443 static IDirect3DMaterial *create_material(IDirect3DDevice *device, D3DMATERIAL *mat)
445 IDirect3DMaterial *material;
446 IDirect3D *d3d;
447 HRESULT hr;
449 hr = IDirect3DDevice_GetDirect3D(device, &d3d);
450 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
451 hr = IDirect3D_CreateMaterial(d3d, &material, NULL);
452 ok(SUCCEEDED(hr), "Failed to create material, hr %#x.\n", hr);
453 hr = IDirect3DMaterial_SetMaterial(material, mat);
454 ok(SUCCEEDED(hr), "Failed to set material data, hr %#x.\n", hr);
455 IDirect3D_Release(d3d);
457 return material;
460 static IDirect3DMaterial *create_diffuse_material(IDirect3DDevice *device, float r, float g, float b, float a)
462 D3DMATERIAL mat;
464 memset(&mat, 0, sizeof(mat));
465 mat.dwSize = sizeof(mat);
466 U1(U(mat).diffuse).r = r;
467 U2(U(mat).diffuse).g = g;
468 U3(U(mat).diffuse).b = b;
469 U4(U(mat).diffuse).a = a;
471 return create_material(device, &mat);
474 static IDirect3DMaterial *create_emissive_material(IDirect3DDevice *device, float r, float g, float b, float a)
476 D3DMATERIAL mat;
478 memset(&mat, 0, sizeof(mat));
479 mat.dwSize = sizeof(mat);
480 U1(U3(mat).emissive).r = r;
481 U2(U3(mat).emissive).g = g;
482 U3(U3(mat).emissive).b = b;
483 U4(U3(mat).emissive).a = a;
485 return create_material(device, &mat);
488 static void destroy_material(IDirect3DMaterial *material)
490 IDirect3DMaterial_Release(material);
493 struct message
495 UINT message;
496 BOOL check_wparam;
497 WPARAM expect_wparam;
500 static const struct message *expect_messages;
502 static LRESULT CALLBACK test_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
504 if (expect_messages && message == expect_messages->message)
506 if (expect_messages->check_wparam)
507 ok (wparam == expect_messages->expect_wparam,
508 "Got unexpected wparam %lx for message %x, expected %lx.\n",
509 wparam, message, expect_messages->expect_wparam);
511 ++expect_messages;
514 return DefWindowProcA(hwnd, message, wparam, lparam);
517 /* Set the wndproc back to what ddraw expects it to be, and release the ddraw
518 * interface. This prevents subsequent SetCooperativeLevel() calls on a
519 * different window from failing with DDERR_HWNDALREADYSET. */
520 static void fix_wndproc(HWND window, LONG_PTR proc)
522 IDirectDraw *ddraw;
523 HRESULT hr;
525 if (!(ddraw = create_ddraw()))
526 return;
528 SetWindowLongPtrA(window, GWLP_WNDPROC, proc);
529 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
530 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
531 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
532 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
534 IDirectDraw_Release(ddraw);
537 static HRESULT CALLBACK restore_callback(IDirectDrawSurface *surface, DDSURFACEDESC *desc, void *context)
539 HRESULT hr = IDirectDrawSurface_Restore(surface);
540 ok(SUCCEEDED(hr) || hr == DDERR_IMPLICITLYCREATED, "Failed to restore surface, hr %#x.\n", hr);
541 IDirectDrawSurface_Release(surface);
543 return DDENUMRET_OK;
546 static HRESULT restore_surfaces(IDirectDraw *ddraw)
548 return IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
549 NULL, NULL, restore_callback);
552 static void test_coop_level_create_device_window(void)
554 HWND focus_window, device_window;
555 IDirectDraw *ddraw;
556 HRESULT hr;
558 focus_window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
559 0, 0, 640, 480, 0, 0, 0, 0);
560 ddraw = create_ddraw();
561 ok(!!ddraw, "Failed to create a ddraw object.\n");
563 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
564 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
565 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
566 ok(!device_window, "Unexpected device window found.\n");
567 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW);
568 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
569 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
570 ok(!device_window, "Unexpected device window found.\n");
571 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_NORMAL);
572 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
573 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
574 ok(!device_window, "Unexpected device window found.\n");
575 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_NORMAL | DDSCL_FULLSCREEN);
576 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
577 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
578 ok(!device_window, "Unexpected device window found.\n");
579 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
580 ok(hr == DDERR_NOFOCUSWINDOW || broken(hr == DDERR_INVALIDPARAMS), "Got unexpected hr %#x.\n", hr);
581 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
582 ok(!device_window, "Unexpected device window found.\n");
584 /* Windows versions before 98 / NT5 don't support DDSCL_CREATEDEVICEWINDOW. */
585 if (broken(hr == DDERR_INVALIDPARAMS))
587 win_skip("DDSCL_CREATEDEVICEWINDOW not supported, skipping test.\n");
588 IDirectDraw_Release(ddraw);
589 DestroyWindow(focus_window);
590 return;
593 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
594 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
595 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
596 ok(!device_window, "Unexpected device window found.\n");
597 hr = IDirectDraw_SetCooperativeLevel(ddraw, focus_window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
598 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
599 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
600 ok(!device_window, "Unexpected device window found.\n");
602 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
603 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
604 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
605 ok(!device_window, "Unexpected device window found.\n");
606 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_SETFOCUSWINDOW
607 | DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
608 ok(hr == DDERR_NOHWND, "Got unexpected hr %#x.\n", hr);
609 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
610 ok(!!device_window, "Device window not found.\n");
612 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
613 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
614 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
615 ok(!device_window, "Unexpected device window found.\n");
616 hr = IDirectDraw_SetCooperativeLevel(ddraw, focus_window, DDSCL_SETFOCUSWINDOW
617 | DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
618 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
619 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
620 ok(!!device_window, "Device window not found.\n");
622 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
623 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
624 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
625 ok(!device_window, "Unexpected device window found.\n");
626 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
627 ok(hr == DDERR_NOFOCUSWINDOW, "Got unexpected hr %#x.\n", hr);
628 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
629 ok(!device_window, "Unexpected device window found.\n");
630 hr = IDirectDraw_SetCooperativeLevel(ddraw, focus_window, DDSCL_SETFOCUSWINDOW);
631 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
632 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
633 ok(!device_window, "Unexpected device window found.\n");
634 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
635 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
636 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
637 ok(!!device_window, "Device window not found.\n");
639 IDirectDraw_Release(ddraw);
640 DestroyWindow(focus_window);
643 static void test_clipper_blt(void)
645 IDirectDrawSurface *src_surface, *dst_surface;
646 RECT client_rect, src_rect;
647 IDirectDrawClipper *clipper;
648 DDSURFACEDESC surface_desc;
649 unsigned int i, j, x, y;
650 IDirectDraw *ddraw;
651 RGNDATA *rgn_data;
652 D3DCOLOR color;
653 ULONG refcount;
654 HRGN r1, r2;
655 HWND window;
656 DDBLTFX fx;
657 HRESULT hr;
658 DWORD *ptr;
659 DWORD ret;
661 static const DWORD src_data[] =
663 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
664 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
665 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
667 static const D3DCOLOR expected1[] =
669 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
670 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
671 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
672 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
674 /* Nvidia on Windows seems to have an off-by-one error
675 * when processing source rectangles. Our left = 1 and
676 * right = 5 input reads from x = {1, 2, 3}. x = 4 is
677 * read as well, but only for the edge pixels on the
678 * output image. The bug happens on the y axis as well,
679 * but we only read one row there, and all source rows
680 * contain the same data. This bug is not dependent on
681 * the presence of a clipper. */
682 static const D3DCOLOR expected1_broken[] =
684 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
685 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
686 0x00000000, 0x00000000, 0x00ff0000, 0x00ff0000,
687 0x00000000, 0x00000000, 0x0000ff00, 0x00ff0000,
689 static const D3DCOLOR expected2[] =
691 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
692 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
693 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
694 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
697 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
698 10, 10, 640, 480, 0, 0, 0, 0);
699 ShowWindow(window, SW_SHOW);
700 ddraw = create_ddraw();
701 ok(!!ddraw, "Failed to create a ddraw object.\n");
703 ret = GetClientRect(window, &client_rect);
704 ok(ret, "Failed to get client rect.\n");
705 ret = MapWindowPoints(window, NULL, (POINT *)&client_rect, 2);
706 ok(ret, "Failed to map client rect.\n");
708 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
709 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
711 hr = IDirectDraw_CreateClipper(ddraw, 0, &clipper, NULL);
712 ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr);
713 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
714 ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr);
715 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
716 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
717 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
718 ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr);
719 rgn_data = HeapAlloc(GetProcessHeap(), 0, ret);
720 hr = IDirectDrawClipper_GetClipList(clipper, NULL, rgn_data, &ret);
721 ok(SUCCEEDED(hr), "Failed to get clip list, hr %#x.\n", hr);
722 ok(rgn_data->rdh.dwSize == sizeof(rgn_data->rdh), "Got unexpected structure size %#x.\n", rgn_data->rdh.dwSize);
723 ok(rgn_data->rdh.iType == RDH_RECTANGLES, "Got unexpected type %#x.\n", rgn_data->rdh.iType);
724 ok(rgn_data->rdh.nCount >= 1, "Got unexpected count %u.\n", rgn_data->rdh.nCount);
725 ok(EqualRect(&rgn_data->rdh.rcBound, &client_rect),
726 "Got unexpected bounding rect {%d, %d, %d, %d}, expected {%d, %d, %d, %d}.\n",
727 rgn_data->rdh.rcBound.left, rgn_data->rdh.rcBound.top,
728 rgn_data->rdh.rcBound.right, rgn_data->rdh.rcBound.bottom,
729 client_rect.left, client_rect.top, client_rect.right, client_rect.bottom);
730 HeapFree(GetProcessHeap(), 0, rgn_data);
732 r1 = CreateRectRgn(0, 0, 320, 240);
733 ok(!!r1, "Failed to create region.\n");
734 r2 = CreateRectRgn(320, 240, 640, 480);
735 ok(!!r2, "Failed to create region.\n");
736 CombineRgn(r1, r1, r2, RGN_OR);
737 ret = GetRegionData(r1, 0, NULL);
738 rgn_data = HeapAlloc(GetProcessHeap(), 0, ret);
739 ret = GetRegionData(r1, ret, rgn_data);
740 ok(!!ret, "Failed to get region data.\n");
742 DeleteObject(r2);
743 DeleteObject(r1);
745 hr = IDirectDrawClipper_SetClipList(clipper, rgn_data, 0);
746 ok(hr == DDERR_CLIPPERISUSINGHWND, "Got unexpected hr %#x.\n", hr);
747 hr = IDirectDrawClipper_SetHWnd(clipper, 0, NULL);
748 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
749 hr = IDirectDrawClipper_SetClipList(clipper, rgn_data, 0);
750 ok(SUCCEEDED(hr), "Failed to set clip list, hr %#x.\n", hr);
752 HeapFree(GetProcessHeap(), 0, rgn_data);
754 memset(&surface_desc, 0, sizeof(surface_desc));
755 surface_desc.dwSize = sizeof(surface_desc);
756 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
757 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
758 surface_desc.dwWidth = 640;
759 surface_desc.dwHeight = 480;
760 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
761 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB;
762 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount = 32;
763 U2(surface_desc.ddpfPixelFormat).dwRBitMask = 0x00ff0000;
764 U3(surface_desc.ddpfPixelFormat).dwGBitMask = 0x0000ff00;
765 U4(surface_desc.ddpfPixelFormat).dwBBitMask = 0x000000ff;
767 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &src_surface, NULL);
768 ok(SUCCEEDED(hr), "Failed to create source surface, hr %#x.\n", hr);
769 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &dst_surface, NULL);
770 ok(SUCCEEDED(hr), "Failed to create destination surface, hr %#x.\n", hr);
772 memset(&fx, 0, sizeof(fx));
773 fx.dwSize = sizeof(fx);
774 hr = IDirectDrawSurface_Blt(src_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
775 ok(SUCCEEDED(hr), "Failed to clear source surface, hr %#x.\n", hr);
776 hr = IDirectDrawSurface_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
777 ok(SUCCEEDED(hr), "Failed to clear destination surface, hr %#x.\n", hr);
779 hr = IDirectDrawSurface_Lock(src_surface, NULL, &surface_desc, DDLOCK_WAIT, NULL);
780 ok(SUCCEEDED(hr), "Failed to lock source surface, hr %#x.\n", hr);
781 ok(U1(surface_desc).lPitch == 2560, "Got unexpected surface pitch %u.\n", U1(surface_desc).lPitch);
782 ptr = surface_desc.lpSurface;
783 memcpy(&ptr[ 0], &src_data[ 0], 6 * sizeof(DWORD));
784 memcpy(&ptr[ 640], &src_data[ 6], 6 * sizeof(DWORD));
785 memcpy(&ptr[1280], &src_data[12], 6 * sizeof(DWORD));
786 hr = IDirectDrawSurface_Unlock(src_surface, NULL);
787 ok(SUCCEEDED(hr), "Failed to unlock source surface, hr %#x.\n", hr);
789 hr = IDirectDrawSurface_SetClipper(dst_surface, clipper);
790 ok(SUCCEEDED(hr), "Failed to set clipper, hr %#x.\n", hr);
792 SetRect(&src_rect, 1, 1, 5, 2);
793 hr = IDirectDrawSurface_Blt(dst_surface, NULL, src_surface, &src_rect, DDBLT_WAIT, NULL);
794 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
795 for (i = 0; i < 4; ++i)
797 for (j = 0; j < 4; ++j)
799 x = 80 * ((2 * j) + 1);
800 y = 60 * ((2 * i) + 1);
801 color = get_surface_color(dst_surface, x, y);
802 ok(compare_color(color, expected1[i * 4 + j], 1)
803 || broken(compare_color(color, expected1_broken[i * 4 + j], 1)),
804 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected1[i * 4 + j], x, y, color);
808 U5(fx).dwFillColor = 0xff0000ff;
809 hr = IDirectDrawSurface_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
810 ok(SUCCEEDED(hr), "Failed to clear destination surface, hr %#x.\n", hr);
811 for (i = 0; i < 4; ++i)
813 for (j = 0; j < 4; ++j)
815 x = 80 * ((2 * j) + 1);
816 y = 60 * ((2 * i) + 1);
817 color = get_surface_color(dst_surface, x, y);
818 ok(compare_color(color, expected2[i * 4 + j], 1),
819 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected2[i * 4 + j], x, y, color);
823 hr = IDirectDrawSurface_BltFast(dst_surface, 0, 0, src_surface, NULL, DDBLTFAST_WAIT);
824 ok(hr == DDERR_BLTFASTCANTCLIP || broken(hr == E_NOTIMPL /* NT4 */), "Got unexpected hr %#x.\n", hr);
826 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
827 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
828 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
829 ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr);
830 DestroyWindow(window);
831 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
832 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
833 hr = IDirectDrawClipper_SetHWnd(clipper, 0, NULL);
834 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
835 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
836 ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr);
837 hr = IDirectDrawClipper_SetClipList(clipper, NULL, 0);
838 ok(SUCCEEDED(hr), "Failed to set clip list, hr %#x.\n", hr);
839 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
840 ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr);
841 hr = IDirectDrawSurface_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
842 ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr);
844 IDirectDrawSurface_Release(dst_surface);
845 IDirectDrawSurface_Release(src_surface);
846 refcount = IDirectDrawClipper_Release(clipper);
847 ok(!refcount, "Clipper has %u references left.\n", refcount);
848 IDirectDraw_Release(ddraw);
851 static void test_coop_level_d3d_state(void)
853 D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
854 IDirectDrawSurface *rt, *surface;
855 IDirect3DMaterial *background;
856 IDirect3DViewport *viewport;
857 IDirect3DDevice *device;
858 D3DMATERIAL material;
859 IDirectDraw *ddraw;
860 D3DCOLOR color;
861 HWND window;
862 HRESULT hr;
864 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
865 0, 0, 640, 480, 0, 0, 0, 0);
866 ddraw = create_ddraw();
867 ok(!!ddraw, "Failed to create a ddraw object.\n");
868 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
870 skip("Failed to create a 3D device, skipping test.\n");
871 IDirectDraw_Release(ddraw);
872 DestroyWindow(window);
873 return;
876 background = create_diffuse_material(device, 1.0f, 0.0f, 0.0f, 1.0f);
877 viewport = create_viewport(device, 0, 0, 640, 480);
878 viewport_set_background(device, viewport, background);
880 hr = IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&rt);
881 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
882 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
883 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
884 color = get_surface_color(rt, 320, 240);
885 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
887 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
888 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
889 hr = IDirectDrawSurface_IsLost(rt);
890 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
891 hr = restore_surfaces(ddraw);
892 ok(SUCCEEDED(hr), "Failed to restore surfaces, hr %#x.\n", hr);
894 memset(&material, 0, sizeof(material));
895 material.dwSize = sizeof(material);
896 U1(U(material).diffuse).r = 0.0f;
897 U2(U(material).diffuse).g = 1.0f;
898 U3(U(material).diffuse).b = 0.0f;
899 U4(U(material).diffuse).a = 1.0f;
900 hr = IDirect3DMaterial_SetMaterial(background, &material);
901 ok(SUCCEEDED(hr), "Failed to set material data, hr %#x.\n", hr);
903 hr = IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&surface);
904 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
905 ok(surface == rt, "Got unexpected surface %p.\n", surface);
906 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
907 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
908 color = get_surface_color(rt, 320, 240);
909 ok(compare_color(color, 0x0000ff00, 1) || broken(compare_color(color, 0x00000000, 1)),
910 "Got unexpected color 0x%08x.\n", color);
912 destroy_viewport(device, viewport);
913 destroy_material(background);
914 IDirectDrawSurface_Release(surface);
915 IDirectDrawSurface_Release(rt);
916 IDirect3DDevice_Release(device);
917 IDirectDraw_Release(ddraw);
918 DestroyWindow(window);
921 static void test_surface_interface_mismatch(void)
923 IDirectDraw *ddraw = NULL;
924 IDirectDrawSurface *surface = NULL, *ds;
925 IDirectDrawSurface3 *surface3 = NULL;
926 IDirect3DDevice *device = NULL;
927 IDirect3DViewport *viewport = NULL;
928 IDirect3DMaterial *background = NULL;
929 DDSURFACEDESC surface_desc;
930 DWORD z_depth = 0;
931 ULONG refcount;
932 HRESULT hr;
933 D3DCOLOR color;
934 HWND window;
935 D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
937 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
938 0, 0, 640, 480, 0, 0, 0, 0);
939 ddraw = create_ddraw();
940 ok(!!ddraw, "Failed to create a ddraw object.\n");
941 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
943 skip("Failed to create a 3D device, skipping test.\n");
944 IDirectDraw_Release(ddraw);
945 DestroyWindow(window);
946 return;
948 z_depth = get_device_z_depth(device);
949 ok(!!z_depth, "Failed to get device z depth.\n");
950 IDirect3DDevice_Release(device);
951 device = NULL;
953 memset(&surface_desc, 0, sizeof(surface_desc));
954 surface_desc.dwSize = sizeof(surface_desc);
955 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
956 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
957 surface_desc.dwWidth = 640;
958 surface_desc.dwHeight = 480;
960 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
961 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
963 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirectDrawSurface3, (void **)&surface3);
964 if (FAILED(hr))
966 skip("Failed to get the IDirectDrawSurface3 interface, skipping test.\n");
967 goto cleanup;
970 memset(&surface_desc, 0, sizeof(surface_desc));
971 surface_desc.dwSize = sizeof(surface_desc);
972 surface_desc.dwFlags = DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_WIDTH | DDSD_HEIGHT;
973 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
974 U2(surface_desc).dwZBufferBitDepth = z_depth;
975 surface_desc.dwWidth = 640;
976 surface_desc.dwHeight = 480;
977 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &ds, NULL);
978 ok(SUCCEEDED(hr), "Failed to create depth buffer, hr %#x.\n", hr);
979 if (FAILED(hr))
980 goto cleanup;
982 /* Using a different surface interface version still works */
983 hr = IDirectDrawSurface3_AddAttachedSurface(surface3, (IDirectDrawSurface3 *)ds);
984 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
985 refcount = IDirectDrawSurface_Release(ds);
986 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
987 if (FAILED(hr))
988 goto cleanup;
990 /* Here too */
991 hr = IDirectDrawSurface3_QueryInterface(surface3, &IID_IDirect3DHALDevice, (void **)&device);
992 ok(SUCCEEDED(hr), "Failed to create d3d device.\n");
993 if (FAILED(hr))
994 goto cleanup;
996 background = create_diffuse_material(device, 1.0f, 0.0f, 0.0f, 1.0f);
997 viewport = create_viewport(device, 0, 0, 640, 480);
998 viewport_set_background(device, viewport, background);
1000 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
1001 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
1002 color = get_surface_color(surface, 320, 240);
1003 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
1005 cleanup:
1006 if (viewport)
1007 destroy_viewport(device, viewport);
1008 if (background)
1009 destroy_material(background);
1010 if (surface3) IDirectDrawSurface3_Release(surface3);
1011 if (surface) IDirectDrawSurface_Release(surface);
1012 if (device) IDirect3DDevice_Release(device);
1013 if (ddraw) IDirectDraw_Release(ddraw);
1014 DestroyWindow(window);
1017 static void test_coop_level_threaded(void)
1019 struct create_window_thread_param p;
1020 IDirectDraw *ddraw;
1021 HRESULT hr;
1023 ddraw = create_ddraw();
1024 ok(!!ddraw, "Failed to create a ddraw object.\n");
1025 create_window_thread(&p);
1027 hr = IDirectDraw_SetCooperativeLevel(ddraw, p.window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
1028 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
1030 IDirectDraw_Release(ddraw);
1031 destroy_window_thread(&p);
1034 static ULONG get_refcount(IUnknown *test_iface)
1036 IUnknown_AddRef(test_iface);
1037 return IUnknown_Release(test_iface);
1040 static void test_viewport(void)
1042 IDirectDraw *ddraw;
1043 IDirect3D *d3d;
1044 HRESULT hr;
1045 ULONG ref;
1046 IDirect3DViewport *viewport, *another_vp;
1047 IDirect3DViewport2 *viewport2;
1048 IDirect3DViewport3 *viewport3;
1049 IDirectDrawGammaControl *gamma;
1050 IUnknown *unknown;
1051 IDirect3DDevice *device;
1052 HWND window;
1054 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1055 0, 0, 640, 480, 0, 0, 0, 0);
1056 ddraw = create_ddraw();
1057 ok(!!ddraw, "Failed to create a ddraw object.\n");
1058 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
1060 skip("Failed to create a 3D device, skipping test.\n");
1061 IDirectDraw_Release(ddraw);
1062 DestroyWindow(window);
1063 return;
1066 hr = IDirectDraw_QueryInterface(ddraw, &IID_IDirect3D, (void **)&d3d);
1067 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
1068 ref = get_refcount((IUnknown *) d3d);
1069 ok(ref == 2, "IDirect3D refcount is %d\n", ref);
1071 hr = IDirect3D_CreateViewport(d3d, &viewport, NULL);
1072 ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
1073 ref = get_refcount((IUnknown *)viewport);
1074 ok(ref == 1, "Initial IDirect3DViewport refcount is %u\n", ref);
1075 ref = get_refcount((IUnknown *)d3d);
1076 ok(ref == 2, "IDirect3D refcount is %u\n", ref);
1078 /* E_FAIL return values are returned by Winetestbot Windows NT machines. While not supporting
1079 * newer interfaces is legitimate for old ddraw versions, E_FAIL violates Microsoft's rules
1080 * for QueryInterface, hence the broken() */
1081 gamma = (IDirectDrawGammaControl *)0xdeadbeef;
1082 hr = IDirect3DViewport_QueryInterface(viewport, &IID_IDirectDrawGammaControl, (void **)&gamma);
1083 ok(hr == E_NOINTERFACE || broken(hr == E_FAIL), "Got unexpected hr %#x.\n", hr);
1084 ok(gamma == NULL, "Interface not set to NULL by failed QI call: %p\n", gamma);
1085 if (SUCCEEDED(hr)) IDirectDrawGammaControl_Release(gamma);
1086 /* NULL iid: Segfaults */
1088 hr = IDirect3DViewport_QueryInterface(viewport, &IID_IDirect3DViewport2, (void **)&viewport2);
1089 ok(SUCCEEDED(hr) || hr == E_NOINTERFACE || broken(hr == E_FAIL),
1090 "Failed to QI IDirect3DViewport2, hr %#x.\n", hr);
1091 if (viewport2)
1093 ref = get_refcount((IUnknown *)viewport);
1094 ok(ref == 2, "IDirect3DViewport refcount is %u\n", ref);
1095 ref = get_refcount((IUnknown *)viewport2);
1096 ok(ref == 2, "IDirect3DViewport2 refcount is %u\n", ref);
1097 IDirect3DViewport2_Release(viewport2);
1098 viewport2 = NULL;
1101 hr = IDirect3DViewport_QueryInterface(viewport, &IID_IDirect3DViewport3, (void **)&viewport3);
1102 ok(SUCCEEDED(hr) || hr == E_NOINTERFACE || broken(hr == E_FAIL),
1103 "Failed to QI IDirect3DViewport3, hr %#x.\n", hr);
1104 if (viewport3)
1106 ref = get_refcount((IUnknown *)viewport);
1107 ok(ref == 2, "IDirect3DViewport refcount is %u\n", ref);
1108 ref = get_refcount((IUnknown *)viewport3);
1109 ok(ref == 2, "IDirect3DViewport3 refcount is %u\n", ref);
1110 IDirect3DViewport3_Release(viewport3);
1113 hr = IDirect3DViewport_QueryInterface(viewport, &IID_IUnknown, (void **)&unknown);
1114 ok(SUCCEEDED(hr), "Failed to QI IUnknown, hr %#x.\n", hr);
1115 if (unknown)
1117 ref = get_refcount((IUnknown *)viewport);
1118 ok(ref == 2, "IDirect3DViewport refcount is %u\n", ref);
1119 ref = get_refcount(unknown);
1120 ok(ref == 2, "IUnknown refcount is %u\n", ref);
1121 IUnknown_Release(unknown);
1124 /* AddViewport(NULL): Segfault */
1125 hr = IDirect3DDevice_DeleteViewport(device, NULL);
1126 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
1128 hr = IDirect3D_CreateViewport(d3d, &another_vp, NULL);
1129 ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
1131 hr = IDirect3DDevice_AddViewport(device, viewport);
1132 ok(SUCCEEDED(hr), "Failed to add viewport to device, hr %#x.\n", hr);
1133 ref = get_refcount((IUnknown *) viewport);
1134 ok(ref == 2, "IDirect3DViewport refcount is %d\n", ref);
1135 hr = IDirect3DDevice_AddViewport(device, another_vp);
1136 ok(SUCCEEDED(hr), "Failed to add viewport to device, hr %#x.\n", hr);
1137 ref = get_refcount((IUnknown *) another_vp);
1138 ok(ref == 2, "IDirect3DViewport refcount is %d\n", ref);
1140 hr = IDirect3DDevice_DeleteViewport(device, another_vp);
1141 ok(SUCCEEDED(hr), "Failed to delete viewport from device, hr %#x.\n", hr);
1142 ref = get_refcount((IUnknown *) another_vp);
1143 ok(ref == 1, "IDirect3DViewport refcount is %d\n", ref);
1145 IDirect3DDevice_Release(device);
1146 ref = get_refcount((IUnknown *) viewport);
1147 ok(ref == 1, "IDirect3DViewport refcount is %d\n", ref);
1149 IDirect3DViewport_Release(another_vp);
1150 IDirect3D_Release(d3d);
1151 IDirect3DViewport_Release(viewport);
1152 DestroyWindow(window);
1153 IDirectDraw_Release(ddraw);
1156 static void test_zenable(void)
1158 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
1159 static D3DTLVERTEX tquad[] =
1161 {{ 0.0f}, {480.0f}, {-0.5f}, {1.0f}, {0xff00ff00}, {0x00000000}, {0.0f}, {0.0f}},
1162 {{ 0.0f}, { 0.0f}, {-0.5f}, {1.0f}, {0xff00ff00}, {0x00000000}, {0.0f}, {0.0f}},
1163 {{640.0f}, {480.0f}, { 1.5f}, {1.0f}, {0xff00ff00}, {0x00000000}, {0.0f}, {0.0f}},
1164 {{640.0f}, { 0.0f}, { 1.5f}, {1.0f}, {0xff00ff00}, {0x00000000}, {0.0f}, {0.0f}},
1166 IDirect3DExecuteBuffer *execute_buffer;
1167 D3DEXECUTEBUFFERDESC exec_desc;
1168 IDirect3DMaterial *background;
1169 IDirect3DViewport *viewport;
1170 IDirect3DDevice *device;
1171 IDirectDrawSurface *rt;
1172 IDirectDraw *ddraw;
1173 UINT inst_length;
1174 D3DCOLOR color;
1175 HWND window;
1176 HRESULT hr;
1177 UINT x, y;
1178 UINT i, j;
1179 void *ptr;
1181 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1182 0, 0, 640, 480, 0, 0, 0, 0);
1183 ddraw = create_ddraw();
1184 ok(!!ddraw, "Failed to create a ddraw object.\n");
1185 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
1187 skip("Failed to create a 3D device, skipping test.\n");
1188 IDirectDraw_Release(ddraw);
1189 DestroyWindow(window);
1190 return;
1193 background = create_diffuse_material(device, 1.0f, 0.0f, 0.0f, 1.0f);
1194 viewport = create_viewport(device, 0, 0, 640, 480);
1195 viewport_set_background(device, viewport, background);
1197 memset(&exec_desc, 0, sizeof(exec_desc));
1198 exec_desc.dwSize = sizeof(exec_desc);
1199 exec_desc.dwFlags = D3DDEB_BUFSIZE | D3DDEB_CAPS;
1200 exec_desc.dwBufferSize = 1024;
1201 exec_desc.dwCaps = D3DDEBCAPS_SYSTEMMEMORY;
1203 hr = IDirect3DDevice_CreateExecuteBuffer(device, &exec_desc, &execute_buffer, NULL);
1204 ok(SUCCEEDED(hr), "Failed to create execute buffer, hr %#x.\n", hr);
1205 hr = IDirect3DExecuteBuffer_Lock(execute_buffer, &exec_desc);
1206 ok(SUCCEEDED(hr), "Failed to lock execute buffer, hr %#x.\n", hr);
1207 memcpy(exec_desc.lpData, tquad, sizeof(tquad));
1208 ptr = ((BYTE *)exec_desc.lpData) + sizeof(tquad);
1209 emit_process_vertices(&ptr, D3DPROCESSVERTICES_COPY, 0, 4);
1210 emit_set_rs(&ptr, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
1211 emit_tquad(&ptr, 0);
1212 emit_end(&ptr);
1213 inst_length = (BYTE *)ptr - (BYTE *)exec_desc.lpData;
1214 inst_length -= sizeof(tquad);
1215 hr = IDirect3DExecuteBuffer_Unlock(execute_buffer);
1216 ok(SUCCEEDED(hr), "Failed to unlock execute buffer, hr %#x.\n", hr);
1218 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
1219 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
1220 hr = IDirect3DDevice_BeginScene(device);
1221 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1222 set_execute_data(execute_buffer, 4, sizeof(tquad), inst_length);
1223 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
1224 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
1225 hr = IDirect3DDevice_EndScene(device);
1226 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1228 hr = IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&rt);
1229 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1230 for (i = 0; i < 4; ++i)
1232 for (j = 0; j < 4; ++j)
1234 x = 80 * ((2 * j) + 1);
1235 y = 60 * ((2 * i) + 1);
1236 color = get_surface_color(rt, x, y);
1237 ok(compare_color(color, 0x0000ff00, 1),
1238 "Expected color 0x0000ff00 at %u, %u, got 0x%08x.\n", x, y, color);
1241 IDirectDrawSurface_Release(rt);
1243 destroy_viewport(device, viewport);
1244 IDirect3DExecuteBuffer_Release(execute_buffer);
1245 destroy_material(background);
1246 IDirect3DDevice_Release(device);
1247 IDirectDraw_Release(ddraw);
1248 DestroyWindow(window);
1251 static void test_ck_rgba(void)
1253 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
1254 static D3DTLVERTEX tquad[] =
1256 {{ 0.0f}, {480.0f}, {0.25f}, {1.0f}, {0xffffffff}, {0x00000000}, {0.0f}, {0.0f}},
1257 {{ 0.0f}, { 0.0f}, {0.25f}, {1.0f}, {0xffffffff}, {0x00000000}, {0.0f}, {1.0f}},
1258 {{640.0f}, {480.0f}, {0.25f}, {1.0f}, {0xffffffff}, {0x00000000}, {1.0f}, {0.0f}},
1259 {{640.0f}, { 0.0f}, {0.25f}, {1.0f}, {0xffffffff}, {0x00000000}, {1.0f}, {1.0f}},
1260 {{ 0.0f}, {480.0f}, {0.75f}, {1.0f}, {0xffffffff}, {0x00000000}, {0.0f}, {0.0f}},
1261 {{ 0.0f}, { 0.0f}, {0.75f}, {1.0f}, {0xffffffff}, {0x00000000}, {0.0f}, {1.0f}},
1262 {{640.0f}, {480.0f}, {0.75f}, {1.0f}, {0xffffffff}, {0x00000000}, {1.0f}, {0.0f}},
1263 {{640.0f}, { 0.0f}, {0.75f}, {1.0f}, {0xffffffff}, {0x00000000}, {1.0f}, {1.0f}},
1265 /* Supposedly there was no D3DRENDERSTATE_COLORKEYENABLE in D3D < 5.
1266 * Maybe the WARP driver on Windows 8 ignores setting it via the older
1267 * device interface but it's buggy in that the internal state is not
1268 * initialized, or possibly toggling D3DRENDERSTATE_COLORKEYENABLE /
1269 * D3DRENDERSTATE_ALPHABLENDENABLE has unintended side effects.
1270 * Checking the W8 test results it seems like test 1 fails most of the time
1271 * and test 0 fails very rarely. */
1272 static const struct
1274 D3DCOLOR fill_color;
1275 BOOL color_key;
1276 BOOL blend;
1277 D3DCOLOR result1, result1_r200, result1_warp;
1278 D3DCOLOR result2, result2_r200, result2_warp;
1280 tests[] =
1282 /* r200 on Windows doesn't check the alpha component when applying the color
1283 * key, so the key matches on every texel. */
1284 {0xff00ff00, TRUE, TRUE, 0x00ff0000, 0x00ff0000, 0x0000ff00,
1285 0x000000ff, 0x000000ff, 0x0000ff00},
1286 {0xff00ff00, TRUE, FALSE, 0x00ff0000, 0x00ff0000, 0x0000ff00,
1287 0x000000ff, 0x000000ff, 0x0000ff00},
1288 {0xff00ff00, FALSE, TRUE, 0x0000ff00, 0x0000ff00, 0x0000ff00,
1289 0x0000ff00, 0x0000ff00, 0x0000ff00},
1290 {0xff00ff00, FALSE, FALSE, 0x0000ff00, 0x0000ff00, 0x0000ff00,
1291 0x0000ff00, 0x0000ff00, 0x0000ff00},
1292 {0x7f00ff00, TRUE, TRUE, 0x00807f00, 0x00ff0000, 0x00807f00,
1293 0x00807f00, 0x000000ff, 0x00807f00},
1294 {0x7f00ff00, TRUE, FALSE, 0x0000ff00, 0x00ff0000, 0x0000ff00,
1295 0x0000ff00, 0x000000ff, 0x0000ff00},
1296 {0x7f00ff00, FALSE, TRUE, 0x00807f00, 0x00807f00, 0x00807f00,
1297 0x00807f00, 0x00807f00, 0x00807f00},
1298 {0x7f00ff00, FALSE, FALSE, 0x0000ff00, 0x0000ff00, 0x0000ff00,
1299 0x0000ff00, 0x0000ff00, 0x0000ff00},
1302 IDirect3DExecuteBuffer *execute_buffer;
1303 D3DTEXTUREHANDLE texture_handle;
1304 D3DEXECUTEBUFFERDESC exec_desc;
1305 IDirect3DMaterial *background;
1306 IDirectDrawSurface *surface;
1307 IDirect3DViewport *viewport;
1308 DDSURFACEDESC surface_desc;
1309 IDirect3DTexture *texture;
1310 IDirect3DDevice *device;
1311 IDirectDrawSurface *rt;
1312 IDirectDraw *ddraw;
1313 D3DCOLOR color;
1314 HWND window;
1315 DDBLTFX fx;
1316 HRESULT hr;
1317 UINT i;
1319 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1320 0, 0, 640, 480, 0, 0, 0, 0);
1321 ddraw = create_ddraw();
1322 ok(!!ddraw, "Failed to create a ddraw object.\n");
1323 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
1325 skip("Failed to create a 3D device, skipping test.\n");
1326 IDirectDraw_Release(ddraw);
1327 DestroyWindow(window);
1328 return;
1331 background = create_diffuse_material(device, 1.0, 0.0f, 0.0f, 1.0f);
1332 viewport = create_viewport(device, 0, 0, 640, 480);
1333 viewport_set_background(device, viewport, background);
1335 memset(&surface_desc, 0, sizeof(surface_desc));
1336 surface_desc.dwSize = sizeof(surface_desc);
1337 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CKSRCBLT;
1338 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1339 surface_desc.dwWidth = 256;
1340 surface_desc.dwHeight = 256;
1341 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
1342 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
1343 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount = 32;
1344 U2(surface_desc.ddpfPixelFormat).dwRBitMask = 0x00ff0000;
1345 U3(surface_desc.ddpfPixelFormat).dwGBitMask = 0x0000ff00;
1346 U4(surface_desc.ddpfPixelFormat).dwBBitMask = 0x000000ff;
1347 U5(surface_desc.ddpfPixelFormat).dwRGBAlphaBitMask = 0xff000000;
1348 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0xff00ff00;
1349 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0xff00ff00;
1350 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1351 ok(SUCCEEDED(hr), "Failed to create destination surface, hr %#x.\n", hr);
1352 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirect3DTexture, (void **)&texture);
1353 ok(SUCCEEDED(hr), "Failed to get texture interface, hr %#x.\n", hr);
1354 hr = IDirect3DTexture_GetHandle(texture, device, &texture_handle);
1355 ok(SUCCEEDED(hr), "Failed to get texture handle, hr %#x.\n", hr);
1356 IDirect3DTexture_Release(texture);
1358 memset(&exec_desc, 0, sizeof(exec_desc));
1359 exec_desc.dwSize = sizeof(exec_desc);
1360 exec_desc.dwFlags = D3DDEB_BUFSIZE | D3DDEB_CAPS;
1361 exec_desc.dwBufferSize = 1024;
1362 exec_desc.dwCaps = D3DDEBCAPS_SYSTEMMEMORY;
1363 hr = IDirect3DDevice_CreateExecuteBuffer(device, &exec_desc, &execute_buffer, NULL);
1364 ok(SUCCEEDED(hr), "Failed to create execute buffer, hr %#x.\n", hr);
1366 hr = IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&rt);
1367 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1369 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
1371 UINT draw1_len, draw2_len;
1372 void *ptr;
1374 hr = IDirect3DExecuteBuffer_Lock(execute_buffer, &exec_desc);
1375 ok(SUCCEEDED(hr), "Failed to lock execute buffer, hr %#x.\n", hr);
1376 memcpy(exec_desc.lpData, tquad, sizeof(tquad));
1377 ptr = ((BYTE *)exec_desc.lpData) + sizeof(tquad);
1378 emit_process_vertices(&ptr, D3DPROCESSVERTICES_COPY, 0, 4);
1379 emit_set_rs(&ptr, D3DRENDERSTATE_TEXTUREHANDLE, texture_handle);
1380 emit_set_rs(&ptr, D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);
1381 emit_set_rs(&ptr, D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA);
1382 emit_set_rs(&ptr, D3DRENDERSTATE_COLORKEYENABLE, tests[i].color_key);
1383 emit_set_rs(&ptr, D3DRENDERSTATE_ALPHABLENDENABLE, tests[i].blend);
1384 emit_tquad(&ptr, 0);
1385 emit_end(&ptr);
1386 draw1_len = (BYTE *)ptr - (BYTE *)exec_desc.lpData - sizeof(tquad);
1387 emit_process_vertices(&ptr, D3DPROCESSVERTICES_COPY, 4, 4);
1388 emit_tquad(&ptr, 0);
1389 emit_set_rs(&ptr, D3DRENDERSTATE_TEXTUREHANDLE, 0);
1390 emit_end(&ptr);
1391 draw2_len = (BYTE *)ptr - (BYTE *)exec_desc.lpData - draw1_len;
1392 hr = IDirect3DExecuteBuffer_Unlock(execute_buffer);
1393 ok(SUCCEEDED(hr), "Failed to unlock execute buffer, hr %#x.\n", hr);
1395 memset(&fx, 0, sizeof(fx));
1396 fx.dwSize = sizeof(fx);
1397 U5(fx).dwFillColor = tests[i].fill_color;
1398 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
1399 ok(SUCCEEDED(hr), "Failed to fill texture, hr %#x.\n", hr);
1401 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER);
1402 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
1403 hr = IDirect3DDevice_BeginScene(device);
1404 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1405 set_execute_data(execute_buffer, 8, sizeof(tquad), draw1_len);
1406 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
1407 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
1408 hr = IDirect3DDevice_EndScene(device);
1409 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1411 color = get_surface_color(rt, 320, 240);
1412 ok(compare_color(color, tests[i].result1, 1)
1413 || broken(compare_color(color, tests[i].result1_r200, 1))
1414 || broken(compare_color(color, tests[i].result1_warp, 1)),
1415 "Got unexpected color 0x%08x for test %u.\n", color, i);
1417 U5(fx).dwFillColor = 0xff0000ff;
1418 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
1419 ok(SUCCEEDED(hr), "Failed to fill texture, hr %#x.\n", hr);
1421 hr = IDirect3DDevice_BeginScene(device);
1422 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1423 set_execute_data(execute_buffer, 8, sizeof(tquad) + draw1_len, draw2_len);
1424 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
1425 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
1426 hr = IDirect3DDevice_EndScene(device);
1427 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1429 /* This tests that fragments that are masked out by the color key are
1430 * discarded, instead of just fully transparent. */
1431 color = get_surface_color(rt, 320, 240);
1432 ok(compare_color(color, tests[i].result2, 1)
1433 || broken(compare_color(color, tests[i].result2_r200, 1))
1434 || broken(compare_color(color, tests[i].result2_warp, 1)),
1435 "Got unexpected color 0x%08x for test %u.\n", color, i);
1438 IDirectDrawSurface_Release(rt);
1439 IDirect3DExecuteBuffer_Release(execute_buffer);
1440 IDirectDrawSurface_Release(surface);
1441 destroy_viewport(device, viewport);
1442 destroy_material(background);
1443 IDirect3DDevice_Release(device);
1444 IDirectDraw_Release(ddraw);
1445 DestroyWindow(window);
1448 static void test_ck_default(void)
1450 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
1451 static D3DTLVERTEX tquad[] =
1453 {{ 0.0f}, {480.0f}, {0.0f}, {1.0f}, {0xffffffff}, {0x00000000}, {0.0f}, {0.0f}},
1454 {{ 0.0f}, { 0.0f}, {0.0f}, {1.0f}, {0xffffffff}, {0x00000000}, {0.0f}, {1.0f}},
1455 {{640.0f}, {480.0f}, {0.0f}, {1.0f}, {0xffffffff}, {0x00000000}, {1.0f}, {0.0f}},
1456 {{640.0f}, { 0.0f}, {0.0f}, {1.0f}, {0xffffffff}, {0x00000000}, {1.0f}, {1.0f}},
1458 IDirect3DExecuteBuffer *execute_buffer;
1459 IDirectDrawSurface *surface, *rt;
1460 D3DTEXTUREHANDLE texture_handle;
1461 D3DEXECUTEBUFFERDESC exec_desc;
1462 IDirect3DMaterial *background;
1463 UINT draw1_offset, draw1_len;
1464 UINT draw2_offset, draw2_len;
1465 UINT draw3_offset, draw3_len;
1466 UINT draw4_offset, draw4_len;
1467 IDirect3DViewport *viewport;
1468 DDSURFACEDESC surface_desc;
1469 IDirect3DTexture *texture;
1470 IDirect3DDevice *device;
1471 IDirectDraw *ddraw;
1472 D3DCOLOR color;
1473 HWND window;
1474 DDBLTFX fx;
1475 HRESULT hr;
1476 void *ptr;
1478 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1479 0, 0, 640, 480, 0, 0, 0, 0);
1480 ddraw = create_ddraw();
1481 ok(!!ddraw, "Failed to create a ddraw object.\n");
1482 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
1484 skip("Failed to create a 3D device, skipping test.\n");
1485 IDirectDraw_Release(ddraw);
1486 DestroyWindow(window);
1487 return;
1490 hr = IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&rt);
1491 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1493 background = create_diffuse_material(device, 0.0, 1.0f, 0.0f, 1.0f);
1494 viewport = create_viewport(device, 0, 0, 640, 480);
1495 viewport_set_background(device, viewport, background);
1497 memset(&surface_desc, 0, sizeof(surface_desc));
1498 surface_desc.dwSize = sizeof(surface_desc);
1499 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CKSRCBLT;
1500 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1501 surface_desc.dwWidth = 256;
1502 surface_desc.dwHeight = 256;
1503 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
1504 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB;
1505 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount = 32;
1506 U2(surface_desc.ddpfPixelFormat).dwRBitMask = 0x00ff0000;
1507 U3(surface_desc.ddpfPixelFormat).dwGBitMask = 0x0000ff00;
1508 U4(surface_desc.ddpfPixelFormat).dwBBitMask = 0x000000ff;
1509 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x000000ff;
1510 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x000000ff;
1511 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1512 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1513 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirect3DTexture, (void **)&texture);
1514 ok(SUCCEEDED(hr), "Failed to get texture interface, hr %#x.\n", hr);
1515 hr = IDirect3DTexture_GetHandle(texture, device, &texture_handle);
1516 ok(SUCCEEDED(hr), "Failed to get texture handle, hr %#x.\n", hr);
1517 IDirect3DTexture_Release(texture);
1519 memset(&fx, 0, sizeof(fx));
1520 fx.dwSize = sizeof(fx);
1521 U5(fx).dwFillColor = 0x000000ff;
1522 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
1523 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
1525 memset(&exec_desc, 0, sizeof(exec_desc));
1526 exec_desc.dwSize = sizeof(exec_desc);
1527 exec_desc.dwFlags = D3DDEB_BUFSIZE | D3DDEB_CAPS;
1528 exec_desc.dwBufferSize = 1024;
1529 exec_desc.dwCaps = D3DDEBCAPS_SYSTEMMEMORY;
1530 hr = IDirect3DDevice_CreateExecuteBuffer(device, &exec_desc, &execute_buffer, NULL);
1531 ok(SUCCEEDED(hr), "Failed to create execute buffer, hr %#x.\n", hr);
1533 hr = IDirect3DExecuteBuffer_Lock(execute_buffer, &exec_desc);
1534 ok(SUCCEEDED(hr), "Failed to lock execute buffer, hr %#x.\n", hr);
1535 memcpy(exec_desc.lpData, tquad, sizeof(tquad));
1536 ptr = (BYTE *)exec_desc.lpData + sizeof(tquad);
1537 emit_process_vertices(&ptr, D3DPROCESSVERTICES_COPY, 0, 4);
1538 emit_set_rs(&ptr, D3DRENDERSTATE_TEXTUREHANDLE, texture_handle);
1539 emit_tquad(&ptr, 0);
1540 emit_end(&ptr);
1541 draw1_offset = sizeof(tquad);
1542 draw1_len = (BYTE *)ptr - (BYTE *)exec_desc.lpData - draw1_offset;
1543 emit_process_vertices(&ptr, D3DPROCESSVERTICES_COPY, 0, 4);
1544 emit_set_rs(&ptr, D3DRENDERSTATE_COLORKEYENABLE, FALSE);
1545 emit_tquad(&ptr, 0);
1546 emit_end(&ptr);
1547 draw2_offset = draw1_offset + draw1_len;
1548 draw2_len = (BYTE *)ptr - (BYTE *)exec_desc.lpData - draw2_offset;
1549 emit_process_vertices(&ptr, D3DPROCESSVERTICES_COPY, 0, 4);
1550 emit_tquad(&ptr, 0);
1551 emit_end(&ptr);
1552 draw3_offset = draw2_offset + draw2_len;
1553 draw3_len = (BYTE *)ptr - (BYTE *)exec_desc.lpData - draw3_offset;
1554 emit_process_vertices(&ptr, D3DPROCESSVERTICES_COPY, 0, 4);
1555 emit_set_rs(&ptr, D3DRENDERSTATE_COLORKEYENABLE, TRUE);
1556 emit_tquad(&ptr, 0);
1557 emit_set_rs(&ptr, D3DRENDERSTATE_TEXTUREHANDLE, 0);
1558 emit_end(&ptr);
1559 draw4_offset = draw3_offset + draw3_len;
1560 draw4_len = (BYTE *)ptr - (BYTE *)exec_desc.lpData - draw4_offset;
1561 hr = IDirect3DExecuteBuffer_Unlock(execute_buffer);
1562 ok(SUCCEEDED(hr), "Failed to unlock execute buffer, hr %#x.\n", hr);
1564 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
1565 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
1566 hr = IDirect3DDevice_BeginScene(device);
1567 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1568 set_execute_data(execute_buffer, 4, draw1_offset, draw1_len);
1569 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
1570 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
1571 hr = IDirect3DDevice_EndScene(device);
1572 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1573 color = get_surface_color(rt, 320, 240);
1574 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
1576 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
1577 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
1578 hr = IDirect3DDevice_BeginScene(device);
1579 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1580 set_execute_data(execute_buffer, 4, draw2_offset, draw2_len);
1581 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
1582 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
1583 hr = IDirect3DDevice_EndScene(device);
1584 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1585 color = get_surface_color(rt, 320, 240);
1586 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
1588 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
1589 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
1590 hr = IDirect3DDevice_BeginScene(device);
1591 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1592 set_execute_data(execute_buffer, 4, draw3_offset, draw3_len);
1593 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
1594 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
1595 hr = IDirect3DDevice_EndScene(device);
1596 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1597 color = get_surface_color(rt, 320, 240);
1598 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
1600 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
1601 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
1602 hr = IDirect3DDevice_BeginScene(device);
1603 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1604 set_execute_data(execute_buffer, 4, draw4_offset, draw4_len);
1605 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
1606 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
1607 hr = IDirect3DDevice_EndScene(device);
1608 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1609 color = get_surface_color(rt, 320, 240);
1610 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
1612 IDirect3DExecuteBuffer_Release(execute_buffer);
1613 IDirectDrawSurface_Release(surface);
1614 destroy_viewport(device, viewport);
1615 destroy_material(background);
1616 IDirectDrawSurface_Release(rt);
1617 IDirect3DDevice_Release(device);
1618 IDirectDraw_Release(ddraw);
1619 DestroyWindow(window);
1622 static void test_ck_complex(void)
1624 IDirectDrawSurface *surface, *mipmap, *tmp;
1625 DDSCAPS caps = {DDSCAPS_COMPLEX};
1626 DDSURFACEDESC surface_desc;
1627 IDirect3DDevice *device;
1628 DDCOLORKEY color_key;
1629 IDirectDraw *ddraw;
1630 unsigned int i;
1631 ULONG refcount;
1632 HWND window;
1633 HRESULT hr;
1635 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1636 0, 0, 640, 480, 0, 0, 0, 0);
1637 ddraw = create_ddraw();
1638 ok(!!ddraw, "Failed to create a ddraw object.\n");
1639 if (!(device = create_device(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN)))
1641 skip("Failed to create a 3D device, skipping test.\n");
1642 DestroyWindow(window);
1643 IDirectDraw2_Release(ddraw);
1644 return;
1646 IDirect3DDevice_Release(device);
1648 memset(&surface_desc, 0, sizeof(surface_desc));
1649 surface_desc.dwSize = sizeof(surface_desc);
1650 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1651 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
1652 surface_desc.dwWidth = 128;
1653 surface_desc.dwHeight = 128;
1654 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1655 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1657 hr = IDirectDrawSurface_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1658 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1659 color_key.dwColorSpaceLowValue = 0x0000ff00;
1660 color_key.dwColorSpaceHighValue = 0x0000ff00;
1661 hr = IDirectDrawSurface_SetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1662 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1663 memset(&color_key, 0, sizeof(color_key));
1664 hr = IDirectDrawSurface_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1665 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
1666 ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1667 color_key.dwColorSpaceLowValue);
1668 ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1669 color_key.dwColorSpaceHighValue);
1671 mipmap = surface;
1672 IDirectDrawSurface_AddRef(mipmap);
1673 for (i = 0; i < 7; ++i)
1675 hr = IDirectDrawSurface_GetAttachedSurface(mipmap, &caps, &tmp);
1676 ok(SUCCEEDED(hr), "Failed to get attached surface, i %u, hr %#x.\n", i, hr);
1678 hr = IDirectDrawSurface_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1679 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x, i %u.\n", hr, i);
1680 color_key.dwColorSpaceLowValue = 0x000000ff;
1681 color_key.dwColorSpaceHighValue = 0x000000ff;
1682 hr = IDirectDrawSurface_SetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1683 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x, i %u.\n", hr, i);
1684 memset(&color_key, 0, sizeof(color_key));
1685 hr = IDirectDrawSurface_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1686 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x, i %u.\n", hr, i);
1687 ok(color_key.dwColorSpaceLowValue == 0x000000ff, "Got unexpected value 0x%08x, i %u.\n",
1688 color_key.dwColorSpaceLowValue, i);
1689 ok(color_key.dwColorSpaceHighValue == 0x000000ff, "Got unexpected value 0x%08x, i %u.\n",
1690 color_key.dwColorSpaceHighValue, i);
1692 IDirectDrawSurface_Release(mipmap);
1693 mipmap = tmp;
1696 memset(&color_key, 0, sizeof(color_key));
1697 hr = IDirectDrawSurface_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1698 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
1699 ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1700 color_key.dwColorSpaceLowValue);
1701 ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1702 color_key.dwColorSpaceHighValue);
1704 hr = IDirectDrawSurface_GetAttachedSurface(mipmap, &caps, &tmp);
1705 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
1706 IDirectDrawSurface_Release(mipmap);
1707 refcount = IDirectDrawSurface_Release(surface);
1708 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1710 memset(&surface_desc, 0, sizeof(surface_desc));
1711 surface_desc.dwSize = sizeof(surface_desc);
1712 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
1713 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
1714 surface_desc.dwBackBufferCount = 1;
1715 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1716 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1718 hr = IDirectDrawSurface_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1719 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1720 color_key.dwColorSpaceLowValue = 0x0000ff00;
1721 color_key.dwColorSpaceHighValue = 0x0000ff00;
1722 hr = IDirectDrawSurface_SetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1723 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1724 memset(&color_key, 0, sizeof(color_key));
1725 hr = IDirectDrawSurface_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1726 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
1727 ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1728 color_key.dwColorSpaceLowValue);
1729 ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1730 color_key.dwColorSpaceHighValue);
1732 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &tmp);
1733 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
1735 hr = IDirectDrawSurface_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1736 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x, i %u.\n", hr, i);
1737 color_key.dwColorSpaceLowValue = 0x0000ff00;
1738 color_key.dwColorSpaceHighValue = 0x0000ff00;
1739 hr = IDirectDrawSurface_SetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1740 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1741 memset(&color_key, 0, sizeof(color_key));
1742 hr = IDirectDrawSurface_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1743 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
1744 ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1745 color_key.dwColorSpaceLowValue);
1746 ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1747 color_key.dwColorSpaceHighValue);
1749 IDirectDrawSurface_Release(tmp);
1751 refcount = IDirectDrawSurface_Release(surface);
1752 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1753 refcount = IDirectDraw_Release(ddraw);
1754 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1755 DestroyWindow(window);
1758 struct qi_test
1760 REFIID iid;
1761 REFIID refcount_iid;
1762 HRESULT hr;
1765 static void test_qi(const char *test_name, IUnknown *base_iface,
1766 REFIID refcount_iid, const struct qi_test *tests, UINT entry_count)
1768 ULONG refcount, expected_refcount;
1769 IUnknown *iface1, *iface2;
1770 HRESULT hr;
1771 UINT i, j;
1773 for (i = 0; i < entry_count; ++i)
1775 hr = IUnknown_QueryInterface(base_iface, tests[i].iid, (void **)&iface1);
1776 ok(hr == tests[i].hr, "Got hr %#x for test \"%s\" %u.\n", hr, test_name, i);
1777 if (SUCCEEDED(hr))
1779 for (j = 0; j < entry_count; ++j)
1781 hr = IUnknown_QueryInterface(iface1, tests[j].iid, (void **)&iface2);
1782 ok(hr == tests[j].hr, "Got hr %#x for test \"%s\" %u, %u.\n", hr, test_name, i, j);
1783 if (SUCCEEDED(hr))
1785 expected_refcount = 0;
1786 if (IsEqualGUID(refcount_iid, tests[j].refcount_iid))
1787 ++expected_refcount;
1788 if (IsEqualGUID(tests[i].refcount_iid, tests[j].refcount_iid))
1789 ++expected_refcount;
1790 refcount = IUnknown_Release(iface2);
1791 ok(refcount == expected_refcount, "Got refcount %u for test \"%s\" %u, %u, expected %u.\n",
1792 refcount, test_name, i, j, expected_refcount);
1796 expected_refcount = 0;
1797 if (IsEqualGUID(refcount_iid, tests[i].refcount_iid))
1798 ++expected_refcount;
1799 refcount = IUnknown_Release(iface1);
1800 ok(refcount == expected_refcount, "Got refcount %u for test \"%s\" %u, expected %u.\n",
1801 refcount, test_name, i, expected_refcount);
1806 static void test_surface_qi(void)
1808 static const struct qi_test tests[] =
1810 {&IID_IDirect3DTexture2, &IID_IDirectDrawSurface, S_OK },
1811 {&IID_IDirect3DTexture, &IID_IDirectDrawSurface, S_OK },
1812 {&IID_IDirectDrawGammaControl, &IID_IDirectDrawGammaControl, S_OK },
1813 {&IID_IDirectDrawColorControl, NULL, E_NOINTERFACE},
1814 {&IID_IDirectDrawSurface7, &IID_IDirectDrawSurface7, S_OK },
1815 {&IID_IDirectDrawSurface4, &IID_IDirectDrawSurface4, S_OK },
1816 {&IID_IDirectDrawSurface3, &IID_IDirectDrawSurface3, S_OK },
1817 {&IID_IDirectDrawSurface2, &IID_IDirectDrawSurface2, S_OK },
1818 {&IID_IDirectDrawSurface, &IID_IDirectDrawSurface, S_OK },
1819 {&IID_IDirect3DDevice7, NULL, E_INVALIDARG },
1820 {&IID_IDirect3DDevice3, NULL, E_INVALIDARG },
1821 {&IID_IDirect3DDevice2, NULL, E_INVALIDARG },
1822 {&IID_IDirect3DDevice, NULL, E_INVALIDARG },
1823 {&IID_IDirect3D7, NULL, E_INVALIDARG },
1824 {&IID_IDirect3D3, NULL, E_INVALIDARG },
1825 {&IID_IDirect3D2, NULL, E_INVALIDARG },
1826 {&IID_IDirect3D, NULL, E_INVALIDARG },
1827 {&IID_IDirectDraw7, NULL, E_INVALIDARG },
1828 {&IID_IDirectDraw4, NULL, E_INVALIDARG },
1829 {&IID_IDirectDraw3, NULL, E_INVALIDARG },
1830 {&IID_IDirectDraw2, NULL, E_INVALIDARG },
1831 {&IID_IDirectDraw, NULL, E_INVALIDARG },
1832 {&IID_IDirect3DLight, NULL, E_INVALIDARG },
1833 {&IID_IDirect3DMaterial, NULL, E_INVALIDARG },
1834 {&IID_IDirect3DMaterial2, NULL, E_INVALIDARG },
1835 {&IID_IDirect3DMaterial3, NULL, E_INVALIDARG },
1836 {&IID_IDirect3DExecuteBuffer, NULL, E_INVALIDARG },
1837 {&IID_IDirect3DViewport, NULL, E_INVALIDARG },
1838 {&IID_IDirect3DViewport2, NULL, E_INVALIDARG },
1839 {&IID_IDirect3DViewport3, NULL, E_INVALIDARG },
1840 {&IID_IDirect3DVertexBuffer, NULL, E_INVALIDARG },
1841 {&IID_IDirect3DVertexBuffer7, NULL, E_INVALIDARG },
1842 {&IID_IDirectDrawPalette, NULL, E_INVALIDARG },
1843 {&IID_IDirectDrawClipper, NULL, E_INVALIDARG },
1844 {&IID_IUnknown, &IID_IDirectDrawSurface, S_OK },
1847 IDirectDrawSurface *surface;
1848 DDSURFACEDESC surface_desc;
1849 IDirect3DDevice *device;
1850 IDirectDraw *ddraw;
1851 HWND window;
1852 HRESULT hr;
1854 if (!GetProcAddress(GetModuleHandleA("ddraw.dll"), "DirectDrawCreateEx"))
1856 win_skip("DirectDrawCreateEx not available, skipping test.\n");
1857 return;
1860 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1861 0, 0, 640, 480, 0, 0, 0, 0);
1862 ddraw = create_ddraw();
1863 ok(!!ddraw, "Failed to create a ddraw object.\n");
1864 /* Try to create a D3D device to see if the ddraw implementation supports
1865 * D3D. 64-bit ddraw in particular doesn't seem to support D3D, and
1866 * doesn't support e.g. the IDirect3DTexture interfaces. */
1867 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
1869 skip("Failed to create a 3D device, skipping test.\n");
1870 IDirectDraw_Release(ddraw);
1871 DestroyWindow(window);
1872 return;
1874 IDirect3DDevice_Release(device);
1876 memset(&surface_desc, 0, sizeof(surface_desc));
1877 surface_desc.dwSize = sizeof(surface_desc);
1878 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1879 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1880 surface_desc.dwWidth = 512;
1881 surface_desc.dwHeight = 512;
1882 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1883 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1885 test_qi("surface_qi", (IUnknown *)surface, &IID_IDirectDrawSurface, tests, sizeof(tests) / sizeof(*tests));
1887 IDirectDrawSurface_Release(surface);
1888 IDirectDraw_Release(ddraw);
1889 DestroyWindow(window);
1892 static void test_device_qi(void)
1894 static const struct qi_test tests[] =
1896 {&IID_IDirect3DTexture2, &IID_IDirectDrawSurface, S_OK },
1897 {&IID_IDirect3DTexture, &IID_IDirectDrawSurface, S_OK },
1898 {&IID_IDirectDrawGammaControl, &IID_IDirectDrawGammaControl, S_OK },
1899 {&IID_IDirectDrawColorControl, NULL, E_NOINTERFACE},
1900 {&IID_IDirectDrawSurface7, &IID_IDirectDrawSurface7, S_OK },
1901 {&IID_IDirectDrawSurface4, &IID_IDirectDrawSurface4, S_OK },
1902 {&IID_IDirectDrawSurface3, &IID_IDirectDrawSurface3, S_OK },
1903 {&IID_IDirectDrawSurface2, &IID_IDirectDrawSurface2, S_OK },
1904 {&IID_IDirectDrawSurface, &IID_IDirectDrawSurface, S_OK },
1905 {&IID_IDirect3DDevice7, NULL, E_INVALIDARG },
1906 {&IID_IDirect3DDevice3, NULL, E_INVALIDARG },
1907 {&IID_IDirect3DDevice2, NULL, E_INVALIDARG },
1908 {&IID_IDirect3DDevice, NULL, E_INVALIDARG },
1909 {&IID_IDirect3DHALDevice, &IID_IDirectDrawSurface, S_OK },
1910 {&IID_IDirect3D7, NULL, E_INVALIDARG },
1911 {&IID_IDirect3D3, NULL, E_INVALIDARG },
1912 {&IID_IDirect3D2, NULL, E_INVALIDARG },
1913 {&IID_IDirect3D, NULL, E_INVALIDARG },
1914 {&IID_IDirectDraw7, NULL, E_INVALIDARG },
1915 {&IID_IDirectDraw4, NULL, E_INVALIDARG },
1916 {&IID_IDirectDraw3, NULL, E_INVALIDARG },
1917 {&IID_IDirectDraw2, NULL, E_INVALIDARG },
1918 {&IID_IDirectDraw, NULL, E_INVALIDARG },
1919 {&IID_IDirect3DLight, NULL, E_INVALIDARG },
1920 {&IID_IDirect3DMaterial, NULL, E_INVALIDARG },
1921 {&IID_IDirect3DMaterial2, NULL, E_INVALIDARG },
1922 {&IID_IDirect3DMaterial3, NULL, E_INVALIDARG },
1923 {&IID_IDirect3DExecuteBuffer, NULL, E_INVALIDARG },
1924 {&IID_IDirect3DViewport, NULL, E_INVALIDARG },
1925 {&IID_IDirect3DViewport2, NULL, E_INVALIDARG },
1926 {&IID_IDirect3DViewport3, NULL, E_INVALIDARG },
1927 {&IID_IDirect3DVertexBuffer, NULL, E_INVALIDARG },
1928 {&IID_IDirect3DVertexBuffer7, NULL, E_INVALIDARG },
1929 {&IID_IDirectDrawPalette, NULL, E_INVALIDARG },
1930 {&IID_IDirectDrawClipper, NULL, E_INVALIDARG },
1931 {&IID_IUnknown, &IID_IDirectDrawSurface, S_OK },
1935 IDirect3DDevice *device;
1936 IDirectDraw *ddraw;
1937 HWND window;
1939 if (!GetProcAddress(GetModuleHandleA("ddraw.dll"), "DirectDrawCreateEx"))
1941 win_skip("DirectDrawCreateEx not available, skipping test.\n");
1942 return;
1945 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1946 0, 0, 640, 480, 0, 0, 0, 0);
1947 ddraw = create_ddraw();
1948 ok(!!ddraw, "Failed to create a ddraw object.\n");
1949 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
1951 skip("Failed to create a 3D device, skipping test.\n");
1952 IDirectDraw_Release(ddraw);
1953 DestroyWindow(window);
1954 return;
1957 test_qi("device_qi", (IUnknown *)device, &IID_IDirectDrawSurface, tests, sizeof(tests) / sizeof(*tests));
1959 IDirect3DDevice_Release(device);
1960 IDirectDraw_Release(ddraw);
1961 DestroyWindow(window);
1964 static void test_wndproc(void)
1966 LONG_PTR proc, ddraw_proc;
1967 IDirectDraw *ddraw;
1968 WNDCLASSA wc = {0};
1969 HWND window;
1970 HRESULT hr;
1971 ULONG ref;
1973 static struct message messages[] =
1975 {WM_WINDOWPOSCHANGING, FALSE, 0},
1976 {WM_MOVE, FALSE, 0},
1977 {WM_SIZE, FALSE, 0},
1978 {WM_WINDOWPOSCHANGING, FALSE, 0},
1979 {WM_ACTIVATE, FALSE, 0},
1980 {WM_SETFOCUS, FALSE, 0},
1981 {0, FALSE, 0},
1984 /* DDSCL_EXCLUSIVE replaces the window's window proc. */
1985 ddraw = create_ddraw();
1986 ok(!!ddraw, "Failed to create a ddraw object.\n");
1988 wc.lpfnWndProc = test_proc;
1989 wc.lpszClassName = "ddraw_test_wndproc_wc";
1990 ok(RegisterClassA(&wc), "Failed to register window class.\n");
1992 window = CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
1993 WS_MAXIMIZE | WS_CAPTION , 0, 0, 640, 480, 0, 0, 0, 0);
1995 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
1996 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1997 (LONG_PTR)test_proc, proc);
1998 expect_messages = messages;
1999 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2000 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2001 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2002 expect_messages = NULL;
2003 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2004 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
2005 (LONG_PTR)test_proc, proc);
2006 ref = IDirectDraw_Release(ddraw);
2007 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2008 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2009 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2010 (LONG_PTR)test_proc, proc);
2012 /* DDSCL_NORMAL doesn't. */
2013 ddraw = create_ddraw();
2014 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2015 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2016 (LONG_PTR)test_proc, proc);
2017 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL | DDSCL_FULLSCREEN);
2018 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2019 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2020 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2021 (LONG_PTR)test_proc, proc);
2022 ref = IDirectDraw_Release(ddraw);
2023 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2024 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2025 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2026 (LONG_PTR)test_proc, proc);
2028 /* The original window proc is only restored by ddraw if the current
2029 * window proc matches the one ddraw set. This also affects switching
2030 * from DDSCL_NORMAL to DDSCL_EXCLUSIVE. */
2031 ddraw = create_ddraw();
2032 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2033 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2034 (LONG_PTR)test_proc, proc);
2035 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2036 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2037 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2038 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
2039 (LONG_PTR)test_proc, proc);
2040 ddraw_proc = proc;
2041 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2042 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2043 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2044 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2045 (LONG_PTR)test_proc, proc);
2046 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2047 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2048 proc = SetWindowLongPtrA(window, GWLP_WNDPROC, (LONG_PTR)DefWindowProcA);
2049 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
2050 (LONG_PTR)test_proc, proc);
2051 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2052 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2053 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2054 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#lx, got %#lx.\n",
2055 (LONG_PTR)DefWindowProcA, proc);
2056 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2057 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2058 proc = SetWindowLongPtrA(window, GWLP_WNDPROC, (LONG_PTR)ddraw_proc);
2059 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#lx, got %#lx.\n",
2060 (LONG_PTR)DefWindowProcA, proc);
2061 ref = IDirectDraw_Release(ddraw);
2062 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2063 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2064 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2065 (LONG_PTR)test_proc, proc);
2067 ddraw = create_ddraw();
2068 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2069 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2070 (LONG_PTR)test_proc, proc);
2071 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2072 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2073 proc = SetWindowLongPtrA(window, GWLP_WNDPROC, (LONG_PTR)DefWindowProcA);
2074 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
2075 (LONG_PTR)test_proc, proc);
2076 ref = IDirectDraw_Release(ddraw);
2077 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2078 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2079 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#lx, got %#lx.\n",
2080 (LONG_PTR)DefWindowProcA, proc);
2082 fix_wndproc(window, (LONG_PTR)test_proc);
2083 expect_messages = NULL;
2084 DestroyWindow(window);
2085 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL));
2088 static void test_window_style(void)
2090 LONG style, exstyle, tmp, expected_style;
2091 RECT fullscreen_rect, r;
2092 IDirectDraw *ddraw;
2093 HWND window;
2094 HRESULT hr;
2095 ULONG ref;
2096 BOOL ret;
2098 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
2099 0, 0, 100, 100, 0, 0, 0, 0);
2100 ddraw = create_ddraw();
2101 ok(!!ddraw, "Failed to create a ddraw object.\n");
2103 style = GetWindowLongA(window, GWL_STYLE);
2104 exstyle = GetWindowLongA(window, GWL_EXSTYLE);
2105 SetRect(&fullscreen_rect, 0, 0, registry_mode.dmPelsWidth, registry_mode.dmPelsHeight);
2107 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2108 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2110 tmp = GetWindowLongA(window, GWL_STYLE);
2111 todo_wine ok(tmp == style, "Expected window style %#x, got %#x.\n", style, tmp);
2112 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2113 todo_wine ok(tmp == exstyle, "Expected window extended style %#x, got %#x.\n", exstyle, tmp);
2115 GetWindowRect(window, &r);
2116 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2117 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2118 r.left, r.top, r.right, r.bottom);
2119 GetClientRect(window, &r);
2120 todo_wine ok(!EqualRect(&r, &fullscreen_rect), "Client rect and window rect are equal.\n");
2122 ret = SetForegroundWindow(GetDesktopWindow());
2123 ok(ret, "Failed to set foreground window.\n");
2125 tmp = GetWindowLongA(window, GWL_STYLE);
2126 todo_wine ok(tmp == style, "Expected window style %#x, got %#x.\n", style, tmp);
2127 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2128 todo_wine ok(tmp == exstyle, "Expected window extended style %#x, got %#x.\n", exstyle, tmp);
2130 ret = SetForegroundWindow(window);
2131 ok(ret, "Failed to set foreground window.\n");
2132 /* Windows 7 (but not Vista and XP) shows the window when it receives focus. Hide it again,
2133 * the next tests expect this. */
2134 ShowWindow(window, SW_HIDE);
2136 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2137 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2139 tmp = GetWindowLongA(window, GWL_STYLE);
2140 todo_wine ok(tmp == style, "Expected window style %#x, got %#x.\n", style, tmp);
2141 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2142 todo_wine ok(tmp == exstyle, "Expected window extended style %#x, got %#x.\n", exstyle, tmp);
2144 ShowWindow(window, SW_SHOW);
2145 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2146 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2148 tmp = GetWindowLongA(window, GWL_STYLE);
2149 expected_style = style | WS_VISIBLE;
2150 todo_wine ok(tmp == expected_style, "Expected window style %#x, got %#x.\n", expected_style, tmp);
2151 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2152 expected_style = exstyle | WS_EX_TOPMOST;
2153 todo_wine ok(tmp == expected_style, "Expected window extended style %#x, got %#x.\n", expected_style, tmp);
2155 ret = SetForegroundWindow(GetDesktopWindow());
2156 ok(ret, "Failed to set foreground window.\n");
2157 tmp = GetWindowLongA(window, GWL_STYLE);
2158 expected_style = style | WS_VISIBLE | WS_MINIMIZE;
2159 todo_wine ok(tmp == expected_style, "Expected window style %#x, got %#x.\n", expected_style, tmp);
2160 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2161 expected_style = exstyle | WS_EX_TOPMOST;
2162 todo_wine ok(tmp == expected_style, "Expected window extended style %#x, got %#x.\n", expected_style, tmp);
2164 ref = IDirectDraw_Release(ddraw);
2165 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2167 DestroyWindow(window);
2170 static void test_redundant_mode_set(void)
2172 DDSURFACEDESC surface_desc = {0};
2173 IDirectDraw *ddraw;
2174 HWND window;
2175 HRESULT hr;
2176 RECT r, s;
2177 ULONG ref;
2179 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
2180 0, 0, 100, 100, 0, 0, 0, 0);
2181 ddraw = create_ddraw();
2182 ok(!!ddraw, "Failed to create a ddraw object.\n");
2184 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2185 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2187 surface_desc.dwSize = sizeof(surface_desc);
2188 hr = IDirectDraw_GetDisplayMode(ddraw, &surface_desc);
2189 ok(SUCCEEDED(hr), "GetDipslayMode failed, hr %#x.\n", hr);
2191 hr = IDirectDraw_SetDisplayMode(ddraw, surface_desc.dwWidth, surface_desc.dwHeight,
2192 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount);
2193 ok(SUCCEEDED(hr), "SetDisplayMode failed, hr %#x.\n", hr);
2195 GetWindowRect(window, &r);
2196 r.right /= 2;
2197 r.bottom /= 2;
2198 SetWindowPos(window, HWND_TOP, r.left, r.top, r.right, r.bottom, 0);
2199 GetWindowRect(window, &s);
2200 ok(EqualRect(&r, &s), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2201 r.left, r.top, r.right, r.bottom,
2202 s.left, s.top, s.right, s.bottom);
2204 hr = IDirectDraw_SetDisplayMode(ddraw, surface_desc.dwWidth, surface_desc.dwHeight,
2205 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount);
2206 ok(SUCCEEDED(hr), "SetDisplayMode failed, hr %#x.\n", hr);
2208 GetWindowRect(window, &s);
2209 ok(EqualRect(&r, &s), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2210 r.left, r.top, r.right, r.bottom,
2211 s.left, s.top, s.right, s.bottom);
2213 ref = IDirectDraw_Release(ddraw);
2214 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2216 DestroyWindow(window);
2219 static SIZE screen_size;
2221 static LRESULT CALLBACK mode_set_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
2223 if (message == WM_SIZE)
2225 screen_size.cx = GetSystemMetrics(SM_CXSCREEN);
2226 screen_size.cy = GetSystemMetrics(SM_CYSCREEN);
2229 return test_proc(hwnd, message, wparam, lparam);
2232 struct test_coop_level_mode_set_enum_param
2234 DWORD ddraw_width, ddraw_height, user32_width, user32_height;
2237 static HRESULT CALLBACK test_coop_level_mode_set_enum_cb(DDSURFACEDESC *surface_desc, void *context)
2239 struct test_coop_level_mode_set_enum_param *param = context;
2241 if (U1(surface_desc->ddpfPixelFormat).dwRGBBitCount != registry_mode.dmBitsPerPel)
2242 return DDENUMRET_OK;
2243 if (surface_desc->dwWidth == registry_mode.dmPelsWidth
2244 && surface_desc->dwHeight == registry_mode.dmPelsHeight)
2245 return DDENUMRET_OK;
2247 if (!param->ddraw_width)
2249 param->ddraw_width = surface_desc->dwWidth;
2250 param->ddraw_height = surface_desc->dwHeight;
2251 return DDENUMRET_OK;
2253 if (surface_desc->dwWidth == param->ddraw_width && surface_desc->dwHeight == param->ddraw_height)
2254 return DDENUMRET_OK;
2256 param->user32_width = surface_desc->dwWidth;
2257 param->user32_height = surface_desc->dwHeight;
2258 return DDENUMRET_CANCEL;
2261 static void test_coop_level_mode_set(void)
2263 IDirectDrawSurface *primary;
2264 RECT registry_rect, ddraw_rect, user32_rect, r;
2265 IDirectDraw *ddraw;
2266 DDSURFACEDESC ddsd;
2267 WNDCLASSA wc = {0};
2268 HWND window;
2269 HRESULT hr;
2270 ULONG ref;
2271 MSG msg;
2272 struct test_coop_level_mode_set_enum_param param;
2273 DEVMODEW devmode;
2274 BOOL ret;
2275 LONG change_ret;
2277 static const struct message exclusive_messages[] =
2279 {WM_WINDOWPOSCHANGING, FALSE, 0},
2280 {WM_WINDOWPOSCHANGED, FALSE, 0},
2281 {WM_SIZE, FALSE, 0},
2282 {WM_DISPLAYCHANGE, FALSE, 0},
2283 {0, FALSE, 0},
2285 static const struct message exclusive_focus_loss_messages[] =
2287 {WM_ACTIVATE, TRUE, WA_INACTIVE},
2288 {WM_DISPLAYCHANGE, FALSE, 0},
2289 {WM_WINDOWPOSCHANGING, FALSE, 0},
2290 /* Like d3d8 and d3d9 ddraw seems to use SW_SHOWMINIMIZED instead of
2291 * SW_MINIMIZED, causing a recursive window activation that does not
2292 * produce the same result in Wine yet. Ignore the difference for now.
2293 * {WM_ACTIVATE, TRUE, 0x200000 | WA_ACTIVE}, */
2294 {WM_WINDOWPOSCHANGED, FALSE, 0},
2295 {WM_MOVE, FALSE, 0},
2296 {WM_SIZE, TRUE, SIZE_MINIMIZED},
2297 {WM_ACTIVATEAPP, TRUE, FALSE},
2298 {0, FALSE, 0},
2300 static const struct message exclusive_focus_restore_messages[] =
2302 {WM_WINDOWPOSCHANGING, FALSE, 0}, /* From the ShowWindow(SW_RESTORE). */
2303 {WM_WINDOWPOSCHANGING, FALSE, 0}, /* Generated by ddraw, matches d3d9 behavior. */
2304 {WM_WINDOWPOSCHANGED, FALSE, 0}, /* Matching previous message. */
2305 {WM_SIZE, FALSE, 0}, /* DefWindowProc. */
2306 {WM_DISPLAYCHANGE, FALSE, 0}, /* Ddraw restores mode. */
2307 /* Native redundantly sets the window size here. */
2308 {WM_ACTIVATEAPP, TRUE, TRUE}, /* End of ddraw's hooks. */
2309 {WM_WINDOWPOSCHANGED, FALSE, 0}, /* Matching the one from ShowWindow. */
2310 {WM_MOVE, FALSE, 0}, /* DefWindowProc. */
2311 {WM_SIZE, TRUE, SIZE_RESTORED}, /* DefWindowProc. */
2312 {0, FALSE, 0},
2314 static const struct message sc_restore_messages[] =
2316 {WM_SYSCOMMAND, TRUE, SC_RESTORE},
2317 {WM_WINDOWPOSCHANGING, FALSE, 0},
2318 {WM_WINDOWPOSCHANGED, FALSE, 0},
2319 {WM_SIZE, TRUE, SIZE_RESTORED},
2320 {0, FALSE, 0},
2322 static const struct message sc_minimize_messages[] =
2324 {WM_SYSCOMMAND, TRUE, SC_MINIMIZE},
2325 {WM_WINDOWPOSCHANGING, FALSE, 0},
2326 {WM_WINDOWPOSCHANGED, FALSE, 0},
2327 {WM_SIZE, TRUE, SIZE_MINIMIZED},
2328 {0, FALSE, 0},
2330 static const struct message sc_maximize_messages[] =
2332 {WM_SYSCOMMAND, TRUE, SC_MAXIMIZE},
2333 {WM_WINDOWPOSCHANGING, FALSE, 0},
2334 {WM_WINDOWPOSCHANGED, FALSE, 0},
2335 {WM_SIZE, TRUE, SIZE_MAXIMIZED},
2336 {0, FALSE, 0},
2339 static const struct message normal_messages[] =
2341 {WM_DISPLAYCHANGE, FALSE, 0},
2342 {0, FALSE, 0},
2345 ddraw = create_ddraw();
2346 ok(!!ddraw, "Failed to create a ddraw object.\n");
2348 memset(&param, 0, sizeof(param));
2349 hr = IDirectDraw_EnumDisplayModes(ddraw, 0, NULL, &param, test_coop_level_mode_set_enum_cb);
2350 ok(SUCCEEDED(hr), "Failed to enumerate display mode, hr %#x.\n", hr);
2351 ref = IDirectDraw_Release(ddraw);
2352 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2354 if (!param.user32_height)
2356 skip("Fewer than 3 different modes supported, skipping mode restore test.\n");
2357 return;
2360 SetRect(&registry_rect, 0, 0, registry_mode.dmPelsWidth, registry_mode.dmPelsHeight);
2361 SetRect(&ddraw_rect, 0, 0, param.ddraw_width, param.ddraw_height);
2362 SetRect(&user32_rect, 0, 0, param.user32_width, param.user32_height);
2364 memset(&devmode, 0, sizeof(devmode));
2365 devmode.dmSize = sizeof(devmode);
2366 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
2367 devmode.dmPelsWidth = param.user32_width;
2368 devmode.dmPelsHeight = param.user32_height;
2369 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
2370 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2372 ddraw = create_ddraw();
2373 ok(!!ddraw, "Failed to create a ddraw object.\n");
2375 wc.lpfnWndProc = mode_set_proc;
2376 wc.lpszClassName = "ddraw_test_wndproc_wc";
2377 ok(RegisterClassA(&wc), "Failed to register window class.\n");
2379 window = CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test", WS_OVERLAPPEDWINDOW,
2380 0, 0, 100, 100, 0, 0, 0, 0);
2382 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2383 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2385 GetWindowRect(window, &r);
2386 ok(EqualRect(&r, &user32_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2387 user32_rect.left, user32_rect.top, user32_rect.right, user32_rect.bottom,
2388 r.left, r.top, r.right, r.bottom);
2390 memset(&ddsd, 0, sizeof(ddsd));
2391 ddsd.dwSize = sizeof(ddsd);
2392 ddsd.dwFlags = DDSD_CAPS;
2393 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2395 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &primary, NULL);
2396 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2397 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2398 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2399 ok(ddsd.dwWidth == param.user32_width, "Expected surface width %u, got %u.\n",
2400 param.user32_width, ddsd.dwWidth);
2401 ok(ddsd.dwHeight == param.user32_height, "Expected surface height %u, got %u.\n",
2402 param.user32_height, ddsd.dwHeight);
2404 GetWindowRect(window, &r);
2405 ok(EqualRect(&r, &user32_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2406 user32_rect.left, user32_rect.top, user32_rect.right, user32_rect.bottom,
2407 r.left, r.top, r.right, r.bottom);
2409 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2410 expect_messages = exclusive_messages;
2411 screen_size.cx = 0;
2412 screen_size.cy = 0;
2414 hr = IDirectDrawSurface_IsLost(primary);
2415 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
2416 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
2417 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2418 hr = IDirectDrawSurface_IsLost(primary);
2419 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2421 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2422 expect_messages = NULL;
2423 ok(screen_size.cx == param.ddraw_width && screen_size.cy == param.ddraw_height,
2424 "Expected screen size %ux%u, got %ux%u.\n",
2425 param.ddraw_width, param.ddraw_height, screen_size.cx, screen_size.cy);
2427 GetWindowRect(window, &r);
2428 ok(EqualRect(&r, &ddraw_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2429 ddraw_rect.left, ddraw_rect.top, ddraw_rect.right, ddraw_rect.bottom,
2430 r.left, r.top, r.right, r.bottom);
2432 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2433 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2434 ok(ddsd.dwWidth == param.user32_width, "Expected surface width %u, got %u.\n",
2435 param.user32_width, ddsd.dwWidth);
2436 ok(ddsd.dwHeight == param.user32_height, "Expected surface height %u, got %u.\n",
2437 param.user32_height, ddsd.dwHeight);
2438 IDirectDrawSurface_Release(primary);
2440 memset(&ddsd, 0, sizeof(ddsd));
2441 ddsd.dwSize = sizeof(ddsd);
2442 ddsd.dwFlags = DDSD_CAPS;
2443 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2445 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &primary, NULL);
2446 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2447 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2448 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2449 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2450 param.ddraw_width, ddsd.dwWidth);
2451 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2452 param.ddraw_height, ddsd.dwHeight);
2454 GetWindowRect(window, &r);
2455 ok(EqualRect(&r, &ddraw_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2456 ddraw_rect.left, ddraw_rect.top, ddraw_rect.right, ddraw_rect.bottom,
2457 r.left, r.top, r.right, r.bottom);
2459 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2460 expect_messages = exclusive_messages;
2461 screen_size.cx = 0;
2462 screen_size.cy = 0;
2464 hr = IDirectDrawSurface_IsLost(primary);
2465 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
2466 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
2467 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2468 hr = IDirectDrawSurface_IsLost(primary);
2469 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2471 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2472 expect_messages = NULL;
2473 ok(screen_size.cx == param.user32_width && screen_size.cy == param.user32_height,
2474 "Expected screen size %ux%u, got %ux%u.\n",
2475 param.user32_width, param.user32_height, screen_size.cx, screen_size.cy);
2477 GetWindowRect(window, &r);
2478 ok(EqualRect(&r, &user32_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2479 user32_rect.left, user32_rect.top, user32_rect.right, user32_rect.bottom,
2480 r.left, r.top, r.right, r.bottom);
2482 expect_messages = exclusive_focus_loss_messages;
2483 ret = SetForegroundWindow(GetDesktopWindow());
2484 ok(ret, "Failed to set foreground window.\n");
2485 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2486 memset(&devmode, 0, sizeof(devmode));
2487 devmode.dmSize = sizeof(devmode);
2488 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
2489 ok(ret, "Failed to get display mode.\n");
2490 ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth
2491 && devmode.dmPelsHeight == registry_mode.dmPelsHeight, "Got unexpect screen size %ux%u.\n",
2492 devmode.dmPelsWidth, devmode.dmPelsHeight);
2494 expect_messages = exclusive_focus_restore_messages;
2495 ShowWindow(window, SW_RESTORE);
2496 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2498 GetWindowRect(window, &r);
2499 ok(EqualRect(&r, &ddraw_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2500 ddraw_rect.left, ddraw_rect.top, ddraw_rect.right, ddraw_rect.bottom,
2501 r.left, r.top, r.right, r.bottom);
2502 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
2503 ok(ret, "Failed to get display mode.\n");
2504 ok(devmode.dmPelsWidth == param.ddraw_width
2505 && devmode.dmPelsHeight == param.ddraw_height, "Got unexpect screen size %ux%u.\n",
2506 devmode.dmPelsWidth, devmode.dmPelsHeight);
2508 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2509 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2510 /* Normally the primary should be restored here. Unfortunately this causes the
2511 * GetSurfaceDesc call after the next display mode change to crash on the Windows 8
2512 * testbot. Another Restore call would presumably avoid the crash, but it also moots
2513 * the point of the GetSurfaceDesc call. */
2515 expect_messages = sc_minimize_messages;
2516 SendMessageA(window, WM_SYSCOMMAND, SC_MINIMIZE, 0);
2517 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2518 expect_messages = NULL;
2520 expect_messages = sc_restore_messages;
2521 SendMessageA(window, WM_SYSCOMMAND, SC_RESTORE, 0);
2522 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2523 expect_messages = NULL;
2525 expect_messages = sc_maximize_messages;
2526 SendMessageA(window, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
2527 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2528 expect_messages = NULL;
2530 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2531 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2533 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2534 expect_messages = exclusive_messages;
2535 screen_size.cx = 0;
2536 screen_size.cy = 0;
2538 hr = IDirectDrawSurface_IsLost(primary);
2539 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2540 hr = IDirectDraw_RestoreDisplayMode(ddraw);
2541 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
2542 hr = IDirectDrawSurface_IsLost(primary);
2543 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2545 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2546 expect_messages = NULL;
2547 ok(screen_size.cx == registry_mode.dmPelsWidth
2548 && screen_size.cy == registry_mode.dmPelsHeight,
2549 "Expected screen size %ux%u, got %ux%u.\n",
2550 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight, screen_size.cx, screen_size.cy);
2552 GetWindowRect(window, &r);
2553 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2554 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2555 r.left, r.top, r.right, r.bottom);
2557 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2558 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2559 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2560 param.ddraw_width, ddsd.dwWidth);
2561 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2562 param.ddraw_height, ddsd.dwHeight);
2563 IDirectDrawSurface_Release(primary);
2565 /* For Wine. */
2566 change_ret = ChangeDisplaySettingsW(NULL, CDS_FULLSCREEN);
2567 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2569 memset(&ddsd, 0, sizeof(ddsd));
2570 ddsd.dwSize = sizeof(ddsd);
2571 ddsd.dwFlags = DDSD_CAPS;
2572 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2574 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &primary, NULL);
2575 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2576 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2577 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2578 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2579 registry_mode.dmPelsWidth, ddsd.dwWidth);
2580 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2581 registry_mode.dmPelsHeight, ddsd.dwHeight);
2583 GetWindowRect(window, &r);
2584 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2585 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2586 r.left, r.top, r.right, r.bottom);
2588 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2589 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2591 GetWindowRect(window, &r);
2592 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2593 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2594 r.left, r.top, r.right, r.bottom);
2596 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2597 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2598 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2599 registry_mode.dmPelsWidth, ddsd.dwWidth);
2600 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2601 registry_mode.dmPelsHeight, ddsd.dwHeight);
2602 IDirectDrawSurface_Release(primary);
2604 memset(&ddsd, 0, sizeof(ddsd));
2605 ddsd.dwSize = sizeof(ddsd);
2606 ddsd.dwFlags = DDSD_CAPS;
2607 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2609 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &primary, NULL);
2610 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2611 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2612 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2613 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2614 registry_mode.dmPelsWidth, ddsd.dwWidth);
2615 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2616 registry_mode.dmPelsHeight, ddsd.dwHeight);
2618 GetWindowRect(window, &r);
2619 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2620 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2621 r.left, r.top, r.right, r.bottom);
2623 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2624 expect_messages = normal_messages;
2625 screen_size.cx = 0;
2626 screen_size.cy = 0;
2628 hr = IDirectDrawSurface_IsLost(primary);
2629 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
2630 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
2631 devmode.dmPelsWidth = param.user32_width;
2632 devmode.dmPelsHeight = param.user32_height;
2633 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
2634 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2635 hr = IDirectDrawSurface_IsLost(primary);
2636 todo_wine ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2638 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2639 expect_messages = NULL;
2640 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2642 GetWindowRect(window, &r);
2643 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2644 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2645 r.left, r.top, r.right, r.bottom);
2647 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2648 expect_messages = normal_messages;
2649 screen_size.cx = 0;
2650 screen_size.cy = 0;
2652 hr = IDirectDrawSurface_Restore(primary);
2653 todo_wine ok(hr == DDERR_WRONGMODE, "Got unexpected hr %#x.\n", hr);
2654 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
2655 if (hr == DDERR_NOEXCLUSIVEMODE /* NT4 testbot */)
2657 win_skip("Broken SetDisplayMode(), skipping remaining tests.\n");
2658 IDirectDrawSurface_Release(primary);
2659 IDirectDraw_Release(ddraw);
2660 goto done;
2662 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2663 hr = IDirectDrawSurface_Restore(primary);
2664 todo_wine ok(hr == DDERR_WRONGMODE, "Got unexpected hr %#x.\n", hr);
2665 hr = IDirectDrawSurface_IsLost(primary);
2666 todo_wine ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2668 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2669 expect_messages = NULL;
2670 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2672 GetWindowRect(window, &r);
2673 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2674 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2675 r.left, r.top, r.right, r.bottom);
2677 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2678 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2679 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2680 registry_mode.dmPelsWidth, ddsd.dwWidth);
2681 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2682 registry_mode.dmPelsHeight, ddsd.dwHeight);
2683 IDirectDrawSurface_Release(primary);
2685 memset(&ddsd, 0, sizeof(ddsd));
2686 ddsd.dwSize = sizeof(ddsd);
2687 ddsd.dwFlags = DDSD_CAPS;
2688 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2690 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &primary, NULL);
2691 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2692 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2693 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2694 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2695 param.ddraw_width, ddsd.dwWidth);
2696 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2697 param.ddraw_height, ddsd.dwHeight);
2699 GetWindowRect(window, &r);
2700 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2701 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2702 r.left, r.top, r.right, r.bottom);
2704 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2705 expect_messages = normal_messages;
2706 screen_size.cx = 0;
2707 screen_size.cy = 0;
2709 hr = IDirectDrawSurface_IsLost(primary);
2710 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
2711 hr = IDirectDraw_RestoreDisplayMode(ddraw);
2712 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
2713 hr = IDirectDrawSurface_IsLost(primary);
2714 todo_wine ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2716 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2717 expect_messages = NULL;
2718 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2720 GetWindowRect(window, &r);
2721 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2722 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2723 r.left, r.top, r.right, r.bottom);
2725 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2726 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2727 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2728 param.ddraw_width, ddsd.dwWidth);
2729 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2730 param.ddraw_height, ddsd.dwHeight);
2731 IDirectDrawSurface_Release(primary);
2733 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
2734 ok(ret, "Failed to get display mode.\n");
2735 ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth
2736 && devmode.dmPelsHeight == registry_mode.dmPelsHeight,
2737 "Expected resolution %ux%u, got %ux%u.\n",
2738 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight,
2739 devmode.dmPelsWidth, devmode.dmPelsHeight);
2740 change_ret = ChangeDisplaySettingsW(NULL, CDS_FULLSCREEN);
2741 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2743 memset(&ddsd, 0, sizeof(ddsd));
2744 ddsd.dwSize = sizeof(ddsd);
2745 ddsd.dwFlags = DDSD_CAPS;
2746 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2748 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &primary, NULL);
2749 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2750 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2751 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2752 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2753 registry_mode.dmPelsWidth, ddsd.dwWidth);
2754 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2755 registry_mode.dmPelsHeight, ddsd.dwHeight);
2757 GetWindowRect(window, &r);
2758 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2759 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2760 r.left, r.top, r.right, r.bottom);
2762 /* DDSCL_NORMAL | DDSCL_FULLSCREEN behaves the same as just DDSCL_NORMAL.
2763 * Resizing the window on mode changes is a property of DDSCL_EXCLUSIVE,
2764 * not DDSCL_FULLSCREEN. */
2765 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL | DDSCL_FULLSCREEN);
2766 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2768 GetWindowRect(window, &r);
2769 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2770 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2771 r.left, r.top, r.right, r.bottom);
2773 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2774 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2775 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2776 registry_mode.dmPelsWidth, ddsd.dwWidth);
2777 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2778 registry_mode.dmPelsHeight, ddsd.dwHeight);
2779 IDirectDrawSurface_Release(primary);
2781 memset(&ddsd, 0, sizeof(ddsd));
2782 ddsd.dwSize = sizeof(ddsd);
2783 ddsd.dwFlags = DDSD_CAPS;
2784 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2786 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &primary, NULL);
2787 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2788 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2789 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2790 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2791 registry_mode.dmPelsWidth, ddsd.dwWidth);
2792 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2793 registry_mode.dmPelsHeight, ddsd.dwHeight);
2795 GetWindowRect(window, &r);
2796 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2797 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2798 r.left, r.top, r.right, r.bottom);
2800 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2801 expect_messages = normal_messages;
2802 screen_size.cx = 0;
2803 screen_size.cy = 0;
2805 hr = IDirectDrawSurface_IsLost(primary);
2806 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
2807 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
2808 devmode.dmPelsWidth = param.user32_width;
2809 devmode.dmPelsHeight = param.user32_height;
2810 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
2811 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2812 hr = IDirectDrawSurface_IsLost(primary);
2813 todo_wine ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2815 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2816 expect_messages = NULL;
2817 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2819 GetWindowRect(window, &r);
2820 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2821 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2822 r.left, r.top, r.right, r.bottom);
2824 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2825 expect_messages = normal_messages;
2826 screen_size.cx = 0;
2827 screen_size.cy = 0;
2829 hr = IDirectDrawSurface_Restore(primary);
2830 todo_wine ok(hr == DDERR_WRONGMODE, "Got unexpected hr %#x.\n", hr);
2831 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
2832 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2833 hr = IDirectDrawSurface_Restore(primary);
2834 todo_wine ok(hr == DDERR_WRONGMODE, "Got unexpected hr %#x.\n", hr);
2835 hr = IDirectDrawSurface_IsLost(primary);
2836 todo_wine ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2838 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2839 expect_messages = NULL;
2840 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2842 GetWindowRect(window, &r);
2843 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2844 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2845 r.left, r.top, r.right, r.bottom);
2847 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2848 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2849 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2850 registry_mode.dmPelsWidth, ddsd.dwWidth);
2851 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2852 registry_mode.dmPelsHeight, ddsd.dwHeight);
2853 IDirectDrawSurface_Release(primary);
2855 memset(&ddsd, 0, sizeof(ddsd));
2856 ddsd.dwSize = sizeof(ddsd);
2857 ddsd.dwFlags = DDSD_CAPS;
2858 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2860 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &primary, NULL);
2861 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2862 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2863 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2864 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2865 param.ddraw_width, ddsd.dwWidth);
2866 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2867 param.ddraw_height, ddsd.dwHeight);
2869 GetWindowRect(window, &r);
2870 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2871 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2872 r.left, r.top, r.right, r.bottom);
2874 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2875 expect_messages = normal_messages;
2876 screen_size.cx = 0;
2877 screen_size.cy = 0;
2879 hr = IDirectDrawSurface_IsLost(primary);
2880 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
2881 hr = IDirectDraw_RestoreDisplayMode(ddraw);
2882 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
2883 hr = IDirectDrawSurface_IsLost(primary);
2884 todo_wine ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2886 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2887 expect_messages = NULL;
2888 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2890 GetWindowRect(window, &r);
2891 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2892 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2893 r.left, r.top, r.right, r.bottom);
2895 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2896 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2897 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2898 param.ddraw_width, ddsd.dwWidth);
2899 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2900 param.ddraw_height, ddsd.dwHeight);
2901 IDirectDrawSurface_Release(primary);
2903 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
2904 ok(ret, "Failed to get display mode.\n");
2905 ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth
2906 && devmode.dmPelsHeight == registry_mode.dmPelsHeight,
2907 "Expected resolution %ux%u, got %ux%u.\n",
2908 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight,
2909 devmode.dmPelsWidth, devmode.dmPelsHeight);
2910 change_ret = ChangeDisplaySettingsW(NULL, CDS_FULLSCREEN);
2911 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2913 memset(&ddsd, 0, sizeof(ddsd));
2914 ddsd.dwSize = sizeof(ddsd);
2915 ddsd.dwFlags = DDSD_CAPS;
2916 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2918 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &primary, NULL);
2919 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2920 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2921 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2922 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2923 registry_mode.dmPelsWidth, ddsd.dwWidth);
2924 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2925 registry_mode.dmPelsHeight, ddsd.dwHeight);
2926 IDirectDrawSurface_Release(primary);
2928 GetWindowRect(window, &r);
2929 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2930 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2931 r.left, r.top, r.right, r.bottom);
2933 /* Unlike ddraw2-7, changing from EXCLUSIVE to NORMAL does not restore the resolution */
2934 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2935 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2936 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
2937 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2939 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2940 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2942 memset(&ddsd, 0, sizeof(ddsd));
2943 ddsd.dwSize = sizeof(ddsd);
2944 ddsd.dwFlags = DDSD_CAPS;
2945 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2947 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &primary, NULL);
2948 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2949 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2950 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2951 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2952 param.ddraw_width, ddsd.dwWidth);
2953 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2954 param.ddraw_height, ddsd.dwHeight);
2955 IDirectDrawSurface_Release(primary);
2956 hr = IDirectDraw_RestoreDisplayMode(ddraw);
2957 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
2959 ref = IDirectDraw_Release(ddraw);
2960 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2962 GetWindowRect(window, &r);
2963 ok(EqualRect(&r, &ddraw_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2964 ddraw_rect.left, ddraw_rect.top, ddraw_rect.right, ddraw_rect.bottom,
2965 r.left, r.top, r.right, r.bottom);
2967 done:
2968 expect_messages = NULL;
2969 DestroyWindow(window);
2970 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL));
2973 static void test_coop_level_mode_set_multi(void)
2975 IDirectDraw *ddraw1, *ddraw2;
2976 UINT w, h;
2977 HWND window;
2978 HRESULT hr;
2979 ULONG ref;
2981 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
2982 0, 0, 100, 100, 0, 0, 0, 0);
2983 ddraw1 = create_ddraw();
2984 ok(!!ddraw1, "Failed to create a ddraw object.\n");
2986 /* With just a single ddraw object, the display mode is restored on
2987 * release. */
2988 hr = set_display_mode(ddraw1, 800, 600);
2989 if (hr == DDERR_NOEXCLUSIVEMODE /* NT4 testbot */)
2991 win_skip("Broken SetDisplayMode(), skipping test.\n");
2992 IDirectDraw_Release(ddraw1);
2993 DestroyWindow(window);
2994 return;
2996 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2997 w = GetSystemMetrics(SM_CXSCREEN);
2998 ok(w == 800, "Got unexpected screen width %u.\n", w);
2999 h = GetSystemMetrics(SM_CYSCREEN);
3000 ok(h == 600, "Got unexpected screen height %u.\n", h);
3002 ref = IDirectDraw_Release(ddraw1);
3003 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3004 w = GetSystemMetrics(SM_CXSCREEN);
3005 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3006 h = GetSystemMetrics(SM_CYSCREEN);
3007 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3009 /* When there are multiple ddraw objects, the display mode is restored to
3010 * the initial mode, before the first SetDisplayMode() call. */
3011 ddraw1 = create_ddraw();
3012 hr = set_display_mode(ddraw1, 800, 600);
3013 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3014 w = GetSystemMetrics(SM_CXSCREEN);
3015 ok(w == 800, "Got unexpected screen width %u.\n", w);
3016 h = GetSystemMetrics(SM_CYSCREEN);
3017 ok(h == 600, "Got unexpected screen height %u.\n", h);
3019 ddraw2 = create_ddraw();
3020 hr = set_display_mode(ddraw2, 640, 480);
3021 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3022 w = GetSystemMetrics(SM_CXSCREEN);
3023 ok(w == 640, "Got unexpected screen width %u.\n", w);
3024 h = GetSystemMetrics(SM_CYSCREEN);
3025 ok(h == 480, "Got unexpected screen height %u.\n", h);
3027 ref = IDirectDraw_Release(ddraw2);
3028 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3029 w = GetSystemMetrics(SM_CXSCREEN);
3030 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3031 h = GetSystemMetrics(SM_CYSCREEN);
3032 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3034 ref = IDirectDraw_Release(ddraw1);
3035 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3036 w = GetSystemMetrics(SM_CXSCREEN);
3037 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3038 h = GetSystemMetrics(SM_CYSCREEN);
3039 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3041 /* Regardless of release ordering. */
3042 ddraw1 = create_ddraw();
3043 hr = set_display_mode(ddraw1, 800, 600);
3044 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3045 w = GetSystemMetrics(SM_CXSCREEN);
3046 ok(w == 800, "Got unexpected screen width %u.\n", w);
3047 h = GetSystemMetrics(SM_CYSCREEN);
3048 ok(h == 600, "Got unexpected screen height %u.\n", h);
3050 ddraw2 = create_ddraw();
3051 hr = set_display_mode(ddraw2, 640, 480);
3052 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3053 w = GetSystemMetrics(SM_CXSCREEN);
3054 ok(w == 640, "Got unexpected screen width %u.\n", w);
3055 h = GetSystemMetrics(SM_CYSCREEN);
3056 ok(h == 480, "Got unexpected screen height %u.\n", h);
3058 ref = IDirectDraw_Release(ddraw1);
3059 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3060 w = GetSystemMetrics(SM_CXSCREEN);
3061 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3062 h = GetSystemMetrics(SM_CYSCREEN);
3063 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3065 ref = IDirectDraw_Release(ddraw2);
3066 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3067 w = GetSystemMetrics(SM_CXSCREEN);
3068 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3069 h = GetSystemMetrics(SM_CYSCREEN);
3070 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3072 /* But only for ddraw objects that called SetDisplayMode(). */
3073 ddraw1 = create_ddraw();
3074 ddraw2 = create_ddraw();
3075 hr = set_display_mode(ddraw2, 640, 480);
3076 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3077 w = GetSystemMetrics(SM_CXSCREEN);
3078 ok(w == 640, "Got unexpected screen width %u.\n", w);
3079 h = GetSystemMetrics(SM_CYSCREEN);
3080 ok(h == 480, "Got unexpected screen height %u.\n", h);
3082 ref = IDirectDraw_Release(ddraw1);
3083 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3084 w = GetSystemMetrics(SM_CXSCREEN);
3085 ok(w == 640, "Got unexpected screen width %u.\n", w);
3086 h = GetSystemMetrics(SM_CYSCREEN);
3087 ok(h == 480, "Got unexpected screen height %u.\n", h);
3089 ref = IDirectDraw_Release(ddraw2);
3090 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3091 w = GetSystemMetrics(SM_CXSCREEN);
3092 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3093 h = GetSystemMetrics(SM_CYSCREEN);
3094 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3096 /* If there's a ddraw object that's currently in exclusive mode, it blocks
3097 * restoring the display mode. */
3098 ddraw1 = create_ddraw();
3099 hr = set_display_mode(ddraw1, 800, 600);
3100 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3101 w = GetSystemMetrics(SM_CXSCREEN);
3102 ok(w == 800, "Got unexpected screen width %u.\n", w);
3103 h = GetSystemMetrics(SM_CYSCREEN);
3104 ok(h == 600, "Got unexpected screen height %u.\n", h);
3106 ddraw2 = create_ddraw();
3107 hr = set_display_mode(ddraw2, 640, 480);
3108 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3109 w = GetSystemMetrics(SM_CXSCREEN);
3110 ok(w == 640, "Got unexpected screen width %u.\n", w);
3111 h = GetSystemMetrics(SM_CYSCREEN);
3112 ok(h == 480, "Got unexpected screen height %u.\n", h);
3114 hr = IDirectDraw_SetCooperativeLevel(ddraw2, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3115 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3117 ref = IDirectDraw_Release(ddraw1);
3118 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3119 w = GetSystemMetrics(SM_CXSCREEN);
3120 ok(w == 640, "Got unexpected screen width %u.\n", w);
3121 h = GetSystemMetrics(SM_CYSCREEN);
3122 ok(h == 480, "Got unexpected screen height %u.\n", h);
3124 ref = IDirectDraw_Release(ddraw2);
3125 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3126 w = GetSystemMetrics(SM_CXSCREEN);
3127 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3128 h = GetSystemMetrics(SM_CYSCREEN);
3129 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3131 /* Exclusive mode blocks mode setting on other ddraw objects in general. */
3132 ddraw1 = create_ddraw();
3133 hr = set_display_mode(ddraw1, 800, 600);
3134 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3135 w = GetSystemMetrics(SM_CXSCREEN);
3136 ok(w == 800, "Got unexpected screen width %u.\n", w);
3137 h = GetSystemMetrics(SM_CYSCREEN);
3138 ok(h == 600, "Got unexpected screen height %u.\n", h);
3140 hr = IDirectDraw_SetCooperativeLevel(ddraw1, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3141 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3143 ddraw2 = create_ddraw();
3144 hr = set_display_mode(ddraw2, 640, 480);
3145 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
3147 ref = IDirectDraw_Release(ddraw1);
3148 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3149 w = GetSystemMetrics(SM_CXSCREEN);
3150 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3151 h = GetSystemMetrics(SM_CYSCREEN);
3152 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3154 ref = IDirectDraw_Release(ddraw2);
3155 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3156 w = GetSystemMetrics(SM_CXSCREEN);
3157 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3158 h = GetSystemMetrics(SM_CYSCREEN);
3159 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3161 DestroyWindow(window);
3164 static void test_initialize(void)
3166 IDirectDraw *ddraw;
3167 IDirect3D *d3d;
3168 HRESULT hr;
3170 ddraw = create_ddraw();
3171 ok(!!ddraw, "Failed to create a ddraw object.\n");
3173 hr = IDirectDraw_Initialize(ddraw, NULL);
3174 ok(hr == DDERR_ALREADYINITIALIZED, "Initialize returned hr %#x.\n", hr);
3175 IDirectDraw_Release(ddraw);
3177 CoInitialize(NULL);
3178 hr = CoCreateInstance(&CLSID_DirectDraw, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectDraw, (void **)&ddraw);
3179 ok(SUCCEEDED(hr), "Failed to create IDirectDraw instance, hr %#x.\n", hr);
3180 hr = IDirectDraw_QueryInterface(ddraw, &IID_IDirect3D, (void **)&d3d);
3181 if (SUCCEEDED(hr))
3183 /* IDirect3D_Initialize() just returns DDERR_ALREADYINITIALIZED. */
3184 hr = IDirect3D_Initialize(d3d, NULL);
3185 ok(hr == DDERR_ALREADYINITIALIZED, "Initialize returned hr %#x, expected DDERR_ALREADYINITIALIZED.\n", hr);
3186 IDirect3D_Release(d3d);
3188 else
3189 skip("D3D interface is not available, skipping test.\n");
3190 hr = IDirectDraw_Initialize(ddraw, NULL);
3191 ok(hr == DD_OK, "Initialize returned hr %#x, expected DD_OK.\n", hr);
3192 hr = IDirectDraw_Initialize(ddraw, NULL);
3193 ok(hr == DDERR_ALREADYINITIALIZED, "Initialize returned hr %#x, expected DDERR_ALREADYINITIALIZED.\n", hr);
3194 IDirectDraw_Release(ddraw);
3195 CoUninitialize();
3197 if (0) /* This crashes on the W2KPROSP4 testbot. */
3199 CoInitialize(NULL);
3200 hr = CoCreateInstance(&CLSID_DirectDraw, NULL, CLSCTX_INPROC_SERVER, &IID_IDirect3D, (void **)&d3d);
3201 ok(hr == E_NOINTERFACE, "CoCreateInstance returned hr %#x, expected E_NOINTERFACE.\n", hr);
3202 CoUninitialize();
3206 static void test_coop_level_surf_create(void)
3208 IDirectDrawSurface *surface;
3209 IDirectDraw *ddraw;
3210 DDSURFACEDESC ddsd;
3211 HRESULT hr;
3213 ddraw = create_ddraw();
3214 ok(!!ddraw, "Failed to create a ddraw object.\n");
3216 memset(&ddsd, 0, sizeof(ddsd));
3217 ddsd.dwSize = sizeof(ddsd);
3218 ddsd.dwFlags = DDSD_CAPS;
3219 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3220 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &surface, NULL);
3221 ok(hr == DDERR_NOCOOPERATIVELEVELSET, "Surface creation returned hr %#x.\n", hr);
3223 IDirectDraw_Release(ddraw);
3226 static void test_coop_level_multi_window(void)
3228 HWND window1, window2;
3229 IDirectDraw *ddraw;
3230 HRESULT hr;
3232 window1 = CreateWindowA("static", "ddraw_test1", WS_OVERLAPPEDWINDOW,
3233 0, 0, 640, 480, 0, 0, 0, 0);
3234 window2 = CreateWindowA("static", "ddraw_test2", WS_OVERLAPPEDWINDOW,
3235 0, 0, 640, 480, 0, 0, 0, 0);
3236 ddraw = create_ddraw();
3237 ok(!!ddraw, "Failed to create a ddraw object.\n");
3239 hr = IDirectDraw_SetCooperativeLevel(ddraw, window1, DDSCL_NORMAL);
3240 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3241 hr = IDirectDraw_SetCooperativeLevel(ddraw, window2, DDSCL_NORMAL);
3242 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3243 ok(IsWindow(window1), "Window 1 was destroyed.\n");
3244 ok(IsWindow(window2), "Window 2 was destroyed.\n");
3246 IDirectDraw_Release(ddraw);
3247 DestroyWindow(window2);
3248 DestroyWindow(window1);
3251 static void test_clear_rect_count(void)
3253 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
3254 IDirect3DMaterial *white, *red, *green, *blue;
3255 IDirect3DViewport *viewport;
3256 IDirect3DDevice *device;
3257 IDirectDrawSurface *rt;
3258 IDirectDraw *ddraw;
3259 D3DCOLOR color;
3260 HWND window;
3261 HRESULT hr;
3263 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
3264 0, 0, 640, 480, 0, 0, 0, 0);
3265 ddraw = create_ddraw();
3266 ok(!!ddraw, "Failed to create a ddraw object.\n");
3267 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
3269 skip("Failed to create a 3D device, skipping test.\n");
3270 IDirectDraw_Release(ddraw);
3271 DestroyWindow(window);
3272 return;
3275 hr = IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&rt);
3276 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
3278 white = create_diffuse_material(device, 1.0f, 1.0f, 1.0f, 1.0f);
3279 red = create_diffuse_material(device, 1.0f, 0.0f, 0.0f, 1.0f);
3280 green = create_diffuse_material(device, 0.0f, 1.0f, 0.0f, 1.0f);
3281 blue = create_diffuse_material(device, 0.0f, 0.0f, 1.0f, 1.0f);
3282 viewport = create_viewport(device, 0, 0, 640, 480);
3284 viewport_set_background(device, viewport, white);
3285 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
3286 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
3287 viewport_set_background(device, viewport, red);
3288 hr = IDirect3DViewport_Clear(viewport, 0, &clear_rect, D3DCLEAR_TARGET);
3289 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
3290 viewport_set_background(device, viewport, green);
3291 hr = IDirect3DViewport_Clear(viewport, 0, NULL, D3DCLEAR_TARGET);
3292 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
3293 viewport_set_background(device, viewport, blue);
3294 hr = IDirect3DViewport_Clear(viewport, 1, NULL, D3DCLEAR_TARGET);
3295 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
3297 color = get_surface_color(rt, 320, 240);
3298 ok(compare_color(color, 0x00ffffff, 1) || broken(compare_color(color, 0x000000ff, 1)),
3299 "Got unexpected color 0x%08x.\n", color);
3301 IDirectDrawSurface_Release(rt);
3302 destroy_viewport(device, viewport);
3303 destroy_material(white);
3304 destroy_material(red);
3305 destroy_material(green);
3306 destroy_material(blue);
3307 IDirect3DDevice_Release(device);
3308 IDirectDraw_Release(ddraw);
3309 DestroyWindow(window);
3312 static struct
3314 BOOL received;
3315 IDirectDraw *ddraw;
3316 HWND window;
3317 DWORD coop_level;
3318 } activateapp_testdata;
3320 static LRESULT CALLBACK activateapp_test_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
3322 if (message == WM_ACTIVATEAPP)
3324 if (activateapp_testdata.ddraw)
3326 HRESULT hr;
3327 activateapp_testdata.received = FALSE;
3328 hr = IDirectDraw_SetCooperativeLevel(activateapp_testdata.ddraw,
3329 activateapp_testdata.window, activateapp_testdata.coop_level);
3330 ok(SUCCEEDED(hr), "Recursive SetCooperativeLevel call failed, hr %#x.\n", hr);
3331 ok(!activateapp_testdata.received, "Received WM_ACTIVATEAPP during recursive SetCooperativeLevel call.\n");
3333 activateapp_testdata.received = TRUE;
3336 return DefWindowProcA(hwnd, message, wparam, lparam);
3339 static void test_coop_level_activateapp(void)
3341 IDirectDraw *ddraw;
3342 HRESULT hr;
3343 HWND window;
3344 WNDCLASSA wc = {0};
3345 DDSURFACEDESC ddsd;
3346 IDirectDrawSurface *surface;
3348 ddraw = create_ddraw();
3349 ok(!!ddraw, "Failed to create a ddraw object.\n");
3351 wc.lpfnWndProc = activateapp_test_proc;
3352 wc.lpszClassName = "ddraw_test_wndproc_wc";
3353 ok(RegisterClassA(&wc), "Failed to register window class.\n");
3355 window = CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
3356 WS_MAXIMIZE | WS_CAPTION , 0, 0, 640, 480, 0, 0, 0, 0);
3358 /* Exclusive with window already active. */
3359 SetForegroundWindow(window);
3360 activateapp_testdata.received = FALSE;
3361 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3362 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3363 ok(!activateapp_testdata.received, "Received WM_ACTIVATEAPP although window was already active.\n");
3364 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3365 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3367 /* Exclusive with window not active. */
3368 SetForegroundWindow(GetDesktopWindow());
3369 activateapp_testdata.received = FALSE;
3370 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3371 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3372 ok(activateapp_testdata.received, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3373 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3374 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3376 /* Normal with window not active, then exclusive with the same window. */
3377 SetForegroundWindow(GetDesktopWindow());
3378 activateapp_testdata.received = FALSE;
3379 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
3380 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3381 ok(!activateapp_testdata.received, "Received WM_ACTIVATEAPP when setting DDSCL_NORMAL.\n");
3382 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3383 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3384 ok(activateapp_testdata.received, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3385 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3386 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3388 /* Recursive set of DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN. */
3389 SetForegroundWindow(GetDesktopWindow());
3390 activateapp_testdata.received = FALSE;
3391 activateapp_testdata.ddraw = ddraw;
3392 activateapp_testdata.window = window;
3393 activateapp_testdata.coop_level = DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN;
3394 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3395 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3396 ok(activateapp_testdata.received, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3397 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3398 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3400 /* The recursive call seems to have some bad effect on native ddraw, despite (apparently)
3401 * succeeding. Another switch to exclusive and back to normal is needed to release the
3402 * window properly. Without doing this, SetCooperativeLevel(EXCLUSIVE) will not send
3403 * WM_ACTIVATEAPP messages. */
3404 activateapp_testdata.ddraw = NULL;
3405 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3406 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3407 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3408 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3410 /* Setting DDSCL_NORMAL with recursive invocation. */
3411 SetForegroundWindow(GetDesktopWindow());
3412 activateapp_testdata.received = FALSE;
3413 activateapp_testdata.ddraw = ddraw;
3414 activateapp_testdata.window = window;
3415 activateapp_testdata.coop_level = DDSCL_NORMAL;
3416 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3417 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3418 ok(activateapp_testdata.received, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3420 /* DDraw is in exlusive mode now. */
3421 memset(&ddsd, 0, sizeof(ddsd));
3422 ddsd.dwSize = sizeof(ddsd);
3423 ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
3424 ddsd.dwBackBufferCount = 1;
3425 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
3426 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &surface, NULL);
3427 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
3428 IDirectDrawSurface_Release(surface);
3430 /* Recover again, just to be sure. */
3431 activateapp_testdata.ddraw = NULL;
3432 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3433 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3434 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3435 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3437 DestroyWindow(window);
3438 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL));
3439 IDirectDraw_Release(ddraw);
3442 struct format_support_check
3444 const DDPIXELFORMAT *format;
3445 BOOL supported;
3448 static HRESULT WINAPI test_unsupported_formats_cb(DDSURFACEDESC *desc, void *ctx)
3450 struct format_support_check *format = ctx;
3452 if (!memcmp(format->format, &desc->ddpfPixelFormat, sizeof(*format->format)))
3454 format->supported = TRUE;
3455 return DDENUMRET_CANCEL;
3458 return DDENUMRET_OK;
3461 static void test_unsupported_formats(void)
3463 HRESULT hr;
3464 BOOL expect_success;
3465 HWND window;
3466 IDirectDraw *ddraw;
3467 IDirect3DDevice *device;
3468 IDirectDrawSurface *surface;
3469 DDSURFACEDESC ddsd;
3470 unsigned int i, j;
3471 DWORD expected_caps;
3472 static const struct
3474 const char *name;
3475 DDPIXELFORMAT fmt;
3477 formats[] =
3480 "D3DFMT_A8R8G8B8",
3482 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
3483 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
3487 "D3DFMT_P8",
3489 sizeof(DDPIXELFORMAT), DDPF_PALETTEINDEXED8 | DDPF_RGB, 0,
3490 {8 }, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}
3494 static const DWORD caps[] = {0, DDSCAPS_SYSTEMMEMORY, DDSCAPS_VIDEOMEMORY};
3496 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
3497 0, 0, 640, 480, 0, 0, 0, 0);
3498 ddraw = create_ddraw();
3499 ok(!!ddraw, "Failed to create a ddraw object.\n");
3500 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
3502 skip("Failed to create a 3D device, skipping test.\n");
3503 IDirectDraw_Release(ddraw);
3504 DestroyWindow(window);
3505 return;
3508 for (i = 0; i < sizeof(formats) / sizeof(*formats); i++)
3510 struct format_support_check check = {&formats[i].fmt, FALSE};
3511 hr = IDirect3DDevice_EnumTextureFormats(device, test_unsupported_formats_cb, &check);
3512 ok(SUCCEEDED(hr), "Failed to enumerate texture formats %#x.\n", hr);
3514 for (j = 0; j < sizeof(caps) / sizeof(*caps); j++)
3516 memset(&ddsd, 0, sizeof(ddsd));
3517 ddsd.dwSize = sizeof(ddsd);
3518 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
3519 ddsd.ddpfPixelFormat = formats[i].fmt;
3520 ddsd.dwWidth = 4;
3521 ddsd.dwHeight = 4;
3522 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | caps[j];
3524 if (caps[j] & DDSCAPS_VIDEOMEMORY && !check.supported)
3525 expect_success = FALSE;
3526 else
3527 expect_success = TRUE;
3529 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &surface, NULL);
3530 ok(SUCCEEDED(hr) == expect_success,
3531 "Got unexpected hr %#x for format %s, caps %#x, expected %s.\n",
3532 hr, formats[i].name, caps[j], expect_success ? "success" : "failure");
3533 if (FAILED(hr))
3534 continue;
3536 memset(&ddsd, 0, sizeof(ddsd));
3537 ddsd.dwSize = sizeof(ddsd);
3538 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &ddsd);
3539 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
3541 if (caps[j] & DDSCAPS_VIDEOMEMORY)
3542 expected_caps = DDSCAPS_VIDEOMEMORY;
3543 else if (caps[j] & DDSCAPS_SYSTEMMEMORY)
3544 expected_caps = DDSCAPS_SYSTEMMEMORY;
3545 else if (check.supported)
3546 expected_caps = DDSCAPS_VIDEOMEMORY;
3547 else
3548 expected_caps = DDSCAPS_SYSTEMMEMORY;
3550 ok(ddsd.ddsCaps.dwCaps & expected_caps,
3551 "Expected capability %#x, format %s, input cap %#x.\n",
3552 expected_caps, formats[i].name, caps[j]);
3554 IDirectDrawSurface_Release(surface);
3558 IDirect3DDevice_Release(device);
3559 IDirectDraw_Release(ddraw);
3560 DestroyWindow(window);
3563 static void test_rt_caps(void)
3565 PALETTEENTRY palette_entries[256];
3566 IDirectDrawPalette *palette;
3567 IDirect3DDevice *device;
3568 IDirectDraw *ddraw;
3569 DWORD z_depth = 0;
3570 unsigned int i;
3571 ULONG refcount;
3572 HWND window;
3573 HRESULT hr;
3575 static const DDPIXELFORMAT p8_fmt =
3577 sizeof(DDPIXELFORMAT), DDPF_PALETTEINDEXED8 | DDPF_RGB, 0,
3578 {8}, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000},
3581 static const struct
3583 const DDPIXELFORMAT *pf;
3584 DWORD caps_in;
3585 DWORD caps_out;
3586 HRESULT create_device_hr;
3587 BOOL create_may_fail;
3589 test_data[] =
3592 NULL,
3593 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY,
3594 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
3595 D3D_OK,
3596 FALSE,
3599 NULL,
3600 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE,
3601 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
3602 D3D_OK,
3603 FALSE,
3606 NULL,
3607 DDSCAPS_OFFSCREENPLAIN,
3608 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
3609 DDERR_INVALIDCAPS,
3610 FALSE,
3613 NULL,
3614 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
3615 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
3616 D3DERR_SURFACENOTINVIDMEM,
3617 FALSE,
3620 NULL,
3621 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
3622 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
3623 DDERR_INVALIDCAPS,
3624 FALSE,
3627 NULL,
3628 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY,
3629 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
3630 D3D_OK,
3631 FALSE,
3634 NULL,
3635 DDSCAPS_3DDEVICE,
3636 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
3637 D3D_OK,
3638 FALSE,
3641 NULL,
3643 DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
3644 DDERR_INVALIDCAPS,
3645 FALSE,
3648 NULL,
3649 DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
3650 DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
3651 D3DERR_SURFACENOTINVIDMEM,
3652 FALSE,
3655 NULL,
3656 DDSCAPS_SYSTEMMEMORY,
3657 DDSCAPS_SYSTEMMEMORY,
3658 DDERR_INVALIDCAPS,
3659 FALSE,
3662 &p8_fmt,
3664 DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
3665 DDERR_INVALIDCAPS,
3666 FALSE,
3669 &p8_fmt,
3670 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE,
3671 ~0U /* AMD r200 */ ,
3672 DDERR_NOPALETTEATTACHED,
3673 FALSE,
3676 &p8_fmt,
3677 DDSCAPS_OFFSCREENPLAIN,
3678 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
3679 DDERR_INVALIDCAPS,
3680 FALSE,
3683 &p8_fmt,
3684 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
3685 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
3686 DDERR_NOPALETTEATTACHED,
3687 FALSE,
3690 &p8_fmt,
3691 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
3692 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
3693 DDERR_INVALIDCAPS,
3694 FALSE,
3697 NULL,
3698 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_ZBUFFER,
3699 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_ZBUFFER | DDSCAPS_LOCALVIDMEM,
3700 DDERR_INVALIDCAPS,
3701 TRUE /* AMD Evergreen */,
3704 NULL,
3705 DDSCAPS_3DDEVICE | DDSCAPS_ZBUFFER,
3706 ~0U /* AMD Evergreen */,
3707 DDERR_INVALIDCAPS,
3708 FALSE,
3711 NULL,
3712 DDSCAPS_ZBUFFER,
3713 ~0U /* AMD Evergreen */,
3714 DDERR_INVALIDCAPS,
3715 FALSE,
3718 NULL,
3719 DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE | DDSCAPS_ZBUFFER,
3720 DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE | DDSCAPS_ZBUFFER,
3721 DDERR_INVALIDCAPS,
3722 TRUE /* Nvidia Kepler */,
3725 NULL,
3726 DDSCAPS_SYSTEMMEMORY | DDSCAPS_ZBUFFER,
3727 DDSCAPS_SYSTEMMEMORY | DDSCAPS_ZBUFFER,
3728 DDERR_INVALIDCAPS,
3729 TRUE /* Nvidia Kepler */,
3733 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
3734 0, 0, 640, 480, 0, 0, 0, 0);
3735 ddraw = create_ddraw();
3736 ok(!!ddraw, "Failed to create a ddraw object.\n");
3737 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
3739 skip("Failed to create a 3D device, skipping test.\n");
3740 IDirectDraw_Release(ddraw);
3741 DestroyWindow(window);
3742 return;
3744 z_depth = get_device_z_depth(device);
3745 ok(!!z_depth, "Failed to get device z depth.\n");
3746 IDirect3DDevice_Release(device);
3748 memset(palette_entries, 0, sizeof(palette_entries));
3749 hr = IDirectDraw_CreatePalette(ddraw, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, palette_entries, &palette, NULL);
3750 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
3752 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
3754 IDirectDrawSurface *surface;
3755 DDSURFACEDESC surface_desc;
3756 IDirect3DDevice *device;
3758 memset(&surface_desc, 0, sizeof(surface_desc));
3759 surface_desc.dwSize = sizeof(surface_desc);
3760 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
3761 surface_desc.ddsCaps.dwCaps = test_data[i].caps_in;
3762 if (test_data[i].pf)
3764 surface_desc.dwFlags |= DDSD_PIXELFORMAT;
3765 surface_desc.ddpfPixelFormat = *test_data[i].pf;
3767 if (test_data[i].caps_in & DDSCAPS_ZBUFFER)
3769 surface_desc.dwFlags |= DDSD_ZBUFFERBITDEPTH;
3770 U2(surface_desc).dwZBufferBitDepth = z_depth;
3772 surface_desc.dwWidth = 640;
3773 surface_desc.dwHeight = 480;
3774 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
3775 ok(SUCCEEDED(hr) || broken(test_data[i].create_may_fail),
3776 "Test %u: Failed to create surface with caps %#x, hr %#x.\n",
3777 i, test_data[i].caps_in, hr);
3778 if (FAILED(hr))
3779 continue;
3781 memset(&surface_desc, 0, sizeof(surface_desc));
3782 surface_desc.dwSize = sizeof(surface_desc);
3783 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
3784 ok(SUCCEEDED(hr), "Test %u: Failed to get surface desc, hr %#x.\n", i, hr);
3785 ok(test_data[i].caps_out == ~0U || surface_desc.ddsCaps.dwCaps == test_data[i].caps_out,
3786 "Test %u: Got unexpected caps %#x, expected %#x.\n",
3787 i, surface_desc.ddsCaps.dwCaps, test_data[i].caps_out);
3789 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirect3DHALDevice, (void **)&device);
3790 ok(hr == test_data[i].create_device_hr, "Test %u: Got unexpected hr %#x, expected %#x.\n",
3791 i, hr, test_data[i].create_device_hr);
3792 if (hr == DDERR_NOPALETTEATTACHED)
3794 hr = IDirectDrawSurface_SetPalette(surface, palette);
3795 ok(SUCCEEDED(hr), "Test %u: Failed to set palette, hr %#x.\n", i, hr);
3796 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirect3DHALDevice, (void **)&device);
3797 if (surface_desc.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY)
3798 ok(hr == DDERR_INVALIDPIXELFORMAT, "Test %u: Got unexpected hr %#x.\n", i, hr);
3799 else
3800 ok(hr == D3DERR_SURFACENOTINVIDMEM, "Test %u: Got unexpected hr %#x.\n", i, hr);
3802 if (SUCCEEDED(hr))
3804 refcount = IDirect3DDevice_Release(device);
3805 ok(refcount == 1, "Test %u: Got unexpected refcount %u.\n", i, refcount);
3808 refcount = IDirectDrawSurface_Release(surface);
3809 ok(refcount == 0, "Test %u: The surface was not properly freed, refcount %u.\n", i, refcount);
3812 IDirectDrawPalette_Release(palette);
3813 refcount = IDirectDraw_Release(ddraw);
3814 ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount);
3815 DestroyWindow(window);
3818 static void test_primary_caps(void)
3820 const DWORD placement = DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY | DDSCAPS_SYSTEMMEMORY;
3821 IDirectDrawSurface *surface;
3822 DDSURFACEDESC surface_desc;
3823 IDirectDraw *ddraw;
3824 unsigned int i;
3825 ULONG refcount;
3826 HWND window;
3827 HRESULT hr;
3829 static const struct
3831 DWORD coop_level;
3832 DWORD caps_in;
3833 DWORD back_buffer_count;
3834 HRESULT hr;
3835 DWORD caps_out;
3837 test_data[] =
3840 DDSCL_NORMAL,
3841 DDSCAPS_PRIMARYSURFACE,
3842 ~0u,
3843 DD_OK,
3844 DDSCAPS_VISIBLE | DDSCAPS_PRIMARYSURFACE,
3847 DDSCL_NORMAL,
3848 DDSCAPS_PRIMARYSURFACE | DDSCAPS_TEXTURE,
3849 ~0u,
3850 DDERR_INVALIDCAPS,
3851 ~0u,
3854 DDSCL_NORMAL,
3855 DDSCAPS_PRIMARYSURFACE | DDSCAPS_FRONTBUFFER,
3856 ~0u,
3857 DD_OK,
3858 DDSCAPS_VISIBLE | DDSCAPS_PRIMARYSURFACE | DDSCAPS_FRONTBUFFER,
3861 DDSCL_NORMAL,
3862 DDSCAPS_PRIMARYSURFACE | DDSCAPS_BACKBUFFER,
3863 ~0u,
3864 DDERR_INVALIDCAPS,
3865 ~0u,
3868 DDSCL_NORMAL,
3869 DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP,
3870 ~0u,
3871 DDERR_INVALIDCAPS,
3872 ~0u,
3875 DDSCL_NORMAL,
3876 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX,
3877 ~0u,
3878 DDERR_INVALIDCAPS,
3879 ~0u,
3882 DDSCL_NORMAL,
3883 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
3884 ~0u,
3885 DDERR_INVALIDCAPS,
3886 ~0u,
3889 DDSCL_NORMAL,
3890 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
3892 DDERR_INVALIDCAPS,
3893 ~0u,
3896 DDSCL_NORMAL,
3897 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
3899 DDERR_NOEXCLUSIVEMODE,
3900 ~0u,
3903 DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN,
3904 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
3906 DDERR_INVALIDCAPS,
3907 ~0u,
3910 DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN,
3911 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
3913 DD_OK,
3914 DDSCAPS_VISIBLE | DDSCAPS_PRIMARYSURFACE | DDSCAPS_FRONTBUFFER | DDSCAPS_FLIP | DDSCAPS_COMPLEX,
3917 DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN,
3918 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP | DDSCAPS_FRONTBUFFER,
3920 DDERR_INVALIDCAPS,
3921 ~0u,
3924 DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN,
3925 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP | DDSCAPS_BACKBUFFER,
3927 DDERR_INVALIDCAPS,
3928 ~0u,
3932 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
3933 0, 0, 640, 480, 0, 0, 0, 0);
3934 ddraw = create_ddraw();
3935 ok(!!ddraw, "Failed to create a ddraw object.\n");
3937 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
3939 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, test_data[i].coop_level);
3940 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3942 memset(&surface_desc, 0, sizeof(surface_desc));
3943 surface_desc.dwSize = sizeof(surface_desc);
3944 surface_desc.dwFlags = DDSD_CAPS;
3945 if (test_data[i].back_buffer_count != ~0u)
3946 surface_desc.dwFlags |= DDSD_BACKBUFFERCOUNT;
3947 surface_desc.ddsCaps.dwCaps = test_data[i].caps_in;
3948 surface_desc.dwBackBufferCount = test_data[i].back_buffer_count;
3949 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
3950 ok(hr == test_data[i].hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, test_data[i].hr);
3951 if (FAILED(hr))
3952 continue;
3954 memset(&surface_desc, 0, sizeof(surface_desc));
3955 surface_desc.dwSize = sizeof(surface_desc);
3956 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
3957 ok(SUCCEEDED(hr), "Test %u: Failed to get surface desc, hr %#x.\n", i, hr);
3958 ok((surface_desc.ddsCaps.dwCaps & ~placement) == test_data[i].caps_out,
3959 "Test %u: Got unexpected caps %#x, expected %#x.\n",
3960 i, surface_desc.ddsCaps.dwCaps, test_data[i].caps_out);
3962 IDirectDrawSurface_Release(surface);
3965 refcount = IDirectDraw_Release(ddraw);
3966 ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount);
3967 DestroyWindow(window);
3970 static void test_surface_lock(void)
3972 IDirectDraw *ddraw;
3973 IDirectDrawSurface *surface;
3974 IDirect3DDevice *device;
3975 HRESULT hr;
3976 HWND window;
3977 unsigned int i;
3978 DDSURFACEDESC ddsd;
3979 ULONG refcount;
3980 DWORD z_depth = 0;
3981 static const struct
3983 DWORD caps;
3984 const char *name;
3986 tests[] =
3989 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY,
3990 "videomemory offscreenplain"
3993 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
3994 "systemmemory offscreenplain"
3997 DDSCAPS_PRIMARYSURFACE,
3998 "primary"
4001 DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY,
4002 "videomemory texture"
4005 DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY,
4006 "systemmemory texture"
4009 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE,
4010 "render target"
4013 DDSCAPS_ZBUFFER,
4014 "Z buffer"
4018 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
4019 0, 0, 640, 480, 0, 0, 0, 0);
4020 ddraw = create_ddraw();
4021 ok(!!ddraw, "Failed to create a ddraw object.\n");
4022 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
4024 skip("Failed to create a 3D device, skipping test.\n");
4025 IDirectDraw_Release(ddraw);
4026 DestroyWindow(window);
4027 return;
4029 z_depth = get_device_z_depth(device);
4030 ok(!!z_depth, "Failed to get device z depth.\n");
4031 IDirect3DDevice_Release(device);
4033 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
4035 memset(&ddsd, 0, sizeof(ddsd));
4036 ddsd.dwSize = sizeof(ddsd);
4037 ddsd.dwFlags = DDSD_CAPS;
4038 if (!(tests[i].caps & DDSCAPS_PRIMARYSURFACE))
4040 ddsd.dwFlags |= DDSD_WIDTH | DDSD_HEIGHT;
4041 ddsd.dwWidth = 64;
4042 ddsd.dwHeight = 64;
4044 if (tests[i].caps & DDSCAPS_ZBUFFER)
4046 ddsd.dwFlags |= DDSD_ZBUFFERBITDEPTH;
4047 U2(ddsd).dwZBufferBitDepth = z_depth;
4049 ddsd.ddsCaps.dwCaps = tests[i].caps;
4051 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &surface, NULL);
4052 ok(SUCCEEDED(hr), "Failed to create surface, type %s, hr %#x.\n", tests[i].name, hr);
4054 memset(&ddsd, 0, sizeof(ddsd));
4055 ddsd.dwSize = sizeof(ddsd);
4056 hr = IDirectDrawSurface_Lock(surface, NULL, &ddsd, DDLOCK_WAIT, NULL);
4057 ok(SUCCEEDED(hr), "Failed to lock surface, type %s, hr %#x.\n", tests[i].name, hr);
4058 if (SUCCEEDED(hr))
4060 hr = IDirectDrawSurface_Unlock(surface, NULL);
4061 ok(SUCCEEDED(hr), "Failed to unlock surface, type %s, hr %#x.\n", tests[i].name, hr);
4064 IDirectDrawSurface_Release(surface);
4067 refcount = IDirectDraw_Release(ddraw);
4068 ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount);
4069 DestroyWindow(window);
4072 static void test_surface_discard(void)
4074 IDirectDraw *ddraw;
4075 IDirect3DDevice *device;
4076 HRESULT hr;
4077 HWND window;
4078 DDSURFACEDESC ddsd;
4079 IDirectDrawSurface *surface, *target;
4080 void *addr;
4081 static const struct
4083 DWORD caps;
4084 BOOL discard;
4086 tests[] =
4088 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, TRUE},
4089 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY, FALSE},
4090 {DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, TRUE},
4091 {DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, FALSE},
4093 unsigned int i;
4095 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
4096 0, 0, 640, 480, 0, 0, 0, 0);
4097 ddraw = create_ddraw();
4098 ok(!!ddraw, "Failed to create a ddraw object.\n");
4099 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
4101 skip("Failed to create a 3D device, skipping test.\n");
4102 IDirectDraw_Release(ddraw);
4103 DestroyWindow(window);
4104 return;
4107 hr = IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&target);
4108 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
4110 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
4112 BOOL discarded;
4114 memset(&ddsd, 0, sizeof(ddsd));
4115 ddsd.dwSize = sizeof(ddsd);
4116 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4117 ddsd.ddsCaps.dwCaps = tests[i].caps;
4118 ddsd.dwWidth = 64;
4119 ddsd.dwHeight = 64;
4120 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &surface, NULL);
4121 if (FAILED(hr))
4123 skip("Failed to create surface, skipping.\n");
4124 continue;
4127 memset(&ddsd, 0, sizeof(ddsd));
4128 ddsd.dwSize = sizeof(ddsd);
4129 hr = IDirectDrawSurface_Lock(surface, NULL, &ddsd, DDLOCK_WAIT, NULL);
4130 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
4131 addr = ddsd.lpSurface;
4132 hr = IDirectDrawSurface_Unlock(surface, NULL);
4133 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
4135 memset(&ddsd, 0, sizeof(ddsd));
4136 ddsd.dwSize = sizeof(ddsd);
4137 hr = IDirectDrawSurface_Lock(surface, NULL, &ddsd, DDLOCK_DISCARDCONTENTS | DDLOCK_WAIT, NULL);
4138 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
4139 discarded = ddsd.lpSurface != addr;
4140 hr = IDirectDrawSurface_Unlock(surface, NULL);
4141 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
4143 hr = IDirectDrawSurface_Blt(target, NULL, surface, NULL, DDBLT_WAIT, NULL);
4144 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
4146 memset(&ddsd, 0, sizeof(ddsd));
4147 ddsd.dwSize = sizeof(ddsd);
4148 hr = IDirectDrawSurface_Lock(surface, NULL, &ddsd, DDLOCK_DISCARDCONTENTS | DDLOCK_WAIT, NULL);
4149 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
4150 discarded |= ddsd.lpSurface != addr;
4151 hr = IDirectDrawSurface_Unlock(surface, NULL);
4152 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
4154 IDirectDrawSurface_Release(surface);
4156 /* Windows 7 reliably changes the address of surfaces that are discardable (Nvidia Kepler,
4157 * AMD r500, evergreen). Windows XP, at least on AMD r200, never changes the pointer. */
4158 ok(!discarded || tests[i].discard, "Expected surface not to be discarded, case %u\n", i);
4161 IDirectDrawSurface_Release(target);
4162 IDirect3DDevice_Release(device);
4163 IDirectDraw_Release(ddraw);
4164 DestroyWindow(window);
4167 static void test_flip(void)
4169 const DWORD placement = DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY | DDSCAPS_SYSTEMMEMORY;
4170 IDirectDrawSurface *frontbuffer, *backbuffer1, *backbuffer2, *backbuffer3, *surface;
4171 DDSCAPS caps = {DDSCAPS_FLIP};
4172 DDSURFACEDESC surface_desc;
4173 BOOL sysmem_primary;
4174 IDirectDraw *ddraw;
4175 DWORD expected_caps;
4176 unsigned int i;
4177 D3DCOLOR color;
4178 ULONG refcount;
4179 HWND window;
4180 DDBLTFX fx;
4181 HRESULT hr;
4183 static const struct
4185 const char *name;
4186 DWORD caps;
4188 test_data[] =
4190 {"PRIMARYSURFACE", DDSCAPS_PRIMARYSURFACE},
4191 {"OFFSCREENPLAIN", DDSCAPS_OFFSCREENPLAIN},
4192 {"TEXTURE", DDSCAPS_TEXTURE},
4195 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
4196 0, 0, 640, 480, 0, 0, 0, 0);
4197 ddraw = create_ddraw();
4198 ok(!!ddraw, "Failed to create a ddraw object.\n");
4200 hr = set_display_mode(ddraw, 640, 480);
4201 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
4202 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
4203 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4205 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
4207 memset(&surface_desc, 0, sizeof(surface_desc));
4208 surface_desc.dwSize = sizeof(surface_desc);
4209 surface_desc.dwFlags = DDSD_CAPS;
4210 if (!(test_data[i].caps & DDSCAPS_PRIMARYSURFACE))
4211 surface_desc.dwFlags |= DDSD_WIDTH | DDSD_HEIGHT;
4212 surface_desc.ddsCaps.dwCaps = DDSCAPS_COMPLEX | DDSCAPS_FLIP | test_data[i].caps;
4213 surface_desc.dwWidth = 512;
4214 surface_desc.dwHeight = 512;
4215 surface_desc.dwBackBufferCount = 3;
4216 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &frontbuffer, NULL);
4217 ok(hr == DDERR_INVALIDCAPS, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
4219 surface_desc.ddsCaps.dwCaps &= ~DDSCAPS_FLIP;
4220 surface_desc.dwFlags |= DDSD_BACKBUFFERCOUNT;
4221 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &frontbuffer, NULL);
4222 ok(hr == DDERR_INVALIDCAPS, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
4224 surface_desc.ddsCaps.dwCaps &= ~DDSCAPS_COMPLEX;
4225 surface_desc.ddsCaps.dwCaps |= DDSCAPS_FLIP;
4226 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &frontbuffer, NULL);
4227 ok(hr == DDERR_INVALIDCAPS, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
4229 surface_desc.ddsCaps.dwCaps |= DDSCAPS_COMPLEX;
4230 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &frontbuffer, NULL);
4231 todo_wine_if(test_data[i].caps & DDSCAPS_TEXTURE)
4232 ok(SUCCEEDED(hr), "%s: Failed to create surface, hr %#x.\n", test_data[i].name, hr);
4233 if (FAILED(hr))
4234 continue;
4236 memset(&surface_desc, 0, sizeof(surface_desc));
4237 surface_desc.dwSize = sizeof(surface_desc);
4238 hr = IDirectDrawSurface_GetSurfaceDesc(frontbuffer, &surface_desc);
4239 ok(SUCCEEDED(hr), "%s: Failed to get surface desc, hr %#x.\n", test_data[i].name, hr);
4240 expected_caps = DDSCAPS_FRONTBUFFER | DDSCAPS_COMPLEX | DDSCAPS_FLIP | test_data[i].caps;
4241 if (test_data[i].caps & DDSCAPS_PRIMARYSURFACE)
4242 expected_caps |= DDSCAPS_VISIBLE;
4243 ok((surface_desc.ddsCaps.dwCaps & ~placement) == expected_caps,
4244 "%s: Got unexpected caps %#x.\n", test_data[i].name, surface_desc.ddsCaps.dwCaps);
4245 sysmem_primary = surface_desc.ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY;
4247 hr = IDirectDrawSurface_GetAttachedSurface(frontbuffer, &caps, &backbuffer1);
4248 ok(SUCCEEDED(hr), "%s: Failed to get attached surface, hr %#x.\n", test_data[i].name, hr);
4249 memset(&surface_desc, 0, sizeof(surface_desc));
4250 surface_desc.dwSize = sizeof(surface_desc);
4251 hr = IDirectDrawSurface_GetSurfaceDesc(backbuffer1, &surface_desc);
4252 ok(SUCCEEDED(hr), "%s: Failed to get surface desc, hr %#x.\n", test_data[i].name, hr);
4253 ok(!surface_desc.dwBackBufferCount, "%s: Got unexpected back buffer count %u.\n",
4254 test_data[i].name, surface_desc.dwBackBufferCount);
4255 expected_caps &= ~(DDSCAPS_VISIBLE | DDSCAPS_PRIMARYSURFACE | DDSCAPS_FRONTBUFFER);
4256 expected_caps |= DDSCAPS_BACKBUFFER;
4257 ok((surface_desc.ddsCaps.dwCaps & ~placement) == expected_caps,
4258 "%s: Got unexpected caps %#x.\n", test_data[i].name, surface_desc.ddsCaps.dwCaps);
4260 hr = IDirectDrawSurface_GetAttachedSurface(backbuffer1, &caps, &backbuffer2);
4261 ok(SUCCEEDED(hr), "%s: Failed to get attached surface, hr %#x.\n", test_data[i].name, hr);
4262 memset(&surface_desc, 0, sizeof(surface_desc));
4263 surface_desc.dwSize = sizeof(surface_desc);
4264 hr = IDirectDrawSurface_GetSurfaceDesc(backbuffer2, &surface_desc);
4265 ok(SUCCEEDED(hr), "%s: Failed to get surface desc, hr %#x.\n", test_data[i].name, hr);
4266 ok(!surface_desc.dwBackBufferCount, "%s: Got unexpected back buffer count %u.\n",
4267 test_data[i].name, surface_desc.dwBackBufferCount);
4268 expected_caps &= ~DDSCAPS_BACKBUFFER;
4269 ok((surface_desc.ddsCaps.dwCaps & ~placement) == expected_caps,
4270 "%s: Got unexpected caps %#x.\n", test_data[i].name, surface_desc.ddsCaps.dwCaps);
4272 hr = IDirectDrawSurface_GetAttachedSurface(backbuffer2, &caps, &backbuffer3);
4273 ok(SUCCEEDED(hr), "%s: Failed to get attached surface, hr %#x.\n", test_data[i].name, hr);
4274 memset(&surface_desc, 0, sizeof(surface_desc));
4275 surface_desc.dwSize = sizeof(surface_desc);
4276 hr = IDirectDrawSurface_GetSurfaceDesc(backbuffer3, &surface_desc);
4277 ok(SUCCEEDED(hr), "%s: Failed to get surface desc, hr %#x.\n", test_data[i].name, hr);
4278 ok(!surface_desc.dwBackBufferCount, "%s: Got unexpected back buffer count %u.\n",
4279 test_data[i].name, surface_desc.dwBackBufferCount);
4280 ok((surface_desc.ddsCaps.dwCaps & ~placement) == expected_caps,
4281 "%s: Got unexpected caps %#x.\n", test_data[i].name, surface_desc.ddsCaps.dwCaps);
4283 hr = IDirectDrawSurface_GetAttachedSurface(backbuffer3, &caps, &surface);
4284 ok(SUCCEEDED(hr), "%s: Failed to get attached surface, hr %#x.\n", test_data[i].name, hr);
4285 ok(surface == frontbuffer, "%s: Got unexpected surface %p, expected %p.\n",
4286 test_data[i].name, surface, frontbuffer);
4287 IDirectDrawSurface_Release(surface);
4289 memset(&surface_desc, 0, sizeof(surface_desc));
4290 surface_desc.dwSize = sizeof(surface_desc);
4291 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4292 surface_desc.ddsCaps.dwCaps = 0;
4293 surface_desc.dwWidth = 640;
4294 surface_desc.dwHeight = 480;
4295 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
4296 ok(SUCCEEDED(hr), "%s: Failed to create surface, hr %#x.\n", test_data[i].name, hr);
4297 hr = IDirectDrawSurface_Flip(frontbuffer, surface, DDFLIP_WAIT);
4298 ok(hr == DDERR_NOTFLIPPABLE, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
4299 IDirectDrawSurface_Release(surface);
4301 hr = IDirectDrawSurface_Flip(frontbuffer, frontbuffer, DDFLIP_WAIT);
4302 ok(hr == DDERR_NOTFLIPPABLE, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
4303 hr = IDirectDrawSurface_Flip(backbuffer1, NULL, DDFLIP_WAIT);
4304 ok(hr == DDERR_NOTFLIPPABLE, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
4305 hr = IDirectDrawSurface_Flip(backbuffer2, NULL, DDFLIP_WAIT);
4306 ok(hr == DDERR_NOTFLIPPABLE, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
4307 hr = IDirectDrawSurface_Flip(backbuffer3, NULL, DDFLIP_WAIT);
4308 ok(hr == DDERR_NOTFLIPPABLE, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
4310 memset(&fx, 0, sizeof(fx));
4311 fx.dwSize = sizeof(fx);
4312 U5(fx).dwFillColor = 0xffff0000;
4313 hr = IDirectDrawSurface_Blt(backbuffer1, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
4314 ok(SUCCEEDED(hr), "%s: Failed to fill surface, hr %#x.\n", test_data[i].name, hr);
4315 U5(fx).dwFillColor = 0xff00ff00;
4316 hr = IDirectDrawSurface_Blt(backbuffer2, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
4317 ok(SUCCEEDED(hr), "%s: Failed to fill surface, hr %#x.\n", test_data[i].name, hr);
4318 U5(fx).dwFillColor = 0xff0000ff;
4319 hr = IDirectDrawSurface_Blt(backbuffer3, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
4320 ok(SUCCEEDED(hr), "%s: Failed to fill surface, hr %#x.\n", test_data[i].name, hr);
4322 hr = IDirectDrawSurface_Flip(frontbuffer, NULL, DDFLIP_WAIT);
4323 ok(SUCCEEDED(hr), "%s: Failed to flip, hr %#x.\n", test_data[i].name, hr);
4324 color = get_surface_color(backbuffer1, 320, 240);
4325 /* The testbot seems to just copy the contents of one surface to all the
4326 * others, instead of properly flipping. */
4327 ok(compare_color(color, 0x0000ff00, 1) || broken(sysmem_primary && compare_color(color, 0x000000ff, 1)),
4328 "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
4329 color = get_surface_color(backbuffer2, 320, 240);
4330 ok(compare_color(color, 0x000000ff, 1), "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
4331 U5(fx).dwFillColor = 0xffff0000;
4332 hr = IDirectDrawSurface_Blt(backbuffer3, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
4333 ok(SUCCEEDED(hr), "%s: Failed to fill surface, hr %#x.\n", test_data[i].name, hr);
4335 hr = IDirectDrawSurface_Flip(frontbuffer, NULL, DDFLIP_WAIT);
4336 ok(SUCCEEDED(hr), "%s: Failed to flip, hr %#x.\n", test_data[i].name, hr);
4337 color = get_surface_color(backbuffer1, 320, 240);
4338 ok(compare_color(color, 0x000000ff, 1) || broken(sysmem_primary && compare_color(color, 0x00ff0000, 1)),
4339 "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
4340 color = get_surface_color(backbuffer2, 320, 240);
4341 ok(compare_color(color, 0x00ff0000, 1), "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
4342 U5(fx).dwFillColor = 0xff00ff00;
4343 hr = IDirectDrawSurface_Blt(backbuffer3, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
4344 ok(SUCCEEDED(hr), "%s: Failed to fill surface, hr %#x.\n", test_data[i].name, hr);
4346 hr = IDirectDrawSurface_Flip(frontbuffer, NULL, DDFLIP_WAIT);
4347 ok(SUCCEEDED(hr), "%s: Failed to flip, hr %#x.\n", test_data[i].name, hr);
4348 color = get_surface_color(backbuffer1, 320, 240);
4349 ok(compare_color(color, 0x00ff0000, 1) || broken(sysmem_primary && compare_color(color, 0x0000ff00, 1)),
4350 "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
4351 color = get_surface_color(backbuffer2, 320, 240);
4352 ok(compare_color(color, 0x0000ff00, 1), "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
4353 U5(fx).dwFillColor = 0xff0000ff;
4354 hr = IDirectDrawSurface_Blt(backbuffer3, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
4355 ok(SUCCEEDED(hr), "%s: Failed to fill surface, hr %#x.\n", test_data[i].name, hr);
4357 hr = IDirectDrawSurface_Flip(frontbuffer, backbuffer1, DDFLIP_WAIT);
4358 ok(SUCCEEDED(hr), "%s: Failed to flip, hr %#x.\n", test_data[i].name, hr);
4359 color = get_surface_color(backbuffer2, 320, 240);
4360 ok(compare_color(color, 0x0000ff00, 1) || broken(sysmem_primary && compare_color(color, 0x000000ff, 1)),
4361 "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
4362 color = get_surface_color(backbuffer3, 320, 240);
4363 ok(compare_color(color, 0x000000ff, 1), "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
4364 U5(fx).dwFillColor = 0xffff0000;
4365 hr = IDirectDrawSurface_Blt(backbuffer1, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
4366 ok(SUCCEEDED(hr), "%s: Failed to fill surface, hr %#x.\n", test_data[i].name, hr);
4368 hr = IDirectDrawSurface_Flip(frontbuffer, backbuffer2, DDFLIP_WAIT);
4369 ok(SUCCEEDED(hr), "%s: Failed to flip, hr %#x.\n", test_data[i].name, hr);
4370 color = get_surface_color(backbuffer1, 320, 240);
4371 ok(compare_color(color, 0x00ff0000, 1), "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
4372 color = get_surface_color(backbuffer3, 320, 240);
4373 ok(compare_color(color, 0x000000ff, 1) || broken(sysmem_primary && compare_color(color, 0x00ff0000, 1)),
4374 "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
4375 U5(fx).dwFillColor = 0xff00ff00;
4376 hr = IDirectDrawSurface_Blt(backbuffer2, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
4377 ok(SUCCEEDED(hr), "%s: Failed to fill surface, hr %#x.\n", test_data[i].name, hr);
4379 hr = IDirectDrawSurface_Flip(frontbuffer, backbuffer3, DDFLIP_WAIT);
4380 ok(SUCCEEDED(hr), "%s: Failed to flip, hr %#x.\n", test_data[i].name, hr);
4381 color = get_surface_color(backbuffer1, 320, 240);
4382 ok(compare_color(color, 0x00ff0000, 1) || broken(sysmem_primary && compare_color(color, 0x0000ff00, 1)),
4383 "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
4384 color = get_surface_color(backbuffer2, 320, 240);
4385 ok(compare_color(color, 0x0000ff00, 1), "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
4387 IDirectDrawSurface_Release(backbuffer3);
4388 IDirectDrawSurface_Release(backbuffer2);
4389 IDirectDrawSurface_Release(backbuffer1);
4390 IDirectDrawSurface_Release(frontbuffer);
4393 refcount = IDirectDraw_Release(ddraw);
4394 ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount);
4395 DestroyWindow(window);
4398 static void test_sysmem_overlay(void)
4400 IDirectDraw *ddraw;
4401 HWND window;
4402 HRESULT hr;
4403 DDSURFACEDESC ddsd;
4404 IDirectDrawSurface *surface;
4405 ULONG ref;
4407 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
4408 0, 0, 640, 480, 0, 0, 0, 0);
4409 ddraw = create_ddraw();
4410 ok(!!ddraw, "Failed to create a ddraw object.\n");
4412 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
4413 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4415 memset(&ddsd, 0, sizeof(ddsd));
4416 ddsd.dwSize = sizeof(ddsd);
4417 ddsd.dwFlags = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT;
4418 ddsd.dwWidth = 16;
4419 ddsd.dwHeight = 16;
4420 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OVERLAY;
4421 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
4422 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
4423 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 32;
4424 U2(ddsd.ddpfPixelFormat).dwRBitMask = 0x00ff0000;
4425 U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x0000ff00;
4426 U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x000000ff;
4427 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &surface, NULL);
4428 ok(hr == DDERR_NOOVERLAYHW, "Got unexpected hr %#x.\n", hr);
4430 ref = IDirectDraw_Release(ddraw);
4431 ok(ref == 0, "Ddraw object not properly released, refcount %u.\n", ref);
4432 DestroyWindow(window);
4435 static void test_primary_palette(void)
4437 DDSCAPS surface_caps = {DDSCAPS_FLIP};
4438 IDirectDrawSurface *primary, *backbuffer;
4439 PALETTEENTRY palette_entries[256];
4440 IDirectDrawPalette *palette, *tmp;
4441 DDSURFACEDESC surface_desc;
4442 IDirectDraw *ddraw;
4443 DWORD palette_caps;
4444 ULONG refcount;
4445 HWND window;
4446 HRESULT hr;
4448 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
4449 0, 0, 640, 480, 0, 0, 0, 0);
4450 ddraw = create_ddraw();
4451 ok(!!ddraw, "Failed to create a ddraw object.\n");
4452 if (FAILED(IDirectDraw_SetDisplayMode(ddraw, 640, 480, 8)))
4454 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
4455 IDirectDraw_Release(ddraw);
4456 DestroyWindow(window);
4457 return;
4459 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
4460 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4462 memset(&surface_desc, 0, sizeof(surface_desc));
4463 surface_desc.dwSize = sizeof(surface_desc);
4464 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
4465 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
4466 surface_desc.dwBackBufferCount = 1;
4467 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &primary, NULL);
4468 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4469 hr = IDirectDrawSurface_GetAttachedSurface(primary, &surface_caps, &backbuffer);
4470 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
4472 memset(palette_entries, 0, sizeof(palette_entries));
4473 hr = IDirectDraw_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256, palette_entries, &palette, NULL);
4474 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
4475 refcount = get_refcount((IUnknown *)palette);
4476 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4478 hr = IDirectDrawPalette_GetCaps(palette, &palette_caps);
4479 ok(SUCCEEDED(hr), "Failed to get palette caps, hr %#x.\n", hr);
4480 ok(palette_caps == (DDPCAPS_8BIT | DDPCAPS_ALLOW256), "Got unexpected palette caps %#x.\n", palette_caps);
4482 hr = IDirectDrawSurface_SetPalette(primary, palette);
4483 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
4485 /* The Windows 8 testbot attaches the palette to the backbuffer as well,
4486 * and is generally somewhat broken with respect to 8 bpp / palette
4487 * handling. */
4488 if (SUCCEEDED(IDirectDrawSurface_GetPalette(backbuffer, &tmp)))
4490 win_skip("Broken palette handling detected, skipping tests.\n");
4491 IDirectDrawPalette_Release(tmp);
4492 IDirectDrawPalette_Release(palette);
4493 /* The Windows 8 testbot keeps extra references to the primary and
4494 * backbuffer while in 8 bpp mode. */
4495 hr = IDirectDraw_RestoreDisplayMode(ddraw);
4496 ok(SUCCEEDED(hr), "Failed to restore display mode, hr %#x.\n", hr);
4497 goto done;
4500 refcount = get_refcount((IUnknown *)palette);
4501 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
4503 hr = IDirectDrawPalette_GetCaps(palette, &palette_caps);
4504 ok(SUCCEEDED(hr), "Failed to get palette caps, hr %#x.\n", hr);
4505 ok(palette_caps == (DDPCAPS_8BIT | DDPCAPS_PRIMARYSURFACE | DDPCAPS_ALLOW256),
4506 "Got unexpected palette caps %#x.\n", palette_caps);
4508 hr = IDirectDrawSurface_SetPalette(primary, NULL);
4509 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
4510 refcount = get_refcount((IUnknown *)palette);
4511 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4513 hr = IDirectDrawPalette_GetCaps(palette, &palette_caps);
4514 ok(SUCCEEDED(hr), "Failed to get palette caps, hr %#x.\n", hr);
4515 ok(palette_caps == (DDPCAPS_8BIT | DDPCAPS_ALLOW256), "Got unexpected palette caps %#x.\n", palette_caps);
4517 hr = IDirectDrawSurface_SetPalette(primary, palette);
4518 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
4519 refcount = get_refcount((IUnknown *)palette);
4520 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
4522 hr = IDirectDrawSurface_GetPalette(primary, &tmp);
4523 ok(SUCCEEDED(hr), "Failed to get palette, hr %#x.\n", hr);
4524 ok(tmp == palette, "Got unexpected palette %p, expected %p.\n", tmp, palette);
4525 IDirectDrawPalette_Release(tmp);
4526 hr = IDirectDrawSurface_GetPalette(backbuffer, &tmp);
4527 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x.\n", hr);
4529 refcount = IDirectDrawPalette_Release(palette);
4530 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4531 refcount = IDirectDrawPalette_Release(palette);
4532 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4534 /* Note that this only seems to work when the palette is attached to the
4535 * primary surface. When attached to a regular surface, attempting to get
4536 * the palette here will cause an access violation. */
4537 hr = IDirectDrawSurface_GetPalette(primary, &tmp);
4538 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x.\n", hr);
4540 done:
4541 refcount = IDirectDrawSurface_Release(backbuffer);
4542 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4543 refcount = IDirectDrawSurface_Release(primary);
4544 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4545 refcount = IDirectDraw_Release(ddraw);
4546 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4547 DestroyWindow(window);
4550 static HRESULT WINAPI surface_counter(IDirectDrawSurface *surface, DDSURFACEDESC *desc, void *context)
4552 UINT *surface_count = context;
4554 ++(*surface_count);
4555 IDirectDrawSurface_Release(surface);
4557 return DDENUMRET_OK;
4560 static void test_surface_attachment(void)
4562 IDirectDrawSurface *surface1, *surface2, *surface3, *surface4;
4563 DDSCAPS caps = {DDSCAPS_TEXTURE};
4564 DDSURFACEDESC surface_desc;
4565 IDirectDraw *ddraw;
4566 UINT surface_count;
4567 ULONG refcount;
4568 HWND window;
4569 HRESULT hr;
4571 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
4572 0, 0, 640, 480, 0, 0, 0, 0);
4573 ddraw = create_ddraw();
4574 ok(!!ddraw, "Failed to create a ddraw object.\n");
4575 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
4576 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4578 memset(&surface_desc, 0, sizeof(surface_desc));
4579 surface_desc.dwSize = sizeof(surface_desc);
4580 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_MIPMAPCOUNT;
4581 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
4582 U2(surface_desc).dwMipMapCount = 3;
4583 surface_desc.dwWidth = 128;
4584 surface_desc.dwHeight = 128;
4585 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface1, NULL);
4586 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4588 hr = IDirectDrawSurface_GetAttachedSurface(surface1, &caps, &surface2);
4589 ok(SUCCEEDED(hr), "Failed to get mip level, hr %#x.\n", hr);
4590 hr = IDirectDrawSurface_GetAttachedSurface(surface2, &caps, &surface3);
4591 ok(SUCCEEDED(hr), "Failed to get mip level, hr %#x.\n", hr);
4592 hr = IDirectDrawSurface_GetAttachedSurface(surface3, &caps, &surface4);
4593 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
4595 surface_count = 0;
4596 IDirectDrawSurface_EnumAttachedSurfaces(surface1, &surface_count, surface_counter);
4597 ok(surface_count == 1, "Got unexpected surface_count %u.\n", surface_count);
4598 surface_count = 0;
4599 IDirectDrawSurface_EnumAttachedSurfaces(surface2, &surface_count, surface_counter);
4600 ok(surface_count == 1, "Got unexpected surface_count %u.\n", surface_count);
4601 surface_count = 0;
4602 IDirectDrawSurface_EnumAttachedSurfaces(surface3, &surface_count, surface_counter);
4603 ok(!surface_count, "Got unexpected surface_count %u.\n", surface_count);
4605 memset(&surface_desc, 0, sizeof(surface_desc));
4606 surface_desc.dwSize = sizeof(surface_desc);
4607 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4608 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
4609 surface_desc.dwWidth = 16;
4610 surface_desc.dwHeight = 16;
4611 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface4, NULL);
4612 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4614 hr = IDirectDrawSurface_AddAttachedSurface(surface1, surface4);
4615 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
4616 hr = IDirectDrawSurface_AddAttachedSurface(surface4, surface1);
4617 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
4618 hr = IDirectDrawSurface_AddAttachedSurface(surface3, surface4);
4619 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
4620 hr = IDirectDrawSurface_AddAttachedSurface(surface4, surface3);
4621 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
4622 hr = IDirectDrawSurface_AddAttachedSurface(surface2, surface4);
4623 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
4624 hr = IDirectDrawSurface_AddAttachedSurface(surface4, surface2);
4625 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
4627 IDirectDrawSurface_Release(surface4);
4629 memset(&surface_desc, 0, sizeof(surface_desc));
4630 surface_desc.dwSize = sizeof(surface_desc);
4631 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4632 surface_desc.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
4633 surface_desc.dwWidth = 16;
4634 surface_desc.dwHeight = 16;
4635 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface4, NULL);
4636 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4638 if (SUCCEEDED(hr = IDirectDrawSurface_AddAttachedSurface(surface1, surface4)))
4640 skip("Running on refrast, skipping some tests.\n");
4641 hr = IDirectDrawSurface_DeleteAttachedSurface(surface1, 0, surface4);
4642 ok(SUCCEEDED(hr), "Failed to detach surface, hr %#x.\n", hr);
4644 else
4646 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
4647 hr = IDirectDrawSurface_AddAttachedSurface(surface4, surface1);
4648 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
4649 hr = IDirectDrawSurface_AddAttachedSurface(surface3, surface4);
4650 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
4651 hr = IDirectDrawSurface_AddAttachedSurface(surface4, surface3);
4652 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
4653 hr = IDirectDrawSurface_AddAttachedSurface(surface2, surface4);
4654 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
4655 hr = IDirectDrawSurface_AddAttachedSurface(surface4, surface2);
4656 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
4659 IDirectDrawSurface_Release(surface4);
4660 IDirectDrawSurface_Release(surface3);
4661 IDirectDrawSurface_Release(surface2);
4662 IDirectDrawSurface_Release(surface1);
4664 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
4665 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4667 /* Try a single primary and two offscreen plain surfaces. */
4668 memset(&surface_desc, 0, sizeof(surface_desc));
4669 surface_desc.dwSize = sizeof(surface_desc);
4670 surface_desc.dwFlags = DDSD_CAPS;
4671 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
4672 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface1, NULL);
4673 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4675 memset(&surface_desc, 0, sizeof(surface_desc));
4676 surface_desc.dwSize = sizeof(surface_desc);
4677 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4678 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
4679 surface_desc.dwWidth = registry_mode.dmPelsWidth;
4680 surface_desc.dwHeight = registry_mode.dmPelsHeight;
4681 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface2, NULL);
4682 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4684 memset(&surface_desc, 0, sizeof(surface_desc));
4685 surface_desc.dwSize = sizeof(surface_desc);
4686 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4687 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
4688 surface_desc.dwWidth = registry_mode.dmPelsWidth;
4689 surface_desc.dwHeight = registry_mode.dmPelsHeight;
4690 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface3, NULL);
4691 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4693 /* This one has a different size. */
4694 memset(&surface_desc, 0, sizeof(surface_desc));
4695 surface_desc.dwSize = sizeof(surface_desc);
4696 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4697 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
4698 surface_desc.dwWidth = 128;
4699 surface_desc.dwHeight = 128;
4700 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface4, NULL);
4701 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4703 hr = IDirectDrawSurface_AddAttachedSurface(surface1, surface2);
4704 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
4705 /* Try the reverse without detaching first. */
4706 hr = IDirectDrawSurface_AddAttachedSurface(surface2, surface1);
4707 ok(hr == DDERR_SURFACEALREADYATTACHED, "Got unexpected hr %#x.\n", hr);
4708 hr = IDirectDrawSurface_DeleteAttachedSurface(surface1, 0, surface2);
4709 ok(SUCCEEDED(hr), "Failed to detach surface, hr %#x.\n", hr);
4711 hr = IDirectDrawSurface_AddAttachedSurface(surface2, surface1);
4712 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
4713 /* Try to detach reversed. */
4714 hr = IDirectDrawSurface_DeleteAttachedSurface(surface1, 0, surface2);
4715 ok(hr == DDERR_CANNOTDETACHSURFACE, "Got unexpected hr %#x.\n", hr);
4716 hr = IDirectDrawSurface_DeleteAttachedSurface(surface2, 0, surface1);
4717 ok(SUCCEEDED(hr), "Failed to detach surface, hr %#x.\n", hr);
4719 hr = IDirectDrawSurface_AddAttachedSurface(surface2, surface3);
4720 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
4721 hr = IDirectDrawSurface_DeleteAttachedSurface(surface2, 0, surface3);
4722 ok(SUCCEEDED(hr), "Failed to detach surface, hr %#x.\n", hr);
4724 hr = IDirectDrawSurface_AddAttachedSurface(surface1, surface4);
4725 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
4726 hr = IDirectDrawSurface_AddAttachedSurface(surface4, surface1);
4727 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
4729 IDirectDrawSurface_Release(surface4);
4730 IDirectDrawSurface_Release(surface3);
4731 IDirectDrawSurface_Release(surface2);
4732 IDirectDrawSurface_Release(surface1);
4734 /* Test DeleteAttachedSurface() and automatic detachment of attached surfaces on release. */
4735 memset(&surface_desc, 0, sizeof(surface_desc));
4736 surface_desc.dwSize = sizeof(surface_desc);
4737 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
4738 surface_desc.dwWidth = 64;
4739 surface_desc.dwHeight = 64;
4740 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
4741 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
4742 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB; /* D3DFMT_R5G6B5 */
4743 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount = 16;
4744 U2(surface_desc.ddpfPixelFormat).dwRBitMask = 0xf800;
4745 U3(surface_desc.ddpfPixelFormat).dwGBitMask = 0x07e0;
4746 U4(surface_desc.ddpfPixelFormat).dwBBitMask = 0x001f;
4747 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface1, NULL);
4748 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4749 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface3, NULL);
4750 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4752 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
4753 surface_desc.ddpfPixelFormat.dwFlags = DDPF_ZBUFFER;
4754 U1(surface_desc.ddpfPixelFormat).dwZBufferBitDepth = 16;
4755 U3(surface_desc.ddpfPixelFormat).dwZBitMask = 0x0000ffff;
4756 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface2, NULL);
4757 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4759 hr = IDirectDrawSurface_AddAttachedSurface(surface1, surface2);
4760 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
4761 refcount = get_refcount((IUnknown *)surface2);
4762 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
4763 hr = IDirectDrawSurface_AddAttachedSurface(surface1, surface2);
4764 ok(hr == DDERR_SURFACEALREADYATTACHED, "Got unexpected hr %#x.\n", hr);
4766 /* Attaching while already attached to other surface. */
4767 hr = IDirectDrawSurface_AddAttachedSurface(surface3, surface2);
4768 todo_wine ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
4769 hr = IDirectDrawSurface_DeleteAttachedSurface(surface3, 0, surface2);
4770 todo_wine ok(SUCCEEDED(hr), "Failed to detach surface, hr %#x.\n", hr);
4771 IDirectDrawSurface_Release(surface3);
4773 hr = IDirectDrawSurface_DeleteAttachedSurface(surface1, 0, surface2);
4774 ok(SUCCEEDED(hr), "Failed to detach surface, hr %#x.\n", hr);
4775 refcount = get_refcount((IUnknown *)surface2);
4776 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4778 /* Automatic detachment on release. */
4779 hr = IDirectDrawSurface_AddAttachedSurface(surface1, surface2);
4780 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
4781 refcount = get_refcount((IUnknown *)surface2);
4782 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
4783 refcount = IDirectDrawSurface_Release(surface1);
4784 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4785 refcount = IDirectDrawSurface_Release(surface2);
4786 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4787 refcount = IDirectDraw_Release(ddraw);
4788 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4789 DestroyWindow(window);
4792 static void test_pixel_format(void)
4794 HWND window, window2 = NULL;
4795 HDC hdc, hdc2 = NULL;
4796 HMODULE gl = NULL;
4797 int format, test_format;
4798 PIXELFORMATDESCRIPTOR pfd;
4799 IDirectDraw *ddraw = NULL;
4800 IDirectDrawClipper *clipper = NULL;
4801 DDSURFACEDESC ddsd;
4802 IDirectDrawSurface *primary = NULL;
4803 DDBLTFX fx;
4804 HRESULT hr;
4806 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4807 100, 100, 160, 160, NULL, NULL, NULL, NULL);
4808 if (!window)
4810 skip("Failed to create window\n");
4811 return;
4814 window2 = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4815 100, 100, 160, 160, NULL, NULL, NULL, NULL);
4817 hdc = GetDC(window);
4818 if (!hdc)
4820 skip("Failed to get DC\n");
4821 goto cleanup;
4824 if (window2)
4825 hdc2 = GetDC(window2);
4827 gl = LoadLibraryA("opengl32.dll");
4828 ok(!!gl, "failed to load opengl32.dll; SetPixelFormat()/GetPixelFormat() may not work right\n");
4830 format = GetPixelFormat(hdc);
4831 ok(format == 0, "new window has pixel format %d\n", format);
4833 ZeroMemory(&pfd, sizeof(pfd));
4834 pfd.nSize = sizeof(pfd);
4835 pfd.nVersion = 1;
4836 pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
4837 pfd.iPixelType = PFD_TYPE_RGBA;
4838 pfd.iLayerType = PFD_MAIN_PLANE;
4839 format = ChoosePixelFormat(hdc, &pfd);
4840 if (format <= 0)
4842 skip("no pixel format available\n");
4843 goto cleanup;
4846 if (!SetPixelFormat(hdc, format, &pfd) || GetPixelFormat(hdc) != format)
4848 skip("failed to set pixel format\n");
4849 goto cleanup;
4852 if (!hdc2 || !SetPixelFormat(hdc2, format, &pfd) || GetPixelFormat(hdc2) != format)
4854 skip("failed to set pixel format on second window\n");
4855 if (hdc2)
4857 ReleaseDC(window2, hdc2);
4858 hdc2 = NULL;
4862 ddraw = create_ddraw();
4863 ok(!!ddraw, "Failed to create a ddraw object.\n");
4865 test_format = GetPixelFormat(hdc);
4866 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
4868 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
4869 if (FAILED(hr))
4871 skip("Failed to set cooperative level, hr %#x.\n", hr);
4872 goto cleanup;
4875 test_format = GetPixelFormat(hdc);
4876 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
4878 if (hdc2)
4880 hr = IDirectDraw_CreateClipper(ddraw, 0, &clipper, NULL);
4881 ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr);
4882 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window2);
4883 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
4885 test_format = GetPixelFormat(hdc);
4886 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
4888 test_format = GetPixelFormat(hdc2);
4889 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
4892 memset(&ddsd, 0, sizeof(ddsd));
4893 ddsd.dwSize = sizeof(ddsd);
4894 ddsd.dwFlags = DDSD_CAPS;
4895 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
4897 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &primary, NULL);
4898 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
4900 test_format = GetPixelFormat(hdc);
4901 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
4903 if (hdc2)
4905 test_format = GetPixelFormat(hdc2);
4906 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
4909 if (clipper)
4911 hr = IDirectDrawSurface_SetClipper(primary, clipper);
4912 ok(SUCCEEDED(hr), "Failed to set clipper, hr %#x.\n", hr);
4914 test_format = GetPixelFormat(hdc);
4915 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
4917 test_format = GetPixelFormat(hdc2);
4918 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
4921 memset(&fx, 0, sizeof(fx));
4922 fx.dwSize = sizeof(fx);
4923 hr = IDirectDrawSurface_Blt(primary, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
4924 ok(SUCCEEDED(hr), "Failed to clear source surface, hr %#x.\n", hr);
4926 test_format = GetPixelFormat(hdc);
4927 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
4929 if (hdc2)
4931 test_format = GetPixelFormat(hdc2);
4932 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
4935 cleanup:
4936 if (primary) IDirectDrawSurface_Release(primary);
4937 if (clipper) IDirectDrawClipper_Release(clipper);
4938 if (ddraw) IDirectDraw_Release(ddraw);
4939 if (gl) FreeLibrary(gl);
4940 if (hdc) ReleaseDC(window, hdc);
4941 if (hdc2) ReleaseDC(window2, hdc2);
4942 if (window) DestroyWindow(window);
4943 if (window2) DestroyWindow(window2);
4946 static void test_create_surface_pitch(void)
4948 IDirectDrawSurface *surface;
4949 DDSURFACEDESC surface_desc;
4950 IDirectDraw *ddraw;
4951 unsigned int i;
4952 ULONG refcount;
4953 HWND window;
4954 HRESULT hr;
4955 void *mem;
4957 static const struct
4959 DWORD caps;
4960 DWORD flags_in;
4961 DWORD pitch_in;
4962 HRESULT hr;
4963 DWORD flags_out;
4964 DWORD pitch_out32;
4965 DWORD pitch_out64;
4967 test_data[] =
4969 /* 0 */
4970 {DDSCAPS_VIDEOMEMORY | DDSCAPS_OFFSCREENPLAIN,
4971 0, 0, DD_OK,
4972 DDSD_PITCH, 0x100, 0x100},
4973 {DDSCAPS_VIDEOMEMORY | DDSCAPS_OFFSCREENPLAIN,
4974 DDSD_PITCH, 0x104, DD_OK,
4975 DDSD_PITCH, 0x100, 0x100},
4976 {DDSCAPS_VIDEOMEMORY | DDSCAPS_OFFSCREENPLAIN,
4977 DDSD_PITCH, 0x0f8, DD_OK,
4978 DDSD_PITCH, 0x100, 0x100},
4979 {DDSCAPS_VIDEOMEMORY | DDSCAPS_OFFSCREENPLAIN,
4980 DDSD_LPSURFACE | DDSD_PITCH, 0x100, DDERR_INVALIDCAPS,
4981 0, 0, 0 },
4982 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
4983 0, 0, DD_OK,
4984 DDSD_PITCH, 0x100, 0x0fc},
4985 /* 5 */
4986 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
4987 DDSD_PITCH, 0x104, DD_OK,
4988 DDSD_PITCH, 0x100, 0x0fc},
4989 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
4990 DDSD_PITCH, 0x0f8, DD_OK,
4991 DDSD_PITCH, 0x100, 0x0fc},
4992 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
4993 DDSD_PITCH | DDSD_LINEARSIZE, 0, DD_OK,
4994 DDSD_PITCH, 0x100, 0x0fc},
4995 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
4996 DDSD_LPSURFACE, 0, DDERR_INVALIDPARAMS,
4997 0, 0, 0 },
4998 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
4999 DDSD_LPSURFACE | DDSD_PITCH, 0x100, DDERR_INVALIDPARAMS,
5000 0, 0, 0 },
5001 /* 10 */
5002 {DDSCAPS_VIDEOMEMORY | DDSCAPS_OFFSCREENPLAIN | DDSCAPS_ALLOCONLOAD,
5003 0, 0, DDERR_INVALIDCAPS,
5004 0, 0, 0 },
5005 {DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD,
5006 0, 0, DD_OK,
5007 DDSD_PITCH, 0x100, 0 },
5008 {DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD,
5009 DDSD_LPSURFACE | DDSD_PITCH, 0x100, DDERR_INVALIDCAPS,
5010 0, 0, 0 },
5011 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN | DDSCAPS_ALLOCONLOAD,
5012 0, 0, DDERR_INVALIDCAPS,
5013 0, 0, 0 },
5014 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD,
5015 0, 0, DD_OK,
5016 DDSD_PITCH, 0x100, 0 },
5017 /* 15 */
5018 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD,
5019 DDSD_LPSURFACE | DDSD_PITCH, 0x100, DDERR_INVALIDPARAMS,
5020 0, 0, 0 },
5022 DWORD flags_mask = DDSD_PITCH | DDSD_LPSURFACE | DDSD_LINEARSIZE;
5024 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5025 0, 0, 640, 480, 0, 0, 0, 0);
5026 ddraw = create_ddraw();
5027 ok(!!ddraw, "Failed to create a ddraw object.\n");
5028 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
5029 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5031 mem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ((63 * 4) + 8) * 63);
5033 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
5035 memset(&surface_desc, 0, sizeof(surface_desc));
5036 surface_desc.dwSize = sizeof(surface_desc);
5037 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | test_data[i].flags_in;
5038 surface_desc.ddsCaps.dwCaps = test_data[i].caps;
5039 surface_desc.dwWidth = 63;
5040 surface_desc.dwHeight = 63;
5041 U1(surface_desc).lPitch = test_data[i].pitch_in;
5042 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
5043 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB;
5044 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount = 32;
5045 U2(surface_desc.ddpfPixelFormat).dwRBitMask = 0x00ff0000;
5046 U3(surface_desc.ddpfPixelFormat).dwGBitMask = 0x0000ff00;
5047 U4(surface_desc.ddpfPixelFormat).dwBBitMask = 0x000000ff;
5048 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
5049 if (test_data[i].flags_in & DDSD_LPSURFACE)
5051 HRESULT expected_hr = SUCCEEDED(test_data[i].hr) ? DDERR_INVALIDPARAMS : test_data[i].hr;
5052 ok(hr == expected_hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, expected_hr);
5053 surface_desc.lpSurface = mem;
5054 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
5056 if ((test_data[i].caps & DDSCAPS_VIDEOMEMORY) && hr == DDERR_NODIRECTDRAWHW)
5057 continue;
5058 ok(hr == test_data[i].hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, test_data[i].hr);
5059 if (FAILED(hr))
5060 continue;
5062 memset(&surface_desc, 0, sizeof(surface_desc));
5063 surface_desc.dwSize = sizeof(surface_desc);
5064 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
5065 ok(SUCCEEDED(hr), "Test %u: Failed to get surface desc, hr %#x.\n", i, hr);
5066 ok((surface_desc.dwFlags & flags_mask) == test_data[i].flags_out,
5067 "Test %u: Got unexpected flags %#x, expected %#x.\n",
5068 i, surface_desc.dwFlags & flags_mask, test_data[i].flags_out);
5069 if (!(test_data[i].caps & DDSCAPS_TEXTURE))
5071 if (is_ddraw64 && test_data[i].pitch_out32 != test_data[i].pitch_out64)
5072 todo_wine ok(U1(surface_desc).lPitch == test_data[i].pitch_out64,
5073 "Test %u: Got unexpected pitch %u, expected %u.\n",
5074 i, U1(surface_desc).lPitch, test_data[i].pitch_out64);
5075 else
5076 ok(U1(surface_desc).lPitch == test_data[i].pitch_out32,
5077 "Test %u: Got unexpected pitch %u, expected %u.\n",
5078 i, U1(surface_desc).lPitch, test_data[i].pitch_out32);
5080 ok(!surface_desc.lpSurface, "Test %u: Got unexpected lpSurface %p.\n", i, surface_desc.lpSurface);
5082 IDirectDrawSurface_Release(surface);
5085 HeapFree(GetProcessHeap(), 0, mem);
5086 refcount = IDirectDraw_Release(ddraw);
5087 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
5088 DestroyWindow(window);
5091 static void test_mipmap(void)
5093 IDirectDrawSurface *surface, *surface2;
5094 DDSURFACEDESC surface_desc;
5095 IDirectDraw *ddraw;
5096 unsigned int i;
5097 ULONG refcount;
5098 HWND window;
5099 HRESULT hr;
5100 DDSCAPS caps = {DDSCAPS_COMPLEX};
5101 DDCAPS hal_caps;
5103 static const struct
5105 DWORD flags;
5106 DWORD caps;
5107 DWORD width;
5108 DWORD height;
5109 DWORD mipmap_count_in;
5110 HRESULT hr;
5111 DWORD mipmap_count_out;
5113 tests[] =
5115 {DDSD_MIPMAPCOUNT, DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP, 128, 32, 3, DD_OK, 3},
5116 {DDSD_MIPMAPCOUNT, DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP, 128, 32, 0, DDERR_INVALIDPARAMS, 0},
5117 {0, DDSCAPS_TEXTURE | DDSCAPS_MIPMAP, 128, 32, 0, DD_OK, 1},
5118 {0, DDSCAPS_MIPMAP, 128, 32, 0, DDERR_INVALIDCAPS, 0},
5119 {0, DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP, 128, 32, 0, DD_OK, 6},
5120 {0, DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP, 32, 64, 0, DD_OK, 6},
5123 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5124 0, 0, 640, 480, 0, 0, 0, 0);
5125 ddraw = create_ddraw();
5126 ok(!!ddraw, "Failed to create a ddraw object.\n");
5127 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
5128 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5130 memset(&hal_caps, 0, sizeof(hal_caps));
5131 hal_caps.dwSize = sizeof(hal_caps);
5132 hr = IDirectDraw_GetCaps(ddraw, &hal_caps, NULL);
5133 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
5134 if ((hal_caps.ddsCaps.dwCaps & (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP)) != (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP))
5136 skip("Mipmapped textures not supported, skipping tests.\n");
5137 IDirectDraw_Release(ddraw);
5138 DestroyWindow(window);
5139 return;
5142 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
5144 memset(&surface_desc, 0, sizeof(surface_desc));
5145 surface_desc.dwSize = sizeof(surface_desc);
5146 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | tests[i].flags;
5147 surface_desc.ddsCaps.dwCaps = tests[i].caps;
5148 surface_desc.dwWidth = tests[i].width;
5149 surface_desc.dwHeight = tests[i].height;
5150 if (tests[i].flags & DDSD_MIPMAPCOUNT)
5151 U2(surface_desc).dwMipMapCount = tests[i].mipmap_count_in;
5152 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
5153 ok(hr == tests[i].hr, "Test %u: Got unexpected hr %#x.\n", i, hr);
5154 if (FAILED(hr))
5155 continue;
5157 memset(&surface_desc, 0, sizeof(surface_desc));
5158 surface_desc.dwSize = sizeof(surface_desc);
5159 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
5160 ok(SUCCEEDED(hr), "Test %u: Failed to get surface desc, hr %#x.\n", i, hr);
5161 ok(surface_desc.dwFlags & DDSD_MIPMAPCOUNT,
5162 "Test %u: Got unexpected flags %#x.\n", i, surface_desc.dwFlags);
5163 ok(U2(surface_desc).dwMipMapCount == tests[i].mipmap_count_out,
5164 "Test %u: Got unexpected mipmap count %u.\n", i, U2(surface_desc).dwMipMapCount);
5166 if (U2(surface_desc).dwMipMapCount > 1)
5168 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &surface2);
5169 ok(SUCCEEDED(hr), "Test %u: Failed to get attached surface, hr %#x.\n", i, hr);
5171 memset(&surface_desc, 0, sizeof(surface_desc));
5172 surface_desc.dwSize = sizeof(surface_desc);
5173 hr = IDirectDrawSurface_Lock(surface, NULL, &surface_desc, 0, NULL);
5174 ok(SUCCEEDED(hr), "Test %u: Failed to lock surface, hr %#x.\n", i, hr);
5175 memset(&surface_desc, 0, sizeof(surface_desc));
5176 surface_desc.dwSize = sizeof(surface_desc);
5177 hr = IDirectDrawSurface_Lock(surface2, NULL, &surface_desc, 0, NULL);
5178 ok(SUCCEEDED(hr), "Test %u: Failed to lock surface, hr %#x.\n", i, hr);
5179 IDirectDrawSurface_Unlock(surface2, NULL);
5180 IDirectDrawSurface_Unlock(surface, NULL);
5182 IDirectDrawSurface_Release(surface2);
5185 IDirectDrawSurface_Release(surface);
5188 refcount = IDirectDraw_Release(ddraw);
5189 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
5190 DestroyWindow(window);
5193 static void test_palette_complex(void)
5195 IDirectDrawSurface *surface, *mipmap, *tmp;
5196 DDSURFACEDESC surface_desc;
5197 IDirectDraw *ddraw;
5198 IDirectDrawPalette *palette, *palette2, *palette_mipmap;
5199 ULONG refcount;
5200 HWND window;
5201 HRESULT hr;
5202 DDSCAPS caps = {DDSCAPS_COMPLEX};
5203 DDCAPS hal_caps;
5204 PALETTEENTRY palette_entries[256];
5205 unsigned int i;
5206 HDC dc;
5207 RGBQUAD rgbquad;
5208 UINT count;
5210 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5211 0, 0, 640, 480, 0, 0, 0, 0);
5212 ddraw = create_ddraw();
5213 ok(!!ddraw, "Failed to create a ddraw object.\n");
5214 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
5215 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5217 memset(&hal_caps, 0, sizeof(hal_caps));
5218 hal_caps.dwSize = sizeof(hal_caps);
5219 hr = IDirectDraw_GetCaps(ddraw, &hal_caps, NULL);
5220 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
5221 if ((hal_caps.ddsCaps.dwCaps & (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP)) != (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP))
5223 skip("Mipmapped textures not supported, skipping mipmap palette test.\n");
5224 IDirectDraw_Release(ddraw);
5225 DestroyWindow(window);
5226 return;
5229 memset(&surface_desc, 0, sizeof(surface_desc));
5230 surface_desc.dwSize = sizeof(surface_desc);
5231 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
5232 surface_desc.dwWidth = 128;
5233 surface_desc.dwHeight = 128;
5234 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
5235 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
5236 surface_desc.ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
5237 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount = 8;
5238 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
5239 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5241 memset(palette_entries, 0, sizeof(palette_entries));
5242 hr = IDirectDraw_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
5243 palette_entries, &palette, NULL);
5244 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
5246 memset(palette_entries, 0, sizeof(palette_entries));
5247 palette_entries[1].peRed = 0xff;
5248 palette_entries[1].peGreen = 0x80;
5249 hr = IDirectDraw_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
5250 palette_entries, &palette_mipmap, NULL);
5251 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
5253 palette2 = (void *)0xdeadbeef;
5254 hr = IDirectDrawSurface_GetPalette(surface, &palette2);
5255 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x.\n", hr);
5256 ok(!palette2, "Got unexpected palette %p.\n", palette2);
5257 hr = IDirectDrawSurface_SetPalette(surface, palette);
5258 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
5259 hr = IDirectDrawSurface_GetPalette(surface, &palette2);
5260 ok(SUCCEEDED(hr), "Failed to get palette, hr %#x.\n", hr);
5261 ok(palette == palette2, "Got unexpected palette %p.\n", palette2);
5262 IDirectDrawPalette_Release(palette2);
5264 mipmap = surface;
5265 IDirectDrawSurface_AddRef(mipmap);
5266 for (i = 0; i < 7; ++i)
5268 hr = IDirectDrawSurface_GetAttachedSurface(mipmap, &caps, &tmp);
5269 ok(SUCCEEDED(hr), "Failed to get attached surface, i %u, hr %#x.\n", i, hr);
5270 palette2 = (void *)0xdeadbeef;
5271 hr = IDirectDrawSurface_GetPalette(tmp, &palette2);
5272 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x, i %u.\n", hr, i);
5273 ok(!palette2, "Got unexpected palette %p, i %u.\n", palette2, i);
5275 hr = IDirectDrawSurface_SetPalette(tmp, palette_mipmap);
5276 ok(SUCCEEDED(hr), "Failed to set palette, i %u, hr %#x.\n", i, hr);
5278 hr = IDirectDrawSurface_GetPalette(tmp, &palette2);
5279 ok(SUCCEEDED(hr), "Failed to get palette, i %u, hr %#x.\n", i, hr);
5280 ok(palette_mipmap == palette2, "Got unexpected palette %p.\n", palette2);
5281 IDirectDrawPalette_Release(palette2);
5283 hr = IDirectDrawSurface_GetDC(tmp, &dc);
5284 ok(SUCCEEDED(hr), "Failed to get DC, i %u, hr %#x.\n", i, hr);
5285 count = GetDIBColorTable(dc, 1, 1, &rgbquad);
5286 ok(count == 1, "Expected count 1, got %u.\n", count);
5287 ok(rgbquad.rgbRed == 0xff, "Expected rgbRed = 0xff, got %#x.\n", rgbquad.rgbRed);
5288 ok(rgbquad.rgbGreen == 0x80, "Expected rgbGreen = 0x80, got %#x.\n", rgbquad.rgbGreen);
5289 ok(rgbquad.rgbBlue == 0x0, "Expected rgbBlue = 0x0, got %#x.\n", rgbquad.rgbBlue);
5290 hr = IDirectDrawSurface_ReleaseDC(tmp, dc);
5291 ok(SUCCEEDED(hr), "Failed to release DC, i %u, hr %#x.\n", i, hr);
5293 IDirectDrawSurface_Release(mipmap);
5294 mipmap = tmp;
5297 hr = IDirectDrawSurface_GetAttachedSurface(mipmap, &caps, &tmp);
5298 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
5299 IDirectDrawSurface_Release(mipmap);
5300 refcount = IDirectDrawSurface_Release(surface);
5301 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
5302 refcount = IDirectDrawPalette_Release(palette_mipmap);
5303 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
5304 refcount = IDirectDrawPalette_Release(palette);
5305 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
5307 refcount = IDirectDraw_Release(ddraw);
5308 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
5309 DestroyWindow(window);
5312 static void test_p8_rgb_blit(void)
5314 IDirectDrawSurface *src, *dst;
5315 DDSURFACEDESC surface_desc;
5316 IDirectDraw *ddraw;
5317 IDirectDrawPalette *palette;
5318 ULONG refcount;
5319 HWND window;
5320 HRESULT hr;
5321 PALETTEENTRY palette_entries[256];
5322 unsigned int x;
5323 static const BYTE src_data[] = {0x10, 0x1, 0x2, 0x3, 0x4, 0x5, 0xff, 0x80};
5324 static const D3DCOLOR expected[] =
5326 0x00101010, 0x00010101, 0x00020202, 0x00030303,
5327 0x00040404, 0x00050505, 0x00ffffff, 0x00808080,
5329 D3DCOLOR color;
5331 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5332 0, 0, 640, 480, 0, 0, 0, 0);
5333 ddraw = create_ddraw();
5334 ok(!!ddraw, "Failed to create a ddraw object.\n");
5335 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
5336 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5338 memset(palette_entries, 0, sizeof(palette_entries));
5339 palette_entries[1].peGreen = 0xff;
5340 palette_entries[2].peBlue = 0xff;
5341 palette_entries[3].peFlags = 0xff;
5342 palette_entries[4].peRed = 0xff;
5343 hr = IDirectDraw_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
5344 palette_entries, &palette, NULL);
5345 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
5347 memset(&surface_desc, 0, sizeof(surface_desc));
5348 surface_desc.dwSize = sizeof(surface_desc);
5349 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
5350 surface_desc.dwWidth = 8;
5351 surface_desc.dwHeight = 1;
5352 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
5353 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
5354 surface_desc.ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
5355 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount = 8;
5356 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &src, NULL);
5357 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5359 memset(&surface_desc, 0, sizeof(surface_desc));
5360 surface_desc.dwSize = sizeof(surface_desc);
5361 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
5362 surface_desc.dwWidth = 8;
5363 surface_desc.dwHeight = 1;
5364 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
5365 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
5366 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
5367 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount = 32;
5368 U2(surface_desc.ddpfPixelFormat).dwRBitMask = 0x00ff0000;
5369 U3(surface_desc.ddpfPixelFormat).dwGBitMask = 0x0000ff00;
5370 U4(surface_desc.ddpfPixelFormat).dwBBitMask = 0x000000ff;
5371 U5(surface_desc.ddpfPixelFormat).dwRGBAlphaBitMask = 0xff000000;
5372 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &dst, NULL);
5373 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5375 memset(&surface_desc, 0, sizeof(surface_desc));
5376 surface_desc.dwSize = sizeof(surface_desc);
5377 hr = IDirectDrawSurface_Lock(src, NULL, &surface_desc, 0, NULL);
5378 ok(SUCCEEDED(hr), "Failed to lock source surface, hr %#x.\n", hr);
5379 memcpy(surface_desc.lpSurface, src_data, sizeof(src_data));
5380 hr = IDirectDrawSurface_Unlock(src, NULL);
5381 ok(SUCCEEDED(hr), "Failed to unlock source surface, hr %#x.\n", hr);
5383 hr = IDirectDrawSurface_SetPalette(src, palette);
5384 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
5385 hr = IDirectDrawSurface_Blt(dst, NULL, src, NULL, DDBLT_WAIT, NULL);
5386 /* The r500 Windows 7 driver returns E_NOTIMPL. r200 on Windows XP works.
5387 * The Geforce 7 driver on Windows Vista returns E_FAIL. Newer Nvidia GPUs work. */
5388 ok(SUCCEEDED(hr) || broken(hr == E_NOTIMPL) || broken(hr == E_FAIL),
5389 "Failed to blit, hr %#x.\n", hr);
5391 if (SUCCEEDED(hr))
5393 for (x = 0; x < sizeof(expected) / sizeof(*expected); x++)
5395 color = get_surface_color(dst, x, 0);
5396 todo_wine ok(compare_color(color, expected[x], 0),
5397 "Pixel %u: Got color %#x, expected %#x.\n",
5398 x, color, expected[x]);
5402 IDirectDrawSurface_Release(src);
5403 IDirectDrawSurface_Release(dst);
5404 IDirectDrawPalette_Release(palette);
5406 refcount = IDirectDraw_Release(ddraw);
5407 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
5408 DestroyWindow(window);
5411 static void test_material(void)
5413 IDirect3DMaterial *background, *material;
5414 IDirect3DExecuteBuffer *execute_buffer;
5415 D3DMATERIALHANDLE mat_handle, tmp;
5416 D3DEXECUTEBUFFERDESC exec_desc;
5417 IDirect3DViewport *viewport;
5418 IDirect3DDevice *device;
5419 IDirectDrawSurface *rt;
5420 IDirectDraw *ddraw;
5421 UINT inst_length;
5422 D3DCOLOR color;
5423 ULONG refcount;
5424 unsigned int i;
5425 HWND window;
5426 HRESULT hr;
5427 BOOL valid;
5428 void *ptr;
5430 static D3DVERTEX quad[] =
5432 {{-1.0f}, {-1.0f}, {0.0f}, {1.0f}, {0.0f}, {0.0f}},
5433 {{-1.0f}, { 1.0f}, {0.0f}, {1.0f}, {0.0f}, {0.0f}},
5434 {{ 1.0f}, {-1.0f}, {0.0f}, {1.0f}, {0.0f}, {0.0f}},
5435 {{ 1.0f}, { 1.0f}, {0.0f}, {1.0f}, {0.0f}, {0.0f}},
5437 static const struct
5439 BOOL material;
5440 D3DCOLOR expected_color;
5442 test_data[] =
5444 {TRUE, 0x0000ff00},
5445 {FALSE, 0x00ffffff},
5447 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
5449 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5450 0, 0, 640, 480, 0, 0, 0, 0);
5451 ddraw = create_ddraw();
5452 ok(!!ddraw, "Failed to create a ddraw object.\n");
5453 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
5455 skip("Failed to create a 3D device, skipping test.\n");
5456 DestroyWindow(window);
5457 return;
5460 hr = IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&rt);
5461 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
5463 background = create_diffuse_material(device, 0.0f, 0.0f, 1.0f, 1.0f);
5464 viewport = create_viewport(device, 0, 0, 640, 480);
5465 viewport_set_background(device, viewport, background);
5467 material = create_emissive_material(device, 0.0f, 1.0f, 0.0f, 0.0f);
5468 hr = IDirect3DMaterial_GetHandle(material, device, &mat_handle);
5469 ok(SUCCEEDED(hr), "Failed to get material handle, hr %#x.\n", hr);
5471 memset(&exec_desc, 0, sizeof(exec_desc));
5472 exec_desc.dwSize = sizeof(exec_desc);
5473 exec_desc.dwFlags = D3DDEB_BUFSIZE | D3DDEB_CAPS;
5474 exec_desc.dwBufferSize = 1024;
5475 exec_desc.dwCaps = D3DDEBCAPS_SYSTEMMEMORY;
5477 hr = IDirect3DDevice_CreateExecuteBuffer(device, &exec_desc, &execute_buffer, NULL);
5478 ok(SUCCEEDED(hr), "Failed to create execute buffer, hr %#x.\n", hr);
5480 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
5482 hr = IDirect3DExecuteBuffer_Lock(execute_buffer, &exec_desc);
5483 ok(SUCCEEDED(hr), "Failed to lock execute buffer, hr %#x.\n", hr);
5485 memcpy(exec_desc.lpData, quad, sizeof(quad));
5486 ptr = ((BYTE *)exec_desc.lpData) + sizeof(quad);
5487 emit_set_ls(&ptr, D3DLIGHTSTATE_MATERIAL, test_data[i].material ? mat_handle : 0);
5488 emit_process_vertices(&ptr, D3DPROCESSVERTICES_TRANSFORMLIGHT, 0, 4);
5489 emit_tquad(&ptr, 0);
5490 emit_end(&ptr);
5491 inst_length = (BYTE *)ptr - (BYTE *)exec_desc.lpData;
5492 inst_length -= sizeof(quad);
5494 hr = IDirect3DExecuteBuffer_Unlock(execute_buffer);
5495 ok(SUCCEEDED(hr), "Failed to unlock execute buffer, hr %#x.\n", hr);
5497 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER);
5498 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
5500 hr = IDirect3DDevice_BeginScene(device);
5501 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
5502 set_execute_data(execute_buffer, 4, sizeof(quad), inst_length);
5503 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
5504 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
5505 hr = IDirect3DDevice_EndScene(device);
5506 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
5507 color = get_surface_color(rt, 320, 240);
5508 if (test_data[i].material)
5509 todo_wine ok(compare_color(color, test_data[i].expected_color, 1)
5510 /* The Windows 8 testbot appears to return undefined results. */
5511 || broken(TRUE),
5512 "Got unexpected color 0x%08x, test %u.\n", color, i);
5513 else
5514 ok(compare_color(color, test_data[i].expected_color, 1),
5515 "Got unexpected color 0x%08x, test %u.\n", color, i);
5518 destroy_material(material);
5519 material = create_diffuse_material(device, 1.0f, 0.0f, 0.0f, 1.0f);
5520 hr = IDirect3DMaterial_GetHandle(material, device, &mat_handle);
5521 ok(SUCCEEDED(hr), "Failed to get material handle, hr %#x.\n", hr);
5523 hr = IDirect3DViewport_SetBackground(viewport, mat_handle);
5524 ok(SUCCEEDED(hr), "Failed to set viewport background, hr %#x.\n", hr);
5525 hr = IDirect3DViewport_GetBackground(viewport, &tmp, &valid);
5526 ok(SUCCEEDED(hr), "Failed to get viewport background, hr %#x.\n", hr);
5527 ok(tmp == mat_handle, "Got unexpected material handle %#x, expected %#x.\n", tmp, mat_handle);
5528 ok(valid, "Got unexpected valid %#x.\n", valid);
5529 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
5530 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
5531 color = get_surface_color(rt, 320, 240);
5532 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
5534 hr = IDirect3DViewport_SetBackground(viewport, 0);
5535 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
5536 hr = IDirect3DViewport_GetBackground(viewport, &tmp, &valid);
5537 ok(SUCCEEDED(hr), "Failed to get viewport background, hr %#x.\n", hr);
5538 ok(tmp == mat_handle, "Got unexpected material handle %#x, expected %#x.\n", tmp, mat_handle);
5539 ok(valid, "Got unexpected valid %#x.\n", valid);
5540 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
5541 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
5542 color = get_surface_color(rt, 320, 240);
5543 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
5545 destroy_viewport(device, viewport);
5546 viewport = create_viewport(device, 0, 0, 640, 480);
5548 hr = IDirect3DViewport_GetBackground(viewport, &tmp, &valid);
5549 ok(SUCCEEDED(hr), "Failed to get viewport background, hr %#x.\n", hr);
5550 ok(!tmp, "Got unexpected material handle %#x.\n", tmp);
5551 ok(!valid, "Got unexpected valid %#x.\n", valid);
5552 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
5553 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
5554 color = get_surface_color(rt, 320, 240);
5555 ok(compare_color(color, 0x00000000, 1), "Got unexpected color 0x%08x.\n", color);
5557 IDirect3DExecuteBuffer_Release(execute_buffer);
5558 destroy_viewport(device, viewport);
5559 destroy_material(background);
5560 destroy_material(material);
5561 IDirectDrawSurface_Release(rt);
5562 refcount = IDirect3DDevice_Release(device);
5563 ok(!refcount, "Device has %u references left.\n", refcount);
5564 refcount = IDirectDraw_Release(ddraw);
5565 ok(!refcount, "Ddraw object has %u references left.\n", refcount);
5566 DestroyWindow(window);
5569 static void test_lighting(void)
5571 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
5572 static D3DMATRIX mat =
5574 1.0f, 0.0f, 0.0f, 0.0f,
5575 0.0f, 1.0f, 0.0f, 0.0f,
5576 0.0f, 0.0f, 1.0f, 0.0f,
5577 0.0f, 0.0f, 0.0f, 1.0f,
5579 mat_singular =
5581 1.0f, 0.0f, 1.0f, 0.0f,
5582 0.0f, 1.0f, 0.0f, 0.0f,
5583 1.0f, 0.0f, 1.0f, 0.0f,
5584 0.0f, 0.0f, 0.5f, 1.0f,
5586 mat_transf =
5588 0.0f, 0.0f, 1.0f, 0.0f,
5589 0.0f, 1.0f, 0.0f, 0.0f,
5590 -1.0f, 0.0f, 0.0f, 0.0f,
5591 10.f, 10.0f, 10.0f, 1.0f,
5593 mat_nonaffine =
5595 1.0f, 0.0f, 0.0f, 0.0f,
5596 0.0f, 1.0f, 0.0f, 0.0f,
5597 0.0f, 0.0f, 1.0f, -1.0f,
5598 10.f, 10.0f, 10.0f, 0.0f,
5600 static D3DLVERTEX unlitquad[] =
5602 {{-1.0f}, {-1.0f}, {0.1f}, 0, {0xffff0000}, {0}, {0.0f}, {0.0f}},
5603 {{-1.0f}, { 0.0f}, {0.1f}, 0, {0xffff0000}, {0}, {0.0f}, {0.0f}},
5604 {{ 0.0f}, { 0.0f}, {0.1f}, 0, {0xffff0000}, {0}, {0.0f}, {0.0f}},
5605 {{ 0.0f}, {-1.0f}, {0.1f}, 0, {0xffff0000}, {0}, {0.0f}, {0.0f}},
5607 litquad[] =
5609 {{-1.0f}, { 0.0f}, {0.1f}, 0, {0xff00ff00}, {0}, {0.0f}, {0.0f}},
5610 {{-1.0f}, { 1.0f}, {0.1f}, 0, {0xff00ff00}, {0}, {0.0f}, {0.0f}},
5611 {{ 0.0f}, { 1.0f}, {0.1f}, 0, {0xff00ff00}, {0}, {0.0f}, {0.0f}},
5612 {{ 0.0f}, { 0.0f}, {0.1f}, 0, {0xff00ff00}, {0}, {0.0f}, {0.0f}},
5614 static D3DVERTEX unlitnquad[] =
5616 {{0.0f}, {-1.0f}, {0.1f}, {1.0f}, {1.0f}, {1.0f}, {0.0f}, {0.0f}},
5617 {{0.0f}, { 0.0f}, {0.1f}, {1.0f}, {1.0f}, {1.0f}, {0.0f}, {0.0f}},
5618 {{1.0f}, { 0.0f}, {0.1f}, {1.0f}, {1.0f}, {1.0f}, {0.0f}, {0.0f}},
5619 {{1.0f}, {-1.0f}, {0.1f}, {1.0f}, {1.0f}, {1.0f}, {0.0f}, {0.0f}},
5621 litnquad[] =
5623 {{0.0f}, { 0.0f}, {0.1f}, {1.0f}, {1.0f}, {1.0f}, {0.0f}, {0.0f}},
5624 {{0.0f}, { 1.0f}, {0.1f}, {1.0f}, {1.0f}, {1.0f}, {0.0f}, {0.0f}},
5625 {{1.0f}, { 1.0f}, {0.1f}, {1.0f}, {1.0f}, {1.0f}, {0.0f}, {0.0f}},
5626 {{1.0f}, { 0.0f}, {0.1f}, {1.0f}, {1.0f}, {1.0f}, {0.0f}, {0.0f}},
5628 nquad[] =
5630 {{-1.0f}, {-1.0f}, {0.0f}, {0.0f}, {0.0f}, {-1.0f}, {0.0f}, {0.0f}},
5631 {{-1.0f}, { 1.0f}, {0.0f}, {0.0f}, {0.0f}, {-1.0f}, {0.0f}, {0.0f}},
5632 {{ 1.0f}, { 1.0f}, {0.0f}, {0.0f}, {0.0f}, {-1.0f}, {0.0f}, {0.0f}},
5633 {{ 1.0f}, {-1.0f}, {0.0f}, {0.0f}, {0.0f}, {-1.0f}, {0.0f}, {0.0f}},
5635 rotatedquad[] =
5637 {{-10.0f}, {-11.0f}, {11.0f}, {-1.0f}, {0.0f}, {0.0f}, {0.0f}, {0.0f}},
5638 {{-10.0f}, { -9.0f}, {11.0f}, {-1.0f}, {0.0f}, {0.0f}, {0.0f}, {0.0f}},
5639 {{-10.0f}, { -9.0f}, { 9.0f}, {-1.0f}, {0.0f}, {0.0f}, {0.0f}, {0.0f}},
5640 {{-10.0f}, {-11.0f}, { 9.0f}, {-1.0f}, {0.0f}, {0.0f}, {0.0f}, {0.0f}},
5642 translatedquad[] =
5644 {{-11.0f}, {-11.0f}, {-10.0f}, {0.0f}, {0.0f}, {-1.0f}, {0.0f}, {0.0f}},
5645 {{-11.0f}, { -9.0f}, {-10.0f}, {0.0f}, {0.0f}, {-1.0f}, {0.0f}, {0.0f}},
5646 {{ -9.0f}, { -9.0f}, {-10.0f}, {0.0f}, {0.0f}, {-1.0f}, {0.0f}, {0.0f}},
5647 {{ -9.0f}, {-11.0f}, {-10.0f}, {0.0f}, {0.0f}, {-1.0f}, {0.0f}, {0.0f}},
5649 static const struct
5651 D3DMATRIX *world_matrix;
5652 void *quad;
5653 DWORD expected;
5654 const char *message;
5656 tests[] =
5658 {&mat, nquad, 0x000000ff, "Lit quad with light"},
5659 {&mat_singular, nquad, 0x000000b4, "Lit quad with singular world matrix"},
5660 {&mat_transf, rotatedquad, 0x000000ff, "Lit quad with transformation matrix"},
5661 {&mat_nonaffine, translatedquad, 0x000000ff, "Lit quad with non-affine matrix"},
5664 HWND window;
5665 IDirect3D *d3d;
5666 IDirect3DDevice *device;
5667 IDirectDraw *ddraw;
5668 IDirectDrawSurface *rt;
5669 IDirect3DViewport *viewport;
5670 IDirect3DMaterial *material;
5671 IDirect3DLight *light;
5672 IDirect3DExecuteBuffer *execute_buffer;
5673 D3DEXECUTEBUFFERDESC exec_desc;
5674 D3DMATERIALHANDLE mat_handle;
5675 D3DMATRIXHANDLE world_handle, view_handle, proj_handle;
5676 D3DLIGHT light_desc;
5677 HRESULT hr;
5678 D3DCOLOR color;
5679 void *ptr;
5680 UINT inst_length;
5681 ULONG refcount;
5682 unsigned int i;
5684 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5685 0, 0, 640, 480, 0, 0, 0, 0);
5686 ddraw = create_ddraw();
5687 ok(!!ddraw, "Failed to create a ddraw object.\n");
5688 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
5690 skip("Failed to create a 3D device, skipping test.\n");
5691 IDirectDraw_Release(ddraw);
5692 DestroyWindow(window);
5693 return;
5696 hr = IDirect3DDevice_GetDirect3D(device, &d3d);
5697 ok(SUCCEEDED(hr), "Failed to get D3D interface, hr %#x.\n", hr);
5699 hr = IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&rt);
5700 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
5702 viewport = create_viewport(device, 0, 0, 640, 480);
5703 material = create_diffuse_material(device, 1.0f, 1.0f, 1.0f, 1.0f);
5704 viewport_set_background(device, viewport, material);
5706 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
5707 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
5709 hr = IDirect3DDevice_CreateMatrix(device, &world_handle);
5710 ok(hr == D3D_OK, "Creating a matrix object failed, hr %#x.\n", hr);
5711 hr = IDirect3DDevice_SetMatrix(device, world_handle, &mat);
5712 ok(hr == D3D_OK, "Setting a matrix object failed, hr %#x.\n", hr);
5713 hr = IDirect3DDevice_CreateMatrix(device, &view_handle);
5714 ok(hr == D3D_OK, "Creating a matrix object failed, hr %#x.\n", hr);
5715 hr = IDirect3DDevice_SetMatrix(device, view_handle, &mat);
5716 ok(hr == D3D_OK, "Setting a matrix object failed, hr %#x.\n", hr);
5717 hr = IDirect3DDevice_CreateMatrix(device, &proj_handle);
5718 ok(hr == D3D_OK, "Creating a matrix object failed, hr %#x.\n", hr);
5719 hr = IDirect3DDevice_SetMatrix(device, proj_handle, &mat);
5720 ok(hr == D3D_OK, "Setting a matrix object failed, hr %#x.\n", hr);
5722 memset(&exec_desc, 0, sizeof(exec_desc));
5723 exec_desc.dwSize = sizeof(exec_desc);
5724 exec_desc.dwFlags = D3DDEB_BUFSIZE | D3DDEB_CAPS;
5725 exec_desc.dwBufferSize = 1024;
5726 exec_desc.dwCaps = D3DDEBCAPS_SYSTEMMEMORY;
5728 hr = IDirect3DDevice_CreateExecuteBuffer(device, &exec_desc, &execute_buffer, NULL);
5729 ok(SUCCEEDED(hr), "Failed to create execute buffer, hr %#x.\n", hr);
5731 hr = IDirect3DExecuteBuffer_Lock(execute_buffer, &exec_desc);
5732 ok(SUCCEEDED(hr), "Failed to lock execute buffer, hr %#x.\n", hr);
5734 memcpy(exec_desc.lpData, unlitquad, sizeof(unlitquad));
5735 ptr = ((BYTE *)exec_desc.lpData) + sizeof(unlitquad);
5736 emit_set_ts(&ptr, D3DTRANSFORMSTATE_WORLD, world_handle);
5737 emit_set_ts(&ptr, D3DTRANSFORMSTATE_VIEW, view_handle);
5738 emit_set_ts(&ptr, D3DTRANSFORMSTATE_PROJECTION, proj_handle);
5739 emit_set_rs(&ptr, D3DRENDERSTATE_CLIPPING, FALSE);
5740 emit_set_rs(&ptr, D3DRENDERSTATE_ZENABLE, FALSE);
5741 emit_set_rs(&ptr, D3DRENDERSTATE_FOGENABLE, FALSE);
5742 emit_set_rs(&ptr, D3DRENDERSTATE_CULLMODE, D3DCULL_NONE);
5743 emit_process_vertices(&ptr, D3DPROCESSVERTICES_TRANSFORM, 0, 4);
5744 emit_tquad_tlist(&ptr, 0);
5745 emit_end(&ptr);
5746 inst_length = (BYTE *)ptr - (BYTE *)exec_desc.lpData;
5747 inst_length -= sizeof(unlitquad);
5749 hr = IDirect3DExecuteBuffer_Unlock(execute_buffer);
5750 ok(SUCCEEDED(hr), "Failed to unlock execute buffer, hr %#x.\n", hr);
5752 hr = IDirect3DDevice_BeginScene(device);
5753 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
5755 set_execute_data(execute_buffer, 4, sizeof(unlitquad), inst_length);
5756 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
5757 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
5759 hr = IDirect3DExecuteBuffer_Lock(execute_buffer, &exec_desc);
5760 ok(SUCCEEDED(hr), "Failed to lock execute buffer, hr %#x.\n", hr);
5762 memcpy(exec_desc.lpData, litquad, sizeof(litquad));
5763 ptr = ((BYTE *)exec_desc.lpData) + sizeof(litquad);
5764 emit_process_vertices(&ptr, D3DPROCESSVERTICES_TRANSFORM, 0, 4);
5765 emit_tquad_tlist(&ptr, 0);
5766 emit_end(&ptr);
5767 inst_length = (BYTE *)ptr - (BYTE *)exec_desc.lpData;
5768 inst_length -= sizeof(litquad);
5770 hr = IDirect3DExecuteBuffer_Unlock(execute_buffer);
5771 ok(SUCCEEDED(hr), "Failed to unlock execute buffer, hr %#x.\n", hr);
5773 set_execute_data(execute_buffer, 4, sizeof(litquad), inst_length);
5774 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
5775 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
5777 hr = IDirect3DExecuteBuffer_Lock(execute_buffer, &exec_desc);
5778 ok(SUCCEEDED(hr), "Failed to lock execute buffer, hr %#x.\n", hr);
5780 memcpy(exec_desc.lpData, unlitnquad, sizeof(unlitnquad));
5781 ptr = ((BYTE *)exec_desc.lpData) + sizeof(unlitnquad);
5782 emit_process_vertices(&ptr, D3DPROCESSVERTICES_TRANSFORMLIGHT, 0, 4);
5783 emit_tquad_tlist(&ptr, 0);
5784 emit_end(&ptr);
5785 inst_length = (BYTE *)ptr - (BYTE *)exec_desc.lpData;
5786 inst_length -= sizeof(unlitnquad);
5788 hr = IDirect3DExecuteBuffer_Unlock(execute_buffer);
5789 ok(SUCCEEDED(hr), "Failed to unlock execute buffer, hr %#x.\n", hr);
5791 set_execute_data(execute_buffer, 4, sizeof(unlitnquad), inst_length);
5792 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
5793 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
5795 hr = IDirect3DExecuteBuffer_Lock(execute_buffer, &exec_desc);
5796 ok(SUCCEEDED(hr), "Failed to lock execute buffer, hr %#x.\n", hr);
5798 memcpy(exec_desc.lpData, litnquad, sizeof(litnquad));
5799 ptr = ((BYTE *)exec_desc.lpData) + sizeof(litnquad);
5800 emit_process_vertices(&ptr, D3DPROCESSVERTICES_TRANSFORMLIGHT, 0, 4);
5801 emit_tquad_tlist(&ptr, 0);
5802 emit_end(&ptr);
5803 inst_length = (BYTE *)ptr - (BYTE *)exec_desc.lpData;
5804 inst_length -= sizeof(litnquad);
5806 hr = IDirect3DExecuteBuffer_Unlock(execute_buffer);
5807 ok(SUCCEEDED(hr), "Failed to unlock execute buffer, hr %#x.\n", hr);
5809 set_execute_data(execute_buffer, 4, sizeof(litnquad), inst_length);
5810 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
5811 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
5813 hr = IDirect3DDevice_EndScene(device);
5814 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
5816 color = get_surface_color(rt, 160, 360);
5817 ok(color == 0x00ff0000, "Unlit quad without normals has color 0x%08x.\n", color);
5818 color = get_surface_color(rt, 160, 120);
5819 ok(color == 0x0000ff00, "Lit quad without normals has color 0x%08x.\n", color);
5820 color = get_surface_color(rt, 480, 360);
5821 ok(color == 0x00ffffff, "Unlit quad with normals has color 0x%08x.\n", color);
5822 color = get_surface_color(rt, 480, 120);
5823 ok(color == 0x00ffffff, "Lit quad with normals has color 0x%08x.\n", color);
5825 hr = IDirect3DMaterial_GetHandle(material, device, &mat_handle);
5826 ok(SUCCEEDED(hr), "Failed to get material handle, hr %#x.\n", hr);
5828 hr = IDirect3D_CreateLight(d3d, &light, NULL);
5829 ok(SUCCEEDED(hr), "Failed to create a light object, hr %#x.\n", hr);
5830 memset(&light_desc, 0, sizeof(light_desc));
5831 light_desc.dwSize = sizeof(light_desc);
5832 light_desc.dltType = D3DLIGHT_DIRECTIONAL;
5833 U1(light_desc.dcvColor).r = 0.0f;
5834 U2(light_desc.dcvColor).g = 0.0f;
5835 U3(light_desc.dcvColor).b = 1.0f;
5836 U4(light_desc.dcvColor).a = 1.0f;
5837 U3(light_desc.dvDirection).z = 1.0f;
5838 hr = IDirect3DLight_SetLight(light, &light_desc);
5839 ok(SUCCEEDED(hr), "Failed to set light, hr %#x.\n", hr);
5840 hr = IDirect3DViewport_AddLight(viewport, light);
5841 ok(SUCCEEDED(hr), "Failed to add a light to the viewport, hr %#x.\n", hr);
5843 for (i = 0; i < sizeof(tests) / sizeof(tests[0]); ++i)
5845 hr = IDirect3DDevice_SetMatrix(device, world_handle, tests[i].world_matrix);
5846 ok(hr == D3D_OK, "Setting a matrix object failed, hr %#x.\n", hr);
5848 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
5849 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
5851 hr = IDirect3DDevice_BeginScene(device);
5852 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
5854 hr = IDirect3DExecuteBuffer_Lock(execute_buffer, &exec_desc);
5855 ok(SUCCEEDED(hr), "Failed to lock execute buffer, hr %#x.\n", hr);
5857 memcpy(exec_desc.lpData, tests[i].quad, sizeof(nquad));
5858 ptr = ((BYTE *)exec_desc.lpData) + sizeof(nquad);
5859 emit_set_ls(&ptr, D3DLIGHTSTATE_MATERIAL, mat_handle);
5860 emit_process_vertices(&ptr, D3DPROCESSVERTICES_TRANSFORMLIGHT, 0, 4);
5861 emit_tquad_tlist(&ptr, 0);
5862 emit_end(&ptr);
5863 inst_length = (BYTE *)ptr - (BYTE *)exec_desc.lpData;
5864 inst_length -= sizeof(nquad);
5866 hr = IDirect3DExecuteBuffer_Unlock(execute_buffer);
5867 ok(SUCCEEDED(hr), "Failed to unlock execute buffer, hr %#x.\n", hr);
5869 set_execute_data(execute_buffer, 4, sizeof(nquad), inst_length);
5870 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
5871 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
5873 hr = IDirect3DDevice_EndScene(device);
5874 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
5876 color = get_surface_color(rt, 320, 240);
5877 todo_wine ok(color == tests[i].expected, "%s has color 0x%08x.\n", tests[i].message, color);
5880 IDirect3DExecuteBuffer_Release(execute_buffer);
5881 IDirect3DDevice_DeleteMatrix(device, world_handle);
5882 IDirect3DDevice_DeleteMatrix(device, view_handle);
5883 IDirect3DDevice_DeleteMatrix(device, proj_handle);
5884 hr = IDirect3DViewport_DeleteLight(viewport, light);
5885 ok(SUCCEEDED(hr), "Failed to remove a light from the viewport, hr %#x.\n", hr);
5886 IDirect3DLight_Release(light);
5887 destroy_material(material);
5888 destroy_viewport(device, viewport);
5889 IDirectDrawSurface_Release(rt);
5890 refcount = IDirect3DDevice_Release(device);
5891 ok(!refcount, "Device has %u references left.\n", refcount);
5892 IDirect3D_Release(d3d);
5893 refcount = IDirectDraw_Release(ddraw);
5894 ok(!refcount, "Ddraw object has %u references left.\n", refcount);
5895 DestroyWindow(window);
5898 static void test_palette_gdi(void)
5900 IDirectDrawSurface *surface, *primary;
5901 DDSURFACEDESC surface_desc;
5902 IDirectDraw *ddraw;
5903 IDirectDrawPalette *palette, *palette2;
5904 ULONG refcount;
5905 HWND window;
5906 HRESULT hr;
5907 PALETTEENTRY palette_entries[256];
5908 UINT i;
5909 HDC dc;
5910 /* On the Windows 8 testbot palette index 0 of the onscreen palette is forced to
5911 * r = 0, g = 0, b = 0. Do not attempt to set it to something else as this is
5912 * not the point of this test. */
5913 static const RGBQUAD expected1[] =
5915 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
5916 {0x03, 0x00, 0x00, 0x00}, {0x15, 0x14, 0x13, 0x00},
5918 static const RGBQUAD expected2[] =
5920 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
5921 {0x03, 0x00, 0x00, 0x00}, {0x25, 0x24, 0x23, 0x00},
5923 static const RGBQUAD expected3[] =
5925 {0x00, 0x00, 0x00, 0x00}, {0x40, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x40, 0x00},
5926 {0x00, 0x40, 0x00, 0x00}, {0x56, 0x34, 0x12, 0x00},
5928 HPALETTE ddraw_palette_handle;
5929 /* Similar to index 0, index 255 is r = 0xff, g = 0xff, b = 0xff on the Win8 VMs. */
5930 RGBQUAD rgbquad[255];
5931 static const RGBQUAD rgb_zero = {0, 0, 0, 0};
5933 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5934 0, 0, 640, 480, 0, 0, 0, 0);
5935 ddraw = create_ddraw();
5936 ok(!!ddraw, "Failed to create a ddraw object.\n");
5937 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
5938 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5940 memset(&surface_desc, 0, sizeof(surface_desc));
5941 surface_desc.dwSize = sizeof(surface_desc);
5942 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
5943 surface_desc.dwWidth = 16;
5944 surface_desc.dwHeight = 16;
5945 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
5946 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
5947 surface_desc.ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
5948 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount = 8;
5949 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
5950 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5952 /* Avoid colors from the Windows default palette. */
5953 memset(palette_entries, 0, sizeof(palette_entries));
5954 palette_entries[1].peRed = 0x01;
5955 palette_entries[2].peGreen = 0x02;
5956 palette_entries[3].peBlue = 0x03;
5957 palette_entries[4].peRed = 0x13;
5958 palette_entries[4].peGreen = 0x14;
5959 palette_entries[4].peBlue = 0x15;
5960 hr = IDirectDraw_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
5961 palette_entries, &palette, NULL);
5962 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
5964 /* If there is no palette assigned and the display mode is not 8 bpp, some
5965 * drivers refuse to create a DC while others allow it. If a DC is created,
5966 * the DIB color table is uninitialized and contains random colors. No error
5967 * is generated when trying to read pixels and random garbage is returned.
5969 * The most likely explanation is that if the driver creates a DC, it (or
5970 * the higher-level runtime) uses GetSystemPaletteEntries to find the
5971 * palette, but GetSystemPaletteEntries fails when bpp > 8 and the palette
5972 * contains uninitialized garbage. See comments below for the P8 case. */
5974 hr = IDirectDrawSurface_SetPalette(surface, palette);
5975 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
5976 hr = IDirectDrawSurface_GetDC(surface, &dc);
5977 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
5978 ddraw_palette_handle = SelectPalette(dc, GetStockObject(DEFAULT_PALETTE), FALSE);
5979 ok(ddraw_palette_handle == GetStockObject(DEFAULT_PALETTE),
5980 "Got unexpected palette %p, expected %p.\n",
5981 ddraw_palette_handle, GetStockObject(DEFAULT_PALETTE));
5983 i = GetDIBColorTable(dc, 0, sizeof(rgbquad) / sizeof(*rgbquad), rgbquad);
5984 ok(i == sizeof(rgbquad) / sizeof(*rgbquad), "Expected count 255, got %u.\n", i);
5985 for (i = 0; i < sizeof(expected1) / sizeof(*expected1); i++)
5987 ok(!memcmp(&rgbquad[i], &expected1[i], sizeof(rgbquad[i])),
5988 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
5989 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
5990 expected1[i].rgbRed, expected1[i].rgbGreen, expected1[i].rgbBlue);
5992 for (; i < sizeof(rgbquad) / sizeof(*rgbquad); i++)
5994 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
5995 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
5996 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
5999 /* Update the palette while the DC is in use. This does not modify the DC. */
6000 palette_entries[4].peRed = 0x23;
6001 palette_entries[4].peGreen = 0x24;
6002 palette_entries[4].peBlue = 0x25;
6003 hr = IDirectDrawPalette_SetEntries(palette, 0, 4, 1, &palette_entries[4]);
6004 ok(SUCCEEDED(hr), "Failed to set palette entries, hr %#x.\n", hr);
6006 i = GetDIBColorTable(dc, 4, 1, &rgbquad[4]);
6007 ok(i == 1, "Expected count 1, got %u.\n", i);
6008 ok(!memcmp(&rgbquad[4], &expected1[4], sizeof(rgbquad[4])),
6009 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
6010 i, rgbquad[4].rgbRed, rgbquad[4].rgbGreen, rgbquad[4].rgbBlue,
6011 expected1[4].rgbRed, expected1[4].rgbGreen, expected1[4].rgbBlue);
6013 /* Neither does re-setting the palette. */
6014 hr = IDirectDrawSurface_SetPalette(surface, NULL);
6015 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
6016 hr = IDirectDrawSurface_SetPalette(surface, palette);
6017 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
6019 i = GetDIBColorTable(dc, 4, 1, &rgbquad[4]);
6020 ok(i == 1, "Expected count 1, got %u.\n", i);
6021 ok(!memcmp(&rgbquad[4], &expected1[4], sizeof(rgbquad[4])),
6022 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
6023 i, rgbquad[4].rgbRed, rgbquad[4].rgbGreen, rgbquad[4].rgbBlue,
6024 expected1[4].rgbRed, expected1[4].rgbGreen, expected1[4].rgbBlue);
6026 hr = IDirectDrawSurface_ReleaseDC(surface, dc);
6027 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
6029 /* Refresh the DC. This updates the palette. */
6030 hr = IDirectDrawSurface_GetDC(surface, &dc);
6031 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
6032 i = GetDIBColorTable(dc, 0, sizeof(rgbquad) / sizeof(*rgbquad), rgbquad);
6033 ok(i == sizeof(rgbquad) / sizeof(*rgbquad), "Expected count 255, got %u.\n", i);
6034 for (i = 0; i < sizeof(expected2) / sizeof(*expected2); i++)
6036 ok(!memcmp(&rgbquad[i], &expected2[i], sizeof(rgbquad[i])),
6037 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
6038 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
6039 expected2[i].rgbRed, expected2[i].rgbGreen, expected2[i].rgbBlue);
6041 for (; i < sizeof(rgbquad) / sizeof(*rgbquad); i++)
6043 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
6044 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
6045 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
6047 hr = IDirectDrawSurface_ReleaseDC(surface, dc);
6048 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
6050 refcount = IDirectDrawSurface_Release(surface);
6051 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6053 if (FAILED(IDirectDraw_SetDisplayMode(ddraw, 640, 480, 8)))
6055 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
6056 IDirectDrawPalette_Release(palette);
6057 IDirectDraw_Release(ddraw);
6058 DestroyWindow(window);
6059 return;
6061 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
6062 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
6063 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6065 memset(&surface_desc, 0, sizeof(surface_desc));
6066 surface_desc.dwSize = sizeof(surface_desc);
6067 surface_desc.dwFlags = DDSD_CAPS;
6068 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
6069 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &primary, NULL);
6070 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6072 hr = IDirectDrawSurface_SetPalette(primary, palette);
6073 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
6074 hr = IDirectDrawSurface_GetDC(primary, &dc);
6075 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
6076 ddraw_palette_handle = SelectPalette(dc, GetStockObject(DEFAULT_PALETTE), FALSE);
6077 /* Windows 2000 on the testbot assigns a different palette to the primary. Refrast? */
6078 ok(ddraw_palette_handle == GetStockObject(DEFAULT_PALETTE) || broken(TRUE),
6079 "Got unexpected palette %p, expected %p.\n",
6080 ddraw_palette_handle, GetStockObject(DEFAULT_PALETTE));
6081 SelectPalette(dc, ddraw_palette_handle, FALSE);
6083 /* The primary uses the system palette. In exclusive mode, the system palette matches
6084 * the ddraw palette attached to the primary, so the result is what you would expect
6085 * from a regular surface. Tests for the interaction between the ddraw palette and
6086 * the system palette are not included pending an application that depends on this.
6087 * The relation between those causes problems on Windows Vista and newer for games
6088 * like Age of Empires or StarCraft. Don't emulate it without a real need. */
6089 i = GetDIBColorTable(dc, 0, sizeof(rgbquad) / sizeof(*rgbquad), rgbquad);
6090 ok(i == sizeof(rgbquad) / sizeof(*rgbquad), "Expected count 255, got %u.\n", i);
6091 for (i = 0; i < sizeof(expected2) / sizeof(*expected2); i++)
6093 ok(!memcmp(&rgbquad[i], &expected2[i], sizeof(rgbquad[i])),
6094 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
6095 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
6096 expected2[i].rgbRed, expected2[i].rgbGreen, expected2[i].rgbBlue);
6098 for (; i < sizeof(rgbquad) / sizeof(*rgbquad); i++)
6100 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
6101 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
6102 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
6104 hr = IDirectDrawSurface_ReleaseDC(primary, dc);
6105 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
6107 memset(&surface_desc, 0, sizeof(surface_desc));
6108 surface_desc.dwSize = sizeof(surface_desc);
6109 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
6110 surface_desc.dwWidth = 16;
6111 surface_desc.dwHeight = 16;
6112 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
6113 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
6114 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6116 /* Here the offscreen surface appears to use the primary's palette,
6117 * but in all likelihood it is actually the system palette. */
6118 hr = IDirectDrawSurface_GetDC(surface, &dc);
6119 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
6120 i = GetDIBColorTable(dc, 0, sizeof(rgbquad) / sizeof(*rgbquad), rgbquad);
6121 ok(i == sizeof(rgbquad) / sizeof(*rgbquad), "Expected count 255, got %u.\n", i);
6122 for (i = 0; i < sizeof(expected2) / sizeof(*expected2); i++)
6124 ok(!memcmp(&rgbquad[i], &expected2[i], sizeof(rgbquad[i])),
6125 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
6126 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
6127 expected2[i].rgbRed, expected2[i].rgbGreen, expected2[i].rgbBlue);
6129 for (; i < sizeof(rgbquad) / sizeof(*rgbquad); i++)
6131 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
6132 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
6133 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
6135 hr = IDirectDrawSurface_ReleaseDC(surface, dc);
6136 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
6138 /* On real hardware a change to the primary surface's palette applies immediately,
6139 * even on device contexts from offscreen surfaces that do not have their own
6140 * palette. On the testbot VMs this is not the case. Don't test this until we
6141 * know of an application that depends on this. */
6143 memset(palette_entries, 0, sizeof(palette_entries));
6144 palette_entries[1].peBlue = 0x40;
6145 palette_entries[2].peRed = 0x40;
6146 palette_entries[3].peGreen = 0x40;
6147 palette_entries[4].peRed = 0x12;
6148 palette_entries[4].peGreen = 0x34;
6149 palette_entries[4].peBlue = 0x56;
6150 hr = IDirectDraw_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
6151 palette_entries, &palette2, NULL);
6152 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
6153 hr = IDirectDrawSurface_SetPalette(surface, palette2);
6154 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
6156 /* A palette assigned to the offscreen surface overrides the primary / system
6157 * palette. */
6158 hr = IDirectDrawSurface_GetDC(surface, &dc);
6159 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
6160 i = GetDIBColorTable(dc, 0, sizeof(rgbquad) / sizeof(*rgbquad), rgbquad);
6161 ok(i == sizeof(rgbquad) / sizeof(*rgbquad), "Expected count 255, got %u.\n", i);
6162 for (i = 0; i < sizeof(expected3) / sizeof(*expected3); i++)
6164 ok(!memcmp(&rgbquad[i], &expected3[i], sizeof(rgbquad[i])),
6165 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
6166 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
6167 expected3[i].rgbRed, expected3[i].rgbGreen, expected3[i].rgbBlue);
6169 for (; i < sizeof(rgbquad) / sizeof(*rgbquad); i++)
6171 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
6172 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
6173 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
6175 hr = IDirectDrawSurface_ReleaseDC(surface, dc);
6176 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
6178 refcount = IDirectDrawSurface_Release(surface);
6179 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6181 /* The Windows 8 testbot keeps extra references to the primary and
6182 * backbuffer while in 8 bpp mode. */
6183 hr = IDirectDraw_RestoreDisplayMode(ddraw);
6184 ok(SUCCEEDED(hr), "Failed to restore display mode, hr %#x.\n", hr);
6186 refcount = IDirectDrawSurface_Release(primary);
6187 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6188 refcount = IDirectDrawPalette_Release(palette2);
6189 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6190 refcount = IDirectDrawPalette_Release(palette);
6191 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6192 refcount = IDirectDraw_Release(ddraw);
6193 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6194 DestroyWindow(window);
6197 static void test_palette_alpha(void)
6199 IDirectDrawSurface *surface;
6200 DDSURFACEDESC surface_desc;
6201 IDirectDraw *ddraw;
6202 IDirectDrawPalette *palette;
6203 ULONG refcount;
6204 HWND window;
6205 HRESULT hr;
6206 PALETTEENTRY palette_entries[256];
6207 unsigned int i;
6208 static const struct
6210 DWORD caps, flags;
6211 BOOL attach_allowed;
6212 const char *name;
6214 test_data[] =
6216 {DDSCAPS_OFFSCREENPLAIN, DDSD_WIDTH | DDSD_HEIGHT, FALSE, "offscreenplain"},
6217 {DDSCAPS_TEXTURE, DDSD_WIDTH | DDSD_HEIGHT, TRUE, "texture"},
6218 {DDSCAPS_PRIMARYSURFACE, 0, FALSE, "primary"}
6221 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
6222 0, 0, 640, 480, 0, 0, 0, 0);
6223 ddraw = create_ddraw();
6224 ok(!!ddraw, "Failed to create a ddraw object.\n");
6225 if (FAILED(IDirectDraw_SetDisplayMode(ddraw, 640, 480, 8)))
6227 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
6228 IDirectDraw_Release(ddraw);
6229 DestroyWindow(window);
6230 return;
6232 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
6233 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6235 memset(palette_entries, 0, sizeof(palette_entries));
6236 palette_entries[1].peFlags = 0x42;
6237 palette_entries[2].peFlags = 0xff;
6238 palette_entries[3].peFlags = 0x80;
6239 hr = IDirectDraw_CreatePalette(ddraw, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, palette_entries, &palette, NULL);
6240 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
6242 memset(palette_entries, 0x66, sizeof(palette_entries));
6243 hr = IDirectDrawPalette_GetEntries(palette, 0, 1, 4, palette_entries);
6244 ok(SUCCEEDED(hr), "Failed to get palette entries, hr %#x.\n", hr);
6245 ok(palette_entries[0].peFlags == 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
6246 palette_entries[0].peFlags);
6247 ok(palette_entries[1].peFlags == 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
6248 palette_entries[1].peFlags);
6249 ok(palette_entries[2].peFlags == 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
6250 palette_entries[2].peFlags);
6251 ok(palette_entries[3].peFlags == 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
6252 palette_entries[3].peFlags);
6254 IDirectDrawPalette_Release(palette);
6256 memset(palette_entries, 0, sizeof(palette_entries));
6257 palette_entries[1].peFlags = 0x42;
6258 palette_entries[1].peRed = 0xff;
6259 palette_entries[2].peFlags = 0xff;
6260 palette_entries[3].peFlags = 0x80;
6261 hr = IDirectDraw_CreatePalette(ddraw, DDPCAPS_ALLOW256 | DDPCAPS_8BIT | DDPCAPS_ALPHA,
6262 palette_entries, &palette, NULL);
6263 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
6265 memset(palette_entries, 0x66, sizeof(palette_entries));
6266 hr = IDirectDrawPalette_GetEntries(palette, 0, 1, 4, palette_entries);
6267 ok(SUCCEEDED(hr), "Failed to get palette entries, hr %#x.\n", hr);
6268 ok(palette_entries[0].peFlags == 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
6269 palette_entries[0].peFlags);
6270 ok(palette_entries[1].peFlags == 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
6271 palette_entries[1].peFlags);
6272 ok(palette_entries[2].peFlags == 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
6273 palette_entries[2].peFlags);
6274 ok(palette_entries[3].peFlags == 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
6275 palette_entries[3].peFlags);
6277 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); i++)
6279 memset(&surface_desc, 0, sizeof(surface_desc));
6280 surface_desc.dwSize = sizeof(surface_desc);
6281 surface_desc.dwFlags = DDSD_CAPS | test_data[i].flags;
6282 surface_desc.dwWidth = 128;
6283 surface_desc.dwHeight = 128;
6284 surface_desc.ddsCaps.dwCaps = test_data[i].caps;
6285 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
6286 ok(SUCCEEDED(hr), "Failed to create %s surface, hr %#x.\n", test_data[i].name, hr);
6288 hr = IDirectDrawSurface_SetPalette(surface, palette);
6289 if (test_data[i].attach_allowed)
6290 ok(SUCCEEDED(hr), "Failed to attach palette to %s surface, hr %#x.\n", test_data[i].name, hr);
6291 else
6292 ok(hr == DDERR_INVALIDSURFACETYPE, "Got unexpected hr %#x, %s surface.\n", hr, test_data[i].name);
6294 if (SUCCEEDED(hr))
6296 HDC dc;
6297 RGBQUAD rgbquad;
6298 UINT retval;
6300 hr = IDirectDrawSurface_GetDC(surface, &dc);
6301 ok(SUCCEEDED(hr) || broken(hr == DDERR_CANTCREATEDC) /* Win2k testbot */,
6302 "Failed to get DC, hr %#x, %s surface.\n", hr, test_data[i].name);
6303 if (SUCCEEDED(hr))
6305 retval = GetDIBColorTable(dc, 1, 1, &rgbquad);
6306 ok(retval == 1, "GetDIBColorTable returned unexpected result %u.\n", retval);
6307 ok(rgbquad.rgbRed == 0xff, "Expected rgbRed = 0xff, got %#x, %s surface.\n",
6308 rgbquad.rgbRed, test_data[i].name);
6309 ok(rgbquad.rgbGreen == 0, "Expected rgbGreen = 0, got %#x, %s surface.\n",
6310 rgbquad.rgbGreen, test_data[i].name);
6311 ok(rgbquad.rgbBlue == 0, "Expected rgbBlue = 0, got %#x, %s surface.\n",
6312 rgbquad.rgbBlue, test_data[i].name);
6313 todo_wine ok(rgbquad.rgbReserved == 0, "Expected rgbReserved = 0, got %u, %s surface.\n",
6314 rgbquad.rgbReserved, test_data[i].name);
6315 hr = IDirectDrawSurface_ReleaseDC(surface, dc);
6316 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
6319 IDirectDrawSurface_Release(surface);
6322 /* Test INVALIDSURFACETYPE vs INVALIDPIXELFORMAT. */
6323 memset(&surface_desc, 0, sizeof(surface_desc));
6324 surface_desc.dwSize = sizeof(surface_desc);
6325 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
6326 surface_desc.dwWidth = 128;
6327 surface_desc.dwHeight = 128;
6328 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
6329 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
6330 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB;
6331 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount = 32;
6332 U2(surface_desc.ddpfPixelFormat).dwRBitMask = 0x00ff0000;
6333 U3(surface_desc.ddpfPixelFormat).dwGBitMask = 0x0000ff00;
6334 U4(surface_desc.ddpfPixelFormat).dwBBitMask = 0x000000ff;
6335 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
6336 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6337 hr = IDirectDrawSurface_SetPalette(surface, palette);
6338 ok(hr == DDERR_INVALIDSURFACETYPE, "Got unexpected hr %#x.\n", hr);
6339 IDirectDrawSurface_Release(surface);
6341 /* The Windows 8 testbot keeps extra references to the primary
6342 * while in 8 bpp mode. */
6343 hr = IDirectDraw_RestoreDisplayMode(ddraw);
6344 ok(SUCCEEDED(hr), "Failed to restore display mode, hr %#x.\n", hr);
6346 refcount = IDirectDrawPalette_Release(palette);
6347 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6348 refcount = IDirectDraw_Release(ddraw);
6349 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6350 DestroyWindow(window);
6353 static void test_lost_device(void)
6355 IDirectDrawSurface *surface;
6356 DDSURFACEDESC surface_desc;
6357 HWND window1, window2;
6358 IDirectDraw *ddraw;
6359 ULONG refcount;
6360 HRESULT hr;
6361 BOOL ret;
6363 window1 = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
6364 0, 0, 640, 480, 0, 0, 0, 0);
6365 window2 = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
6366 0, 0, 640, 480, 0, 0, 0, 0);
6367 ddraw = create_ddraw();
6368 ok(!!ddraw, "Failed to create a ddraw object.\n");
6369 hr = IDirectDraw_SetCooperativeLevel(ddraw, window1, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
6370 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6372 memset(&surface_desc, 0, sizeof(surface_desc));
6373 surface_desc.dwSize = sizeof(surface_desc);
6374 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
6375 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
6376 surface_desc.dwBackBufferCount = 1;
6377 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
6378 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6380 hr = IDirectDrawSurface_IsLost(surface);
6381 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6382 hr = IDirectDrawSurface_Flip(surface, NULL, DDFLIP_WAIT);
6383 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6385 ret = SetForegroundWindow(GetDesktopWindow());
6386 ok(ret, "Failed to set foreground window.\n");
6387 hr = IDirectDrawSurface_IsLost(surface);
6388 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
6389 hr = IDirectDrawSurface_Flip(surface, NULL, DDFLIP_WAIT);
6390 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
6392 ret = SetForegroundWindow(window1);
6393 ok(ret, "Failed to set foreground window.\n");
6394 hr = IDirectDrawSurface_IsLost(surface);
6395 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
6396 hr = IDirectDrawSurface_Flip(surface, NULL, DDFLIP_WAIT);
6397 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
6399 hr = restore_surfaces(ddraw);
6400 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6401 hr = IDirectDrawSurface_IsLost(surface);
6402 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6403 hr = IDirectDrawSurface_Flip(surface, NULL, DDFLIP_WAIT);
6404 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6406 hr = IDirectDraw_SetCooperativeLevel(ddraw, window1, DDSCL_NORMAL);
6407 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6408 hr = IDirectDrawSurface_IsLost(surface);
6409 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6410 hr = IDirectDrawSurface_Flip(surface, NULL, DDFLIP_WAIT);
6411 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
6413 /* Trying to restore the primary will crash, probably because flippable
6414 * surfaces can't exist in DDSCL_NORMAL. */
6415 IDirectDrawSurface_Release(surface);
6416 memset(&surface_desc, 0, sizeof(surface_desc));
6417 surface_desc.dwSize = sizeof(surface_desc);
6418 surface_desc.dwFlags = DDSD_CAPS;
6419 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
6420 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
6421 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6423 hr = IDirectDrawSurface_IsLost(surface);
6424 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6426 ret = SetForegroundWindow(GetDesktopWindow());
6427 ok(ret, "Failed to set foreground window.\n");
6428 hr = IDirectDrawSurface_IsLost(surface);
6429 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6431 ret = SetForegroundWindow(window1);
6432 ok(ret, "Failed to set foreground window.\n");
6433 hr = IDirectDrawSurface_IsLost(surface);
6434 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6436 hr = IDirectDraw_SetCooperativeLevel(ddraw, window1, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
6437 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6438 hr = IDirectDrawSurface_IsLost(surface);
6439 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
6441 hr = restore_surfaces(ddraw);
6442 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6443 hr = IDirectDrawSurface_IsLost(surface);
6444 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6446 IDirectDrawSurface_Release(surface);
6447 memset(&surface_desc, 0, sizeof(surface_desc));
6448 surface_desc.dwSize = sizeof(surface_desc);
6449 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
6450 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
6451 U5(surface_desc).dwBackBufferCount = 1;
6452 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
6453 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6455 hr = IDirectDraw_SetCooperativeLevel(ddraw, window1, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
6456 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6457 hr = IDirectDrawSurface_IsLost(surface);
6458 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6459 hr = IDirectDrawSurface_Flip(surface, NULL, DDFLIP_WAIT);
6460 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6462 hr = IDirectDraw_SetCooperativeLevel(ddraw, window1, DDSCL_NORMAL | DDSCL_FULLSCREEN);
6463 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6464 hr = IDirectDrawSurface_IsLost(surface);
6465 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6466 hr = IDirectDrawSurface_Flip(surface, NULL, DDFLIP_WAIT);
6467 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
6469 hr = IDirectDraw_SetCooperativeLevel(ddraw, window1, DDSCL_NORMAL);
6470 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6471 hr = IDirectDrawSurface_IsLost(surface);
6472 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6473 hr = IDirectDrawSurface_Flip(surface, NULL, DDFLIP_WAIT);
6474 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
6476 hr = IDirectDraw_SetCooperativeLevel(ddraw, window2, DDSCL_NORMAL);
6477 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6478 hr = IDirectDrawSurface_IsLost(surface);
6479 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6480 hr = IDirectDrawSurface_Flip(surface, NULL, DDFLIP_WAIT);
6481 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
6483 hr = IDirectDraw_SetCooperativeLevel(ddraw, window2, DDSCL_NORMAL | DDSCL_FULLSCREEN);
6484 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6485 hr = IDirectDrawSurface_IsLost(surface);
6486 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6487 hr = IDirectDrawSurface_Flip(surface, NULL, DDFLIP_WAIT);
6488 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
6490 hr = IDirectDraw_SetCooperativeLevel(ddraw, window2, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
6491 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6492 hr = IDirectDrawSurface_IsLost(surface);
6493 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
6494 hr = IDirectDrawSurface_Flip(surface, NULL, DDFLIP_WAIT);
6495 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
6497 IDirectDrawSurface_Release(surface);
6498 refcount = IDirectDraw_Release(ddraw);
6499 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6500 DestroyWindow(window2);
6501 DestroyWindow(window1);
6504 static void test_surface_desc_lock(void)
6506 IDirectDrawSurface *surface;
6507 DDSURFACEDESC surface_desc;
6508 IDirectDraw *ddraw;
6509 ULONG refcount;
6510 HWND window;
6511 HRESULT hr;
6513 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
6514 0, 0, 640, 480, 0, 0, 0, 0);
6515 ddraw = create_ddraw();
6516 ok(!!ddraw, "Failed to create a ddraw object.\n");
6517 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6518 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6520 memset(&surface_desc, 0, sizeof(surface_desc));
6521 surface_desc.dwSize = sizeof(surface_desc);
6522 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
6523 surface_desc.dwWidth = 16;
6524 surface_desc.dwHeight = 16;
6525 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
6526 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
6527 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6529 memset(&surface_desc, 0xaa, sizeof(surface_desc));
6530 surface_desc.dwSize = sizeof(surface_desc);
6531 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
6532 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
6533 ok(!surface_desc.lpSurface, "Got unexpected lpSurface %p.\n", surface_desc.lpSurface);
6535 memset(&surface_desc, 0xaa, sizeof(surface_desc));
6536 surface_desc.dwSize = sizeof(surface_desc);
6537 hr = IDirectDrawSurface_Lock(surface, NULL, &surface_desc, 0, NULL);
6538 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
6539 ok(surface_desc.lpSurface != NULL, "Got unexpected lpSurface %p.\n", surface_desc.lpSurface);
6540 memset(&surface_desc, 0xaa, sizeof(surface_desc));
6541 surface_desc.dwSize = sizeof(surface_desc);
6542 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
6543 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
6544 ok(!surface_desc.lpSurface, "Got unexpected lpSurface %p.\n", surface_desc.lpSurface);
6545 hr = IDirectDrawSurface_Unlock(surface, NULL);
6546 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
6548 memset(&surface_desc, 0xaa, sizeof(surface_desc));
6549 surface_desc.dwSize = sizeof(surface_desc);
6550 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
6551 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
6552 ok(!surface_desc.lpSurface, "Got unexpected lpSurface %p.\n", surface_desc.lpSurface);
6554 IDirectDrawSurface_Release(surface);
6555 refcount = IDirectDraw_Release(ddraw);
6556 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6557 DestroyWindow(window);
6560 static void test_texturemapblend(void)
6562 HRESULT hr;
6563 DDSURFACEDESC ddsd;
6564 D3DEXECUTEBUFFERDESC exec_desc;
6565 DDBLTFX fx;
6566 static RECT rect = {0, 0, 64, 128};
6567 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
6568 DDCOLORKEY ckey;
6569 IDirectDrawSurface *surface, *rt;
6570 IDirect3DTexture *texture;
6571 D3DTEXTUREHANDLE texture_handle;
6572 HWND window;
6573 IDirectDraw *ddraw;
6574 IDirect3DDevice *device;
6575 IDirect3DMaterial *material;
6576 IDirect3DViewport *viewport;
6577 IDirect3DExecuteBuffer *execute_buffer;
6578 UINT inst_length;
6579 void *ptr;
6580 ULONG ref;
6581 D3DCOLOR color;
6583 static const D3DTLVERTEX test1_quads[] =
6585 {{0.0f}, {0.0f}, {0.0f}, {1.0f}, {0xffffffff}, {0}, {0.0f}, {0.0f}},
6586 {{0.0f}, {240.0f}, {0.0f}, {1.0f}, {0xffffffff}, {0}, {0.0f}, {1.0f}},
6587 {{640.0f}, {0.0f}, {0.0f}, {1.0f}, {0xffffffff}, {0}, {1.0f}, {0.0f}},
6588 {{640.0f}, {240.0f}, {0.0f}, {1.0f}, {0xffffffff}, {0}, {1.0f}, {1.0f}},
6589 {{0.0f}, {240.0f}, {0.0f}, {1.0f}, {0x80ffffff}, {0}, {0.0f}, {0.0f}},
6590 {{0.0f}, {480.0f}, {0.0f}, {1.0f}, {0x80ffffff}, {0}, {0.0f}, {1.0f}},
6591 {{640.0f}, {240.0f}, {0.0f}, {1.0f}, {0x80ffffff}, {0}, {1.0f}, {0.0f}},
6592 {{640.0f}, {480.0f}, {0.0f}, {1.0f}, {0x80ffffff}, {0}, {1.0f}, {1.0f}},
6594 test2_quads[] =
6596 {{0.0f}, {0.0f}, {0.0f}, {1.0f}, {0x00ff0080}, {0}, {0.0f}, {0.0f}},
6597 {{0.0f}, {240.0f}, {0.0f}, {1.0f}, {0x00ff0080}, {0}, {0.0f}, {1.0f}},
6598 {{640.0f}, {0.0f}, {0.0f}, {1.0f}, {0x00ff0080}, {0}, {1.0f}, {0.0f}},
6599 {{640.0f}, {240.0f}, {0.0f}, {1.0f}, {0x00ff0080}, {0}, {1.0f}, {1.0f}},
6600 {{0.0f}, {240.0f}, {0.0f}, {1.0f}, {0x008000ff}, {0}, {0.0f}, {0.0f}},
6601 {{0.0f}, {480.0f}, {0.0f}, {1.0f}, {0x008000ff}, {0}, {0.0f}, {1.0f}},
6602 {{640.0f}, {240.0f}, {0.0f}, {1.0f}, {0x008000ff}, {0}, {1.0f}, {0.0f}},
6603 {{640.0f}, {480.0f}, {0.0f}, {1.0f}, {0x008000ff}, {0}, {1.0f}, {1.0f}},
6606 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
6607 0, 0, 640, 480, 0, 0, 0, 0);
6608 ddraw = create_ddraw();
6609 ok(!!ddraw, "Failed to create a ddraw object.\n");
6610 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
6612 skip("Failed to create a 3D device, skipping test.\n");
6613 DestroyWindow(window);
6614 IDirectDraw_Release(ddraw);
6615 return;
6618 hr = IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&rt);
6619 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
6621 material = create_diffuse_material(device, 0.0f, 0.0f, 0.0f, 1.0f);
6622 viewport = create_viewport(device, 0, 0, 640, 480);
6623 viewport_set_background(device, viewport, material);
6625 memset(&exec_desc, 0, sizeof(exec_desc));
6626 exec_desc.dwSize = sizeof(exec_desc);
6627 exec_desc.dwFlags = D3DDEB_BUFSIZE | D3DDEB_CAPS;
6628 exec_desc.dwBufferSize = 1024;
6629 exec_desc.dwCaps = D3DDEBCAPS_SYSTEMMEMORY;
6630 hr = IDirect3DDevice_CreateExecuteBuffer(device, &exec_desc, &execute_buffer, NULL);
6631 ok(SUCCEEDED(hr), "Failed to create execute buffer, hr %#x.\n", hr);
6633 /* Test alpha with DDPF_ALPHAPIXELS texture - should be taken from texture alpha channel.
6635 * The vertex alpha is completely ignored in this case, so case 1 and 2 combined are not
6636 * a D3DTOP_MODULATE with texture alpha = 0xff in case 2 (no alpha in texture). */
6637 memset(&ddsd, 0, sizeof(ddsd));
6638 ddsd.dwSize = sizeof(ddsd);
6639 ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
6640 ddsd.dwHeight = 128;
6641 ddsd.dwWidth = 128;
6642 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
6643 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
6644 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
6645 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 32;
6646 U2(ddsd.ddpfPixelFormat).dwRBitMask = 0x00ff0000;
6647 U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x0000ff00;
6648 U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x000000ff;
6649 U5(ddsd.ddpfPixelFormat).dwRGBAlphaBitMask = 0xff000000;
6650 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &surface, NULL);
6651 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6653 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirect3DTexture, (void **)&texture);
6654 ok(SUCCEEDED(hr), "Failed to get texture interface, hr %#x.\n", hr);
6655 hr = IDirect3DTexture_GetHandle(texture, device, &texture_handle);
6656 ok(SUCCEEDED(hr), "Failed to get texture handle, hr %#x.\n", hr);
6658 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
6659 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
6661 memset(&fx, 0, sizeof(fx));
6662 fx.dwSize = sizeof(fx);
6663 U5(fx).dwFillColor = 0xff0000ff;
6664 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
6665 ok(SUCCEEDED(hr), "Failed to clear texture, hr %#x.\n", hr);
6666 U5(fx).dwFillColor = 0x800000ff;
6667 hr = IDirectDrawSurface_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
6668 ok(SUCCEEDED(hr), "Failed to clear texture, hr %#x.\n", hr);
6670 hr = IDirect3DExecuteBuffer_Lock(execute_buffer, &exec_desc);
6671 ok(SUCCEEDED(hr), "Failed to lock execute buffer, hr %#x.\n", hr);
6673 memcpy(exec_desc.lpData, test1_quads, sizeof(test1_quads));
6675 ptr = ((BYTE *)exec_desc.lpData) + sizeof(test1_quads);
6676 emit_process_vertices(&ptr, D3DPROCESSVERTICES_COPY, 0, 8);
6677 emit_set_rs(&ptr, D3DRENDERSTATE_CULLMODE, D3DCULL_NONE);
6678 emit_set_rs(&ptr, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
6679 emit_set_rs(&ptr, D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);
6680 emit_set_rs(&ptr, D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA);
6681 /* The history of D3DRENDERSTATE_ALPHABLENDENABLE is quite a mess. In the
6682 * first D3D release there was a D3DRENDERSTATE_BLENDENABLE (enum value 27).
6683 * D3D5 introduced a new and separate D3DRENDERSTATE_ALPHABLENDENABLE (42)
6684 * together with D3DRENDERSTATE_COLORKEYENABLE (41). The docs aren't all
6685 * that clear but they mention that D3DRENDERSTATE_BLENDENABLE overrides the
6686 * two new states.
6687 * Then D3D6 came and got rid of the new D3DRENDERSTATE_ALPHABLENDENABLE
6688 * state (42), renaming the older D3DRENDERSTATE_BLENDENABLE enum (27)
6689 * as D3DRENDERSTATE_ALPHABLENDENABLE.
6690 * There is a comment in the D3D6 docs which mentions that hardware
6691 * rasterizers always used D3DRENDERSTATE_BLENDENABLE to just toggle alpha
6692 * blending while prior to D3D5 software rasterizers toggled both color
6693 * keying and alpha blending according to it. What I gather is that, from
6694 * D3D6 onwards, D3DRENDERSTATE_ALPHABLENDENABLE always only toggles the
6695 * alpha blending state.
6696 * These tests seem to show that actual, current hardware follows the D3D6
6697 * behavior even when using the original D3D interfaces, for the HAL device
6698 * at least. */
6699 emit_set_rs(&ptr, D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);
6700 emit_set_rs(&ptr, D3DRENDERSTATE_TEXTUREMAPBLEND, D3DTBLEND_MODULATE);
6701 emit_set_rs(&ptr, D3DRENDERSTATE_TEXTUREHANDLE, texture_handle);
6703 emit_tquad(&ptr, 0);
6704 emit_tquad(&ptr, 4);
6705 emit_end(&ptr);
6707 inst_length = (BYTE *)ptr - (BYTE *)exec_desc.lpData;
6708 inst_length -= sizeof(test1_quads);
6709 hr = IDirect3DExecuteBuffer_Unlock(execute_buffer);
6710 ok(SUCCEEDED(hr), "Failed to unlock execute buffer, hr %#x.\n", hr);
6711 set_execute_data(execute_buffer, 8, sizeof(test1_quads), inst_length);
6713 hr = IDirect3DDevice_BeginScene(device);
6714 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
6715 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_UNCLIPPED);
6716 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
6717 hr = IDirect3DDevice_EndScene(device);
6718 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
6720 color = get_surface_color(rt, 5, 5);
6721 ok(compare_color(color, 0x00000080, 2), "Got unexpected color 0x%08x.\n", color);
6722 color = get_surface_color(rt, 400, 5);
6723 ok(compare_color(color, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color);
6724 color = get_surface_color(rt, 5, 245);
6725 ok(compare_color(color, 0x00000080, 2), "Got unexpected color 0x%08x.\n", color);
6726 color = get_surface_color(rt, 400, 245);
6727 ok(compare_color(color, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color);
6729 IDirect3DTexture_Release(texture);
6730 ref = IDirectDrawSurface_Release(surface);
6731 ok(ref == 0, "Surface not properly released, refcount %u.\n", ref);
6733 /* Test alpha with texture that has no alpha channel - alpha should be taken from diffuse vertex color. */
6734 memset(&ddsd, 0, sizeof(ddsd));
6735 ddsd.dwSize = sizeof(ddsd);
6736 ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
6737 ddsd.dwHeight = 128;
6738 ddsd.dwWidth = 128;
6739 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
6740 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
6741 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
6742 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 32;
6743 U2(ddsd.ddpfPixelFormat).dwRBitMask = 0x00ff0000;
6744 U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x0000ff00;
6745 U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x000000ff;
6747 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &surface, NULL);
6748 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6750 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirect3DTexture, (void **)&texture);
6751 ok(SUCCEEDED(hr), "Failed to get texture interface, hr %#x.\n", hr);
6752 hr = IDirect3DTexture_GetHandle(texture, device, &texture_handle);
6753 ok(SUCCEEDED(hr), "Failed to get texture handle, hr %#x.\n", hr);
6755 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
6756 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
6758 U5(fx).dwFillColor = 0xff0000ff;
6759 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
6760 ok(SUCCEEDED(hr), "Failed to clear texture, hr %#x.\n", hr);
6761 U5(fx).dwFillColor = 0x800000ff;
6762 hr = IDirectDrawSurface_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
6763 ok(SUCCEEDED(hr), "Failed to clear texture, hr %#x.\n", hr);
6765 hr = IDirect3DExecuteBuffer_Lock(execute_buffer, &exec_desc);
6766 ok(SUCCEEDED(hr), "Failed to lock execute buffer, hr %#x.\n", hr);
6768 ptr = ((BYTE *)exec_desc.lpData) + sizeof(test1_quads);
6769 emit_process_vertices(&ptr, D3DPROCESSVERTICES_COPY, 0, 8);
6770 emit_set_rs(&ptr, D3DRENDERSTATE_TEXTUREHANDLE, texture_handle);
6772 emit_tquad(&ptr, 0);
6773 emit_tquad(&ptr, 4);
6774 emit_end(&ptr);
6776 inst_length = (BYTE *)ptr - (BYTE *)exec_desc.lpData;
6777 inst_length -= sizeof(test1_quads);
6778 hr = IDirect3DExecuteBuffer_Unlock(execute_buffer);
6779 ok(SUCCEEDED(hr), "Failed to unlock execute buffer, hr %#x.\n", hr);
6780 set_execute_data(execute_buffer, 8, sizeof(test1_quads), inst_length);
6782 hr = IDirect3DDevice_BeginScene(device);
6783 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
6784 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_UNCLIPPED);
6785 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
6786 hr = IDirect3DDevice_EndScene(device);
6787 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
6789 color = get_surface_color(rt, 5, 5);
6790 ok(compare_color(color, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color);
6791 color = get_surface_color(rt, 400, 5);
6792 ok(compare_color(color, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color);
6793 color = get_surface_color(rt, 5, 245);
6794 ok(compare_color(color, 0x00000080, 2), "Got unexpected color 0x%08x.\n", color);
6795 color = get_surface_color(rt, 400, 245);
6796 ok(compare_color(color, 0x00000080, 2), "Got unexpected color 0x%08x.\n", color);
6798 IDirect3DTexture_Release(texture);
6799 ref = IDirectDrawSurface_Release(surface);
6800 ok(ref == 0, "Surface not properly released, refcount %u.\n", ref);
6802 /* Test RGB - should multiply color components from diffuse vertex color and texture. */
6803 memset(&ddsd, 0, sizeof(ddsd));
6804 ddsd.dwSize = sizeof(ddsd);
6805 ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
6806 ddsd.dwHeight = 128;
6807 ddsd.dwWidth = 128;
6808 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
6809 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
6810 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
6811 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 32;
6812 U2(ddsd.ddpfPixelFormat).dwRBitMask = 0x00ff0000;
6813 U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x0000ff00;
6814 U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x000000ff;
6815 U5(ddsd.ddpfPixelFormat).dwRGBAlphaBitMask = 0xff000000;
6816 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &surface, NULL);
6817 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6819 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirect3DTexture, (void **)&texture);
6820 ok(SUCCEEDED(hr), "Failed to get texture interface, hr %#x.\n", hr);
6821 hr = IDirect3DTexture_GetHandle(texture, device, &texture_handle);
6822 ok(SUCCEEDED(hr), "Failed to get texture handle, hr %#x.\n", hr);
6824 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
6825 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
6827 U5(fx).dwFillColor = 0x00ffffff;
6828 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
6829 ok(SUCCEEDED(hr), "Failed to clear texture, hr %#x.\n", hr);
6830 U5(fx).dwFillColor = 0x00ffff80;
6831 hr = IDirectDrawSurface_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
6832 ok(SUCCEEDED(hr), "Failed to clear texture, hr %#x.\n", hr);
6834 hr = IDirect3DExecuteBuffer_Lock(execute_buffer, &exec_desc);
6835 ok(SUCCEEDED(hr), "Failed to lock execute buffer, hr %#x.\n", hr);
6837 memcpy(exec_desc.lpData, test2_quads, sizeof(test2_quads));
6839 ptr = ((BYTE *)exec_desc.lpData) + sizeof(test2_quads);
6840 emit_process_vertices(&ptr, D3DPROCESSVERTICES_COPY, 0, 8);
6841 emit_set_rs(&ptr, D3DRENDERSTATE_ALPHABLENDENABLE, FALSE);
6842 emit_set_rs(&ptr, D3DRENDERSTATE_TEXTUREHANDLE, texture_handle);
6844 emit_tquad(&ptr, 0);
6845 emit_tquad(&ptr, 4);
6846 emit_end(&ptr);
6848 inst_length = (BYTE *)ptr - (BYTE *)exec_desc.lpData;
6849 inst_length -= sizeof(test2_quads);
6850 hr = IDirect3DExecuteBuffer_Unlock(execute_buffer);
6851 ok(SUCCEEDED(hr), "Failed to unlock execute buffer, hr %#x.\n", hr);
6852 set_execute_data(execute_buffer, 8, sizeof(test2_quads), inst_length);
6854 hr = IDirect3DDevice_BeginScene(device);
6855 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
6856 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_UNCLIPPED);
6857 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
6858 hr = IDirect3DDevice_EndScene(device);
6859 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
6861 /* WARP (Win8 testbot) emulates color keying with the alpha channel like Wine does,
6862 * but even applies it when there's no color key assigned. The surface alpha is zero
6863 * here, so nothing gets drawn.
6865 * The ddraw2 version of this test draws these quads with color keying off due to
6866 * different defaults in ddraw1 and ddraw2. */
6867 color = get_surface_color(rt, 5, 5);
6868 ok(compare_color(color, 0x00ff0040, 2) || broken(compare_color(color, 0x00000000, 1)),
6869 "Got unexpected color 0x%08x.\n", color);
6870 color = get_surface_color(rt, 400, 5);
6871 ok(compare_color(color, 0x00ff0080, 2) || broken(compare_color(color, 0x00000000, 1)),
6872 "Got unexpected color 0x%08x.\n", color);
6873 color = get_surface_color(rt, 5, 245);
6874 ok(compare_color(color, 0x00800080, 2) || broken(compare_color(color, 0x00000000, 1)),
6875 "Got unexpected color 0x%08x.\n", color);
6876 color = get_surface_color(rt, 400, 245);
6877 ok(compare_color(color, 0x008000ff, 2) || broken(compare_color(color, 0x00000000, 1)),
6878 "Got unexpected color 0x%08x.\n", color);
6880 IDirect3DTexture_Release(texture);
6881 ref = IDirectDrawSurface_Release(surface);
6882 ok(ref == 0, "Surface not properly released, refcount %u.\n", ref);
6884 /* Test alpha again, now with color keyed texture (colorkey emulation in wine can interfere). */
6885 memset(&ddsd, 0, sizeof(ddsd));
6886 ddsd.dwSize = sizeof(ddsd);
6887 ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
6888 ddsd.dwHeight = 128;
6889 ddsd.dwWidth = 128;
6890 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
6891 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
6892 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
6893 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 16;
6894 U2(ddsd.ddpfPixelFormat).dwRBitMask = 0xf800;
6895 U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x07e0;
6896 U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x001f;
6898 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &surface, NULL);
6899 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6901 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirect3DTexture, (void **)&texture);
6902 ok(SUCCEEDED(hr), "Failed to get texture interface, hr %#x.\n", hr);
6903 hr = IDirect3DTexture_GetHandle(texture, device, &texture_handle);
6904 ok(SUCCEEDED(hr), "Failed to get texture handle, hr %#x.\n", hr);
6906 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
6907 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
6909 U5(fx).dwFillColor = 0xf800;
6910 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
6911 ok(SUCCEEDED(hr), "Failed to clear texture, hr %#x.\n", hr);
6912 U5(fx).dwFillColor = 0x001f;
6913 hr = IDirectDrawSurface_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
6914 ok(SUCCEEDED(hr), "Failed to clear texture, hr %#x.\n", hr);
6916 ckey.dwColorSpaceLowValue = 0x001f;
6917 ckey.dwColorSpaceHighValue = 0x001f;
6918 hr = IDirectDrawSurface_SetColorKey(surface, DDCKEY_SRCBLT, &ckey);
6919 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
6921 hr = IDirect3DExecuteBuffer_Lock(execute_buffer, &exec_desc);
6922 ok(SUCCEEDED(hr), "Failed to lock execute buffer, hr %#x.\n", hr);
6924 memcpy(exec_desc.lpData, test1_quads, sizeof(test1_quads));
6926 ptr = ((BYTE *)exec_desc.lpData) + sizeof(test1_quads);
6927 emit_process_vertices(&ptr, D3DPROCESSVERTICES_COPY, 0, 8);
6928 emit_set_rs(&ptr, D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);
6929 emit_set_rs(&ptr, D3DRENDERSTATE_TEXTUREHANDLE, texture_handle);
6930 /* D3DRENDERSTATE_COLORKEYENABLE is supposed to be on by default on version
6931 * 1 devices, but for some reason it randomly defaults to FALSE on the W8
6932 * testbot. This is either the fault of Windows 8 or the WARP driver.
6933 * Also D3DRENDERSTATE_COLORKEYENABLE was introduced in D3D 5 aka version 2
6934 * devices only, which might imply this doesn't actually do anything on
6935 * WARP. */
6936 emit_set_rs(&ptr, D3DRENDERSTATE_COLORKEYENABLE, TRUE);
6938 emit_tquad(&ptr, 0);
6939 emit_tquad(&ptr, 4);
6940 emit_end(&ptr);
6942 inst_length = (BYTE *)ptr - (BYTE *)exec_desc.lpData;
6943 inst_length -= sizeof(test1_quads);
6944 hr = IDirect3DExecuteBuffer_Unlock(execute_buffer);
6945 ok(SUCCEEDED(hr), "Failed to unlock execute buffer, hr %#x.\n", hr);
6946 set_execute_data(execute_buffer, 8, sizeof(test1_quads), inst_length);
6948 hr = IDirect3DDevice_BeginScene(device);
6949 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
6950 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_UNCLIPPED);
6951 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
6952 hr = IDirect3DDevice_EndScene(device);
6953 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
6955 /* Allow broken WARP results (colorkey disabled). */
6956 color = get_surface_color(rt, 5, 5);
6957 ok(compare_color(color, 0x00000000, 2) || broken(compare_color(color, 0x000000ff, 2)),
6958 "Got unexpected color 0x%08x.\n", color);
6959 color = get_surface_color(rt, 400, 5);
6960 ok(compare_color(color, 0x00ff0000, 2), "Got unexpected color 0x%08x.\n", color);
6961 color = get_surface_color(rt, 5, 245);
6962 ok(compare_color(color, 0x00000000, 2) || broken(compare_color(color, 0x00000080, 2)),
6963 "Got unexpected color 0x%08x.\n", color);
6964 color = get_surface_color(rt, 400, 245);
6965 ok(compare_color(color, 0x00800000, 2), "Got unexpected color 0x%08x.\n", color);
6967 IDirect3DTexture_Release(texture);
6968 ref = IDirectDrawSurface_Release(surface);
6969 ok(ref == 0, "Surface not properly released, refcount %u.\n", ref);
6971 ref = IDirect3DExecuteBuffer_Release(execute_buffer);
6972 ok(ref == 0, "Execute buffer not properly released, refcount %u.\n", ref);
6973 destroy_viewport(device, viewport);
6974 ref = IDirect3DMaterial_Release(material);
6975 ok(ref == 0, "Material not properly released, refcount %u.\n", ref);
6976 IDirectDrawSurface_Release(rt);
6977 IDirect3DDevice_Release(device);
6978 ref = IDirectDraw_Release(ddraw);
6979 ok(ref == 0, "Ddraw object not properly released, refcount %u.\n", ref);
6980 DestroyWindow(window);
6983 static void test_viewport_clear_rect(void)
6985 HRESULT hr;
6986 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
6987 static D3DRECT clear_rect2 = {{90}, {90}, {110}, {110}};
6988 IDirectDrawSurface *rt;
6989 HWND window;
6990 IDirectDraw *ddraw;
6991 IDirect3DDevice *device;
6992 IDirect3DMaterial *red, *green;
6993 IDirect3DViewport *viewport, *viewport2;
6994 ULONG ref;
6995 D3DCOLOR color;
6997 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
6998 0, 0, 640, 480, 0, 0, 0, 0);
6999 ddraw = create_ddraw();
7000 ok(!!ddraw, "Failed to create a ddraw object.\n");
7001 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
7003 skip("Failed to create a 3D device, skipping test.\n");
7004 DestroyWindow(window);
7005 IDirectDraw_Release(ddraw);
7006 return;
7009 hr = IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&rt);
7010 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
7012 red = create_diffuse_material(device, 1.0f, 0.0f, 0.0f, 1.0f);
7013 viewport = create_viewport(device, 0, 0, 640, 480);
7014 viewport_set_background(device, viewport, red);
7015 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
7016 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
7018 green = create_diffuse_material(device, 0.0f, 1.0f, 0.0f, 1.0f);
7019 viewport2 = create_viewport(device, 100, 100, 20, 20);
7020 viewport_set_background(device, viewport2, green);
7021 hr = IDirect3DViewport_Clear(viewport2, 1, &clear_rect2, D3DCLEAR_TARGET);
7022 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
7024 color = get_surface_color(rt, 85, 85); /* Outside both. */
7025 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
7026 color = get_surface_color(rt, 95, 95); /* Outside vp, inside rect. */
7027 /* AMD GPUs ignore the viewport dimensions and only care about the rectangle. */
7028 ok(compare_color(color, 0x00ff0000, 1) || broken(compare_color(color, 0x0000ff00, 1)),
7029 "Got unexpected color 0x%08x.\n", color);
7030 color = get_surface_color(rt, 105, 105); /* Inside both. */
7031 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
7032 color = get_surface_color(rt, 115, 115); /* Inside vp, outside rect. */
7033 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
7034 color = get_surface_color(rt, 125, 125); /* Outside both. */
7035 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
7037 destroy_viewport(device, viewport2);
7038 destroy_material(green);
7039 destroy_viewport(device, viewport);
7040 destroy_material(red);
7041 IDirectDrawSurface_Release(rt);
7042 IDirect3DDevice_Release(device);
7043 ref = IDirectDraw_Release(ddraw);
7044 ok(ref == 0, "Ddraw object not properly released, refcount %u.\n", ref);
7045 DestroyWindow(window);
7048 static void test_color_fill(void)
7050 HRESULT hr;
7051 IDirect3DDevice *device;
7052 IDirectDraw *ddraw;
7053 IDirectDrawSurface *surface, *surface2;
7054 DDSURFACEDESC surface_desc;
7055 ULONG refcount;
7056 HWND window;
7057 unsigned int i;
7058 DDBLTFX fx;
7059 RECT rect = {5, 5, 7, 7};
7060 DWORD *color;
7061 DWORD num_fourcc_codes, *fourcc_codes;
7062 DDCAPS hal_caps;
7063 BOOL support_uyvy = FALSE, support_yuy2 = FALSE;
7064 static const struct
7066 DWORD caps;
7067 HRESULT colorfill_hr, depthfill_hr;
7068 BOOL rop_success;
7069 const char *name;
7070 DWORD result;
7071 BOOL check_result;
7072 DDPIXELFORMAT format;
7074 tests[] =
7077 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY,
7078 DD_OK, DDERR_INVALIDPARAMS, TRUE, "vidmem offscreenplain RGB", 0xdeadbeef, TRUE,
7080 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
7081 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
7085 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
7086 DD_OK, DDERR_INVALIDPARAMS, TRUE, "sysmem offscreenplain RGB", 0xdeadbeef, TRUE,
7088 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
7089 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
7093 DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY,
7094 DD_OK, DDERR_INVALIDPARAMS, TRUE, "vidmem texture RGB", 0xdeadbeef, TRUE,
7096 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
7097 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
7101 DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY,
7102 DD_OK, DDERR_INVALIDPARAMS, TRUE, "sysmem texture RGB", 0xdeadbeef, TRUE,
7104 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
7105 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
7109 DDSCAPS_ZBUFFER | DDSCAPS_VIDEOMEMORY,
7110 DDERR_INVALIDPARAMS, DD_OK, TRUE, "vidmem zbuffer", 0, FALSE,
7111 {0, 0, 0, {0}, {0}, {0}, {0}, {0}}
7114 /* Colorfill on YUV surfaces always returns DD_OK, but the content is
7115 * different afterwards. DX9+ GPUs set one of the two luminance values
7116 * in each block, but AMD and Nvidia GPUs disagree on which luminance
7117 * value they set. r200 (dx8) just sets the entire block to the clear
7118 * value. */
7119 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY,
7120 DD_OK, DDERR_INVALIDPARAMS, FALSE, "vidmem offscreenplain YUY2", 0, FALSE,
7122 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y', 'U', 'Y', '2'),
7123 {0}, {0}, {0}, {0}, {0}
7127 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY,
7128 DD_OK, DDERR_INVALIDPARAMS, FALSE, "vidmem offscreenplain UYVY", 0, FALSE,
7130 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('U', 'Y', 'V', 'Y'),
7131 {0}, {0}, {0}, {0}, {0}
7135 DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY,
7136 DD_OK, DDERR_INVALIDPARAMS, FALSE, "vidmem overlay YUY2", 0, FALSE,
7138 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y', 'U', 'Y', '2'),
7139 {0}, {0}, {0}, {0}, {0}
7143 DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY,
7144 DD_OK, DDERR_INVALIDPARAMS, FALSE, "vidmem overlay UYVY", 0, FALSE,
7146 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('U', 'Y', 'V', 'Y'),
7147 {0}, {0}, {0}, {0}, {0}
7151 DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY,
7152 E_NOTIMPL, DDERR_INVALIDPARAMS, FALSE, "vidmem texture DXT1", 0, FALSE,
7154 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('D', 'X', 'T', '1'),
7155 {0}, {0}, {0}, {0}, {0}
7159 DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY,
7160 E_NOTIMPL, DDERR_INVALIDPARAMS, FALSE, "sysmem texture DXT1", 0, FALSE,
7162 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('D', 'X', 'T', '1'),
7163 {0}, {0}, {0}, {0}, {0}
7167 /* The testbot fills this with 0x00 instead of the blue channel. The sysmem
7168 * surface works, presumably because it is handled by the runtime instead of
7169 * the driver. */
7170 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY,
7171 DD_OK, DDERR_INVALIDPARAMS, TRUE, "vidmem offscreenplain P8", 0xefefefef, FALSE,
7173 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_PALETTEINDEXED8, 0,
7174 {8}, {0}, {0}, {0}, {0}
7178 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
7179 DD_OK, DDERR_INVALIDPARAMS, TRUE, "sysmem offscreenplain P8", 0xefefefef, TRUE,
7181 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_PALETTEINDEXED8, 0,
7182 {8}, {0}, {0}, {0}, {0}
7186 static const struct
7188 DWORD rop;
7189 const char *name;
7190 HRESULT hr;
7192 rops[] =
7194 {SRCCOPY, "SRCCOPY", DD_OK},
7195 {SRCPAINT, "SRCPAINT", DDERR_NORASTEROPHW},
7196 {SRCAND, "SRCAND", DDERR_NORASTEROPHW},
7197 {SRCINVERT, "SRCINVERT", DDERR_NORASTEROPHW},
7198 {SRCERASE, "SRCERASE", DDERR_NORASTEROPHW},
7199 {NOTSRCCOPY, "NOTSRCCOPY", DDERR_NORASTEROPHW},
7200 {NOTSRCERASE, "NOTSRCERASE", DDERR_NORASTEROPHW},
7201 {MERGECOPY, "MERGECOPY", DDERR_NORASTEROPHW},
7202 {MERGEPAINT, "MERGEPAINT", DDERR_NORASTEROPHW},
7203 {PATCOPY, "PATCOPY", DDERR_NORASTEROPHW},
7204 {PATPAINT, "PATPAINT", DDERR_NORASTEROPHW},
7205 {PATINVERT, "PATINVERT", DDERR_NORASTEROPHW},
7206 {DSTINVERT, "DSTINVERT", DDERR_NORASTEROPHW},
7207 {BLACKNESS, "BLACKNESS", DD_OK},
7208 {WHITENESS, "WHITENESS", DD_OK},
7209 {0xaa0029, "0xaa0029", DDERR_NORASTEROPHW} /* noop */
7212 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
7213 0, 0, 640, 480, 0, 0, 0, 0);
7214 ddraw = create_ddraw();
7215 ok(!!ddraw, "Failed to create a ddraw object.\n");
7216 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
7218 skip("Failed to create a 3D device, skipping test.\n");
7219 DestroyWindow(window);
7220 IDirectDraw_Release(ddraw);
7221 return;
7224 hr = IDirectDraw_GetFourCCCodes(ddraw, &num_fourcc_codes, NULL);
7225 ok(SUCCEEDED(hr), "Failed to get fourcc codes %#x.\n", hr);
7226 fourcc_codes = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
7227 num_fourcc_codes * sizeof(*fourcc_codes));
7228 if (!fourcc_codes)
7229 goto done;
7230 hr = IDirectDraw_GetFourCCCodes(ddraw, &num_fourcc_codes, fourcc_codes);
7231 ok(SUCCEEDED(hr), "Failed to get fourcc codes %#x.\n", hr);
7232 for (i = 0; i < num_fourcc_codes; i++)
7234 if (fourcc_codes[i] == MAKEFOURCC('Y', 'U', 'Y', '2'))
7235 support_yuy2 = TRUE;
7236 else if (fourcc_codes[i] == MAKEFOURCC('U', 'Y', 'V', 'Y'))
7237 support_uyvy = TRUE;
7239 HeapFree(GetProcessHeap(), 0, fourcc_codes);
7241 memset(&hal_caps, 0, sizeof(hal_caps));
7242 hal_caps.dwSize = sizeof(hal_caps);
7243 hr = IDirectDraw_GetCaps(ddraw, &hal_caps, NULL);
7244 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
7246 if ((!support_yuy2 && !support_uyvy) || !(hal_caps.dwCaps & DDCAPS_OVERLAY))
7247 skip("Overlays or some YUV formats not supported, skipping YUV colorfill tests.\n");
7249 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
7251 /* Some Windows drivers modify dwFillColor when it is used on P8 or FourCC formats. */
7252 memset(&fx, 0, sizeof(fx));
7253 fx.dwSize = sizeof(fx);
7254 U5(fx).dwFillColor = 0xdeadbeef;
7256 memset(&surface_desc, 0, sizeof(surface_desc));
7257 surface_desc.dwSize = sizeof(surface_desc);
7258 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
7259 surface_desc.dwWidth = 64;
7260 surface_desc.dwHeight = 64;
7261 surface_desc.ddpfPixelFormat = tests[i].format;
7262 surface_desc.ddsCaps.dwCaps = tests[i].caps;
7264 if (tests[i].caps & DDSCAPS_TEXTURE)
7266 struct format_support_check check = {&tests[i].format, FALSE};
7267 hr = IDirect3DDevice_EnumTextureFormats(device, test_unsupported_formats_cb, &check);
7268 ok(SUCCEEDED(hr), "Failed to enumerate texture formats %#x.\n", hr);
7269 if (!check.supported)
7270 continue;
7273 if (tests[i].format.dwFourCC == MAKEFOURCC('Y','U','Y','2') && !support_yuy2)
7274 continue;
7275 if (tests[i].format.dwFourCC == MAKEFOURCC('U','Y','V','Y') && !support_uyvy)
7276 continue;
7277 if (tests[i].caps & DDSCAPS_OVERLAY && !(hal_caps.dwCaps & DDCAPS_OVERLAY))
7278 continue;
7280 if (tests[i].caps & DDSCAPS_ZBUFFER)
7282 surface_desc.dwFlags &= ~DDSD_PIXELFORMAT;
7283 surface_desc.dwFlags |= DDSD_ZBUFFERBITDEPTH;
7284 U2(surface_desc).dwZBufferBitDepth = get_device_z_depth(device);
7287 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7288 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x, surface %s.\n", hr, tests[i].name);
7290 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
7291 todo_wine_if (tests[i].format.dwFourCC)
7292 ok(hr == tests[i].colorfill_hr, "Blt returned %#x, expected %#x, surface %s.\n",
7293 hr, tests[i].colorfill_hr, tests[i].name);
7295 hr = IDirectDrawSurface_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
7296 todo_wine_if (tests[i].format.dwFourCC)
7297 ok(hr == tests[i].colorfill_hr, "Blt returned %#x, expected %#x, surface %s.\n",
7298 hr, tests[i].colorfill_hr, tests[i].name);
7300 if (SUCCEEDED(hr) && tests[i].check_result)
7302 memset(&surface_desc, 0, sizeof(surface_desc));
7303 surface_desc.dwSize = sizeof(surface_desc);
7304 hr = IDirectDrawSurface_Lock(surface, NULL, &surface_desc, DDLOCK_READONLY, 0);
7305 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x, surface %s.\n", hr, tests[i].name);
7306 color = surface_desc.lpSurface;
7307 ok(*color == tests[i].result, "Got clear result 0x%08x, expected 0x%08x, surface %s.\n",
7308 *color, tests[i].result, tests[i].name);
7309 hr = IDirectDrawSurface_Unlock(surface, NULL);
7310 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, surface %s.\n", hr, tests[i].name);
7313 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
7314 ok(hr == tests[i].depthfill_hr, "Blt returned %#x, expected %#x, surface %s.\n",
7315 hr, tests[i].depthfill_hr, tests[i].name);
7316 hr = IDirectDrawSurface_Blt(surface, &rect, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
7317 ok(hr == tests[i].depthfill_hr, "Blt returned %#x, expected %#x, surface %s.\n",
7318 hr, tests[i].depthfill_hr, tests[i].name);
7320 U5(fx).dwFillColor = 0xdeadbeef;
7321 fx.dwROP = BLACKNESS;
7322 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, NULL, DDBLT_ROP | DDBLT_WAIT, &fx);
7323 ok(FAILED(hr) == !tests[i].rop_success, "Blt returned %#x, expected %s, surface %s.\n",
7324 hr, tests[i].rop_success ? "success" : "failure", tests[i].name);
7325 ok(U5(fx).dwFillColor == 0xdeadbeef, "dwFillColor was set to 0x%08x, surface %s\n",
7326 U5(fx).dwFillColor, tests[i].name);
7328 if (SUCCEEDED(hr) && tests[i].check_result)
7330 memset(&surface_desc, 0, sizeof(surface_desc));
7331 surface_desc.dwSize = sizeof(surface_desc);
7332 hr = IDirectDrawSurface_Lock(surface, NULL, &surface_desc, DDLOCK_READONLY, 0);
7333 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x, surface %s.\n", hr, tests[i].name);
7334 color = surface_desc.lpSurface;
7335 ok(*color == 0, "Got clear result 0x%08x, expected 0x00000000, surface %s.\n",
7336 *color, tests[i].name);
7337 hr = IDirectDrawSurface_Unlock(surface, NULL);
7338 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, surface %s.\n", hr, tests[i].name);
7341 fx.dwROP = WHITENESS;
7342 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, NULL, DDBLT_ROP | DDBLT_WAIT, &fx);
7343 ok(FAILED(hr) == !tests[i].rop_success, "Blt returned %#x, expected %s, surface %s.\n",
7344 hr, tests[i].rop_success ? "success" : "failure", tests[i].name);
7345 ok(U5(fx).dwFillColor == 0xdeadbeef, "dwFillColor was set to 0x%08x, surface %s\n",
7346 U5(fx).dwFillColor, tests[i].name);
7348 if (SUCCEEDED(hr) && tests[i].check_result)
7350 memset(&surface_desc, 0, sizeof(surface_desc));
7351 surface_desc.dwSize = sizeof(surface_desc);
7352 hr = IDirectDrawSurface_Lock(surface, NULL, &surface_desc, DDLOCK_READONLY, 0);
7353 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x, surface %s.\n", hr, tests[i].name);
7354 color = surface_desc.lpSurface;
7355 /* WHITENESS sets the alpha channel to 0x00. Ignore this for now. */
7356 ok((*color & 0x00ffffff) == 0x00ffffff, "Got clear result 0x%08x, expected 0xffffffff, surface %s.\n",
7357 *color, tests[i].name);
7358 hr = IDirectDrawSurface_Unlock(surface, NULL);
7359 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, surface %s.\n", hr, tests[i].name);
7362 IDirectDrawSurface_Release(surface);
7365 memset(&fx, 0, sizeof(fx));
7366 fx.dwSize = sizeof(fx);
7367 U5(fx).dwFillColor = 0xdeadbeef;
7368 fx.dwROP = WHITENESS;
7370 memset(&surface_desc, 0, sizeof(surface_desc));
7371 surface_desc.dwSize = sizeof(surface_desc);
7372 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
7373 surface_desc.dwWidth = 64;
7374 surface_desc.dwHeight = 64;
7375 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
7376 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB;
7377 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount = 32;
7378 U2(surface_desc.ddpfPixelFormat).dwRBitMask = 0x00ff0000;
7379 U3(surface_desc.ddpfPixelFormat).dwGBitMask = 0x0000ff00;
7380 U4(surface_desc.ddpfPixelFormat).dwBBitMask = 0x000000ff;
7381 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
7382 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7383 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7384 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface2, NULL);
7385 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7387 /* No DDBLTFX. */
7388 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, &rect, DDBLT_COLORFILL | DDBLT_WAIT, NULL);
7389 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7390 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, &rect, DDBLT_ROP | DDBLT_WAIT, NULL);
7391 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7393 /* Unused source rectangle. */
7394 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
7395 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7396 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, &rect, DDBLT_ROP | DDBLT_WAIT, &fx);
7397 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7399 /* Unused source surface. */
7400 hr = IDirectDrawSurface_Blt(surface, NULL, surface2, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
7401 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7402 hr = IDirectDrawSurface_Blt(surface, NULL, surface2, NULL, DDBLT_ROP | DDBLT_WAIT, &fx);
7403 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7404 hr = IDirectDrawSurface_Blt(surface, NULL, surface2, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
7405 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7406 hr = IDirectDrawSurface_Blt(surface, NULL, surface2, &rect, DDBLT_ROP | DDBLT_WAIT, &fx);
7407 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7409 /* Inverted destination or source rectangle. */
7410 SetRect(&rect, 5, 7, 7, 5);
7411 hr = IDirectDrawSurface_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
7412 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
7413 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
7414 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7415 hr = IDirectDrawSurface_Blt(surface, &rect, surface2, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
7416 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7417 hr = IDirectDrawSurface_Blt(surface, NULL, surface2, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
7418 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7419 hr = IDirectDrawSurface_Blt(surface, NULL, surface2, &rect, DDBLT_ROP | DDBLT_WAIT, &fx);
7420 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
7422 /* Negative rectangle. */
7423 SetRect(&rect, -1, -1, 5, 5);
7424 hr = IDirectDrawSurface_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
7425 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
7426 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
7427 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7428 hr = IDirectDrawSurface_Blt(surface, &rect, surface2, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
7429 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7430 hr = IDirectDrawSurface_Blt(surface, &rect, surface2, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
7431 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7432 hr = IDirectDrawSurface_Blt(surface, NULL, surface2, &rect, DDBLT_ROP | DDBLT_WAIT, &fx);
7433 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
7435 /* Out of bounds rectangle. */
7436 SetRect(&rect, 0, 0, 65, 65);
7437 hr = IDirectDrawSurface_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
7438 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
7439 hr = IDirectDrawSurface_Blt(surface, NULL, surface2, &rect, DDBLT_ROP | DDBLT_WAIT, &fx);
7440 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
7442 /* Combine multiple flags. */
7443 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
7444 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7445 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_ROP | DDBLT_WAIT, &fx);
7446 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7447 hr = IDirectDrawSurface_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_ROP | DDBLT_WAIT, &fx);
7448 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7450 for (i = 0; i < sizeof(rops) / sizeof(*rops); i++)
7452 fx.dwROP = rops[i].rop;
7453 hr = IDirectDrawSurface_Blt(surface, NULL, surface2, NULL, DDBLT_ROP | DDBLT_WAIT, &fx);
7454 ok(hr == rops[i].hr, "Got unexpected hr %#x for rop %s.\n", hr, rops[i].name);
7457 IDirectDrawSurface_Release(surface2);
7458 IDirectDrawSurface_Release(surface);
7460 memset(&surface_desc, 0, sizeof(surface_desc));
7461 surface_desc.dwSize = sizeof(surface_desc);
7462 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_ZBUFFERBITDEPTH;
7463 surface_desc.dwWidth = 64;
7464 surface_desc.dwHeight = 64;
7465 U2(surface_desc).dwZBufferBitDepth = get_device_z_depth(device);
7466 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
7467 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7468 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7469 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface2, NULL);
7470 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7472 /* No DDBLTFX. */
7473 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, NULL);
7474 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7476 /* Unused source rectangle. */
7477 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
7478 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7480 /* Unused source surface. */
7481 hr = IDirectDrawSurface_Blt(surface, NULL, surface2, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
7482 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7483 hr = IDirectDrawSurface_Blt(surface, NULL, surface2, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
7484 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7486 /* Inverted destination or source rectangle. */
7487 SetRect(&rect, 5, 7, 7, 5);
7488 hr = IDirectDrawSurface_Blt(surface, &rect, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
7489 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
7490 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
7491 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7492 hr = IDirectDrawSurface_Blt(surface, &rect, surface2, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
7493 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7494 hr = IDirectDrawSurface_Blt(surface, NULL, surface2, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
7495 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7497 /* Negative rectangle. */
7498 SetRect(&rect, -1, -1, 5, 5);
7499 hr = IDirectDrawSurface_Blt(surface, &rect, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
7500 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
7501 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
7502 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7503 hr = IDirectDrawSurface_Blt(surface, &rect, surface2, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
7504 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7505 hr = IDirectDrawSurface_Blt(surface, &rect, surface2, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
7506 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7508 /* Out of bounds rectangle. */
7509 SetRect(&rect, 0, 0, 65, 65);
7510 hr = IDirectDrawSurface_Blt(surface, &rect, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
7511 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
7513 /* Combine multiple flags. */
7514 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
7515 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7517 IDirectDrawSurface_Release(surface2);
7518 IDirectDrawSurface_Release(surface);
7520 done:
7521 IDirect3DDevice_Release(device);
7522 refcount = IDirectDraw_Release(ddraw);
7523 ok(refcount == 0, "Ddraw object not properly released, refcount %u.\n", refcount);
7524 DestroyWindow(window);
7527 static void test_colorkey_precision(void)
7529 static D3DTLVERTEX quad[] =
7531 {{ 0.0f}, {480.0f}, {0.0f}, {1.0f}, {0x00000000}, {0x00000000}, {0.0f}, {1.0f}},
7532 {{ 0.0f}, { 0.0f}, {0.0f}, {1.0f}, {0x00000000}, {0x00000000}, {0.0f}, {0.0f}},
7533 {{640.0f}, {480.0f}, {0.0f}, {1.0f}, {0x00000000}, {0x00000000}, {1.0f}, {1.0f}},
7534 {{640.0f}, { 0.0f}, {0.0f}, {1.0f}, {0x00000000}, {0x00000000}, {1.0f}, {0.0f}},
7536 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
7537 IDirect3DDevice *device;
7538 IDirectDraw *ddraw;
7539 IDirectDrawSurface *rt;
7540 IDirect3DViewport *viewport;
7541 IDirect3DExecuteBuffer *execute_buffer;
7542 D3DEXECUTEBUFFERDESC exec_desc;
7543 UINT inst_length;
7544 void *ptr;
7545 HWND window;
7546 HRESULT hr;
7547 IDirectDrawSurface *src, *dst, *texture;
7548 D3DTEXTUREHANDLE handle;
7549 IDirect3DTexture *d3d_texture;
7550 IDirect3DMaterial *green;
7551 DDSURFACEDESC surface_desc, lock_desc;
7552 ULONG refcount;
7553 D3DCOLOR color;
7554 unsigned int t, c;
7555 DDCOLORKEY ckey;
7556 DDBLTFX fx;
7557 DWORD data[4] = {0}, color_mask;
7558 D3DDEVICEDESC device_desc, hel_desc;
7559 BOOL warp;
7560 static const struct
7562 unsigned int max, shift, bpp, clear;
7563 const char *name;
7564 DDPIXELFORMAT fmt;
7566 tests[] =
7569 255, 0, 4, 0x00345678, "D3DFMT_X8R8G8B8",
7571 sizeof(DDPIXELFORMAT), DDPF_RGB, 0,
7572 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0x00000000}
7577 63, 5, 2, 0x5678, "D3DFMT_R5G6B5, G channel",
7579 sizeof(DDPIXELFORMAT), DDPF_RGB, 0,
7580 {16}, {0xf800}, {0x07e0}, {0x001f}, {0x0000}
7585 31, 0, 2, 0x5678, "D3DFMT_R5G6B5, B channel",
7587 sizeof(DDPIXELFORMAT), DDPF_RGB, 0,
7588 {16}, {0xf800}, {0x07e0}, {0x001f}, {0x0000}
7593 15, 0, 2, 0x0678, "D3DFMT_A4R4G4B4",
7595 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
7596 {16}, {0x0f00}, {0x00f0}, {0x000f}, {0xf000}
7602 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
7603 0, 0, 640, 480, 0, 0, 0, 0);
7604 ddraw = create_ddraw();
7605 ok(!!ddraw, "Failed to create a ddraw object.\n");
7606 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
7608 skip("Failed to create a 3D device, skipping test.\n");
7609 DestroyWindow(window);
7610 IDirectDraw_Release(ddraw);
7611 return;
7613 hr = IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&rt);
7614 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
7616 /* The Windows 8 WARP driver has plenty of false negatives in X8R8G8B8
7617 * (color key doesn't match although the values are equal), and a false
7618 * positive when the color key is 0 and the texture contains the value 1.
7619 * I don't want to mark this broken unconditionally since this would
7620 * essentially disable the test on Windows. Try to detect WARP (and I
7621 * guess mismatch other SW renderers) by its ability to texture from
7622 * system memory. Also on random occasions 254 == 255 and 255 != 255.*/
7623 memset(&device_desc, 0, sizeof(device_desc));
7624 device_desc.dwSize = sizeof(device_desc);
7625 memset(&hel_desc, 0, sizeof(hel_desc));
7626 hel_desc.dwSize = sizeof(hel_desc);
7627 hr = IDirect3DDevice_GetCaps(device, &device_desc, &hel_desc);
7628 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
7629 warp = !!(device_desc.dwDevCaps & D3DDEVCAPS_TEXTURESYSTEMMEMORY);
7631 green = create_diffuse_material(device, 0.0f, 1.0f, 0.0f, 0.0f);
7632 viewport = create_viewport(device, 0, 0, 640, 480);
7633 viewport_set_background(device, viewport, green);
7635 memset(&exec_desc, 0, sizeof(exec_desc));
7636 exec_desc.dwSize = sizeof(exec_desc);
7637 exec_desc.dwFlags = D3DDEB_BUFSIZE | D3DDEB_CAPS;
7638 exec_desc.dwBufferSize = 1024;
7639 exec_desc.dwCaps = D3DDEBCAPS_SYSTEMMEMORY;
7640 hr = IDirect3DDevice_CreateExecuteBuffer(device, &exec_desc, &execute_buffer, NULL);
7641 ok(SUCCEEDED(hr), "Failed to create execute buffer, hr %#x.\n", hr);
7643 memset(&fx, 0, sizeof(fx));
7644 fx.dwSize = sizeof(fx);
7645 memset(&lock_desc, 0, sizeof(lock_desc));
7646 lock_desc.dwSize = sizeof(lock_desc);
7648 for (t = 0; t < sizeof(tests) / sizeof(*tests); ++t)
7650 memset(&surface_desc, 0, sizeof(surface_desc));
7651 surface_desc.dwSize = sizeof(surface_desc);
7652 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
7653 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
7654 surface_desc.dwWidth = 4;
7655 surface_desc.dwHeight = 1;
7656 surface_desc.ddpfPixelFormat = tests[t].fmt;
7657 /* Windows XP (at least with the r200 driver, other drivers untested) produces
7658 * garbage when doing color keyed texture->texture blits. */
7659 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &src, NULL);
7660 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7661 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &dst, NULL);
7662 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7664 fx.dwFillColor = tests[t].clear;
7665 /* On the w8 testbot (WARP driver) the blit result has different values in the
7666 * X channel. */
7667 color_mask = U2(tests[t].fmt).dwRBitMask
7668 | U3(tests[t].fmt).dwGBitMask
7669 | U4(tests[t].fmt).dwBBitMask;
7671 for (c = 0; c <= tests[t].max; ++c)
7673 /* The idiotic Nvidia Windows driver can't change the color key on a d3d
7674 * texture after it has been set once... */
7675 surface_desc.dwFlags |= DDSD_CKSRCBLT;
7676 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
7677 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = c << tests[t].shift;
7678 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = c << tests[t].shift;
7679 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &texture, NULL);
7680 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7682 hr = IDirectDrawSurface_QueryInterface(texture, &IID_IDirect3DTexture, (void **)&d3d_texture);
7683 ok(SUCCEEDED(hr), "Failed to get texture interface, hr %#x.\n", hr);
7684 hr = IDirect3DTexture_GetHandle(d3d_texture, device, &handle);
7685 ok(SUCCEEDED(hr), "Failed to get texture handle, hr %#x.\n", hr);
7686 IDirect3DTexture_Release(d3d_texture);
7688 hr = IDirect3DExecuteBuffer_Lock(execute_buffer, &exec_desc);
7689 ok(SUCCEEDED(hr), "Failed to lock execute buffer, hr %#x.\n", hr);
7691 memcpy(exec_desc.lpData, quad, sizeof(quad));
7693 ptr = ((BYTE *)exec_desc.lpData) + sizeof(quad);
7694 emit_process_vertices(&ptr, D3DPROCESSVERTICES_COPY, 0, 8);
7695 emit_set_rs(&ptr, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
7696 emit_set_rs(&ptr, D3DRENDERSTATE_TEXTUREHANDLE, handle);
7697 emit_set_rs(&ptr, D3DRENDERSTATE_TEXTUREMAPBLEND, D3DTBLEND_MODULATEALPHA);
7698 /* D3DRENDERSTATE_COLORKEYENABLE is supposed to be on by default on version
7699 * 1 devices, but for some reason it randomly defaults to FALSE on the W8
7700 * testbot. This is either the fault of Windows 8 or the WARP driver.
7701 * Also D3DRENDERSTATE_COLORKEYENABLE was introduced in D3D 5 aka version 2
7702 * devices only, which might imply this doesn't actually do anything on
7703 * WARP. */
7704 emit_set_rs(&ptr, D3DRENDERSTATE_COLORKEYENABLE, TRUE);
7706 emit_tquad(&ptr, 0);
7707 emit_tquad(&ptr, 4);
7708 emit_set_rs(&ptr, D3DRENDERSTATE_TEXTUREHANDLE, 0);
7709 emit_end(&ptr);
7711 inst_length = (BYTE *)ptr - (BYTE *)exec_desc.lpData;
7712 inst_length -= sizeof(quad);
7713 hr = IDirect3DExecuteBuffer_Unlock(execute_buffer);
7714 ok(SUCCEEDED(hr), "Failed to unlock execute buffer, hr %#x.\n", hr);
7715 set_execute_data(execute_buffer, 8, sizeof(quad), inst_length);
7717 hr = IDirectDrawSurface_Blt(dst, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
7718 ok(SUCCEEDED(hr), "Failed to clear destination surface, hr %#x.\n", hr);
7720 hr = IDirectDrawSurface_Lock(src, NULL, &lock_desc, DDLOCK_WAIT, NULL);
7721 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
7722 switch (tests[t].bpp)
7724 case 4:
7725 ((DWORD *)lock_desc.lpSurface)[0] = (c ? c - 1 : 0) << tests[t].shift;
7726 ((DWORD *)lock_desc.lpSurface)[1] = c << tests[t].shift;
7727 ((DWORD *)lock_desc.lpSurface)[2] = min(c + 1, tests[t].max) << tests[t].shift;
7728 ((DWORD *)lock_desc.lpSurface)[3] = 0xffffffff;
7729 break;
7731 case 2:
7732 ((WORD *)lock_desc.lpSurface)[0] = (c ? c - 1 : 0) << tests[t].shift;
7733 ((WORD *)lock_desc.lpSurface)[1] = c << tests[t].shift;
7734 ((WORD *)lock_desc.lpSurface)[2] = min(c + 1, tests[t].max) << tests[t].shift;
7735 ((WORD *)lock_desc.lpSurface)[3] = 0xffff;
7736 break;
7738 hr = IDirectDrawSurface_Unlock(src, 0);
7739 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
7740 hr = IDirectDrawSurface_Blt(texture, NULL, src, NULL, DDBLT_WAIT, NULL);
7741 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
7743 ckey.dwColorSpaceLowValue = c << tests[t].shift;
7744 ckey.dwColorSpaceHighValue = c << tests[t].shift;
7745 hr = IDirectDrawSurface_SetColorKey(src, DDCKEY_SRCBLT, &ckey);
7746 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
7748 hr = IDirectDrawSurface_Blt(dst, NULL, src, NULL, DDBLT_KEYSRC | DDBLT_WAIT, NULL);
7749 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
7751 /* Don't make this read only, it somehow breaks the detection of the Nvidia bug below. */
7752 hr = IDirectDrawSurface_Lock(dst, NULL, &lock_desc, DDLOCK_WAIT, NULL);
7753 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
7754 switch (tests[t].bpp)
7756 case 4:
7757 data[0] = ((DWORD *)lock_desc.lpSurface)[0] & color_mask;
7758 data[1] = ((DWORD *)lock_desc.lpSurface)[1] & color_mask;
7759 data[2] = ((DWORD *)lock_desc.lpSurface)[2] & color_mask;
7760 data[3] = ((DWORD *)lock_desc.lpSurface)[3] & color_mask;
7761 break;
7763 case 2:
7764 data[0] = ((WORD *)lock_desc.lpSurface)[0] & color_mask;
7765 data[1] = ((WORD *)lock_desc.lpSurface)[1] & color_mask;
7766 data[2] = ((WORD *)lock_desc.lpSurface)[2] & color_mask;
7767 data[3] = ((WORD *)lock_desc.lpSurface)[3] & color_mask;
7768 break;
7770 hr = IDirectDrawSurface_Unlock(dst, 0);
7771 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
7773 if (!c)
7775 ok(data[0] == tests[t].clear, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
7776 tests[t].clear, data[0], tests[t].name, c);
7778 if (data[3] == tests[t].clear)
7780 /* My Geforce GTX 460 on Windows 7 misbehaves when A4R4G4B4 is blitted with color
7781 * keying: The blit takes ~0.5 seconds, and subsequent color keying draws are broken,
7782 * even when a different surface is used. The blit itself doesn't draw anything,
7783 * so we can detect the bug by looking at the otherwise unused 4th texel. It should
7784 * never be masked out by the key.
7786 * Also appears to affect the testbot in some way with R5G6B5. Color keying is
7787 * terrible on WARP. */
7788 skip("Nvidia A4R4G4B4 color keying blit bug detected, skipping.\n");
7789 IDirectDrawSurface_Release(texture);
7790 IDirectDrawSurface_Release(src);
7791 IDirectDrawSurface_Release(dst);
7792 goto done;
7795 else
7796 ok(data[0] == (c - 1) << tests[t].shift, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
7797 (c - 1) << tests[t].shift, data[0], tests[t].name, c);
7799 ok(data[1] == tests[t].clear, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
7800 tests[t].clear, data[1], tests[t].name, c);
7802 if (c == tests[t].max)
7803 ok(data[2] == tests[t].clear, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
7804 tests[t].clear, data[2], tests[t].name, c);
7805 else
7806 ok(data[2] == (c + 1) << tests[t].shift, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
7807 (c + 1) << tests[t].shift, data[2], tests[t].name, c);
7809 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
7810 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
7812 hr = IDirect3DDevice_BeginScene(device);
7813 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
7814 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_UNCLIPPED);
7815 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
7816 hr = IDirect3DDevice_EndScene(device);
7817 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
7819 color = get_surface_color(rt, 80, 240);
7820 if (!c)
7821 ok(compare_color(color, 0x0000ff00, 1) || broken(warp && compare_color(color, 0x00000000, 1)),
7822 "Got unexpected color 0x%08x, format %s, c=%u.\n",
7823 color, tests[t].name, c);
7824 else
7825 ok(compare_color(color, 0x00000000, 1) || broken(warp && compare_color(color, 0x0000ff00, 1)),
7826 "Got unexpected color 0x%08x, format %s, c=%u.\n",
7827 color, tests[t].name, c);
7829 color = get_surface_color(rt, 240, 240);
7830 ok(compare_color(color, 0x0000ff00, 1) || broken(warp && compare_color(color, 0x00000000, 1)),
7831 "Got unexpected color 0x%08x, format %s, c=%u.\n",
7832 color, tests[t].name, c);
7834 color = get_surface_color(rt, 400, 240);
7835 if (c == tests[t].max)
7836 ok(compare_color(color, 0x0000ff00, 1) || broken(warp && compare_color(color, 0x00000000, 1)),
7837 "Got unexpected color 0x%08x, format %s, c=%u.\n",
7838 color, tests[t].name, c);
7839 else
7840 ok(compare_color(color, 0x00000000, 1) || broken(warp && compare_color(color, 0x0000ff00, 1)),
7841 "Got unexpected color 0x%08x, format %s, c=%u.\n",
7842 color, tests[t].name, c);
7844 IDirectDrawSurface_Release(texture);
7846 IDirectDrawSurface_Release(src);
7847 IDirectDrawSurface_Release(dst);
7849 done:
7851 destroy_viewport(device, viewport);
7852 destroy_material(green);
7853 IDirectDrawSurface_Release(rt);
7854 IDirect3DExecuteBuffer_Release(execute_buffer);
7855 IDirect3DDevice_Release(device);
7856 refcount = IDirectDraw_Release(ddraw);
7857 ok(refcount == 0, "Ddraw object not properly released, refcount %u.\n", refcount);
7858 DestroyWindow(window);
7861 static void test_range_colorkey(void)
7863 IDirectDraw *ddraw;
7864 HWND window;
7865 HRESULT hr;
7866 IDirectDrawSurface *surface;
7867 DDSURFACEDESC surface_desc;
7868 ULONG refcount;
7869 DDCOLORKEY ckey;
7871 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
7872 0, 0, 640, 480, 0, 0, 0, 0);
7873 ddraw = create_ddraw();
7874 ok(!!ddraw, "Failed to create a ddraw object.\n");
7875 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
7876 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
7878 memset(&surface_desc, 0, sizeof(surface_desc));
7879 surface_desc.dwSize = sizeof(surface_desc);
7880 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CKSRCBLT;
7881 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
7882 surface_desc.dwWidth = 1;
7883 surface_desc.dwHeight = 1;
7884 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB;
7885 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount = 32;
7886 U2(surface_desc.ddpfPixelFormat).dwRBitMask = 0x00ff0000;
7887 U3(surface_desc.ddpfPixelFormat).dwGBitMask = 0x0000ff00;
7888 U4(surface_desc.ddpfPixelFormat).dwBBitMask = 0x000000ff;
7889 U5(surface_desc.ddpfPixelFormat).dwRGBAlphaBitMask = 0x00000000;
7891 /* Creating a surface with a range color key fails with DDERR_NOCOLORKEY. */
7892 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00000000;
7893 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00000001;
7894 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7895 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
7897 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00000001;
7898 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00000000;
7899 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7900 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
7902 /* Same for DDSCAPS_OFFSCREENPLAIN. */
7903 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
7904 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00000000;
7905 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00000001;
7906 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7907 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
7909 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00000001;
7910 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00000000;
7911 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7912 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
7914 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00000000;
7915 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00000000;
7916 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7917 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7919 /* Setting a range color key without DDCKEY_COLORSPACE collapses the key. */
7920 ckey.dwColorSpaceLowValue = 0x00000000;
7921 ckey.dwColorSpaceHighValue = 0x00000001;
7922 hr = IDirectDrawSurface_SetColorKey(surface, DDCKEY_SRCBLT, &ckey);
7923 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
7925 hr = IDirectDrawSurface_GetColorKey(surface, DDCKEY_SRCBLT, &ckey);
7926 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
7927 ok(!ckey.dwColorSpaceLowValue, "Got unexpected value 0x%08x.\n", ckey.dwColorSpaceLowValue);
7928 ok(!ckey.dwColorSpaceHighValue, "Got unexpected value 0x%08x.\n", ckey.dwColorSpaceHighValue);
7930 ckey.dwColorSpaceLowValue = 0x00000001;
7931 ckey.dwColorSpaceHighValue = 0x00000000;
7932 hr = IDirectDrawSurface_SetColorKey(surface, DDCKEY_SRCBLT, &ckey);
7933 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
7935 hr = IDirectDrawSurface_GetColorKey(surface, DDCKEY_SRCBLT, &ckey);
7936 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
7937 ok(ckey.dwColorSpaceLowValue == 0x00000001, "Got unexpected value 0x%08x.\n", ckey.dwColorSpaceLowValue);
7938 ok(ckey.dwColorSpaceHighValue == 0x00000001, "Got unexpected value 0x%08x.\n", ckey.dwColorSpaceHighValue);
7940 /* DDCKEY_COLORSPACE is ignored if the key is a single value. */
7941 ckey.dwColorSpaceLowValue = 0x00000000;
7942 ckey.dwColorSpaceHighValue = 0x00000000;
7943 hr = IDirectDrawSurface_SetColorKey(surface, DDCKEY_SRCBLT | DDCKEY_COLORSPACE, &ckey);
7944 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
7946 /* Using it with a range key results in DDERR_NOCOLORKEYHW. */
7947 ckey.dwColorSpaceLowValue = 0x00000001;
7948 ckey.dwColorSpaceHighValue = 0x00000000;
7949 hr = IDirectDrawSurface_SetColorKey(surface, DDCKEY_SRCBLT | DDCKEY_COLORSPACE, &ckey);
7950 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
7951 ckey.dwColorSpaceLowValue = 0x00000000;
7952 ckey.dwColorSpaceHighValue = 0x00000001;
7953 hr = IDirectDrawSurface_SetColorKey(surface, DDCKEY_SRCBLT | DDCKEY_COLORSPACE, &ckey);
7954 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
7955 /* Range destination keys don't work either. */
7956 hr = IDirectDrawSurface_SetColorKey(surface, DDCKEY_DESTBLT | DDCKEY_COLORSPACE, &ckey);
7957 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
7959 /* Just to show it's not because of A, R, and G having equal values. */
7960 ckey.dwColorSpaceLowValue = 0x00000000;
7961 ckey.dwColorSpaceHighValue = 0x01010101;
7962 hr = IDirectDrawSurface_SetColorKey(surface, DDCKEY_SRCBLT | DDCKEY_COLORSPACE, &ckey);
7963 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
7965 /* None of these operations modified the key. */
7966 hr = IDirectDrawSurface_GetColorKey(surface, DDCKEY_SRCBLT, &ckey);
7967 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
7968 ok(!ckey.dwColorSpaceLowValue, "Got unexpected value 0x%08x.\n", ckey.dwColorSpaceLowValue);
7969 ok(!ckey.dwColorSpaceHighValue, "Got unexpected value 0x%08x.\n", ckey.dwColorSpaceHighValue);
7971 IDirectDrawSurface_Release(surface),
7972 refcount = IDirectDraw_Release(ddraw);
7973 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7974 DestroyWindow(window);
7977 static void test_shademode(void)
7979 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
7980 IDirect3DExecuteBuffer *execute_buffer;
7981 D3DEXECUTEBUFFERDESC exec_desc;
7982 IDirect3DMaterial *background;
7983 IDirect3DViewport *viewport;
7984 IDirect3DDevice *device;
7985 IDirectDrawSurface *rt;
7986 const D3DLVERTEX *quad;
7987 DWORD color0, color1;
7988 UINT i, inst_length;
7989 IDirectDraw *ddraw;
7990 ULONG refcount;
7991 HWND window;
7992 HRESULT hr;
7993 void *ptr;
7994 static const D3DLVERTEX quad_strip[] =
7996 {{-1.0f}, {-1.0f}, {0.0f}, 0, {0xffff0000}},
7997 {{-1.0f}, { 1.0f}, {0.0f}, 0, {0xff00ff00}},
7998 {{ 1.0f}, {-1.0f}, {0.0f}, 0, {0xff0000ff}},
7999 {{ 1.0f}, { 1.0f}, {0.0f}, 0, {0xffffffff}},
8001 quad_list[] =
8003 {{ 1.0f}, {-1.0f}, {0.0f}, 0, {0xff0000ff}},
8004 {{-1.0f}, {-1.0f}, {0.0f}, 0, {0xffff0000}},
8005 {{-1.0f}, { 1.0f}, {0.0f}, 0, {0xff00ff00}},
8006 {{ 1.0f}, { 1.0f}, {0.0f}, 0, {0xffffffff}},
8008 static const struct
8010 DWORD primtype;
8011 DWORD shademode;
8012 DWORD color0, color1;
8014 tests[] =
8016 {D3DPT_TRIANGLESTRIP, D3DSHADE_FLAT, 0x00ff0000, 0x000000ff},
8017 {D3DPT_TRIANGLESTRIP, D3DSHADE_PHONG, 0x000dca28, 0x000d45c7},
8018 {D3DPT_TRIANGLESTRIP, D3DSHADE_GOURAUD, 0x000dca28, 0x000d45c7},
8019 {D3DPT_TRIANGLESTRIP, D3DSHADE_PHONG, 0x000dca28, 0x000d45c7},
8020 {D3DPT_TRIANGLELIST, D3DSHADE_FLAT, 0x000000ff, 0x0000ff00},
8021 {D3DPT_TRIANGLELIST, D3DSHADE_GOURAUD, 0x000dca28, 0x000d45c7},
8024 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
8025 0, 0, 640, 480, 0, 0, 0, 0);
8026 ddraw = create_ddraw();
8027 ok(!!ddraw, "Failed to create a ddraw object.\n");
8028 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
8030 skip("Failed to create a 3D device, skipping test.\n");
8031 IDirectDraw_Release(ddraw);
8032 DestroyWindow(window);
8033 return;
8036 hr = IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&rt);
8037 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
8039 background = create_diffuse_material(device, 1.0f, 1.0f, 1.0f, 1.0f);
8040 viewport = create_viewport(device, 0, 0, 640, 480);
8041 viewport_set_background(device, viewport, background);
8043 memset(&exec_desc, 0, sizeof(exec_desc));
8044 exec_desc.dwSize = sizeof(exec_desc);
8045 exec_desc.dwFlags = D3DDEB_BUFSIZE | D3DDEB_CAPS;
8046 exec_desc.dwBufferSize = 1024;
8047 exec_desc.dwCaps = D3DDEBCAPS_SYSTEMMEMORY;
8049 hr = IDirect3DDevice_CreateExecuteBuffer(device, &exec_desc, &execute_buffer, NULL);
8050 ok(SUCCEEDED(hr), "Failed to create execute buffer, hr %#x.\n", hr);
8052 /* Try it first with a TRIANGLESTRIP. Do it with different geometry because
8053 * the color fixups we have to do for FLAT shading will be dependent on that. */
8055 for (i = 0; i < sizeof(tests) / sizeof(tests[0]); ++i)
8057 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
8058 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
8060 hr = IDirect3DExecuteBuffer_Lock(execute_buffer, &exec_desc);
8061 ok(SUCCEEDED(hr), "Failed to lock execute buffer, hr %#x.\n", hr);
8063 quad = tests[i].primtype == D3DPT_TRIANGLESTRIP ? quad_strip : quad_list;
8064 memcpy(exec_desc.lpData, quad, sizeof(quad_strip));
8065 ptr = ((BYTE *)exec_desc.lpData) + sizeof(quad_strip);
8066 emit_set_rs(&ptr, D3DRENDERSTATE_CLIPPING, FALSE);
8067 emit_set_rs(&ptr, D3DRENDERSTATE_ZENABLE, FALSE);
8068 emit_set_rs(&ptr, D3DRENDERSTATE_FOGENABLE, FALSE);
8069 emit_set_rs(&ptr, D3DRENDERSTATE_CULLMODE, D3DCULL_NONE);
8070 emit_set_rs(&ptr, D3DRENDERSTATE_SHADEMODE, tests[i].shademode);
8072 emit_process_vertices(&ptr, D3DPROCESSVERTICES_TRANSFORM, 0, 4);
8073 if (tests[i].primtype == D3DPT_TRIANGLESTRIP)
8074 emit_tquad(&ptr, 0);
8075 else
8076 emit_tquad_tlist(&ptr, 0);
8077 emit_end(&ptr);
8078 inst_length = (BYTE *)ptr - (BYTE *)exec_desc.lpData;
8079 inst_length -= sizeof(quad_strip);
8081 hr = IDirect3DExecuteBuffer_Unlock(execute_buffer);
8082 ok(SUCCEEDED(hr), "Failed to unlock execute buffer, hr %#x.\n", hr);
8084 hr = IDirect3DDevice2_BeginScene(device);
8085 set_execute_data(execute_buffer, 4, sizeof(quad_strip), inst_length);
8086 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
8087 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
8088 hr = IDirect3DDevice2_EndScene(device);
8089 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
8091 color0 = get_surface_color(rt, 100, 100); /* Inside first triangle */
8092 color1 = get_surface_color(rt, 500, 350); /* Inside second triangle */
8094 /* For D3DSHADE_FLAT it should take the color of the first vertex of
8095 * each triangle. This requires EXT_provoking_vertex or similar
8096 * functionality being available. */
8097 /* PHONG should be the same as GOURAUD, since no hardware implements
8098 * this. */
8099 ok(compare_color(color0, tests[i].color0, 1), "Test %u shading has color0 %08x, expected %08x.\n",
8100 i, color0, tests[i].color0);
8101 ok(compare_color(color1, tests[i].color1, 1), "Test %u shading has color1 %08x, expected %08x.\n",
8102 i, color1, tests[i].color1);
8105 IDirect3DExecuteBuffer_Release(execute_buffer);
8106 destroy_viewport(device, viewport);
8107 destroy_material(background);
8108 IDirectDrawSurface_Release(rt);
8109 refcount = IDirect3DDevice_Release(device);
8110 ok(!refcount, "Device has %u references left.\n", refcount);
8111 IDirectDraw_Release(ddraw);
8112 DestroyWindow(window);
8115 static void test_lockrect_invalid(void)
8117 unsigned int i, r;
8118 IDirectDraw *ddraw;
8119 IDirectDrawSurface *surface;
8120 HWND window;
8121 HRESULT hr;
8122 DDSURFACEDESC surface_desc;
8123 DDCAPS hal_caps;
8124 DWORD needed_caps = DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY;
8125 static RECT valid[] =
8127 {60, 60, 68, 68},
8128 {60, 60, 60, 68},
8129 {60, 60, 68, 60},
8130 {120, 60, 128, 68},
8131 {60, 120, 68, 128},
8133 static RECT invalid[] =
8135 {68, 60, 60, 68}, /* left > right */
8136 {60, 68, 68, 60}, /* top > bottom */
8137 {-8, 60, 0, 68}, /* left < surface */
8138 {60, -8, 68, 0}, /* top < surface */
8139 {-16, 60, -8, 68}, /* right < surface */
8140 {60, -16, 68, -8}, /* bottom < surface */
8141 {60, 60, 136, 68}, /* right > surface */
8142 {60, 60, 68, 136}, /* bottom > surface */
8143 {136, 60, 144, 68}, /* left > surface */
8144 {60, 136, 68, 144}, /* top > surface */
8146 static const struct
8148 DWORD caps;
8149 const char *name;
8150 HRESULT hr;
8152 resources[] =
8154 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY, "sysmem offscreenplain", DDERR_INVALIDPARAMS},
8155 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, "vidmem offscreenplain", DDERR_INVALIDPARAMS},
8156 {DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, "sysmem texture", DDERR_INVALIDPARAMS},
8157 {DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, "vidmem texture", DDERR_INVALIDPARAMS},
8160 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
8161 0, 0, 640, 480, 0, 0, 0, 0);
8162 ddraw = create_ddraw();
8163 ok(!!ddraw, "Failed to create a ddraw object.\n");
8164 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
8165 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
8167 memset(&hal_caps, 0, sizeof(hal_caps));
8168 hal_caps.dwSize = sizeof(hal_caps);
8169 hr = IDirectDraw_GetCaps(ddraw, &hal_caps, NULL);
8170 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
8171 if ((hal_caps.ddsCaps.dwCaps & needed_caps) != needed_caps)
8173 skip("Required surface types not supported, skipping test.\n");
8174 goto done;
8177 for (r = 0; r < sizeof(resources) / sizeof(*resources); ++r)
8179 memset(&surface_desc, 0, sizeof(surface_desc));
8180 surface_desc.dwSize = sizeof(surface_desc);
8181 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
8182 surface_desc.ddsCaps.dwCaps = resources[r].caps;
8183 surface_desc.dwWidth = 128;
8184 surface_desc.dwHeight = 128;
8185 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
8186 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB;
8187 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount = 32;
8188 U2(surface_desc.ddpfPixelFormat).dwRBitMask = 0xff0000;
8189 U3(surface_desc.ddpfPixelFormat).dwGBitMask = 0x00ff00;
8190 U4(surface_desc.ddpfPixelFormat).dwBBitMask = 0x0000ff;
8192 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8193 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x, type %s.\n", hr, resources[r].name);
8195 hr = IDirectDrawSurface_Lock(surface, NULL, NULL, DDLOCK_WAIT, NULL);
8196 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x, type %s.\n", hr, resources[r].name);
8198 for (i = 0; i < sizeof(valid) / sizeof(*valid); ++i)
8200 RECT *rect = &valid[i];
8202 memset(&surface_desc, 0, sizeof(surface_desc));
8203 surface_desc.dwSize = sizeof(surface_desc);
8205 hr = IDirectDrawSurface_Lock(surface, rect, &surface_desc, DDLOCK_WAIT, NULL);
8206 ok(SUCCEEDED(hr), "Lock failed (%#x) for rect [%d, %d]->[%d, %d], type %s.\n",
8207 hr, rect->left, rect->top, rect->right, rect->bottom, resources[r].name);
8209 hr = IDirectDrawSurface_Unlock(surface, NULL);
8210 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
8213 for (i = 0; i < sizeof(invalid) / sizeof(*invalid); ++i)
8215 RECT *rect = &invalid[i];
8217 memset(&surface_desc, 1, sizeof(surface_desc));
8218 surface_desc.dwSize = sizeof(surface_desc);
8220 hr = IDirectDrawSurface_Lock(surface, rect, &surface_desc, DDLOCK_WAIT, NULL);
8221 ok(hr == resources[r].hr, "Lock returned %#x for rect [%d, %d]->[%d, %d], type %s.\n",
8222 hr, rect->left, rect->top, rect->right, rect->bottom, resources[r].name);
8223 if (SUCCEEDED(hr))
8225 hr = IDirectDrawSurface_Unlock(surface, NULL);
8226 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
8228 else
8229 ok(!surface_desc.lpSurface, "Got unexpected lpSurface %p.\n", surface_desc.lpSurface);
8232 hr = IDirectDrawSurface_Lock(surface, NULL, &surface_desc, DDLOCK_WAIT, NULL);
8233 ok(SUCCEEDED(hr), "Lock(rect = NULL) failed, hr %#x, type %s.\n",
8234 hr, resources[r].name);
8235 hr = IDirectDrawSurface_Lock(surface, NULL, &surface_desc, DDLOCK_WAIT, NULL);
8236 ok(hr == DDERR_SURFACEBUSY, "Double lock(rect = NULL) returned %#x, type %s.\n",
8237 hr, resources[r].name);
8238 hr = IDirectDrawSurface_Unlock(surface, NULL);
8239 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
8241 hr = IDirectDrawSurface_Lock(surface, &valid[0], &surface_desc, DDLOCK_WAIT, NULL);
8242 ok(SUCCEEDED(hr), "Lock(rect = [%d, %d]->[%d, %d]) failed (%#x).\n",
8243 valid[0].left, valid[0].top, valid[0].right, valid[0].bottom, hr);
8244 hr = IDirectDrawSurface_Lock(surface, &valid[0], &surface_desc, DDLOCK_WAIT, NULL);
8245 ok(hr == DDERR_SURFACEBUSY, "Double lock(rect = [%d, %d]->[%d, %d]) failed (%#x).\n",
8246 valid[0].left, valid[0].top, valid[0].right, valid[0].bottom, hr);
8248 /* Locking a different rectangle returns DD_OK, but it seems to break the surface.
8249 * Afterwards unlocking the surface fails(NULL rectangle or both locked rectangles) */
8251 hr = IDirectDrawSurface_Unlock(surface, NULL);
8252 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
8254 IDirectDrawSurface_Release(surface);
8257 done:
8258 IDirectDraw_Release(ddraw);
8259 DestroyWindow(window);
8262 static void test_yv12_overlay(void)
8264 IDirectDrawSurface *src_surface, *dst_surface;
8265 RECT rect = {13, 17, 14, 18};
8266 unsigned int offset, y;
8267 unsigned char *base;
8268 DDSURFACEDESC desc;
8269 IDirectDraw *ddraw;
8270 HWND window;
8271 HRESULT hr;
8273 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
8274 0, 0, 640, 480, 0, 0, 0, 0);
8275 ddraw = create_ddraw();
8276 ok(!!ddraw, "Failed to create a ddraw object.\n");
8277 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
8278 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
8280 if (!(src_surface = create_overlay(ddraw, 256, 256, MAKEFOURCC('Y','V','1','2'))))
8282 skip("Failed to create a YV12 overlay, skipping test.\n");
8283 goto done;
8286 memset(&desc, 0, sizeof(desc));
8287 desc.dwSize = sizeof(desc);
8288 hr = IDirectDrawSurface_Lock(src_surface, NULL, &desc, DDLOCK_WAIT, NULL);
8289 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
8291 ok(desc.dwFlags == (DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_PITCH),
8292 "Got unexpected flags %#x.\n", desc.dwFlags);
8293 ok(desc.ddsCaps.dwCaps == (DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM | DDSCAPS_HWCODEC)
8294 || desc.ddsCaps.dwCaps == (DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM),
8295 "Got unexpected caps %#x.\n", desc.ddsCaps.dwCaps);
8296 ok(desc.dwWidth == 256, "Got unexpected width %u.\n", desc.dwWidth);
8297 ok(desc.dwHeight == 256, "Got unexpected height %u.\n", desc.dwHeight);
8298 /* The overlay pitch seems to have 256 byte alignment. */
8299 ok(!(U1(desc).lPitch & 0xff), "Got unexpected pitch %u.\n", U1(desc).lPitch);
8301 /* Fill the surface with some data for the blit test. */
8302 base = desc.lpSurface;
8303 /* Luminance */
8304 for (y = 0; y < desc.dwHeight; ++y)
8306 memset(base + U1(desc).lPitch * y, 0x10, desc.dwWidth);
8308 /* V */
8309 for (; y < desc.dwHeight + desc.dwHeight / 4; ++y)
8311 memset(base + U1(desc).lPitch * y, 0x20, desc.dwWidth);
8313 /* U */
8314 for (; y < desc.dwHeight + desc.dwHeight / 2; ++y)
8316 memset(base + U1(desc).lPitch * y, 0x30, desc.dwWidth);
8319 hr = IDirectDrawSurface_Unlock(src_surface, NULL);
8320 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
8322 /* YV12 uses 2x2 blocks with 6 bytes per block (4*Y, 1*U, 1*V). Unlike
8323 * other block-based formats like DXT the entire Y channel is stored in
8324 * one big chunk of memory, followed by the chroma channels. So partial
8325 * locks do not really make sense. Show that they are allowed nevertheless
8326 * and the offset points into the luminance data. */
8327 hr = IDirectDrawSurface_Lock(src_surface, &rect, &desc, DDLOCK_WAIT, NULL);
8328 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
8329 offset = ((const unsigned char *)desc.lpSurface - base);
8330 ok(offset == rect.top * U1(desc).lPitch + rect.left, "Got unexpected offset %u, expected %u.\n",
8331 offset, rect.top * U1(desc).lPitch + rect.left);
8332 hr = IDirectDrawSurface_Unlock(src_surface, NULL);
8333 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
8335 if (!(dst_surface = create_overlay(ddraw, 256, 256, MAKEFOURCC('Y','V','1','2'))))
8337 /* Windows XP with a Radeon X1600 GPU refuses to create a second
8338 * overlay surface, DDERR_NOOVERLAYHW, making the blit tests moot. */
8339 skip("Failed to create a second YV12 surface, skipping blit test.\n");
8340 IDirectDrawSurface_Release(src_surface);
8341 goto done;
8344 hr = IDirectDrawSurface_Blt(dst_surface, NULL, src_surface, NULL, DDBLT_WAIT, NULL);
8345 /* VMware rejects YV12 blits. This behavior has not been seen on real
8346 * hardware yet, so mark it broken. */
8347 ok(SUCCEEDED(hr) || broken(hr == E_NOTIMPL), "Failed to blit, hr %#x.\n", hr);
8349 if (SUCCEEDED(hr))
8351 memset(&desc, 0, sizeof(desc));
8352 desc.dwSize = sizeof(desc);
8353 hr = IDirectDrawSurface_Lock(dst_surface, NULL, &desc, DDLOCK_WAIT, NULL);
8354 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
8356 base = desc.lpSurface;
8357 ok(base[0] == 0x10, "Got unexpected Y data 0x%02x.\n", base[0]);
8358 base += desc.dwHeight * U1(desc).lPitch;
8359 todo_wine ok(base[0] == 0x20, "Got unexpected V data 0x%02x.\n", base[0]);
8360 base += desc.dwHeight / 4 * U1(desc).lPitch;
8361 todo_wine ok(base[0] == 0x30, "Got unexpected U data 0x%02x.\n", base[0]);
8363 hr = IDirectDrawSurface_Unlock(dst_surface, NULL);
8364 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
8367 IDirectDrawSurface_Release(dst_surface);
8368 IDirectDrawSurface_Release(src_surface);
8369 done:
8370 IDirectDraw_Release(ddraw);
8371 DestroyWindow(window);
8374 static void test_offscreen_overlay(void)
8376 IDirectDrawSurface *overlay, *offscreen, *primary;
8377 DDSURFACEDESC surface_desc;
8378 IDirectDraw *ddraw;
8379 HWND window;
8380 HRESULT hr;
8381 HDC dc;
8383 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
8384 0, 0, 640, 480, 0, 0, 0, 0);
8385 ddraw = create_ddraw();
8386 ok(!!ddraw, "Failed to create a ddraw object.\n");
8387 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
8388 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
8390 if (!(overlay = create_overlay(ddraw, 64, 64, MAKEFOURCC('U','Y','V','Y'))))
8392 skip("Failed to create a UYVY overlay, skipping test.\n");
8393 goto done;
8396 memset(&surface_desc, 0, sizeof(surface_desc));
8397 surface_desc.dwSize = sizeof(surface_desc);
8398 surface_desc.dwFlags = DDSD_CAPS;
8399 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
8400 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &primary, NULL);
8401 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
8403 /* On Windows 7, and probably Vista, UpdateOverlay() will return
8404 * DDERR_OUTOFCAPS if the dwm is active. Calling GetDC() on the primary
8405 * surface prevents this by disabling the dwm. */
8406 hr = IDirectDrawSurface_GetDC(primary, &dc);
8407 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
8408 hr = IDirectDrawSurface_ReleaseDC(primary, dc);
8409 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
8411 /* Try to overlay a NULL surface. */
8412 hr = IDirectDrawSurface_UpdateOverlay(overlay, NULL, NULL, NULL, DDOVER_SHOW, NULL);
8413 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
8414 hr = IDirectDrawSurface_UpdateOverlay(overlay, NULL, NULL, NULL, DDOVER_HIDE, NULL);
8415 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
8417 /* Try to overlay an offscreen surface. */
8418 memset(&surface_desc, 0, sizeof(surface_desc));
8419 surface_desc.dwSize = sizeof(surface_desc);
8420 surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
8421 surface_desc.dwWidth = 64;
8422 surface_desc.dwHeight = 64;
8423 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
8424 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
8425 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB;
8426 surface_desc.ddpfPixelFormat.dwFourCC = 0;
8427 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount = 16;
8428 U2(surface_desc.ddpfPixelFormat).dwRBitMask = 0xf800;
8429 U3(surface_desc.ddpfPixelFormat).dwGBitMask = 0x07e0;
8430 U4(surface_desc.ddpfPixelFormat).dwBBitMask = 0x001f;
8431 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &offscreen, NULL);
8432 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
8434 hr = IDirectDrawSurface_UpdateOverlay(overlay, NULL, offscreen, NULL, DDOVER_SHOW, NULL);
8435 ok(SUCCEEDED(hr), "Failed to update overlay, hr %#x.\n", hr);
8437 /* Try to overlay the primary with a non-overlay surface. */
8438 hr = IDirectDrawSurface_UpdateOverlay(offscreen, NULL, primary, NULL, DDOVER_SHOW, NULL);
8439 ok(hr == DDERR_NOTAOVERLAYSURFACE, "Got unexpected hr %#x.\n", hr);
8440 hr = IDirectDrawSurface_UpdateOverlay(offscreen, NULL, primary, NULL, DDOVER_HIDE, NULL);
8441 ok(hr == DDERR_NOTAOVERLAYSURFACE, "Got unexpected hr %#x.\n", hr);
8443 IDirectDrawSurface_Release(offscreen);
8444 IDirectDrawSurface_Release(primary);
8445 IDirectDrawSurface_Release(overlay);
8446 done:
8447 IDirectDraw_Release(ddraw);
8448 DestroyWindow(window);
8451 static void test_overlay_rect(void)
8453 IDirectDrawSurface *overlay, *primary;
8454 DDSURFACEDESC surface_desc;
8455 RECT rect = {0, 0, 64, 64};
8456 IDirectDraw *ddraw;
8457 LONG pos_x, pos_y;
8458 HRESULT hr, hr2;
8459 HWND window;
8460 HDC dc;
8462 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
8463 0, 0, 640, 480, 0, 0, 0, 0);
8464 ddraw = create_ddraw();
8465 ok(!!ddraw, "Failed to create a ddraw object.\n");
8466 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
8467 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
8469 if (!(overlay = create_overlay(ddraw, 64, 64, MAKEFOURCC('U','Y','V','Y'))))
8471 skip("Failed to create a UYVY overlay, skipping test.\n");
8472 goto done;
8475 memset(&surface_desc, 0, sizeof(surface_desc));
8476 surface_desc.dwSize = sizeof(surface_desc);
8477 surface_desc.dwFlags = DDSD_CAPS;
8478 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
8479 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &primary, NULL);
8480 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
8482 /* On Windows 7, and probably Vista, UpdateOverlay() will return
8483 * DDERR_OUTOFCAPS if the dwm is active. Calling GetDC() on the primary
8484 * surface prevents this by disabling the dwm. */
8485 hr = IDirectDrawSurface_GetDC(primary, &dc);
8486 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
8487 hr = IDirectDrawSurface_ReleaseDC(primary, dc);
8488 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
8490 /* The dx sdk sort of implies that rect must be set when DDOVER_SHOW is
8491 * used. This is not true in Windows Vista and earlier, but changed in
8492 * Windows 7. */
8493 hr = IDirectDrawSurface_UpdateOverlay(overlay, NULL, primary, &rect, DDOVER_SHOW, NULL);
8494 ok(SUCCEEDED(hr), "Failed to update overlay, hr %#x.\n", hr);
8495 hr = IDirectDrawSurface_UpdateOverlay(overlay, NULL, primary, NULL, DDOVER_HIDE, NULL);
8496 ok(SUCCEEDED(hr), "Failed to update overlay, hr %#x.\n", hr);
8497 hr = IDirectDrawSurface_UpdateOverlay(overlay, NULL, primary, NULL, DDOVER_SHOW, NULL);
8498 ok(hr == DD_OK || hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
8500 /* Show that the overlay position is the (top, left) coordinate of the
8501 * destination rectangle. */
8502 OffsetRect(&rect, 32, 16);
8503 hr = IDirectDrawSurface_UpdateOverlay(overlay, NULL, primary, &rect, DDOVER_SHOW, NULL);
8504 ok(SUCCEEDED(hr), "Failed to update overlay, hr %#x.\n", hr);
8505 pos_x = -1; pos_y = -1;
8506 hr = IDirectDrawSurface_GetOverlayPosition(overlay, &pos_x, &pos_y);
8507 ok(SUCCEEDED(hr), "Failed to get overlay position, hr %#x.\n", hr);
8508 ok(pos_x == rect.left, "Got unexpected pos_x %d, expected %d.\n", pos_x, rect.left);
8509 ok(pos_y == rect.top, "Got unexpected pos_y %d, expected %d.\n", pos_y, rect.top);
8511 /* Passing a NULL dest rect sets the position to 0/0. Visually it can be
8512 * seen that the overlay overlays the whole primary(==screen). */
8513 hr2 = IDirectDrawSurface_UpdateOverlay(overlay, NULL, primary, NULL, 0, NULL);
8514 ok(hr2 == DD_OK || hr2 == DDERR_INVALIDPARAMS || hr2 == DDERR_OUTOFCAPS, "Got unexpected hr %#x.\n", hr2);
8515 hr = IDirectDrawSurface_GetOverlayPosition(overlay, &pos_x, &pos_y);
8516 ok(SUCCEEDED(hr), "Failed to get overlay position, hr %#x.\n", hr);
8517 if (SUCCEEDED(hr2))
8519 ok(!pos_x, "Got unexpected pos_x %d.\n", pos_x);
8520 ok(!pos_y, "Got unexpected pos_y %d.\n", pos_y);
8522 else
8524 ok(pos_x == 32, "Got unexpected pos_x %d.\n", pos_x);
8525 ok(pos_y == 16, "Got unexpected pos_y %d.\n", pos_y);
8528 /* The position cannot be retrieved when the overlay is not shown. */
8529 hr = IDirectDrawSurface_UpdateOverlay(overlay, NULL, primary, &rect, DDOVER_HIDE, NULL);
8530 ok(SUCCEEDED(hr), "Failed to update overlay, hr %#x.\n", hr);
8531 pos_x = -1; pos_y = -1;
8532 hr = IDirectDrawSurface_GetOverlayPosition(overlay, &pos_x, &pos_y);
8533 ok(hr == DDERR_OVERLAYNOTVISIBLE, "Got unexpected hr %#x.\n", hr);
8534 ok(!pos_x, "Got unexpected pos_x %d.\n", pos_x);
8535 ok(!pos_y, "Got unexpected pos_y %d.\n", pos_y);
8537 IDirectDrawSurface_Release(primary);
8538 IDirectDrawSurface_Release(overlay);
8539 done:
8540 IDirectDraw_Release(ddraw);
8541 DestroyWindow(window);
8544 static void test_blt(void)
8546 IDirectDrawSurface *surface, *rt;
8547 DDSURFACEDESC surface_desc;
8548 IDirect3DDevice *device;
8549 IDirectDraw *ddraw;
8550 unsigned int i;
8551 ULONG refcount;
8552 HWND window;
8553 HRESULT hr;
8555 static struct
8557 RECT src_rect;
8558 RECT dst_rect;
8559 HRESULT hr;
8561 test_data[] =
8563 {{160, 0, 640, 480}, { 0, 0, 480, 480}, DD_OK}, /* Overlapped blit. */
8564 {{160, 480, 640, 0}, { 0, 0, 480, 480}, DDERR_INVALIDRECT}, /* Overlapped blit, flipped source. */
8565 {{640, 0, 160, 480}, { 0, 0, 480, 480}, DDERR_INVALIDRECT}, /* Overlapped blit, mirrored source. */
8566 {{160, 0, 480, 480}, { 0, 0, 480, 480}, DD_OK}, /* Overlapped blit, stretched x. */
8567 {{160, 160, 640, 480}, { 0, 0, 480, 480}, DD_OK}, /* Overlapped blit, stretched y. */
8568 {{ 0, 0, 640, 480}, { 0, 0, 640, 480}, DD_OK}, /* Full surface blit. */
8569 {{ 0, 0, 640, 480}, { 0, 480, 640, 0}, DDERR_INVALIDRECT}, /* Full surface, flipped destination. */
8570 {{ 0, 0, 640, 480}, {640, 0, 0, 480}, DDERR_INVALIDRECT}, /* Full surface, mirrored destination. */
8571 {{ 0, 480, 640, 0}, { 0, 0, 640, 480}, DDERR_INVALIDRECT}, /* Full surface, flipped source. */
8572 {{640, 0, 0, 480}, { 0, 0, 640, 480}, DDERR_INVALIDRECT}, /* Full surface, mirrored source. */
8575 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
8576 0, 0, 640, 480, 0, 0, 0, 0);
8577 ddraw = create_ddraw();
8578 ok(!!ddraw, "Failed to create a ddraw object.\n");
8579 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
8581 skip("Failed to create a 3D device, skipping test.\n");
8582 IDirectDraw_Release(ddraw);
8583 DestroyWindow(window);
8584 return;
8587 hr = IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&rt);
8588 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
8590 memset(&surface_desc, 0, sizeof(surface_desc));
8591 surface_desc.dwSize = sizeof(surface_desc);
8592 surface_desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
8593 surface_desc.dwWidth = 640;
8594 surface_desc.dwHeight = 480;
8595 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
8596 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8597 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8599 hr = IDirectDrawSurface_Blt(surface, NULL, surface, NULL, 0, NULL);
8600 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
8602 hr = IDirectDrawSurface_Blt(surface, NULL, rt, NULL, 0, NULL);
8603 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
8605 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
8607 hr = IDirectDrawSurface_Blt(surface, &test_data[i].dst_rect,
8608 surface, &test_data[i].src_rect, DDBLT_WAIT, NULL);
8609 ok(hr == test_data[i].hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, test_data[i].hr);
8611 hr = IDirectDrawSurface_Blt(surface, &test_data[i].dst_rect,
8612 rt, &test_data[i].src_rect, DDBLT_WAIT, NULL);
8613 ok(hr == test_data[i].hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, test_data[i].hr);
8616 IDirectDrawSurface_Release(surface);
8617 IDirectDrawSurface_Release(rt);
8618 refcount = IDirect3DDevice_Release(device);
8619 ok(!refcount, "Device has %u references left.\n", refcount);
8620 IDirectDraw_Release(ddraw);
8621 DestroyWindow(window);
8624 static void test_getdc(void)
8626 IDirectDrawSurface *surface, *surface2, *tmp;
8627 DDSURFACEDESC surface_desc, map_desc;
8628 DDSCAPS caps = {DDSCAPS_COMPLEX};
8629 IDirectDraw *ddraw;
8630 unsigned int i;
8631 HWND window;
8632 HDC dc, dc2;
8633 HRESULT hr;
8635 static const struct
8637 const char *name;
8638 DDPIXELFORMAT format;
8639 BOOL getdc_supported;
8640 HRESULT alt_result;
8642 test_data[] =
8644 {"D3DFMT_A8R8G8B8", {sizeof(test_data->format), DDPF_RGB | DDPF_ALPHAPIXELS, 0, {32},
8645 {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}}, TRUE},
8646 {"D3DFMT_X8R8G8B8", {sizeof(test_data->format), DDPF_RGB, 0, {32},
8647 {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0x00000000}}, TRUE},
8648 {"D3DFMT_R5G6B5", {sizeof(test_data->format), DDPF_RGB, 0, {16},
8649 {0x0000f800}, {0x000007e0}, {0x0000001f}, {0x00000000}}, TRUE},
8650 {"D3DFMT_X1R5G5B5", {sizeof(test_data->format), DDPF_RGB, 0, {16},
8651 {0x00007c00}, {0x000003e0}, {0x0000001f}, {0x00000000}}, TRUE},
8652 {"D3DFMT_A1R5G5B5", {sizeof(test_data->format), DDPF_RGB | DDPF_ALPHAPIXELS, 0, {16},
8653 {0x00007c00}, {0x000003e0}, {0x0000001f}, {0x00008000}}, TRUE},
8654 {"D3DFMT_A4R4G4B4", {sizeof(test_data->format), DDPF_RGB | DDPF_ALPHAPIXELS, 0, {16},
8655 {0x00000f00}, {0x000000f0}, {0x0000000f}, {0x0000f000}}, TRUE, DDERR_CANTCREATEDC /* Vista+ */},
8656 {"D3DFMT_X4R4G4B4", {sizeof(test_data->format), DDPF_RGB, 0, {16},
8657 {0x00000f00}, {0x000000f0}, {0x0000000f}, {0x00000000}}, TRUE, DDERR_CANTCREATEDC /* Vista+ */},
8658 {"D3DFMT_A2R10G10B10", {sizeof(test_data->format), DDPF_RGB | DDPF_ALPHAPIXELS, 0, {32},
8659 {0xc0000000}, {0x3ff00000}, {0x000ffc00}, {0x000003ff}}, TRUE},
8660 {"D3DFMT_A8B8G8R8", {sizeof(test_data->format), DDPF_RGB | DDPF_ALPHAPIXELS, 0, {32},
8661 {0x000000ff}, {0x0000ff00}, {0x00ff0000}, {0xff000000}}, TRUE, DDERR_CANTCREATEDC /* Vista+ */},
8662 {"D3DFMT_X8B8G8R8", {sizeof(test_data->format), DDPF_RGB, 0, {32},
8663 {0x000000ff}, {0x0000ff00}, {0x00ff0000}, {0x00000000}}, TRUE, DDERR_CANTCREATEDC /* Vista+ */},
8664 {"D3DFMT_R3G3B2", {sizeof(test_data->format), DDPF_RGB, 0, {8},
8665 {0x000000e0}, {0x0000001c}, {0x00000003}, {0x00000000}}, FALSE},
8666 /* GetDC() on a P8 surface fails unless the display mode is 8 bpp.
8667 * This is not implemented in wine yet, so disable the test for now.
8668 * Succeeding P8 GetDC() calls are tested in the ddraw:visual test.
8669 {"D3DFMT_P8", {sizeof(test_data->format), DDPF_PALETTEINDEXED8 | DDPF_RGB, 0, {8 },
8670 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
8672 {"D3DFMT_L8", {sizeof(test_data->format), DDPF_LUMINANCE, 0, {8},
8673 {0x000000ff}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
8674 {"D3DFMT_A8L8", {sizeof(test_data->format), DDPF_ALPHAPIXELS | DDPF_LUMINANCE, 0, {16},
8675 {0x000000ff}, {0x00000000}, {0x00000000}, {0x0000ff00}}, FALSE},
8676 {"D3DFMT_DXT1", {sizeof(test_data->format), DDPF_FOURCC, MAKEFOURCC('D','X','T','1'), {0},
8677 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
8678 {"D3DFMT_DXT2", {sizeof(test_data->format), DDPF_FOURCC, MAKEFOURCC('D','X','T','2'), {0},
8679 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
8680 {"D3DFMT_DXT3", {sizeof(test_data->format), DDPF_FOURCC, MAKEFOURCC('D','X','T','3'), {0},
8681 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
8682 {"D3DFMT_DXT4", {sizeof(test_data->format), DDPF_FOURCC, MAKEFOURCC('D','X','T','4'), {0},
8683 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
8684 {"D3DFMT_DXT5", {sizeof(test_data->format), DDPF_FOURCC, MAKEFOURCC('D','X','T','5'), {0},
8685 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
8688 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
8689 0, 0, 640, 480, 0, 0, 0, 0);
8690 ddraw = create_ddraw();
8691 ok(!!ddraw, "Failed to create a ddraw object.\n");
8692 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
8693 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
8695 for (i = 0; i < (sizeof(test_data) / sizeof(*test_data)); ++i)
8697 memset(&surface_desc, 0, sizeof(surface_desc));
8698 surface_desc.dwSize = sizeof(surface_desc);
8699 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
8700 surface_desc.dwWidth = 64;
8701 surface_desc.dwHeight = 64;
8702 U4(surface_desc).ddpfPixelFormat = test_data[i].format;
8703 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
8705 if (FAILED(IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL)))
8707 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
8708 if (FAILED(hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL)))
8710 skip("Failed to create surface for format %s (hr %#x), skipping tests.\n", test_data[i].name, hr);
8711 continue;
8715 dc = (void *)0x1234;
8716 hr = IDirectDrawSurface_GetDC(surface, &dc);
8717 if (test_data[i].getdc_supported)
8718 ok(SUCCEEDED(hr) || (test_data[i].alt_result && hr == test_data[i].alt_result),
8719 "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
8720 else
8721 ok(FAILED(hr), "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
8723 if (SUCCEEDED(hr))
8725 unsigned int width_bytes;
8726 DIBSECTION dib;
8727 HBITMAP bitmap;
8728 DWORD type;
8729 int size;
8731 type = GetObjectType(dc);
8732 ok(type == OBJ_MEMDC, "Got unexpected object type %#x for format %s.\n", type, test_data[i].name);
8733 bitmap = GetCurrentObject(dc, OBJ_BITMAP);
8734 type = GetObjectType(bitmap);
8735 ok(type == OBJ_BITMAP, "Got unexpected object type %#x for format %s.\n", type, test_data[i].name);
8737 size = GetObjectA(bitmap, sizeof(dib), &dib);
8738 ok(size == sizeof(dib), "Got unexpected size %d for format %s.\n", size, test_data[i].name);
8739 ok(!dib.dsBm.bmType, "Got unexpected type %#x for format %s.\n",
8740 dib.dsBm.bmType, test_data[i].name);
8741 ok(dib.dsBm.bmWidth == surface_desc.dwWidth, "Got unexpected width %d for format %s.\n",
8742 dib.dsBm.bmWidth, test_data[i].name);
8743 ok(dib.dsBm.bmHeight == surface_desc.dwHeight, "Got unexpected height %d for format %s.\n",
8744 dib.dsBm.bmHeight, test_data[i].name);
8745 width_bytes = ((dib.dsBm.bmWidth * U1(test_data[i].format).dwRGBBitCount + 31) >> 3) & ~3;
8746 ok(dib.dsBm.bmWidthBytes == width_bytes, "Got unexpected width bytes %d for format %s.\n",
8747 dib.dsBm.bmWidthBytes, test_data[i].name);
8748 ok(dib.dsBm.bmPlanes == 1, "Got unexpected plane count %d for format %s.\n",
8749 dib.dsBm.bmPlanes, test_data[i].name);
8750 ok(dib.dsBm.bmBitsPixel == U1(test_data[i].format).dwRGBBitCount,
8751 "Got unexpected bit count %d for format %s.\n",
8752 dib.dsBm.bmBitsPixel, test_data[i].name);
8753 ok(!!dib.dsBm.bmBits, "Got unexpected bits %p for format %s.\n",
8754 dib.dsBm.bmBits, test_data[i].name);
8756 ok(dib.dsBmih.biSize == sizeof(dib.dsBmih), "Got unexpected size %u for format %s.\n",
8757 dib.dsBmih.biSize, test_data[i].name);
8758 ok(dib.dsBmih.biWidth == surface_desc.dwWidth, "Got unexpected width %d for format %s.\n",
8759 dib.dsBmih.biHeight, test_data[i].name);
8760 ok(dib.dsBmih.biHeight == surface_desc.dwHeight, "Got unexpected height %d for format %s.\n",
8761 dib.dsBmih.biHeight, test_data[i].name);
8762 ok(dib.dsBmih.biPlanes == 1, "Got unexpected plane count %u for format %s.\n",
8763 dib.dsBmih.biPlanes, test_data[i].name);
8764 ok(dib.dsBmih.biBitCount == U1(test_data[i].format).dwRGBBitCount,
8765 "Got unexpected bit count %u for format %s.\n",
8766 dib.dsBmih.biBitCount, test_data[i].name);
8767 ok(dib.dsBmih.biCompression == (U1(test_data[i].format).dwRGBBitCount == 16 ? BI_BITFIELDS : BI_RGB)
8768 || broken(U2(test_data[i].format).dwRGBBitCount == 32 && dib.dsBmih.biCompression == BI_BITFIELDS),
8769 "Got unexpected compression %#x for format %s.\n",
8770 dib.dsBmih.biCompression, test_data[i].name);
8771 ok(!dib.dsBmih.biSizeImage, "Got unexpected image size %u for format %s.\n",
8772 dib.dsBmih.biSizeImage, test_data[i].name);
8773 ok(!dib.dsBmih.biXPelsPerMeter, "Got unexpected horizontal resolution %d for format %s.\n",
8774 dib.dsBmih.biXPelsPerMeter, test_data[i].name);
8775 ok(!dib.dsBmih.biYPelsPerMeter, "Got unexpected vertical resolution %d for format %s.\n",
8776 dib.dsBmih.biYPelsPerMeter, test_data[i].name);
8777 ok(!dib.dsBmih.biClrUsed, "Got unexpected used colour count %u for format %s.\n",
8778 dib.dsBmih.biClrUsed, test_data[i].name);
8779 ok(!dib.dsBmih.biClrImportant, "Got unexpected important colour count %u for format %s.\n",
8780 dib.dsBmih.biClrImportant, test_data[i].name);
8782 if (dib.dsBmih.biCompression == BI_BITFIELDS)
8784 ok((dib.dsBitfields[0] == U2(test_data[i].format).dwRBitMask
8785 && dib.dsBitfields[1] == U3(test_data[i].format).dwGBitMask
8786 && dib.dsBitfields[2] == U4(test_data[i].format).dwBBitMask)
8787 || broken(!dib.dsBitfields[0] && !dib.dsBitfields[1] && !dib.dsBitfields[2]),
8788 "Got unexpected colour masks 0x%08x 0x%08x 0x%08x for format %s.\n",
8789 dib.dsBitfields[0], dib.dsBitfields[1], dib.dsBitfields[2], test_data[i].name);
8791 else
8793 ok(!dib.dsBitfields[0] && !dib.dsBitfields[1] && !dib.dsBitfields[2],
8794 "Got unexpected colour masks 0x%08x 0x%08x 0x%08x for format %s.\n",
8795 dib.dsBitfields[0], dib.dsBitfields[1], dib.dsBitfields[2], test_data[i].name);
8797 ok(!dib.dshSection, "Got unexpected section %p for format %s.\n", dib.dshSection, test_data[i].name);
8798 ok(!dib.dsOffset, "Got unexpected offset %u for format %s.\n", dib.dsOffset, test_data[i].name);
8800 hr = IDirectDrawSurface_ReleaseDC(surface, dc);
8801 ok(hr == DD_OK, "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
8803 else
8805 ok(!dc, "Got unexpected dc %p for format %s.\n", dc, test_data[i].name);
8808 IDirectDrawSurface_Release(surface);
8810 if (FAILED(hr))
8811 continue;
8813 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
8814 if (FAILED(hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL)))
8816 skip("Failed to create mip-mapped texture for format %s (hr %#x), skipping tests.\n",
8817 test_data[i].name, hr);
8818 continue;
8821 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &tmp);
8822 ok(SUCCEEDED(hr), "Failed to get attached surface for format %s, hr %#x.\n", test_data[i].name, hr);
8823 hr = IDirectDrawSurface_GetAttachedSurface(tmp, &caps, &surface2);
8824 ok(SUCCEEDED(hr), "Failed to get attached surface for format %s, hr %#x.\n", test_data[i].name, hr);
8825 IDirectDrawSurface_Release(tmp);
8827 hr = IDirectDrawSurface_GetDC(surface, &dc);
8828 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
8829 hr = IDirectDrawSurface_ReleaseDC(surface, dc);
8830 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
8831 hr = IDirectDrawSurface_GetDC(surface2, &dc);
8832 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
8833 hr = IDirectDrawSurface_ReleaseDC(surface2, dc);
8834 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
8836 hr = IDirectDrawSurface_GetDC(surface, &dc);
8837 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
8838 dc2 = (void *)0x1234;
8839 hr = IDirectDrawSurface_GetDC(surface, &dc2);
8840 ok(hr == DDERR_DCALREADYCREATED, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
8841 ok(dc2 == (void *)0x1234, "Got unexpected dc %p for format %s.\n", dc, test_data[i].name);
8842 hr = IDirectDrawSurface_ReleaseDC(surface, dc);
8843 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
8844 hr = IDirectDrawSurface_ReleaseDC(surface, dc);
8845 ok(hr == DDERR_NODC, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
8847 map_desc.dwSize = sizeof(map_desc);
8848 hr = IDirectDrawSurface_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
8849 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
8850 hr = IDirectDrawSurface_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
8851 ok(hr == DDERR_SURFACEBUSY, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
8852 hr = IDirectDrawSurface_Unlock(surface, NULL);
8853 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
8854 hr = IDirectDrawSurface_Unlock(surface, NULL);
8855 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
8857 hr = IDirectDrawSurface_GetDC(surface, &dc);
8858 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
8859 hr = IDirectDrawSurface_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
8860 ok(hr == DDERR_SURFACEBUSY, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
8861 hr = IDirectDrawSurface_ReleaseDC(surface, dc);
8862 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
8864 hr = IDirectDrawSurface_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
8865 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
8866 hr = IDirectDrawSurface_GetDC(surface, &dc);
8867 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
8868 hr = IDirectDrawSurface_ReleaseDC(surface, dc);
8869 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
8870 hr = IDirectDrawSurface_Unlock(surface, NULL);
8871 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
8873 hr = IDirectDrawSurface_GetDC(surface, &dc);
8874 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
8875 hr = IDirectDrawSurface_GetDC(surface2, &dc2);
8876 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
8877 hr = IDirectDrawSurface_ReleaseDC(surface2, dc2);
8878 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
8879 hr = IDirectDrawSurface_ReleaseDC(surface, dc);
8880 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
8882 hr = IDirectDrawSurface_GetDC(surface2, &dc);
8883 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
8884 hr = IDirectDrawSurface_GetDC(surface, &dc2);
8885 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
8886 hr = IDirectDrawSurface_ReleaseDC(surface, dc2);
8887 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
8888 hr = IDirectDrawSurface_ReleaseDC(surface2, dc);
8889 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
8891 hr = IDirectDrawSurface_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
8892 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
8893 hr = IDirectDrawSurface_Lock(surface2, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
8894 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
8895 hr = IDirectDrawSurface_Unlock(surface2, NULL);
8896 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
8897 hr = IDirectDrawSurface_Unlock(surface, NULL);
8898 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
8900 hr = IDirectDrawSurface_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
8901 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
8902 hr = IDirectDrawSurface_GetDC(surface, &dc);
8903 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
8904 hr = IDirectDrawSurface_ReleaseDC(surface, dc);
8905 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
8906 hr = IDirectDrawSurface_Unlock(surface, NULL);
8907 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
8909 hr = IDirectDrawSurface_Lock(surface2, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
8910 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
8911 hr = IDirectDrawSurface_GetDC(surface, &dc);
8912 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
8913 hr = IDirectDrawSurface_ReleaseDC(surface, dc);
8914 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
8915 hr = IDirectDrawSurface_Unlock(surface2, NULL);
8916 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
8918 hr = IDirectDrawSurface_GetDC(surface, &dc);
8919 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
8920 hr = IDirectDrawSurface_Lock(surface2, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
8921 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
8922 hr = IDirectDrawSurface_Unlock(surface2, NULL);
8923 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
8924 hr = IDirectDrawSurface_ReleaseDC(surface, dc);
8925 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
8927 hr = IDirectDrawSurface_GetDC(surface2, &dc);
8928 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
8929 hr = IDirectDrawSurface_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
8930 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
8931 hr = IDirectDrawSurface_Unlock(surface, NULL);
8932 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
8933 hr = IDirectDrawSurface_ReleaseDC(surface2, dc);
8934 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
8936 hr = IDirectDrawSurface_Unlock(surface, NULL);
8937 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
8938 hr = IDirectDrawSurface_GetDC(surface2, &dc);
8939 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
8940 hr = IDirectDrawSurface_Unlock(surface, NULL);
8941 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
8942 hr = IDirectDrawSurface_ReleaseDC(surface2, dc);
8943 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
8944 hr = IDirectDrawSurface_Unlock(surface, NULL);
8945 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
8947 hr = IDirectDrawSurface_Unlock(surface2, NULL);
8948 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
8949 hr = IDirectDrawSurface_GetDC(surface, &dc);
8950 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
8951 hr = IDirectDrawSurface_Unlock(surface2, NULL);
8952 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
8953 hr = IDirectDrawSurface_ReleaseDC(surface, dc);
8954 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
8955 hr = IDirectDrawSurface_Unlock(surface2, NULL);
8956 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
8958 IDirectDrawSurface_Release(surface2);
8959 IDirectDrawSurface_Release(surface);
8962 IDirectDraw_Release(ddraw);
8963 DestroyWindow(window);
8966 START_TEST(ddraw1)
8968 IDirectDraw *ddraw;
8969 DEVMODEW current_mode;
8971 if (!(ddraw = create_ddraw()))
8973 skip("Failed to create a ddraw object, skipping tests.\n");
8974 return;
8976 IDirectDraw_Release(ddraw);
8978 memset(&current_mode, 0, sizeof(current_mode));
8979 current_mode.dmSize = sizeof(current_mode);
8980 ok(EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &current_mode), "Failed to get display mode.\n");
8981 registry_mode.dmSize = sizeof(registry_mode);
8982 ok(EnumDisplaySettingsW(NULL, ENUM_REGISTRY_SETTINGS, &registry_mode), "Failed to get display mode.\n");
8983 if (registry_mode.dmPelsWidth != current_mode.dmPelsWidth
8984 || registry_mode.dmPelsHeight != current_mode.dmPelsHeight)
8986 skip("Current mode does not match registry mode, skipping test.\n");
8987 return;
8990 test_coop_level_create_device_window();
8991 test_clipper_blt();
8992 test_coop_level_d3d_state();
8993 test_surface_interface_mismatch();
8994 test_coop_level_threaded();
8995 test_viewport();
8996 test_zenable();
8997 test_ck_rgba();
8998 test_ck_default();
8999 test_ck_complex();
9000 test_surface_qi();
9001 test_device_qi();
9002 test_wndproc();
9003 test_window_style();
9004 test_redundant_mode_set();
9005 test_coop_level_mode_set();
9006 test_coop_level_mode_set_multi();
9007 test_initialize();
9008 test_coop_level_surf_create();
9009 test_coop_level_multi_window();
9010 test_clear_rect_count();
9011 test_coop_level_activateapp();
9012 test_unsupported_formats();
9013 test_rt_caps();
9014 test_primary_caps();
9015 test_surface_lock();
9016 test_surface_discard();
9017 test_flip();
9018 test_sysmem_overlay();
9019 test_primary_palette();
9020 test_surface_attachment();
9021 test_pixel_format();
9022 test_create_surface_pitch();
9023 test_mipmap();
9024 test_palette_complex();
9025 test_p8_rgb_blit();
9026 test_material();
9027 test_lighting();
9028 test_palette_gdi();
9029 test_palette_alpha();
9030 test_lost_device();
9031 test_surface_desc_lock();
9032 test_texturemapblend();
9033 test_viewport_clear_rect();
9034 test_color_fill();
9035 test_colorkey_precision();
9036 test_range_colorkey();
9037 test_shademode();
9038 test_lockrect_invalid();
9039 test_yv12_overlay();
9040 test_offscreen_overlay();
9041 test_overlay_rect();
9042 test_blt();
9043 test_getdc();