ddraw/tests: Spelling fixes in comments and an ok() message.
[wine.git] / dlls / ddraw / tests / ddraw1.c
blob4f53ee10594c7ad051a74f9dc9f240ed284a468e
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 <limits.h>
24 #include <math.h>
25 #include "d3d.h"
27 static BOOL is_ddraw64 = sizeof(DWORD) != sizeof(DWORD *);
28 static DEVMODEW registry_mode;
30 static HRESULT (WINAPI *pDwmIsCompositionEnabled)(BOOL *);
32 #ifndef ARRAY_SIZE
33 #define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
34 #endif
36 struct vec4
38 float x, y, z, w;
41 struct create_window_thread_param
43 HWND window;
44 HANDLE window_created;
45 HANDLE destroy_window;
46 HANDLE thread;
49 static BOOL compare_color(D3DCOLOR c1, D3DCOLOR c2, BYTE max_diff)
51 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
52 c1 >>= 8; c2 >>= 8;
53 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
54 c1 >>= 8; c2 >>= 8;
55 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
56 c1 >>= 8; c2 >>= 8;
57 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
58 return TRUE;
61 static BOOL compare_float(float f, float g, unsigned int ulps)
63 int x = *(int *)&f;
64 int y = *(int *)&g;
66 if (x < 0)
67 x = INT_MIN - x;
68 if (y < 0)
69 y = INT_MIN - y;
71 if (abs(x - y) > ulps)
72 return FALSE;
74 return TRUE;
77 static BOOL compare_vec4(const struct vec4 *vec, float x, float y, float z, float w, unsigned int ulps)
79 return compare_float(vec->x, x, ulps)
80 && compare_float(vec->y, y, ulps)
81 && compare_float(vec->z, z, ulps)
82 && compare_float(vec->w, w, ulps);
85 static BOOL ddraw_is_warp(IDirectDraw *ddraw)
87 IDirectDraw4 *ddraw4;
88 DDDEVICEIDENTIFIER identifier;
89 HRESULT hr;
91 if (!strcmp(winetest_platform, "wine"))
92 return FALSE;
94 hr = IDirectDraw_QueryInterface(ddraw, &IID_IDirectDraw4, (void **)&ddraw4);
95 ok(SUCCEEDED(hr), "Failed to get IDirectDraw4 interface, hr %#x.\n", hr);
96 hr = IDirectDraw4_GetDeviceIdentifier(ddraw4, &identifier, 0);
97 ok(SUCCEEDED(hr), "Failed to get device identifier, hr %#x.\n", hr);
98 IDirectDraw4_Release(ddraw4);
100 return !!strstr(identifier.szDriver, "warp");
103 static BOOL ddraw_is_nvidia(IDirectDraw *ddraw)
105 IDirectDraw4 *ddraw4;
106 DDDEVICEIDENTIFIER identifier;
107 HRESULT hr;
109 if (!strcmp(winetest_platform, "wine"))
110 return FALSE;
112 hr = IDirectDraw_QueryInterface(ddraw, &IID_IDirectDraw4, (void **)&ddraw4);
113 ok(SUCCEEDED(hr), "Failed to get IDirectDraw4 interface, hr %#x.\n", hr);
114 hr = IDirectDraw4_GetDeviceIdentifier(ddraw4, &identifier, 0);
115 ok(SUCCEEDED(hr), "Failed to get device identifier, hr %#x.\n", hr);
116 IDirectDraw4_Release(ddraw4);
118 return identifier.dwVendorId == 0x10de;
121 static BOOL ddraw_is_intel(IDirectDraw *ddraw)
123 IDirectDraw4 *ddraw4;
124 DDDEVICEIDENTIFIER identifier;
125 HRESULT hr;
127 if (!strcmp(winetest_platform, "wine"))
128 return FALSE;
130 hr = IDirectDraw_QueryInterface(ddraw, &IID_IDirectDraw4, (void **)&ddraw4);
131 ok(SUCCEEDED(hr), "Failed to get IDirectDraw4 interface, hr %#x.\n", hr);
132 hr = IDirectDraw4_GetDeviceIdentifier(ddraw4, &identifier, 0);
133 ok(SUCCEEDED(hr), "Failed to get device identifier, hr %#x.\n", hr);
134 IDirectDraw4_Release(ddraw4);
136 return identifier.dwVendorId == 0x8086;
139 static IDirectDrawSurface *create_overlay(IDirectDraw *ddraw,
140 unsigned int width, unsigned int height, DWORD format)
142 IDirectDrawSurface *surface;
143 DDSURFACEDESC desc;
145 memset(&desc, 0, sizeof(desc));
146 desc.dwSize = sizeof(desc);
147 desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
148 desc.dwWidth = width;
149 desc.dwHeight = height;
150 desc.ddsCaps.dwCaps = DDSCAPS_OVERLAY;
151 desc.ddpfPixelFormat.dwSize = sizeof(desc.ddpfPixelFormat);
152 desc.ddpfPixelFormat.dwFlags = DDPF_FOURCC;
153 desc.ddpfPixelFormat.dwFourCC = format;
155 if (FAILED(IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL)))
156 return NULL;
157 return surface;
160 static DWORD WINAPI create_window_thread_proc(void *param)
162 struct create_window_thread_param *p = param;
163 DWORD res;
164 BOOL ret;
166 p->window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
167 0, 0, 640, 480, 0, 0, 0, 0);
168 ret = SetEvent(p->window_created);
169 ok(ret, "SetEvent failed, last error %#x.\n", GetLastError());
171 for (;;)
173 MSG msg;
175 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
176 DispatchMessageA(&msg);
177 res = WaitForSingleObject(p->destroy_window, 100);
178 if (res == WAIT_OBJECT_0)
179 break;
180 if (res != WAIT_TIMEOUT)
182 ok(0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
183 break;
187 DestroyWindow(p->window);
189 return 0;
192 static void create_window_thread(struct create_window_thread_param *p)
194 DWORD res, tid;
196 p->window_created = CreateEventA(NULL, FALSE, FALSE, NULL);
197 ok(!!p->window_created, "CreateEvent failed, last error %#x.\n", GetLastError());
198 p->destroy_window = CreateEventA(NULL, FALSE, FALSE, NULL);
199 ok(!!p->destroy_window, "CreateEvent failed, last error %#x.\n", GetLastError());
200 p->thread = CreateThread(NULL, 0, create_window_thread_proc, p, 0, &tid);
201 ok(!!p->thread, "Failed to create thread, last error %#x.\n", GetLastError());
202 res = WaitForSingleObject(p->window_created, INFINITE);
203 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
206 static void destroy_window_thread(struct create_window_thread_param *p)
208 SetEvent(p->destroy_window);
209 WaitForSingleObject(p->thread, INFINITE);
210 CloseHandle(p->destroy_window);
211 CloseHandle(p->window_created);
212 CloseHandle(p->thread);
215 static HRESULT set_display_mode(IDirectDraw *ddraw, DWORD width, DWORD height)
217 if (SUCCEEDED(IDirectDraw_SetDisplayMode(ddraw, width, height, 32)))
218 return DD_OK;
219 return IDirectDraw_SetDisplayMode(ddraw, width, height, 24);
222 static D3DCOLOR get_surface_color(IDirectDrawSurface *surface, UINT x, UINT y)
224 RECT rect = {x, y, x + 1, y + 1};
225 DDSURFACEDESC surface_desc;
226 D3DCOLOR color;
227 HRESULT hr;
229 memset(&surface_desc, 0, sizeof(surface_desc));
230 surface_desc.dwSize = sizeof(surface_desc);
232 hr = IDirectDrawSurface_Lock(surface, &rect, &surface_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
233 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
234 if (FAILED(hr))
235 return 0xdeadbeef;
237 color = *((DWORD *)surface_desc.lpSurface) & 0x00ffffff;
239 hr = IDirectDrawSurface_Unlock(surface, NULL);
240 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
242 return color;
245 static void emit_process_vertices(void **ptr, DWORD flags, WORD base_idx, DWORD vertex_count)
247 D3DINSTRUCTION *inst = *ptr;
248 D3DPROCESSVERTICES *pv = (D3DPROCESSVERTICES *)(inst + 1);
250 inst->bOpcode = D3DOP_PROCESSVERTICES;
251 inst->bSize = sizeof(*pv);
252 inst->wCount = 1;
254 pv->dwFlags = flags;
255 pv->wStart = base_idx;
256 pv->wDest = 0;
257 pv->dwCount = vertex_count;
258 pv->dwReserved = 0;
260 *ptr = pv + 1;
263 static void emit_set_ts(void **ptr, D3DTRANSFORMSTATETYPE state, DWORD value)
265 D3DINSTRUCTION *inst = *ptr;
266 D3DSTATE *ts = (D3DSTATE *)(inst + 1);
268 inst->bOpcode = D3DOP_STATETRANSFORM;
269 inst->bSize = sizeof(*ts);
270 inst->wCount = 1;
272 U1(*ts).dtstTransformStateType = state;
273 U2(*ts).dwArg[0] = value;
275 *ptr = ts + 1;
278 static void emit_set_ls(void **ptr, D3DLIGHTSTATETYPE state, DWORD value)
280 D3DINSTRUCTION *inst = *ptr;
281 D3DSTATE *ls = (D3DSTATE *)(inst + 1);
283 inst->bOpcode = D3DOP_STATELIGHT;
284 inst->bSize = sizeof(*ls);
285 inst->wCount = 1;
287 U1(*ls).dlstLightStateType = state;
288 U2(*ls).dwArg[0] = value;
290 *ptr = ls + 1;
293 static void emit_set_rs(void **ptr, D3DRENDERSTATETYPE state, DWORD value)
295 D3DINSTRUCTION *inst = *ptr;
296 D3DSTATE *rs = (D3DSTATE *)(inst + 1);
298 inst->bOpcode = D3DOP_STATERENDER;
299 inst->bSize = sizeof(*rs);
300 inst->wCount = 1;
302 U1(*rs).drstRenderStateType = state;
303 U2(*rs).dwArg[0] = value;
305 *ptr = rs + 1;
308 static void emit_tquad(void **ptr, WORD base_idx)
310 D3DINSTRUCTION *inst = *ptr;
311 D3DTRIANGLE *tri = (D3DTRIANGLE *)(inst + 1);
313 inst->bOpcode = D3DOP_TRIANGLE;
314 inst->bSize = sizeof(*tri);
315 inst->wCount = 2;
317 U1(*tri).v1 = base_idx;
318 U2(*tri).v2 = base_idx + 1;
319 U3(*tri).v3 = base_idx + 2;
320 tri->wFlags = D3DTRIFLAG_START;
321 ++tri;
323 U1(*tri).v1 = base_idx + 2;
324 U2(*tri).v2 = base_idx + 1;
325 U3(*tri).v3 = base_idx + 3;
326 tri->wFlags = D3DTRIFLAG_ODD;
327 ++tri;
329 *ptr = tri;
332 static void emit_tquad_tlist(void **ptr, WORD base_idx)
334 D3DINSTRUCTION *inst = *ptr;
335 D3DTRIANGLE *tri = (D3DTRIANGLE *)(inst + 1);
337 inst->bOpcode = D3DOP_TRIANGLE;
338 inst->bSize = sizeof(*tri);
339 inst->wCount = 2;
341 U1(*tri).v1 = base_idx;
342 U2(*tri).v2 = base_idx + 1;
343 U3(*tri).v3 = base_idx + 2;
344 tri->wFlags = D3DTRIFLAG_START;
345 ++tri;
347 U1(*tri).v1 = base_idx + 2;
348 U2(*tri).v2 = base_idx + 3;
349 U3(*tri).v3 = base_idx;
350 tri->wFlags = D3DTRIFLAG_START;
351 ++tri;
353 *ptr = tri;
356 static void emit_texture_load(void **ptr, D3DTEXTUREHANDLE dst_texture,
357 D3DTEXTUREHANDLE src_texture)
359 D3DINSTRUCTION *instruction = *ptr;
360 D3DTEXTURELOAD *texture_load = (D3DTEXTURELOAD *)(instruction + 1);
362 instruction->bOpcode = D3DOP_TEXTURELOAD;
363 instruction->bSize = sizeof(*texture_load);
364 instruction->wCount = 1;
366 texture_load->hDestTexture = dst_texture;
367 texture_load->hSrcTexture = src_texture;
368 ++texture_load;
370 *ptr = texture_load;
373 static void emit_end(void **ptr)
375 D3DINSTRUCTION *inst = *ptr;
377 inst->bOpcode = D3DOP_EXIT;
378 inst->bSize = 0;
379 inst->wCount = 0;
381 *ptr = inst + 1;
384 static void set_execute_data(IDirect3DExecuteBuffer *execute_buffer, UINT vertex_count, UINT offset, UINT len)
386 D3DEXECUTEDATA exec_data;
387 HRESULT hr;
389 memset(&exec_data, 0, sizeof(exec_data));
390 exec_data.dwSize = sizeof(exec_data);
391 exec_data.dwVertexCount = vertex_count;
392 exec_data.dwInstructionOffset = offset;
393 exec_data.dwInstructionLength = len;
394 hr = IDirect3DExecuteBuffer_SetExecuteData(execute_buffer, &exec_data);
395 ok(SUCCEEDED(hr), "Failed to set execute data, hr %#x.\n", hr);
398 static DWORD get_device_z_depth(IDirect3DDevice *device)
400 DDSCAPS caps = {DDSCAPS_ZBUFFER};
401 IDirectDrawSurface *ds, *rt;
402 DDSURFACEDESC desc;
403 HRESULT hr;
405 if (FAILED(IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&rt)))
406 return 0;
408 hr = IDirectDrawSurface_GetAttachedSurface(rt, &caps, &ds);
409 IDirectDrawSurface_Release(rt);
410 if (FAILED(hr))
411 return 0;
413 desc.dwSize = sizeof(desc);
414 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
415 IDirectDrawSurface_Release(ds);
416 if (FAILED(hr))
417 return 0;
419 return U2(desc).dwZBufferBitDepth;
422 static IDirectDraw *create_ddraw(void)
424 IDirectDraw *ddraw;
426 if (FAILED(DirectDrawCreate(NULL, &ddraw, NULL)))
427 return NULL;
429 return ddraw;
432 static IDirect3DDevice *create_device(IDirectDraw *ddraw, HWND window, DWORD coop_level)
434 static const DWORD z_depths[] = {32, 24, 16};
435 IDirectDrawSurface *surface, *ds;
436 IDirect3DDevice *device = NULL;
437 DDSURFACEDESC surface_desc;
438 unsigned int i;
439 HRESULT hr;
441 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, coop_level);
442 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
444 memset(&surface_desc, 0, sizeof(surface_desc));
445 surface_desc.dwSize = sizeof(surface_desc);
446 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
447 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
448 surface_desc.dwWidth = 640;
449 surface_desc.dwHeight = 480;
451 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
452 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
454 if (coop_level & DDSCL_NORMAL)
456 IDirectDrawClipper *clipper;
458 hr = IDirectDraw_CreateClipper(ddraw, 0, &clipper, NULL);
459 ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr);
460 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
461 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
462 hr = IDirectDrawSurface_SetClipper(surface, clipper);
463 ok(SUCCEEDED(hr), "Failed to set surface clipper, hr %#x.\n", hr);
464 IDirectDrawClipper_Release(clipper);
467 /* We used to use EnumDevices() for this, but it seems
468 * D3DDEVICEDESC.dwDeviceZBufferBitDepth only has a very casual
469 * relationship with reality. */
470 for (i = 0; i < sizeof(z_depths) / sizeof(*z_depths); ++i)
472 memset(&surface_desc, 0, sizeof(surface_desc));
473 surface_desc.dwSize = sizeof(surface_desc);
474 surface_desc.dwFlags = DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_WIDTH | DDSD_HEIGHT;
475 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
476 U2(surface_desc).dwZBufferBitDepth = z_depths[i];
477 surface_desc.dwWidth = 640;
478 surface_desc.dwHeight = 480;
479 if (FAILED(IDirectDraw_CreateSurface(ddraw, &surface_desc, &ds, NULL)))
480 continue;
482 hr = IDirectDrawSurface_AddAttachedSurface(surface, ds);
483 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
484 IDirectDrawSurface_Release(ds);
485 if (FAILED(hr))
486 continue;
488 if (SUCCEEDED(IDirectDrawSurface_QueryInterface(surface, &IID_IDirect3DHALDevice, (void **)&device)))
489 break;
491 IDirectDrawSurface_DeleteAttachedSurface(surface, 0, ds);
494 IDirectDrawSurface_Release(surface);
495 return device;
498 static IDirect3DViewport *create_viewport(IDirect3DDevice *device, UINT x, UINT y, UINT w, UINT h)
500 IDirect3DViewport *viewport;
501 D3DVIEWPORT vp;
502 IDirect3D *d3d;
503 HRESULT hr;
505 hr = IDirect3DDevice_GetDirect3D(device, &d3d);
506 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
507 hr = IDirect3D_CreateViewport(d3d, &viewport, NULL);
508 ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
509 hr = IDirect3DDevice_AddViewport(device, viewport);
510 ok(SUCCEEDED(hr), "Failed to add viewport, hr %#x.\n", hr);
511 memset(&vp, 0, sizeof(vp));
512 vp.dwSize = sizeof(vp);
513 vp.dwX = x;
514 vp.dwY = y;
515 vp.dwWidth = w;
516 vp.dwHeight = h;
517 vp.dvScaleX = (float)w / 2.0f;
518 vp.dvScaleY = (float)h / 2.0f;
519 vp.dvMaxX = 1.0f;
520 vp.dvMaxY = 1.0f;
521 vp.dvMinZ = 0.0f;
522 vp.dvMaxZ = 1.0f;
523 hr = IDirect3DViewport_SetViewport(viewport, &vp);
524 ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
525 IDirect3D_Release(d3d);
527 return viewport;
530 static void viewport_set_background(IDirect3DDevice *device, IDirect3DViewport *viewport,
531 IDirect3DMaterial *material)
533 D3DMATERIALHANDLE material_handle;
534 HRESULT hr;
536 hr = IDirect3DMaterial2_GetHandle(material, device, &material_handle);
537 ok(SUCCEEDED(hr), "Failed to get material handle, hr %#x.\n", hr);
538 hr = IDirect3DViewport2_SetBackground(viewport, material_handle);
539 ok(SUCCEEDED(hr), "Failed to set viewport background, hr %#x.\n", hr);
542 static void destroy_viewport(IDirect3DDevice *device, IDirect3DViewport *viewport)
544 HRESULT hr;
546 hr = IDirect3DDevice_DeleteViewport(device, viewport);
547 ok(SUCCEEDED(hr), "Failed to delete viewport, hr %#x.\n", hr);
548 IDirect3DViewport_Release(viewport);
551 static IDirect3DMaterial *create_material(IDirect3DDevice *device, D3DMATERIAL *mat)
553 IDirect3DMaterial *material;
554 IDirect3D *d3d;
555 HRESULT hr;
557 hr = IDirect3DDevice_GetDirect3D(device, &d3d);
558 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
559 hr = IDirect3D_CreateMaterial(d3d, &material, NULL);
560 ok(SUCCEEDED(hr), "Failed to create material, hr %#x.\n", hr);
561 hr = IDirect3DMaterial_SetMaterial(material, mat);
562 ok(SUCCEEDED(hr), "Failed to set material data, hr %#x.\n", hr);
563 IDirect3D_Release(d3d);
565 return material;
568 static IDirect3DMaterial *create_diffuse_material(IDirect3DDevice *device, float r, float g, float b, float a)
570 D3DMATERIAL mat;
572 memset(&mat, 0, sizeof(mat));
573 mat.dwSize = sizeof(mat);
574 U1(U(mat).diffuse).r = r;
575 U2(U(mat).diffuse).g = g;
576 U3(U(mat).diffuse).b = b;
577 U4(U(mat).diffuse).a = a;
579 return create_material(device, &mat);
582 static IDirect3DMaterial *create_emissive_material(IDirect3DDevice *device, float r, float g, float b, float a)
584 D3DMATERIAL mat;
586 memset(&mat, 0, sizeof(mat));
587 mat.dwSize = sizeof(mat);
588 U1(U3(mat).emissive).r = r;
589 U2(U3(mat).emissive).g = g;
590 U3(U3(mat).emissive).b = b;
591 U4(U3(mat).emissive).a = a;
593 return create_material(device, &mat);
596 static void destroy_material(IDirect3DMaterial *material)
598 IDirect3DMaterial_Release(material);
601 struct message
603 UINT message;
604 BOOL check_wparam;
605 WPARAM expect_wparam;
608 static const struct message *expect_messages;
610 static LRESULT CALLBACK test_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
612 if (expect_messages && message == expect_messages->message)
614 if (expect_messages->check_wparam)
615 ok (wparam == expect_messages->expect_wparam,
616 "Got unexpected wparam %lx for message %x, expected %lx.\n",
617 wparam, message, expect_messages->expect_wparam);
619 ++expect_messages;
622 return DefWindowProcA(hwnd, message, wparam, lparam);
625 /* Set the wndproc back to what ddraw expects it to be, and release the ddraw
626 * interface. This prevents subsequent SetCooperativeLevel() calls on a
627 * different window from failing with DDERR_HWNDALREADYSET. */
628 static void fix_wndproc(HWND window, LONG_PTR proc)
630 IDirectDraw *ddraw;
631 HRESULT hr;
633 if (!(ddraw = create_ddraw()))
634 return;
636 SetWindowLongPtrA(window, GWLP_WNDPROC, proc);
637 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
638 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
639 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
640 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
642 IDirectDraw_Release(ddraw);
645 static HRESULT CALLBACK restore_callback(IDirectDrawSurface *surface, DDSURFACEDESC *desc, void *context)
647 HRESULT hr = IDirectDrawSurface_Restore(surface);
648 ok(SUCCEEDED(hr) || hr == DDERR_IMPLICITLYCREATED, "Failed to restore surface, hr %#x.\n", hr);
649 IDirectDrawSurface_Release(surface);
651 return DDENUMRET_OK;
654 static HRESULT restore_surfaces(IDirectDraw *ddraw)
656 return IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
657 NULL, NULL, restore_callback);
660 static void test_coop_level_create_device_window(void)
662 HWND focus_window, device_window;
663 IDirectDraw *ddraw;
664 HRESULT hr;
666 focus_window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
667 0, 0, 640, 480, 0, 0, 0, 0);
668 ddraw = create_ddraw();
669 ok(!!ddraw, "Failed to create a ddraw object.\n");
671 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
672 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
673 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
674 ok(!device_window, "Unexpected device window found.\n");
675 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW);
676 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
677 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
678 ok(!device_window, "Unexpected device window found.\n");
679 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_NORMAL);
680 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
681 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
682 ok(!device_window, "Unexpected device window found.\n");
683 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_NORMAL | DDSCL_FULLSCREEN);
684 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
685 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
686 ok(!device_window, "Unexpected device window found.\n");
687 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
688 ok(hr == DDERR_NOFOCUSWINDOW || broken(hr == DDERR_INVALIDPARAMS), "Got unexpected hr %#x.\n", hr);
689 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
690 ok(!device_window, "Unexpected device window found.\n");
692 /* Windows versions before 98 / NT5 don't support DDSCL_CREATEDEVICEWINDOW. */
693 if (broken(hr == DDERR_INVALIDPARAMS))
695 win_skip("DDSCL_CREATEDEVICEWINDOW not supported, skipping test.\n");
696 IDirectDraw_Release(ddraw);
697 DestroyWindow(focus_window);
698 return;
701 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
702 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
703 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
704 ok(!device_window, "Unexpected device window found.\n");
705 hr = IDirectDraw_SetCooperativeLevel(ddraw, focus_window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
706 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
707 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
708 ok(!device_window, "Unexpected device window found.\n");
710 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
711 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
712 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
713 ok(!device_window, "Unexpected device window found.\n");
714 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_SETFOCUSWINDOW
715 | DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
716 ok(hr == DDERR_NOHWND, "Got unexpected hr %#x.\n", hr);
717 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
718 ok(!!device_window, "Device window not found.\n");
720 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
721 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
722 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
723 ok(!device_window, "Unexpected device window found.\n");
724 hr = IDirectDraw_SetCooperativeLevel(ddraw, focus_window, DDSCL_SETFOCUSWINDOW
725 | DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
726 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
727 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
728 ok(!!device_window, "Device window not found.\n");
730 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
731 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
732 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
733 ok(!device_window, "Unexpected device window found.\n");
734 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
735 ok(hr == DDERR_NOFOCUSWINDOW, "Got unexpected hr %#x.\n", hr);
736 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
737 ok(!device_window, "Unexpected device window found.\n");
738 hr = IDirectDraw_SetCooperativeLevel(ddraw, focus_window, DDSCL_SETFOCUSWINDOW);
739 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
740 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
741 ok(!device_window, "Unexpected device window found.\n");
742 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
743 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
744 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
745 ok(!!device_window, "Device window not found.\n");
747 IDirectDraw_Release(ddraw);
748 DestroyWindow(focus_window);
751 static void test_clipper_blt(void)
753 IDirectDrawSurface *src_surface, *dst_surface;
754 RECT client_rect, src_rect;
755 IDirectDrawClipper *clipper;
756 DDSURFACEDESC surface_desc;
757 unsigned int i, j, x, y;
758 IDirectDraw *ddraw;
759 RGNDATA *rgn_data;
760 D3DCOLOR color;
761 ULONG refcount;
762 HRGN r1, r2;
763 HWND window;
764 DDBLTFX fx;
765 HRESULT hr;
766 DWORD *ptr;
767 DWORD ret;
769 static const DWORD src_data[] =
771 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
772 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
773 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
775 static const D3DCOLOR expected1[] =
777 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
778 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
779 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
780 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
782 /* Nvidia on Windows seems to have an off-by-one error
783 * when processing source rectangles. Our left = 1 and
784 * right = 5 input reads from x = {1, 2, 3}. x = 4 is
785 * read as well, but only for the edge pixels on the
786 * output image. The bug happens on the y axis as well,
787 * but we only read one row there, and all source rows
788 * contain the same data. This bug is not dependent on
789 * the presence of a clipper. */
790 static const D3DCOLOR expected1_broken[] =
792 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
793 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
794 0x00000000, 0x00000000, 0x00ff0000, 0x00ff0000,
795 0x00000000, 0x00000000, 0x0000ff00, 0x00ff0000,
797 static const D3DCOLOR expected2[] =
799 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
800 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
801 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
802 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
805 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
806 10, 10, 640, 480, 0, 0, 0, 0);
807 ShowWindow(window, SW_SHOW);
808 ddraw = create_ddraw();
809 ok(!!ddraw, "Failed to create a ddraw object.\n");
811 ret = GetClientRect(window, &client_rect);
812 ok(ret, "Failed to get client rect.\n");
813 ret = MapWindowPoints(window, NULL, (POINT *)&client_rect, 2);
814 ok(ret, "Failed to map client rect.\n");
816 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
817 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
819 hr = IDirectDraw_CreateClipper(ddraw, 0, &clipper, NULL);
820 ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr);
821 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
822 ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr);
823 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
824 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
825 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
826 ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr);
827 rgn_data = HeapAlloc(GetProcessHeap(), 0, ret);
828 hr = IDirectDrawClipper_GetClipList(clipper, NULL, rgn_data, &ret);
829 ok(SUCCEEDED(hr), "Failed to get clip list, hr %#x.\n", hr);
830 ok(rgn_data->rdh.dwSize == sizeof(rgn_data->rdh), "Got unexpected structure size %#x.\n", rgn_data->rdh.dwSize);
831 ok(rgn_data->rdh.iType == RDH_RECTANGLES, "Got unexpected type %#x.\n", rgn_data->rdh.iType);
832 ok(rgn_data->rdh.nCount >= 1, "Got unexpected count %u.\n", rgn_data->rdh.nCount);
833 ok(EqualRect(&rgn_data->rdh.rcBound, &client_rect),
834 "Got unexpected bounding rect %s, expected %s.\n",
835 wine_dbgstr_rect(&rgn_data->rdh.rcBound), wine_dbgstr_rect(&client_rect));
836 HeapFree(GetProcessHeap(), 0, rgn_data);
838 r1 = CreateRectRgn(0, 0, 320, 240);
839 ok(!!r1, "Failed to create region.\n");
840 r2 = CreateRectRgn(320, 240, 640, 480);
841 ok(!!r2, "Failed to create region.\n");
842 CombineRgn(r1, r1, r2, RGN_OR);
843 ret = GetRegionData(r1, 0, NULL);
844 rgn_data = HeapAlloc(GetProcessHeap(), 0, ret);
845 ret = GetRegionData(r1, ret, rgn_data);
846 ok(!!ret, "Failed to get region data.\n");
848 DeleteObject(r2);
849 DeleteObject(r1);
851 hr = IDirectDrawClipper_SetClipList(clipper, rgn_data, 0);
852 ok(hr == DDERR_CLIPPERISUSINGHWND, "Got unexpected hr %#x.\n", hr);
853 hr = IDirectDrawClipper_SetHWnd(clipper, 0, NULL);
854 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
855 hr = IDirectDrawClipper_SetClipList(clipper, rgn_data, 0);
856 ok(SUCCEEDED(hr), "Failed to set clip list, hr %#x.\n", hr);
858 HeapFree(GetProcessHeap(), 0, rgn_data);
860 memset(&surface_desc, 0, sizeof(surface_desc));
861 surface_desc.dwSize = sizeof(surface_desc);
862 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
863 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
864 surface_desc.dwWidth = 640;
865 surface_desc.dwHeight = 480;
866 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
867 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB;
868 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount = 32;
869 U2(surface_desc.ddpfPixelFormat).dwRBitMask = 0x00ff0000;
870 U3(surface_desc.ddpfPixelFormat).dwGBitMask = 0x0000ff00;
871 U4(surface_desc.ddpfPixelFormat).dwBBitMask = 0x000000ff;
873 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &src_surface, NULL);
874 ok(SUCCEEDED(hr), "Failed to create source surface, hr %#x.\n", hr);
875 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &dst_surface, NULL);
876 ok(SUCCEEDED(hr), "Failed to create destination surface, hr %#x.\n", hr);
878 memset(&fx, 0, sizeof(fx));
879 fx.dwSize = sizeof(fx);
880 hr = IDirectDrawSurface_Blt(src_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
881 ok(SUCCEEDED(hr), "Failed to clear source surface, hr %#x.\n", hr);
882 hr = IDirectDrawSurface_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
883 ok(SUCCEEDED(hr), "Failed to clear destination surface, hr %#x.\n", hr);
885 hr = IDirectDrawSurface_Lock(src_surface, NULL, &surface_desc, DDLOCK_WAIT, NULL);
886 ok(SUCCEEDED(hr), "Failed to lock source surface, hr %#x.\n", hr);
887 ok(U1(surface_desc).lPitch == 2560, "Got unexpected surface pitch %u.\n", U1(surface_desc).lPitch);
888 ptr = surface_desc.lpSurface;
889 memcpy(&ptr[ 0], &src_data[ 0], 6 * sizeof(DWORD));
890 memcpy(&ptr[ 640], &src_data[ 6], 6 * sizeof(DWORD));
891 memcpy(&ptr[1280], &src_data[12], 6 * sizeof(DWORD));
892 hr = IDirectDrawSurface_Unlock(src_surface, NULL);
893 ok(SUCCEEDED(hr), "Failed to unlock source surface, hr %#x.\n", hr);
895 hr = IDirectDrawSurface_SetClipper(dst_surface, clipper);
896 ok(SUCCEEDED(hr), "Failed to set clipper, hr %#x.\n", hr);
898 SetRect(&src_rect, 1, 1, 5, 2);
899 hr = IDirectDrawSurface_Blt(dst_surface, NULL, src_surface, &src_rect, DDBLT_WAIT, NULL);
900 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
901 for (i = 0; i < 4; ++i)
903 for (j = 0; j < 4; ++j)
905 x = 80 * ((2 * j) + 1);
906 y = 60 * ((2 * i) + 1);
907 color = get_surface_color(dst_surface, x, y);
908 ok(compare_color(color, expected1[i * 4 + j], 1)
909 || broken(compare_color(color, expected1_broken[i * 4 + j], 1)),
910 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected1[i * 4 + j], x, y, color);
914 U5(fx).dwFillColor = 0xff0000ff;
915 hr = IDirectDrawSurface_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
916 ok(SUCCEEDED(hr), "Failed to clear destination surface, hr %#x.\n", hr);
917 for (i = 0; i < 4; ++i)
919 for (j = 0; j < 4; ++j)
921 x = 80 * ((2 * j) + 1);
922 y = 60 * ((2 * i) + 1);
923 color = get_surface_color(dst_surface, x, y);
924 ok(compare_color(color, expected2[i * 4 + j], 1),
925 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected2[i * 4 + j], x, y, color);
929 hr = IDirectDrawSurface_BltFast(dst_surface, 0, 0, src_surface, NULL, DDBLTFAST_WAIT);
930 ok(hr == DDERR_BLTFASTCANTCLIP || broken(hr == E_NOTIMPL /* NT4 */), "Got unexpected hr %#x.\n", hr);
932 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
933 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
934 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
935 ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr);
936 DestroyWindow(window);
937 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
938 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
939 hr = IDirectDrawClipper_SetHWnd(clipper, 0, NULL);
940 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
941 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
942 ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr);
943 hr = IDirectDrawClipper_SetClipList(clipper, NULL, 0);
944 ok(SUCCEEDED(hr), "Failed to set clip list, hr %#x.\n", hr);
945 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
946 ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr);
947 hr = IDirectDrawSurface_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
948 ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr);
950 IDirectDrawSurface_Release(dst_surface);
951 IDirectDrawSurface_Release(src_surface);
952 refcount = IDirectDrawClipper_Release(clipper);
953 ok(!refcount, "Clipper has %u references left.\n", refcount);
954 IDirectDraw_Release(ddraw);
957 static void test_coop_level_d3d_state(void)
959 D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
960 IDirectDrawSurface *rt, *surface;
961 IDirect3DMaterial *background;
962 IDirect3DViewport *viewport;
963 IDirect3DDevice *device;
964 D3DMATERIAL material;
965 IDirectDraw *ddraw;
966 D3DCOLOR color;
967 HWND window;
968 HRESULT hr;
970 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
971 0, 0, 640, 480, 0, 0, 0, 0);
972 ddraw = create_ddraw();
973 ok(!!ddraw, "Failed to create a ddraw object.\n");
974 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
976 skip("Failed to create a 3D device, skipping test.\n");
977 IDirectDraw_Release(ddraw);
978 DestroyWindow(window);
979 return;
982 background = create_diffuse_material(device, 1.0f, 0.0f, 0.0f, 1.0f);
983 viewport = create_viewport(device, 0, 0, 640, 480);
984 viewport_set_background(device, viewport, background);
986 hr = IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&rt);
987 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
988 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
989 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
990 color = get_surface_color(rt, 320, 240);
991 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
993 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
994 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
995 hr = IDirectDrawSurface_IsLost(rt);
996 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
997 hr = restore_surfaces(ddraw);
998 ok(SUCCEEDED(hr), "Failed to restore surfaces, hr %#x.\n", hr);
1000 memset(&material, 0, sizeof(material));
1001 material.dwSize = sizeof(material);
1002 U1(U(material).diffuse).r = 0.0f;
1003 U2(U(material).diffuse).g = 1.0f;
1004 U3(U(material).diffuse).b = 0.0f;
1005 U4(U(material).diffuse).a = 1.0f;
1006 hr = IDirect3DMaterial_SetMaterial(background, &material);
1007 ok(SUCCEEDED(hr), "Failed to set material data, hr %#x.\n", hr);
1009 hr = IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&surface);
1010 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1011 ok(surface == rt, "Got unexpected surface %p.\n", surface);
1012 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
1013 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
1014 color = get_surface_color(rt, 320, 240);
1015 ok(compare_color(color, 0x0000ff00, 1) || broken(compare_color(color, 0x00000000, 1)),
1016 "Got unexpected color 0x%08x.\n", color);
1018 destroy_viewport(device, viewport);
1019 destroy_material(background);
1020 IDirectDrawSurface_Release(surface);
1021 IDirectDrawSurface_Release(rt);
1022 IDirect3DDevice_Release(device);
1023 IDirectDraw_Release(ddraw);
1024 DestroyWindow(window);
1027 static void test_surface_interface_mismatch(void)
1029 IDirectDraw *ddraw = NULL;
1030 IDirectDrawSurface *surface = NULL, *ds;
1031 IDirectDrawSurface3 *surface3 = NULL;
1032 IDirect3DDevice *device = NULL;
1033 IDirect3DViewport *viewport = NULL;
1034 IDirect3DMaterial *background = NULL;
1035 DDSURFACEDESC surface_desc;
1036 DWORD z_depth = 0;
1037 ULONG refcount;
1038 HRESULT hr;
1039 D3DCOLOR color;
1040 HWND window;
1041 D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
1043 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1044 0, 0, 640, 480, 0, 0, 0, 0);
1045 ddraw = create_ddraw();
1046 ok(!!ddraw, "Failed to create a ddraw object.\n");
1047 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
1049 skip("Failed to create a 3D device, skipping test.\n");
1050 IDirectDraw_Release(ddraw);
1051 DestroyWindow(window);
1052 return;
1054 z_depth = get_device_z_depth(device);
1055 ok(!!z_depth, "Failed to get device z depth.\n");
1056 IDirect3DDevice_Release(device);
1057 device = NULL;
1059 memset(&surface_desc, 0, sizeof(surface_desc));
1060 surface_desc.dwSize = sizeof(surface_desc);
1061 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1062 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
1063 surface_desc.dwWidth = 640;
1064 surface_desc.dwHeight = 480;
1066 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1067 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1069 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirectDrawSurface3, (void **)&surface3);
1070 if (FAILED(hr))
1072 skip("Failed to get the IDirectDrawSurface3 interface, skipping test.\n");
1073 goto cleanup;
1076 memset(&surface_desc, 0, sizeof(surface_desc));
1077 surface_desc.dwSize = sizeof(surface_desc);
1078 surface_desc.dwFlags = DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_WIDTH | DDSD_HEIGHT;
1079 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
1080 U2(surface_desc).dwZBufferBitDepth = z_depth;
1081 surface_desc.dwWidth = 640;
1082 surface_desc.dwHeight = 480;
1083 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &ds, NULL);
1084 ok(SUCCEEDED(hr), "Failed to create depth buffer, hr %#x.\n", hr);
1085 if (FAILED(hr))
1086 goto cleanup;
1088 /* Using a different surface interface version still works */
1089 hr = IDirectDrawSurface3_AddAttachedSurface(surface3, (IDirectDrawSurface3 *)ds);
1090 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
1091 refcount = IDirectDrawSurface_Release(ds);
1092 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
1093 if (FAILED(hr))
1094 goto cleanup;
1096 /* Here too */
1097 hr = IDirectDrawSurface3_QueryInterface(surface3, &IID_IDirect3DHALDevice, (void **)&device);
1098 ok(SUCCEEDED(hr), "Failed to create d3d device.\n");
1099 if (FAILED(hr))
1100 goto cleanup;
1102 background = create_diffuse_material(device, 1.0f, 0.0f, 0.0f, 1.0f);
1103 viewport = create_viewport(device, 0, 0, 640, 480);
1104 viewport_set_background(device, viewport, background);
1106 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
1107 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
1108 color = get_surface_color(surface, 320, 240);
1109 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
1111 cleanup:
1112 if (viewport)
1113 destroy_viewport(device, viewport);
1114 if (background)
1115 destroy_material(background);
1116 if (surface3) IDirectDrawSurface3_Release(surface3);
1117 if (surface) IDirectDrawSurface_Release(surface);
1118 if (device) IDirect3DDevice_Release(device);
1119 if (ddraw) IDirectDraw_Release(ddraw);
1120 DestroyWindow(window);
1123 static void test_coop_level_threaded(void)
1125 struct create_window_thread_param p;
1126 IDirectDraw *ddraw;
1127 HRESULT hr;
1129 ddraw = create_ddraw();
1130 ok(!!ddraw, "Failed to create a ddraw object.\n");
1131 create_window_thread(&p);
1133 hr = IDirectDraw_SetCooperativeLevel(ddraw, p.window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
1134 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
1136 IDirectDraw_Release(ddraw);
1137 destroy_window_thread(&p);
1140 static ULONG get_refcount(IUnknown *test_iface)
1142 IUnknown_AddRef(test_iface);
1143 return IUnknown_Release(test_iface);
1146 static void test_viewport(void)
1148 IDirectDraw *ddraw;
1149 IDirect3D *d3d;
1150 HRESULT hr;
1151 ULONG ref;
1152 IDirect3DViewport *viewport, *another_vp;
1153 IDirect3DViewport2 *viewport2;
1154 IDirect3DViewport3 *viewport3;
1155 IDirectDrawGammaControl *gamma;
1156 IUnknown *unknown;
1157 IDirect3DDevice *device;
1158 HWND window;
1160 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1161 0, 0, 640, 480, 0, 0, 0, 0);
1162 ddraw = create_ddraw();
1163 ok(!!ddraw, "Failed to create a ddraw object.\n");
1164 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
1166 skip("Failed to create a 3D device, skipping test.\n");
1167 IDirectDraw_Release(ddraw);
1168 DestroyWindow(window);
1169 return;
1172 hr = IDirectDraw_QueryInterface(ddraw, &IID_IDirect3D, (void **)&d3d);
1173 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
1174 ref = get_refcount((IUnknown *) d3d);
1175 ok(ref == 2, "IDirect3D refcount is %d\n", ref);
1177 hr = IDirect3D_CreateViewport(d3d, &viewport, NULL);
1178 ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
1179 ref = get_refcount((IUnknown *)viewport);
1180 ok(ref == 1, "Initial IDirect3DViewport refcount is %u\n", ref);
1181 ref = get_refcount((IUnknown *)d3d);
1182 ok(ref == 2, "IDirect3D refcount is %u\n", ref);
1184 /* E_FAIL return values are returned by Winetestbot Windows NT machines. While not supporting
1185 * newer interfaces is legitimate for old ddraw versions, E_FAIL violates Microsoft's rules
1186 * for QueryInterface, hence the broken() */
1187 gamma = (IDirectDrawGammaControl *)0xdeadbeef;
1188 hr = IDirect3DViewport_QueryInterface(viewport, &IID_IDirectDrawGammaControl, (void **)&gamma);
1189 ok(hr == E_NOINTERFACE || broken(hr == E_FAIL), "Got unexpected hr %#x.\n", hr);
1190 ok(gamma == NULL, "Interface not set to NULL by failed QI call: %p\n", gamma);
1191 if (SUCCEEDED(hr)) IDirectDrawGammaControl_Release(gamma);
1192 /* NULL iid: Segfaults */
1194 hr = IDirect3DViewport_QueryInterface(viewport, &IID_IDirect3DViewport2, (void **)&viewport2);
1195 ok(SUCCEEDED(hr) || hr == E_NOINTERFACE || broken(hr == E_FAIL),
1196 "Failed to QI IDirect3DViewport2, hr %#x.\n", hr);
1197 if (viewport2)
1199 ref = get_refcount((IUnknown *)viewport);
1200 ok(ref == 2, "IDirect3DViewport refcount is %u\n", ref);
1201 ref = get_refcount((IUnknown *)viewport2);
1202 ok(ref == 2, "IDirect3DViewport2 refcount is %u\n", ref);
1203 IDirect3DViewport2_Release(viewport2);
1204 viewport2 = NULL;
1207 hr = IDirect3DViewport_QueryInterface(viewport, &IID_IDirect3DViewport3, (void **)&viewport3);
1208 ok(SUCCEEDED(hr) || hr == E_NOINTERFACE || broken(hr == E_FAIL),
1209 "Failed to QI IDirect3DViewport3, hr %#x.\n", hr);
1210 if (viewport3)
1212 ref = get_refcount((IUnknown *)viewport);
1213 ok(ref == 2, "IDirect3DViewport refcount is %u\n", ref);
1214 ref = get_refcount((IUnknown *)viewport3);
1215 ok(ref == 2, "IDirect3DViewport3 refcount is %u\n", ref);
1216 IDirect3DViewport3_Release(viewport3);
1219 hr = IDirect3DViewport_QueryInterface(viewport, &IID_IUnknown, (void **)&unknown);
1220 ok(SUCCEEDED(hr), "Failed to QI IUnknown, hr %#x.\n", hr);
1221 if (unknown)
1223 ref = get_refcount((IUnknown *)viewport);
1224 ok(ref == 2, "IDirect3DViewport refcount is %u\n", ref);
1225 ref = get_refcount(unknown);
1226 ok(ref == 2, "IUnknown refcount is %u\n", ref);
1227 IUnknown_Release(unknown);
1230 /* AddViewport(NULL): Segfault */
1231 hr = IDirect3DDevice_DeleteViewport(device, NULL);
1232 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
1234 hr = IDirect3D_CreateViewport(d3d, &another_vp, NULL);
1235 ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
1237 hr = IDirect3DDevice_AddViewport(device, viewport);
1238 ok(SUCCEEDED(hr), "Failed to add viewport to device, hr %#x.\n", hr);
1239 ref = get_refcount((IUnknown *) viewport);
1240 ok(ref == 2, "IDirect3DViewport refcount is %d\n", ref);
1241 hr = IDirect3DDevice_AddViewport(device, another_vp);
1242 ok(SUCCEEDED(hr), "Failed to add viewport to device, hr %#x.\n", hr);
1243 ref = get_refcount((IUnknown *) another_vp);
1244 ok(ref == 2, "IDirect3DViewport refcount is %d\n", ref);
1246 hr = IDirect3DDevice_DeleteViewport(device, another_vp);
1247 ok(SUCCEEDED(hr), "Failed to delete viewport from device, hr %#x.\n", hr);
1248 ref = get_refcount((IUnknown *) another_vp);
1249 ok(ref == 1, "IDirect3DViewport refcount is %d\n", ref);
1251 IDirect3DDevice_Release(device);
1252 ref = get_refcount((IUnknown *) viewport);
1253 ok(ref == 1, "IDirect3DViewport refcount is %d\n", ref);
1255 IDirect3DViewport_Release(another_vp);
1256 IDirect3D_Release(d3d);
1257 IDirect3DViewport_Release(viewport);
1258 DestroyWindow(window);
1259 IDirectDraw_Release(ddraw);
1262 static void test_zenable(void)
1264 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
1265 static D3DTLVERTEX tquad[] =
1267 {{ 0.0f}, {480.0f}, {-0.5f}, {1.0f}, {0xff00ff00}, {0x00000000}, {0.0f}, {0.0f}},
1268 {{ 0.0f}, { 0.0f}, {-0.5f}, {1.0f}, {0xff00ff00}, {0x00000000}, {0.0f}, {0.0f}},
1269 {{640.0f}, {480.0f}, { 1.5f}, {1.0f}, {0xff00ff00}, {0x00000000}, {0.0f}, {0.0f}},
1270 {{640.0f}, { 0.0f}, { 1.5f}, {1.0f}, {0xff00ff00}, {0x00000000}, {0.0f}, {0.0f}},
1272 IDirect3DExecuteBuffer *execute_buffer;
1273 D3DEXECUTEBUFFERDESC exec_desc;
1274 IDirect3DMaterial *background;
1275 IDirect3DViewport *viewport;
1276 IDirect3DDevice *device;
1277 IDirectDrawSurface *rt;
1278 IDirectDraw *ddraw;
1279 UINT inst_length;
1280 D3DCOLOR color;
1281 HWND window;
1282 HRESULT hr;
1283 UINT x, y;
1284 UINT i, j;
1285 void *ptr;
1287 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1288 0, 0, 640, 480, 0, 0, 0, 0);
1289 ddraw = create_ddraw();
1290 ok(!!ddraw, "Failed to create a ddraw object.\n");
1291 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
1293 skip("Failed to create a 3D device, skipping test.\n");
1294 IDirectDraw_Release(ddraw);
1295 DestroyWindow(window);
1296 return;
1299 background = create_diffuse_material(device, 1.0f, 0.0f, 0.0f, 1.0f);
1300 viewport = create_viewport(device, 0, 0, 640, 480);
1301 viewport_set_background(device, viewport, background);
1303 memset(&exec_desc, 0, sizeof(exec_desc));
1304 exec_desc.dwSize = sizeof(exec_desc);
1305 exec_desc.dwFlags = D3DDEB_BUFSIZE | D3DDEB_CAPS;
1306 exec_desc.dwBufferSize = 1024;
1307 exec_desc.dwCaps = D3DDEBCAPS_SYSTEMMEMORY;
1309 hr = IDirect3DDevice_CreateExecuteBuffer(device, &exec_desc, &execute_buffer, NULL);
1310 ok(SUCCEEDED(hr), "Failed to create execute buffer, hr %#x.\n", hr);
1311 hr = IDirect3DExecuteBuffer_Lock(execute_buffer, &exec_desc);
1312 ok(SUCCEEDED(hr), "Failed to lock execute buffer, hr %#x.\n", hr);
1313 memcpy(exec_desc.lpData, tquad, sizeof(tquad));
1314 ptr = ((BYTE *)exec_desc.lpData) + sizeof(tquad);
1315 emit_process_vertices(&ptr, D3DPROCESSVERTICES_COPY, 0, 4);
1316 emit_set_rs(&ptr, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
1317 emit_tquad(&ptr, 0);
1318 emit_end(&ptr);
1319 inst_length = (BYTE *)ptr - (BYTE *)exec_desc.lpData;
1320 inst_length -= sizeof(tquad);
1321 hr = IDirect3DExecuteBuffer_Unlock(execute_buffer);
1322 ok(SUCCEEDED(hr), "Failed to unlock execute buffer, hr %#x.\n", hr);
1324 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
1325 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
1326 hr = IDirect3DDevice_BeginScene(device);
1327 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1328 set_execute_data(execute_buffer, 4, sizeof(tquad), inst_length);
1329 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
1330 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
1331 hr = IDirect3DDevice_EndScene(device);
1332 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1334 hr = IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&rt);
1335 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1336 for (i = 0; i < 4; ++i)
1338 for (j = 0; j < 4; ++j)
1340 x = 80 * ((2 * j) + 1);
1341 y = 60 * ((2 * i) + 1);
1342 color = get_surface_color(rt, x, y);
1343 ok(compare_color(color, 0x0000ff00, 1),
1344 "Expected color 0x0000ff00 at %u, %u, got 0x%08x.\n", x, y, color);
1347 IDirectDrawSurface_Release(rt);
1349 destroy_viewport(device, viewport);
1350 IDirect3DExecuteBuffer_Release(execute_buffer);
1351 destroy_material(background);
1352 IDirect3DDevice_Release(device);
1353 IDirectDraw_Release(ddraw);
1354 DestroyWindow(window);
1357 static void test_ck_rgba(void)
1359 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
1360 static D3DTLVERTEX tquad[] =
1362 {{ 0.0f}, {480.0f}, {0.25f}, {1.0f}, {0xffffffff}, {0x00000000}, {0.0f}, {0.0f}},
1363 {{ 0.0f}, { 0.0f}, {0.25f}, {1.0f}, {0xffffffff}, {0x00000000}, {0.0f}, {1.0f}},
1364 {{640.0f}, {480.0f}, {0.25f}, {1.0f}, {0xffffffff}, {0x00000000}, {1.0f}, {0.0f}},
1365 {{640.0f}, { 0.0f}, {0.25f}, {1.0f}, {0xffffffff}, {0x00000000}, {1.0f}, {1.0f}},
1366 {{ 0.0f}, {480.0f}, {0.75f}, {1.0f}, {0xffffffff}, {0x00000000}, {0.0f}, {0.0f}},
1367 {{ 0.0f}, { 0.0f}, {0.75f}, {1.0f}, {0xffffffff}, {0x00000000}, {0.0f}, {1.0f}},
1368 {{640.0f}, {480.0f}, {0.75f}, {1.0f}, {0xffffffff}, {0x00000000}, {1.0f}, {0.0f}},
1369 {{640.0f}, { 0.0f}, {0.75f}, {1.0f}, {0xffffffff}, {0x00000000}, {1.0f}, {1.0f}},
1371 /* Supposedly there was no D3DRENDERSTATE_COLORKEYENABLE in D3D < 5.
1372 * Maybe the WARP driver on Windows 8 ignores setting it via the older
1373 * device interface but it's buggy in that the internal state is not
1374 * initialized, or possibly toggling D3DRENDERSTATE_COLORKEYENABLE /
1375 * D3DRENDERSTATE_ALPHABLENDENABLE has unintended side effects.
1376 * Checking the W8 test results it seems like test 1 fails most of the time
1377 * and test 0 fails very rarely. */
1378 static const struct
1380 D3DCOLOR fill_color;
1381 BOOL color_key;
1382 BOOL blend;
1383 D3DCOLOR result1, result1_r200, result1_warp;
1384 D3DCOLOR result2, result2_r200, result2_warp;
1386 tests[] =
1388 /* r200 on Windows doesn't check the alpha component when applying the color
1389 * key, so the key matches on every texel. */
1390 {0xff00ff00, TRUE, TRUE, 0x00ff0000, 0x00ff0000, 0x0000ff00,
1391 0x000000ff, 0x000000ff, 0x0000ff00},
1392 {0xff00ff00, TRUE, FALSE, 0x00ff0000, 0x00ff0000, 0x0000ff00,
1393 0x000000ff, 0x000000ff, 0x0000ff00},
1394 {0xff00ff00, FALSE, TRUE, 0x0000ff00, 0x0000ff00, 0x0000ff00,
1395 0x0000ff00, 0x0000ff00, 0x0000ff00},
1396 {0xff00ff00, FALSE, FALSE, 0x0000ff00, 0x0000ff00, 0x0000ff00,
1397 0x0000ff00, 0x0000ff00, 0x0000ff00},
1398 {0x7f00ff00, TRUE, TRUE, 0x00807f00, 0x00ff0000, 0x00807f00,
1399 0x00807f00, 0x000000ff, 0x00807f00},
1400 {0x7f00ff00, TRUE, FALSE, 0x0000ff00, 0x00ff0000, 0x0000ff00,
1401 0x0000ff00, 0x000000ff, 0x0000ff00},
1402 {0x7f00ff00, FALSE, TRUE, 0x00807f00, 0x00807f00, 0x00807f00,
1403 0x00807f00, 0x00807f00, 0x00807f00},
1404 {0x7f00ff00, FALSE, FALSE, 0x0000ff00, 0x0000ff00, 0x0000ff00,
1405 0x0000ff00, 0x0000ff00, 0x0000ff00},
1408 IDirect3DExecuteBuffer *execute_buffer;
1409 D3DTEXTUREHANDLE texture_handle;
1410 D3DEXECUTEBUFFERDESC exec_desc;
1411 IDirect3DMaterial *background;
1412 IDirectDrawSurface *surface;
1413 IDirect3DViewport *viewport;
1414 DDSURFACEDESC surface_desc;
1415 IDirect3DTexture *texture;
1416 IDirect3DDevice *device;
1417 IDirectDrawSurface *rt;
1418 IDirectDraw *ddraw;
1419 D3DCOLOR color;
1420 HWND window;
1421 DDBLTFX fx;
1422 HRESULT hr;
1423 UINT i;
1425 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1426 0, 0, 640, 480, 0, 0, 0, 0);
1427 ddraw = create_ddraw();
1428 ok(!!ddraw, "Failed to create a ddraw object.\n");
1429 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
1431 skip("Failed to create a 3D device, skipping test.\n");
1432 IDirectDraw_Release(ddraw);
1433 DestroyWindow(window);
1434 return;
1437 background = create_diffuse_material(device, 1.0, 0.0f, 0.0f, 1.0f);
1438 viewport = create_viewport(device, 0, 0, 640, 480);
1439 viewport_set_background(device, viewport, background);
1441 memset(&surface_desc, 0, sizeof(surface_desc));
1442 surface_desc.dwSize = sizeof(surface_desc);
1443 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CKSRCBLT;
1444 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1445 surface_desc.dwWidth = 256;
1446 surface_desc.dwHeight = 256;
1447 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
1448 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
1449 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount = 32;
1450 U2(surface_desc.ddpfPixelFormat).dwRBitMask = 0x00ff0000;
1451 U3(surface_desc.ddpfPixelFormat).dwGBitMask = 0x0000ff00;
1452 U4(surface_desc.ddpfPixelFormat).dwBBitMask = 0x000000ff;
1453 U5(surface_desc.ddpfPixelFormat).dwRGBAlphaBitMask = 0xff000000;
1454 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0xff00ff00;
1455 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0xff00ff00;
1456 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1457 ok(SUCCEEDED(hr), "Failed to create destination surface, hr %#x.\n", hr);
1458 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirect3DTexture, (void **)&texture);
1459 ok(SUCCEEDED(hr), "Failed to get texture interface, hr %#x.\n", hr);
1460 hr = IDirect3DTexture_GetHandle(texture, device, &texture_handle);
1461 ok(SUCCEEDED(hr), "Failed to get texture handle, hr %#x.\n", hr);
1462 IDirect3DTexture_Release(texture);
1464 memset(&exec_desc, 0, sizeof(exec_desc));
1465 exec_desc.dwSize = sizeof(exec_desc);
1466 exec_desc.dwFlags = D3DDEB_BUFSIZE | D3DDEB_CAPS;
1467 exec_desc.dwBufferSize = 1024;
1468 exec_desc.dwCaps = D3DDEBCAPS_SYSTEMMEMORY;
1469 hr = IDirect3DDevice_CreateExecuteBuffer(device, &exec_desc, &execute_buffer, NULL);
1470 ok(SUCCEEDED(hr), "Failed to create execute buffer, hr %#x.\n", hr);
1472 hr = IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&rt);
1473 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1475 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
1477 UINT draw1_len, draw2_len;
1478 void *ptr;
1480 hr = IDirect3DExecuteBuffer_Lock(execute_buffer, &exec_desc);
1481 ok(SUCCEEDED(hr), "Failed to lock execute buffer, hr %#x.\n", hr);
1482 memcpy(exec_desc.lpData, tquad, sizeof(tquad));
1483 ptr = ((BYTE *)exec_desc.lpData) + sizeof(tquad);
1484 emit_process_vertices(&ptr, D3DPROCESSVERTICES_COPY, 0, 4);
1485 emit_set_rs(&ptr, D3DRENDERSTATE_TEXTUREHANDLE, texture_handle);
1486 emit_set_rs(&ptr, D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);
1487 emit_set_rs(&ptr, D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA);
1488 emit_set_rs(&ptr, D3DRENDERSTATE_COLORKEYENABLE, tests[i].color_key);
1489 emit_set_rs(&ptr, D3DRENDERSTATE_ALPHABLENDENABLE, tests[i].blend);
1490 emit_tquad(&ptr, 0);
1491 emit_end(&ptr);
1492 draw1_len = (BYTE *)ptr - (BYTE *)exec_desc.lpData - sizeof(tquad);
1493 emit_process_vertices(&ptr, D3DPROCESSVERTICES_COPY, 4, 4);
1494 emit_tquad(&ptr, 0);
1495 emit_set_rs(&ptr, D3DRENDERSTATE_TEXTUREHANDLE, 0);
1496 emit_end(&ptr);
1497 draw2_len = (BYTE *)ptr - (BYTE *)exec_desc.lpData - draw1_len;
1498 hr = IDirect3DExecuteBuffer_Unlock(execute_buffer);
1499 ok(SUCCEEDED(hr), "Failed to unlock execute buffer, hr %#x.\n", hr);
1501 memset(&fx, 0, sizeof(fx));
1502 fx.dwSize = sizeof(fx);
1503 U5(fx).dwFillColor = tests[i].fill_color;
1504 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
1505 ok(SUCCEEDED(hr), "Failed to fill texture, hr %#x.\n", hr);
1507 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER);
1508 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
1509 hr = IDirect3DDevice_BeginScene(device);
1510 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1511 set_execute_data(execute_buffer, 8, sizeof(tquad), draw1_len);
1512 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
1513 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
1514 hr = IDirect3DDevice_EndScene(device);
1515 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1517 color = get_surface_color(rt, 320, 240);
1518 ok(compare_color(color, tests[i].result1, 1)
1519 || broken(compare_color(color, tests[i].result1_r200, 1))
1520 || broken(compare_color(color, tests[i].result1_warp, 1)),
1521 "Got unexpected color 0x%08x for test %u.\n", color, i);
1523 U5(fx).dwFillColor = 0xff0000ff;
1524 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
1525 ok(SUCCEEDED(hr), "Failed to fill texture, hr %#x.\n", hr);
1527 hr = IDirect3DDevice_BeginScene(device);
1528 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1529 set_execute_data(execute_buffer, 8, sizeof(tquad) + draw1_len, draw2_len);
1530 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
1531 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
1532 hr = IDirect3DDevice_EndScene(device);
1533 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1535 /* This tests that fragments that are masked out by the color key are
1536 * discarded, instead of just fully transparent. */
1537 color = get_surface_color(rt, 320, 240);
1538 ok(compare_color(color, tests[i].result2, 1)
1539 || broken(compare_color(color, tests[i].result2_r200, 1))
1540 || broken(compare_color(color, tests[i].result2_warp, 1)),
1541 "Got unexpected color 0x%08x for test %u.\n", color, i);
1544 IDirectDrawSurface_Release(rt);
1545 IDirect3DExecuteBuffer_Release(execute_buffer);
1546 IDirectDrawSurface_Release(surface);
1547 destroy_viewport(device, viewport);
1548 destroy_material(background);
1549 IDirect3DDevice_Release(device);
1550 IDirectDraw_Release(ddraw);
1551 DestroyWindow(window);
1554 static void test_ck_default(void)
1556 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
1557 static D3DTLVERTEX tquad[] =
1559 {{ 0.0f}, {480.0f}, {0.0f}, {1.0f}, {0xffffffff}, {0x00000000}, {0.0f}, {0.0f}},
1560 {{ 0.0f}, { 0.0f}, {0.0f}, {1.0f}, {0xffffffff}, {0x00000000}, {0.0f}, {1.0f}},
1561 {{640.0f}, {480.0f}, {0.0f}, {1.0f}, {0xffffffff}, {0x00000000}, {1.0f}, {0.0f}},
1562 {{640.0f}, { 0.0f}, {0.0f}, {1.0f}, {0xffffffff}, {0x00000000}, {1.0f}, {1.0f}},
1564 IDirect3DExecuteBuffer *execute_buffer;
1565 IDirectDrawSurface *surface, *rt;
1566 D3DTEXTUREHANDLE texture_handle;
1567 D3DEXECUTEBUFFERDESC exec_desc;
1568 IDirect3DMaterial *background;
1569 UINT draw1_offset, draw1_len;
1570 UINT draw2_offset, draw2_len;
1571 UINT draw3_offset, draw3_len;
1572 UINT draw4_offset, draw4_len;
1573 IDirect3DViewport *viewport;
1574 DDSURFACEDESC surface_desc;
1575 IDirect3DTexture *texture;
1576 IDirect3DDevice *device;
1577 IDirectDraw *ddraw;
1578 D3DCOLOR color;
1579 HWND window;
1580 DDBLTFX fx;
1581 HRESULT hr;
1582 void *ptr;
1584 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1585 0, 0, 640, 480, 0, 0, 0, 0);
1586 ddraw = create_ddraw();
1587 ok(!!ddraw, "Failed to create a ddraw object.\n");
1588 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
1590 skip("Failed to create a 3D device, skipping test.\n");
1591 IDirectDraw_Release(ddraw);
1592 DestroyWindow(window);
1593 return;
1596 hr = IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&rt);
1597 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1599 background = create_diffuse_material(device, 0.0, 1.0f, 0.0f, 1.0f);
1600 viewport = create_viewport(device, 0, 0, 640, 480);
1601 viewport_set_background(device, viewport, background);
1603 memset(&surface_desc, 0, sizeof(surface_desc));
1604 surface_desc.dwSize = sizeof(surface_desc);
1605 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CKSRCBLT;
1606 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1607 surface_desc.dwWidth = 256;
1608 surface_desc.dwHeight = 256;
1609 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
1610 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB;
1611 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount = 32;
1612 U2(surface_desc.ddpfPixelFormat).dwRBitMask = 0x00ff0000;
1613 U3(surface_desc.ddpfPixelFormat).dwGBitMask = 0x0000ff00;
1614 U4(surface_desc.ddpfPixelFormat).dwBBitMask = 0x000000ff;
1615 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x000000ff;
1616 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x000000ff;
1617 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1618 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1619 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirect3DTexture, (void **)&texture);
1620 ok(SUCCEEDED(hr), "Failed to get texture interface, hr %#x.\n", hr);
1621 hr = IDirect3DTexture_GetHandle(texture, device, &texture_handle);
1622 ok(SUCCEEDED(hr), "Failed to get texture handle, hr %#x.\n", hr);
1623 IDirect3DTexture_Release(texture);
1625 memset(&fx, 0, sizeof(fx));
1626 fx.dwSize = sizeof(fx);
1627 U5(fx).dwFillColor = 0x000000ff;
1628 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
1629 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
1631 memset(&exec_desc, 0, sizeof(exec_desc));
1632 exec_desc.dwSize = sizeof(exec_desc);
1633 exec_desc.dwFlags = D3DDEB_BUFSIZE | D3DDEB_CAPS;
1634 exec_desc.dwBufferSize = 1024;
1635 exec_desc.dwCaps = D3DDEBCAPS_SYSTEMMEMORY;
1636 hr = IDirect3DDevice_CreateExecuteBuffer(device, &exec_desc, &execute_buffer, NULL);
1637 ok(SUCCEEDED(hr), "Failed to create execute buffer, hr %#x.\n", hr);
1639 hr = IDirect3DExecuteBuffer_Lock(execute_buffer, &exec_desc);
1640 ok(SUCCEEDED(hr), "Failed to lock execute buffer, hr %#x.\n", hr);
1641 memcpy(exec_desc.lpData, tquad, sizeof(tquad));
1642 ptr = (BYTE *)exec_desc.lpData + sizeof(tquad);
1643 emit_process_vertices(&ptr, D3DPROCESSVERTICES_COPY, 0, 4);
1644 emit_set_rs(&ptr, D3DRENDERSTATE_TEXTUREHANDLE, texture_handle);
1645 emit_tquad(&ptr, 0);
1646 emit_end(&ptr);
1647 draw1_offset = sizeof(tquad);
1648 draw1_len = (BYTE *)ptr - (BYTE *)exec_desc.lpData - draw1_offset;
1649 emit_process_vertices(&ptr, D3DPROCESSVERTICES_COPY, 0, 4);
1650 emit_set_rs(&ptr, D3DRENDERSTATE_COLORKEYENABLE, FALSE);
1651 emit_tquad(&ptr, 0);
1652 emit_end(&ptr);
1653 draw2_offset = draw1_offset + draw1_len;
1654 draw2_len = (BYTE *)ptr - (BYTE *)exec_desc.lpData - draw2_offset;
1655 emit_process_vertices(&ptr, D3DPROCESSVERTICES_COPY, 0, 4);
1656 emit_tquad(&ptr, 0);
1657 emit_end(&ptr);
1658 draw3_offset = draw2_offset + draw2_len;
1659 draw3_len = (BYTE *)ptr - (BYTE *)exec_desc.lpData - draw3_offset;
1660 emit_process_vertices(&ptr, D3DPROCESSVERTICES_COPY, 0, 4);
1661 emit_set_rs(&ptr, D3DRENDERSTATE_COLORKEYENABLE, TRUE);
1662 emit_tquad(&ptr, 0);
1663 emit_set_rs(&ptr, D3DRENDERSTATE_TEXTUREHANDLE, 0);
1664 emit_end(&ptr);
1665 draw4_offset = draw3_offset + draw3_len;
1666 draw4_len = (BYTE *)ptr - (BYTE *)exec_desc.lpData - draw4_offset;
1667 hr = IDirect3DExecuteBuffer_Unlock(execute_buffer);
1668 ok(SUCCEEDED(hr), "Failed to unlock execute buffer, hr %#x.\n", hr);
1670 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
1671 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
1672 hr = IDirect3DDevice_BeginScene(device);
1673 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1674 set_execute_data(execute_buffer, 4, draw1_offset, draw1_len);
1675 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
1676 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
1677 hr = IDirect3DDevice_EndScene(device);
1678 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1679 color = get_surface_color(rt, 320, 240);
1680 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
1682 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
1683 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
1684 hr = IDirect3DDevice_BeginScene(device);
1685 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1686 set_execute_data(execute_buffer, 4, draw2_offset, draw2_len);
1687 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
1688 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
1689 hr = IDirect3DDevice_EndScene(device);
1690 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1691 color = get_surface_color(rt, 320, 240);
1692 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
1694 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
1695 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
1696 hr = IDirect3DDevice_BeginScene(device);
1697 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1698 set_execute_data(execute_buffer, 4, draw3_offset, draw3_len);
1699 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
1700 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
1701 hr = IDirect3DDevice_EndScene(device);
1702 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1703 color = get_surface_color(rt, 320, 240);
1704 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
1706 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
1707 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
1708 hr = IDirect3DDevice_BeginScene(device);
1709 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1710 set_execute_data(execute_buffer, 4, draw4_offset, draw4_len);
1711 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
1712 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
1713 hr = IDirect3DDevice_EndScene(device);
1714 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1715 color = get_surface_color(rt, 320, 240);
1716 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
1718 IDirect3DExecuteBuffer_Release(execute_buffer);
1719 IDirectDrawSurface_Release(surface);
1720 destroy_viewport(device, viewport);
1721 destroy_material(background);
1722 IDirectDrawSurface_Release(rt);
1723 IDirect3DDevice_Release(device);
1724 IDirectDraw_Release(ddraw);
1725 DestroyWindow(window);
1728 static void test_ck_complex(void)
1730 IDirectDrawSurface *surface, *mipmap, *tmp;
1731 DDSCAPS caps = {DDSCAPS_COMPLEX};
1732 DDSURFACEDESC surface_desc;
1733 IDirect3DDevice *device;
1734 DDCOLORKEY color_key;
1735 IDirectDraw *ddraw;
1736 unsigned int i;
1737 ULONG refcount;
1738 HWND window;
1739 HRESULT hr;
1741 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1742 0, 0, 640, 480, 0, 0, 0, 0);
1743 ddraw = create_ddraw();
1744 ok(!!ddraw, "Failed to create a ddraw object.\n");
1745 if (!(device = create_device(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN)))
1747 skip("Failed to create a 3D device, skipping test.\n");
1748 DestroyWindow(window);
1749 IDirectDraw2_Release(ddraw);
1750 return;
1752 IDirect3DDevice_Release(device);
1754 memset(&surface_desc, 0, sizeof(surface_desc));
1755 surface_desc.dwSize = sizeof(surface_desc);
1756 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1757 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
1758 surface_desc.dwWidth = 128;
1759 surface_desc.dwHeight = 128;
1760 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1761 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1763 hr = IDirectDrawSurface_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1764 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1765 color_key.dwColorSpaceLowValue = 0x0000ff00;
1766 color_key.dwColorSpaceHighValue = 0x0000ff00;
1767 hr = IDirectDrawSurface_SetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1768 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1769 memset(&color_key, 0, sizeof(color_key));
1770 hr = IDirectDrawSurface_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1771 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
1772 ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1773 color_key.dwColorSpaceLowValue);
1774 ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1775 color_key.dwColorSpaceHighValue);
1777 mipmap = surface;
1778 IDirectDrawSurface_AddRef(mipmap);
1779 for (i = 0; i < 7; ++i)
1781 hr = IDirectDrawSurface_GetAttachedSurface(mipmap, &caps, &tmp);
1782 ok(SUCCEEDED(hr), "Failed to get attached surface, i %u, hr %#x.\n", i, hr);
1784 hr = IDirectDrawSurface_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1785 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x, i %u.\n", hr, i);
1786 color_key.dwColorSpaceLowValue = 0x000000ff;
1787 color_key.dwColorSpaceHighValue = 0x000000ff;
1788 hr = IDirectDrawSurface_SetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1789 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x, i %u.\n", hr, i);
1790 memset(&color_key, 0, sizeof(color_key));
1791 hr = IDirectDrawSurface_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1792 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x, i %u.\n", hr, i);
1793 ok(color_key.dwColorSpaceLowValue == 0x000000ff, "Got unexpected value 0x%08x, i %u.\n",
1794 color_key.dwColorSpaceLowValue, i);
1795 ok(color_key.dwColorSpaceHighValue == 0x000000ff, "Got unexpected value 0x%08x, i %u.\n",
1796 color_key.dwColorSpaceHighValue, i);
1798 IDirectDrawSurface_Release(mipmap);
1799 mipmap = tmp;
1802 memset(&color_key, 0, sizeof(color_key));
1803 hr = IDirectDrawSurface_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1804 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
1805 ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1806 color_key.dwColorSpaceLowValue);
1807 ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1808 color_key.dwColorSpaceHighValue);
1810 hr = IDirectDrawSurface_GetAttachedSurface(mipmap, &caps, &tmp);
1811 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
1812 IDirectDrawSurface_Release(mipmap);
1813 refcount = IDirectDrawSurface_Release(surface);
1814 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1816 memset(&surface_desc, 0, sizeof(surface_desc));
1817 surface_desc.dwSize = sizeof(surface_desc);
1818 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
1819 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
1820 surface_desc.dwBackBufferCount = 1;
1821 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1822 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1824 hr = IDirectDrawSurface_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1825 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1826 color_key.dwColorSpaceLowValue = 0x0000ff00;
1827 color_key.dwColorSpaceHighValue = 0x0000ff00;
1828 hr = IDirectDrawSurface_SetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1829 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1830 memset(&color_key, 0, sizeof(color_key));
1831 hr = IDirectDrawSurface_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1832 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
1833 ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1834 color_key.dwColorSpaceLowValue);
1835 ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1836 color_key.dwColorSpaceHighValue);
1838 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &tmp);
1839 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
1841 hr = IDirectDrawSurface_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1842 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x, i %u.\n", hr, i);
1843 color_key.dwColorSpaceLowValue = 0x0000ff00;
1844 color_key.dwColorSpaceHighValue = 0x0000ff00;
1845 hr = IDirectDrawSurface_SetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1846 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1847 memset(&color_key, 0, sizeof(color_key));
1848 hr = IDirectDrawSurface_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1849 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
1850 ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1851 color_key.dwColorSpaceLowValue);
1852 ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1853 color_key.dwColorSpaceHighValue);
1855 IDirectDrawSurface_Release(tmp);
1857 refcount = IDirectDrawSurface_Release(surface);
1858 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1859 refcount = IDirectDraw_Release(ddraw);
1860 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1861 DestroyWindow(window);
1864 struct qi_test
1866 REFIID iid;
1867 REFIID refcount_iid;
1868 HRESULT hr;
1871 static void test_qi(const char *test_name, IUnknown *base_iface,
1872 REFIID refcount_iid, const struct qi_test *tests, UINT entry_count)
1874 ULONG refcount, expected_refcount;
1875 IUnknown *iface1, *iface2;
1876 HRESULT hr;
1877 UINT i, j;
1879 for (i = 0; i < entry_count; ++i)
1881 hr = IUnknown_QueryInterface(base_iface, tests[i].iid, (void **)&iface1);
1882 ok(hr == tests[i].hr, "Got hr %#x for test \"%s\" %u.\n", hr, test_name, i);
1883 if (SUCCEEDED(hr))
1885 for (j = 0; j < entry_count; ++j)
1887 hr = IUnknown_QueryInterface(iface1, tests[j].iid, (void **)&iface2);
1888 ok(hr == tests[j].hr, "Got hr %#x for test \"%s\" %u, %u.\n", hr, test_name, i, j);
1889 if (SUCCEEDED(hr))
1891 expected_refcount = 0;
1892 if (IsEqualGUID(refcount_iid, tests[j].refcount_iid))
1893 ++expected_refcount;
1894 if (IsEqualGUID(tests[i].refcount_iid, tests[j].refcount_iid))
1895 ++expected_refcount;
1896 refcount = IUnknown_Release(iface2);
1897 ok(refcount == expected_refcount, "Got refcount %u for test \"%s\" %u, %u, expected %u.\n",
1898 refcount, test_name, i, j, expected_refcount);
1902 expected_refcount = 0;
1903 if (IsEqualGUID(refcount_iid, tests[i].refcount_iid))
1904 ++expected_refcount;
1905 refcount = IUnknown_Release(iface1);
1906 ok(refcount == expected_refcount, "Got refcount %u for test \"%s\" %u, expected %u.\n",
1907 refcount, test_name, i, expected_refcount);
1912 static void test_surface_qi(void)
1914 static const struct qi_test tests[] =
1916 {&IID_IDirect3DTexture2, &IID_IDirectDrawSurface, S_OK },
1917 {&IID_IDirect3DTexture, &IID_IDirectDrawSurface, S_OK },
1918 {&IID_IDirectDrawGammaControl, &IID_IDirectDrawGammaControl, S_OK },
1919 {&IID_IDirectDrawColorControl, NULL, E_NOINTERFACE},
1920 {&IID_IDirectDrawSurface7, &IID_IDirectDrawSurface7, S_OK },
1921 {&IID_IDirectDrawSurface4, &IID_IDirectDrawSurface4, S_OK },
1922 {&IID_IDirectDrawSurface3, &IID_IDirectDrawSurface3, S_OK },
1923 {&IID_IDirectDrawSurface2, &IID_IDirectDrawSurface2, S_OK },
1924 {&IID_IDirectDrawSurface, &IID_IDirectDrawSurface, S_OK },
1925 {&IID_IDirect3DDevice7, NULL, E_INVALIDARG },
1926 {&IID_IDirect3DDevice3, NULL, E_INVALIDARG },
1927 {&IID_IDirect3DDevice2, NULL, E_INVALIDARG },
1928 {&IID_IDirect3DDevice, NULL, E_INVALIDARG },
1929 {&IID_IDirect3D7, NULL, E_INVALIDARG },
1930 {&IID_IDirect3D3, NULL, E_INVALIDARG },
1931 {&IID_IDirect3D2, NULL, E_INVALIDARG },
1932 {&IID_IDirect3D, NULL, E_INVALIDARG },
1933 {&IID_IDirectDraw7, NULL, E_INVALIDARG },
1934 {&IID_IDirectDraw4, NULL, E_INVALIDARG },
1935 {&IID_IDirectDraw3, NULL, E_INVALIDARG },
1936 {&IID_IDirectDraw2, NULL, E_INVALIDARG },
1937 {&IID_IDirectDraw, NULL, E_INVALIDARG },
1938 {&IID_IDirect3DLight, NULL, E_INVALIDARG },
1939 {&IID_IDirect3DMaterial, NULL, E_INVALIDARG },
1940 {&IID_IDirect3DMaterial2, NULL, E_INVALIDARG },
1941 {&IID_IDirect3DMaterial3, NULL, E_INVALIDARG },
1942 {&IID_IDirect3DExecuteBuffer, NULL, E_INVALIDARG },
1943 {&IID_IDirect3DViewport, NULL, E_INVALIDARG },
1944 {&IID_IDirect3DViewport2, NULL, E_INVALIDARG },
1945 {&IID_IDirect3DViewport3, NULL, E_INVALIDARG },
1946 {&IID_IDirect3DVertexBuffer, NULL, E_INVALIDARG },
1947 {&IID_IDirect3DVertexBuffer7, NULL, E_INVALIDARG },
1948 {&IID_IDirectDrawPalette, NULL, E_INVALIDARG },
1949 {&IID_IDirectDrawClipper, NULL, E_INVALIDARG },
1950 {&IID_IUnknown, &IID_IDirectDrawSurface, S_OK },
1953 IDirectDrawSurface *surface;
1954 DDSURFACEDESC surface_desc;
1955 IDirect3DDevice *device;
1956 IDirectDraw *ddraw;
1957 HWND window;
1958 HRESULT hr;
1960 if (!GetProcAddress(GetModuleHandleA("ddraw.dll"), "DirectDrawCreateEx"))
1962 win_skip("DirectDrawCreateEx not available, skipping test.\n");
1963 return;
1966 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1967 0, 0, 640, 480, 0, 0, 0, 0);
1968 ddraw = create_ddraw();
1969 ok(!!ddraw, "Failed to create a ddraw object.\n");
1970 /* Try to create a D3D device to see if the ddraw implementation supports
1971 * D3D. 64-bit ddraw in particular doesn't seem to support D3D, and
1972 * doesn't support e.g. the IDirect3DTexture interfaces. */
1973 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
1975 skip("Failed to create a 3D device, skipping test.\n");
1976 IDirectDraw_Release(ddraw);
1977 DestroyWindow(window);
1978 return;
1980 IDirect3DDevice_Release(device);
1982 memset(&surface_desc, 0, sizeof(surface_desc));
1983 surface_desc.dwSize = sizeof(surface_desc);
1984 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1985 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1986 surface_desc.dwWidth = 512;
1987 surface_desc.dwHeight = 512;
1988 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, (IDirectDrawSurface **)0xdeadbeef, NULL);
1989 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1990 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1991 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1993 test_qi("surface_qi", (IUnknown *)surface, &IID_IDirectDrawSurface, tests, sizeof(tests) / sizeof(*tests));
1995 IDirectDrawSurface_Release(surface);
1996 IDirectDraw_Release(ddraw);
1997 DestroyWindow(window);
2000 static void test_device_qi(void)
2002 static const struct qi_test tests[] =
2004 {&IID_IDirect3DTexture2, &IID_IDirectDrawSurface, S_OK },
2005 {&IID_IDirect3DTexture, &IID_IDirectDrawSurface, S_OK },
2006 {&IID_IDirectDrawGammaControl, &IID_IDirectDrawGammaControl, S_OK },
2007 {&IID_IDirectDrawColorControl, NULL, E_NOINTERFACE},
2008 {&IID_IDirectDrawSurface7, &IID_IDirectDrawSurface7, S_OK },
2009 {&IID_IDirectDrawSurface4, &IID_IDirectDrawSurface4, S_OK },
2010 {&IID_IDirectDrawSurface3, &IID_IDirectDrawSurface3, S_OK },
2011 {&IID_IDirectDrawSurface2, &IID_IDirectDrawSurface2, S_OK },
2012 {&IID_IDirectDrawSurface, &IID_IDirectDrawSurface, S_OK },
2013 {&IID_IDirect3DDevice7, NULL, E_INVALIDARG },
2014 {&IID_IDirect3DDevice3, NULL, E_INVALIDARG },
2015 {&IID_IDirect3DDevice2, NULL, E_INVALIDARG },
2016 {&IID_IDirect3DDevice, NULL, E_INVALIDARG },
2017 {&IID_IDirect3DHALDevice, &IID_IDirectDrawSurface, S_OK },
2018 {&IID_IDirect3D7, NULL, E_INVALIDARG },
2019 {&IID_IDirect3D3, NULL, E_INVALIDARG },
2020 {&IID_IDirect3D2, NULL, E_INVALIDARG },
2021 {&IID_IDirect3D, NULL, E_INVALIDARG },
2022 {&IID_IDirectDraw7, NULL, E_INVALIDARG },
2023 {&IID_IDirectDraw4, NULL, E_INVALIDARG },
2024 {&IID_IDirectDraw3, NULL, E_INVALIDARG },
2025 {&IID_IDirectDraw2, NULL, E_INVALIDARG },
2026 {&IID_IDirectDraw, NULL, E_INVALIDARG },
2027 {&IID_IDirect3DLight, NULL, E_INVALIDARG },
2028 {&IID_IDirect3DMaterial, NULL, E_INVALIDARG },
2029 {&IID_IDirect3DMaterial2, NULL, E_INVALIDARG },
2030 {&IID_IDirect3DMaterial3, NULL, E_INVALIDARG },
2031 {&IID_IDirect3DExecuteBuffer, NULL, E_INVALIDARG },
2032 {&IID_IDirect3DViewport, NULL, E_INVALIDARG },
2033 {&IID_IDirect3DViewport2, NULL, E_INVALIDARG },
2034 {&IID_IDirect3DViewport3, NULL, E_INVALIDARG },
2035 {&IID_IDirect3DVertexBuffer, NULL, E_INVALIDARG },
2036 {&IID_IDirect3DVertexBuffer7, NULL, E_INVALIDARG },
2037 {&IID_IDirectDrawPalette, NULL, E_INVALIDARG },
2038 {&IID_IDirectDrawClipper, NULL, E_INVALIDARG },
2039 {&IID_IUnknown, &IID_IDirectDrawSurface, S_OK },
2043 IDirect3DDevice *device;
2044 IDirectDraw *ddraw;
2045 HWND window;
2047 if (!GetProcAddress(GetModuleHandleA("ddraw.dll"), "DirectDrawCreateEx"))
2049 win_skip("DirectDrawCreateEx not available, skipping test.\n");
2050 return;
2053 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
2054 0, 0, 640, 480, 0, 0, 0, 0);
2055 ddraw = create_ddraw();
2056 ok(!!ddraw, "Failed to create a ddraw object.\n");
2057 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
2059 skip("Failed to create a 3D device, skipping test.\n");
2060 IDirectDraw_Release(ddraw);
2061 DestroyWindow(window);
2062 return;
2065 test_qi("device_qi", (IUnknown *)device, &IID_IDirectDrawSurface, tests, sizeof(tests) / sizeof(*tests));
2067 IDirect3DDevice_Release(device);
2068 IDirectDraw_Release(ddraw);
2069 DestroyWindow(window);
2072 static void test_wndproc(void)
2074 LONG_PTR proc, ddraw_proc;
2075 IDirectDraw *ddraw;
2076 WNDCLASSA wc = {0};
2077 HWND window;
2078 HRESULT hr;
2079 ULONG ref;
2081 static struct message messages[] =
2083 {WM_WINDOWPOSCHANGING, FALSE, 0},
2084 {WM_MOVE, FALSE, 0},
2085 {WM_SIZE, FALSE, 0},
2086 {WM_WINDOWPOSCHANGING, FALSE, 0},
2087 {WM_ACTIVATE, FALSE, 0},
2088 {WM_SETFOCUS, FALSE, 0},
2089 {0, FALSE, 0},
2092 /* DDSCL_EXCLUSIVE replaces the window's window proc. */
2093 ddraw = create_ddraw();
2094 ok(!!ddraw, "Failed to create a ddraw object.\n");
2096 wc.lpfnWndProc = test_proc;
2097 wc.lpszClassName = "ddraw_test_wndproc_wc";
2098 ok(RegisterClassA(&wc), "Failed to register window class.\n");
2100 window = CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
2101 WS_MAXIMIZE | WS_CAPTION , 0, 0, 640, 480, 0, 0, 0, 0);
2103 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2104 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2105 (LONG_PTR)test_proc, proc);
2106 expect_messages = messages;
2107 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2108 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2109 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2110 expect_messages = NULL;
2111 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2112 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
2113 (LONG_PTR)test_proc, proc);
2114 ref = IDirectDraw_Release(ddraw);
2115 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2116 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2117 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2118 (LONG_PTR)test_proc, proc);
2120 /* DDSCL_NORMAL doesn't. */
2121 ddraw = create_ddraw();
2122 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2123 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2124 (LONG_PTR)test_proc, proc);
2125 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL | DDSCL_FULLSCREEN);
2126 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2127 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2128 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2129 (LONG_PTR)test_proc, proc);
2130 ref = IDirectDraw_Release(ddraw);
2131 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2132 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2133 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2134 (LONG_PTR)test_proc, proc);
2136 /* The original window proc is only restored by ddraw if the current
2137 * window proc matches the one ddraw set. This also affects switching
2138 * from DDSCL_NORMAL to DDSCL_EXCLUSIVE. */
2139 ddraw = create_ddraw();
2140 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2141 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2142 (LONG_PTR)test_proc, proc);
2143 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2144 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2145 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2146 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
2147 (LONG_PTR)test_proc, proc);
2148 ddraw_proc = proc;
2149 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2150 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2151 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2152 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2153 (LONG_PTR)test_proc, proc);
2154 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2155 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2156 proc = SetWindowLongPtrA(window, GWLP_WNDPROC, (LONG_PTR)DefWindowProcA);
2157 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
2158 (LONG_PTR)test_proc, proc);
2159 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2160 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2161 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2162 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#lx, got %#lx.\n",
2163 (LONG_PTR)DefWindowProcA, proc);
2164 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2165 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2166 proc = SetWindowLongPtrA(window, GWLP_WNDPROC, (LONG_PTR)ddraw_proc);
2167 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#lx, got %#lx.\n",
2168 (LONG_PTR)DefWindowProcA, proc);
2169 ref = IDirectDraw_Release(ddraw);
2170 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2171 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2172 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2173 (LONG_PTR)test_proc, proc);
2175 ddraw = create_ddraw();
2176 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2177 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2178 (LONG_PTR)test_proc, proc);
2179 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2180 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2181 proc = SetWindowLongPtrA(window, GWLP_WNDPROC, (LONG_PTR)DefWindowProcA);
2182 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
2183 (LONG_PTR)test_proc, proc);
2184 ref = IDirectDraw_Release(ddraw);
2185 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2186 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2187 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#lx, got %#lx.\n",
2188 (LONG_PTR)DefWindowProcA, proc);
2190 fix_wndproc(window, (LONG_PTR)test_proc);
2191 expect_messages = NULL;
2192 DestroyWindow(window);
2193 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL));
2196 static void test_window_style(void)
2198 LONG style, exstyle, tmp, expected_style;
2199 RECT fullscreen_rect, r;
2200 IDirectDraw *ddraw;
2201 HWND window;
2202 HRESULT hr;
2203 ULONG ref;
2204 BOOL ret;
2206 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
2207 0, 0, 100, 100, 0, 0, 0, 0);
2208 ddraw = create_ddraw();
2209 ok(!!ddraw, "Failed to create a ddraw object.\n");
2211 style = GetWindowLongA(window, GWL_STYLE);
2212 exstyle = GetWindowLongA(window, GWL_EXSTYLE);
2213 SetRect(&fullscreen_rect, 0, 0, registry_mode.dmPelsWidth, registry_mode.dmPelsHeight);
2215 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2216 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2218 tmp = GetWindowLongA(window, GWL_STYLE);
2219 todo_wine ok(tmp == style, "Expected window style %#x, got %#x.\n", style, tmp);
2220 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2221 todo_wine ok(tmp == exstyle, "Expected window extended style %#x, got %#x.\n", exstyle, tmp);
2223 GetWindowRect(window, &r);
2224 ok(EqualRect(&r, &fullscreen_rect), "Expected %s, got %s.\n",
2225 wine_dbgstr_rect(&fullscreen_rect), wine_dbgstr_rect(&r));
2226 GetClientRect(window, &r);
2227 todo_wine ok(!EqualRect(&r, &fullscreen_rect), "Client rect and window rect are equal.\n");
2229 ret = SetForegroundWindow(GetDesktopWindow());
2230 ok(ret, "Failed to set foreground window.\n");
2232 tmp = GetWindowLongA(window, GWL_STYLE);
2233 todo_wine ok(tmp == style, "Expected window style %#x, got %#x.\n", style, tmp);
2234 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2235 todo_wine ok(tmp == exstyle, "Expected window extended style %#x, got %#x.\n", exstyle, tmp);
2237 ret = SetForegroundWindow(window);
2238 ok(ret, "Failed to set foreground window.\n");
2239 /* Windows 7 (but not Vista and XP) shows the window when it receives focus. Hide it again,
2240 * the next tests expect this. */
2241 ShowWindow(window, SW_HIDE);
2243 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2244 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2246 tmp = GetWindowLongA(window, GWL_STYLE);
2247 todo_wine ok(tmp == style, "Expected window style %#x, got %#x.\n", style, tmp);
2248 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2249 todo_wine ok(tmp == exstyle, "Expected window extended style %#x, got %#x.\n", exstyle, tmp);
2251 ShowWindow(window, SW_SHOW);
2252 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2253 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2255 tmp = GetWindowLongA(window, GWL_STYLE);
2256 expected_style = style | WS_VISIBLE;
2257 todo_wine ok(tmp == expected_style, "Expected window style %#x, got %#x.\n", expected_style, tmp);
2258 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2259 expected_style = exstyle | WS_EX_TOPMOST;
2260 todo_wine ok(tmp == expected_style, "Expected window extended style %#x, got %#x.\n", expected_style, tmp);
2262 ret = SetForegroundWindow(GetDesktopWindow());
2263 ok(ret, "Failed to set foreground window.\n");
2264 tmp = GetWindowLongA(window, GWL_STYLE);
2265 expected_style = style | WS_VISIBLE | WS_MINIMIZE;
2266 todo_wine ok(tmp == expected_style, "Expected window style %#x, got %#x.\n", expected_style, tmp);
2267 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2268 expected_style = exstyle | WS_EX_TOPMOST;
2269 todo_wine ok(tmp == expected_style, "Expected window extended style %#x, got %#x.\n", expected_style, tmp);
2271 ref = IDirectDraw_Release(ddraw);
2272 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2274 DestroyWindow(window);
2277 static void test_redundant_mode_set(void)
2279 DDSURFACEDESC surface_desc = {0};
2280 IDirectDraw *ddraw;
2281 HWND window;
2282 HRESULT hr;
2283 RECT r, s;
2284 ULONG ref;
2286 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
2287 0, 0, 100, 100, 0, 0, 0, 0);
2288 ddraw = create_ddraw();
2289 ok(!!ddraw, "Failed to create a ddraw object.\n");
2291 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2292 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2294 surface_desc.dwSize = sizeof(surface_desc);
2295 hr = IDirectDraw_GetDisplayMode(ddraw, &surface_desc);
2296 ok(SUCCEEDED(hr), "GetDisplayMode failed, hr %#x.\n", hr);
2298 hr = IDirectDraw_SetDisplayMode(ddraw, surface_desc.dwWidth, surface_desc.dwHeight,
2299 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount);
2300 ok(SUCCEEDED(hr), "SetDisplayMode failed, hr %#x.\n", hr);
2302 GetWindowRect(window, &r);
2303 r.right /= 2;
2304 r.bottom /= 2;
2305 SetWindowPos(window, HWND_TOP, r.left, r.top, r.right, r.bottom, 0);
2306 GetWindowRect(window, &s);
2307 ok(EqualRect(&r, &s), "Expected %s, got %s.\n", wine_dbgstr_rect(&r), wine_dbgstr_rect(&s));
2309 hr = IDirectDraw_SetDisplayMode(ddraw, surface_desc.dwWidth, surface_desc.dwHeight,
2310 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount);
2311 ok(SUCCEEDED(hr), "SetDisplayMode failed, hr %#x.\n", hr);
2313 GetWindowRect(window, &s);
2314 ok(EqualRect(&r, &s), "Expected %s, got %s.\n", wine_dbgstr_rect(&r), wine_dbgstr_rect(&s));
2316 ref = IDirectDraw_Release(ddraw);
2317 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2319 DestroyWindow(window);
2322 static SIZE screen_size;
2324 static LRESULT CALLBACK mode_set_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
2326 if (message == WM_SIZE)
2328 screen_size.cx = GetSystemMetrics(SM_CXSCREEN);
2329 screen_size.cy = GetSystemMetrics(SM_CYSCREEN);
2332 return test_proc(hwnd, message, wparam, lparam);
2335 struct test_coop_level_mode_set_enum_param
2337 DWORD ddraw_width, ddraw_height, user32_width, user32_height;
2340 static HRESULT CALLBACK test_coop_level_mode_set_enum_cb(DDSURFACEDESC *surface_desc, void *context)
2342 struct test_coop_level_mode_set_enum_param *param = context;
2344 if (U1(surface_desc->ddpfPixelFormat).dwRGBBitCount != registry_mode.dmBitsPerPel)
2345 return DDENUMRET_OK;
2346 if (surface_desc->dwWidth == registry_mode.dmPelsWidth
2347 && surface_desc->dwHeight == registry_mode.dmPelsHeight)
2348 return DDENUMRET_OK;
2350 if (!param->ddraw_width)
2352 param->ddraw_width = surface_desc->dwWidth;
2353 param->ddraw_height = surface_desc->dwHeight;
2354 return DDENUMRET_OK;
2356 if (surface_desc->dwWidth == param->ddraw_width && surface_desc->dwHeight == param->ddraw_height)
2357 return DDENUMRET_OK;
2359 param->user32_width = surface_desc->dwWidth;
2360 param->user32_height = surface_desc->dwHeight;
2361 return DDENUMRET_CANCEL;
2364 static void test_coop_level_mode_set(void)
2366 IDirectDrawSurface *primary;
2367 RECT registry_rect, ddraw_rect, user32_rect, r;
2368 IDirectDraw *ddraw;
2369 DDSURFACEDESC ddsd;
2370 WNDCLASSA wc = {0};
2371 HWND window;
2372 HRESULT hr;
2373 ULONG ref;
2374 MSG msg;
2375 struct test_coop_level_mode_set_enum_param param;
2376 DEVMODEW devmode;
2377 BOOL ret;
2378 LONG change_ret;
2380 static const struct message exclusive_messages[] =
2382 {WM_WINDOWPOSCHANGING, FALSE, 0},
2383 {WM_WINDOWPOSCHANGED, FALSE, 0},
2384 {WM_SIZE, FALSE, 0},
2385 {WM_DISPLAYCHANGE, FALSE, 0},
2386 {0, FALSE, 0},
2388 static const struct message exclusive_focus_loss_messages[] =
2390 {WM_ACTIVATE, TRUE, WA_INACTIVE},
2391 {WM_DISPLAYCHANGE, FALSE, 0},
2392 {WM_WINDOWPOSCHANGING, FALSE, 0},
2393 /* Like d3d8 and d3d9 ddraw seems to use SW_SHOWMINIMIZED instead of
2394 * SW_MINIMIZED, causing a recursive window activation that does not
2395 * produce the same result in Wine yet. Ignore the difference for now.
2396 * {WM_ACTIVATE, TRUE, 0x200000 | WA_ACTIVE}, */
2397 {WM_WINDOWPOSCHANGED, FALSE, 0},
2398 {WM_MOVE, FALSE, 0},
2399 {WM_SIZE, TRUE, SIZE_MINIMIZED},
2400 {WM_ACTIVATEAPP, TRUE, FALSE},
2401 {0, FALSE, 0},
2403 static const struct message exclusive_focus_restore_messages[] =
2405 {WM_WINDOWPOSCHANGING, FALSE, 0}, /* From the ShowWindow(SW_RESTORE). */
2406 {WM_WINDOWPOSCHANGING, FALSE, 0}, /* Generated by ddraw, matches d3d9 behavior. */
2407 {WM_WINDOWPOSCHANGED, FALSE, 0}, /* Matching previous message. */
2408 {WM_SIZE, FALSE, 0}, /* DefWindowProc. */
2409 {WM_DISPLAYCHANGE, FALSE, 0}, /* Ddraw restores mode. */
2410 /* Native redundantly sets the window size here. */
2411 {WM_ACTIVATEAPP, TRUE, TRUE}, /* End of ddraw's hooks. */
2412 {WM_WINDOWPOSCHANGED, FALSE, 0}, /* Matching the one from ShowWindow. */
2413 {WM_MOVE, FALSE, 0}, /* DefWindowProc. */
2414 {WM_SIZE, TRUE, SIZE_RESTORED}, /* DefWindowProc. */
2415 {0, FALSE, 0},
2417 static const struct message sc_restore_messages[] =
2419 {WM_SYSCOMMAND, TRUE, SC_RESTORE},
2420 {WM_WINDOWPOSCHANGING, FALSE, 0},
2421 {WM_WINDOWPOSCHANGED, FALSE, 0},
2422 {WM_SIZE, TRUE, SIZE_RESTORED},
2423 {0, FALSE, 0},
2425 static const struct message sc_minimize_messages[] =
2427 {WM_SYSCOMMAND, TRUE, SC_MINIMIZE},
2428 {WM_WINDOWPOSCHANGING, FALSE, 0},
2429 {WM_WINDOWPOSCHANGED, FALSE, 0},
2430 {WM_SIZE, TRUE, SIZE_MINIMIZED},
2431 {0, FALSE, 0},
2433 static const struct message sc_maximize_messages[] =
2435 {WM_SYSCOMMAND, TRUE, SC_MAXIMIZE},
2436 {WM_WINDOWPOSCHANGING, FALSE, 0},
2437 {WM_WINDOWPOSCHANGED, FALSE, 0},
2438 {WM_SIZE, TRUE, SIZE_MAXIMIZED},
2439 {0, FALSE, 0},
2442 static const struct message normal_messages[] =
2444 {WM_DISPLAYCHANGE, FALSE, 0},
2445 {0, FALSE, 0},
2448 ddraw = create_ddraw();
2449 ok(!!ddraw, "Failed to create a ddraw object.\n");
2451 memset(&param, 0, sizeof(param));
2452 hr = IDirectDraw_EnumDisplayModes(ddraw, 0, NULL, &param, test_coop_level_mode_set_enum_cb);
2453 ok(SUCCEEDED(hr), "Failed to enumerate display mode, hr %#x.\n", hr);
2454 ref = IDirectDraw_Release(ddraw);
2455 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2457 if (!param.user32_height)
2459 skip("Fewer than 3 different modes supported, skipping mode restore test.\n");
2460 return;
2463 SetRect(&registry_rect, 0, 0, registry_mode.dmPelsWidth, registry_mode.dmPelsHeight);
2464 SetRect(&ddraw_rect, 0, 0, param.ddraw_width, param.ddraw_height);
2465 SetRect(&user32_rect, 0, 0, param.user32_width, param.user32_height);
2467 memset(&devmode, 0, sizeof(devmode));
2468 devmode.dmSize = sizeof(devmode);
2469 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
2470 devmode.dmPelsWidth = param.user32_width;
2471 devmode.dmPelsHeight = param.user32_height;
2472 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
2473 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2475 ddraw = create_ddraw();
2476 ok(!!ddraw, "Failed to create a ddraw object.\n");
2478 wc.lpfnWndProc = mode_set_proc;
2479 wc.lpszClassName = "ddraw_test_wndproc_wc";
2480 ok(RegisterClassA(&wc), "Failed to register window class.\n");
2482 window = CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test", WS_OVERLAPPEDWINDOW,
2483 0, 0, 100, 100, 0, 0, 0, 0);
2485 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2486 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2488 GetWindowRect(window, &r);
2489 ok(EqualRect(&r, &user32_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&user32_rect),
2490 wine_dbgstr_rect(&r));
2492 memset(&ddsd, 0, sizeof(ddsd));
2493 ddsd.dwSize = sizeof(ddsd);
2494 ddsd.dwFlags = DDSD_CAPS;
2495 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2497 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &primary, NULL);
2498 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2499 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2500 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2501 ok(ddsd.dwWidth == param.user32_width, "Expected surface width %u, got %u.\n",
2502 param.user32_width, ddsd.dwWidth);
2503 ok(ddsd.dwHeight == param.user32_height, "Expected surface height %u, got %u.\n",
2504 param.user32_height, ddsd.dwHeight);
2506 GetWindowRect(window, &r);
2507 ok(EqualRect(&r, &user32_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&user32_rect),
2508 wine_dbgstr_rect(&r));
2510 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2511 expect_messages = exclusive_messages;
2512 screen_size.cx = 0;
2513 screen_size.cy = 0;
2515 hr = IDirectDrawSurface_IsLost(primary);
2516 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
2517 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
2518 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2519 hr = IDirectDrawSurface_IsLost(primary);
2520 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2522 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2523 expect_messages = NULL;
2524 ok(screen_size.cx == param.ddraw_width && screen_size.cy == param.ddraw_height,
2525 "Expected screen size %ux%u, got %ux%u.\n",
2526 param.ddraw_width, param.ddraw_height, screen_size.cx, screen_size.cy);
2528 GetWindowRect(window, &r);
2529 ok(EqualRect(&r, &ddraw_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect),
2530 wine_dbgstr_rect(&r));
2532 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2533 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2534 ok(ddsd.dwWidth == param.user32_width, "Expected surface width %u, got %u.\n",
2535 param.user32_width, ddsd.dwWidth);
2536 ok(ddsd.dwHeight == param.user32_height, "Expected surface height %u, got %u.\n",
2537 param.user32_height, ddsd.dwHeight);
2538 IDirectDrawSurface_Release(primary);
2540 memset(&ddsd, 0, sizeof(ddsd));
2541 ddsd.dwSize = sizeof(ddsd);
2542 ddsd.dwFlags = DDSD_CAPS;
2543 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2545 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &primary, NULL);
2546 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2547 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2548 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2549 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2550 param.ddraw_width, ddsd.dwWidth);
2551 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2552 param.ddraw_height, ddsd.dwHeight);
2554 GetWindowRect(window, &r);
2555 ok(EqualRect(&r, &ddraw_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect),
2556 wine_dbgstr_rect(&r));
2558 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2559 expect_messages = exclusive_messages;
2560 screen_size.cx = 0;
2561 screen_size.cy = 0;
2563 hr = IDirectDrawSurface_IsLost(primary);
2564 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
2565 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
2566 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2567 hr = IDirectDrawSurface_IsLost(primary);
2568 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2570 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2571 expect_messages = NULL;
2572 ok(screen_size.cx == param.user32_width && screen_size.cy == param.user32_height,
2573 "Expected screen size %ux%u, got %ux%u.\n",
2574 param.user32_width, param.user32_height, screen_size.cx, screen_size.cy);
2576 GetWindowRect(window, &r);
2577 ok(EqualRect(&r, &user32_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&user32_rect),
2578 wine_dbgstr_rect(&r));
2580 expect_messages = exclusive_focus_loss_messages;
2581 ret = SetForegroundWindow(GetDesktopWindow());
2582 ok(ret, "Failed to set foreground window.\n");
2583 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2584 memset(&devmode, 0, sizeof(devmode));
2585 devmode.dmSize = sizeof(devmode);
2586 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
2587 ok(ret, "Failed to get display mode.\n");
2588 ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth
2589 && devmode.dmPelsHeight == registry_mode.dmPelsHeight, "Got unexpect screen size %ux%u.\n",
2590 devmode.dmPelsWidth, devmode.dmPelsHeight);
2592 expect_messages = exclusive_focus_restore_messages;
2593 ShowWindow(window, SW_RESTORE);
2594 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2596 GetWindowRect(window, &r);
2597 ok(EqualRect(&r, &ddraw_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect),
2598 wine_dbgstr_rect(&r));
2599 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
2600 ok(ret, "Failed to get display mode.\n");
2601 ok(devmode.dmPelsWidth == param.ddraw_width
2602 && devmode.dmPelsHeight == param.ddraw_height, "Got unexpect screen size %ux%u.\n",
2603 devmode.dmPelsWidth, devmode.dmPelsHeight);
2605 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2606 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2607 /* Normally the primary should be restored here. Unfortunately this causes the
2608 * GetSurfaceDesc call after the next display mode change to crash on the Windows 8
2609 * testbot. Another Restore call would presumably avoid the crash, but it also moots
2610 * the point of the GetSurfaceDesc call. */
2612 expect_messages = sc_minimize_messages;
2613 SendMessageA(window, WM_SYSCOMMAND, SC_MINIMIZE, 0);
2614 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2615 expect_messages = NULL;
2617 expect_messages = sc_restore_messages;
2618 SendMessageA(window, WM_SYSCOMMAND, SC_RESTORE, 0);
2619 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2620 expect_messages = NULL;
2622 expect_messages = sc_maximize_messages;
2623 SendMessageA(window, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
2624 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2625 expect_messages = NULL;
2627 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2628 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2630 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2631 expect_messages = exclusive_messages;
2632 screen_size.cx = 0;
2633 screen_size.cy = 0;
2635 hr = IDirectDrawSurface_IsLost(primary);
2636 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2637 hr = IDirectDraw_RestoreDisplayMode(ddraw);
2638 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
2639 hr = IDirectDrawSurface_IsLost(primary);
2640 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2642 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2643 expect_messages = NULL;
2644 ok(screen_size.cx == registry_mode.dmPelsWidth
2645 && screen_size.cy == registry_mode.dmPelsHeight,
2646 "Expected screen size %ux%u, got %ux%u.\n",
2647 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight, screen_size.cx, screen_size.cy);
2649 GetWindowRect(window, &r);
2650 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2651 wine_dbgstr_rect(&r));
2653 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2654 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2655 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2656 param.ddraw_width, ddsd.dwWidth);
2657 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2658 param.ddraw_height, ddsd.dwHeight);
2659 IDirectDrawSurface_Release(primary);
2661 /* For Wine. */
2662 change_ret = ChangeDisplaySettingsW(NULL, CDS_FULLSCREEN);
2663 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2665 memset(&ddsd, 0, sizeof(ddsd));
2666 ddsd.dwSize = sizeof(ddsd);
2667 ddsd.dwFlags = DDSD_CAPS;
2668 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2670 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &primary, NULL);
2671 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2672 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2673 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2674 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2675 registry_mode.dmPelsWidth, ddsd.dwWidth);
2676 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2677 registry_mode.dmPelsHeight, ddsd.dwHeight);
2679 GetWindowRect(window, &r);
2680 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2681 wine_dbgstr_rect(&r));
2683 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2684 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2686 GetWindowRect(window, &r);
2687 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2688 wine_dbgstr_rect(&r));
2690 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2691 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2692 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2693 registry_mode.dmPelsWidth, ddsd.dwWidth);
2694 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2695 registry_mode.dmPelsHeight, ddsd.dwHeight);
2696 IDirectDrawSurface_Release(primary);
2698 memset(&ddsd, 0, sizeof(ddsd));
2699 ddsd.dwSize = sizeof(ddsd);
2700 ddsd.dwFlags = DDSD_CAPS;
2701 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2703 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &primary, NULL);
2704 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2705 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2706 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2707 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2708 registry_mode.dmPelsWidth, ddsd.dwWidth);
2709 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2710 registry_mode.dmPelsHeight, ddsd.dwHeight);
2712 GetWindowRect(window, &r);
2713 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2714 wine_dbgstr_rect(&r));
2716 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2717 expect_messages = normal_messages;
2718 screen_size.cx = 0;
2719 screen_size.cy = 0;
2721 hr = IDirectDrawSurface_IsLost(primary);
2722 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
2723 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
2724 devmode.dmPelsWidth = param.user32_width;
2725 devmode.dmPelsHeight = param.user32_height;
2726 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
2727 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2728 hr = IDirectDrawSurface_IsLost(primary);
2729 todo_wine ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2731 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2732 expect_messages = NULL;
2733 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2735 GetWindowRect(window, &r);
2736 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2737 wine_dbgstr_rect(&r));
2739 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2740 expect_messages = normal_messages;
2741 screen_size.cx = 0;
2742 screen_size.cy = 0;
2744 hr = IDirectDrawSurface_Restore(primary);
2745 ok(hr == DDERR_WRONGMODE, "Got unexpected hr %#x.\n", hr);
2746 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
2747 if (hr == DDERR_NOEXCLUSIVEMODE /* NT4 testbot */)
2749 win_skip("Broken SetDisplayMode(), skipping remaining tests.\n");
2750 IDirectDrawSurface_Release(primary);
2751 IDirectDraw_Release(ddraw);
2752 goto done;
2754 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2755 hr = IDirectDrawSurface_Restore(primary);
2756 ok(hr == DDERR_WRONGMODE, "Got unexpected hr %#x.\n", hr);
2757 hr = IDirectDrawSurface_IsLost(primary);
2758 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2760 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2761 expect_messages = NULL;
2762 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2764 GetWindowRect(window, &r);
2765 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2766 wine_dbgstr_rect(&r));
2768 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2769 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2770 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2771 registry_mode.dmPelsWidth, ddsd.dwWidth);
2772 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2773 registry_mode.dmPelsHeight, ddsd.dwHeight);
2774 IDirectDrawSurface_Release(primary);
2776 memset(&ddsd, 0, sizeof(ddsd));
2777 ddsd.dwSize = sizeof(ddsd);
2778 ddsd.dwFlags = DDSD_CAPS;
2779 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2781 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &primary, NULL);
2782 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2783 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2784 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2785 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2786 param.ddraw_width, ddsd.dwWidth);
2787 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2788 param.ddraw_height, ddsd.dwHeight);
2790 GetWindowRect(window, &r);
2791 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2792 wine_dbgstr_rect(&r));
2794 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2795 expect_messages = normal_messages;
2796 screen_size.cx = 0;
2797 screen_size.cy = 0;
2799 hr = IDirectDrawSurface_IsLost(primary);
2800 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
2801 hr = IDirectDraw_RestoreDisplayMode(ddraw);
2802 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
2803 hr = IDirectDrawSurface_IsLost(primary);
2804 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2806 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2807 expect_messages = NULL;
2808 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2810 GetWindowRect(window, &r);
2811 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2812 wine_dbgstr_rect(&r));
2814 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2815 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2816 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2817 param.ddraw_width, ddsd.dwWidth);
2818 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2819 param.ddraw_height, ddsd.dwHeight);
2820 IDirectDrawSurface_Release(primary);
2822 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
2823 ok(ret, "Failed to get display mode.\n");
2824 ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth
2825 && devmode.dmPelsHeight == registry_mode.dmPelsHeight,
2826 "Expected resolution %ux%u, got %ux%u.\n",
2827 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight,
2828 devmode.dmPelsWidth, devmode.dmPelsHeight);
2829 change_ret = ChangeDisplaySettingsW(NULL, CDS_FULLSCREEN);
2830 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2832 memset(&ddsd, 0, sizeof(ddsd));
2833 ddsd.dwSize = sizeof(ddsd);
2834 ddsd.dwFlags = DDSD_CAPS;
2835 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2837 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &primary, NULL);
2838 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2839 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2840 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2841 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2842 registry_mode.dmPelsWidth, ddsd.dwWidth);
2843 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2844 registry_mode.dmPelsHeight, ddsd.dwHeight);
2846 GetWindowRect(window, &r);
2847 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2848 wine_dbgstr_rect(&r));
2850 /* DDSCL_NORMAL | DDSCL_FULLSCREEN behaves the same as just DDSCL_NORMAL.
2851 * Resizing the window on mode changes is a property of DDSCL_EXCLUSIVE,
2852 * not DDSCL_FULLSCREEN. */
2853 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL | DDSCL_FULLSCREEN);
2854 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2856 GetWindowRect(window, &r);
2857 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2858 wine_dbgstr_rect(&r));
2860 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2861 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2862 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2863 registry_mode.dmPelsWidth, ddsd.dwWidth);
2864 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2865 registry_mode.dmPelsHeight, ddsd.dwHeight);
2866 IDirectDrawSurface_Release(primary);
2868 memset(&ddsd, 0, sizeof(ddsd));
2869 ddsd.dwSize = sizeof(ddsd);
2870 ddsd.dwFlags = DDSD_CAPS;
2871 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2873 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &primary, NULL);
2874 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2875 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2876 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2877 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2878 registry_mode.dmPelsWidth, ddsd.dwWidth);
2879 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2880 registry_mode.dmPelsHeight, ddsd.dwHeight);
2882 GetWindowRect(window, &r);
2883 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2884 wine_dbgstr_rect(&r));
2886 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2887 expect_messages = normal_messages;
2888 screen_size.cx = 0;
2889 screen_size.cy = 0;
2891 hr = IDirectDrawSurface_IsLost(primary);
2892 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
2893 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
2894 devmode.dmPelsWidth = param.user32_width;
2895 devmode.dmPelsHeight = param.user32_height;
2896 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
2897 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2898 hr = IDirectDrawSurface_IsLost(primary);
2899 todo_wine ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2901 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2902 expect_messages = NULL;
2903 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2905 GetWindowRect(window, &r);
2906 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2907 wine_dbgstr_rect(&r));
2909 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2910 expect_messages = normal_messages;
2911 screen_size.cx = 0;
2912 screen_size.cy = 0;
2914 hr = IDirectDrawSurface_Restore(primary);
2915 ok(hr == DDERR_WRONGMODE, "Got unexpected hr %#x.\n", hr);
2916 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
2917 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2918 hr = IDirectDrawSurface_Restore(primary);
2919 ok(hr == DDERR_WRONGMODE, "Got unexpected hr %#x.\n", hr);
2920 hr = IDirectDrawSurface_IsLost(primary);
2921 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2923 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2924 expect_messages = NULL;
2925 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2927 GetWindowRect(window, &r);
2928 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2929 wine_dbgstr_rect(&r));
2931 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2932 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2933 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2934 registry_mode.dmPelsWidth, ddsd.dwWidth);
2935 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2936 registry_mode.dmPelsHeight, ddsd.dwHeight);
2937 IDirectDrawSurface_Release(primary);
2939 memset(&ddsd, 0, sizeof(ddsd));
2940 ddsd.dwSize = sizeof(ddsd);
2941 ddsd.dwFlags = DDSD_CAPS;
2942 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2944 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &primary, NULL);
2945 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2946 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2947 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2948 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2949 param.ddraw_width, ddsd.dwWidth);
2950 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2951 param.ddraw_height, ddsd.dwHeight);
2953 GetWindowRect(window, &r);
2954 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2955 wine_dbgstr_rect(&r));
2957 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2958 expect_messages = normal_messages;
2959 screen_size.cx = 0;
2960 screen_size.cy = 0;
2962 hr = IDirectDrawSurface_IsLost(primary);
2963 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
2964 hr = IDirectDraw_RestoreDisplayMode(ddraw);
2965 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
2966 hr = IDirectDrawSurface_IsLost(primary);
2967 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2969 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2970 expect_messages = NULL;
2971 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2973 GetWindowRect(window, &r);
2974 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2975 wine_dbgstr_rect(&r));
2977 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2978 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2979 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2980 param.ddraw_width, ddsd.dwWidth);
2981 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2982 param.ddraw_height, ddsd.dwHeight);
2983 IDirectDrawSurface_Release(primary);
2985 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
2986 ok(ret, "Failed to get display mode.\n");
2987 ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth
2988 && devmode.dmPelsHeight == registry_mode.dmPelsHeight,
2989 "Expected resolution %ux%u, got %ux%u.\n",
2990 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight,
2991 devmode.dmPelsWidth, devmode.dmPelsHeight);
2992 change_ret = ChangeDisplaySettingsW(NULL, CDS_FULLSCREEN);
2993 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2995 memset(&ddsd, 0, sizeof(ddsd));
2996 ddsd.dwSize = sizeof(ddsd);
2997 ddsd.dwFlags = DDSD_CAPS;
2998 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3000 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &primary, NULL);
3001 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
3002 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
3003 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
3004 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
3005 registry_mode.dmPelsWidth, ddsd.dwWidth);
3006 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
3007 registry_mode.dmPelsHeight, ddsd.dwHeight);
3008 IDirectDrawSurface_Release(primary);
3010 GetWindowRect(window, &r);
3011 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
3012 wine_dbgstr_rect(&r));
3014 /* Unlike ddraw2-7, changing from EXCLUSIVE to NORMAL does not restore the resolution */
3015 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3016 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3017 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
3018 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3020 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
3021 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3023 memset(&ddsd, 0, sizeof(ddsd));
3024 ddsd.dwSize = sizeof(ddsd);
3025 ddsd.dwFlags = DDSD_CAPS;
3026 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3028 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &primary, NULL);
3029 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
3030 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
3031 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
3032 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
3033 param.ddraw_width, ddsd.dwWidth);
3034 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
3035 param.ddraw_height, ddsd.dwHeight);
3036 IDirectDrawSurface_Release(primary);
3037 hr = IDirectDraw_RestoreDisplayMode(ddraw);
3038 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
3040 ref = IDirectDraw_Release(ddraw);
3041 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3043 GetWindowRect(window, &r);
3044 ok(EqualRect(&r, &ddraw_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect),
3045 wine_dbgstr_rect(&r));
3047 done:
3048 expect_messages = NULL;
3049 DestroyWindow(window);
3050 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL));
3053 static void test_coop_level_mode_set_multi(void)
3055 IDirectDraw *ddraw1, *ddraw2;
3056 UINT w, h;
3057 HWND window;
3058 HRESULT hr;
3059 ULONG ref;
3061 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
3062 0, 0, 100, 100, 0, 0, 0, 0);
3063 ddraw1 = create_ddraw();
3064 ok(!!ddraw1, "Failed to create a ddraw object.\n");
3066 /* With just a single ddraw object, the display mode is restored on
3067 * release. */
3068 hr = set_display_mode(ddraw1, 800, 600);
3069 if (hr == DDERR_NOEXCLUSIVEMODE /* NT4 testbot */)
3071 win_skip("Broken SetDisplayMode(), skipping test.\n");
3072 IDirectDraw_Release(ddraw1);
3073 DestroyWindow(window);
3074 return;
3076 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3077 w = GetSystemMetrics(SM_CXSCREEN);
3078 ok(w == 800, "Got unexpected screen width %u.\n", w);
3079 h = GetSystemMetrics(SM_CYSCREEN);
3080 ok(h == 600, "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 == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3086 h = GetSystemMetrics(SM_CYSCREEN);
3087 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3089 /* When there are multiple ddraw objects, the display mode is restored to
3090 * the initial mode, before the first SetDisplayMode() call. */
3091 ddraw1 = create_ddraw();
3092 hr = set_display_mode(ddraw1, 800, 600);
3093 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3094 w = GetSystemMetrics(SM_CXSCREEN);
3095 ok(w == 800, "Got unexpected screen width %u.\n", w);
3096 h = GetSystemMetrics(SM_CYSCREEN);
3097 ok(h == 600, "Got unexpected screen height %u.\n", h);
3099 ddraw2 = create_ddraw();
3100 hr = set_display_mode(ddraw2, 640, 480);
3101 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3102 w = GetSystemMetrics(SM_CXSCREEN);
3103 ok(w == 640, "Got unexpected screen width %u.\n", w);
3104 h = GetSystemMetrics(SM_CYSCREEN);
3105 ok(h == 480, "Got unexpected screen height %u.\n", h);
3107 ref = IDirectDraw_Release(ddraw2);
3108 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3109 w = GetSystemMetrics(SM_CXSCREEN);
3110 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3111 h = GetSystemMetrics(SM_CYSCREEN);
3112 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3114 ref = IDirectDraw_Release(ddraw1);
3115 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3116 w = GetSystemMetrics(SM_CXSCREEN);
3117 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3118 h = GetSystemMetrics(SM_CYSCREEN);
3119 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3121 /* Regardless of release ordering. */
3122 ddraw1 = create_ddraw();
3123 hr = set_display_mode(ddraw1, 800, 600);
3124 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3125 w = GetSystemMetrics(SM_CXSCREEN);
3126 ok(w == 800, "Got unexpected screen width %u.\n", w);
3127 h = GetSystemMetrics(SM_CYSCREEN);
3128 ok(h == 600, "Got unexpected screen height %u.\n", h);
3130 ddraw2 = create_ddraw();
3131 hr = set_display_mode(ddraw2, 640, 480);
3132 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3133 w = GetSystemMetrics(SM_CXSCREEN);
3134 ok(w == 640, "Got unexpected screen width %u.\n", w);
3135 h = GetSystemMetrics(SM_CYSCREEN);
3136 ok(h == 480, "Got unexpected screen height %u.\n", h);
3138 ref = IDirectDraw_Release(ddraw1);
3139 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3140 w = GetSystemMetrics(SM_CXSCREEN);
3141 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3142 h = GetSystemMetrics(SM_CYSCREEN);
3143 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3145 ref = IDirectDraw_Release(ddraw2);
3146 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3147 w = GetSystemMetrics(SM_CXSCREEN);
3148 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3149 h = GetSystemMetrics(SM_CYSCREEN);
3150 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3152 /* But only for ddraw objects that called SetDisplayMode(). */
3153 ddraw1 = create_ddraw();
3154 ddraw2 = create_ddraw();
3155 hr = set_display_mode(ddraw2, 640, 480);
3156 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3157 w = GetSystemMetrics(SM_CXSCREEN);
3158 ok(w == 640, "Got unexpected screen width %u.\n", w);
3159 h = GetSystemMetrics(SM_CYSCREEN);
3160 ok(h == 480, "Got unexpected screen height %u.\n", h);
3162 ref = IDirectDraw_Release(ddraw1);
3163 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3164 w = GetSystemMetrics(SM_CXSCREEN);
3165 ok(w == 640, "Got unexpected screen width %u.\n", w);
3166 h = GetSystemMetrics(SM_CYSCREEN);
3167 ok(h == 480, "Got unexpected screen height %u.\n", h);
3169 ref = IDirectDraw_Release(ddraw2);
3170 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3171 w = GetSystemMetrics(SM_CXSCREEN);
3172 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3173 h = GetSystemMetrics(SM_CYSCREEN);
3174 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3176 /* If there's a ddraw object that's currently in exclusive mode, it blocks
3177 * restoring the display mode. */
3178 ddraw1 = create_ddraw();
3179 hr = set_display_mode(ddraw1, 800, 600);
3180 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3181 w = GetSystemMetrics(SM_CXSCREEN);
3182 ok(w == 800, "Got unexpected screen width %u.\n", w);
3183 h = GetSystemMetrics(SM_CYSCREEN);
3184 ok(h == 600, "Got unexpected screen height %u.\n", h);
3186 ddraw2 = create_ddraw();
3187 hr = set_display_mode(ddraw2, 640, 480);
3188 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3189 w = GetSystemMetrics(SM_CXSCREEN);
3190 ok(w == 640, "Got unexpected screen width %u.\n", w);
3191 h = GetSystemMetrics(SM_CYSCREEN);
3192 ok(h == 480, "Got unexpected screen height %u.\n", h);
3194 hr = IDirectDraw_SetCooperativeLevel(ddraw2, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3195 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3197 ref = IDirectDraw_Release(ddraw1);
3198 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3199 w = GetSystemMetrics(SM_CXSCREEN);
3200 ok(w == 640, "Got unexpected screen width %u.\n", w);
3201 h = GetSystemMetrics(SM_CYSCREEN);
3202 ok(h == 480, "Got unexpected screen height %u.\n", h);
3204 ref = IDirectDraw_Release(ddraw2);
3205 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3206 w = GetSystemMetrics(SM_CXSCREEN);
3207 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3208 h = GetSystemMetrics(SM_CYSCREEN);
3209 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3211 /* Exclusive mode blocks mode setting on other ddraw objects in general. */
3212 ddraw1 = create_ddraw();
3213 hr = set_display_mode(ddraw1, 800, 600);
3214 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3215 w = GetSystemMetrics(SM_CXSCREEN);
3216 ok(w == 800, "Got unexpected screen width %u.\n", w);
3217 h = GetSystemMetrics(SM_CYSCREEN);
3218 ok(h == 600, "Got unexpected screen height %u.\n", h);
3220 hr = IDirectDraw_SetCooperativeLevel(ddraw1, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3221 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3223 ddraw2 = create_ddraw();
3224 hr = set_display_mode(ddraw2, 640, 480);
3225 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
3227 ref = IDirectDraw_Release(ddraw1);
3228 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3229 w = GetSystemMetrics(SM_CXSCREEN);
3230 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3231 h = GetSystemMetrics(SM_CYSCREEN);
3232 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3234 ref = IDirectDraw_Release(ddraw2);
3235 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3236 w = GetSystemMetrics(SM_CXSCREEN);
3237 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3238 h = GetSystemMetrics(SM_CYSCREEN);
3239 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3241 DestroyWindow(window);
3244 static void test_initialize(void)
3246 IDirectDraw *ddraw;
3247 IDirect3D *d3d;
3248 HRESULT hr;
3250 ddraw = create_ddraw();
3251 ok(!!ddraw, "Failed to create a ddraw object.\n");
3253 hr = IDirectDraw_Initialize(ddraw, NULL);
3254 ok(hr == DDERR_ALREADYINITIALIZED, "Initialize returned hr %#x.\n", hr);
3255 IDirectDraw_Release(ddraw);
3257 CoInitialize(NULL);
3258 hr = CoCreateInstance(&CLSID_DirectDraw, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectDraw, (void **)&ddraw);
3259 ok(SUCCEEDED(hr), "Failed to create IDirectDraw instance, hr %#x.\n", hr);
3260 hr = IDirectDraw_QueryInterface(ddraw, &IID_IDirect3D, (void **)&d3d);
3261 if (SUCCEEDED(hr))
3263 /* IDirect3D_Initialize() just returns DDERR_ALREADYINITIALIZED. */
3264 hr = IDirect3D_Initialize(d3d, NULL);
3265 ok(hr == DDERR_ALREADYINITIALIZED, "Initialize returned hr %#x, expected DDERR_ALREADYINITIALIZED.\n", hr);
3266 IDirect3D_Release(d3d);
3268 else
3269 skip("D3D interface is not available, skipping test.\n");
3270 hr = IDirectDraw_Initialize(ddraw, NULL);
3271 ok(hr == DD_OK, "Initialize returned hr %#x, expected DD_OK.\n", hr);
3272 hr = IDirectDraw_Initialize(ddraw, NULL);
3273 ok(hr == DDERR_ALREADYINITIALIZED, "Initialize returned hr %#x, expected DDERR_ALREADYINITIALIZED.\n", hr);
3274 IDirectDraw_Release(ddraw);
3275 CoUninitialize();
3277 if (0) /* This crashes on the W2KPROSP4 testbot. */
3279 CoInitialize(NULL);
3280 hr = CoCreateInstance(&CLSID_DirectDraw, NULL, CLSCTX_INPROC_SERVER, &IID_IDirect3D, (void **)&d3d);
3281 ok(hr == E_NOINTERFACE, "CoCreateInstance returned hr %#x, expected E_NOINTERFACE.\n", hr);
3282 CoUninitialize();
3286 static void test_coop_level_surf_create(void)
3288 IDirectDrawSurface *surface;
3289 IDirectDraw *ddraw;
3290 DDSURFACEDESC ddsd;
3291 HRESULT hr;
3293 ddraw = create_ddraw();
3294 ok(!!ddraw, "Failed to create a ddraw object.\n");
3296 memset(&ddsd, 0, sizeof(ddsd));
3297 ddsd.dwSize = sizeof(ddsd);
3298 ddsd.dwFlags = DDSD_CAPS;
3299 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3300 surface = (void *)0xdeadbeef;
3301 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &surface, NULL);
3302 ok(hr == DDERR_NOCOOPERATIVELEVELSET, "Surface creation returned hr %#x.\n", hr);
3303 ok(surface == (void *)0xdeadbeef, "Got unexpected surface %p.\n", surface);
3305 IDirectDraw_Release(ddraw);
3308 static void test_coop_level_multi_window(void)
3310 HWND window1, window2;
3311 IDirectDraw *ddraw;
3312 HRESULT hr;
3314 window1 = CreateWindowA("static", "ddraw_test1", WS_OVERLAPPEDWINDOW,
3315 0, 0, 640, 480, 0, 0, 0, 0);
3316 window2 = CreateWindowA("static", "ddraw_test2", WS_OVERLAPPEDWINDOW,
3317 0, 0, 640, 480, 0, 0, 0, 0);
3318 ddraw = create_ddraw();
3319 ok(!!ddraw, "Failed to create a ddraw object.\n");
3321 hr = IDirectDraw_SetCooperativeLevel(ddraw, window1, DDSCL_NORMAL);
3322 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3323 hr = IDirectDraw_SetCooperativeLevel(ddraw, window2, DDSCL_NORMAL);
3324 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3325 ok(IsWindow(window1), "Window 1 was destroyed.\n");
3326 ok(IsWindow(window2), "Window 2 was destroyed.\n");
3328 IDirectDraw_Release(ddraw);
3329 DestroyWindow(window2);
3330 DestroyWindow(window1);
3333 static void test_clear_rect_count(void)
3335 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
3336 IDirect3DMaterial *white, *red, *green, *blue;
3337 IDirect3DViewport *viewport;
3338 IDirect3DDevice *device;
3339 IDirectDrawSurface *rt;
3340 IDirectDraw *ddraw;
3341 D3DCOLOR color;
3342 HWND window;
3343 HRESULT hr;
3345 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
3346 0, 0, 640, 480, 0, 0, 0, 0);
3347 ddraw = create_ddraw();
3348 ok(!!ddraw, "Failed to create a ddraw object.\n");
3349 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
3351 skip("Failed to create a 3D device, skipping test.\n");
3352 IDirectDraw_Release(ddraw);
3353 DestroyWindow(window);
3354 return;
3357 hr = IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&rt);
3358 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
3360 white = create_diffuse_material(device, 1.0f, 1.0f, 1.0f, 1.0f);
3361 red = create_diffuse_material(device, 1.0f, 0.0f, 0.0f, 1.0f);
3362 green = create_diffuse_material(device, 0.0f, 1.0f, 0.0f, 1.0f);
3363 blue = create_diffuse_material(device, 0.0f, 0.0f, 1.0f, 1.0f);
3364 viewport = create_viewport(device, 0, 0, 640, 480);
3366 viewport_set_background(device, viewport, white);
3367 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
3368 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
3369 viewport_set_background(device, viewport, red);
3370 hr = IDirect3DViewport_Clear(viewport, 0, &clear_rect, D3DCLEAR_TARGET);
3371 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
3372 viewport_set_background(device, viewport, green);
3373 hr = IDirect3DViewport_Clear(viewport, 0, NULL, D3DCLEAR_TARGET);
3374 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
3375 viewport_set_background(device, viewport, blue);
3376 hr = IDirect3DViewport_Clear(viewport, 1, NULL, D3DCLEAR_TARGET);
3377 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
3379 color = get_surface_color(rt, 320, 240);
3380 ok(compare_color(color, 0x00ffffff, 1) || broken(compare_color(color, 0x000000ff, 1)),
3381 "Got unexpected color 0x%08x.\n", color);
3383 IDirectDrawSurface_Release(rt);
3384 destroy_viewport(device, viewport);
3385 destroy_material(white);
3386 destroy_material(red);
3387 destroy_material(green);
3388 destroy_material(blue);
3389 IDirect3DDevice_Release(device);
3390 IDirectDraw_Release(ddraw);
3391 DestroyWindow(window);
3394 static struct
3396 BOOL received;
3397 IDirectDraw *ddraw;
3398 HWND window;
3399 DWORD coop_level;
3400 } activateapp_testdata;
3402 static LRESULT CALLBACK activateapp_test_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
3404 if (message == WM_ACTIVATEAPP)
3406 if (activateapp_testdata.ddraw)
3408 HRESULT hr;
3409 activateapp_testdata.received = FALSE;
3410 hr = IDirectDraw_SetCooperativeLevel(activateapp_testdata.ddraw,
3411 activateapp_testdata.window, activateapp_testdata.coop_level);
3412 ok(SUCCEEDED(hr), "Recursive SetCooperativeLevel call failed, hr %#x.\n", hr);
3413 ok(!activateapp_testdata.received, "Received WM_ACTIVATEAPP during recursive SetCooperativeLevel call.\n");
3415 activateapp_testdata.received = TRUE;
3418 return DefWindowProcA(hwnd, message, wparam, lparam);
3421 static void test_coop_level_activateapp(void)
3423 IDirectDraw *ddraw;
3424 HRESULT hr;
3425 HWND window;
3426 WNDCLASSA wc = {0};
3427 DDSURFACEDESC ddsd;
3428 IDirectDrawSurface *surface;
3430 ddraw = create_ddraw();
3431 ok(!!ddraw, "Failed to create a ddraw object.\n");
3433 wc.lpfnWndProc = activateapp_test_proc;
3434 wc.lpszClassName = "ddraw_test_wndproc_wc";
3435 ok(RegisterClassA(&wc), "Failed to register window class.\n");
3437 window = CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
3438 WS_MAXIMIZE | WS_CAPTION , 0, 0, 640, 480, 0, 0, 0, 0);
3440 /* Exclusive with window already active. */
3441 SetForegroundWindow(window);
3442 activateapp_testdata.received = FALSE;
3443 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3444 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3445 ok(!activateapp_testdata.received, "Received WM_ACTIVATEAPP although window was already active.\n");
3446 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3447 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3449 /* Exclusive with window not active. */
3450 SetForegroundWindow(GetDesktopWindow());
3451 activateapp_testdata.received = FALSE;
3452 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3453 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3454 ok(activateapp_testdata.received, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3455 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3456 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3458 /* Normal with window not active, then exclusive with the same window. */
3459 SetForegroundWindow(GetDesktopWindow());
3460 activateapp_testdata.received = FALSE;
3461 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
3462 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3463 ok(!activateapp_testdata.received, "Received WM_ACTIVATEAPP when setting DDSCL_NORMAL.\n");
3464 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3465 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3466 ok(activateapp_testdata.received, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3467 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3468 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3470 /* Recursive set of DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN. */
3471 SetForegroundWindow(GetDesktopWindow());
3472 activateapp_testdata.received = FALSE;
3473 activateapp_testdata.ddraw = ddraw;
3474 activateapp_testdata.window = window;
3475 activateapp_testdata.coop_level = DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN;
3476 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3477 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3478 ok(activateapp_testdata.received, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3479 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3480 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3482 /* The recursive call seems to have some bad effect on native ddraw, despite (apparently)
3483 * succeeding. Another switch to exclusive and back to normal is needed to release the
3484 * window properly. Without doing this, SetCooperativeLevel(EXCLUSIVE) will not send
3485 * WM_ACTIVATEAPP messages. */
3486 activateapp_testdata.ddraw = NULL;
3487 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3488 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3489 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3490 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3492 /* Setting DDSCL_NORMAL with recursive invocation. */
3493 SetForegroundWindow(GetDesktopWindow());
3494 activateapp_testdata.received = FALSE;
3495 activateapp_testdata.ddraw = ddraw;
3496 activateapp_testdata.window = window;
3497 activateapp_testdata.coop_level = DDSCL_NORMAL;
3498 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3499 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3500 ok(activateapp_testdata.received, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3502 /* DDraw is in exclusive mode now. */
3503 memset(&ddsd, 0, sizeof(ddsd));
3504 ddsd.dwSize = sizeof(ddsd);
3505 ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
3506 ddsd.dwBackBufferCount = 1;
3507 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
3508 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &surface, NULL);
3509 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
3510 IDirectDrawSurface_Release(surface);
3512 /* Recover again, just to be sure. */
3513 activateapp_testdata.ddraw = NULL;
3514 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3515 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3516 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3517 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3519 DestroyWindow(window);
3520 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL));
3521 IDirectDraw_Release(ddraw);
3524 struct format_support_check
3526 const DDPIXELFORMAT *format;
3527 BOOL supported;
3530 static HRESULT WINAPI test_unsupported_formats_cb(DDSURFACEDESC *desc, void *ctx)
3532 struct format_support_check *format = ctx;
3534 if (!memcmp(format->format, &desc->ddpfPixelFormat, sizeof(*format->format)))
3536 format->supported = TRUE;
3537 return DDENUMRET_CANCEL;
3540 return DDENUMRET_OK;
3543 static void test_unsupported_formats(void)
3545 HRESULT hr;
3546 BOOL expect_success;
3547 HWND window;
3548 IDirectDraw *ddraw;
3549 IDirect3DDevice *device;
3550 IDirectDrawSurface *surface;
3551 DDSURFACEDESC ddsd;
3552 unsigned int i, j;
3553 DWORD expected_caps;
3554 static const struct
3556 const char *name;
3557 DDPIXELFORMAT fmt;
3559 formats[] =
3562 "D3DFMT_A8R8G8B8",
3564 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
3565 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
3569 "D3DFMT_P8",
3571 sizeof(DDPIXELFORMAT), DDPF_PALETTEINDEXED8 | DDPF_RGB, 0,
3572 {8 }, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}
3576 static const DWORD caps[] = {0, DDSCAPS_SYSTEMMEMORY, DDSCAPS_VIDEOMEMORY};
3578 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
3579 0, 0, 640, 480, 0, 0, 0, 0);
3580 ddraw = create_ddraw();
3581 ok(!!ddraw, "Failed to create a ddraw object.\n");
3582 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
3584 skip("Failed to create a 3D device, skipping test.\n");
3585 IDirectDraw_Release(ddraw);
3586 DestroyWindow(window);
3587 return;
3590 for (i = 0; i < sizeof(formats) / sizeof(*formats); i++)
3592 struct format_support_check check = {&formats[i].fmt, FALSE};
3593 hr = IDirect3DDevice_EnumTextureFormats(device, test_unsupported_formats_cb, &check);
3594 ok(SUCCEEDED(hr), "Failed to enumerate texture formats %#x.\n", hr);
3596 for (j = 0; j < sizeof(caps) / sizeof(*caps); j++)
3598 memset(&ddsd, 0, sizeof(ddsd));
3599 ddsd.dwSize = sizeof(ddsd);
3600 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
3601 ddsd.ddpfPixelFormat = formats[i].fmt;
3602 ddsd.dwWidth = 4;
3603 ddsd.dwHeight = 4;
3604 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | caps[j];
3606 if (caps[j] & DDSCAPS_VIDEOMEMORY && !check.supported)
3607 expect_success = FALSE;
3608 else
3609 expect_success = TRUE;
3611 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &surface, NULL);
3612 ok(SUCCEEDED(hr) == expect_success,
3613 "Got unexpected hr %#x for format %s, caps %#x, expected %s.\n",
3614 hr, formats[i].name, caps[j], expect_success ? "success" : "failure");
3615 if (FAILED(hr))
3616 continue;
3618 memset(&ddsd, 0, sizeof(ddsd));
3619 ddsd.dwSize = sizeof(ddsd);
3620 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &ddsd);
3621 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
3623 if (caps[j] & DDSCAPS_VIDEOMEMORY)
3624 expected_caps = DDSCAPS_VIDEOMEMORY;
3625 else if (caps[j] & DDSCAPS_SYSTEMMEMORY)
3626 expected_caps = DDSCAPS_SYSTEMMEMORY;
3627 else if (check.supported)
3628 expected_caps = DDSCAPS_VIDEOMEMORY;
3629 else
3630 expected_caps = DDSCAPS_SYSTEMMEMORY;
3632 ok(ddsd.ddsCaps.dwCaps & expected_caps,
3633 "Expected capability %#x, format %s, input cap %#x.\n",
3634 expected_caps, formats[i].name, caps[j]);
3636 IDirectDrawSurface_Release(surface);
3640 IDirect3DDevice_Release(device);
3641 IDirectDraw_Release(ddraw);
3642 DestroyWindow(window);
3645 static void test_rt_caps(void)
3647 PALETTEENTRY palette_entries[256];
3648 IDirectDrawPalette *palette;
3649 IDirect3DDevice *device;
3650 IDirectDraw *ddraw;
3651 DWORD z_depth = 0;
3652 unsigned int i;
3653 ULONG refcount;
3654 HWND window;
3655 HRESULT hr;
3657 static const DDPIXELFORMAT p8_fmt =
3659 sizeof(DDPIXELFORMAT), DDPF_PALETTEINDEXED8 | DDPF_RGB, 0,
3660 {8}, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000},
3663 static const struct
3665 const DDPIXELFORMAT *pf;
3666 DWORD caps_in;
3667 DWORD caps_out;
3668 HRESULT create_device_hr;
3669 BOOL create_may_fail;
3671 test_data[] =
3674 NULL,
3675 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY,
3676 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
3677 D3D_OK,
3678 FALSE,
3681 NULL,
3682 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE,
3683 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
3684 D3D_OK,
3685 FALSE,
3688 NULL,
3689 DDSCAPS_OFFSCREENPLAIN,
3690 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
3691 DDERR_INVALIDCAPS,
3692 FALSE,
3695 NULL,
3696 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
3697 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
3698 D3DERR_SURFACENOTINVIDMEM,
3699 FALSE,
3702 NULL,
3703 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
3704 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
3705 DDERR_INVALIDCAPS,
3706 FALSE,
3709 NULL,
3710 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY,
3711 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
3712 D3D_OK,
3713 FALSE,
3716 NULL,
3717 DDSCAPS_3DDEVICE,
3718 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
3719 D3D_OK,
3720 FALSE,
3723 NULL,
3725 DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
3726 DDERR_INVALIDCAPS,
3727 FALSE,
3730 NULL,
3731 DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
3732 DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
3733 D3DERR_SURFACENOTINVIDMEM,
3734 FALSE,
3737 NULL,
3738 DDSCAPS_SYSTEMMEMORY,
3739 DDSCAPS_SYSTEMMEMORY,
3740 DDERR_INVALIDCAPS,
3741 FALSE,
3744 &p8_fmt,
3746 DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
3747 DDERR_INVALIDCAPS,
3748 FALSE,
3751 &p8_fmt,
3752 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE,
3753 ~0U /* AMD r200 */ ,
3754 DDERR_NOPALETTEATTACHED,
3755 FALSE,
3758 &p8_fmt,
3759 DDSCAPS_OFFSCREENPLAIN,
3760 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
3761 DDERR_INVALIDCAPS,
3762 FALSE,
3765 &p8_fmt,
3766 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
3767 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
3768 DDERR_NOPALETTEATTACHED,
3769 FALSE,
3772 &p8_fmt,
3773 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
3774 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
3775 DDERR_INVALIDCAPS,
3776 FALSE,
3779 NULL,
3780 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_ZBUFFER,
3781 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_ZBUFFER | DDSCAPS_LOCALVIDMEM,
3782 DDERR_INVALIDCAPS,
3783 TRUE /* AMD Evergreen */,
3786 NULL,
3787 DDSCAPS_3DDEVICE | DDSCAPS_ZBUFFER,
3788 ~0U /* AMD Evergreen */,
3789 DDERR_INVALIDCAPS,
3790 FALSE,
3793 NULL,
3794 DDSCAPS_ZBUFFER,
3795 ~0U /* AMD Evergreen */,
3796 DDERR_INVALIDCAPS,
3797 FALSE,
3800 NULL,
3801 DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE | DDSCAPS_ZBUFFER,
3802 DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE | DDSCAPS_ZBUFFER,
3803 DDERR_INVALIDCAPS,
3804 TRUE /* Nvidia Kepler */,
3807 NULL,
3808 DDSCAPS_SYSTEMMEMORY | DDSCAPS_ZBUFFER,
3809 DDSCAPS_SYSTEMMEMORY | DDSCAPS_ZBUFFER,
3810 DDERR_INVALIDCAPS,
3811 TRUE /* Nvidia Kepler */,
3815 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
3816 0, 0, 640, 480, 0, 0, 0, 0);
3817 ddraw = create_ddraw();
3818 ok(!!ddraw, "Failed to create a ddraw object.\n");
3819 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
3821 skip("Failed to create a 3D device, skipping test.\n");
3822 IDirectDraw_Release(ddraw);
3823 DestroyWindow(window);
3824 return;
3826 z_depth = get_device_z_depth(device);
3827 ok(!!z_depth, "Failed to get device z depth.\n");
3828 IDirect3DDevice_Release(device);
3830 memset(palette_entries, 0, sizeof(palette_entries));
3831 hr = IDirectDraw_CreatePalette(ddraw, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, palette_entries, &palette, NULL);
3832 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
3834 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
3836 IDirectDrawSurface *surface;
3837 DDSURFACEDESC surface_desc;
3838 IDirect3DDevice *device;
3840 memset(&surface_desc, 0, sizeof(surface_desc));
3841 surface_desc.dwSize = sizeof(surface_desc);
3842 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
3843 surface_desc.ddsCaps.dwCaps = test_data[i].caps_in;
3844 if (test_data[i].pf)
3846 surface_desc.dwFlags |= DDSD_PIXELFORMAT;
3847 surface_desc.ddpfPixelFormat = *test_data[i].pf;
3849 if (test_data[i].caps_in & DDSCAPS_ZBUFFER)
3851 surface_desc.dwFlags |= DDSD_ZBUFFERBITDEPTH;
3852 U2(surface_desc).dwZBufferBitDepth = z_depth;
3854 surface_desc.dwWidth = 640;
3855 surface_desc.dwHeight = 480;
3856 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
3857 ok(SUCCEEDED(hr) || broken(test_data[i].create_may_fail),
3858 "Test %u: Failed to create surface with caps %#x, hr %#x.\n",
3859 i, test_data[i].caps_in, hr);
3860 if (FAILED(hr))
3861 continue;
3863 memset(&surface_desc, 0, sizeof(surface_desc));
3864 surface_desc.dwSize = sizeof(surface_desc);
3865 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
3866 ok(SUCCEEDED(hr), "Test %u: Failed to get surface desc, hr %#x.\n", i, hr);
3867 ok(test_data[i].caps_out == ~0U || surface_desc.ddsCaps.dwCaps == test_data[i].caps_out,
3868 "Test %u: Got unexpected caps %#x, expected %#x.\n",
3869 i, surface_desc.ddsCaps.dwCaps, test_data[i].caps_out);
3871 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirect3DHALDevice, (void **)&device);
3872 ok(hr == test_data[i].create_device_hr, "Test %u: Got unexpected hr %#x, expected %#x.\n",
3873 i, hr, test_data[i].create_device_hr);
3874 if (hr == DDERR_NOPALETTEATTACHED)
3876 hr = IDirectDrawSurface_SetPalette(surface, palette);
3877 ok(SUCCEEDED(hr), "Test %u: Failed to set palette, hr %#x.\n", i, hr);
3878 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirect3DHALDevice, (void **)&device);
3879 if (surface_desc.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY)
3880 ok(hr == DDERR_INVALIDPIXELFORMAT, "Test %u: Got unexpected hr %#x.\n", i, hr);
3881 else
3882 ok(hr == D3DERR_SURFACENOTINVIDMEM, "Test %u: Got unexpected hr %#x.\n", i, hr);
3884 if (SUCCEEDED(hr))
3886 refcount = IDirect3DDevice_Release(device);
3887 ok(refcount == 1, "Test %u: Got unexpected refcount %u.\n", i, refcount);
3890 refcount = IDirectDrawSurface_Release(surface);
3891 ok(refcount == 0, "Test %u: The surface was not properly freed, refcount %u.\n", i, refcount);
3894 IDirectDrawPalette_Release(palette);
3895 refcount = IDirectDraw_Release(ddraw);
3896 ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount);
3897 DestroyWindow(window);
3900 static void test_primary_caps(void)
3902 const DWORD placement = DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY | DDSCAPS_SYSTEMMEMORY;
3903 IDirectDrawSurface *surface;
3904 DDSURFACEDESC surface_desc;
3905 IDirectDraw *ddraw;
3906 unsigned int i;
3907 ULONG refcount;
3908 HWND window;
3909 HRESULT hr;
3911 static const struct
3913 DWORD coop_level;
3914 DWORD caps_in;
3915 DWORD back_buffer_count;
3916 HRESULT hr;
3917 DWORD caps_out;
3919 test_data[] =
3922 DDSCL_NORMAL,
3923 DDSCAPS_PRIMARYSURFACE,
3924 ~0u,
3925 DD_OK,
3926 DDSCAPS_VISIBLE | DDSCAPS_PRIMARYSURFACE,
3929 DDSCL_NORMAL,
3930 DDSCAPS_PRIMARYSURFACE | DDSCAPS_TEXTURE,
3931 ~0u,
3932 DDERR_INVALIDCAPS,
3933 ~0u,
3936 DDSCL_NORMAL,
3937 DDSCAPS_PRIMARYSURFACE | DDSCAPS_FRONTBUFFER,
3938 ~0u,
3939 DD_OK,
3940 DDSCAPS_VISIBLE | DDSCAPS_PRIMARYSURFACE | DDSCAPS_FRONTBUFFER,
3943 DDSCL_NORMAL,
3944 DDSCAPS_PRIMARYSURFACE | DDSCAPS_BACKBUFFER,
3945 ~0u,
3946 DDERR_INVALIDCAPS,
3947 ~0u,
3950 DDSCL_NORMAL,
3951 DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP,
3952 ~0u,
3953 DDERR_INVALIDCAPS,
3954 ~0u,
3957 DDSCL_NORMAL,
3958 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX,
3959 ~0u,
3960 DDERR_INVALIDCAPS,
3961 ~0u,
3964 DDSCL_NORMAL,
3965 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
3966 ~0u,
3967 DDERR_INVALIDCAPS,
3968 ~0u,
3971 DDSCL_NORMAL,
3972 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
3974 DDERR_INVALIDCAPS,
3975 ~0u,
3978 DDSCL_NORMAL,
3979 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
3981 DDERR_NOEXCLUSIVEMODE,
3982 ~0u,
3985 DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN,
3986 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
3988 DDERR_INVALIDCAPS,
3989 ~0u,
3992 DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN,
3993 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
3995 DD_OK,
3996 DDSCAPS_VISIBLE | DDSCAPS_PRIMARYSURFACE | DDSCAPS_FRONTBUFFER | DDSCAPS_FLIP | DDSCAPS_COMPLEX,
3999 DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN,
4000 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP | DDSCAPS_FRONTBUFFER,
4002 DDERR_INVALIDCAPS,
4003 ~0u,
4006 DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN,
4007 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP | DDSCAPS_BACKBUFFER,
4009 DDERR_INVALIDCAPS,
4010 ~0u,
4014 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
4015 0, 0, 640, 480, 0, 0, 0, 0);
4016 ddraw = create_ddraw();
4017 ok(!!ddraw, "Failed to create a ddraw object.\n");
4019 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
4021 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, test_data[i].coop_level);
4022 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4024 memset(&surface_desc, 0, sizeof(surface_desc));
4025 surface_desc.dwSize = sizeof(surface_desc);
4026 surface_desc.dwFlags = DDSD_CAPS;
4027 if (test_data[i].back_buffer_count != ~0u)
4028 surface_desc.dwFlags |= DDSD_BACKBUFFERCOUNT;
4029 surface_desc.ddsCaps.dwCaps = test_data[i].caps_in;
4030 surface_desc.dwBackBufferCount = test_data[i].back_buffer_count;
4031 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
4032 ok(hr == test_data[i].hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, test_data[i].hr);
4033 if (FAILED(hr))
4034 continue;
4036 memset(&surface_desc, 0, sizeof(surface_desc));
4037 surface_desc.dwSize = sizeof(surface_desc);
4038 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
4039 ok(SUCCEEDED(hr), "Test %u: Failed to get surface desc, hr %#x.\n", i, hr);
4040 ok((surface_desc.ddsCaps.dwCaps & ~placement) == test_data[i].caps_out,
4041 "Test %u: Got unexpected caps %#x, expected %#x.\n",
4042 i, surface_desc.ddsCaps.dwCaps, test_data[i].caps_out);
4044 IDirectDrawSurface_Release(surface);
4047 refcount = IDirectDraw_Release(ddraw);
4048 ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount);
4049 DestroyWindow(window);
4052 static void test_surface_lock(void)
4054 IDirectDraw *ddraw;
4055 IDirectDrawSurface *surface;
4056 IDirect3DDevice *device;
4057 HRESULT hr;
4058 HWND window;
4059 unsigned int i;
4060 DDSURFACEDESC ddsd;
4061 ULONG refcount;
4062 DWORD z_depth = 0;
4063 static const struct
4065 DWORD caps;
4066 const char *name;
4068 tests[] =
4071 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY,
4072 "videomemory offscreenplain"
4075 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
4076 "systemmemory offscreenplain"
4079 DDSCAPS_PRIMARYSURFACE,
4080 "primary"
4083 DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY,
4084 "videomemory texture"
4087 DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY,
4088 "systemmemory texture"
4091 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE,
4092 "render target"
4095 DDSCAPS_ZBUFFER,
4096 "Z buffer"
4100 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
4101 0, 0, 640, 480, 0, 0, 0, 0);
4102 ddraw = create_ddraw();
4103 ok(!!ddraw, "Failed to create a ddraw object.\n");
4104 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
4106 skip("Failed to create a 3D device, skipping test.\n");
4107 IDirectDraw_Release(ddraw);
4108 DestroyWindow(window);
4109 return;
4111 z_depth = get_device_z_depth(device);
4112 ok(!!z_depth, "Failed to get device z depth.\n");
4113 IDirect3DDevice_Release(device);
4115 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
4117 memset(&ddsd, 0, sizeof(ddsd));
4118 ddsd.dwSize = sizeof(ddsd);
4119 ddsd.dwFlags = DDSD_CAPS;
4120 if (!(tests[i].caps & DDSCAPS_PRIMARYSURFACE))
4122 ddsd.dwFlags |= DDSD_WIDTH | DDSD_HEIGHT;
4123 ddsd.dwWidth = 64;
4124 ddsd.dwHeight = 64;
4126 if (tests[i].caps & DDSCAPS_ZBUFFER)
4128 ddsd.dwFlags |= DDSD_ZBUFFERBITDEPTH;
4129 U2(ddsd).dwZBufferBitDepth = z_depth;
4131 ddsd.ddsCaps.dwCaps = tests[i].caps;
4133 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &surface, NULL);
4134 ok(SUCCEEDED(hr), "Failed to create surface, type %s, hr %#x.\n", tests[i].name, hr);
4136 memset(&ddsd, 0, sizeof(ddsd));
4137 ddsd.dwSize = sizeof(ddsd);
4138 hr = IDirectDrawSurface_Lock(surface, NULL, &ddsd, DDLOCK_WAIT, NULL);
4139 ok(SUCCEEDED(hr), "Failed to lock surface, type %s, hr %#x.\n", tests[i].name, hr);
4140 if (SUCCEEDED(hr))
4142 hr = IDirectDrawSurface_Unlock(surface, NULL);
4143 ok(SUCCEEDED(hr), "Failed to unlock surface, type %s, hr %#x.\n", tests[i].name, hr);
4146 memset(&ddsd, 0, sizeof(ddsd));
4147 hr = IDirectDrawSurface_Lock(surface, NULL, &ddsd, DDLOCK_WAIT, NULL);
4148 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x, type %s.\n", hr, tests[i].name);
4150 IDirectDrawSurface_Release(surface);
4153 refcount = IDirectDraw_Release(ddraw);
4154 ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount);
4155 DestroyWindow(window);
4158 static void test_surface_discard(void)
4160 IDirectDraw *ddraw;
4161 IDirect3DDevice *device;
4162 HRESULT hr;
4163 HWND window;
4164 DDSURFACEDESC ddsd;
4165 IDirectDrawSurface *surface, *target;
4166 void *addr;
4167 static const struct
4169 DWORD caps;
4170 BOOL discard;
4172 tests[] =
4174 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, TRUE},
4175 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY, FALSE},
4176 {DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, TRUE},
4177 {DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, FALSE},
4179 unsigned int i;
4181 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
4182 0, 0, 640, 480, 0, 0, 0, 0);
4183 ddraw = create_ddraw();
4184 ok(!!ddraw, "Failed to create a ddraw object.\n");
4185 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
4187 skip("Failed to create a 3D device, skipping test.\n");
4188 IDirectDraw_Release(ddraw);
4189 DestroyWindow(window);
4190 return;
4193 hr = IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&target);
4194 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
4196 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
4198 BOOL discarded;
4200 memset(&ddsd, 0, sizeof(ddsd));
4201 ddsd.dwSize = sizeof(ddsd);
4202 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4203 ddsd.ddsCaps.dwCaps = tests[i].caps;
4204 ddsd.dwWidth = 64;
4205 ddsd.dwHeight = 64;
4206 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &surface, NULL);
4207 if (FAILED(hr))
4209 skip("Failed to create surface, skipping.\n");
4210 continue;
4213 memset(&ddsd, 0, sizeof(ddsd));
4214 ddsd.dwSize = sizeof(ddsd);
4215 hr = IDirectDrawSurface_Lock(surface, NULL, &ddsd, DDLOCK_WAIT, NULL);
4216 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
4217 addr = ddsd.lpSurface;
4218 hr = IDirectDrawSurface_Unlock(surface, NULL);
4219 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
4221 memset(&ddsd, 0, sizeof(ddsd));
4222 ddsd.dwSize = sizeof(ddsd);
4223 hr = IDirectDrawSurface_Lock(surface, NULL, &ddsd, DDLOCK_DISCARDCONTENTS | DDLOCK_WAIT, NULL);
4224 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
4225 discarded = ddsd.lpSurface != addr;
4226 hr = IDirectDrawSurface_Unlock(surface, NULL);
4227 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
4229 hr = IDirectDrawSurface_Blt(target, NULL, surface, NULL, DDBLT_WAIT, NULL);
4230 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
4232 memset(&ddsd, 0, sizeof(ddsd));
4233 ddsd.dwSize = sizeof(ddsd);
4234 hr = IDirectDrawSurface_Lock(surface, NULL, &ddsd, DDLOCK_DISCARDCONTENTS | DDLOCK_WAIT, NULL);
4235 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
4236 discarded |= ddsd.lpSurface != addr;
4237 hr = IDirectDrawSurface_Unlock(surface, NULL);
4238 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
4240 IDirectDrawSurface_Release(surface);
4242 /* Windows 7 reliably changes the address of surfaces that are discardable (Nvidia Kepler,
4243 * AMD r500, evergreen). Windows XP, at least on AMD r200, never changes the pointer. */
4244 ok(!discarded || tests[i].discard, "Expected surface not to be discarded, case %u\n", i);
4247 IDirectDrawSurface_Release(target);
4248 IDirect3DDevice_Release(device);
4249 IDirectDraw_Release(ddraw);
4250 DestroyWindow(window);
4253 static void test_flip(void)
4255 const DWORD placement = DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY | DDSCAPS_SYSTEMMEMORY;
4256 IDirectDrawSurface *frontbuffer, *backbuffer1, *backbuffer2, *backbuffer3, *surface;
4257 DDSCAPS caps = {DDSCAPS_FLIP};
4258 DDSURFACEDESC surface_desc;
4259 BOOL sysmem_primary;
4260 IDirectDraw *ddraw;
4261 DWORD expected_caps;
4262 unsigned int i;
4263 D3DCOLOR color;
4264 ULONG refcount;
4265 HWND window;
4266 DDBLTFX fx;
4267 HRESULT hr;
4269 static const struct
4271 const char *name;
4272 DWORD caps;
4274 test_data[] =
4276 {"PRIMARYSURFACE", DDSCAPS_PRIMARYSURFACE},
4277 {"OFFSCREENPLAIN", DDSCAPS_OFFSCREENPLAIN},
4278 {"TEXTURE", DDSCAPS_TEXTURE},
4281 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
4282 0, 0, 640, 480, 0, 0, 0, 0);
4283 ddraw = create_ddraw();
4284 ok(!!ddraw, "Failed to create a ddraw object.\n");
4286 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
4287 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4289 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
4291 /* Creating a flippable texture induces a BSoD on some versions of the
4292 * Intel graphics driver. At least Intel GMA 950 with driver version
4293 * 6.14.10.4926 on Windows XP SP3 is affected. */
4294 if ((test_data[i].caps & DDSCAPS_TEXTURE) && ddraw_is_intel(ddraw))
4296 win_skip("Skipping flippable texture test.\n");
4297 continue;
4300 memset(&surface_desc, 0, sizeof(surface_desc));
4301 surface_desc.dwSize = sizeof(surface_desc);
4302 surface_desc.dwFlags = DDSD_CAPS;
4303 if (!(test_data[i].caps & DDSCAPS_PRIMARYSURFACE))
4304 surface_desc.dwFlags |= DDSD_WIDTH | DDSD_HEIGHT;
4305 surface_desc.ddsCaps.dwCaps = DDSCAPS_COMPLEX | DDSCAPS_FLIP | test_data[i].caps;
4306 surface_desc.dwWidth = 512;
4307 surface_desc.dwHeight = 512;
4308 surface_desc.dwBackBufferCount = 3;
4309 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &frontbuffer, NULL);
4310 ok(hr == DDERR_INVALIDCAPS, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
4312 surface_desc.ddsCaps.dwCaps &= ~DDSCAPS_FLIP;
4313 surface_desc.dwFlags |= DDSD_BACKBUFFERCOUNT;
4314 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &frontbuffer, NULL);
4315 ok(hr == DDERR_INVALIDCAPS, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
4317 surface_desc.ddsCaps.dwCaps &= ~DDSCAPS_COMPLEX;
4318 surface_desc.ddsCaps.dwCaps |= DDSCAPS_FLIP;
4319 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &frontbuffer, NULL);
4320 ok(hr == DDERR_INVALIDCAPS, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
4322 surface_desc.ddsCaps.dwCaps |= DDSCAPS_COMPLEX;
4323 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &frontbuffer, NULL);
4324 todo_wine_if(test_data[i].caps & DDSCAPS_TEXTURE)
4325 ok(SUCCEEDED(hr), "%s: Failed to create surface, hr %#x.\n", test_data[i].name, hr);
4326 if (FAILED(hr))
4327 continue;
4329 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL | DDSCL_FULLSCREEN);
4330 ok(SUCCEEDED(hr), "%s: Failed to set cooperative level, hr %#x.\n", test_data[i].name, hr);
4331 hr = IDirectDrawSurface_IsLost(frontbuffer);
4332 ok(hr == DD_OK, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
4333 hr = IDirectDrawSurface_Flip(frontbuffer, NULL, DDFLIP_WAIT);
4334 if (test_data[i].caps & DDSCAPS_PRIMARYSURFACE)
4335 ok(hr == DDERR_NOEXCLUSIVEMODE, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
4336 else
4337 ok(SUCCEEDED(hr), "%s: Failed to flip, hr %#x.\n", test_data[i].name, hr);
4338 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
4339 ok(SUCCEEDED(hr), "%s: Failed to set cooperative level, hr %#x.\n", test_data[i].name, hr);
4340 hr = IDirectDrawSurface_IsLost(frontbuffer);
4341 todo_wine ok(hr == DDERR_SURFACELOST, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
4342 hr = restore_surfaces(ddraw);
4343 ok(SUCCEEDED(hr), "%s: Failed to restore surfaces, hr %#x.\n", test_data[i].name, hr);
4345 memset(&surface_desc, 0, sizeof(surface_desc));
4346 surface_desc.dwSize = sizeof(surface_desc);
4347 hr = IDirectDrawSurface_GetSurfaceDesc(frontbuffer, &surface_desc);
4348 ok(SUCCEEDED(hr), "%s: Failed to get surface desc, hr %#x.\n", test_data[i].name, hr);
4349 expected_caps = DDSCAPS_FRONTBUFFER | DDSCAPS_COMPLEX | DDSCAPS_FLIP | test_data[i].caps;
4350 if (test_data[i].caps & DDSCAPS_PRIMARYSURFACE)
4351 expected_caps |= DDSCAPS_VISIBLE;
4352 ok((surface_desc.ddsCaps.dwCaps & ~placement) == expected_caps,
4353 "%s: Got unexpected caps %#x.\n", test_data[i].name, surface_desc.ddsCaps.dwCaps);
4354 sysmem_primary = surface_desc.ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY;
4356 hr = IDirectDrawSurface_GetAttachedSurface(frontbuffer, &caps, &backbuffer1);
4357 ok(SUCCEEDED(hr), "%s: Failed to get attached surface, hr %#x.\n", test_data[i].name, hr);
4358 memset(&surface_desc, 0, sizeof(surface_desc));
4359 surface_desc.dwSize = sizeof(surface_desc);
4360 hr = IDirectDrawSurface_GetSurfaceDesc(backbuffer1, &surface_desc);
4361 ok(SUCCEEDED(hr), "%s: Failed to get surface desc, hr %#x.\n", test_data[i].name, hr);
4362 ok(!surface_desc.dwBackBufferCount, "%s: Got unexpected back buffer count %u.\n",
4363 test_data[i].name, surface_desc.dwBackBufferCount);
4364 expected_caps &= ~(DDSCAPS_VISIBLE | DDSCAPS_PRIMARYSURFACE | DDSCAPS_FRONTBUFFER);
4365 expected_caps |= DDSCAPS_BACKBUFFER;
4366 ok((surface_desc.ddsCaps.dwCaps & ~placement) == expected_caps,
4367 "%s: Got unexpected caps %#x.\n", test_data[i].name, surface_desc.ddsCaps.dwCaps);
4369 hr = IDirectDrawSurface_GetAttachedSurface(backbuffer1, &caps, &backbuffer2);
4370 ok(SUCCEEDED(hr), "%s: Failed to get attached surface, hr %#x.\n", test_data[i].name, hr);
4371 memset(&surface_desc, 0, sizeof(surface_desc));
4372 surface_desc.dwSize = sizeof(surface_desc);
4373 hr = IDirectDrawSurface_GetSurfaceDesc(backbuffer2, &surface_desc);
4374 ok(SUCCEEDED(hr), "%s: Failed to get surface desc, hr %#x.\n", test_data[i].name, hr);
4375 ok(!surface_desc.dwBackBufferCount, "%s: Got unexpected back buffer count %u.\n",
4376 test_data[i].name, surface_desc.dwBackBufferCount);
4377 expected_caps &= ~DDSCAPS_BACKBUFFER;
4378 ok((surface_desc.ddsCaps.dwCaps & ~placement) == expected_caps,
4379 "%s: Got unexpected caps %#x.\n", test_data[i].name, surface_desc.ddsCaps.dwCaps);
4381 hr = IDirectDrawSurface_GetAttachedSurface(backbuffer2, &caps, &backbuffer3);
4382 ok(SUCCEEDED(hr), "%s: Failed to get attached surface, hr %#x.\n", test_data[i].name, hr);
4383 memset(&surface_desc, 0, sizeof(surface_desc));
4384 surface_desc.dwSize = sizeof(surface_desc);
4385 hr = IDirectDrawSurface_GetSurfaceDesc(backbuffer3, &surface_desc);
4386 ok(SUCCEEDED(hr), "%s: Failed to get surface desc, hr %#x.\n", test_data[i].name, hr);
4387 ok(!surface_desc.dwBackBufferCount, "%s: Got unexpected back buffer count %u.\n",
4388 test_data[i].name, surface_desc.dwBackBufferCount);
4389 ok((surface_desc.ddsCaps.dwCaps & ~placement) == expected_caps,
4390 "%s: Got unexpected caps %#x.\n", test_data[i].name, surface_desc.ddsCaps.dwCaps);
4392 hr = IDirectDrawSurface_GetAttachedSurface(backbuffer3, &caps, &surface);
4393 ok(SUCCEEDED(hr), "%s: Failed to get attached surface, hr %#x.\n", test_data[i].name, hr);
4394 ok(surface == frontbuffer, "%s: Got unexpected surface %p, expected %p.\n",
4395 test_data[i].name, surface, frontbuffer);
4396 IDirectDrawSurface_Release(surface);
4398 memset(&surface_desc, 0, sizeof(surface_desc));
4399 surface_desc.dwSize = sizeof(surface_desc);
4400 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4401 surface_desc.ddsCaps.dwCaps = 0;
4402 surface_desc.dwWidth = 640;
4403 surface_desc.dwHeight = 480;
4404 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
4405 ok(SUCCEEDED(hr), "%s: Failed to create surface, hr %#x.\n", test_data[i].name, hr);
4406 hr = IDirectDrawSurface_Flip(frontbuffer, surface, DDFLIP_WAIT);
4407 ok(hr == DDERR_NOTFLIPPABLE, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
4408 IDirectDrawSurface_Release(surface);
4410 hr = IDirectDrawSurface_Flip(frontbuffer, frontbuffer, DDFLIP_WAIT);
4411 ok(hr == DDERR_NOTFLIPPABLE, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
4412 hr = IDirectDrawSurface_Flip(backbuffer1, NULL, DDFLIP_WAIT);
4413 ok(hr == DDERR_NOTFLIPPABLE, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
4414 hr = IDirectDrawSurface_Flip(backbuffer2, NULL, DDFLIP_WAIT);
4415 ok(hr == DDERR_NOTFLIPPABLE, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
4416 hr = IDirectDrawSurface_Flip(backbuffer3, NULL, DDFLIP_WAIT);
4417 ok(hr == DDERR_NOTFLIPPABLE, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
4419 memset(&fx, 0, sizeof(fx));
4420 fx.dwSize = sizeof(fx);
4421 U5(fx).dwFillColor = 0xffff0000;
4422 hr = IDirectDrawSurface_Blt(backbuffer1, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
4423 ok(SUCCEEDED(hr), "%s: Failed to fill surface, hr %#x.\n", test_data[i].name, hr);
4424 U5(fx).dwFillColor = 0xff00ff00;
4425 hr = IDirectDrawSurface_Blt(backbuffer2, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
4426 ok(SUCCEEDED(hr), "%s: Failed to fill surface, hr %#x.\n", test_data[i].name, hr);
4427 U5(fx).dwFillColor = 0xff0000ff;
4428 hr = IDirectDrawSurface_Blt(backbuffer3, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
4429 ok(SUCCEEDED(hr), "%s: Failed to fill surface, hr %#x.\n", test_data[i].name, hr);
4431 hr = IDirectDrawSurface_Flip(frontbuffer, NULL, DDFLIP_WAIT);
4432 ok(SUCCEEDED(hr), "%s: Failed to flip, hr %#x.\n", test_data[i].name, hr);
4433 color = get_surface_color(backbuffer1, 320, 240);
4434 /* The testbot seems to just copy the contents of one surface to all the
4435 * others, instead of properly flipping. */
4436 ok(compare_color(color, 0x0000ff00, 1) || broken(sysmem_primary && compare_color(color, 0x000000ff, 1)),
4437 "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
4438 color = get_surface_color(backbuffer2, 320, 240);
4439 ok(compare_color(color, 0x000000ff, 1), "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
4440 U5(fx).dwFillColor = 0xffff0000;
4441 hr = IDirectDrawSurface_Blt(backbuffer3, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
4442 ok(SUCCEEDED(hr), "%s: Failed to fill surface, hr %#x.\n", test_data[i].name, hr);
4444 hr = IDirectDrawSurface_Flip(frontbuffer, NULL, DDFLIP_WAIT);
4445 ok(SUCCEEDED(hr), "%s: Failed to flip, hr %#x.\n", test_data[i].name, hr);
4446 color = get_surface_color(backbuffer1, 320, 240);
4447 ok(compare_color(color, 0x000000ff, 1) || broken(sysmem_primary && compare_color(color, 0x00ff0000, 1)),
4448 "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
4449 color = get_surface_color(backbuffer2, 320, 240);
4450 ok(compare_color(color, 0x00ff0000, 1), "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
4451 U5(fx).dwFillColor = 0xff00ff00;
4452 hr = IDirectDrawSurface_Blt(backbuffer3, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
4453 ok(SUCCEEDED(hr), "%s: Failed to fill surface, hr %#x.\n", test_data[i].name, hr);
4455 hr = IDirectDrawSurface_Flip(frontbuffer, NULL, DDFLIP_WAIT);
4456 ok(SUCCEEDED(hr), "%s: Failed to flip, hr %#x.\n", test_data[i].name, hr);
4457 color = get_surface_color(backbuffer1, 320, 240);
4458 ok(compare_color(color, 0x00ff0000, 1) || broken(sysmem_primary && compare_color(color, 0x0000ff00, 1)),
4459 "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
4460 color = get_surface_color(backbuffer2, 320, 240);
4461 ok(compare_color(color, 0x0000ff00, 1), "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
4462 U5(fx).dwFillColor = 0xff0000ff;
4463 hr = IDirectDrawSurface_Blt(backbuffer3, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
4464 ok(SUCCEEDED(hr), "%s: Failed to fill surface, hr %#x.\n", test_data[i].name, hr);
4466 hr = IDirectDrawSurface_Flip(frontbuffer, backbuffer1, DDFLIP_WAIT);
4467 ok(SUCCEEDED(hr), "%s: Failed to flip, hr %#x.\n", test_data[i].name, hr);
4468 color = get_surface_color(backbuffer2, 320, 240);
4469 ok(compare_color(color, 0x0000ff00, 1) || broken(sysmem_primary && compare_color(color, 0x000000ff, 1)),
4470 "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
4471 color = get_surface_color(backbuffer3, 320, 240);
4472 ok(compare_color(color, 0x000000ff, 1), "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
4473 U5(fx).dwFillColor = 0xffff0000;
4474 hr = IDirectDrawSurface_Blt(backbuffer1, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
4475 ok(SUCCEEDED(hr), "%s: Failed to fill surface, hr %#x.\n", test_data[i].name, hr);
4477 hr = IDirectDrawSurface_Flip(frontbuffer, backbuffer2, DDFLIP_WAIT);
4478 ok(SUCCEEDED(hr), "%s: Failed to flip, hr %#x.\n", test_data[i].name, hr);
4479 color = get_surface_color(backbuffer1, 320, 240);
4480 ok(compare_color(color, 0x00ff0000, 1), "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
4481 color = get_surface_color(backbuffer3, 320, 240);
4482 ok(compare_color(color, 0x000000ff, 1) || broken(sysmem_primary && compare_color(color, 0x00ff0000, 1)),
4483 "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
4484 U5(fx).dwFillColor = 0xff00ff00;
4485 hr = IDirectDrawSurface_Blt(backbuffer2, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
4486 ok(SUCCEEDED(hr), "%s: Failed to fill surface, hr %#x.\n", test_data[i].name, hr);
4488 hr = IDirectDrawSurface_Flip(frontbuffer, backbuffer3, DDFLIP_WAIT);
4489 ok(SUCCEEDED(hr), "%s: Failed to flip, hr %#x.\n", test_data[i].name, hr);
4490 color = get_surface_color(backbuffer1, 320, 240);
4491 ok(compare_color(color, 0x00ff0000, 1) || broken(sysmem_primary && compare_color(color, 0x0000ff00, 1)),
4492 "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
4493 color = get_surface_color(backbuffer2, 320, 240);
4494 ok(compare_color(color, 0x0000ff00, 1), "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
4496 IDirectDrawSurface_Release(backbuffer3);
4497 IDirectDrawSurface_Release(backbuffer2);
4498 IDirectDrawSurface_Release(backbuffer1);
4499 IDirectDrawSurface_Release(frontbuffer);
4502 refcount = IDirectDraw_Release(ddraw);
4503 ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount);
4504 DestroyWindow(window);
4507 static void test_sysmem_overlay(void)
4509 IDirectDraw *ddraw;
4510 HWND window;
4511 HRESULT hr;
4512 DDSURFACEDESC ddsd;
4513 IDirectDrawSurface *surface;
4514 ULONG ref;
4516 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
4517 0, 0, 640, 480, 0, 0, 0, 0);
4518 ddraw = create_ddraw();
4519 ok(!!ddraw, "Failed to create a ddraw object.\n");
4521 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
4522 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4524 memset(&ddsd, 0, sizeof(ddsd));
4525 ddsd.dwSize = sizeof(ddsd);
4526 ddsd.dwFlags = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT;
4527 ddsd.dwWidth = 16;
4528 ddsd.dwHeight = 16;
4529 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OVERLAY;
4530 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
4531 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
4532 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 32;
4533 U2(ddsd.ddpfPixelFormat).dwRBitMask = 0x00ff0000;
4534 U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x0000ff00;
4535 U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x000000ff;
4536 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &surface, NULL);
4537 ok(hr == DDERR_NOOVERLAYHW, "Got unexpected hr %#x.\n", hr);
4539 ref = IDirectDraw_Release(ddraw);
4540 ok(ref == 0, "Ddraw object not properly released, refcount %u.\n", ref);
4541 DestroyWindow(window);
4544 static void test_primary_palette(void)
4546 DDSCAPS surface_caps = {DDSCAPS_FLIP};
4547 IDirectDrawSurface *primary, *backbuffer;
4548 PALETTEENTRY palette_entries[256];
4549 IDirectDrawPalette *palette, *tmp;
4550 DDSURFACEDESC surface_desc;
4551 IDirectDraw *ddraw;
4552 DWORD palette_caps;
4553 ULONG refcount;
4554 HWND window;
4555 HRESULT hr;
4557 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
4558 0, 0, 640, 480, 0, 0, 0, 0);
4559 ddraw = create_ddraw();
4560 ok(!!ddraw, "Failed to create a ddraw object.\n");
4561 if (FAILED(IDirectDraw_SetDisplayMode(ddraw, 640, 480, 8)))
4563 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
4564 IDirectDraw_Release(ddraw);
4565 DestroyWindow(window);
4566 return;
4568 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
4569 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4571 memset(&surface_desc, 0, sizeof(surface_desc));
4572 surface_desc.dwSize = sizeof(surface_desc);
4573 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
4574 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
4575 surface_desc.dwBackBufferCount = 1;
4576 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &primary, NULL);
4577 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4578 hr = IDirectDrawSurface_GetAttachedSurface(primary, &surface_caps, &backbuffer);
4579 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
4581 memset(palette_entries, 0, sizeof(palette_entries));
4582 hr = IDirectDraw_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256, palette_entries, &palette, NULL);
4583 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
4584 refcount = get_refcount((IUnknown *)palette);
4585 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4587 hr = IDirectDrawPalette_GetCaps(palette, &palette_caps);
4588 ok(SUCCEEDED(hr), "Failed to get palette caps, hr %#x.\n", hr);
4589 ok(palette_caps == (DDPCAPS_8BIT | DDPCAPS_ALLOW256), "Got unexpected palette caps %#x.\n", palette_caps);
4591 hr = IDirectDrawSurface_SetPalette(primary, palette);
4592 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
4594 /* The Windows 8 testbot attaches the palette to the backbuffer as well,
4595 * and is generally somewhat broken with respect to 8 bpp / palette
4596 * handling. */
4597 if (SUCCEEDED(IDirectDrawSurface_GetPalette(backbuffer, &tmp)))
4599 win_skip("Broken palette handling detected, skipping tests.\n");
4600 IDirectDrawPalette_Release(tmp);
4601 IDirectDrawPalette_Release(palette);
4602 /* The Windows 8 testbot keeps extra references to the primary and
4603 * backbuffer while in 8 bpp mode. */
4604 hr = IDirectDraw_RestoreDisplayMode(ddraw);
4605 ok(SUCCEEDED(hr), "Failed to restore display mode, hr %#x.\n", hr);
4606 goto done;
4609 refcount = get_refcount((IUnknown *)palette);
4610 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
4612 hr = IDirectDrawPalette_GetCaps(palette, &palette_caps);
4613 ok(SUCCEEDED(hr), "Failed to get palette caps, hr %#x.\n", hr);
4614 ok(palette_caps == (DDPCAPS_8BIT | DDPCAPS_PRIMARYSURFACE | DDPCAPS_ALLOW256),
4615 "Got unexpected palette caps %#x.\n", palette_caps);
4617 hr = IDirectDrawSurface_SetPalette(primary, NULL);
4618 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
4619 refcount = get_refcount((IUnknown *)palette);
4620 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4622 hr = IDirectDrawPalette_GetCaps(palette, &palette_caps);
4623 ok(SUCCEEDED(hr), "Failed to get palette caps, hr %#x.\n", hr);
4624 ok(palette_caps == (DDPCAPS_8BIT | DDPCAPS_ALLOW256), "Got unexpected palette caps %#x.\n", palette_caps);
4626 hr = IDirectDrawSurface_SetPalette(primary, palette);
4627 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
4628 refcount = get_refcount((IUnknown *)palette);
4629 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
4631 hr = IDirectDrawSurface_GetPalette(primary, &tmp);
4632 ok(SUCCEEDED(hr), "Failed to get palette, hr %#x.\n", hr);
4633 ok(tmp == palette, "Got unexpected palette %p, expected %p.\n", tmp, palette);
4634 IDirectDrawPalette_Release(tmp);
4635 hr = IDirectDrawSurface_GetPalette(backbuffer, &tmp);
4636 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x.\n", hr);
4638 refcount = IDirectDrawPalette_Release(palette);
4639 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4640 refcount = IDirectDrawPalette_Release(palette);
4641 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4643 /* Note that this only seems to work when the palette is attached to the
4644 * primary surface. When attached to a regular surface, attempting to get
4645 * the palette here will cause an access violation. */
4646 hr = IDirectDrawSurface_GetPalette(primary, &tmp);
4647 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x.\n", hr);
4649 hr = IDirectDrawSurface_IsLost(primary);
4650 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
4652 memset(&surface_desc, 0, sizeof(surface_desc));
4653 surface_desc.dwSize = sizeof(surface_desc);
4654 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &surface_desc);
4655 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
4656 ok(surface_desc.dwWidth == 640, "Got unexpected surface width %u.\n", surface_desc.dwWidth);
4657 ok(surface_desc.dwHeight == 480, "Got unexpected surface height %u.\n", surface_desc.dwHeight);
4658 ok(U1(surface_desc.ddpfPixelFormat).dwRGBBitCount == 8, "Got unexpected bit count %u.\n",
4659 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount);
4661 hr = set_display_mode(ddraw, 640, 480);
4662 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
4664 memset(&surface_desc, 0, sizeof(surface_desc));
4665 surface_desc.dwSize = sizeof(surface_desc);
4666 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &surface_desc);
4667 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
4668 ok(surface_desc.dwWidth == 640, "Got unexpected surface width %u.\n", surface_desc.dwWidth);
4669 ok(surface_desc.dwHeight == 480, "Got unexpected surface height %u.\n", surface_desc.dwHeight);
4670 ok(U1(surface_desc.ddpfPixelFormat).dwRGBBitCount == 32
4671 || U1(surface_desc.ddpfPixelFormat).dwRGBBitCount == 24,
4672 "Got unexpected bit count %u.\n", U1(surface_desc.ddpfPixelFormat).dwRGBBitCount);
4674 hr = IDirectDrawSurface_IsLost(primary);
4675 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
4676 hr = IDirectDrawSurface_Restore(primary);
4677 ok(hr == DDERR_WRONGMODE, "Got unexpected hr %#x.\n", hr);
4678 hr = IDirectDrawSurface_IsLost(primary);
4679 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
4681 memset(&surface_desc, 0, sizeof(surface_desc));
4682 surface_desc.dwSize = sizeof(surface_desc);
4683 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &surface_desc);
4684 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
4685 ok(surface_desc.dwWidth == 640, "Got unexpected surface width %u.\n", surface_desc.dwWidth);
4686 ok(surface_desc.dwHeight == 480, "Got unexpected surface height %u.\n", surface_desc.dwHeight);
4687 ok(U1(surface_desc.ddpfPixelFormat).dwRGBBitCount == 32
4688 || U1(surface_desc.ddpfPixelFormat).dwRGBBitCount == 24,
4689 "Got unexpected bit count %u.\n", U1(surface_desc.ddpfPixelFormat).dwRGBBitCount);
4691 done:
4692 refcount = IDirectDrawSurface_Release(backbuffer);
4693 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4694 refcount = IDirectDrawSurface_Release(primary);
4695 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4696 refcount = IDirectDraw_Release(ddraw);
4697 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4698 DestroyWindow(window);
4701 static HRESULT WINAPI surface_counter(IDirectDrawSurface *surface, DDSURFACEDESC *desc, void *context)
4703 UINT *surface_count = context;
4705 ++(*surface_count);
4706 IDirectDrawSurface_Release(surface);
4708 return DDENUMRET_OK;
4711 static void test_surface_attachment(void)
4713 IDirectDrawSurface *surface1, *surface2, *surface3, *surface4;
4714 DDSCAPS caps = {DDSCAPS_TEXTURE};
4715 DDSURFACEDESC surface_desc;
4716 IDirectDraw *ddraw;
4717 UINT surface_count;
4718 ULONG refcount;
4719 HWND window;
4720 HRESULT hr;
4722 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
4723 0, 0, 640, 480, 0, 0, 0, 0);
4724 ddraw = create_ddraw();
4725 ok(!!ddraw, "Failed to create a ddraw object.\n");
4726 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
4727 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4729 memset(&surface_desc, 0, sizeof(surface_desc));
4730 surface_desc.dwSize = sizeof(surface_desc);
4731 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_MIPMAPCOUNT;
4732 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
4733 U2(surface_desc).dwMipMapCount = 3;
4734 surface_desc.dwWidth = 128;
4735 surface_desc.dwHeight = 128;
4736 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface1, NULL);
4737 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4739 hr = IDirectDrawSurface_GetAttachedSurface(surface1, &caps, &surface2);
4740 ok(SUCCEEDED(hr), "Failed to get mip level, hr %#x.\n", hr);
4741 hr = IDirectDrawSurface_GetAttachedSurface(surface2, &caps, &surface3);
4742 ok(SUCCEEDED(hr), "Failed to get mip level, hr %#x.\n", hr);
4743 hr = IDirectDrawSurface_GetAttachedSurface(surface3, &caps, &surface4);
4744 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
4746 surface_count = 0;
4747 IDirectDrawSurface_EnumAttachedSurfaces(surface1, &surface_count, surface_counter);
4748 ok(surface_count == 1, "Got unexpected surface_count %u.\n", surface_count);
4749 surface_count = 0;
4750 IDirectDrawSurface_EnumAttachedSurfaces(surface2, &surface_count, surface_counter);
4751 ok(surface_count == 1, "Got unexpected surface_count %u.\n", surface_count);
4752 surface_count = 0;
4753 IDirectDrawSurface_EnumAttachedSurfaces(surface3, &surface_count, surface_counter);
4754 ok(!surface_count, "Got unexpected surface_count %u.\n", surface_count);
4756 memset(&surface_desc, 0, sizeof(surface_desc));
4757 surface_desc.dwSize = sizeof(surface_desc);
4758 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4759 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
4760 surface_desc.dwWidth = 16;
4761 surface_desc.dwHeight = 16;
4762 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface4, NULL);
4763 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4765 hr = IDirectDrawSurface_AddAttachedSurface(surface1, surface4);
4766 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
4767 hr = IDirectDrawSurface_AddAttachedSurface(surface4, surface1);
4768 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
4769 hr = IDirectDrawSurface_AddAttachedSurface(surface3, surface4);
4770 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
4771 hr = IDirectDrawSurface_AddAttachedSurface(surface4, surface3);
4772 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
4773 hr = IDirectDrawSurface_AddAttachedSurface(surface2, surface4);
4774 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
4775 hr = IDirectDrawSurface_AddAttachedSurface(surface4, surface2);
4776 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
4778 IDirectDrawSurface_Release(surface4);
4780 memset(&surface_desc, 0, sizeof(surface_desc));
4781 surface_desc.dwSize = sizeof(surface_desc);
4782 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4783 surface_desc.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
4784 surface_desc.dwWidth = 16;
4785 surface_desc.dwHeight = 16;
4786 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface4, NULL);
4787 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4789 if (SUCCEEDED(hr = IDirectDrawSurface_AddAttachedSurface(surface1, surface4)))
4791 skip("Running on refrast, skipping some tests.\n");
4792 hr = IDirectDrawSurface_DeleteAttachedSurface(surface1, 0, surface4);
4793 ok(SUCCEEDED(hr), "Failed to detach surface, hr %#x.\n", hr);
4795 else
4797 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
4798 hr = IDirectDrawSurface_AddAttachedSurface(surface4, surface1);
4799 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
4800 hr = IDirectDrawSurface_AddAttachedSurface(surface3, surface4);
4801 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
4802 hr = IDirectDrawSurface_AddAttachedSurface(surface4, surface3);
4803 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
4804 hr = IDirectDrawSurface_AddAttachedSurface(surface2, surface4);
4805 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
4806 hr = IDirectDrawSurface_AddAttachedSurface(surface4, surface2);
4807 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
4810 IDirectDrawSurface_Release(surface4);
4811 IDirectDrawSurface_Release(surface3);
4812 IDirectDrawSurface_Release(surface2);
4813 IDirectDrawSurface_Release(surface1);
4815 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
4816 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4818 /* Try a single primary and two offscreen plain surfaces. */
4819 memset(&surface_desc, 0, sizeof(surface_desc));
4820 surface_desc.dwSize = sizeof(surface_desc);
4821 surface_desc.dwFlags = DDSD_CAPS;
4822 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
4823 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface1, NULL);
4824 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4826 memset(&surface_desc, 0, sizeof(surface_desc));
4827 surface_desc.dwSize = sizeof(surface_desc);
4828 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4829 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
4830 surface_desc.dwWidth = registry_mode.dmPelsWidth;
4831 surface_desc.dwHeight = registry_mode.dmPelsHeight;
4832 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface2, NULL);
4833 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4835 memset(&surface_desc, 0, sizeof(surface_desc));
4836 surface_desc.dwSize = sizeof(surface_desc);
4837 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4838 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
4839 surface_desc.dwWidth = registry_mode.dmPelsWidth;
4840 surface_desc.dwHeight = registry_mode.dmPelsHeight;
4841 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface3, NULL);
4842 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4844 /* This one has a different size. */
4845 memset(&surface_desc, 0, sizeof(surface_desc));
4846 surface_desc.dwSize = sizeof(surface_desc);
4847 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4848 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
4849 surface_desc.dwWidth = 128;
4850 surface_desc.dwHeight = 128;
4851 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface4, NULL);
4852 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4854 hr = IDirectDrawSurface_AddAttachedSurface(surface1, surface2);
4855 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
4856 /* Try the reverse without detaching first. */
4857 hr = IDirectDrawSurface_AddAttachedSurface(surface2, surface1);
4858 ok(hr == DDERR_SURFACEALREADYATTACHED, "Got unexpected hr %#x.\n", hr);
4859 hr = IDirectDrawSurface_DeleteAttachedSurface(surface1, 0, surface2);
4860 ok(SUCCEEDED(hr), "Failed to detach surface, hr %#x.\n", hr);
4862 hr = IDirectDrawSurface_AddAttachedSurface(surface2, surface1);
4863 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
4864 /* Try to detach reversed. */
4865 hr = IDirectDrawSurface_DeleteAttachedSurface(surface1, 0, surface2);
4866 ok(hr == DDERR_CANNOTDETACHSURFACE, "Got unexpected hr %#x.\n", hr);
4867 hr = IDirectDrawSurface_DeleteAttachedSurface(surface2, 0, surface1);
4868 ok(SUCCEEDED(hr), "Failed to detach surface, hr %#x.\n", hr);
4870 hr = IDirectDrawSurface_AddAttachedSurface(surface2, surface3);
4871 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
4872 hr = IDirectDrawSurface_DeleteAttachedSurface(surface2, 0, surface3);
4873 ok(SUCCEEDED(hr), "Failed to detach surface, hr %#x.\n", hr);
4875 hr = IDirectDrawSurface_AddAttachedSurface(surface1, surface4);
4876 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
4877 hr = IDirectDrawSurface_AddAttachedSurface(surface4, surface1);
4878 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
4880 IDirectDrawSurface_Release(surface4);
4881 IDirectDrawSurface_Release(surface3);
4882 IDirectDrawSurface_Release(surface2);
4883 IDirectDrawSurface_Release(surface1);
4885 /* Test DeleteAttachedSurface() and automatic detachment of attached surfaces on release. */
4886 memset(&surface_desc, 0, sizeof(surface_desc));
4887 surface_desc.dwSize = sizeof(surface_desc);
4888 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
4889 surface_desc.dwWidth = 64;
4890 surface_desc.dwHeight = 64;
4891 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
4892 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
4893 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB; /* D3DFMT_R5G6B5 */
4894 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount = 16;
4895 U2(surface_desc.ddpfPixelFormat).dwRBitMask = 0xf800;
4896 U3(surface_desc.ddpfPixelFormat).dwGBitMask = 0x07e0;
4897 U4(surface_desc.ddpfPixelFormat).dwBBitMask = 0x001f;
4898 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface1, NULL);
4899 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4900 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface3, NULL);
4901 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4903 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
4904 surface_desc.ddpfPixelFormat.dwFlags = DDPF_ZBUFFER;
4905 U1(surface_desc.ddpfPixelFormat).dwZBufferBitDepth = 16;
4906 U3(surface_desc.ddpfPixelFormat).dwZBitMask = 0x0000ffff;
4907 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface2, NULL);
4908 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4910 hr = IDirectDrawSurface_AddAttachedSurface(surface1, surface2);
4911 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
4912 refcount = get_refcount((IUnknown *)surface2);
4913 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
4914 hr = IDirectDrawSurface_AddAttachedSurface(surface1, surface2);
4915 ok(hr == DDERR_SURFACEALREADYATTACHED, "Got unexpected hr %#x.\n", hr);
4917 /* Attaching while already attached to other surface. */
4918 hr = IDirectDrawSurface_AddAttachedSurface(surface3, surface2);
4919 todo_wine ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
4920 hr = IDirectDrawSurface_DeleteAttachedSurface(surface3, 0, surface2);
4921 todo_wine ok(SUCCEEDED(hr), "Failed to detach surface, hr %#x.\n", hr);
4922 IDirectDrawSurface_Release(surface3);
4924 hr = IDirectDrawSurface_DeleteAttachedSurface(surface1, 0, surface2);
4925 ok(SUCCEEDED(hr), "Failed to detach surface, hr %#x.\n", hr);
4926 refcount = get_refcount((IUnknown *)surface2);
4927 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4929 /* Automatic detachment on release. */
4930 hr = IDirectDrawSurface_AddAttachedSurface(surface1, surface2);
4931 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
4932 refcount = get_refcount((IUnknown *)surface2);
4933 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
4934 refcount = IDirectDrawSurface_Release(surface1);
4935 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4936 refcount = IDirectDrawSurface_Release(surface2);
4937 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4938 refcount = IDirectDraw_Release(ddraw);
4939 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4940 DestroyWindow(window);
4943 static void test_pixel_format(void)
4945 HWND window, window2 = NULL;
4946 HDC hdc, hdc2 = NULL;
4947 HMODULE gl = NULL;
4948 int format, test_format;
4949 PIXELFORMATDESCRIPTOR pfd;
4950 IDirectDraw *ddraw = NULL;
4951 IDirectDrawClipper *clipper = NULL;
4952 DDSURFACEDESC ddsd;
4953 IDirectDrawSurface *primary = NULL;
4954 DDBLTFX fx;
4955 HRESULT hr;
4957 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4958 100, 100, 160, 160, NULL, NULL, NULL, NULL);
4959 if (!window)
4961 skip("Failed to create window\n");
4962 return;
4965 window2 = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4966 100, 100, 160, 160, NULL, NULL, NULL, NULL);
4968 hdc = GetDC(window);
4969 if (!hdc)
4971 skip("Failed to get DC\n");
4972 goto cleanup;
4975 if (window2)
4976 hdc2 = GetDC(window2);
4978 gl = LoadLibraryA("opengl32.dll");
4979 ok(!!gl, "failed to load opengl32.dll; SetPixelFormat()/GetPixelFormat() may not work right\n");
4981 format = GetPixelFormat(hdc);
4982 ok(format == 0, "new window has pixel format %d\n", format);
4984 ZeroMemory(&pfd, sizeof(pfd));
4985 pfd.nSize = sizeof(pfd);
4986 pfd.nVersion = 1;
4987 pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
4988 pfd.iPixelType = PFD_TYPE_RGBA;
4989 pfd.iLayerType = PFD_MAIN_PLANE;
4990 format = ChoosePixelFormat(hdc, &pfd);
4991 if (format <= 0)
4993 skip("no pixel format available\n");
4994 goto cleanup;
4997 if (!SetPixelFormat(hdc, format, &pfd) || GetPixelFormat(hdc) != format)
4999 skip("failed to set pixel format\n");
5000 goto cleanup;
5003 if (!hdc2 || !SetPixelFormat(hdc2, format, &pfd) || GetPixelFormat(hdc2) != format)
5005 skip("failed to set pixel format on second window\n");
5006 if (hdc2)
5008 ReleaseDC(window2, hdc2);
5009 hdc2 = NULL;
5013 ddraw = create_ddraw();
5014 ok(!!ddraw, "Failed to create a ddraw object.\n");
5016 test_format = GetPixelFormat(hdc);
5017 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
5019 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
5020 if (FAILED(hr))
5022 skip("Failed to set cooperative level, hr %#x.\n", hr);
5023 goto cleanup;
5026 test_format = GetPixelFormat(hdc);
5027 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
5029 if (hdc2)
5031 hr = IDirectDraw_CreateClipper(ddraw, 0, &clipper, NULL);
5032 ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr);
5033 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window2);
5034 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
5036 test_format = GetPixelFormat(hdc);
5037 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
5039 test_format = GetPixelFormat(hdc2);
5040 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
5043 memset(&ddsd, 0, sizeof(ddsd));
5044 ddsd.dwSize = sizeof(ddsd);
5045 ddsd.dwFlags = DDSD_CAPS;
5046 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
5048 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &primary, NULL);
5049 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
5051 test_format = GetPixelFormat(hdc);
5052 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
5054 if (hdc2)
5056 test_format = GetPixelFormat(hdc2);
5057 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
5060 if (clipper)
5062 hr = IDirectDrawSurface_SetClipper(primary, clipper);
5063 ok(SUCCEEDED(hr), "Failed to set clipper, hr %#x.\n", hr);
5065 test_format = GetPixelFormat(hdc);
5066 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
5068 test_format = GetPixelFormat(hdc2);
5069 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
5072 memset(&fx, 0, sizeof(fx));
5073 fx.dwSize = sizeof(fx);
5074 hr = IDirectDrawSurface_Blt(primary, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
5075 ok(SUCCEEDED(hr), "Failed to clear source surface, hr %#x.\n", hr);
5077 test_format = GetPixelFormat(hdc);
5078 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
5080 if (hdc2)
5082 test_format = GetPixelFormat(hdc2);
5083 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
5086 cleanup:
5087 if (primary) IDirectDrawSurface_Release(primary);
5088 if (clipper) IDirectDrawClipper_Release(clipper);
5089 if (ddraw) IDirectDraw_Release(ddraw);
5090 if (gl) FreeLibrary(gl);
5091 if (hdc) ReleaseDC(window, hdc);
5092 if (hdc2) ReleaseDC(window2, hdc2);
5093 if (window) DestroyWindow(window);
5094 if (window2) DestroyWindow(window2);
5097 static void test_create_surface_pitch(void)
5099 IDirectDrawSurface *surface;
5100 DDSURFACEDESC surface_desc;
5101 IDirectDraw *ddraw;
5102 unsigned int i;
5103 ULONG refcount;
5104 HWND window;
5105 HRESULT hr;
5106 void *mem;
5108 static const struct
5110 DWORD caps;
5111 DWORD flags_in;
5112 DWORD pitch_in;
5113 HRESULT hr;
5114 DWORD flags_out;
5115 DWORD pitch_out32;
5116 DWORD pitch_out64;
5118 test_data[] =
5120 /* 0 */
5121 {DDSCAPS_VIDEOMEMORY | DDSCAPS_OFFSCREENPLAIN,
5122 0, 0, DD_OK,
5123 DDSD_PITCH, 0x100, 0x100},
5124 {DDSCAPS_VIDEOMEMORY | DDSCAPS_OFFSCREENPLAIN,
5125 DDSD_PITCH, 0x104, DD_OK,
5126 DDSD_PITCH, 0x100, 0x100},
5127 {DDSCAPS_VIDEOMEMORY | DDSCAPS_OFFSCREENPLAIN,
5128 DDSD_PITCH, 0x0f8, DD_OK,
5129 DDSD_PITCH, 0x100, 0x100},
5130 {DDSCAPS_VIDEOMEMORY | DDSCAPS_OFFSCREENPLAIN,
5131 DDSD_LPSURFACE | DDSD_PITCH, 0x100, DDERR_INVALIDCAPS,
5132 0, 0, 0 },
5133 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
5134 0, 0, DD_OK,
5135 DDSD_PITCH, 0x100, 0x0fc},
5136 /* 5 */
5137 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
5138 DDSD_PITCH, 0x104, DD_OK,
5139 DDSD_PITCH, 0x100, 0x0fc},
5140 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
5141 DDSD_PITCH, 0x0f8, DD_OK,
5142 DDSD_PITCH, 0x100, 0x0fc},
5143 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
5144 DDSD_PITCH | DDSD_LINEARSIZE, 0, DD_OK,
5145 DDSD_PITCH, 0x100, 0x0fc},
5146 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
5147 DDSD_LPSURFACE, 0, DDERR_INVALIDPARAMS,
5148 0, 0, 0 },
5149 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
5150 DDSD_LPSURFACE | DDSD_PITCH, 0x100, DDERR_INVALIDPARAMS,
5151 0, 0, 0 },
5152 /* 10 */
5153 {DDSCAPS_VIDEOMEMORY | DDSCAPS_OFFSCREENPLAIN | DDSCAPS_ALLOCONLOAD,
5154 0, 0, DDERR_INVALIDCAPS,
5155 0, 0, 0 },
5156 {DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD,
5157 0, 0, DD_OK,
5158 DDSD_PITCH, 0x100, 0 },
5159 {DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD,
5160 DDSD_LPSURFACE | DDSD_PITCH, 0x100, DDERR_INVALIDCAPS,
5161 0, 0, 0 },
5162 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN | DDSCAPS_ALLOCONLOAD,
5163 0, 0, DDERR_INVALIDCAPS,
5164 0, 0, 0 },
5165 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD,
5166 0, 0, DD_OK,
5167 DDSD_PITCH, 0x100, 0 },
5168 /* 15 */
5169 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD,
5170 DDSD_LPSURFACE | DDSD_PITCH, 0x100, DDERR_INVALIDPARAMS,
5171 0, 0, 0 },
5173 DWORD flags_mask = DDSD_PITCH | DDSD_LPSURFACE | DDSD_LINEARSIZE;
5175 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5176 0, 0, 640, 480, 0, 0, 0, 0);
5177 ddraw = create_ddraw();
5178 ok(!!ddraw, "Failed to create a ddraw object.\n");
5179 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
5180 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5182 mem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ((63 * 4) + 8) * 63);
5184 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
5186 memset(&surface_desc, 0, sizeof(surface_desc));
5187 surface_desc.dwSize = sizeof(surface_desc);
5188 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | test_data[i].flags_in;
5189 surface_desc.ddsCaps.dwCaps = test_data[i].caps;
5190 surface_desc.dwWidth = 63;
5191 surface_desc.dwHeight = 63;
5192 U1(surface_desc).lPitch = test_data[i].pitch_in;
5193 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
5194 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB;
5195 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount = 32;
5196 U2(surface_desc.ddpfPixelFormat).dwRBitMask = 0x00ff0000;
5197 U3(surface_desc.ddpfPixelFormat).dwGBitMask = 0x0000ff00;
5198 U4(surface_desc.ddpfPixelFormat).dwBBitMask = 0x000000ff;
5199 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
5200 if (test_data[i].flags_in & DDSD_LPSURFACE)
5202 HRESULT expected_hr = SUCCEEDED(test_data[i].hr) ? DDERR_INVALIDPARAMS : test_data[i].hr;
5203 ok(hr == expected_hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, expected_hr);
5204 surface_desc.lpSurface = mem;
5205 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
5207 if ((test_data[i].caps & DDSCAPS_VIDEOMEMORY) && hr == DDERR_NODIRECTDRAWHW)
5208 continue;
5209 ok(hr == test_data[i].hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, test_data[i].hr);
5210 if (FAILED(hr))
5211 continue;
5213 memset(&surface_desc, 0, sizeof(surface_desc));
5214 surface_desc.dwSize = sizeof(surface_desc);
5215 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
5216 ok(SUCCEEDED(hr), "Test %u: Failed to get surface desc, hr %#x.\n", i, hr);
5217 ok((surface_desc.dwFlags & flags_mask) == test_data[i].flags_out,
5218 "Test %u: Got unexpected flags %#x, expected %#x.\n",
5219 i, surface_desc.dwFlags & flags_mask, test_data[i].flags_out);
5220 if (!(test_data[i].caps & DDSCAPS_TEXTURE))
5222 if (is_ddraw64 && test_data[i].pitch_out32 != test_data[i].pitch_out64)
5223 todo_wine ok(U1(surface_desc).lPitch == test_data[i].pitch_out64,
5224 "Test %u: Got unexpected pitch %u, expected %u.\n",
5225 i, U1(surface_desc).lPitch, test_data[i].pitch_out64);
5226 else
5227 ok(U1(surface_desc).lPitch == test_data[i].pitch_out32,
5228 "Test %u: Got unexpected pitch %u, expected %u.\n",
5229 i, U1(surface_desc).lPitch, test_data[i].pitch_out32);
5231 ok(!surface_desc.lpSurface, "Test %u: Got unexpected lpSurface %p.\n", i, surface_desc.lpSurface);
5233 IDirectDrawSurface_Release(surface);
5236 HeapFree(GetProcessHeap(), 0, mem);
5237 refcount = IDirectDraw_Release(ddraw);
5238 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
5239 DestroyWindow(window);
5242 static void test_mipmap(void)
5244 IDirectDrawSurface *surface, *surface2;
5245 DDSURFACEDESC surface_desc;
5246 IDirectDraw *ddraw;
5247 unsigned int i;
5248 ULONG refcount;
5249 HWND window;
5250 HRESULT hr;
5251 DDSCAPS caps = {DDSCAPS_COMPLEX};
5252 DDCAPS hal_caps;
5254 static const struct
5256 DWORD flags;
5257 DWORD caps;
5258 DWORD width;
5259 DWORD height;
5260 DWORD mipmap_count_in;
5261 HRESULT hr;
5262 DWORD mipmap_count_out;
5264 tests[] =
5266 {DDSD_MIPMAPCOUNT, DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP, 128, 32, 3, DD_OK, 3},
5267 {DDSD_MIPMAPCOUNT, DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP, 128, 32, 0, DDERR_INVALIDPARAMS, 0},
5268 {0, DDSCAPS_TEXTURE | DDSCAPS_MIPMAP, 128, 32, 0, DD_OK, 1},
5269 {0, DDSCAPS_MIPMAP, 128, 32, 0, DDERR_INVALIDCAPS, 0},
5270 {0, DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP, 128, 32, 0, DD_OK, 6},
5271 {0, DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP, 32, 64, 0, DD_OK, 6},
5274 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5275 0, 0, 640, 480, 0, 0, 0, 0);
5276 ddraw = create_ddraw();
5277 ok(!!ddraw, "Failed to create a ddraw object.\n");
5278 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
5279 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5281 memset(&hal_caps, 0, sizeof(hal_caps));
5282 hal_caps.dwSize = sizeof(hal_caps);
5283 hr = IDirectDraw_GetCaps(ddraw, &hal_caps, NULL);
5284 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
5285 if ((hal_caps.ddsCaps.dwCaps & (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP)) != (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP))
5287 skip("Mipmapped textures not supported, skipping tests.\n");
5288 IDirectDraw_Release(ddraw);
5289 DestroyWindow(window);
5290 return;
5293 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
5295 memset(&surface_desc, 0, sizeof(surface_desc));
5296 surface_desc.dwSize = sizeof(surface_desc);
5297 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | tests[i].flags;
5298 surface_desc.ddsCaps.dwCaps = tests[i].caps;
5299 surface_desc.dwWidth = tests[i].width;
5300 surface_desc.dwHeight = tests[i].height;
5301 if (tests[i].flags & DDSD_MIPMAPCOUNT)
5302 U2(surface_desc).dwMipMapCount = tests[i].mipmap_count_in;
5303 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
5304 ok(hr == tests[i].hr, "Test %u: Got unexpected hr %#x.\n", i, hr);
5305 if (FAILED(hr))
5306 continue;
5308 memset(&surface_desc, 0, sizeof(surface_desc));
5309 surface_desc.dwSize = sizeof(surface_desc);
5310 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
5311 ok(SUCCEEDED(hr), "Test %u: Failed to get surface desc, hr %#x.\n", i, hr);
5312 ok(surface_desc.dwFlags & DDSD_MIPMAPCOUNT,
5313 "Test %u: Got unexpected flags %#x.\n", i, surface_desc.dwFlags);
5314 ok(U2(surface_desc).dwMipMapCount == tests[i].mipmap_count_out,
5315 "Test %u: Got unexpected mipmap count %u.\n", i, U2(surface_desc).dwMipMapCount);
5317 if (U2(surface_desc).dwMipMapCount > 1)
5319 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &surface2);
5320 ok(SUCCEEDED(hr), "Test %u: Failed to get attached surface, hr %#x.\n", i, hr);
5322 memset(&surface_desc, 0, sizeof(surface_desc));
5323 surface_desc.dwSize = sizeof(surface_desc);
5324 hr = IDirectDrawSurface_Lock(surface, NULL, &surface_desc, 0, NULL);
5325 ok(SUCCEEDED(hr), "Test %u: Failed to lock surface, hr %#x.\n", i, hr);
5326 memset(&surface_desc, 0, sizeof(surface_desc));
5327 surface_desc.dwSize = sizeof(surface_desc);
5328 hr = IDirectDrawSurface_Lock(surface2, NULL, &surface_desc, 0, NULL);
5329 ok(SUCCEEDED(hr), "Test %u: Failed to lock surface, hr %#x.\n", i, hr);
5330 IDirectDrawSurface_Unlock(surface2, NULL);
5331 IDirectDrawSurface_Unlock(surface, NULL);
5333 IDirectDrawSurface_Release(surface2);
5336 IDirectDrawSurface_Release(surface);
5339 refcount = IDirectDraw_Release(ddraw);
5340 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
5341 DestroyWindow(window);
5344 static void test_palette_complex(void)
5346 IDirectDrawSurface *surface, *mipmap, *tmp;
5347 DDSURFACEDESC surface_desc;
5348 IDirectDraw *ddraw;
5349 IDirectDrawPalette *palette, *palette2, *palette_mipmap;
5350 ULONG refcount;
5351 HWND window;
5352 HRESULT hr;
5353 DDSCAPS caps = {DDSCAPS_COMPLEX};
5354 DDCAPS hal_caps;
5355 PALETTEENTRY palette_entries[256];
5356 unsigned int i;
5357 HDC dc;
5358 RGBQUAD rgbquad;
5359 UINT count;
5361 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5362 0, 0, 640, 480, 0, 0, 0, 0);
5363 ddraw = create_ddraw();
5364 ok(!!ddraw, "Failed to create a ddraw object.\n");
5365 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
5366 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5368 memset(&hal_caps, 0, sizeof(hal_caps));
5369 hal_caps.dwSize = sizeof(hal_caps);
5370 hr = IDirectDraw_GetCaps(ddraw, &hal_caps, NULL);
5371 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
5372 if ((hal_caps.ddsCaps.dwCaps & (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP)) != (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP))
5374 skip("Mipmapped textures not supported, skipping mipmap palette test.\n");
5375 IDirectDraw_Release(ddraw);
5376 DestroyWindow(window);
5377 return;
5380 memset(&surface_desc, 0, sizeof(surface_desc));
5381 surface_desc.dwSize = sizeof(surface_desc);
5382 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
5383 surface_desc.dwWidth = 128;
5384 surface_desc.dwHeight = 128;
5385 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
5386 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
5387 surface_desc.ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
5388 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount = 8;
5389 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
5390 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5392 memset(palette_entries, 0, sizeof(palette_entries));
5393 hr = IDirectDraw_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
5394 palette_entries, &palette, NULL);
5395 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
5397 memset(palette_entries, 0, sizeof(palette_entries));
5398 palette_entries[1].peRed = 0xff;
5399 palette_entries[1].peGreen = 0x80;
5400 hr = IDirectDraw_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
5401 palette_entries, &palette_mipmap, NULL);
5402 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
5404 palette2 = (void *)0xdeadbeef;
5405 hr = IDirectDrawSurface_GetPalette(surface, &palette2);
5406 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x.\n", hr);
5407 ok(!palette2, "Got unexpected palette %p.\n", palette2);
5408 hr = IDirectDrawSurface_SetPalette(surface, palette);
5409 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
5410 hr = IDirectDrawSurface_GetPalette(surface, &palette2);
5411 ok(SUCCEEDED(hr), "Failed to get palette, hr %#x.\n", hr);
5412 ok(palette == palette2, "Got unexpected palette %p.\n", palette2);
5413 IDirectDrawPalette_Release(palette2);
5415 mipmap = surface;
5416 IDirectDrawSurface_AddRef(mipmap);
5417 for (i = 0; i < 7; ++i)
5419 hr = IDirectDrawSurface_GetAttachedSurface(mipmap, &caps, &tmp);
5420 ok(SUCCEEDED(hr), "Failed to get attached surface, i %u, hr %#x.\n", i, hr);
5421 palette2 = (void *)0xdeadbeef;
5422 hr = IDirectDrawSurface_GetPalette(tmp, &palette2);
5423 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x, i %u.\n", hr, i);
5424 ok(!palette2, "Got unexpected palette %p, i %u.\n", palette2, i);
5426 hr = IDirectDrawSurface_SetPalette(tmp, palette_mipmap);
5427 ok(SUCCEEDED(hr), "Failed to set palette, i %u, hr %#x.\n", i, hr);
5429 hr = IDirectDrawSurface_GetPalette(tmp, &palette2);
5430 ok(SUCCEEDED(hr), "Failed to get palette, i %u, hr %#x.\n", i, hr);
5431 ok(palette_mipmap == palette2, "Got unexpected palette %p.\n", palette2);
5432 IDirectDrawPalette_Release(palette2);
5434 hr = IDirectDrawSurface_GetDC(tmp, &dc);
5435 ok(SUCCEEDED(hr), "Failed to get DC, i %u, hr %#x.\n", i, hr);
5436 count = GetDIBColorTable(dc, 1, 1, &rgbquad);
5437 ok(count == 1, "Expected count 1, got %u.\n", count);
5438 ok(rgbquad.rgbRed == 0xff, "Expected rgbRed = 0xff, got %#x.\n", rgbquad.rgbRed);
5439 ok(rgbquad.rgbGreen == 0x80, "Expected rgbGreen = 0x80, got %#x.\n", rgbquad.rgbGreen);
5440 ok(rgbquad.rgbBlue == 0x0, "Expected rgbBlue = 0x0, got %#x.\n", rgbquad.rgbBlue);
5441 hr = IDirectDrawSurface_ReleaseDC(tmp, dc);
5442 ok(SUCCEEDED(hr), "Failed to release DC, i %u, hr %#x.\n", i, hr);
5444 IDirectDrawSurface_Release(mipmap);
5445 mipmap = tmp;
5448 hr = IDirectDrawSurface_GetAttachedSurface(mipmap, &caps, &tmp);
5449 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
5450 IDirectDrawSurface_Release(mipmap);
5451 refcount = IDirectDrawSurface_Release(surface);
5452 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
5453 refcount = IDirectDrawPalette_Release(palette_mipmap);
5454 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
5455 refcount = IDirectDrawPalette_Release(palette);
5456 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
5458 refcount = IDirectDraw_Release(ddraw);
5459 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
5460 DestroyWindow(window);
5463 static void test_p8_blit(void)
5465 IDirectDrawSurface *src, *dst, *dst_p8;
5466 DDSURFACEDESC surface_desc;
5467 IDirectDraw *ddraw;
5468 IDirectDrawPalette *palette, *palette2;
5469 ULONG refcount;
5470 HWND window;
5471 HRESULT hr;
5472 PALETTEENTRY palette_entries[256];
5473 unsigned int x;
5474 DDBLTFX fx;
5475 BOOL is_warp;
5476 static const BYTE src_data[] = {0x10, 0x1, 0x2, 0x3, 0x4, 0x5, 0xff, 0x80};
5477 static const BYTE src_data2[] = {0x10, 0x5, 0x4, 0x3, 0x2, 0x1, 0xff, 0x80};
5478 static const BYTE expected_p8[] = {0x10, 0x1, 0x4, 0x3, 0x4, 0x5, 0xff, 0x80};
5479 static const D3DCOLOR expected[] =
5481 0x00101010, 0x00010101, 0x00020202, 0x00030303,
5482 0x00040404, 0x00050505, 0x00ffffff, 0x00808080,
5484 D3DCOLOR color;
5486 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5487 0, 0, 640, 480, 0, 0, 0, 0);
5488 ddraw = create_ddraw();
5489 ok(!!ddraw, "Failed to create a ddraw object.\n");
5490 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
5491 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5492 is_warp = ddraw_is_warp(ddraw);
5494 memset(palette_entries, 0, sizeof(palette_entries));
5495 palette_entries[1].peGreen = 0xff;
5496 palette_entries[2].peBlue = 0xff;
5497 palette_entries[3].peFlags = 0xff;
5498 palette_entries[4].peRed = 0xff;
5499 hr = IDirectDraw_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
5500 palette_entries, &palette, NULL);
5501 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
5502 palette_entries[1].peBlue = 0xff;
5503 palette_entries[2].peGreen = 0xff;
5504 palette_entries[3].peRed = 0xff;
5505 palette_entries[4].peFlags = 0x0;
5506 hr = IDirectDraw_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
5507 palette_entries, &palette2, NULL);
5508 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
5510 memset(&surface_desc, 0, sizeof(surface_desc));
5511 surface_desc.dwSize = sizeof(surface_desc);
5512 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
5513 surface_desc.dwWidth = 8;
5514 surface_desc.dwHeight = 1;
5515 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
5516 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
5517 surface_desc.ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
5518 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount = 8;
5519 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &src, NULL);
5520 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5521 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &dst_p8, NULL);
5522 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5523 hr = IDirectDrawSurface_SetPalette(dst_p8, palette2);
5524 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
5526 memset(&surface_desc, 0, sizeof(surface_desc));
5527 surface_desc.dwSize = sizeof(surface_desc);
5528 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
5529 surface_desc.dwWidth = 8;
5530 surface_desc.dwHeight = 1;
5531 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
5532 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
5533 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
5534 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount = 32;
5535 U2(surface_desc.ddpfPixelFormat).dwRBitMask = 0x00ff0000;
5536 U3(surface_desc.ddpfPixelFormat).dwGBitMask = 0x0000ff00;
5537 U4(surface_desc.ddpfPixelFormat).dwBBitMask = 0x000000ff;
5538 U5(surface_desc.ddpfPixelFormat).dwRGBAlphaBitMask = 0xff000000;
5539 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &dst, NULL);
5540 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5542 memset(&surface_desc, 0, sizeof(surface_desc));
5543 surface_desc.dwSize = sizeof(surface_desc);
5544 hr = IDirectDrawSurface_Lock(src, NULL, &surface_desc, DDLOCK_WAIT, NULL);
5545 ok(SUCCEEDED(hr), "Failed to lock source surface, hr %#x.\n", hr);
5546 memcpy(surface_desc.lpSurface, src_data, sizeof(src_data));
5547 hr = IDirectDrawSurface_Unlock(src, NULL);
5548 ok(SUCCEEDED(hr), "Failed to unlock source surface, hr %#x.\n", hr);
5550 hr = IDirectDrawSurface_Lock(dst_p8, NULL, &surface_desc, DDLOCK_WAIT, NULL);
5551 ok(SUCCEEDED(hr), "Failed to lock destination surface, hr %#x.\n", hr);
5552 memcpy(surface_desc.lpSurface, src_data2, sizeof(src_data2));
5553 hr = IDirectDrawSurface_Unlock(dst_p8, NULL);
5554 ok(SUCCEEDED(hr), "Failed to unlock destination surface, hr %#x.\n", hr);
5556 hr = IDirectDrawSurface_SetPalette(src, palette);
5557 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
5558 hr = IDirectDrawSurface_Blt(dst, NULL, src, NULL, DDBLT_WAIT, NULL);
5559 /* The r500 Windows 7 driver returns E_NOTIMPL. r200 on Windows XP works.
5560 * The Geforce 7 driver on Windows Vista returns E_FAIL. Newer Nvidia GPUs work. */
5561 ok(SUCCEEDED(hr) || broken(hr == E_NOTIMPL) || broken(hr == E_FAIL),
5562 "Failed to blit, hr %#x.\n", hr);
5564 if (SUCCEEDED(hr))
5566 for (x = 0; x < sizeof(expected) / sizeof(*expected); x++)
5568 color = get_surface_color(dst, x, 0);
5569 todo_wine ok(compare_color(color, expected[x], 0),
5570 "Pixel %u: Got color %#x, expected %#x.\n",
5571 x, color, expected[x]);
5575 memset(&fx, 0, sizeof(fx));
5576 fx.dwSize = sizeof(fx);
5577 fx.ddckSrcColorkey.dwColorSpaceHighValue = 0x2;
5578 fx.ddckSrcColorkey.dwColorSpaceLowValue = 0x2;
5579 hr = IDirectDrawSurface_Blt(dst_p8, NULL, src, NULL, DDBLT_WAIT | DDBLT_KEYSRCOVERRIDE, &fx);
5580 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
5582 hr = IDirectDrawSurface_Lock(dst_p8, NULL, &surface_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
5583 ok(SUCCEEDED(hr), "Failed to lock destination surface, hr %#x.\n", hr);
5584 /* A color keyed P8 blit doesn't do anything on WARP - it just leaves the data in the destination
5585 * surface untouched. P8 blits without color keys work. Error checking (DDBLT_KEYSRC without a key
5586 * for example) also works as expected.
5588 * Using DDBLT_KEYSRC instead of DDBLT_KEYSRCOVERRIDE doesn't change this. Doing this blit with
5589 * the display mode set to P8 doesn't help either. */
5590 ok(!memcmp(surface_desc.lpSurface, expected_p8, sizeof(expected_p8))
5591 || broken(is_warp && !memcmp(surface_desc.lpSurface, src_data2, sizeof(src_data2))),
5592 "Got unexpected P8 color key blit result.\n");
5593 hr = IDirectDrawSurface_Unlock(dst_p8, NULL);
5594 ok(SUCCEEDED(hr), "Failed to unlock destination surface, hr %#x.\n", hr);
5596 IDirectDrawSurface_Release(src);
5597 IDirectDrawSurface_Release(dst);
5598 IDirectDrawSurface_Release(dst_p8);
5599 IDirectDrawPalette_Release(palette);
5600 IDirectDrawPalette_Release(palette2);
5602 refcount = IDirectDraw_Release(ddraw);
5603 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
5604 DestroyWindow(window);
5607 static void test_material(void)
5609 IDirect3DMaterial *background, *material;
5610 IDirect3DExecuteBuffer *execute_buffer;
5611 D3DMATERIALHANDLE mat_handle, tmp;
5612 D3DEXECUTEBUFFERDESC exec_desc;
5613 IDirect3DViewport *viewport;
5614 IDirect3DDevice *device;
5615 IDirectDrawSurface *rt;
5616 IDirectDraw *ddraw;
5617 UINT inst_length;
5618 D3DCOLOR color;
5619 ULONG refcount;
5620 unsigned int i;
5621 HWND window;
5622 HRESULT hr;
5623 BOOL valid;
5624 void *ptr;
5626 static D3DVERTEX quad[] =
5628 {{-1.0f}, {-1.0f}, {0.0f}, {1.0f}, {0.0f}, {0.0f}},
5629 {{-1.0f}, { 1.0f}, {0.0f}, {1.0f}, {0.0f}, {0.0f}},
5630 {{ 1.0f}, {-1.0f}, {0.0f}, {1.0f}, {0.0f}, {0.0f}},
5631 {{ 1.0f}, { 1.0f}, {0.0f}, {1.0f}, {0.0f}, {0.0f}},
5633 static const struct
5635 BOOL material;
5636 D3DCOLOR expected_color;
5638 test_data[] =
5640 {TRUE, 0x0000ff00},
5641 {FALSE, 0x00ffffff},
5643 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
5645 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5646 0, 0, 640, 480, 0, 0, 0, 0);
5647 ddraw = create_ddraw();
5648 ok(!!ddraw, "Failed to create a ddraw object.\n");
5649 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
5651 skip("Failed to create a 3D device, skipping test.\n");
5652 DestroyWindow(window);
5653 return;
5656 hr = IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&rt);
5657 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
5659 background = create_diffuse_material(device, 0.0f, 0.0f, 1.0f, 1.0f);
5660 viewport = create_viewport(device, 0, 0, 640, 480);
5661 viewport_set_background(device, viewport, background);
5663 material = create_emissive_material(device, 0.0f, 1.0f, 0.0f, 0.0f);
5664 hr = IDirect3DMaterial_GetHandle(material, device, &mat_handle);
5665 ok(SUCCEEDED(hr), "Failed to get material handle, hr %#x.\n", hr);
5667 memset(&exec_desc, 0, sizeof(exec_desc));
5668 exec_desc.dwSize = sizeof(exec_desc);
5669 exec_desc.dwFlags = D3DDEB_BUFSIZE | D3DDEB_CAPS;
5670 exec_desc.dwBufferSize = 1024;
5671 exec_desc.dwCaps = D3DDEBCAPS_SYSTEMMEMORY;
5673 hr = IDirect3DDevice_CreateExecuteBuffer(device, &exec_desc, &execute_buffer, NULL);
5674 ok(SUCCEEDED(hr), "Failed to create execute buffer, hr %#x.\n", hr);
5676 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
5678 hr = IDirect3DExecuteBuffer_Lock(execute_buffer, &exec_desc);
5679 ok(SUCCEEDED(hr), "Failed to lock execute buffer, hr %#x.\n", hr);
5681 memcpy(exec_desc.lpData, quad, sizeof(quad));
5682 ptr = ((BYTE *)exec_desc.lpData) + sizeof(quad);
5683 emit_set_ls(&ptr, D3DLIGHTSTATE_MATERIAL, test_data[i].material ? mat_handle : 0);
5684 emit_process_vertices(&ptr, D3DPROCESSVERTICES_TRANSFORMLIGHT, 0, 4);
5685 emit_tquad(&ptr, 0);
5686 emit_end(&ptr);
5687 inst_length = (BYTE *)ptr - (BYTE *)exec_desc.lpData;
5688 inst_length -= sizeof(quad);
5690 hr = IDirect3DExecuteBuffer_Unlock(execute_buffer);
5691 ok(SUCCEEDED(hr), "Failed to unlock execute buffer, hr %#x.\n", hr);
5693 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER);
5694 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
5696 hr = IDirect3DDevice_BeginScene(device);
5697 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
5698 set_execute_data(execute_buffer, 4, sizeof(quad), inst_length);
5699 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
5700 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
5701 hr = IDirect3DDevice_EndScene(device);
5702 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
5703 color = get_surface_color(rt, 320, 240);
5704 if (test_data[i].material)
5705 todo_wine ok(compare_color(color, test_data[i].expected_color, 1)
5706 /* The Windows 8 testbot appears to return undefined results. */
5707 || broken(TRUE),
5708 "Got unexpected color 0x%08x, test %u.\n", color, i);
5709 else
5710 ok(compare_color(color, test_data[i].expected_color, 1),
5711 "Got unexpected color 0x%08x, test %u.\n", color, i);
5714 destroy_material(material);
5715 material = create_diffuse_material(device, 1.0f, 0.0f, 0.0f, 1.0f);
5716 hr = IDirect3DMaterial_GetHandle(material, device, &mat_handle);
5717 ok(SUCCEEDED(hr), "Failed to get material handle, hr %#x.\n", hr);
5719 hr = IDirect3DViewport_SetBackground(viewport, mat_handle);
5720 ok(SUCCEEDED(hr), "Failed to set viewport background, hr %#x.\n", hr);
5721 hr = IDirect3DViewport_GetBackground(viewport, &tmp, &valid);
5722 ok(SUCCEEDED(hr), "Failed to get viewport background, hr %#x.\n", hr);
5723 ok(tmp == mat_handle, "Got unexpected material handle %#x, expected %#x.\n", tmp, mat_handle);
5724 ok(valid, "Got unexpected valid %#x.\n", valid);
5725 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
5726 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
5727 color = get_surface_color(rt, 320, 240);
5728 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
5730 hr = IDirect3DViewport_SetBackground(viewport, 0);
5731 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
5732 hr = IDirect3DViewport_GetBackground(viewport, &tmp, &valid);
5733 ok(SUCCEEDED(hr), "Failed to get viewport background, hr %#x.\n", hr);
5734 ok(tmp == mat_handle, "Got unexpected material handle %#x, expected %#x.\n", tmp, mat_handle);
5735 ok(valid, "Got unexpected valid %#x.\n", valid);
5736 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
5737 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
5738 color = get_surface_color(rt, 320, 240);
5739 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
5741 destroy_viewport(device, viewport);
5742 viewport = create_viewport(device, 0, 0, 640, 480);
5744 hr = IDirect3DViewport_GetBackground(viewport, &tmp, &valid);
5745 ok(SUCCEEDED(hr), "Failed to get viewport background, hr %#x.\n", hr);
5746 ok(!tmp, "Got unexpected material handle %#x.\n", tmp);
5747 ok(!valid, "Got unexpected valid %#x.\n", valid);
5748 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
5749 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
5750 color = get_surface_color(rt, 320, 240);
5751 ok(compare_color(color, 0x00000000, 1), "Got unexpected color 0x%08x.\n", color);
5753 IDirect3DExecuteBuffer_Release(execute_buffer);
5754 destroy_viewport(device, viewport);
5755 destroy_material(background);
5756 destroy_material(material);
5757 IDirectDrawSurface_Release(rt);
5758 refcount = IDirect3DDevice_Release(device);
5759 ok(!refcount, "Device has %u references left.\n", refcount);
5760 refcount = IDirectDraw_Release(ddraw);
5761 ok(!refcount, "Ddraw object has %u references left.\n", refcount);
5762 DestroyWindow(window);
5765 static void test_lighting(void)
5767 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
5768 static D3DMATRIX mat =
5770 1.0f, 0.0f, 0.0f, 0.0f,
5771 0.0f, 1.0f, 0.0f, 0.0f,
5772 0.0f, 0.0f, 1.0f, 0.0f,
5773 0.0f, 0.0f, 0.0f, 1.0f,
5775 mat_singular =
5777 1.0f, 0.0f, 1.0f, 0.0f,
5778 0.0f, 1.0f, 0.0f, 0.0f,
5779 1.0f, 0.0f, 1.0f, 0.0f,
5780 0.0f, 0.0f, 0.5f, 1.0f,
5782 mat_transf =
5784 0.0f, 0.0f, 1.0f, 0.0f,
5785 0.0f, 1.0f, 0.0f, 0.0f,
5786 -1.0f, 0.0f, 0.0f, 0.0f,
5787 10.f, 10.0f, 10.0f, 1.0f,
5789 mat_nonaffine =
5791 1.0f, 0.0f, 0.0f, 0.0f,
5792 0.0f, 1.0f, 0.0f, 0.0f,
5793 0.0f, 0.0f, 1.0f, -1.0f,
5794 10.f, 10.0f, 10.0f, 0.0f,
5796 static D3DLVERTEX unlitquad[] =
5798 {{-1.0f}, {-1.0f}, {0.1f}, 0, {0xffff0000}, {0}, {0.0f}, {0.0f}},
5799 {{-1.0f}, { 0.0f}, {0.1f}, 0, {0xffff0000}, {0}, {0.0f}, {0.0f}},
5800 {{ 0.0f}, { 0.0f}, {0.1f}, 0, {0xffff0000}, {0}, {0.0f}, {0.0f}},
5801 {{ 0.0f}, {-1.0f}, {0.1f}, 0, {0xffff0000}, {0}, {0.0f}, {0.0f}},
5803 litquad[] =
5805 {{-1.0f}, { 0.0f}, {0.1f}, 0, {0xff00ff00}, {0}, {0.0f}, {0.0f}},
5806 {{-1.0f}, { 1.0f}, {0.1f}, 0, {0xff00ff00}, {0}, {0.0f}, {0.0f}},
5807 {{ 0.0f}, { 1.0f}, {0.1f}, 0, {0xff00ff00}, {0}, {0.0f}, {0.0f}},
5808 {{ 0.0f}, { 0.0f}, {0.1f}, 0, {0xff00ff00}, {0}, {0.0f}, {0.0f}},
5810 static D3DVERTEX unlitnquad[] =
5812 {{0.0f}, {-1.0f}, {0.1f}, {1.0f}, {1.0f}, {1.0f}, {0.0f}, {0.0f}},
5813 {{0.0f}, { 0.0f}, {0.1f}, {1.0f}, {1.0f}, {1.0f}, {0.0f}, {0.0f}},
5814 {{1.0f}, { 0.0f}, {0.1f}, {1.0f}, {1.0f}, {1.0f}, {0.0f}, {0.0f}},
5815 {{1.0f}, {-1.0f}, {0.1f}, {1.0f}, {1.0f}, {1.0f}, {0.0f}, {0.0f}},
5817 litnquad[] =
5819 {{0.0f}, { 0.0f}, {0.1f}, {1.0f}, {1.0f}, {1.0f}, {0.0f}, {0.0f}},
5820 {{0.0f}, { 1.0f}, {0.1f}, {1.0f}, {1.0f}, {1.0f}, {0.0f}, {0.0f}},
5821 {{1.0f}, { 1.0f}, {0.1f}, {1.0f}, {1.0f}, {1.0f}, {0.0f}, {0.0f}},
5822 {{1.0f}, { 0.0f}, {0.1f}, {1.0f}, {1.0f}, {1.0f}, {0.0f}, {0.0f}},
5824 nquad[] =
5826 {{-1.0f}, {-1.0f}, {0.0f}, {0.0f}, {0.0f}, {-1.0f}, {0.0f}, {0.0f}},
5827 {{-1.0f}, { 1.0f}, {0.0f}, {0.0f}, {0.0f}, {-1.0f}, {0.0f}, {0.0f}},
5828 {{ 1.0f}, { 1.0f}, {0.0f}, {0.0f}, {0.0f}, {-1.0f}, {0.0f}, {0.0f}},
5829 {{ 1.0f}, {-1.0f}, {0.0f}, {0.0f}, {0.0f}, {-1.0f}, {0.0f}, {0.0f}},
5831 rotatedquad[] =
5833 {{-10.0f}, {-11.0f}, {11.0f}, {-1.0f}, {0.0f}, {0.0f}, {0.0f}, {0.0f}},
5834 {{-10.0f}, { -9.0f}, {11.0f}, {-1.0f}, {0.0f}, {0.0f}, {0.0f}, {0.0f}},
5835 {{-10.0f}, { -9.0f}, { 9.0f}, {-1.0f}, {0.0f}, {0.0f}, {0.0f}, {0.0f}},
5836 {{-10.0f}, {-11.0f}, { 9.0f}, {-1.0f}, {0.0f}, {0.0f}, {0.0f}, {0.0f}},
5838 translatedquad[] =
5840 {{-11.0f}, {-11.0f}, {-10.0f}, {0.0f}, {0.0f}, {-1.0f}, {0.0f}, {0.0f}},
5841 {{-11.0f}, { -9.0f}, {-10.0f}, {0.0f}, {0.0f}, {-1.0f}, {0.0f}, {0.0f}},
5842 {{ -9.0f}, { -9.0f}, {-10.0f}, {0.0f}, {0.0f}, {-1.0f}, {0.0f}, {0.0f}},
5843 {{ -9.0f}, {-11.0f}, {-10.0f}, {0.0f}, {0.0f}, {-1.0f}, {0.0f}, {0.0f}},
5845 static const struct
5847 D3DMATRIX *world_matrix;
5848 void *quad;
5849 DWORD expected;
5850 const char *message;
5852 tests[] =
5854 {&mat, nquad, 0x000000ff, "Lit quad with light"},
5855 {&mat_singular, nquad, 0x000000b4, "Lit quad with singular world matrix"},
5856 {&mat_transf, rotatedquad, 0x000000ff, "Lit quad with transformation matrix"},
5857 {&mat_nonaffine, translatedquad, 0x000000ff, "Lit quad with non-affine matrix"},
5860 HWND window;
5861 IDirect3D *d3d;
5862 IDirect3DDevice *device;
5863 IDirectDraw *ddraw;
5864 IDirectDrawSurface *rt;
5865 IDirect3DViewport *viewport;
5866 IDirect3DMaterial *material;
5867 IDirect3DLight *light;
5868 IDirect3DExecuteBuffer *execute_buffer;
5869 D3DEXECUTEBUFFERDESC exec_desc;
5870 D3DMATERIALHANDLE mat_handle;
5871 D3DMATRIXHANDLE world_handle, view_handle, proj_handle;
5872 D3DLIGHT light_desc;
5873 HRESULT hr;
5874 D3DCOLOR color;
5875 void *ptr;
5876 UINT inst_length;
5877 ULONG refcount;
5878 unsigned int i;
5880 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5881 0, 0, 640, 480, 0, 0, 0, 0);
5882 ddraw = create_ddraw();
5883 ok(!!ddraw, "Failed to create a ddraw object.\n");
5884 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
5886 skip("Failed to create a 3D device, skipping test.\n");
5887 IDirectDraw_Release(ddraw);
5888 DestroyWindow(window);
5889 return;
5892 hr = IDirect3DDevice_GetDirect3D(device, &d3d);
5893 ok(SUCCEEDED(hr), "Failed to get D3D interface, hr %#x.\n", hr);
5895 hr = IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&rt);
5896 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
5898 viewport = create_viewport(device, 0, 0, 640, 480);
5899 material = create_diffuse_material(device, 1.0f, 1.0f, 1.0f, 1.0f);
5900 viewport_set_background(device, viewport, material);
5902 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
5903 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
5905 hr = IDirect3DDevice_CreateMatrix(device, &world_handle);
5906 ok(hr == D3D_OK, "Creating a matrix object failed, hr %#x.\n", hr);
5907 hr = IDirect3DDevice_SetMatrix(device, world_handle, &mat);
5908 ok(hr == D3D_OK, "Setting a matrix object failed, hr %#x.\n", hr);
5909 hr = IDirect3DDevice_CreateMatrix(device, &view_handle);
5910 ok(hr == D3D_OK, "Creating a matrix object failed, hr %#x.\n", hr);
5911 hr = IDirect3DDevice_SetMatrix(device, view_handle, &mat);
5912 ok(hr == D3D_OK, "Setting a matrix object failed, hr %#x.\n", hr);
5913 hr = IDirect3DDevice_CreateMatrix(device, &proj_handle);
5914 ok(hr == D3D_OK, "Creating a matrix object failed, hr %#x.\n", hr);
5915 hr = IDirect3DDevice_SetMatrix(device, proj_handle, &mat);
5916 ok(hr == D3D_OK, "Setting a matrix object failed, hr %#x.\n", hr);
5918 memset(&exec_desc, 0, sizeof(exec_desc));
5919 exec_desc.dwSize = sizeof(exec_desc);
5920 exec_desc.dwFlags = D3DDEB_BUFSIZE | D3DDEB_CAPS;
5921 exec_desc.dwBufferSize = 1024;
5922 exec_desc.dwCaps = D3DDEBCAPS_SYSTEMMEMORY;
5924 hr = IDirect3DDevice_CreateExecuteBuffer(device, &exec_desc, &execute_buffer, NULL);
5925 ok(SUCCEEDED(hr), "Failed to create execute buffer, hr %#x.\n", hr);
5927 hr = IDirect3DExecuteBuffer_Lock(execute_buffer, &exec_desc);
5928 ok(SUCCEEDED(hr), "Failed to lock execute buffer, hr %#x.\n", hr);
5930 memcpy(exec_desc.lpData, unlitquad, sizeof(unlitquad));
5931 ptr = ((BYTE *)exec_desc.lpData) + sizeof(unlitquad);
5932 emit_set_ts(&ptr, D3DTRANSFORMSTATE_WORLD, world_handle);
5933 emit_set_ts(&ptr, D3DTRANSFORMSTATE_VIEW, view_handle);
5934 emit_set_ts(&ptr, D3DTRANSFORMSTATE_PROJECTION, proj_handle);
5935 emit_set_rs(&ptr, D3DRENDERSTATE_CLIPPING, FALSE);
5936 emit_set_rs(&ptr, D3DRENDERSTATE_ZENABLE, FALSE);
5937 emit_set_rs(&ptr, D3DRENDERSTATE_FOGENABLE, FALSE);
5938 emit_set_rs(&ptr, D3DRENDERSTATE_CULLMODE, D3DCULL_NONE);
5939 emit_process_vertices(&ptr, D3DPROCESSVERTICES_TRANSFORM, 0, 4);
5940 emit_tquad_tlist(&ptr, 0);
5941 emit_end(&ptr);
5942 inst_length = (BYTE *)ptr - (BYTE *)exec_desc.lpData;
5943 inst_length -= sizeof(unlitquad);
5945 hr = IDirect3DExecuteBuffer_Unlock(execute_buffer);
5946 ok(SUCCEEDED(hr), "Failed to unlock execute buffer, hr %#x.\n", hr);
5948 hr = IDirect3DDevice_BeginScene(device);
5949 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
5951 set_execute_data(execute_buffer, 4, sizeof(unlitquad), inst_length);
5952 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
5953 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
5955 hr = IDirect3DExecuteBuffer_Lock(execute_buffer, &exec_desc);
5956 ok(SUCCEEDED(hr), "Failed to lock execute buffer, hr %#x.\n", hr);
5958 memcpy(exec_desc.lpData, litquad, sizeof(litquad));
5959 ptr = ((BYTE *)exec_desc.lpData) + sizeof(litquad);
5960 emit_process_vertices(&ptr, D3DPROCESSVERTICES_TRANSFORM, 0, 4);
5961 emit_tquad_tlist(&ptr, 0);
5962 emit_end(&ptr);
5963 inst_length = (BYTE *)ptr - (BYTE *)exec_desc.lpData;
5964 inst_length -= sizeof(litquad);
5966 hr = IDirect3DExecuteBuffer_Unlock(execute_buffer);
5967 ok(SUCCEEDED(hr), "Failed to unlock execute buffer, hr %#x.\n", hr);
5969 set_execute_data(execute_buffer, 4, sizeof(litquad), inst_length);
5970 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
5971 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
5973 hr = IDirect3DExecuteBuffer_Lock(execute_buffer, &exec_desc);
5974 ok(SUCCEEDED(hr), "Failed to lock execute buffer, hr %#x.\n", hr);
5976 memcpy(exec_desc.lpData, unlitnquad, sizeof(unlitnquad));
5977 ptr = ((BYTE *)exec_desc.lpData) + sizeof(unlitnquad);
5978 emit_process_vertices(&ptr, D3DPROCESSVERTICES_TRANSFORMLIGHT, 0, 4);
5979 emit_tquad_tlist(&ptr, 0);
5980 emit_end(&ptr);
5981 inst_length = (BYTE *)ptr - (BYTE *)exec_desc.lpData;
5982 inst_length -= sizeof(unlitnquad);
5984 hr = IDirect3DExecuteBuffer_Unlock(execute_buffer);
5985 ok(SUCCEEDED(hr), "Failed to unlock execute buffer, hr %#x.\n", hr);
5987 set_execute_data(execute_buffer, 4, sizeof(unlitnquad), inst_length);
5988 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
5989 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
5991 hr = IDirect3DExecuteBuffer_Lock(execute_buffer, &exec_desc);
5992 ok(SUCCEEDED(hr), "Failed to lock execute buffer, hr %#x.\n", hr);
5994 memcpy(exec_desc.lpData, litnquad, sizeof(litnquad));
5995 ptr = ((BYTE *)exec_desc.lpData) + sizeof(litnquad);
5996 emit_process_vertices(&ptr, D3DPROCESSVERTICES_TRANSFORMLIGHT, 0, 4);
5997 emit_tquad_tlist(&ptr, 0);
5998 emit_end(&ptr);
5999 inst_length = (BYTE *)ptr - (BYTE *)exec_desc.lpData;
6000 inst_length -= sizeof(litnquad);
6002 hr = IDirect3DExecuteBuffer_Unlock(execute_buffer);
6003 ok(SUCCEEDED(hr), "Failed to unlock execute buffer, hr %#x.\n", hr);
6005 set_execute_data(execute_buffer, 4, sizeof(litnquad), inst_length);
6006 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
6007 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
6009 hr = IDirect3DDevice_EndScene(device);
6010 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
6012 color = get_surface_color(rt, 160, 360);
6013 ok(color == 0x00ff0000, "Unlit quad without normals has color 0x%08x.\n", color);
6014 color = get_surface_color(rt, 160, 120);
6015 ok(color == 0x0000ff00, "Lit quad without normals has color 0x%08x.\n", color);
6016 color = get_surface_color(rt, 480, 360);
6017 ok(color == 0x00ffffff, "Unlit quad with normals has color 0x%08x.\n", color);
6018 color = get_surface_color(rt, 480, 120);
6019 ok(color == 0x00ffffff, "Lit quad with normals has color 0x%08x.\n", color);
6021 hr = IDirect3DMaterial_GetHandle(material, device, &mat_handle);
6022 ok(SUCCEEDED(hr), "Failed to get material handle, hr %#x.\n", hr);
6024 hr = IDirect3D_CreateLight(d3d, &light, NULL);
6025 ok(SUCCEEDED(hr), "Failed to create a light object, hr %#x.\n", hr);
6026 memset(&light_desc, 0, sizeof(light_desc));
6027 light_desc.dwSize = sizeof(light_desc);
6028 light_desc.dltType = D3DLIGHT_DIRECTIONAL;
6029 U1(light_desc.dcvColor).r = 0.0f;
6030 U2(light_desc.dcvColor).g = 0.0f;
6031 U3(light_desc.dcvColor).b = 1.0f;
6032 U4(light_desc.dcvColor).a = 1.0f;
6033 U3(light_desc.dvDirection).z = 1.0f;
6034 hr = IDirect3DLight_SetLight(light, &light_desc);
6035 ok(SUCCEEDED(hr), "Failed to set light, hr %#x.\n", hr);
6036 hr = IDirect3DViewport_AddLight(viewport, light);
6037 ok(SUCCEEDED(hr), "Failed to add a light to the viewport, hr %#x.\n", hr);
6039 for (i = 0; i < sizeof(tests) / sizeof(tests[0]); ++i)
6041 hr = IDirect3DDevice_SetMatrix(device, world_handle, tests[i].world_matrix);
6042 ok(hr == D3D_OK, "Setting a matrix object failed, hr %#x.\n", hr);
6044 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
6045 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
6047 hr = IDirect3DDevice_BeginScene(device);
6048 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
6050 hr = IDirect3DExecuteBuffer_Lock(execute_buffer, &exec_desc);
6051 ok(SUCCEEDED(hr), "Failed to lock execute buffer, hr %#x.\n", hr);
6053 memcpy(exec_desc.lpData, tests[i].quad, sizeof(nquad));
6054 ptr = ((BYTE *)exec_desc.lpData) + sizeof(nquad);
6055 emit_set_ls(&ptr, D3DLIGHTSTATE_MATERIAL, mat_handle);
6056 emit_process_vertices(&ptr, D3DPROCESSVERTICES_TRANSFORMLIGHT, 0, 4);
6057 emit_tquad_tlist(&ptr, 0);
6058 emit_end(&ptr);
6059 inst_length = (BYTE *)ptr - (BYTE *)exec_desc.lpData;
6060 inst_length -= sizeof(nquad);
6062 hr = IDirect3DExecuteBuffer_Unlock(execute_buffer);
6063 ok(SUCCEEDED(hr), "Failed to unlock execute buffer, hr %#x.\n", hr);
6065 set_execute_data(execute_buffer, 4, sizeof(nquad), inst_length);
6066 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
6067 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
6069 hr = IDirect3DDevice_EndScene(device);
6070 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
6072 color = get_surface_color(rt, 320, 240);
6073 todo_wine ok(color == tests[i].expected, "%s has color 0x%08x.\n", tests[i].message, color);
6076 IDirect3DExecuteBuffer_Release(execute_buffer);
6077 IDirect3DDevice_DeleteMatrix(device, world_handle);
6078 IDirect3DDevice_DeleteMatrix(device, view_handle);
6079 IDirect3DDevice_DeleteMatrix(device, proj_handle);
6080 hr = IDirect3DViewport_DeleteLight(viewport, light);
6081 ok(SUCCEEDED(hr), "Failed to remove a light from the viewport, hr %#x.\n", hr);
6082 IDirect3DLight_Release(light);
6083 destroy_material(material);
6084 destroy_viewport(device, viewport);
6085 IDirectDrawSurface_Release(rt);
6086 refcount = IDirect3DDevice_Release(device);
6087 ok(!refcount, "Device has %u references left.\n", refcount);
6088 IDirect3D_Release(d3d);
6089 refcount = IDirectDraw_Release(ddraw);
6090 ok(!refcount, "Ddraw object has %u references left.\n", refcount);
6091 DestroyWindow(window);
6094 static void test_palette_gdi(void)
6096 IDirectDrawSurface *surface, *primary;
6097 DDSURFACEDESC surface_desc;
6098 IDirectDraw *ddraw;
6099 IDirectDrawPalette *palette, *palette2;
6100 ULONG refcount;
6101 HWND window;
6102 HRESULT hr;
6103 PALETTEENTRY palette_entries[256];
6104 UINT i;
6105 HDC dc;
6106 DDBLTFX fx;
6107 RECT r;
6108 COLORREF color;
6109 /* On the Windows 8 testbot palette index 0 of the onscreen palette is forced to
6110 * r = 0, g = 0, b = 0. Do not attempt to set it to something else as this is
6111 * not the point of this test. */
6112 static const RGBQUAD expected1[] =
6114 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
6115 {0x03, 0x00, 0x00, 0x00}, {0x15, 0x14, 0x13, 0x00},
6117 static const RGBQUAD expected2[] =
6119 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
6120 {0x03, 0x00, 0x00, 0x00}, {0x25, 0x24, 0x23, 0x00},
6122 static const RGBQUAD expected3[] =
6124 {0x00, 0x00, 0x00, 0x00}, {0x40, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x40, 0x00},
6125 {0x00, 0x40, 0x00, 0x00}, {0x56, 0x34, 0x12, 0x00},
6127 HPALETTE ddraw_palette_handle;
6128 /* Similar to index 0, index 255 is r = 0xff, g = 0xff, b = 0xff on the Win8 VMs. */
6129 RGBQUAD rgbquad[255];
6130 static const RGBQUAD rgb_zero = {0, 0, 0, 0};
6132 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
6133 0, 0, 640, 480, 0, 0, 0, 0);
6134 ddraw = create_ddraw();
6135 ok(!!ddraw, "Failed to create a ddraw object.\n");
6136 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6137 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6139 memset(&surface_desc, 0, sizeof(surface_desc));
6140 surface_desc.dwSize = sizeof(surface_desc);
6141 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
6142 surface_desc.dwWidth = 16;
6143 surface_desc.dwHeight = 16;
6144 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
6145 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
6146 surface_desc.ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
6147 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount = 8;
6148 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
6149 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6151 /* Avoid colors from the Windows default palette. */
6152 memset(palette_entries, 0, sizeof(palette_entries));
6153 palette_entries[1].peRed = 0x01;
6154 palette_entries[2].peGreen = 0x02;
6155 palette_entries[3].peBlue = 0x03;
6156 palette_entries[4].peRed = 0x13;
6157 palette_entries[4].peGreen = 0x14;
6158 palette_entries[4].peBlue = 0x15;
6159 hr = IDirectDraw_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
6160 palette_entries, &palette, NULL);
6161 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
6163 /* If there is no palette assigned and the display mode is not 8 bpp, some
6164 * drivers refuse to create a DC while others allow it. If a DC is created,
6165 * the DIB color table is uninitialized and contains random colors. No error
6166 * is generated when trying to read pixels and random garbage is returned.
6168 * The most likely explanation is that if the driver creates a DC, it (or
6169 * the higher-level runtime) uses GetSystemPaletteEntries to find the
6170 * palette, but GetSystemPaletteEntries fails when bpp > 8 and the palette
6171 * contains uninitialized garbage. See comments below for the P8 case. */
6173 hr = IDirectDrawSurface_SetPalette(surface, palette);
6174 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
6175 hr = IDirectDrawSurface_GetDC(surface, &dc);
6176 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
6177 ddraw_palette_handle = SelectPalette(dc, GetStockObject(DEFAULT_PALETTE), FALSE);
6178 ok(ddraw_palette_handle == GetStockObject(DEFAULT_PALETTE),
6179 "Got unexpected palette %p, expected %p.\n",
6180 ddraw_palette_handle, GetStockObject(DEFAULT_PALETTE));
6182 i = GetDIBColorTable(dc, 0, sizeof(rgbquad) / sizeof(*rgbquad), rgbquad);
6183 ok(i == sizeof(rgbquad) / sizeof(*rgbquad), "Expected count 255, got %u.\n", i);
6184 for (i = 0; i < sizeof(expected1) / sizeof(*expected1); i++)
6186 ok(!memcmp(&rgbquad[i], &expected1[i], sizeof(rgbquad[i])),
6187 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
6188 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
6189 expected1[i].rgbRed, expected1[i].rgbGreen, expected1[i].rgbBlue);
6191 for (; i < sizeof(rgbquad) / sizeof(*rgbquad); i++)
6193 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
6194 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
6195 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
6198 /* Update the palette while the DC is in use. This does not modify the DC. */
6199 palette_entries[4].peRed = 0x23;
6200 palette_entries[4].peGreen = 0x24;
6201 palette_entries[4].peBlue = 0x25;
6202 hr = IDirectDrawPalette_SetEntries(palette, 0, 4, 1, &palette_entries[4]);
6203 ok(SUCCEEDED(hr), "Failed to set palette entries, hr %#x.\n", hr);
6205 i = GetDIBColorTable(dc, 4, 1, &rgbquad[4]);
6206 ok(i == 1, "Expected count 1, got %u.\n", i);
6207 ok(!memcmp(&rgbquad[4], &expected1[4], sizeof(rgbquad[4])),
6208 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
6209 i, rgbquad[4].rgbRed, rgbquad[4].rgbGreen, rgbquad[4].rgbBlue,
6210 expected1[4].rgbRed, expected1[4].rgbGreen, expected1[4].rgbBlue);
6212 /* Neither does re-setting the palette. */
6213 hr = IDirectDrawSurface_SetPalette(surface, NULL);
6214 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
6215 hr = IDirectDrawSurface_SetPalette(surface, palette);
6216 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
6218 i = GetDIBColorTable(dc, 4, 1, &rgbquad[4]);
6219 ok(i == 1, "Expected count 1, got %u.\n", i);
6220 ok(!memcmp(&rgbquad[4], &expected1[4], sizeof(rgbquad[4])),
6221 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
6222 i, rgbquad[4].rgbRed, rgbquad[4].rgbGreen, rgbquad[4].rgbBlue,
6223 expected1[4].rgbRed, expected1[4].rgbGreen, expected1[4].rgbBlue);
6225 hr = IDirectDrawSurface_ReleaseDC(surface, dc);
6226 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
6228 /* Refresh the DC. This updates the palette. */
6229 hr = IDirectDrawSurface_GetDC(surface, &dc);
6230 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
6231 i = GetDIBColorTable(dc, 0, sizeof(rgbquad) / sizeof(*rgbquad), rgbquad);
6232 ok(i == sizeof(rgbquad) / sizeof(*rgbquad), "Expected count 255, got %u.\n", i);
6233 for (i = 0; i < sizeof(expected2) / sizeof(*expected2); i++)
6235 ok(!memcmp(&rgbquad[i], &expected2[i], sizeof(rgbquad[i])),
6236 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
6237 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
6238 expected2[i].rgbRed, expected2[i].rgbGreen, expected2[i].rgbBlue);
6240 for (; i < sizeof(rgbquad) / sizeof(*rgbquad); i++)
6242 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
6243 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
6244 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
6246 hr = IDirectDrawSurface_ReleaseDC(surface, dc);
6247 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
6249 refcount = IDirectDrawSurface_Release(surface);
6250 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6252 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
6253 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6254 if (FAILED(IDirectDraw_SetDisplayMode(ddraw, 640, 480, 8)))
6256 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
6257 IDirectDrawPalette_Release(palette);
6258 IDirectDraw_Release(ddraw);
6259 DestroyWindow(window);
6260 return;
6262 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
6264 memset(&surface_desc, 0, sizeof(surface_desc));
6265 surface_desc.dwSize = sizeof(surface_desc);
6266 surface_desc.dwFlags = DDSD_CAPS;
6267 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
6268 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &primary, NULL);
6269 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6271 memset(&fx, 0, sizeof(fx));
6272 fx.dwSize = sizeof(fx);
6273 U5(fx).dwFillColor = 3;
6274 SetRect(&r, 0, 0, 319, 479);
6275 hr = IDirectDrawSurface_Blt(primary, &r, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
6276 ok(SUCCEEDED(hr), "Failed to clear surface, hr %#x.\n", hr);
6277 SetRect(&r, 320, 0, 639, 479);
6278 U5(fx).dwFillColor = 4;
6279 hr = IDirectDrawSurface_Blt(primary, &r, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
6280 ok(SUCCEEDED(hr), "Failed to clear surface, hr %#x.\n", hr);
6282 hr = IDirectDrawSurface_SetPalette(primary, palette);
6283 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
6284 hr = IDirectDrawSurface_GetDC(primary, &dc);
6285 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
6287 color = GetPixel(dc, 160, 240);
6288 ok(color == 0x00030000, "Clear index 3: Got unexpected color 0x%08x.\n", color);
6289 color = GetPixel(dc, 480, 240);
6290 ok(color == 0x00252423, "Clear index 4: Got unexpected color 0x%08x.\n", color);
6292 ddraw_palette_handle = SelectPalette(dc, GetStockObject(DEFAULT_PALETTE), FALSE);
6293 ok(ddraw_palette_handle == GetStockObject(DEFAULT_PALETTE),
6294 "Got unexpected palette %p, expected %p.\n",
6295 ddraw_palette_handle, GetStockObject(DEFAULT_PALETTE));
6296 SelectPalette(dc, ddraw_palette_handle, FALSE);
6298 /* The primary uses the system palette. In exclusive mode, the system palette matches
6299 * the ddraw palette attached to the primary, so the result is what you would expect
6300 * from a regular surface. Tests for the interaction between the ddraw palette and
6301 * the system palette are not included pending an application that depends on this.
6302 * The relation between those causes problems on Windows Vista and newer for games
6303 * like Age of Empires or StarCraft. Don't emulate it without a real need. */
6304 i = GetDIBColorTable(dc, 0, sizeof(rgbquad) / sizeof(*rgbquad), rgbquad);
6305 ok(i == sizeof(rgbquad) / sizeof(*rgbquad), "Expected count 255, got %u.\n", i);
6306 for (i = 0; i < sizeof(expected2) / sizeof(*expected2); i++)
6308 ok(!memcmp(&rgbquad[i], &expected2[i], sizeof(rgbquad[i])),
6309 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
6310 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
6311 expected2[i].rgbRed, expected2[i].rgbGreen, expected2[i].rgbBlue);
6313 for (; i < sizeof(rgbquad) / sizeof(*rgbquad); i++)
6315 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
6316 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
6317 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
6319 hr = IDirectDrawSurface_ReleaseDC(primary, dc);
6320 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
6322 memset(&surface_desc, 0, sizeof(surface_desc));
6323 surface_desc.dwSize = sizeof(surface_desc);
6324 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
6325 surface_desc.dwWidth = 16;
6326 surface_desc.dwHeight = 16;
6327 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
6328 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
6329 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6331 /* Here the offscreen surface appears to use the primary's palette,
6332 * but in all likelihood it is actually the system palette. */
6333 hr = IDirectDrawSurface_GetDC(surface, &dc);
6334 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
6335 i = GetDIBColorTable(dc, 0, sizeof(rgbquad) / sizeof(*rgbquad), rgbquad);
6336 ok(i == sizeof(rgbquad) / sizeof(*rgbquad), "Expected count 255, got %u.\n", i);
6337 for (i = 0; i < sizeof(expected2) / sizeof(*expected2); i++)
6339 ok(!memcmp(&rgbquad[i], &expected2[i], sizeof(rgbquad[i])),
6340 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
6341 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
6342 expected2[i].rgbRed, expected2[i].rgbGreen, expected2[i].rgbBlue);
6344 for (; i < sizeof(rgbquad) / sizeof(*rgbquad); i++)
6346 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
6347 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
6348 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
6350 hr = IDirectDrawSurface_ReleaseDC(surface, dc);
6351 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
6353 /* On real hardware a change to the primary surface's palette applies immediately,
6354 * even on device contexts from offscreen surfaces that do not have their own
6355 * palette. On the testbot VMs this is not the case. Don't test this until we
6356 * know of an application that depends on this. */
6358 memset(palette_entries, 0, sizeof(palette_entries));
6359 palette_entries[1].peBlue = 0x40;
6360 palette_entries[2].peRed = 0x40;
6361 palette_entries[3].peGreen = 0x40;
6362 palette_entries[4].peRed = 0x12;
6363 palette_entries[4].peGreen = 0x34;
6364 palette_entries[4].peBlue = 0x56;
6365 hr = IDirectDraw_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
6366 palette_entries, &palette2, NULL);
6367 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
6368 hr = IDirectDrawSurface_SetPalette(surface, palette2);
6369 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
6371 /* A palette assigned to the offscreen surface overrides the primary / system
6372 * palette. */
6373 hr = IDirectDrawSurface_GetDC(surface, &dc);
6374 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
6375 i = GetDIBColorTable(dc, 0, sizeof(rgbquad) / sizeof(*rgbquad), rgbquad);
6376 ok(i == sizeof(rgbquad) / sizeof(*rgbquad), "Expected count 255, got %u.\n", i);
6377 for (i = 0; i < sizeof(expected3) / sizeof(*expected3); i++)
6379 ok(!memcmp(&rgbquad[i], &expected3[i], sizeof(rgbquad[i])),
6380 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
6381 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
6382 expected3[i].rgbRed, expected3[i].rgbGreen, expected3[i].rgbBlue);
6384 for (; i < sizeof(rgbquad) / sizeof(*rgbquad); i++)
6386 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
6387 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
6388 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
6390 hr = IDirectDrawSurface_ReleaseDC(surface, dc);
6391 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
6393 refcount = IDirectDrawSurface_Release(surface);
6394 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6396 /* The Windows 8 testbot keeps extra references to the primary and
6397 * backbuffer while in 8 bpp mode. */
6398 hr = IDirectDraw_RestoreDisplayMode(ddraw);
6399 ok(SUCCEEDED(hr), "Failed to restore display mode, hr %#x.\n", hr);
6401 refcount = IDirectDrawSurface_Release(primary);
6402 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6403 refcount = IDirectDrawPalette_Release(palette2);
6404 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6405 refcount = IDirectDrawPalette_Release(palette);
6406 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6407 refcount = IDirectDraw_Release(ddraw);
6408 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6409 DestroyWindow(window);
6412 static void test_palette_alpha(void)
6414 IDirectDrawSurface *surface;
6415 DDSURFACEDESC surface_desc;
6416 IDirectDraw *ddraw;
6417 IDirectDrawPalette *palette;
6418 ULONG refcount;
6419 HWND window;
6420 HRESULT hr;
6421 PALETTEENTRY palette_entries[256];
6422 unsigned int i;
6423 static const struct
6425 DWORD caps, flags;
6426 BOOL attach_allowed;
6427 const char *name;
6429 test_data[] =
6431 {DDSCAPS_OFFSCREENPLAIN, DDSD_WIDTH | DDSD_HEIGHT, FALSE, "offscreenplain"},
6432 {DDSCAPS_TEXTURE, DDSD_WIDTH | DDSD_HEIGHT, TRUE, "texture"},
6433 {DDSCAPS_PRIMARYSURFACE, 0, FALSE, "primary"}
6436 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
6437 0, 0, 640, 480, 0, 0, 0, 0);
6438 ddraw = create_ddraw();
6439 ok(!!ddraw, "Failed to create a ddraw object.\n");
6440 if (FAILED(IDirectDraw_SetDisplayMode(ddraw, 640, 480, 8)))
6442 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
6443 IDirectDraw_Release(ddraw);
6444 DestroyWindow(window);
6445 return;
6447 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
6448 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6450 memset(palette_entries, 0, sizeof(palette_entries));
6451 palette_entries[1].peFlags = 0x42;
6452 palette_entries[2].peFlags = 0xff;
6453 palette_entries[3].peFlags = 0x80;
6454 hr = IDirectDraw_CreatePalette(ddraw, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, palette_entries, &palette, NULL);
6455 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
6457 memset(palette_entries, 0x66, sizeof(palette_entries));
6458 hr = IDirectDrawPalette_GetEntries(palette, 0, 1, 4, palette_entries);
6459 ok(SUCCEEDED(hr), "Failed to get palette entries, hr %#x.\n", hr);
6460 ok(palette_entries[0].peFlags == 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
6461 palette_entries[0].peFlags);
6462 ok(palette_entries[1].peFlags == 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
6463 palette_entries[1].peFlags);
6464 ok(palette_entries[2].peFlags == 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
6465 palette_entries[2].peFlags);
6466 ok(palette_entries[3].peFlags == 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
6467 palette_entries[3].peFlags);
6469 IDirectDrawPalette_Release(palette);
6471 memset(palette_entries, 0, sizeof(palette_entries));
6472 palette_entries[1].peFlags = 0x42;
6473 palette_entries[1].peRed = 0xff;
6474 palette_entries[2].peFlags = 0xff;
6475 palette_entries[3].peFlags = 0x80;
6476 hr = IDirectDraw_CreatePalette(ddraw, DDPCAPS_ALLOW256 | DDPCAPS_8BIT | DDPCAPS_ALPHA,
6477 palette_entries, &palette, NULL);
6478 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
6480 memset(palette_entries, 0x66, sizeof(palette_entries));
6481 hr = IDirectDrawPalette_GetEntries(palette, 0, 1, 4, palette_entries);
6482 ok(SUCCEEDED(hr), "Failed to get palette entries, hr %#x.\n", hr);
6483 ok(palette_entries[0].peFlags == 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
6484 palette_entries[0].peFlags);
6485 ok(palette_entries[1].peFlags == 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
6486 palette_entries[1].peFlags);
6487 ok(palette_entries[2].peFlags == 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
6488 palette_entries[2].peFlags);
6489 ok(palette_entries[3].peFlags == 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
6490 palette_entries[3].peFlags);
6492 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); i++)
6494 memset(&surface_desc, 0, sizeof(surface_desc));
6495 surface_desc.dwSize = sizeof(surface_desc);
6496 surface_desc.dwFlags = DDSD_CAPS | test_data[i].flags;
6497 surface_desc.dwWidth = 128;
6498 surface_desc.dwHeight = 128;
6499 surface_desc.ddsCaps.dwCaps = test_data[i].caps;
6500 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
6501 ok(SUCCEEDED(hr), "Failed to create %s surface, hr %#x.\n", test_data[i].name, hr);
6503 hr = IDirectDrawSurface_SetPalette(surface, palette);
6504 if (test_data[i].attach_allowed)
6505 ok(SUCCEEDED(hr), "Failed to attach palette to %s surface, hr %#x.\n", test_data[i].name, hr);
6506 else
6507 ok(hr == DDERR_INVALIDSURFACETYPE, "Got unexpected hr %#x, %s surface.\n", hr, test_data[i].name);
6509 if (SUCCEEDED(hr))
6511 HDC dc;
6512 RGBQUAD rgbquad;
6513 UINT retval;
6515 hr = IDirectDrawSurface_GetDC(surface, &dc);
6516 ok(SUCCEEDED(hr) || broken(hr == DDERR_CANTCREATEDC) /* Win2k testbot */,
6517 "Failed to get DC, hr %#x, %s surface.\n", hr, test_data[i].name);
6518 if (SUCCEEDED(hr))
6520 retval = GetDIBColorTable(dc, 1, 1, &rgbquad);
6521 ok(retval == 1, "GetDIBColorTable returned unexpected result %u.\n", retval);
6522 ok(rgbquad.rgbRed == 0xff, "Expected rgbRed = 0xff, got %#x, %s surface.\n",
6523 rgbquad.rgbRed, test_data[i].name);
6524 ok(rgbquad.rgbGreen == 0, "Expected rgbGreen = 0, got %#x, %s surface.\n",
6525 rgbquad.rgbGreen, test_data[i].name);
6526 ok(rgbquad.rgbBlue == 0, "Expected rgbBlue = 0, got %#x, %s surface.\n",
6527 rgbquad.rgbBlue, test_data[i].name);
6528 ok(rgbquad.rgbReserved == 0, "Expected rgbReserved = 0, got %u, %s surface.\n",
6529 rgbquad.rgbReserved, test_data[i].name);
6530 hr = IDirectDrawSurface_ReleaseDC(surface, dc);
6531 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
6534 IDirectDrawSurface_Release(surface);
6537 /* Test INVALIDSURFACETYPE vs INVALIDPIXELFORMAT. */
6538 memset(&surface_desc, 0, sizeof(surface_desc));
6539 surface_desc.dwSize = sizeof(surface_desc);
6540 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
6541 surface_desc.dwWidth = 128;
6542 surface_desc.dwHeight = 128;
6543 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
6544 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
6545 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB;
6546 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount = 32;
6547 U2(surface_desc.ddpfPixelFormat).dwRBitMask = 0x00ff0000;
6548 U3(surface_desc.ddpfPixelFormat).dwGBitMask = 0x0000ff00;
6549 U4(surface_desc.ddpfPixelFormat).dwBBitMask = 0x000000ff;
6550 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
6551 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6552 hr = IDirectDrawSurface_SetPalette(surface, palette);
6553 ok(hr == DDERR_INVALIDSURFACETYPE, "Got unexpected hr %#x.\n", hr);
6554 IDirectDrawSurface_Release(surface);
6556 /* The Windows 8 testbot keeps extra references to the primary
6557 * while in 8 bpp mode. */
6558 hr = IDirectDraw_RestoreDisplayMode(ddraw);
6559 ok(SUCCEEDED(hr), "Failed to restore display mode, hr %#x.\n", hr);
6561 refcount = IDirectDrawPalette_Release(palette);
6562 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6563 refcount = IDirectDraw_Release(ddraw);
6564 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6565 DestroyWindow(window);
6568 static void test_lost_device(void)
6570 IDirectDrawSurface *surface;
6571 DDSURFACEDESC surface_desc;
6572 HWND window1, window2;
6573 IDirectDraw *ddraw;
6574 ULONG refcount;
6575 HRESULT hr;
6576 BOOL ret;
6578 window1 = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
6579 0, 0, 640, 480, 0, 0, 0, 0);
6580 window2 = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
6581 0, 0, 640, 480, 0, 0, 0, 0);
6582 ddraw = create_ddraw();
6583 ok(!!ddraw, "Failed to create a ddraw object.\n");
6584 hr = IDirectDraw_SetCooperativeLevel(ddraw, window1, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
6585 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6587 memset(&surface_desc, 0, sizeof(surface_desc));
6588 surface_desc.dwSize = sizeof(surface_desc);
6589 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
6590 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
6591 surface_desc.dwBackBufferCount = 1;
6592 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
6593 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6595 hr = IDirectDrawSurface_IsLost(surface);
6596 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6597 hr = IDirectDrawSurface_Flip(surface, NULL, DDFLIP_WAIT);
6598 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6600 ret = SetForegroundWindow(GetDesktopWindow());
6601 ok(ret, "Failed to set foreground window.\n");
6602 hr = IDirectDrawSurface_IsLost(surface);
6603 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
6604 hr = IDirectDrawSurface_Flip(surface, NULL, DDFLIP_WAIT);
6605 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
6607 ret = SetForegroundWindow(window1);
6608 ok(ret, "Failed to set foreground window.\n");
6609 hr = IDirectDrawSurface_IsLost(surface);
6610 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
6611 hr = IDirectDrawSurface_Flip(surface, NULL, DDFLIP_WAIT);
6612 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
6614 hr = restore_surfaces(ddraw);
6615 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6616 hr = IDirectDrawSurface_IsLost(surface);
6617 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6618 hr = IDirectDrawSurface_Flip(surface, NULL, DDFLIP_WAIT);
6619 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6621 hr = IDirectDraw_SetCooperativeLevel(ddraw, window1, DDSCL_NORMAL);
6622 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6623 hr = IDirectDrawSurface_IsLost(surface);
6624 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6625 hr = IDirectDrawSurface_Flip(surface, NULL, DDFLIP_WAIT);
6626 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
6628 /* Trying to restore the primary will crash, probably because flippable
6629 * surfaces can't exist in DDSCL_NORMAL. */
6630 IDirectDrawSurface_Release(surface);
6631 memset(&surface_desc, 0, sizeof(surface_desc));
6632 surface_desc.dwSize = sizeof(surface_desc);
6633 surface_desc.dwFlags = DDSD_CAPS;
6634 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
6635 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
6636 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6638 hr = IDirectDrawSurface_IsLost(surface);
6639 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6641 ret = SetForegroundWindow(GetDesktopWindow());
6642 ok(ret, "Failed to set foreground window.\n");
6643 hr = IDirectDrawSurface_IsLost(surface);
6644 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6646 ret = SetForegroundWindow(window1);
6647 ok(ret, "Failed to set foreground window.\n");
6648 hr = IDirectDrawSurface_IsLost(surface);
6649 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6651 hr = IDirectDraw_SetCooperativeLevel(ddraw, window1, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
6652 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6653 hr = IDirectDrawSurface_IsLost(surface);
6654 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
6656 hr = restore_surfaces(ddraw);
6657 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6658 hr = IDirectDrawSurface_IsLost(surface);
6659 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6661 IDirectDrawSurface_Release(surface);
6662 memset(&surface_desc, 0, sizeof(surface_desc));
6663 surface_desc.dwSize = sizeof(surface_desc);
6664 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
6665 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
6666 surface_desc.dwBackBufferCount = 1;
6667 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
6668 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6670 hr = IDirectDraw_SetCooperativeLevel(ddraw, window1, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
6671 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6672 hr = IDirectDrawSurface_IsLost(surface);
6673 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6674 hr = IDirectDrawSurface_Flip(surface, NULL, DDFLIP_WAIT);
6675 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6677 hr = IDirectDraw_SetCooperativeLevel(ddraw, window1, DDSCL_NORMAL | DDSCL_FULLSCREEN);
6678 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6679 hr = IDirectDrawSurface_IsLost(surface);
6680 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6681 hr = IDirectDrawSurface_Flip(surface, NULL, DDFLIP_WAIT);
6682 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
6684 hr = IDirectDraw_SetCooperativeLevel(ddraw, window1, DDSCL_NORMAL);
6685 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6686 hr = IDirectDrawSurface_IsLost(surface);
6687 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6688 hr = IDirectDrawSurface_Flip(surface, NULL, DDFLIP_WAIT);
6689 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
6691 hr = IDirectDraw_SetCooperativeLevel(ddraw, window2, DDSCL_NORMAL);
6692 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6693 hr = IDirectDrawSurface_IsLost(surface);
6694 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6695 hr = IDirectDrawSurface_Flip(surface, NULL, DDFLIP_WAIT);
6696 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
6698 hr = IDirectDraw_SetCooperativeLevel(ddraw, window2, DDSCL_NORMAL | DDSCL_FULLSCREEN);
6699 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6700 hr = IDirectDrawSurface_IsLost(surface);
6701 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6702 hr = IDirectDrawSurface_Flip(surface, NULL, DDFLIP_WAIT);
6703 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
6705 hr = IDirectDraw_SetCooperativeLevel(ddraw, window2, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
6706 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6707 hr = IDirectDrawSurface_IsLost(surface);
6708 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
6709 hr = IDirectDrawSurface_Flip(surface, NULL, DDFLIP_WAIT);
6710 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
6712 IDirectDrawSurface_Release(surface);
6713 refcount = IDirectDraw_Release(ddraw);
6714 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6715 DestroyWindow(window2);
6716 DestroyWindow(window1);
6719 static void test_surface_desc_lock(void)
6721 IDirectDrawSurface *surface;
6722 DDSURFACEDESC surface_desc;
6723 IDirectDraw *ddraw;
6724 ULONG refcount;
6725 HWND window;
6726 HRESULT hr;
6728 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
6729 0, 0, 640, 480, 0, 0, 0, 0);
6730 ddraw = create_ddraw();
6731 ok(!!ddraw, "Failed to create a ddraw object.\n");
6732 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6733 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6735 memset(&surface_desc, 0, sizeof(surface_desc));
6736 surface_desc.dwSize = sizeof(surface_desc);
6737 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
6738 surface_desc.dwWidth = 16;
6739 surface_desc.dwHeight = 16;
6740 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
6741 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
6742 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6744 memset(&surface_desc, 0xaa, sizeof(surface_desc));
6745 surface_desc.dwSize = sizeof(surface_desc);
6746 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
6747 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
6748 ok(!surface_desc.lpSurface, "Got unexpected lpSurface %p.\n", surface_desc.lpSurface);
6750 memset(&surface_desc, 0xaa, sizeof(surface_desc));
6751 surface_desc.dwSize = sizeof(surface_desc);
6752 hr = IDirectDrawSurface_Lock(surface, NULL, &surface_desc, 0, NULL);
6753 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
6754 ok(surface_desc.lpSurface != NULL, "Got unexpected lpSurface %p.\n", surface_desc.lpSurface);
6755 memset(&surface_desc, 0xaa, sizeof(surface_desc));
6756 surface_desc.dwSize = sizeof(surface_desc);
6757 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
6758 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
6759 ok(!surface_desc.lpSurface, "Got unexpected lpSurface %p.\n", surface_desc.lpSurface);
6760 hr = IDirectDrawSurface_Unlock(surface, NULL);
6761 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
6763 memset(&surface_desc, 0xaa, sizeof(surface_desc));
6764 surface_desc.dwSize = sizeof(surface_desc);
6765 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
6766 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
6767 ok(!surface_desc.lpSurface, "Got unexpected lpSurface %p.\n", surface_desc.lpSurface);
6769 IDirectDrawSurface_Release(surface);
6770 refcount = IDirectDraw_Release(ddraw);
6771 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6772 DestroyWindow(window);
6775 static void test_texturemapblend(void)
6777 HRESULT hr;
6778 DDSURFACEDESC ddsd;
6779 D3DEXECUTEBUFFERDESC exec_desc;
6780 DDBLTFX fx;
6781 static RECT rect = {0, 0, 64, 128};
6782 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
6783 DDCOLORKEY ckey;
6784 IDirectDrawSurface *surface, *rt;
6785 IDirect3DTexture *texture;
6786 D3DTEXTUREHANDLE texture_handle;
6787 HWND window;
6788 IDirectDraw *ddraw;
6789 IDirect3DDevice *device;
6790 IDirect3DMaterial *material;
6791 IDirect3DViewport *viewport;
6792 IDirect3DExecuteBuffer *execute_buffer;
6793 UINT inst_length;
6794 void *ptr;
6795 ULONG ref;
6796 D3DCOLOR color;
6798 static const D3DTLVERTEX test1_quads[] =
6800 {{0.0f}, {0.0f}, {0.0f}, {1.0f}, {0xffffffff}, {0}, {0.0f}, {0.0f}},
6801 {{0.0f}, {240.0f}, {0.0f}, {1.0f}, {0xffffffff}, {0}, {0.0f}, {1.0f}},
6802 {{640.0f}, {0.0f}, {0.0f}, {1.0f}, {0xffffffff}, {0}, {1.0f}, {0.0f}},
6803 {{640.0f}, {240.0f}, {0.0f}, {1.0f}, {0xffffffff}, {0}, {1.0f}, {1.0f}},
6804 {{0.0f}, {240.0f}, {0.0f}, {1.0f}, {0x80ffffff}, {0}, {0.0f}, {0.0f}},
6805 {{0.0f}, {480.0f}, {0.0f}, {1.0f}, {0x80ffffff}, {0}, {0.0f}, {1.0f}},
6806 {{640.0f}, {240.0f}, {0.0f}, {1.0f}, {0x80ffffff}, {0}, {1.0f}, {0.0f}},
6807 {{640.0f}, {480.0f}, {0.0f}, {1.0f}, {0x80ffffff}, {0}, {1.0f}, {1.0f}},
6809 test2_quads[] =
6811 {{0.0f}, {0.0f}, {0.0f}, {1.0f}, {0x00ff0080}, {0}, {0.0f}, {0.0f}},
6812 {{0.0f}, {240.0f}, {0.0f}, {1.0f}, {0x00ff0080}, {0}, {0.0f}, {1.0f}},
6813 {{640.0f}, {0.0f}, {0.0f}, {1.0f}, {0x00ff0080}, {0}, {1.0f}, {0.0f}},
6814 {{640.0f}, {240.0f}, {0.0f}, {1.0f}, {0x00ff0080}, {0}, {1.0f}, {1.0f}},
6815 {{0.0f}, {240.0f}, {0.0f}, {1.0f}, {0x008000ff}, {0}, {0.0f}, {0.0f}},
6816 {{0.0f}, {480.0f}, {0.0f}, {1.0f}, {0x008000ff}, {0}, {0.0f}, {1.0f}},
6817 {{640.0f}, {240.0f}, {0.0f}, {1.0f}, {0x008000ff}, {0}, {1.0f}, {0.0f}},
6818 {{640.0f}, {480.0f}, {0.0f}, {1.0f}, {0x008000ff}, {0}, {1.0f}, {1.0f}},
6821 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
6822 0, 0, 640, 480, 0, 0, 0, 0);
6823 ddraw = create_ddraw();
6824 ok(!!ddraw, "Failed to create a ddraw object.\n");
6825 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
6827 skip("Failed to create a 3D device, skipping test.\n");
6828 DestroyWindow(window);
6829 IDirectDraw_Release(ddraw);
6830 return;
6833 hr = IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&rt);
6834 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
6836 material = create_diffuse_material(device, 0.0f, 0.0f, 0.0f, 1.0f);
6837 viewport = create_viewport(device, 0, 0, 640, 480);
6838 viewport_set_background(device, viewport, material);
6840 memset(&exec_desc, 0, sizeof(exec_desc));
6841 exec_desc.dwSize = sizeof(exec_desc);
6842 exec_desc.dwFlags = D3DDEB_BUFSIZE | D3DDEB_CAPS;
6843 exec_desc.dwBufferSize = 1024;
6844 exec_desc.dwCaps = D3DDEBCAPS_SYSTEMMEMORY;
6845 hr = IDirect3DDevice_CreateExecuteBuffer(device, &exec_desc, &execute_buffer, NULL);
6846 ok(SUCCEEDED(hr), "Failed to create execute buffer, hr %#x.\n", hr);
6848 /* Test alpha with DDPF_ALPHAPIXELS texture - should be taken from texture alpha channel.
6850 * The vertex alpha is completely ignored in this case, so case 1 and 2 combined are not
6851 * a D3DTOP_MODULATE with texture alpha = 0xff in case 2 (no alpha in texture). */
6852 memset(&ddsd, 0, sizeof(ddsd));
6853 ddsd.dwSize = sizeof(ddsd);
6854 ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
6855 ddsd.dwHeight = 128;
6856 ddsd.dwWidth = 128;
6857 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
6858 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
6859 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
6860 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 32;
6861 U2(ddsd.ddpfPixelFormat).dwRBitMask = 0x00ff0000;
6862 U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x0000ff00;
6863 U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x000000ff;
6864 U5(ddsd.ddpfPixelFormat).dwRGBAlphaBitMask = 0xff000000;
6865 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &surface, NULL);
6866 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6868 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirect3DTexture, (void **)&texture);
6869 ok(SUCCEEDED(hr), "Failed to get texture interface, hr %#x.\n", hr);
6870 hr = IDirect3DTexture_GetHandle(texture, device, &texture_handle);
6871 ok(SUCCEEDED(hr), "Failed to get texture handle, hr %#x.\n", hr);
6873 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
6874 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
6876 memset(&fx, 0, sizeof(fx));
6877 fx.dwSize = sizeof(fx);
6878 U5(fx).dwFillColor = 0xff0000ff;
6879 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
6880 ok(SUCCEEDED(hr), "Failed to clear texture, hr %#x.\n", hr);
6881 U5(fx).dwFillColor = 0x800000ff;
6882 hr = IDirectDrawSurface_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
6883 ok(SUCCEEDED(hr), "Failed to clear texture, hr %#x.\n", hr);
6885 hr = IDirect3DExecuteBuffer_Lock(execute_buffer, &exec_desc);
6886 ok(SUCCEEDED(hr), "Failed to lock execute buffer, hr %#x.\n", hr);
6888 memcpy(exec_desc.lpData, test1_quads, sizeof(test1_quads));
6890 ptr = ((BYTE *)exec_desc.lpData) + sizeof(test1_quads);
6891 emit_process_vertices(&ptr, D3DPROCESSVERTICES_COPY, 0, 8);
6892 emit_set_rs(&ptr, D3DRENDERSTATE_CULLMODE, D3DCULL_NONE);
6893 emit_set_rs(&ptr, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
6894 emit_set_rs(&ptr, D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);
6895 emit_set_rs(&ptr, D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA);
6896 /* The history of D3DRENDERSTATE_ALPHABLENDENABLE is quite a mess. In the
6897 * first D3D release there was a D3DRENDERSTATE_BLENDENABLE (enum value 27).
6898 * D3D5 introduced a new and separate D3DRENDERSTATE_ALPHABLENDENABLE (42)
6899 * together with D3DRENDERSTATE_COLORKEYENABLE (41). The docs aren't all
6900 * that clear but they mention that D3DRENDERSTATE_BLENDENABLE overrides the
6901 * two new states.
6902 * Then D3D6 came and got rid of the new D3DRENDERSTATE_ALPHABLENDENABLE
6903 * state (42), renaming the older D3DRENDERSTATE_BLENDENABLE enum (27)
6904 * as D3DRENDERSTATE_ALPHABLENDENABLE.
6905 * There is a comment in the D3D6 docs which mentions that hardware
6906 * rasterizers always used D3DRENDERSTATE_BLENDENABLE to just toggle alpha
6907 * blending while prior to D3D5 software rasterizers toggled both color
6908 * keying and alpha blending according to it. What I gather is that, from
6909 * D3D6 onwards, D3DRENDERSTATE_ALPHABLENDENABLE always only toggles the
6910 * alpha blending state.
6911 * These tests seem to show that actual, current hardware follows the D3D6
6912 * behavior even when using the original D3D interfaces, for the HAL device
6913 * at least. */
6914 emit_set_rs(&ptr, D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);
6915 emit_set_rs(&ptr, D3DRENDERSTATE_TEXTUREMAPBLEND, D3DTBLEND_MODULATE);
6916 emit_set_rs(&ptr, D3DRENDERSTATE_TEXTUREHANDLE, texture_handle);
6918 emit_tquad(&ptr, 0);
6919 emit_tquad(&ptr, 4);
6920 emit_end(&ptr);
6922 inst_length = (BYTE *)ptr - (BYTE *)exec_desc.lpData;
6923 inst_length -= sizeof(test1_quads);
6924 hr = IDirect3DExecuteBuffer_Unlock(execute_buffer);
6925 ok(SUCCEEDED(hr), "Failed to unlock execute buffer, hr %#x.\n", hr);
6926 set_execute_data(execute_buffer, 8, sizeof(test1_quads), inst_length);
6928 hr = IDirect3DDevice_BeginScene(device);
6929 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
6930 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_UNCLIPPED);
6931 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
6932 hr = IDirect3DDevice_EndScene(device);
6933 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
6935 color = get_surface_color(rt, 5, 5);
6936 ok(compare_color(color, 0x00000080, 2), "Got unexpected color 0x%08x.\n", color);
6937 color = get_surface_color(rt, 400, 5);
6938 ok(compare_color(color, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color);
6939 color = get_surface_color(rt, 5, 245);
6940 ok(compare_color(color, 0x00000080, 2), "Got unexpected color 0x%08x.\n", color);
6941 color = get_surface_color(rt, 400, 245);
6942 ok(compare_color(color, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color);
6944 IDirect3DTexture_Release(texture);
6945 ref = IDirectDrawSurface_Release(surface);
6946 ok(ref == 0, "Surface not properly released, refcount %u.\n", ref);
6948 /* Test alpha with texture that has no alpha channel - alpha should be taken from diffuse vertex color. */
6949 memset(&ddsd, 0, sizeof(ddsd));
6950 ddsd.dwSize = sizeof(ddsd);
6951 ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
6952 ddsd.dwHeight = 128;
6953 ddsd.dwWidth = 128;
6954 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
6955 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
6956 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
6957 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 32;
6958 U2(ddsd.ddpfPixelFormat).dwRBitMask = 0x00ff0000;
6959 U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x0000ff00;
6960 U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x000000ff;
6962 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &surface, NULL);
6963 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6965 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirect3DTexture, (void **)&texture);
6966 ok(SUCCEEDED(hr), "Failed to get texture interface, hr %#x.\n", hr);
6967 hr = IDirect3DTexture_GetHandle(texture, device, &texture_handle);
6968 ok(SUCCEEDED(hr), "Failed to get texture handle, hr %#x.\n", hr);
6970 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
6971 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
6973 U5(fx).dwFillColor = 0xff0000ff;
6974 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
6975 ok(SUCCEEDED(hr), "Failed to clear texture, hr %#x.\n", hr);
6976 U5(fx).dwFillColor = 0x800000ff;
6977 hr = IDirectDrawSurface_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
6978 ok(SUCCEEDED(hr), "Failed to clear texture, hr %#x.\n", hr);
6980 hr = IDirect3DExecuteBuffer_Lock(execute_buffer, &exec_desc);
6981 ok(SUCCEEDED(hr), "Failed to lock execute buffer, hr %#x.\n", hr);
6983 ptr = ((BYTE *)exec_desc.lpData) + sizeof(test1_quads);
6984 emit_process_vertices(&ptr, D3DPROCESSVERTICES_COPY, 0, 8);
6985 emit_set_rs(&ptr, D3DRENDERSTATE_TEXTUREHANDLE, texture_handle);
6987 emit_tquad(&ptr, 0);
6988 emit_tquad(&ptr, 4);
6989 emit_end(&ptr);
6991 inst_length = (BYTE *)ptr - (BYTE *)exec_desc.lpData;
6992 inst_length -= sizeof(test1_quads);
6993 hr = IDirect3DExecuteBuffer_Unlock(execute_buffer);
6994 ok(SUCCEEDED(hr), "Failed to unlock execute buffer, hr %#x.\n", hr);
6995 set_execute_data(execute_buffer, 8, sizeof(test1_quads), inst_length);
6997 hr = IDirect3DDevice_BeginScene(device);
6998 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
6999 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_UNCLIPPED);
7000 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
7001 hr = IDirect3DDevice_EndScene(device);
7002 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
7004 color = get_surface_color(rt, 5, 5);
7005 ok(compare_color(color, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color);
7006 color = get_surface_color(rt, 400, 5);
7007 ok(compare_color(color, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color);
7008 color = get_surface_color(rt, 5, 245);
7009 ok(compare_color(color, 0x00000080, 2), "Got unexpected color 0x%08x.\n", color);
7010 color = get_surface_color(rt, 400, 245);
7011 ok(compare_color(color, 0x00000080, 2), "Got unexpected color 0x%08x.\n", color);
7013 IDirect3DTexture_Release(texture);
7014 ref = IDirectDrawSurface_Release(surface);
7015 ok(ref == 0, "Surface not properly released, refcount %u.\n", ref);
7017 /* Test RGB - should multiply color components from diffuse vertex color and texture. */
7018 memset(&ddsd, 0, sizeof(ddsd));
7019 ddsd.dwSize = sizeof(ddsd);
7020 ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
7021 ddsd.dwHeight = 128;
7022 ddsd.dwWidth = 128;
7023 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
7024 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
7025 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
7026 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 32;
7027 U2(ddsd.ddpfPixelFormat).dwRBitMask = 0x00ff0000;
7028 U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x0000ff00;
7029 U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x000000ff;
7030 U5(ddsd.ddpfPixelFormat).dwRGBAlphaBitMask = 0xff000000;
7031 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &surface, NULL);
7032 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7034 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirect3DTexture, (void **)&texture);
7035 ok(SUCCEEDED(hr), "Failed to get texture interface, hr %#x.\n", hr);
7036 hr = IDirect3DTexture_GetHandle(texture, device, &texture_handle);
7037 ok(SUCCEEDED(hr), "Failed to get texture handle, hr %#x.\n", hr);
7039 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
7040 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
7042 U5(fx).dwFillColor = 0x00ffffff;
7043 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
7044 ok(SUCCEEDED(hr), "Failed to clear texture, hr %#x.\n", hr);
7045 U5(fx).dwFillColor = 0x00ffff80;
7046 hr = IDirectDrawSurface_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
7047 ok(SUCCEEDED(hr), "Failed to clear texture, hr %#x.\n", hr);
7049 hr = IDirect3DExecuteBuffer_Lock(execute_buffer, &exec_desc);
7050 ok(SUCCEEDED(hr), "Failed to lock execute buffer, hr %#x.\n", hr);
7052 memcpy(exec_desc.lpData, test2_quads, sizeof(test2_quads));
7054 ptr = ((BYTE *)exec_desc.lpData) + sizeof(test2_quads);
7055 emit_process_vertices(&ptr, D3DPROCESSVERTICES_COPY, 0, 8);
7056 emit_set_rs(&ptr, D3DRENDERSTATE_ALPHABLENDENABLE, FALSE);
7057 emit_set_rs(&ptr, D3DRENDERSTATE_TEXTUREHANDLE, texture_handle);
7059 emit_tquad(&ptr, 0);
7060 emit_tquad(&ptr, 4);
7061 emit_end(&ptr);
7063 inst_length = (BYTE *)ptr - (BYTE *)exec_desc.lpData;
7064 inst_length -= sizeof(test2_quads);
7065 hr = IDirect3DExecuteBuffer_Unlock(execute_buffer);
7066 ok(SUCCEEDED(hr), "Failed to unlock execute buffer, hr %#x.\n", hr);
7067 set_execute_data(execute_buffer, 8, sizeof(test2_quads), inst_length);
7069 hr = IDirect3DDevice_BeginScene(device);
7070 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
7071 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_UNCLIPPED);
7072 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
7073 hr = IDirect3DDevice_EndScene(device);
7074 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
7076 /* WARP (Win8 testbot) emulates color keying with the alpha channel like Wine does,
7077 * but even applies it when there's no color key assigned. The surface alpha is zero
7078 * here, so nothing gets drawn.
7080 * The ddraw2 version of this test draws these quads with color keying off due to
7081 * different defaults in ddraw1 and ddraw2. */
7082 color = get_surface_color(rt, 5, 5);
7083 ok(compare_color(color, 0x00ff0040, 2) || broken(compare_color(color, 0x00000000, 1)),
7084 "Got unexpected color 0x%08x.\n", color);
7085 color = get_surface_color(rt, 400, 5);
7086 ok(compare_color(color, 0x00ff0080, 2) || broken(compare_color(color, 0x00000000, 1)),
7087 "Got unexpected color 0x%08x.\n", color);
7088 color = get_surface_color(rt, 5, 245);
7089 ok(compare_color(color, 0x00800080, 2) || broken(compare_color(color, 0x00000000, 1)),
7090 "Got unexpected color 0x%08x.\n", color);
7091 color = get_surface_color(rt, 400, 245);
7092 ok(compare_color(color, 0x008000ff, 2) || broken(compare_color(color, 0x00000000, 1)),
7093 "Got unexpected color 0x%08x.\n", color);
7095 IDirect3DTexture_Release(texture);
7096 ref = IDirectDrawSurface_Release(surface);
7097 ok(ref == 0, "Surface not properly released, refcount %u.\n", ref);
7099 /* Test alpha again, now with color keyed texture (colorkey emulation in wine can interfere). */
7100 memset(&ddsd, 0, sizeof(ddsd));
7101 ddsd.dwSize = sizeof(ddsd);
7102 ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
7103 ddsd.dwHeight = 128;
7104 ddsd.dwWidth = 128;
7105 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
7106 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
7107 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
7108 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 16;
7109 U2(ddsd.ddpfPixelFormat).dwRBitMask = 0xf800;
7110 U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x07e0;
7111 U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x001f;
7113 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &surface, NULL);
7114 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7116 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirect3DTexture, (void **)&texture);
7117 ok(SUCCEEDED(hr), "Failed to get texture interface, hr %#x.\n", hr);
7118 hr = IDirect3DTexture_GetHandle(texture, device, &texture_handle);
7119 ok(SUCCEEDED(hr), "Failed to get texture handle, hr %#x.\n", hr);
7121 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
7122 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
7124 U5(fx).dwFillColor = 0xf800;
7125 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
7126 ok(SUCCEEDED(hr), "Failed to clear texture, hr %#x.\n", hr);
7127 U5(fx).dwFillColor = 0x001f;
7128 hr = IDirectDrawSurface_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
7129 ok(SUCCEEDED(hr), "Failed to clear texture, hr %#x.\n", hr);
7131 ckey.dwColorSpaceLowValue = 0x001f;
7132 ckey.dwColorSpaceHighValue = 0x001f;
7133 hr = IDirectDrawSurface_SetColorKey(surface, DDCKEY_SRCBLT, &ckey);
7134 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
7136 hr = IDirect3DExecuteBuffer_Lock(execute_buffer, &exec_desc);
7137 ok(SUCCEEDED(hr), "Failed to lock execute buffer, hr %#x.\n", hr);
7139 memcpy(exec_desc.lpData, test1_quads, sizeof(test1_quads));
7141 ptr = ((BYTE *)exec_desc.lpData) + sizeof(test1_quads);
7142 emit_process_vertices(&ptr, D3DPROCESSVERTICES_COPY, 0, 8);
7143 emit_set_rs(&ptr, D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);
7144 emit_set_rs(&ptr, D3DRENDERSTATE_TEXTUREHANDLE, texture_handle);
7145 /* D3DRENDERSTATE_COLORKEYENABLE is supposed to be on by default on version
7146 * 1 devices, but for some reason it randomly defaults to FALSE on the W8
7147 * testbot. This is either the fault of Windows 8 or the WARP driver.
7148 * Also D3DRENDERSTATE_COLORKEYENABLE was introduced in D3D 5 aka version 2
7149 * devices only, which might imply this doesn't actually do anything on
7150 * WARP. */
7151 emit_set_rs(&ptr, D3DRENDERSTATE_COLORKEYENABLE, TRUE);
7153 emit_tquad(&ptr, 0);
7154 emit_tquad(&ptr, 4);
7155 emit_end(&ptr);
7157 inst_length = (BYTE *)ptr - (BYTE *)exec_desc.lpData;
7158 inst_length -= sizeof(test1_quads);
7159 hr = IDirect3DExecuteBuffer_Unlock(execute_buffer);
7160 ok(SUCCEEDED(hr), "Failed to unlock execute buffer, hr %#x.\n", hr);
7161 set_execute_data(execute_buffer, 8, sizeof(test1_quads), inst_length);
7163 hr = IDirect3DDevice_BeginScene(device);
7164 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
7165 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_UNCLIPPED);
7166 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
7167 hr = IDirect3DDevice_EndScene(device);
7168 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
7170 /* Allow broken WARP results (colorkey disabled). */
7171 color = get_surface_color(rt, 5, 5);
7172 ok(compare_color(color, 0x00000000, 2) || broken(compare_color(color, 0x000000ff, 2)),
7173 "Got unexpected color 0x%08x.\n", color);
7174 color = get_surface_color(rt, 400, 5);
7175 ok(compare_color(color, 0x00ff0000, 2), "Got unexpected color 0x%08x.\n", color);
7176 color = get_surface_color(rt, 5, 245);
7177 ok(compare_color(color, 0x00000000, 2) || broken(compare_color(color, 0x00000080, 2)),
7178 "Got unexpected color 0x%08x.\n", color);
7179 color = get_surface_color(rt, 400, 245);
7180 ok(compare_color(color, 0x00800000, 2), "Got unexpected color 0x%08x.\n", color);
7182 IDirect3DTexture_Release(texture);
7183 ref = IDirectDrawSurface_Release(surface);
7184 ok(ref == 0, "Surface not properly released, refcount %u.\n", ref);
7186 ref = IDirect3DExecuteBuffer_Release(execute_buffer);
7187 ok(ref == 0, "Execute buffer not properly released, refcount %u.\n", ref);
7188 destroy_viewport(device, viewport);
7189 ref = IDirect3DMaterial_Release(material);
7190 ok(ref == 0, "Material not properly released, refcount %u.\n", ref);
7191 IDirectDrawSurface_Release(rt);
7192 IDirect3DDevice_Release(device);
7193 ref = IDirectDraw_Release(ddraw);
7194 ok(ref == 0, "Ddraw object not properly released, refcount %u.\n", ref);
7195 DestroyWindow(window);
7198 static void test_viewport_clear_rect(void)
7200 HRESULT hr;
7201 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
7202 static D3DRECT clear_rect2 = {{90}, {90}, {110}, {110}};
7203 IDirectDrawSurface *rt;
7204 HWND window;
7205 IDirectDraw *ddraw;
7206 IDirect3DDevice *device;
7207 IDirect3DMaterial *red, *green;
7208 IDirect3DViewport *viewport, *viewport2;
7209 ULONG ref;
7210 D3DCOLOR color;
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 = IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&rt);
7225 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
7227 red = create_diffuse_material(device, 1.0f, 0.0f, 0.0f, 1.0f);
7228 viewport = create_viewport(device, 0, 0, 640, 480);
7229 viewport_set_background(device, viewport, red);
7230 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
7231 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
7233 green = create_diffuse_material(device, 0.0f, 1.0f, 0.0f, 1.0f);
7234 viewport2 = create_viewport(device, 100, 100, 20, 20);
7235 viewport_set_background(device, viewport2, green);
7236 hr = IDirect3DViewport_Clear(viewport2, 1, &clear_rect2, D3DCLEAR_TARGET);
7237 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
7239 color = get_surface_color(rt, 85, 85); /* Outside both. */
7240 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
7241 color = get_surface_color(rt, 95, 95); /* Outside vp, inside rect. */
7242 /* AMD GPUs ignore the viewport dimensions and only care about the rectangle. */
7243 ok(compare_color(color, 0x00ff0000, 1) || broken(compare_color(color, 0x0000ff00, 1)),
7244 "Got unexpected color 0x%08x.\n", color);
7245 color = get_surface_color(rt, 105, 105); /* Inside both. */
7246 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
7247 color = get_surface_color(rt, 115, 115); /* Inside vp, outside rect. */
7248 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
7249 color = get_surface_color(rt, 125, 125); /* Outside both. */
7250 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
7252 destroy_viewport(device, viewport2);
7253 destroy_material(green);
7254 destroy_viewport(device, viewport);
7255 destroy_material(red);
7256 IDirectDrawSurface_Release(rt);
7257 IDirect3DDevice_Release(device);
7258 ref = IDirectDraw_Release(ddraw);
7259 ok(ref == 0, "Ddraw object not properly released, refcount %u.\n", ref);
7260 DestroyWindow(window);
7263 static void test_color_fill(void)
7265 HRESULT hr;
7266 IDirect3DDevice *device;
7267 IDirectDraw *ddraw;
7268 IDirectDrawSurface *surface, *surface2;
7269 DDSURFACEDESC surface_desc;
7270 ULONG refcount;
7271 HWND window;
7272 unsigned int i;
7273 BOOL is_warp;
7274 DDBLTFX fx;
7275 RECT rect = {5, 5, 7, 7};
7276 DWORD *color;
7277 DWORD num_fourcc_codes, *fourcc_codes;
7278 DDCAPS hal_caps;
7279 BOOL support_uyvy = FALSE, support_yuy2 = FALSE;
7280 static const struct
7282 DWORD caps;
7283 HRESULT colorfill_hr, depthfill_hr;
7284 BOOL rop_success;
7285 const char *name;
7286 DWORD result;
7287 BOOL check_result;
7288 DDPIXELFORMAT format;
7290 tests[] =
7293 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY,
7294 DD_OK, DDERR_INVALIDPARAMS, TRUE, "vidmem offscreenplain RGB", 0xdeadbeef, TRUE,
7296 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
7297 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
7301 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
7302 DD_OK, DDERR_INVALIDPARAMS, TRUE, "sysmem offscreenplain RGB", 0xdeadbeef, TRUE,
7304 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
7305 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
7309 DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY,
7310 DD_OK, DDERR_INVALIDPARAMS, TRUE, "vidmem texture RGB", 0xdeadbeef, TRUE,
7312 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
7313 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
7317 DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY,
7318 DD_OK, DDERR_INVALIDPARAMS, TRUE, "sysmem texture RGB", 0xdeadbeef, TRUE,
7320 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
7321 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
7325 DDSCAPS_ZBUFFER | DDSCAPS_VIDEOMEMORY,
7326 DDERR_INVALIDPARAMS, DD_OK, TRUE, "vidmem zbuffer", 0xdeadbeef, TRUE,
7327 {0, 0, 0, {0}, {0}, {0}, {0}, {0}}
7330 /* Colorfill on YUV surfaces always returns DD_OK, but the content is
7331 * different afterwards. DX9+ GPUs set one of the two luminance values
7332 * in each block, but AMD and Nvidia GPUs disagree on which luminance
7333 * value they set. r200 (dx8) just sets the entire block to the clear
7334 * value. */
7335 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY,
7336 DD_OK, DDERR_INVALIDPARAMS, FALSE, "vidmem offscreenplain YUY2", 0, FALSE,
7338 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y', 'U', 'Y', '2'),
7339 {0}, {0}, {0}, {0}, {0}
7343 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY,
7344 DD_OK, DDERR_INVALIDPARAMS, FALSE, "vidmem offscreenplain UYVY", 0, FALSE,
7346 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('U', 'Y', 'V', 'Y'),
7347 {0}, {0}, {0}, {0}, {0}
7351 DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY,
7352 DD_OK, DDERR_INVALIDPARAMS, FALSE, "vidmem overlay YUY2", 0, FALSE,
7354 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y', 'U', 'Y', '2'),
7355 {0}, {0}, {0}, {0}, {0}
7359 DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY,
7360 DD_OK, DDERR_INVALIDPARAMS, FALSE, "vidmem overlay UYVY", 0, FALSE,
7362 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('U', 'Y', 'V', 'Y'),
7363 {0}, {0}, {0}, {0}, {0}
7367 DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY,
7368 E_NOTIMPL, DDERR_INVALIDPARAMS, FALSE, "vidmem texture DXT1", 0, FALSE,
7370 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('D', 'X', 'T', '1'),
7371 {0}, {0}, {0}, {0}, {0}
7375 DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY,
7376 E_NOTIMPL, DDERR_INVALIDPARAMS, FALSE, "sysmem texture DXT1", 0, FALSE,
7378 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('D', 'X', 'T', '1'),
7379 {0}, {0}, {0}, {0}, {0}
7383 /* The testbot fills this with 0x00 instead of the blue channel. The sysmem
7384 * surface works, presumably because it is handled by the runtime instead of
7385 * the driver. */
7386 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY,
7387 DD_OK, DDERR_INVALIDPARAMS, TRUE, "vidmem offscreenplain P8", 0xefefefef, FALSE,
7389 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_PALETTEINDEXED8, 0,
7390 {8}, {0}, {0}, {0}, {0}
7394 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
7395 DD_OK, DDERR_INVALIDPARAMS, TRUE, "sysmem offscreenplain P8", 0xefefefef, TRUE,
7397 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_PALETTEINDEXED8, 0,
7398 {8}, {0}, {0}, {0}, {0}
7402 static const struct
7404 DWORD rop;
7405 const char *name;
7406 HRESULT hr;
7408 rops[] =
7410 {SRCCOPY, "SRCCOPY", DD_OK},
7411 {SRCPAINT, "SRCPAINT", DDERR_NORASTEROPHW},
7412 {SRCAND, "SRCAND", DDERR_NORASTEROPHW},
7413 {SRCINVERT, "SRCINVERT", DDERR_NORASTEROPHW},
7414 {SRCERASE, "SRCERASE", DDERR_NORASTEROPHW},
7415 {NOTSRCCOPY, "NOTSRCCOPY", DDERR_NORASTEROPHW},
7416 {NOTSRCERASE, "NOTSRCERASE", DDERR_NORASTEROPHW},
7417 {MERGECOPY, "MERGECOPY", DDERR_NORASTEROPHW},
7418 {MERGEPAINT, "MERGEPAINT", DDERR_NORASTEROPHW},
7419 {PATCOPY, "PATCOPY", DDERR_NORASTEROPHW},
7420 {PATPAINT, "PATPAINT", DDERR_NORASTEROPHW},
7421 {PATINVERT, "PATINVERT", DDERR_NORASTEROPHW},
7422 {DSTINVERT, "DSTINVERT", DDERR_NORASTEROPHW},
7423 {BLACKNESS, "BLACKNESS", DD_OK},
7424 {WHITENESS, "WHITENESS", DD_OK},
7425 {0xaa0029, "0xaa0029", DDERR_NORASTEROPHW} /* noop */
7428 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
7429 0, 0, 640, 480, 0, 0, 0, 0);
7430 ddraw = create_ddraw();
7431 ok(!!ddraw, "Failed to create a ddraw object.\n");
7432 is_warp = ddraw_is_warp(ddraw);
7433 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
7435 skip("Failed to create a 3D device, skipping test.\n");
7436 DestroyWindow(window);
7437 IDirectDraw_Release(ddraw);
7438 return;
7441 hr = IDirectDraw_GetFourCCCodes(ddraw, &num_fourcc_codes, NULL);
7442 ok(SUCCEEDED(hr), "Failed to get fourcc codes %#x.\n", hr);
7443 fourcc_codes = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
7444 num_fourcc_codes * sizeof(*fourcc_codes));
7445 if (!fourcc_codes)
7446 goto done;
7447 hr = IDirectDraw_GetFourCCCodes(ddraw, &num_fourcc_codes, fourcc_codes);
7448 ok(SUCCEEDED(hr), "Failed to get fourcc codes %#x.\n", hr);
7449 for (i = 0; i < num_fourcc_codes; i++)
7451 if (fourcc_codes[i] == MAKEFOURCC('Y', 'U', 'Y', '2'))
7452 support_yuy2 = TRUE;
7453 else if (fourcc_codes[i] == MAKEFOURCC('U', 'Y', 'V', 'Y'))
7454 support_uyvy = TRUE;
7456 HeapFree(GetProcessHeap(), 0, fourcc_codes);
7458 memset(&hal_caps, 0, sizeof(hal_caps));
7459 hal_caps.dwSize = sizeof(hal_caps);
7460 hr = IDirectDraw_GetCaps(ddraw, &hal_caps, NULL);
7461 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
7463 if ((!support_yuy2 && !support_uyvy) || !(hal_caps.dwCaps & DDCAPS_OVERLAY))
7464 skip("Overlays or some YUV formats not supported, skipping YUV colorfill tests.\n");
7466 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
7468 DWORD expected_broken = tests[i].result;
7469 DWORD mask = 0xffffffffu;
7471 /* Some Windows drivers modify dwFillColor when it is used on P8 or FourCC formats. */
7472 memset(&fx, 0, sizeof(fx));
7473 fx.dwSize = sizeof(fx);
7474 U5(fx).dwFillColor = 0xdeadbeef;
7476 memset(&surface_desc, 0, sizeof(surface_desc));
7477 surface_desc.dwSize = sizeof(surface_desc);
7478 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
7479 surface_desc.dwWidth = 64;
7480 surface_desc.dwHeight = 64;
7481 surface_desc.ddpfPixelFormat = tests[i].format;
7482 surface_desc.ddsCaps.dwCaps = tests[i].caps;
7484 if (tests[i].caps & DDSCAPS_TEXTURE)
7486 struct format_support_check check = {&tests[i].format, FALSE};
7487 hr = IDirect3DDevice_EnumTextureFormats(device, test_unsupported_formats_cb, &check);
7488 ok(SUCCEEDED(hr), "Failed to enumerate texture formats %#x.\n", hr);
7489 if (!check.supported)
7490 continue;
7493 if (tests[i].format.dwFourCC == MAKEFOURCC('Y','U','Y','2') && !support_yuy2)
7494 continue;
7495 if (tests[i].format.dwFourCC == MAKEFOURCC('U','Y','V','Y') && !support_uyvy)
7496 continue;
7497 if (tests[i].caps & DDSCAPS_OVERLAY && !(hal_caps.dwCaps & DDCAPS_OVERLAY))
7498 continue;
7500 if (tests[i].caps & DDSCAPS_ZBUFFER)
7502 surface_desc.dwFlags &= ~DDSD_PIXELFORMAT;
7503 surface_desc.dwFlags |= DDSD_ZBUFFERBITDEPTH;
7504 U2(surface_desc).dwZBufferBitDepth = get_device_z_depth(device);
7505 mask >>= (32 - U2(surface_desc).dwZBufferBitDepth);
7506 /* Some drivers seem to convert depth values incorrectly or not at
7507 * all. Affects at least AMD PALM, 8.17.10.1247. */
7508 if (tests[i].caps & DDSCAPS_VIDEOMEMORY)
7510 DWORD expected;
7511 float f, g;
7513 expected = tests[i].result & mask;
7514 f = ceilf(log2f(expected + 1.0f));
7515 g = (f + 1.0f) / 2.0f;
7516 g -= (int)g;
7517 expected_broken = (expected / exp2f(f) - g) * 256;
7518 expected_broken *= 0x01010101;
7522 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7523 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x, surface %s.\n", hr, tests[i].name);
7525 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
7526 todo_wine_if (tests[i].format.dwFourCC)
7527 ok(hr == tests[i].colorfill_hr, "Blt returned %#x, expected %#x, surface %s.\n",
7528 hr, tests[i].colorfill_hr, tests[i].name);
7530 hr = IDirectDrawSurface_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
7531 todo_wine_if (tests[i].format.dwFourCC)
7532 ok(hr == tests[i].colorfill_hr, "Blt returned %#x, expected %#x, surface %s.\n",
7533 hr, tests[i].colorfill_hr, tests[i].name);
7535 if (SUCCEEDED(hr) && tests[i].check_result)
7537 memset(&surface_desc, 0, sizeof(surface_desc));
7538 surface_desc.dwSize = sizeof(surface_desc);
7539 hr = IDirectDrawSurface_Lock(surface, NULL, &surface_desc, DDLOCK_READONLY, 0);
7540 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x, surface %s.\n", hr, tests[i].name);
7541 color = surface_desc.lpSurface;
7542 ok(*color == tests[i].result, "Got clear result 0x%08x, expected 0x%08x, surface %s.\n",
7543 *color, tests[i].result, tests[i].name);
7544 hr = IDirectDrawSurface_Unlock(surface, NULL);
7545 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, surface %s.\n", hr, tests[i].name);
7548 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
7549 ok(hr == tests[i].depthfill_hr, "Blt returned %#x, expected %#x, surface %s.\n",
7550 hr, tests[i].depthfill_hr, tests[i].name);
7551 hr = IDirectDrawSurface_Blt(surface, &rect, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
7552 ok(hr == tests[i].depthfill_hr, "Blt returned %#x, expected %#x, surface %s.\n",
7553 hr, tests[i].depthfill_hr, tests[i].name);
7555 if (SUCCEEDED(hr) && tests[i].check_result)
7557 memset(&surface_desc, 0, sizeof(surface_desc));
7558 surface_desc.dwSize = sizeof(surface_desc);
7559 hr = IDirectDrawSurface_Lock(surface, NULL, &surface_desc, DDLOCK_READONLY, 0);
7560 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x, surface %s.\n", hr, tests[i].name);
7561 color = surface_desc.lpSurface;
7562 todo_wine_if(tests[i].caps & DDSCAPS_VIDEOMEMORY && U2(surface_desc).dwZBufferBitDepth != 16)
7563 ok((*color & mask) == (tests[i].result & mask) || broken((*color & mask) == (expected_broken & mask))
7564 || broken(is_warp && (*color & mask) == (~0u & mask)) /* Windows 8+ testbot. */,
7565 "Got clear result 0x%08x, expected 0x%08x, surface %s.\n",
7566 *color & mask, tests[i].result & mask, tests[i].name);
7567 hr = IDirectDrawSurface_Unlock(surface, NULL);
7568 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, surface %s.\n", hr, tests[i].name);
7571 U5(fx).dwFillColor = 0xdeadbeef;
7572 fx.dwROP = BLACKNESS;
7573 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, NULL, DDBLT_ROP | DDBLT_WAIT, &fx);
7574 ok(FAILED(hr) == !tests[i].rop_success, "Blt returned %#x, expected %s, surface %s.\n",
7575 hr, tests[i].rop_success ? "success" : "failure", tests[i].name);
7576 ok(U5(fx).dwFillColor == 0xdeadbeef, "dwFillColor was set to 0x%08x, surface %s\n",
7577 U5(fx).dwFillColor, tests[i].name);
7579 if (SUCCEEDED(hr) && tests[i].check_result)
7581 memset(&surface_desc, 0, sizeof(surface_desc));
7582 surface_desc.dwSize = sizeof(surface_desc);
7583 hr = IDirectDrawSurface_Lock(surface, NULL, &surface_desc, DDLOCK_READONLY, 0);
7584 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x, surface %s.\n", hr, tests[i].name);
7585 color = surface_desc.lpSurface;
7586 ok(*color == 0, "Got clear result 0x%08x, expected 0x00000000, surface %s.\n",
7587 *color, tests[i].name);
7588 hr = IDirectDrawSurface_Unlock(surface, NULL);
7589 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, surface %s.\n", hr, tests[i].name);
7592 fx.dwROP = WHITENESS;
7593 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, NULL, DDBLT_ROP | DDBLT_WAIT, &fx);
7594 ok(FAILED(hr) == !tests[i].rop_success, "Blt returned %#x, expected %s, surface %s.\n",
7595 hr, tests[i].rop_success ? "success" : "failure", tests[i].name);
7596 ok(U5(fx).dwFillColor == 0xdeadbeef, "dwFillColor was set to 0x%08x, surface %s\n",
7597 U5(fx).dwFillColor, tests[i].name);
7599 if (SUCCEEDED(hr) && tests[i].check_result)
7601 memset(&surface_desc, 0, sizeof(surface_desc));
7602 surface_desc.dwSize = sizeof(surface_desc);
7603 hr = IDirectDrawSurface_Lock(surface, NULL, &surface_desc, DDLOCK_READONLY, 0);
7604 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x, surface %s.\n", hr, tests[i].name);
7605 color = surface_desc.lpSurface;
7606 /* WHITENESS sets the alpha channel to 0x00. Ignore this for now. */
7607 ok((*color & 0x00ffffff) == 0x00ffffff, "Got clear result 0x%08x, expected 0xffffffff, surface %s.\n",
7608 *color, tests[i].name);
7609 hr = IDirectDrawSurface_Unlock(surface, NULL);
7610 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, surface %s.\n", hr, tests[i].name);
7613 IDirectDrawSurface_Release(surface);
7616 memset(&fx, 0, sizeof(fx));
7617 fx.dwSize = sizeof(fx);
7618 U5(fx).dwFillColor = 0xdeadbeef;
7619 fx.dwROP = WHITENESS;
7621 memset(&surface_desc, 0, sizeof(surface_desc));
7622 surface_desc.dwSize = sizeof(surface_desc);
7623 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
7624 surface_desc.dwWidth = 64;
7625 surface_desc.dwHeight = 64;
7626 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
7627 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB;
7628 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount = 32;
7629 U2(surface_desc.ddpfPixelFormat).dwRBitMask = 0x00ff0000;
7630 U3(surface_desc.ddpfPixelFormat).dwGBitMask = 0x0000ff00;
7631 U4(surface_desc.ddpfPixelFormat).dwBBitMask = 0x000000ff;
7632 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
7633 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7634 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7635 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface2, NULL);
7636 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7638 /* No DDBLTFX. */
7639 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, &rect, DDBLT_COLORFILL | DDBLT_WAIT, NULL);
7640 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7641 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, &rect, DDBLT_ROP | DDBLT_WAIT, NULL);
7642 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7644 /* Unused source rectangle. */
7645 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
7646 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7647 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, &rect, DDBLT_ROP | DDBLT_WAIT, &fx);
7648 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7650 /* Unused source surface. */
7651 hr = IDirectDrawSurface_Blt(surface, NULL, surface2, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
7652 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7653 hr = IDirectDrawSurface_Blt(surface, NULL, surface2, NULL, DDBLT_ROP | DDBLT_WAIT, &fx);
7654 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7655 hr = IDirectDrawSurface_Blt(surface, NULL, surface2, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
7656 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7657 hr = IDirectDrawSurface_Blt(surface, NULL, surface2, &rect, DDBLT_ROP | DDBLT_WAIT, &fx);
7658 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7660 /* Inverted destination or source rectangle. */
7661 SetRect(&rect, 5, 7, 7, 5);
7662 hr = IDirectDrawSurface_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
7663 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
7664 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
7665 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7666 hr = IDirectDrawSurface_Blt(surface, &rect, surface2, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
7667 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7668 hr = IDirectDrawSurface_Blt(surface, NULL, surface2, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
7669 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7670 hr = IDirectDrawSurface_Blt(surface, NULL, surface2, &rect, DDBLT_ROP | DDBLT_WAIT, &fx);
7671 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
7673 /* Negative rectangle. */
7674 SetRect(&rect, -1, -1, 5, 5);
7675 hr = IDirectDrawSurface_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
7676 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
7677 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
7678 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7679 hr = IDirectDrawSurface_Blt(surface, &rect, surface2, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
7680 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7681 hr = IDirectDrawSurface_Blt(surface, &rect, surface2, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
7682 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7683 hr = IDirectDrawSurface_Blt(surface, NULL, surface2, &rect, DDBLT_ROP | DDBLT_WAIT, &fx);
7684 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
7686 /* Out of bounds rectangle. */
7687 SetRect(&rect, 0, 0, 65, 65);
7688 hr = IDirectDrawSurface_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
7689 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
7690 hr = IDirectDrawSurface_Blt(surface, NULL, surface2, &rect, DDBLT_ROP | DDBLT_WAIT, &fx);
7691 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
7693 /* Combine multiple flags. */
7694 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
7695 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7696 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_ROP | DDBLT_WAIT, &fx);
7697 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7698 hr = IDirectDrawSurface_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_ROP | DDBLT_WAIT, &fx);
7699 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7701 for (i = 0; i < sizeof(rops) / sizeof(*rops); i++)
7703 fx.dwROP = rops[i].rop;
7704 hr = IDirectDrawSurface_Blt(surface, NULL, surface2, NULL, DDBLT_ROP | DDBLT_WAIT, &fx);
7705 ok(hr == rops[i].hr, "Got unexpected hr %#x for rop %s.\n", hr, rops[i].name);
7708 IDirectDrawSurface_Release(surface2);
7709 IDirectDrawSurface_Release(surface);
7711 memset(&surface_desc, 0, sizeof(surface_desc));
7712 surface_desc.dwSize = sizeof(surface_desc);
7713 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_ZBUFFERBITDEPTH;
7714 surface_desc.dwWidth = 64;
7715 surface_desc.dwHeight = 64;
7716 U2(surface_desc).dwZBufferBitDepth = get_device_z_depth(device);
7717 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
7718 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7719 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7720 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface2, NULL);
7721 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7723 /* No DDBLTFX. */
7724 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, NULL);
7725 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7727 /* Unused source rectangle. */
7728 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
7729 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7731 /* Unused source surface. */
7732 hr = IDirectDrawSurface_Blt(surface, NULL, surface2, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
7733 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7734 hr = IDirectDrawSurface_Blt(surface, NULL, surface2, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
7735 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7737 /* Inverted destination or source rectangle. */
7738 SetRect(&rect, 5, 7, 7, 5);
7739 hr = IDirectDrawSurface_Blt(surface, &rect, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
7740 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
7741 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
7742 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7743 hr = IDirectDrawSurface_Blt(surface, &rect, surface2, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
7744 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7745 hr = IDirectDrawSurface_Blt(surface, NULL, surface2, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
7746 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7748 /* Negative rectangle. */
7749 SetRect(&rect, -1, -1, 5, 5);
7750 hr = IDirectDrawSurface_Blt(surface, &rect, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
7751 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
7752 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
7753 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7754 hr = IDirectDrawSurface_Blt(surface, &rect, surface2, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
7755 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7756 hr = IDirectDrawSurface_Blt(surface, &rect, surface2, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
7757 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7759 /* Out of bounds rectangle. */
7760 SetRect(&rect, 0, 0, 65, 65);
7761 hr = IDirectDrawSurface_Blt(surface, &rect, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
7762 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
7764 /* Combine multiple flags. */
7765 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
7766 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7768 IDirectDrawSurface_Release(surface2);
7769 IDirectDrawSurface_Release(surface);
7771 done:
7772 IDirect3DDevice_Release(device);
7773 refcount = IDirectDraw_Release(ddraw);
7774 ok(refcount == 0, "Ddraw object not properly released, refcount %u.\n", refcount);
7775 DestroyWindow(window);
7778 static void test_colorkey_precision(void)
7780 static D3DTLVERTEX quad[] =
7782 {{ 0.0f}, {480.0f}, {0.0f}, {1.0f}, {0x00000000}, {0x00000000}, {0.0f}, {1.0f}},
7783 {{ 0.0f}, { 0.0f}, {0.0f}, {1.0f}, {0x00000000}, {0x00000000}, {0.0f}, {0.0f}},
7784 {{640.0f}, {480.0f}, {0.0f}, {1.0f}, {0x00000000}, {0x00000000}, {1.0f}, {1.0f}},
7785 {{640.0f}, { 0.0f}, {0.0f}, {1.0f}, {0x00000000}, {0x00000000}, {1.0f}, {0.0f}},
7787 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
7788 IDirect3DDevice *device;
7789 IDirectDraw *ddraw;
7790 IDirectDrawSurface *rt;
7791 IDirect3DViewport *viewport;
7792 IDirect3DExecuteBuffer *execute_buffer;
7793 D3DEXECUTEBUFFERDESC exec_desc;
7794 UINT inst_length;
7795 void *ptr;
7796 HWND window;
7797 HRESULT hr;
7798 IDirectDrawSurface *src, *dst, *texture;
7799 D3DTEXTUREHANDLE handle;
7800 IDirect3DTexture *d3d_texture;
7801 IDirect3DMaterial *green;
7802 DDSURFACEDESC surface_desc, lock_desc;
7803 ULONG refcount;
7804 D3DCOLOR color;
7805 unsigned int t, c;
7806 DDCOLORKEY ckey;
7807 DDBLTFX fx;
7808 DWORD data[4] = {0}, color_mask;
7809 BOOL is_nvidia, is_warp;
7810 static const struct
7812 unsigned int max, shift, bpp, clear;
7813 const char *name;
7814 BOOL skip_nv;
7815 DDPIXELFORMAT fmt;
7817 tests[] =
7820 255, 0, 4, 0x00345678, "D3DFMT_X8R8G8B8", FALSE,
7822 sizeof(DDPIXELFORMAT), DDPF_RGB, 0,
7823 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0x00000000}
7828 63, 5, 2, 0x5678, "D3DFMT_R5G6B5, G channel", FALSE,
7830 sizeof(DDPIXELFORMAT), DDPF_RGB, 0,
7831 {16}, {0xf800}, {0x07e0}, {0x001f}, {0x0000}
7836 31, 0, 2, 0x5678, "D3DFMT_R5G6B5, B channel", FALSE,
7838 sizeof(DDPIXELFORMAT), DDPF_RGB, 0,
7839 {16}, {0xf800}, {0x07e0}, {0x001f}, {0x0000}
7844 15, 0, 2, 0x0678, "D3DFMT_A4R4G4B4", TRUE,
7846 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
7847 {16}, {0x0f00}, {0x00f0}, {0x000f}, {0xf000}
7852 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
7853 0, 0, 640, 480, 0, 0, 0, 0);
7854 ddraw = create_ddraw();
7855 ok(!!ddraw, "Failed to create a ddraw object.\n");
7856 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
7858 skip("Failed to create a 3D device, skipping test.\n");
7859 DestroyWindow(window);
7860 IDirectDraw_Release(ddraw);
7861 return;
7863 hr = IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&rt);
7864 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
7866 is_nvidia = ddraw_is_nvidia(ddraw);
7867 /* The Windows 8 WARP driver has plenty of false negatives in X8R8G8B8
7868 * (color key doesn't match although the values are equal), and a false
7869 * positive when the color key is 0 and the texture contains the value 1.
7870 * I don't want to mark this broken unconditionally since this would
7871 * essentially disable the test on Windows. Also on random occasions
7872 * 254 == 255 and 255 != 255.*/
7873 is_warp = ddraw_is_warp(ddraw);
7875 green = create_diffuse_material(device, 0.0f, 1.0f, 0.0f, 0.0f);
7876 viewport = create_viewport(device, 0, 0, 640, 480);
7877 viewport_set_background(device, viewport, green);
7879 memset(&exec_desc, 0, sizeof(exec_desc));
7880 exec_desc.dwSize = sizeof(exec_desc);
7881 exec_desc.dwFlags = D3DDEB_BUFSIZE | D3DDEB_CAPS;
7882 exec_desc.dwBufferSize = 1024;
7883 exec_desc.dwCaps = D3DDEBCAPS_SYSTEMMEMORY;
7884 hr = IDirect3DDevice_CreateExecuteBuffer(device, &exec_desc, &execute_buffer, NULL);
7885 ok(SUCCEEDED(hr), "Failed to create execute buffer, hr %#x.\n", hr);
7887 memset(&fx, 0, sizeof(fx));
7888 fx.dwSize = sizeof(fx);
7889 memset(&lock_desc, 0, sizeof(lock_desc));
7890 lock_desc.dwSize = sizeof(lock_desc);
7892 for (t = 0; t < sizeof(tests) / sizeof(*tests); ++t)
7894 if (is_nvidia && tests[t].skip_nv)
7896 win_skip("Skipping test %s on Nvidia Windows drivers.\n", tests[t].name);
7897 continue;
7900 memset(&surface_desc, 0, sizeof(surface_desc));
7901 surface_desc.dwSize = sizeof(surface_desc);
7902 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
7903 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
7904 surface_desc.dwWidth = 4;
7905 surface_desc.dwHeight = 1;
7906 surface_desc.ddpfPixelFormat = tests[t].fmt;
7907 /* Windows XP (at least with the r200 driver, other drivers untested) produces
7908 * garbage when doing color keyed texture->texture blits. */
7909 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &src, NULL);
7910 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7911 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &dst, NULL);
7912 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7914 U5(fx).dwFillColor = tests[t].clear;
7915 /* On the w8 testbot (WARP driver) the blit result has different values in the
7916 * X channel. */
7917 color_mask = U2(tests[t].fmt).dwRBitMask
7918 | U3(tests[t].fmt).dwGBitMask
7919 | U4(tests[t].fmt).dwBBitMask;
7921 for (c = 0; c <= tests[t].max; ++c)
7923 /* The idiotic Nvidia Windows driver can't change the color key on a d3d
7924 * texture after it has been set once... */
7925 surface_desc.dwFlags |= DDSD_CKSRCBLT;
7926 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
7927 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = c << tests[t].shift;
7928 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = c << tests[t].shift;
7929 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &texture, NULL);
7930 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7932 hr = IDirectDrawSurface_QueryInterface(texture, &IID_IDirect3DTexture, (void **)&d3d_texture);
7933 ok(SUCCEEDED(hr), "Failed to get texture interface, hr %#x.\n", hr);
7934 hr = IDirect3DTexture_GetHandle(d3d_texture, device, &handle);
7935 ok(SUCCEEDED(hr), "Failed to get texture handle, hr %#x.\n", hr);
7936 IDirect3DTexture_Release(d3d_texture);
7938 hr = IDirect3DExecuteBuffer_Lock(execute_buffer, &exec_desc);
7939 ok(SUCCEEDED(hr), "Failed to lock execute buffer, hr %#x.\n", hr);
7941 memcpy(exec_desc.lpData, quad, sizeof(quad));
7943 ptr = ((BYTE *)exec_desc.lpData) + sizeof(quad);
7944 emit_process_vertices(&ptr, D3DPROCESSVERTICES_COPY, 0, 8);
7945 emit_set_rs(&ptr, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
7946 emit_set_rs(&ptr, D3DRENDERSTATE_TEXTUREHANDLE, handle);
7947 emit_set_rs(&ptr, D3DRENDERSTATE_TEXTUREMAPBLEND, D3DTBLEND_MODULATEALPHA);
7948 /* D3DRENDERSTATE_COLORKEYENABLE is supposed to be on by default on version
7949 * 1 devices, but for some reason it randomly defaults to FALSE on the W8
7950 * testbot. This is either the fault of Windows 8 or the WARP driver.
7951 * Also D3DRENDERSTATE_COLORKEYENABLE was introduced in D3D 5 aka version 2
7952 * devices only, which might imply this doesn't actually do anything on
7953 * WARP. */
7954 emit_set_rs(&ptr, D3DRENDERSTATE_COLORKEYENABLE, TRUE);
7956 emit_tquad(&ptr, 0);
7957 emit_tquad(&ptr, 4);
7958 emit_set_rs(&ptr, D3DRENDERSTATE_TEXTUREHANDLE, 0);
7959 emit_end(&ptr);
7961 inst_length = (BYTE *)ptr - (BYTE *)exec_desc.lpData;
7962 inst_length -= sizeof(quad);
7963 hr = IDirect3DExecuteBuffer_Unlock(execute_buffer);
7964 ok(SUCCEEDED(hr), "Failed to unlock execute buffer, hr %#x.\n", hr);
7965 set_execute_data(execute_buffer, 8, sizeof(quad), inst_length);
7967 hr = IDirectDrawSurface_Blt(dst, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
7968 ok(SUCCEEDED(hr), "Failed to clear destination surface, hr %#x.\n", hr);
7970 hr = IDirectDrawSurface_Lock(src, NULL, &lock_desc, DDLOCK_WAIT, NULL);
7971 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
7972 switch (tests[t].bpp)
7974 case 4:
7975 ((DWORD *)lock_desc.lpSurface)[0] = (c ? c - 1 : 0) << tests[t].shift;
7976 ((DWORD *)lock_desc.lpSurface)[1] = c << tests[t].shift;
7977 ((DWORD *)lock_desc.lpSurface)[2] = min(c + 1, tests[t].max) << tests[t].shift;
7978 ((DWORD *)lock_desc.lpSurface)[3] = 0xffffffff;
7979 break;
7981 case 2:
7982 ((WORD *)lock_desc.lpSurface)[0] = (c ? c - 1 : 0) << tests[t].shift;
7983 ((WORD *)lock_desc.lpSurface)[1] = c << tests[t].shift;
7984 ((WORD *)lock_desc.lpSurface)[2] = min(c + 1, tests[t].max) << tests[t].shift;
7985 ((WORD *)lock_desc.lpSurface)[3] = 0xffff;
7986 break;
7988 hr = IDirectDrawSurface_Unlock(src, 0);
7989 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
7990 hr = IDirectDrawSurface_Blt(texture, NULL, src, NULL, DDBLT_WAIT, NULL);
7991 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
7993 ckey.dwColorSpaceLowValue = c << tests[t].shift;
7994 ckey.dwColorSpaceHighValue = c << tests[t].shift;
7995 hr = IDirectDrawSurface_SetColorKey(src, DDCKEY_SRCBLT, &ckey);
7996 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
7998 hr = IDirectDrawSurface_Blt(dst, NULL, src, NULL, DDBLT_KEYSRC | DDBLT_WAIT, NULL);
7999 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
8001 /* Don't make this read only, it somehow breaks the detection of the Nvidia bug below. */
8002 hr = IDirectDrawSurface_Lock(dst, NULL, &lock_desc, DDLOCK_WAIT, NULL);
8003 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
8004 switch (tests[t].bpp)
8006 case 4:
8007 data[0] = ((DWORD *)lock_desc.lpSurface)[0] & color_mask;
8008 data[1] = ((DWORD *)lock_desc.lpSurface)[1] & color_mask;
8009 data[2] = ((DWORD *)lock_desc.lpSurface)[2] & color_mask;
8010 data[3] = ((DWORD *)lock_desc.lpSurface)[3] & color_mask;
8011 break;
8013 case 2:
8014 data[0] = ((WORD *)lock_desc.lpSurface)[0] & color_mask;
8015 data[1] = ((WORD *)lock_desc.lpSurface)[1] & color_mask;
8016 data[2] = ((WORD *)lock_desc.lpSurface)[2] & color_mask;
8017 data[3] = ((WORD *)lock_desc.lpSurface)[3] & color_mask;
8018 break;
8020 hr = IDirectDrawSurface_Unlock(dst, 0);
8021 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
8023 if (!c)
8025 ok(data[0] == tests[t].clear, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
8026 tests[t].clear, data[0], tests[t].name, c);
8028 if (data[3] == tests[t].clear)
8030 /* My Geforce GTX 460 on Windows 7 misbehaves when A4R4G4B4 is blitted with color
8031 * keying: The blit takes ~0.5 seconds, and subsequent color keying draws are broken,
8032 * even when a different surface is used. The blit itself doesn't draw anything,
8033 * so we can detect the bug by looking at the otherwise unused 4th texel. It should
8034 * never be masked out by the key.
8036 * On Windows 10 the problem is worse, Blt just hangs. For this reason the ARGB4444
8037 * test is disabled entirely.
8039 * Also appears to affect the testbot in some way with R5G6B5. Color keying is
8040 * terrible on WARP. */
8041 skip("Nvidia A4R4G4B4 color keying blit bug detected, skipping.\n");
8042 IDirectDrawSurface_Release(texture);
8043 IDirectDrawSurface_Release(src);
8044 IDirectDrawSurface_Release(dst);
8045 goto done;
8048 else
8049 ok(data[0] == (c - 1) << tests[t].shift, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
8050 (c - 1) << tests[t].shift, data[0], tests[t].name, c);
8052 ok(data[1] == tests[t].clear, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
8053 tests[t].clear, data[1], tests[t].name, c);
8055 if (c == tests[t].max)
8056 ok(data[2] == tests[t].clear, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
8057 tests[t].clear, data[2], tests[t].name, c);
8058 else
8059 ok(data[2] == (c + 1) << tests[t].shift, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
8060 (c + 1) << tests[t].shift, data[2], tests[t].name, c);
8062 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
8063 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
8065 hr = IDirect3DDevice_BeginScene(device);
8066 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
8067 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_UNCLIPPED);
8068 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
8069 hr = IDirect3DDevice_EndScene(device);
8070 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
8072 color = get_surface_color(rt, 80, 240);
8073 if (!c)
8074 ok(compare_color(color, 0x0000ff00, 1) || broken(is_warp && compare_color(color, 0x00000000, 1)),
8075 "Got unexpected color 0x%08x, format %s, c=%u.\n",
8076 color, tests[t].name, c);
8077 else
8078 ok(compare_color(color, 0x00000000, 1) || broken(is_warp && compare_color(color, 0x0000ff00, 1)),
8079 "Got unexpected color 0x%08x, format %s, c=%u.\n",
8080 color, tests[t].name, c);
8082 color = get_surface_color(rt, 240, 240);
8083 ok(compare_color(color, 0x0000ff00, 1) || broken(is_warp && compare_color(color, 0x00000000, 1)),
8084 "Got unexpected color 0x%08x, format %s, c=%u.\n",
8085 color, tests[t].name, c);
8087 color = get_surface_color(rt, 400, 240);
8088 if (c == tests[t].max)
8089 ok(compare_color(color, 0x0000ff00, 1) || broken(is_warp && compare_color(color, 0x00000000, 1)),
8090 "Got unexpected color 0x%08x, format %s, c=%u.\n",
8091 color, tests[t].name, c);
8092 else
8093 ok(compare_color(color, 0x00000000, 1) || broken(is_warp && compare_color(color, 0x0000ff00, 1)),
8094 "Got unexpected color 0x%08x, format %s, c=%u.\n",
8095 color, tests[t].name, c);
8097 IDirectDrawSurface_Release(texture);
8099 IDirectDrawSurface_Release(src);
8100 IDirectDrawSurface_Release(dst);
8102 done:
8104 destroy_viewport(device, viewport);
8105 destroy_material(green);
8106 IDirectDrawSurface_Release(rt);
8107 IDirect3DExecuteBuffer_Release(execute_buffer);
8108 IDirect3DDevice_Release(device);
8109 refcount = IDirectDraw_Release(ddraw);
8110 ok(refcount == 0, "Ddraw object not properly released, refcount %u.\n", refcount);
8111 DestroyWindow(window);
8114 static void test_range_colorkey(void)
8116 IDirectDraw *ddraw;
8117 HWND window;
8118 HRESULT hr;
8119 IDirectDrawSurface *surface;
8120 DDSURFACEDESC surface_desc;
8121 ULONG refcount;
8122 DDCOLORKEY ckey;
8124 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
8125 0, 0, 640, 480, 0, 0, 0, 0);
8126 ddraw = create_ddraw();
8127 ok(!!ddraw, "Failed to create a ddraw object.\n");
8128 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
8129 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
8131 memset(&surface_desc, 0, sizeof(surface_desc));
8132 surface_desc.dwSize = sizeof(surface_desc);
8133 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CKSRCBLT;
8134 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
8135 surface_desc.dwWidth = 1;
8136 surface_desc.dwHeight = 1;
8137 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB;
8138 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount = 32;
8139 U2(surface_desc.ddpfPixelFormat).dwRBitMask = 0x00ff0000;
8140 U3(surface_desc.ddpfPixelFormat).dwGBitMask = 0x0000ff00;
8141 U4(surface_desc.ddpfPixelFormat).dwBBitMask = 0x000000ff;
8142 U5(surface_desc.ddpfPixelFormat).dwRGBAlphaBitMask = 0x00000000;
8144 /* Creating a surface with a range color key fails with DDERR_NOCOLORKEY. */
8145 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00000000;
8146 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00000001;
8147 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8148 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
8150 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00000001;
8151 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00000000;
8152 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8153 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
8155 /* Same for DDSCAPS_OFFSCREENPLAIN. */
8156 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
8157 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00000000;
8158 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00000001;
8159 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8160 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
8162 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00000001;
8163 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00000000;
8164 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8165 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
8167 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00000000;
8168 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00000000;
8169 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8170 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8172 /* Setting a range color key without DDCKEY_COLORSPACE collapses the key. */
8173 ckey.dwColorSpaceLowValue = 0x00000000;
8174 ckey.dwColorSpaceHighValue = 0x00000001;
8175 hr = IDirectDrawSurface_SetColorKey(surface, DDCKEY_SRCBLT, &ckey);
8176 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
8178 hr = IDirectDrawSurface_GetColorKey(surface, DDCKEY_SRCBLT, &ckey);
8179 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
8180 ok(!ckey.dwColorSpaceLowValue, "Got unexpected value 0x%08x.\n", ckey.dwColorSpaceLowValue);
8181 ok(!ckey.dwColorSpaceHighValue, "Got unexpected value 0x%08x.\n", ckey.dwColorSpaceHighValue);
8183 ckey.dwColorSpaceLowValue = 0x00000001;
8184 ckey.dwColorSpaceHighValue = 0x00000000;
8185 hr = IDirectDrawSurface_SetColorKey(surface, DDCKEY_SRCBLT, &ckey);
8186 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
8188 hr = IDirectDrawSurface_GetColorKey(surface, DDCKEY_SRCBLT, &ckey);
8189 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
8190 ok(ckey.dwColorSpaceLowValue == 0x00000001, "Got unexpected value 0x%08x.\n", ckey.dwColorSpaceLowValue);
8191 ok(ckey.dwColorSpaceHighValue == 0x00000001, "Got unexpected value 0x%08x.\n", ckey.dwColorSpaceHighValue);
8193 /* DDCKEY_COLORSPACE is ignored if the key is a single value. */
8194 ckey.dwColorSpaceLowValue = 0x00000000;
8195 ckey.dwColorSpaceHighValue = 0x00000000;
8196 hr = IDirectDrawSurface_SetColorKey(surface, DDCKEY_SRCBLT | DDCKEY_COLORSPACE, &ckey);
8197 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
8199 /* Using it with a range key results in DDERR_NOCOLORKEYHW. */
8200 ckey.dwColorSpaceLowValue = 0x00000001;
8201 ckey.dwColorSpaceHighValue = 0x00000000;
8202 hr = IDirectDrawSurface_SetColorKey(surface, DDCKEY_SRCBLT | DDCKEY_COLORSPACE, &ckey);
8203 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
8204 ckey.dwColorSpaceLowValue = 0x00000000;
8205 ckey.dwColorSpaceHighValue = 0x00000001;
8206 hr = IDirectDrawSurface_SetColorKey(surface, DDCKEY_SRCBLT | DDCKEY_COLORSPACE, &ckey);
8207 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
8208 /* Range destination keys don't work either. */
8209 hr = IDirectDrawSurface_SetColorKey(surface, DDCKEY_DESTBLT | DDCKEY_COLORSPACE, &ckey);
8210 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
8212 /* Just to show it's not because of A, R, and G having equal values. */
8213 ckey.dwColorSpaceLowValue = 0x00000000;
8214 ckey.dwColorSpaceHighValue = 0x01010101;
8215 hr = IDirectDrawSurface_SetColorKey(surface, DDCKEY_SRCBLT | DDCKEY_COLORSPACE, &ckey);
8216 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
8218 /* None of these operations modified the key. */
8219 hr = IDirectDrawSurface_GetColorKey(surface, DDCKEY_SRCBLT, &ckey);
8220 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
8221 ok(!ckey.dwColorSpaceLowValue, "Got unexpected value 0x%08x.\n", ckey.dwColorSpaceLowValue);
8222 ok(!ckey.dwColorSpaceHighValue, "Got unexpected value 0x%08x.\n", ckey.dwColorSpaceHighValue);
8224 IDirectDrawSurface_Release(surface),
8225 refcount = IDirectDraw_Release(ddraw);
8226 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8227 DestroyWindow(window);
8230 static void test_shademode(void)
8232 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
8233 IDirect3DExecuteBuffer *execute_buffer;
8234 D3DEXECUTEBUFFERDESC exec_desc;
8235 IDirect3DMaterial *background;
8236 IDirect3DViewport *viewport;
8237 IDirect3DDevice *device;
8238 IDirectDrawSurface *rt;
8239 const D3DLVERTEX *quad;
8240 DWORD color0, color1;
8241 UINT i, inst_length;
8242 IDirectDraw *ddraw;
8243 ULONG refcount;
8244 HWND window;
8245 HRESULT hr;
8246 void *ptr;
8247 static const D3DLVERTEX quad_strip[] =
8249 {{-1.0f}, {-1.0f}, {0.0f}, 0, {0xffff0000}},
8250 {{-1.0f}, { 1.0f}, {0.0f}, 0, {0xff00ff00}},
8251 {{ 1.0f}, {-1.0f}, {0.0f}, 0, {0xff0000ff}},
8252 {{ 1.0f}, { 1.0f}, {0.0f}, 0, {0xffffffff}},
8254 quad_list[] =
8256 {{ 1.0f}, {-1.0f}, {0.0f}, 0, {0xff0000ff}},
8257 {{-1.0f}, {-1.0f}, {0.0f}, 0, {0xffff0000}},
8258 {{-1.0f}, { 1.0f}, {0.0f}, 0, {0xff00ff00}},
8259 {{ 1.0f}, { 1.0f}, {0.0f}, 0, {0xffffffff}},
8261 static const struct
8263 DWORD primtype;
8264 DWORD shademode;
8265 DWORD color0, color1;
8267 tests[] =
8269 {D3DPT_TRIANGLESTRIP, D3DSHADE_FLAT, 0x00ff0000, 0x000000ff},
8270 {D3DPT_TRIANGLESTRIP, D3DSHADE_PHONG, 0x000dca28, 0x000d45c7},
8271 {D3DPT_TRIANGLESTRIP, D3DSHADE_GOURAUD, 0x000dca28, 0x000d45c7},
8272 {D3DPT_TRIANGLESTRIP, D3DSHADE_PHONG, 0x000dca28, 0x000d45c7},
8273 {D3DPT_TRIANGLELIST, D3DSHADE_FLAT, 0x000000ff, 0x0000ff00},
8274 {D3DPT_TRIANGLELIST, D3DSHADE_GOURAUD, 0x000dca28, 0x000d45c7},
8277 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
8278 0, 0, 640, 480, 0, 0, 0, 0);
8279 ddraw = create_ddraw();
8280 ok(!!ddraw, "Failed to create a ddraw object.\n");
8281 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
8283 skip("Failed to create a 3D device, skipping test.\n");
8284 IDirectDraw_Release(ddraw);
8285 DestroyWindow(window);
8286 return;
8289 hr = IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&rt);
8290 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
8292 background = create_diffuse_material(device, 1.0f, 1.0f, 1.0f, 1.0f);
8293 viewport = create_viewport(device, 0, 0, 640, 480);
8294 viewport_set_background(device, viewport, background);
8296 memset(&exec_desc, 0, sizeof(exec_desc));
8297 exec_desc.dwSize = sizeof(exec_desc);
8298 exec_desc.dwFlags = D3DDEB_BUFSIZE | D3DDEB_CAPS;
8299 exec_desc.dwBufferSize = 1024;
8300 exec_desc.dwCaps = D3DDEBCAPS_SYSTEMMEMORY;
8302 hr = IDirect3DDevice_CreateExecuteBuffer(device, &exec_desc, &execute_buffer, NULL);
8303 ok(SUCCEEDED(hr), "Failed to create execute buffer, hr %#x.\n", hr);
8305 /* Try it first with a TRIANGLESTRIP. Do it with different geometry because
8306 * the color fixups we have to do for FLAT shading will be dependent on that. */
8308 for (i = 0; i < sizeof(tests) / sizeof(tests[0]); ++i)
8310 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
8311 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
8313 hr = IDirect3DExecuteBuffer_Lock(execute_buffer, &exec_desc);
8314 ok(SUCCEEDED(hr), "Failed to lock execute buffer, hr %#x.\n", hr);
8316 quad = tests[i].primtype == D3DPT_TRIANGLESTRIP ? quad_strip : quad_list;
8317 memcpy(exec_desc.lpData, quad, sizeof(quad_strip));
8318 ptr = ((BYTE *)exec_desc.lpData) + sizeof(quad_strip);
8319 emit_set_rs(&ptr, D3DRENDERSTATE_CLIPPING, FALSE);
8320 emit_set_rs(&ptr, D3DRENDERSTATE_ZENABLE, FALSE);
8321 emit_set_rs(&ptr, D3DRENDERSTATE_FOGENABLE, FALSE);
8322 emit_set_rs(&ptr, D3DRENDERSTATE_CULLMODE, D3DCULL_NONE);
8323 emit_set_rs(&ptr, D3DRENDERSTATE_SHADEMODE, tests[i].shademode);
8325 emit_process_vertices(&ptr, D3DPROCESSVERTICES_TRANSFORM, 0, 4);
8326 if (tests[i].primtype == D3DPT_TRIANGLESTRIP)
8327 emit_tquad(&ptr, 0);
8328 else
8329 emit_tquad_tlist(&ptr, 0);
8330 emit_end(&ptr);
8331 inst_length = (BYTE *)ptr - (BYTE *)exec_desc.lpData;
8332 inst_length -= sizeof(quad_strip);
8334 hr = IDirect3DExecuteBuffer_Unlock(execute_buffer);
8335 ok(SUCCEEDED(hr), "Failed to unlock execute buffer, hr %#x.\n", hr);
8337 hr = IDirect3DDevice_BeginScene(device);
8338 set_execute_data(execute_buffer, 4, sizeof(quad_strip), inst_length);
8339 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
8340 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
8341 hr = IDirect3DDevice_EndScene(device);
8342 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
8344 color0 = get_surface_color(rt, 100, 100); /* Inside first triangle */
8345 color1 = get_surface_color(rt, 500, 350); /* Inside second triangle */
8347 /* For D3DSHADE_FLAT it should take the color of the first vertex of
8348 * each triangle. This requires EXT_provoking_vertex or similar
8349 * functionality being available. */
8350 /* PHONG should be the same as GOURAUD, since no hardware implements
8351 * this. */
8352 ok(compare_color(color0, tests[i].color0, 1), "Test %u shading has color0 %08x, expected %08x.\n",
8353 i, color0, tests[i].color0);
8354 ok(compare_color(color1, tests[i].color1, 1), "Test %u shading has color1 %08x, expected %08x.\n",
8355 i, color1, tests[i].color1);
8358 IDirect3DExecuteBuffer_Release(execute_buffer);
8359 destroy_viewport(device, viewport);
8360 destroy_material(background);
8361 IDirectDrawSurface_Release(rt);
8362 refcount = IDirect3DDevice_Release(device);
8363 ok(!refcount, "Device has %u references left.\n", refcount);
8364 IDirectDraw_Release(ddraw);
8365 DestroyWindow(window);
8368 static void test_lockrect_invalid(void)
8370 unsigned int i, r;
8371 IDirectDraw *ddraw;
8372 IDirectDrawSurface *surface;
8373 HWND window;
8374 HRESULT hr;
8375 DDSURFACEDESC surface_desc;
8376 DDCAPS hal_caps;
8377 DWORD needed_caps = DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY;
8378 static RECT valid[] =
8380 {60, 60, 68, 68},
8381 {60, 60, 60, 68},
8382 {60, 60, 68, 60},
8383 {120, 60, 128, 68},
8384 {60, 120, 68, 128},
8386 static RECT invalid[] =
8388 {68, 60, 60, 68}, /* left > right */
8389 {60, 68, 68, 60}, /* top > bottom */
8390 {-8, 60, 0, 68}, /* left < surface */
8391 {60, -8, 68, 0}, /* top < surface */
8392 {-16, 60, -8, 68}, /* right < surface */
8393 {60, -16, 68, -8}, /* bottom < surface */
8394 {60, 60, 136, 68}, /* right > surface */
8395 {60, 60, 68, 136}, /* bottom > surface */
8396 {136, 60, 144, 68}, /* left > surface */
8397 {60, 136, 68, 144}, /* top > surface */
8399 static const struct
8401 DWORD caps;
8402 const char *name;
8403 HRESULT hr;
8405 resources[] =
8407 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY, "sysmem offscreenplain", DDERR_INVALIDPARAMS},
8408 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, "vidmem offscreenplain", DDERR_INVALIDPARAMS},
8409 {DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, "sysmem texture", DDERR_INVALIDPARAMS},
8410 {DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, "vidmem texture", DDERR_INVALIDPARAMS},
8413 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
8414 0, 0, 640, 480, 0, 0, 0, 0);
8415 ddraw = create_ddraw();
8416 ok(!!ddraw, "Failed to create a ddraw object.\n");
8417 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
8418 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
8420 memset(&hal_caps, 0, sizeof(hal_caps));
8421 hal_caps.dwSize = sizeof(hal_caps);
8422 hr = IDirectDraw_GetCaps(ddraw, &hal_caps, NULL);
8423 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
8424 if ((hal_caps.ddsCaps.dwCaps & needed_caps) != needed_caps)
8426 skip("Required surface types not supported, skipping test.\n");
8427 goto done;
8430 for (r = 0; r < sizeof(resources) / sizeof(*resources); ++r)
8432 memset(&surface_desc, 0, sizeof(surface_desc));
8433 surface_desc.dwSize = sizeof(surface_desc);
8434 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
8435 surface_desc.ddsCaps.dwCaps = resources[r].caps;
8436 surface_desc.dwWidth = 128;
8437 surface_desc.dwHeight = 128;
8438 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
8439 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB;
8440 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount = 32;
8441 U2(surface_desc.ddpfPixelFormat).dwRBitMask = 0xff0000;
8442 U3(surface_desc.ddpfPixelFormat).dwGBitMask = 0x00ff00;
8443 U4(surface_desc.ddpfPixelFormat).dwBBitMask = 0x0000ff;
8445 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8446 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x, type %s.\n", hr, resources[r].name);
8448 hr = IDirectDrawSurface_Lock(surface, NULL, NULL, DDLOCK_WAIT, NULL);
8449 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x, type %s.\n", hr, resources[r].name);
8451 for (i = 0; i < sizeof(valid) / sizeof(*valid); ++i)
8453 RECT *rect = &valid[i];
8455 memset(&surface_desc, 0, sizeof(surface_desc));
8456 surface_desc.dwSize = sizeof(surface_desc);
8458 hr = IDirectDrawSurface_Lock(surface, rect, &surface_desc, DDLOCK_WAIT, NULL);
8459 ok(SUCCEEDED(hr), "Lock failed (%#x) for rect %s, type %s.\n",
8460 hr, wine_dbgstr_rect(rect), resources[r].name);
8462 hr = IDirectDrawSurface_Unlock(surface, NULL);
8463 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
8466 for (i = 0; i < sizeof(invalid) / sizeof(*invalid); ++i)
8468 RECT *rect = &invalid[i];
8470 memset(&surface_desc, 1, sizeof(surface_desc));
8471 surface_desc.dwSize = sizeof(surface_desc);
8473 hr = IDirectDrawSurface_Lock(surface, rect, &surface_desc, DDLOCK_WAIT, NULL);
8474 ok(hr == resources[r].hr, "Lock returned %#x for rect %s, type %s.\n",
8475 hr, wine_dbgstr_rect(rect), resources[r].name);
8476 if (SUCCEEDED(hr))
8478 hr = IDirectDrawSurface_Unlock(surface, NULL);
8479 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
8481 else
8482 ok(!surface_desc.lpSurface, "Got unexpected lpSurface %p.\n", surface_desc.lpSurface);
8485 hr = IDirectDrawSurface_Lock(surface, NULL, &surface_desc, DDLOCK_WAIT, NULL);
8486 ok(SUCCEEDED(hr), "Lock(rect = NULL) failed, hr %#x, type %s.\n",
8487 hr, resources[r].name);
8488 hr = IDirectDrawSurface_Lock(surface, NULL, &surface_desc, DDLOCK_WAIT, NULL);
8489 ok(hr == DDERR_SURFACEBUSY, "Double lock(rect = NULL) returned %#x, type %s.\n",
8490 hr, resources[r].name);
8491 hr = IDirectDrawSurface_Unlock(surface, NULL);
8492 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
8494 hr = IDirectDrawSurface_Lock(surface, &valid[0], &surface_desc, DDLOCK_WAIT, NULL);
8495 ok(SUCCEEDED(hr), "Lock(rect = %s) failed (%#x).\n", wine_dbgstr_rect(&valid[0]), hr);
8496 hr = IDirectDrawSurface_Lock(surface, &valid[0], &surface_desc, DDLOCK_WAIT, NULL);
8497 ok(hr == DDERR_SURFACEBUSY, "Double lock(rect = %s) failed (%#x).\n",
8498 wine_dbgstr_rect(&valid[0]), hr);
8500 /* Locking a different rectangle returns DD_OK, but it seems to break the surface.
8501 * Afterwards unlocking the surface fails(NULL rectangle or both locked rectangles) */
8503 hr = IDirectDrawSurface_Unlock(surface, NULL);
8504 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
8506 IDirectDrawSurface_Release(surface);
8509 done:
8510 IDirectDraw_Release(ddraw);
8511 DestroyWindow(window);
8514 static void test_yv12_overlay(void)
8516 IDirectDrawSurface *src_surface, *dst_surface;
8517 RECT rect = {13, 17, 14, 18};
8518 unsigned int offset, y;
8519 unsigned char *base;
8520 DDSURFACEDESC desc;
8521 IDirectDraw *ddraw;
8522 HWND window;
8523 HRESULT hr;
8525 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
8526 0, 0, 640, 480, 0, 0, 0, 0);
8527 ddraw = create_ddraw();
8528 ok(!!ddraw, "Failed to create a ddraw object.\n");
8529 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
8530 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
8532 if (!(src_surface = create_overlay(ddraw, 256, 256, MAKEFOURCC('Y','V','1','2'))))
8534 skip("Failed to create a YV12 overlay, skipping test.\n");
8535 goto done;
8538 memset(&desc, 0, sizeof(desc));
8539 desc.dwSize = sizeof(desc);
8540 hr = IDirectDrawSurface_Lock(src_surface, NULL, &desc, DDLOCK_WAIT, NULL);
8541 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
8543 ok(desc.dwFlags == (DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_PITCH),
8544 "Got unexpected flags %#x.\n", desc.dwFlags);
8545 ok(desc.ddsCaps.dwCaps == (DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM | DDSCAPS_HWCODEC)
8546 || desc.ddsCaps.dwCaps == (DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM),
8547 "Got unexpected caps %#x.\n", desc.ddsCaps.dwCaps);
8548 ok(desc.dwWidth == 256, "Got unexpected width %u.\n", desc.dwWidth);
8549 ok(desc.dwHeight == 256, "Got unexpected height %u.\n", desc.dwHeight);
8550 /* The overlay pitch seems to have 256 byte alignment. */
8551 ok(!(U1(desc).lPitch & 0xff), "Got unexpected pitch %u.\n", U1(desc).lPitch);
8553 /* Fill the surface with some data for the blit test. */
8554 base = desc.lpSurface;
8555 /* Luminance */
8556 for (y = 0; y < desc.dwHeight; ++y)
8558 memset(base + U1(desc).lPitch * y, 0x10, desc.dwWidth);
8560 /* V */
8561 for (; y < desc.dwHeight + desc.dwHeight / 4; ++y)
8563 memset(base + U1(desc).lPitch * y, 0x20, desc.dwWidth);
8565 /* U */
8566 for (; y < desc.dwHeight + desc.dwHeight / 2; ++y)
8568 memset(base + U1(desc).lPitch * y, 0x30, desc.dwWidth);
8571 hr = IDirectDrawSurface_Unlock(src_surface, NULL);
8572 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
8574 /* YV12 uses 2x2 blocks with 6 bytes per block (4*Y, 1*U, 1*V). Unlike
8575 * other block-based formats like DXT the entire Y channel is stored in
8576 * one big chunk of memory, followed by the chroma channels. So partial
8577 * locks do not really make sense. Show that they are allowed nevertheless
8578 * and the offset points into the luminance data. */
8579 hr = IDirectDrawSurface_Lock(src_surface, &rect, &desc, DDLOCK_WAIT, NULL);
8580 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
8581 offset = ((const unsigned char *)desc.lpSurface - base);
8582 ok(offset == rect.top * U1(desc).lPitch + rect.left, "Got unexpected offset %u, expected %u.\n",
8583 offset, rect.top * U1(desc).lPitch + rect.left);
8584 hr = IDirectDrawSurface_Unlock(src_surface, NULL);
8585 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
8587 if (!(dst_surface = create_overlay(ddraw, 256, 256, MAKEFOURCC('Y','V','1','2'))))
8589 /* Windows XP with a Radeon X1600 GPU refuses to create a second
8590 * overlay surface, DDERR_NOOVERLAYHW, making the blit tests moot. */
8591 skip("Failed to create a second YV12 surface, skipping blit test.\n");
8592 IDirectDrawSurface_Release(src_surface);
8593 goto done;
8596 hr = IDirectDrawSurface_Blt(dst_surface, NULL, src_surface, NULL, DDBLT_WAIT, NULL);
8597 /* VMware rejects YV12 blits. This behavior has not been seen on real
8598 * hardware yet, so mark it broken. */
8599 ok(SUCCEEDED(hr) || broken(hr == E_NOTIMPL), "Failed to blit, hr %#x.\n", hr);
8601 if (SUCCEEDED(hr))
8603 memset(&desc, 0, sizeof(desc));
8604 desc.dwSize = sizeof(desc);
8605 hr = IDirectDrawSurface_Lock(dst_surface, NULL, &desc, DDLOCK_WAIT, NULL);
8606 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
8608 base = desc.lpSurface;
8609 ok(base[0] == 0x10, "Got unexpected Y data 0x%02x.\n", base[0]);
8610 base += desc.dwHeight * U1(desc).lPitch;
8611 todo_wine ok(base[0] == 0x20, "Got unexpected V data 0x%02x.\n", base[0]);
8612 base += desc.dwHeight / 4 * U1(desc).lPitch;
8613 todo_wine ok(base[0] == 0x30, "Got unexpected U data 0x%02x.\n", base[0]);
8615 hr = IDirectDrawSurface_Unlock(dst_surface, NULL);
8616 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
8619 IDirectDrawSurface_Release(dst_surface);
8620 IDirectDrawSurface_Release(src_surface);
8621 done:
8622 IDirectDraw_Release(ddraw);
8623 DestroyWindow(window);
8626 static BOOL dwm_enabled(void)
8628 BOOL ret = FALSE;
8630 if (!strcmp(winetest_platform, "wine"))
8631 return FALSE;
8632 if (!pDwmIsCompositionEnabled)
8633 return FALSE;
8634 if (FAILED(pDwmIsCompositionEnabled(&ret)))
8635 return FALSE;
8636 return ret;
8639 static void test_offscreen_overlay(void)
8641 IDirectDrawSurface *overlay, *offscreen, *primary;
8642 DDSURFACEDESC surface_desc;
8643 IDirectDraw *ddraw;
8644 HWND window;
8645 HRESULT hr;
8646 HDC dc;
8648 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
8649 0, 0, 640, 480, 0, 0, 0, 0);
8650 ddraw = create_ddraw();
8651 ok(!!ddraw, "Failed to create a ddraw object.\n");
8652 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
8653 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
8655 if (!(overlay = create_overlay(ddraw, 64, 64, MAKEFOURCC('U','Y','V','Y'))))
8657 skip("Failed to create a UYVY overlay, skipping test.\n");
8658 goto done;
8661 memset(&surface_desc, 0, sizeof(surface_desc));
8662 surface_desc.dwSize = sizeof(surface_desc);
8663 surface_desc.dwFlags = DDSD_CAPS;
8664 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
8665 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &primary, NULL);
8666 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
8668 /* On Windows 7, and probably Vista, UpdateOverlay() will return
8669 * DDERR_OUTOFCAPS if the dwm is active. Calling GetDC() on the primary
8670 * surface prevents this by disabling the dwm. */
8671 hr = IDirectDrawSurface_GetDC(primary, &dc);
8672 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
8673 hr = IDirectDrawSurface_ReleaseDC(primary, dc);
8674 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
8676 /* Try to overlay a NULL surface. */
8677 hr = IDirectDrawSurface_UpdateOverlay(overlay, NULL, NULL, NULL, DDOVER_SHOW, NULL);
8678 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
8679 hr = IDirectDrawSurface_UpdateOverlay(overlay, NULL, NULL, NULL, DDOVER_HIDE, NULL);
8680 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
8682 /* Try to overlay an offscreen surface. */
8683 memset(&surface_desc, 0, sizeof(surface_desc));
8684 surface_desc.dwSize = sizeof(surface_desc);
8685 surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
8686 surface_desc.dwWidth = 64;
8687 surface_desc.dwHeight = 64;
8688 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
8689 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
8690 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB;
8691 surface_desc.ddpfPixelFormat.dwFourCC = 0;
8692 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount = 16;
8693 U2(surface_desc.ddpfPixelFormat).dwRBitMask = 0xf800;
8694 U3(surface_desc.ddpfPixelFormat).dwGBitMask = 0x07e0;
8695 U4(surface_desc.ddpfPixelFormat).dwBBitMask = 0x001f;
8696 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &offscreen, NULL);
8697 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
8699 hr = IDirectDrawSurface_UpdateOverlay(overlay, NULL, offscreen, NULL, DDOVER_SHOW, NULL);
8700 ok(SUCCEEDED(hr) || broken(hr == DDERR_OUTOFCAPS && dwm_enabled()),
8701 "Failed to update overlay, hr %#x.\n", hr);
8703 /* Try to overlay the primary with a non-overlay surface. */
8704 hr = IDirectDrawSurface_UpdateOverlay(offscreen, NULL, primary, NULL, DDOVER_SHOW, NULL);
8705 ok(hr == DDERR_NOTAOVERLAYSURFACE, "Got unexpected hr %#x.\n", hr);
8706 hr = IDirectDrawSurface_UpdateOverlay(offscreen, NULL, primary, NULL, DDOVER_HIDE, NULL);
8707 ok(hr == DDERR_NOTAOVERLAYSURFACE, "Got unexpected hr %#x.\n", hr);
8709 IDirectDrawSurface_Release(offscreen);
8710 IDirectDrawSurface_Release(primary);
8711 IDirectDrawSurface_Release(overlay);
8712 done:
8713 IDirectDraw_Release(ddraw);
8714 DestroyWindow(window);
8717 static void test_overlay_rect(void)
8719 IDirectDrawSurface *overlay, *primary = NULL;
8720 DDSURFACEDESC surface_desc;
8721 RECT rect = {0, 0, 64, 64};
8722 IDirectDraw *ddraw;
8723 LONG pos_x, pos_y;
8724 HRESULT hr, hr2;
8725 HWND window;
8726 HDC dc;
8728 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
8729 0, 0, 640, 480, 0, 0, 0, 0);
8730 ddraw = create_ddraw();
8731 ok(!!ddraw, "Failed to create a ddraw object.\n");
8732 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
8733 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
8735 if (!(overlay = create_overlay(ddraw, 64, 64, MAKEFOURCC('U','Y','V','Y'))))
8737 skip("Failed to create a UYVY overlay, skipping test.\n");
8738 goto done;
8741 memset(&surface_desc, 0, sizeof(surface_desc));
8742 surface_desc.dwSize = sizeof(surface_desc);
8743 surface_desc.dwFlags = DDSD_CAPS;
8744 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
8745 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &primary, NULL);
8746 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
8748 /* On Windows 7, and probably Vista, UpdateOverlay() will return
8749 * DDERR_OUTOFCAPS if the dwm is active. Calling GetDC() on the primary
8750 * surface prevents this by disabling the dwm. */
8751 hr = IDirectDrawSurface_GetDC(primary, &dc);
8752 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
8753 hr = IDirectDrawSurface_ReleaseDC(primary, dc);
8754 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
8756 /* On Windows 8 and newer DWM can't be turned off, making overlays unusable. */
8757 if (dwm_enabled())
8759 win_skip("Cannot disable DWM, skipping overlay test.\n");
8760 goto done;
8763 /* The dx sdk sort of implies that rect must be set when DDOVER_SHOW is
8764 * used. This is not true in Windows Vista and earlier, but changed in
8765 * Windows 7. */
8766 hr = IDirectDrawSurface_UpdateOverlay(overlay, NULL, primary, &rect, DDOVER_SHOW, NULL);
8767 ok(SUCCEEDED(hr), "Failed to update overlay, hr %#x.\n", hr);
8768 hr = IDirectDrawSurface_UpdateOverlay(overlay, NULL, primary, NULL, DDOVER_HIDE, NULL);
8769 ok(SUCCEEDED(hr), "Failed to update overlay, hr %#x.\n", hr);
8770 hr = IDirectDrawSurface_UpdateOverlay(overlay, NULL, primary, NULL, DDOVER_SHOW, NULL);
8771 ok(hr == DD_OK || hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
8773 /* Show that the overlay position is the (top, left) coordinate of the
8774 * destination rectangle. */
8775 OffsetRect(&rect, 32, 16);
8776 hr = IDirectDrawSurface_UpdateOverlay(overlay, NULL, primary, &rect, DDOVER_SHOW, NULL);
8777 ok(SUCCEEDED(hr), "Failed to update overlay, hr %#x.\n", hr);
8778 pos_x = -1; pos_y = -1;
8779 hr = IDirectDrawSurface_GetOverlayPosition(overlay, &pos_x, &pos_y);
8780 ok(SUCCEEDED(hr), "Failed to get overlay position, hr %#x.\n", hr);
8781 ok(pos_x == rect.left, "Got unexpected pos_x %d, expected %d.\n", pos_x, rect.left);
8782 ok(pos_y == rect.top, "Got unexpected pos_y %d, expected %d.\n", pos_y, rect.top);
8784 /* Passing a NULL dest rect sets the position to 0/0. Visually it can be
8785 * seen that the overlay overlays the whole primary(==screen). */
8786 hr2 = IDirectDrawSurface_UpdateOverlay(overlay, NULL, primary, NULL, 0, NULL);
8787 ok(hr2 == DD_OK || hr2 == DDERR_INVALIDPARAMS || hr2 == DDERR_OUTOFCAPS, "Got unexpected hr %#x.\n", hr2);
8788 hr = IDirectDrawSurface_GetOverlayPosition(overlay, &pos_x, &pos_y);
8789 ok(SUCCEEDED(hr), "Failed to get overlay position, hr %#x.\n", hr);
8790 if (SUCCEEDED(hr2))
8792 ok(!pos_x, "Got unexpected pos_x %d.\n", pos_x);
8793 ok(!pos_y, "Got unexpected pos_y %d.\n", pos_y);
8795 else
8797 ok(pos_x == 32, "Got unexpected pos_x %d.\n", pos_x);
8798 ok(pos_y == 16, "Got unexpected pos_y %d.\n", pos_y);
8801 /* The position cannot be retrieved when the overlay is not shown. */
8802 hr = IDirectDrawSurface_UpdateOverlay(overlay, NULL, primary, &rect, DDOVER_HIDE, NULL);
8803 ok(SUCCEEDED(hr), "Failed to update overlay, hr %#x.\n", hr);
8804 pos_x = -1; pos_y = -1;
8805 hr = IDirectDrawSurface_GetOverlayPosition(overlay, &pos_x, &pos_y);
8806 ok(hr == DDERR_OVERLAYNOTVISIBLE, "Got unexpected hr %#x.\n", hr);
8807 ok(!pos_x, "Got unexpected pos_x %d.\n", pos_x);
8808 ok(!pos_y, "Got unexpected pos_y %d.\n", pos_y);
8810 IDirectDrawSurface_Release(overlay);
8811 done:
8812 if (primary)
8813 IDirectDrawSurface_Release(primary);
8814 IDirectDraw_Release(ddraw);
8815 DestroyWindow(window);
8818 static void test_blt(void)
8820 IDirectDrawSurface *surface, *rt;
8821 DDSURFACEDESC surface_desc;
8822 IDirect3DDevice *device;
8823 IDirectDraw *ddraw;
8824 unsigned int i;
8825 ULONG refcount;
8826 HWND window;
8827 HRESULT hr;
8829 static struct
8831 RECT src_rect;
8832 RECT dst_rect;
8833 HRESULT hr;
8835 test_data[] =
8837 {{160, 0, 640, 480}, { 0, 0, 480, 480}, DD_OK}, /* Overlapped blit. */
8838 {{160, 480, 640, 0}, { 0, 0, 480, 480}, DDERR_INVALIDRECT}, /* Overlapped blit, flipped source. */
8839 {{640, 0, 160, 480}, { 0, 0, 480, 480}, DDERR_INVALIDRECT}, /* Overlapped blit, mirrored source. */
8840 {{160, 0, 480, 480}, { 0, 0, 480, 480}, DD_OK}, /* Overlapped blit, stretched x. */
8841 {{160, 160, 640, 480}, { 0, 0, 480, 480}, DD_OK}, /* Overlapped blit, stretched y. */
8842 {{ 0, 0, 640, 480}, { 0, 0, 640, 480}, DD_OK}, /* Full surface blit. */
8843 {{ 0, 0, 640, 480}, { 0, 480, 640, 0}, DDERR_INVALIDRECT}, /* Full surface, flipped destination. */
8844 {{ 0, 0, 640, 480}, {640, 0, 0, 480}, DDERR_INVALIDRECT}, /* Full surface, mirrored destination. */
8845 {{ 0, 480, 640, 0}, { 0, 0, 640, 480}, DDERR_INVALIDRECT}, /* Full surface, flipped source. */
8846 {{640, 0, 0, 480}, { 0, 0, 640, 480}, DDERR_INVALIDRECT}, /* Full surface, mirrored source. */
8849 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
8850 0, 0, 640, 480, 0, 0, 0, 0);
8851 ddraw = create_ddraw();
8852 ok(!!ddraw, "Failed to create a ddraw object.\n");
8853 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
8855 skip("Failed to create a 3D device, skipping test.\n");
8856 IDirectDraw_Release(ddraw);
8857 DestroyWindow(window);
8858 return;
8861 hr = IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&rt);
8862 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
8864 memset(&surface_desc, 0, sizeof(surface_desc));
8865 surface_desc.dwSize = sizeof(surface_desc);
8866 surface_desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
8867 surface_desc.dwWidth = 640;
8868 surface_desc.dwHeight = 480;
8869 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
8870 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8871 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8873 hr = IDirectDrawSurface_Blt(surface, NULL, surface, NULL, 0, NULL);
8874 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
8876 hr = IDirectDrawSurface_Blt(surface, NULL, rt, NULL, 0, NULL);
8877 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
8879 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
8881 hr = IDirectDrawSurface_Blt(surface, &test_data[i].dst_rect,
8882 surface, &test_data[i].src_rect, DDBLT_WAIT, NULL);
8883 ok(hr == test_data[i].hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, test_data[i].hr);
8885 hr = IDirectDrawSurface_Blt(surface, &test_data[i].dst_rect,
8886 rt, &test_data[i].src_rect, DDBLT_WAIT, NULL);
8887 ok(hr == test_data[i].hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, test_data[i].hr);
8890 IDirectDrawSurface_Release(surface);
8891 IDirectDrawSurface_Release(rt);
8892 refcount = IDirect3DDevice_Release(device);
8893 ok(!refcount, "Device has %u references left.\n", refcount);
8894 IDirectDraw_Release(ddraw);
8895 DestroyWindow(window);
8898 static void test_getdc(void)
8900 IDirectDrawSurface *surface, *surface2, *tmp;
8901 DDSURFACEDESC surface_desc, map_desc;
8902 DDSCAPS caps = {DDSCAPS_COMPLEX};
8903 IDirectDraw *ddraw;
8904 unsigned int i;
8905 HWND window;
8906 HDC dc, dc2;
8907 HRESULT hr;
8909 static const struct
8911 const char *name;
8912 DDPIXELFORMAT format;
8913 BOOL getdc_supported;
8914 HRESULT alt_result;
8916 test_data[] =
8918 {"D3DFMT_A8R8G8B8", {sizeof(test_data->format), DDPF_RGB | DDPF_ALPHAPIXELS, 0, {32},
8919 {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}}, TRUE},
8920 {"D3DFMT_X8R8G8B8", {sizeof(test_data->format), DDPF_RGB, 0, {32},
8921 {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0x00000000}}, TRUE},
8922 {"D3DFMT_R5G6B5", {sizeof(test_data->format), DDPF_RGB, 0, {16},
8923 {0x0000f800}, {0x000007e0}, {0x0000001f}, {0x00000000}}, TRUE},
8924 {"D3DFMT_X1R5G5B5", {sizeof(test_data->format), DDPF_RGB, 0, {16},
8925 {0x00007c00}, {0x000003e0}, {0x0000001f}, {0x00000000}}, TRUE},
8926 {"D3DFMT_A1R5G5B5", {sizeof(test_data->format), DDPF_RGB | DDPF_ALPHAPIXELS, 0, {16},
8927 {0x00007c00}, {0x000003e0}, {0x0000001f}, {0x00008000}}, TRUE},
8928 {"D3DFMT_A4R4G4B4", {sizeof(test_data->format), DDPF_RGB | DDPF_ALPHAPIXELS, 0, {16},
8929 {0x00000f00}, {0x000000f0}, {0x0000000f}, {0x0000f000}}, TRUE, DDERR_CANTCREATEDC /* Vista+ */},
8930 {"D3DFMT_X4R4G4B4", {sizeof(test_data->format), DDPF_RGB, 0, {16},
8931 {0x00000f00}, {0x000000f0}, {0x0000000f}, {0x00000000}}, TRUE, DDERR_CANTCREATEDC /* Vista+ */},
8932 {"D3DFMT_A2R10G10B10", {sizeof(test_data->format), DDPF_RGB | DDPF_ALPHAPIXELS, 0, {32},
8933 {0xc0000000}, {0x3ff00000}, {0x000ffc00}, {0x000003ff}}, TRUE},
8934 {"D3DFMT_A8B8G8R8", {sizeof(test_data->format), DDPF_RGB | DDPF_ALPHAPIXELS, 0, {32},
8935 {0x000000ff}, {0x0000ff00}, {0x00ff0000}, {0xff000000}}, TRUE, DDERR_CANTCREATEDC /* Vista+ */},
8936 {"D3DFMT_X8B8G8R8", {sizeof(test_data->format), DDPF_RGB, 0, {32},
8937 {0x000000ff}, {0x0000ff00}, {0x00ff0000}, {0x00000000}}, TRUE, DDERR_CANTCREATEDC /* Vista+ */},
8938 {"D3DFMT_R3G3B2", {sizeof(test_data->format), DDPF_RGB, 0, {8},
8939 {0x000000e0}, {0x0000001c}, {0x00000003}, {0x00000000}}, FALSE},
8940 /* GetDC() on a P8 surface fails unless the display mode is 8 bpp.
8941 * This is not implemented in wine yet, so disable the test for now.
8942 * Succeeding P8 GetDC() calls are tested in the ddraw:visual test.
8943 {"D3DFMT_P8", {sizeof(test_data->format), DDPF_PALETTEINDEXED8 | DDPF_RGB, 0, {8 },
8944 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
8946 {"D3DFMT_L8", {sizeof(test_data->format), DDPF_LUMINANCE, 0, {8},
8947 {0x000000ff}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
8948 {"D3DFMT_A8L8", {sizeof(test_data->format), DDPF_ALPHAPIXELS | DDPF_LUMINANCE, 0, {16},
8949 {0x000000ff}, {0x00000000}, {0x00000000}, {0x0000ff00}}, FALSE},
8950 {"D3DFMT_DXT1", {sizeof(test_data->format), DDPF_FOURCC, MAKEFOURCC('D','X','T','1'), {0},
8951 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
8952 {"D3DFMT_DXT2", {sizeof(test_data->format), DDPF_FOURCC, MAKEFOURCC('D','X','T','2'), {0},
8953 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
8954 {"D3DFMT_DXT3", {sizeof(test_data->format), DDPF_FOURCC, MAKEFOURCC('D','X','T','3'), {0},
8955 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
8956 {"D3DFMT_DXT4", {sizeof(test_data->format), DDPF_FOURCC, MAKEFOURCC('D','X','T','4'), {0},
8957 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
8958 {"D3DFMT_DXT5", {sizeof(test_data->format), DDPF_FOURCC, MAKEFOURCC('D','X','T','5'), {0},
8959 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
8962 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
8963 0, 0, 640, 480, 0, 0, 0, 0);
8964 ddraw = create_ddraw();
8965 ok(!!ddraw, "Failed to create a ddraw object.\n");
8966 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
8967 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
8969 for (i = 0; i < (sizeof(test_data) / sizeof(*test_data)); ++i)
8971 memset(&surface_desc, 0, sizeof(surface_desc));
8972 surface_desc.dwSize = sizeof(surface_desc);
8973 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
8974 surface_desc.dwWidth = 64;
8975 surface_desc.dwHeight = 64;
8976 surface_desc.ddpfPixelFormat = test_data[i].format;
8977 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
8979 if (FAILED(IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL)))
8981 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
8982 if (FAILED(hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL)))
8984 skip("Failed to create surface for format %s (hr %#x), skipping tests.\n", test_data[i].name, hr);
8985 continue;
8989 dc = (void *)0x1234;
8990 hr = IDirectDrawSurface_GetDC(surface, &dc);
8991 if (test_data[i].getdc_supported)
8992 ok(SUCCEEDED(hr) || (test_data[i].alt_result && hr == test_data[i].alt_result),
8993 "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
8994 else
8995 ok(FAILED(hr), "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
8997 if (SUCCEEDED(hr))
8999 unsigned int width_bytes;
9000 DIBSECTION dib;
9001 HBITMAP bitmap;
9002 DWORD type;
9003 int size;
9005 type = GetObjectType(dc);
9006 ok(type == OBJ_MEMDC, "Got unexpected object type %#x for format %s.\n", type, test_data[i].name);
9007 bitmap = GetCurrentObject(dc, OBJ_BITMAP);
9008 type = GetObjectType(bitmap);
9009 ok(type == OBJ_BITMAP, "Got unexpected object type %#x for format %s.\n", type, test_data[i].name);
9011 size = GetObjectA(bitmap, sizeof(dib), &dib);
9012 ok(size == sizeof(dib), "Got unexpected size %d for format %s.\n", size, test_data[i].name);
9013 ok(!dib.dsBm.bmType, "Got unexpected type %#x for format %s.\n",
9014 dib.dsBm.bmType, test_data[i].name);
9015 ok(dib.dsBm.bmWidth == surface_desc.dwWidth, "Got unexpected width %d for format %s.\n",
9016 dib.dsBm.bmWidth, test_data[i].name);
9017 ok(dib.dsBm.bmHeight == surface_desc.dwHeight, "Got unexpected height %d for format %s.\n",
9018 dib.dsBm.bmHeight, test_data[i].name);
9019 width_bytes = ((dib.dsBm.bmWidth * U1(test_data[i].format).dwRGBBitCount + 31) >> 3) & ~3;
9020 ok(dib.dsBm.bmWidthBytes == width_bytes, "Got unexpected width bytes %d for format %s.\n",
9021 dib.dsBm.bmWidthBytes, test_data[i].name);
9022 ok(dib.dsBm.bmPlanes == 1, "Got unexpected plane count %d for format %s.\n",
9023 dib.dsBm.bmPlanes, test_data[i].name);
9024 ok(dib.dsBm.bmBitsPixel == U1(test_data[i].format).dwRGBBitCount,
9025 "Got unexpected bit count %d for format %s.\n",
9026 dib.dsBm.bmBitsPixel, test_data[i].name);
9027 ok(!!dib.dsBm.bmBits, "Got unexpected bits %p for format %s.\n",
9028 dib.dsBm.bmBits, test_data[i].name);
9030 ok(dib.dsBmih.biSize == sizeof(dib.dsBmih), "Got unexpected size %u for format %s.\n",
9031 dib.dsBmih.biSize, test_data[i].name);
9032 ok(dib.dsBmih.biWidth == surface_desc.dwWidth, "Got unexpected width %d for format %s.\n",
9033 dib.dsBmih.biHeight, test_data[i].name);
9034 ok(dib.dsBmih.biHeight == surface_desc.dwHeight, "Got unexpected height %d for format %s.\n",
9035 dib.dsBmih.biHeight, test_data[i].name);
9036 ok(dib.dsBmih.biPlanes == 1, "Got unexpected plane count %u for format %s.\n",
9037 dib.dsBmih.biPlanes, test_data[i].name);
9038 ok(dib.dsBmih.biBitCount == U1(test_data[i].format).dwRGBBitCount,
9039 "Got unexpected bit count %u for format %s.\n",
9040 dib.dsBmih.biBitCount, test_data[i].name);
9041 ok(dib.dsBmih.biCompression == (U1(test_data[i].format).dwRGBBitCount == 16 ? BI_BITFIELDS : BI_RGB)
9042 || broken(U1(test_data[i].format).dwRGBBitCount == 32 && dib.dsBmih.biCompression == BI_BITFIELDS),
9043 "Got unexpected compression %#x for format %s.\n",
9044 dib.dsBmih.biCompression, test_data[i].name);
9045 ok(!dib.dsBmih.biSizeImage, "Got unexpected image size %u for format %s.\n",
9046 dib.dsBmih.biSizeImage, test_data[i].name);
9047 ok(!dib.dsBmih.biXPelsPerMeter, "Got unexpected horizontal resolution %d for format %s.\n",
9048 dib.dsBmih.biXPelsPerMeter, test_data[i].name);
9049 ok(!dib.dsBmih.biYPelsPerMeter, "Got unexpected vertical resolution %d for format %s.\n",
9050 dib.dsBmih.biYPelsPerMeter, test_data[i].name);
9051 ok(!dib.dsBmih.biClrUsed, "Got unexpected used colour count %u for format %s.\n",
9052 dib.dsBmih.biClrUsed, test_data[i].name);
9053 ok(!dib.dsBmih.biClrImportant, "Got unexpected important colour count %u for format %s.\n",
9054 dib.dsBmih.biClrImportant, test_data[i].name);
9056 if (dib.dsBmih.biCompression == BI_BITFIELDS)
9058 ok((dib.dsBitfields[0] == U2(test_data[i].format).dwRBitMask
9059 && dib.dsBitfields[1] == U3(test_data[i].format).dwGBitMask
9060 && dib.dsBitfields[2] == U4(test_data[i].format).dwBBitMask)
9061 || broken(!dib.dsBitfields[0] && !dib.dsBitfields[1] && !dib.dsBitfields[2]),
9062 "Got unexpected colour masks 0x%08x 0x%08x 0x%08x for format %s.\n",
9063 dib.dsBitfields[0], dib.dsBitfields[1], dib.dsBitfields[2], test_data[i].name);
9065 else
9067 ok(!dib.dsBitfields[0] && !dib.dsBitfields[1] && !dib.dsBitfields[2],
9068 "Got unexpected colour masks 0x%08x 0x%08x 0x%08x for format %s.\n",
9069 dib.dsBitfields[0], dib.dsBitfields[1], dib.dsBitfields[2], test_data[i].name);
9071 ok(!dib.dshSection, "Got unexpected section %p for format %s.\n", dib.dshSection, test_data[i].name);
9072 ok(!dib.dsOffset, "Got unexpected offset %u for format %s.\n", dib.dsOffset, test_data[i].name);
9074 hr = IDirectDrawSurface_ReleaseDC(surface, dc);
9075 ok(hr == DD_OK, "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
9077 else
9079 ok(!dc, "Got unexpected dc %p for format %s.\n", dc, test_data[i].name);
9082 IDirectDrawSurface_Release(surface);
9084 if (FAILED(hr))
9085 continue;
9087 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
9088 if (FAILED(hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL)))
9090 skip("Failed to create mip-mapped texture for format %s (hr %#x), skipping tests.\n",
9091 test_data[i].name, hr);
9092 continue;
9095 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &tmp);
9096 ok(SUCCEEDED(hr), "Failed to get attached surface for format %s, hr %#x.\n", test_data[i].name, hr);
9097 hr = IDirectDrawSurface_GetAttachedSurface(tmp, &caps, &surface2);
9098 ok(SUCCEEDED(hr), "Failed to get attached surface for format %s, hr %#x.\n", test_data[i].name, hr);
9099 IDirectDrawSurface_Release(tmp);
9101 hr = IDirectDrawSurface_GetDC(surface, &dc);
9102 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
9103 hr = IDirectDrawSurface_ReleaseDC(surface, dc);
9104 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
9105 hr = IDirectDrawSurface_GetDC(surface2, &dc);
9106 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
9107 hr = IDirectDrawSurface_ReleaseDC(surface2, dc);
9108 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
9110 hr = IDirectDrawSurface_GetDC(surface, &dc);
9111 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
9112 dc2 = (void *)0x1234;
9113 hr = IDirectDrawSurface_GetDC(surface, &dc2);
9114 ok(hr == DDERR_DCALREADYCREATED, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
9115 ok(dc2 == (void *)0x1234, "Got unexpected dc %p for format %s.\n", dc, test_data[i].name);
9116 hr = IDirectDrawSurface_ReleaseDC(surface, dc);
9117 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
9118 hr = IDirectDrawSurface_ReleaseDC(surface, dc);
9119 ok(hr == DDERR_NODC, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
9121 map_desc.dwSize = sizeof(map_desc);
9122 hr = IDirectDrawSurface_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
9123 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
9124 hr = IDirectDrawSurface_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
9125 ok(hr == DDERR_SURFACEBUSY, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
9126 hr = IDirectDrawSurface_Unlock(surface, NULL);
9127 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
9128 hr = IDirectDrawSurface_Unlock(surface, NULL);
9129 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
9131 hr = IDirectDrawSurface_GetDC(surface, &dc);
9132 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
9133 hr = IDirectDrawSurface_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
9134 ok(hr == DDERR_SURFACEBUSY, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
9135 hr = IDirectDrawSurface_ReleaseDC(surface, dc);
9136 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
9138 hr = IDirectDrawSurface_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
9139 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
9140 hr = IDirectDrawSurface_GetDC(surface, &dc);
9141 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
9142 hr = IDirectDrawSurface_ReleaseDC(surface, dc);
9143 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
9144 hr = IDirectDrawSurface_Unlock(surface, NULL);
9145 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
9147 hr = IDirectDrawSurface_GetDC(surface, &dc);
9148 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
9149 hr = IDirectDrawSurface_GetDC(surface2, &dc2);
9150 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
9151 hr = IDirectDrawSurface_ReleaseDC(surface2, dc2);
9152 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
9153 hr = IDirectDrawSurface_ReleaseDC(surface, dc);
9154 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
9156 hr = IDirectDrawSurface_GetDC(surface2, &dc);
9157 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
9158 hr = IDirectDrawSurface_GetDC(surface, &dc2);
9159 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
9160 hr = IDirectDrawSurface_ReleaseDC(surface, dc2);
9161 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
9162 hr = IDirectDrawSurface_ReleaseDC(surface2, dc);
9163 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
9165 hr = IDirectDrawSurface_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
9166 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
9167 hr = IDirectDrawSurface_Lock(surface2, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
9168 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
9169 hr = IDirectDrawSurface_Unlock(surface2, NULL);
9170 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
9171 hr = IDirectDrawSurface_Unlock(surface, NULL);
9172 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
9174 hr = IDirectDrawSurface_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
9175 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
9176 hr = IDirectDrawSurface_GetDC(surface, &dc);
9177 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
9178 hr = IDirectDrawSurface_ReleaseDC(surface, dc);
9179 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
9180 hr = IDirectDrawSurface_Unlock(surface, NULL);
9181 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
9183 hr = IDirectDrawSurface_Lock(surface2, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
9184 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
9185 hr = IDirectDrawSurface_GetDC(surface, &dc);
9186 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
9187 hr = IDirectDrawSurface_ReleaseDC(surface, dc);
9188 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
9189 hr = IDirectDrawSurface_Unlock(surface2, NULL);
9190 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
9192 hr = IDirectDrawSurface_GetDC(surface, &dc);
9193 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
9194 hr = IDirectDrawSurface_Lock(surface2, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
9195 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
9196 hr = IDirectDrawSurface_Unlock(surface2, NULL);
9197 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
9198 hr = IDirectDrawSurface_ReleaseDC(surface, dc);
9199 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
9201 hr = IDirectDrawSurface_GetDC(surface2, &dc);
9202 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
9203 hr = IDirectDrawSurface_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
9204 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
9205 hr = IDirectDrawSurface_Unlock(surface, NULL);
9206 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
9207 hr = IDirectDrawSurface_ReleaseDC(surface2, dc);
9208 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
9210 hr = IDirectDrawSurface_Unlock(surface, NULL);
9211 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
9212 hr = IDirectDrawSurface_GetDC(surface2, &dc);
9213 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
9214 hr = IDirectDrawSurface_Unlock(surface, NULL);
9215 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
9216 hr = IDirectDrawSurface_ReleaseDC(surface2, dc);
9217 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
9218 hr = IDirectDrawSurface_Unlock(surface, NULL);
9219 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
9221 hr = IDirectDrawSurface_Unlock(surface2, NULL);
9222 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
9223 hr = IDirectDrawSurface_GetDC(surface, &dc);
9224 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
9225 hr = IDirectDrawSurface_Unlock(surface2, NULL);
9226 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
9227 hr = IDirectDrawSurface_ReleaseDC(surface, dc);
9228 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
9229 hr = IDirectDrawSurface_Unlock(surface2, NULL);
9230 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
9232 IDirectDrawSurface_Release(surface2);
9233 IDirectDrawSurface_Release(surface);
9236 IDirectDraw_Release(ddraw);
9237 DestroyWindow(window);
9240 /* TransformVertices always writes 32 bytes regardless of the input / output stride.
9241 * The stride is honored for navigating to the next vertex. 3 floats input position
9242 * are read, and 16 bytes extra vertex data are copied around. */
9243 struct transform_input
9245 float x, y, z, unused1; /* Position data, transformed. */
9246 DWORD v1, v2, v3, v4; /* Extra data, e.g. color and texture coords, copied. */
9247 DWORD unused2;
9250 struct transform_output
9252 float x, y, z, w;
9253 DWORD v1, v2, v3, v4;
9254 DWORD unused3, unused4;
9257 static void test_transform_vertices(void)
9259 IDirect3DDevice *device;
9260 IDirectDrawSurface *rt;
9261 IDirectDraw *ddraw;
9262 ULONG refcount;
9263 HWND window;
9264 HRESULT hr;
9265 D3DCOLOR color;
9266 IDirect3DViewport *viewport;
9267 IDirect3DExecuteBuffer *execute_buffer;
9268 IDirect3DMaterial *background;
9269 D3DEXECUTEBUFFERDESC exec_desc;
9270 UINT inst_length;
9271 void *ptr;
9272 D3DMATRIXHANDLE world_handle, view_handle, proj_handle;
9273 static struct transform_input position_tests[] =
9275 { 0.0f, 0.0f, 0.0f, 0.0f, 1, 2, 3, 4, 5},
9276 { 1.0f, 1.0f, 1.0f, 8.0f, 6, 7, 8, 9, 10},
9277 {-1.0f, -1.0f, -1.0f, 4.0f, 11, 12, 13, 14, 15},
9278 { 0.5f, 0.5f, 0.5f, 2.0f, 16, 17, 18, 19, 20},
9279 {-0.5f, -0.5f, -0.5f, 1.0f, ~1U, ~2U, ~3U, ~4U, ~5U},
9280 {-0.5f, -0.5f, 0.0f, 0.0f, ~6U, ~7U, ~8U, ~9U, ~0U},
9282 static struct transform_input cliptest[] =
9284 { 25.59f, 25.59f, 1.0f, 0.0f, 1, 2, 3, 4, 5},
9285 { 25.61f, 25.61f, 1.01f, 0.0f, 1, 2, 3, 4, 5},
9286 {-25.59f, -25.59f, 0.0f, 0.0f, 1, 2, 3, 4, 5},
9287 {-25.61f, -25.61f, -0.01f, 0.0f, 1, 2, 3, 4, 5},
9289 static struct transform_input offscreentest[] =
9291 {128.1f, 0.0f, 0.0f, 0.0f, 1, 2, 3, 4, 5},
9293 struct transform_output out[ARRAY_SIZE(position_tests)];
9294 D3DHVERTEX out_h[ARRAY_SIZE(position_tests)];
9295 D3DTRANSFORMDATA transformdata;
9296 static const D3DVIEWPORT vp_template =
9298 sizeof(vp_template), 0, 0, 256, 256, 5.0f, 5.0f, 256.0f, 256.0f, -25.0f, 60.0f
9300 D3DVIEWPORT vp_data =
9302 sizeof(vp_data), 0, 0, 256, 256, 1.0f, 1.0f, 256.0f, 256.0f, 0.0f, 1.0f
9304 unsigned int i;
9305 DWORD offscreen;
9306 static D3DMATRIX mat_scale =
9308 2.0f, 0.0f, 0.0f, 0.0f,
9309 0.0f, 2.0f, 0.0f, 0.0f,
9310 0.0f, 0.0f, 2.0f, 0.0f,
9311 0.0f, 0.0f, 0.0f, 1.0f,
9313 mat_translate1 =
9315 1.0f, 0.0f, 0.0f, 0.0f,
9316 0.0f, 1.0f, 0.0f, 0.0f,
9317 0.0f, 0.0f, 1.0f, 0.0f,
9318 1.0f, 0.0f, 0.0f, 1.0f,
9320 mat_translate2 =
9322 1.0f, 0.0f, 0.0f, 0.0f,
9323 0.0f, 1.0f, 0.0f, 0.0f,
9324 0.0f, 0.0f, 1.0f, 0.0f,
9325 0.0f, 1.0f, 0.0f, 1.0f,
9327 static const D3DLVERTEX quad[] =
9329 {{-0.75f},{-0.5f }, {0.0f}, 0, {0xffff0000}},
9330 {{-0.75f},{ 0.25f}, {0.0f}, 0, {0xffff0000}},
9331 {{ 0.5f}, {-0.5f }, {0.0f}, 0, {0xffff0000}},
9332 {{ 0.5f}, { 0.25f}, {0.0f}, 0, {0xffff0000}},
9334 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
9337 for (i = 0; i < ARRAY_SIZE(out); ++i)
9339 out[i].unused3 = 0xdeadbeef;
9340 out[i].unused4 = 0xcafecafe;
9343 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
9344 0, 0, 640, 480, 0, 0, 0, 0);
9345 ddraw = create_ddraw();
9346 ok(!!ddraw, "Failed to create a ddraw object.\n");
9347 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
9349 skip("Failed to create a 3D device, skipping test.\n");
9350 IDirectDraw_Release(ddraw);
9351 DestroyWindow(window);
9352 return;
9355 hr = IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&rt);
9356 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
9358 viewport = create_viewport(device, 0, 0, 256, 256);
9359 hr = IDirect3DViewport_SetViewport(viewport, &vp_data);
9360 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#x.\n", hr);
9362 memset(&transformdata, 0, sizeof(transformdata));
9363 transformdata.dwSize = sizeof(transformdata);
9364 transformdata.lpIn = position_tests;
9365 transformdata.dwInSize = sizeof(position_tests[0]);
9366 transformdata.lpOut = out;
9367 transformdata.dwOutSize = sizeof(out[0]);
9368 transformdata.lpHOut = NULL;
9370 hr = IDirect3DViewport_TransformVertices(viewport, ARRAY_SIZE(position_tests),
9371 &transformdata, D3DTRANSFORM_UNCLIPPED, &offscreen);
9372 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#x.\n", hr);
9373 ok(!offscreen, "Offscreen is %x.\n", offscreen);
9375 for (i = 0; i < ARRAY_SIZE(position_tests); ++i)
9377 static const struct vec4 cmp[] =
9379 {128.0f, 128.0f, 0.0f, 1.0f}, {129.0f, 127.0f, 1.0f, 1.0f}, {127.0f, 129.0f, -1.0f, 1.0f},
9380 {128.5f, 127.5f, 0.5f, 1.0f}, {127.5f, 128.5f, -0.5f, 1.0f}, {127.5f, 128.5f, 0.0f, 1.0f}
9383 ok(compare_vec4(&cmp[i], out[i].x, out[i].y, out[i].z, out[i].w, 4096),
9384 "Vertex %u differs. Got %f %f %f %f.\n", i,
9385 out[i].x, out[i].y, out[i].z, out[i].w);
9386 ok(out[i].v1 == position_tests[i].v1 && out[i].v2 == position_tests[i].v2
9387 && out[i].v3 == position_tests[i].v3 && out[i].v4 == position_tests[i].v4,
9388 "Vertex %u payload is %u %u %u %u.\n", i, out[i].v1, out[i].v2, out[i].v3, out[i].v4);
9389 ok(out[i].unused3 == 0xdeadbeef && out[i].unused4 == 0xcafecafe,
9390 "Vertex %u unused data is %#x, %#x.\n", i, out[i].unused3, out[i].unused4);
9393 vp_data = vp_template;
9394 hr = IDirect3DViewport_SetViewport(viewport, &vp_data);
9395 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#x.\n", hr);
9396 offscreen = 0xdeadbeef;
9397 hr = IDirect3DViewport_TransformVertices(viewport, ARRAY_SIZE(position_tests),
9398 &transformdata, D3DTRANSFORM_UNCLIPPED, &offscreen);
9399 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#x.\n", hr);
9400 ok(!offscreen, "Offscreen is %x.\n", offscreen);
9402 for (i = 0; i < ARRAY_SIZE(position_tests); ++i)
9404 static const struct vec4 cmp[] =
9406 {128.0f, 128.0f, 0.0f, 1.0f}, {133.0f, 123.0f, 1.0f, 1.0f}, {123.0f, 133.0f, -1.0f, 1.0f},
9407 {130.5f, 125.5f, 0.5f, 1.0f}, {125.5f, 130.5f, -0.5f, 1.0f}, {125.5f, 130.5f, 0.0f, 1.0f}
9409 ok(compare_vec4(&cmp[i], out[i].x, out[i].y, out[i].z, out[i].w, 4096),
9410 "Vertex %u differs. Got %f %f %f %f.\n", i,
9411 out[i].x, out[i].y, out[i].z, out[i].w);
9414 vp_data.dwX = 10;
9415 vp_data.dwY = 20;
9416 hr = IDirect3DViewport_SetViewport(viewport, &vp_data);
9417 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#x.\n", hr);
9418 offscreen = 0xdeadbeef;
9419 hr = IDirect3DViewport_TransformVertices(viewport, ARRAY_SIZE(position_tests),
9420 &transformdata, D3DTRANSFORM_UNCLIPPED, &offscreen);
9421 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#x.\n", hr);
9422 ok(!offscreen, "Offscreen is %x.\n", offscreen);
9423 for (i = 0; i < ARRAY_SIZE(position_tests); ++i)
9425 static const struct vec4 cmp[] =
9427 {138.0f, 148.0f, 0.0f, 1.0f}, {143.0f, 143.0f, 1.0f, 1.0f}, {133.0f, 153.0f, -1.0f, 1.0f},
9428 {140.5f, 145.5f, 0.5f, 1.0f}, {135.5f, 150.5f, -0.5f, 1.0f}, {135.5f, 150.5f, 0.0f, 1.0f}
9430 ok(compare_vec4(&cmp[i], out[i].x, out[i].y, out[i].z, out[i].w, 4096),
9431 "Vertex %u differs. Got %f %f %f %f.\n", i,
9432 out[i].x, out[i].y, out[i].z, out[i].w);
9435 transformdata.lpHOut = out_h;
9436 offscreen = 0xdeadbeef;
9437 hr = IDirect3DViewport_TransformVertices(viewport, ARRAY_SIZE(position_tests),
9438 &transformdata, D3DTRANSFORM_CLIPPED, &offscreen);
9439 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#x.\n", hr);
9440 ok(!offscreen, "Offscreen is %x.\n", offscreen);
9441 for (i = 0; i < ARRAY_SIZE(position_tests); ++i)
9443 static const D3DHVERTEX cmp_h[] =
9445 {0, { 0.0f}, { 0.0f}, { 0.0f}}, {0, { 1.0f}, { 1.0f}, {1.0f}},
9446 {D3DCLIP_FRONT, {-1.0f}, {-1.0f}, {-1.0f}}, {0, { 0.5f}, { 0.5f}, {0.5f}},
9447 {D3DCLIP_FRONT, {-0.5f}, {-0.5f}, {-0.5f}}, {0, {-0.5f}, {-0.5f}, {0.0f}}
9449 ok(compare_float(U1(cmp_h[i]).hx, U1(out_h[i]).hx, 4096)
9450 && compare_float(U2(cmp_h[i]).hy, U2(out_h[i]).hy, 4096)
9451 && compare_float(U3(cmp_h[i]).hz, U3(out_h[i]).hz, 4096)
9452 && cmp_h[i].dwFlags == out_h[i].dwFlags,
9453 "HVertex %u differs. Got %#x %f %f %f.\n", i,
9454 out_h[i].dwFlags, U1(out_h[i]).hx, U2(out_h[i]).hy, U3(out_h[i]).hz);
9456 /* No scheme has been found behind those return values. It seems to be
9457 * whatever data windows has when throwing the vertex away. Modify the
9458 * input test vertices to test this more. Depending on the input data
9459 * it can happen that the z coord gets written into y, or similar things. */
9460 if (0)
9462 static const struct vec4 cmp[] =
9464 {138.0f, 148.0f, 0.0f, 1.0f}, {143.0f, 143.0f, 1.0f, 1.0f}, { -1.0f, -1.0f, 0.5f, 1.0f},
9465 {140.5f, 145.5f, 0.5f, 1.0f}, { -0.5f, -0.5f, -0.5f, 1.0f}, {135.5f, 150.5f, 0.0f, 1.0f}
9467 ok(compare_vec4(&cmp[i], out[i].x, out[i].y, out[i].z, out[i].w, 4096),
9468 "Vertex %u differs. Got %f %f %f %f.\n", i,
9469 out[i].x, out[i].y, out[i].z, out[i].w);
9473 transformdata.lpIn = cliptest;
9474 transformdata.dwInSize = sizeof(cliptest[0]);
9475 offscreen = 0xdeadbeef;
9476 hr = IDirect3DViewport_TransformVertices(viewport, ARRAY_SIZE(cliptest),
9477 &transformdata, D3DTRANSFORM_CLIPPED, &offscreen);
9478 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#x.\n", hr);
9479 ok(!offscreen, "Offscreen is %x.\n", offscreen);
9480 for (i = 0; i < ARRAY_SIZE(cliptest); ++i)
9482 static const DWORD flags[] =
9485 D3DCLIP_RIGHT | D3DCLIP_BACK | D3DCLIP_TOP,
9487 D3DCLIP_LEFT | D3DCLIP_BOTTOM | D3DCLIP_FRONT,
9489 ok(flags[i] == out_h[i].dwFlags, "Cliptest %u returned %#x.\n", i, out_h[i].dwFlags);
9492 vp_data = vp_template;
9493 vp_data.dwWidth = 10;
9494 vp_data.dwHeight = 1000;
9495 hr = IDirect3DViewport_SetViewport(viewport, &vp_data);
9496 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#x.\n", hr);
9497 offscreen = 0xdeadbeef;
9498 hr = IDirect3DViewport_TransformVertices(viewport, ARRAY_SIZE(cliptest),
9499 &transformdata, D3DTRANSFORM_CLIPPED, &offscreen);
9500 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#x.\n", hr);
9501 ok(!offscreen, "Offscreen is %x.\n", offscreen);
9502 for (i = 0; i < ARRAY_SIZE(cliptest); ++i)
9504 static const DWORD flags[] =
9506 D3DCLIP_RIGHT,
9507 D3DCLIP_RIGHT | D3DCLIP_BACK,
9508 D3DCLIP_LEFT,
9509 D3DCLIP_LEFT | D3DCLIP_FRONT,
9511 ok(flags[i] == out_h[i].dwFlags, "Cliptest %u returned %#x.\n", i, out_h[i].dwFlags);
9514 vp_data = vp_template;
9515 vp_data.dwWidth = 256;
9516 vp_data.dwHeight = 256;
9517 vp_data.dvScaleX = 1;
9518 vp_data.dvScaleY = 1;
9519 hr = IDirect3DViewport_SetViewport(viewport, &vp_data);
9520 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#x.\n", hr);
9521 hr = IDirect3DViewport_TransformVertices(viewport, ARRAY_SIZE(cliptest),
9522 &transformdata, D3DTRANSFORM_CLIPPED, &offscreen);
9523 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#x.\n", hr);
9524 ok(!offscreen, "Offscreen is %x.\n", offscreen);
9525 for (i = 0; i < ARRAY_SIZE(cliptest); ++i)
9527 static const DWORD flags[] =
9530 D3DCLIP_BACK,
9532 D3DCLIP_FRONT,
9534 ok(flags[i] == out_h[i].dwFlags, "Cliptest %u returned %#x.\n", i, out_h[i].dwFlags);
9537 /* Finally try to figure out how the DWORD dwOffscreen works.
9538 * It is a logical AND of the vertices' dwFlags members. */
9539 vp_data = vp_template;
9540 vp_data.dwWidth = 5;
9541 vp_data.dwHeight = 5;
9542 vp_data.dvScaleX = 10000.0f;
9543 vp_data.dvScaleY = 10000.0f;
9544 hr = IDirect3DViewport_SetViewport(viewport, &vp_data);
9545 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#x.\n", hr);
9546 transformdata.lpIn = cliptest;
9547 offscreen = 0xdeadbeef;
9548 hr = IDirect3DViewport_TransformVertices(viewport, 1,
9549 &transformdata, D3DTRANSFORM_UNCLIPPED, &offscreen);
9550 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#x.\n", hr);
9551 ok(!offscreen, "Offscreen is %x.\n", offscreen);
9553 offscreen = 0xdeadbeef;
9554 hr = IDirect3DViewport_TransformVertices(viewport, 1,
9555 &transformdata, D3DTRANSFORM_CLIPPED, &offscreen);
9556 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#x.\n", hr);
9557 ok(offscreen == (D3DCLIP_RIGHT | D3DCLIP_TOP), "Offscreen is %x.\n", offscreen);
9558 offscreen = 0xdeadbeef;
9559 hr = IDirect3DViewport_TransformVertices(viewport, 2,
9560 &transformdata, D3DTRANSFORM_CLIPPED, &offscreen);
9561 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#x.\n", hr);
9562 ok(offscreen == (D3DCLIP_RIGHT | D3DCLIP_TOP), "Offscreen is %x.\n", offscreen);
9563 hr = IDirect3DViewport_TransformVertices(viewport, 3,
9564 &transformdata, D3DTRANSFORM_CLIPPED, &offscreen);
9565 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#x.\n", hr);
9566 ok(!offscreen, "Offscreen is %x.\n", offscreen);
9568 transformdata.lpIn = cliptest + 1;
9569 hr = IDirect3DViewport_TransformVertices(viewport, 1,
9570 &transformdata, D3DTRANSFORM_CLIPPED, &offscreen);
9571 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#x.\n", hr);
9572 ok(offscreen == (D3DCLIP_BACK | D3DCLIP_RIGHT | D3DCLIP_TOP), "Offscreen is %x.\n", offscreen);
9574 transformdata.lpIn = cliptest + 2;
9575 hr = IDirect3DViewport_TransformVertices(viewport, 1,
9576 &transformdata, D3DTRANSFORM_CLIPPED, &offscreen);
9577 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#x.\n", hr);
9578 ok(offscreen == (D3DCLIP_BOTTOM | D3DCLIP_LEFT), "Offscreen is %x.\n", offscreen);
9579 offscreen = 0xdeadbeef;
9580 hr = IDirect3DViewport_TransformVertices(viewport, 2,
9581 &transformdata, D3DTRANSFORM_CLIPPED, &offscreen);
9582 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#x.\n", hr);
9583 ok(offscreen == (D3DCLIP_BOTTOM | D3DCLIP_LEFT), "Offscreen is %x.\n", offscreen);
9585 transformdata.lpIn = cliptest + 3;
9586 hr = IDirect3DViewport_TransformVertices(viewport, 1,
9587 &transformdata, D3DTRANSFORM_CLIPPED, &offscreen);
9588 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#x.\n", hr);
9589 ok(offscreen == (D3DCLIP_FRONT | D3DCLIP_BOTTOM | D3DCLIP_LEFT), "Offscreen is %x.\n", offscreen);
9591 transformdata.lpIn = offscreentest;
9592 transformdata.dwInSize = sizeof(offscreentest[0]);
9593 vp_data = vp_template;
9594 vp_data.dwWidth = 257;
9595 vp_data.dwHeight = 257;
9596 vp_data.dvScaleX = 1.0f;
9597 vp_data.dvScaleY = 1.0f;
9598 hr = IDirect3DViewport_SetViewport(viewport, &vp_data);
9599 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#x.\n", hr);
9600 offscreen = 0xdeadbeef;
9601 hr = IDirect3DViewport_TransformVertices(viewport, 1,
9602 &transformdata, D3DTRANSFORM_CLIPPED, &offscreen);
9603 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#x.\n", hr);
9604 ok(!offscreen, "Offscreen is %x.\n", offscreen);
9606 vp_data.dwWidth = 256;
9607 vp_data.dwHeight = 256;
9608 hr = IDirect3DViewport_SetViewport(viewport, &vp_data);
9609 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#x.\n", hr);
9610 hr = IDirect3DViewport_TransformVertices(viewport, 1,
9611 &transformdata, D3DTRANSFORM_CLIPPED, &offscreen);
9612 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#x.\n", hr);
9613 ok(offscreen == D3DCLIP_RIGHT, "Offscreen is %x.\n", offscreen);
9615 /* Test the effect of Matrices.
9617 * Basically the x coordinate ends up as ((x + 1) * 2 + 0) * 5 and
9618 * y as ((y + 0) * 2 + 1) * 5. The 5 comes from dvScaleX/Y, 2 from
9619 * the view matrix and the +1's from the world and projection matrix. */
9620 vp_data.dwX = 0;
9621 vp_data.dwY = 0;
9622 vp_data.dwWidth = 256;
9623 vp_data.dwHeight = 256;
9624 vp_data.dvScaleX = 5.0f;
9625 vp_data.dvScaleY = 5.0f;
9626 vp_data.dvMinZ = 0.0f;
9627 vp_data.dvMaxZ = 1.0f;
9628 hr = IDirect3DViewport_SetViewport(viewport, &vp_data);
9629 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#x.\n", hr);
9631 hr = IDirect3DDevice_CreateMatrix(device, &world_handle);
9632 ok(hr == D3D_OK, "Creating a matrix object failed, hr %#x.\n", hr);
9633 hr = IDirect3DDevice_SetMatrix(device, world_handle, &mat_translate1);
9634 ok(hr == D3D_OK, "Setting a matrix object failed, hr %#x.\n", hr);
9636 hr = IDirect3DDevice_CreateMatrix(device, &view_handle);
9637 ok(hr == D3D_OK, "Creating a matrix object failed, hr %#x.\n", hr);
9638 hr = IDirect3DDevice_SetMatrix(device, view_handle, &mat_scale);
9639 ok(hr == D3D_OK, "Setting a matrix object failed, hr %#x.\n", hr);
9641 hr = IDirect3DDevice_CreateMatrix(device, &proj_handle);
9642 ok(hr == D3D_OK, "Creating a matrix object failed, hr %#x.\n", hr);
9643 hr = IDirect3DDevice_SetMatrix(device, proj_handle, &mat_translate2);
9644 ok(hr == D3D_OK, "Setting a matrix object failed, hr %#x.\n", hr);
9646 memset(&exec_desc, 0, sizeof(exec_desc));
9647 exec_desc.dwSize = sizeof(exec_desc);
9648 exec_desc.dwFlags = D3DDEB_BUFSIZE | D3DDEB_CAPS;
9649 exec_desc.dwBufferSize = 1024;
9650 exec_desc.dwCaps = D3DDEBCAPS_SYSTEMMEMORY;
9651 hr = IDirect3DDevice_CreateExecuteBuffer(device, &exec_desc, &execute_buffer, NULL);
9652 ok(SUCCEEDED(hr), "Failed to create execute buffer, hr %#x.\n", hr);
9654 hr = IDirect3DExecuteBuffer_Lock(execute_buffer, &exec_desc);
9655 ok(SUCCEEDED(hr), "Failed to lock execute buffer, hr %#x.\n", hr);
9656 ptr = (BYTE *)exec_desc.lpData;
9657 emit_set_ts(&ptr, D3DTRANSFORMSTATE_WORLD, world_handle);
9658 emit_set_ts(&ptr, D3DTRANSFORMSTATE_VIEW, view_handle);
9659 emit_set_ts(&ptr, D3DTRANSFORMSTATE_PROJECTION, proj_handle);
9660 emit_end(&ptr);
9661 inst_length = (BYTE *)ptr - (BYTE *)exec_desc.lpData;
9662 hr = IDirect3DExecuteBuffer_Unlock(execute_buffer);
9663 ok(SUCCEEDED(hr), "Failed to unlock execute buffer, hr %#x.\n", hr);
9665 set_execute_data(execute_buffer, 0, 0, inst_length);
9666 hr = IDirect3DDevice_BeginScene(device);
9667 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
9668 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
9669 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
9670 hr = IDirect3DDevice_EndScene(device);
9671 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
9673 transformdata.lpIn = position_tests;
9674 transformdata.dwInSize = sizeof(position_tests[0]);
9675 hr = IDirect3DViewport_TransformVertices(viewport, ARRAY_SIZE(position_tests),
9676 &transformdata, D3DTRANSFORM_UNCLIPPED, &offscreen);
9677 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#x.\n", hr);
9679 for (i = 0; i < ARRAY_SIZE(position_tests); ++i)
9681 static const struct vec4 cmp[] =
9683 {138.0f, 123.0f, 0.0f, 1.0f}, {148.0f, 113.0f, 2.0f, 1.0f}, {128.0f, 133.0f, -2.0f, 1.0f},
9684 {143.0f, 118.0f, 1.0f, 1.0f}, {133.0f, 128.0f, -1.0f, 1.0f}, {133.0f, 128.0f, 0.0f, 1.0f}
9687 ok(compare_vec4(&cmp[i], out[i].x, out[i].y, out[i].z, out[i].w, 4096),
9688 "Vertex %u differs. Got %f %f %f %f.\n", i,
9689 out[i].x, out[i].y, out[i].z, out[i].w);
9692 /* Invalid flags. */
9693 offscreen = 0xdeadbeef;
9694 hr = IDirect3DViewport_TransformVertices(viewport, ARRAY_SIZE(position_tests),
9695 &transformdata, 0, &offscreen);
9696 ok(hr == DDERR_INVALIDPARAMS, "TransformVertices returned %#x.\n", hr);
9697 ok(offscreen == 0xdeadbeef, "Offscreen is %x.\n", offscreen);
9699 /* NULL transform data. */
9700 hr = IDirect3DViewport_TransformVertices(viewport, 1,
9701 NULL, D3DTRANSFORM_UNCLIPPED, &offscreen);
9702 ok(hr == DDERR_INVALIDPARAMS, "TransformVertices returned %#x.\n", hr);
9703 ok(offscreen == 0xdeadbeef, "Offscreen is %x.\n", offscreen);
9704 hr = IDirect3DViewport_TransformVertices(viewport, 0,
9705 NULL, D3DTRANSFORM_UNCLIPPED, &offscreen);
9706 ok(hr == DDERR_INVALIDPARAMS, "TransformVertices returned %#x.\n", hr);
9707 ok(offscreen == 0xdeadbeef, "Offscreen is %x.\n", offscreen);
9709 /* NULL transform data and NULL dwOffscreen.
9711 * Valid transform data + NULL dwOffscreen -> crash. */
9712 hr = IDirect3DViewport_TransformVertices(viewport, 1,
9713 NULL, D3DTRANSFORM_UNCLIPPED, NULL);
9714 ok(hr == DDERR_INVALIDPARAMS, "TransformVertices returned %#x.\n", hr);
9716 /* No vertices. */
9717 hr = IDirect3DViewport_TransformVertices(viewport, 0,
9718 &transformdata, D3DTRANSFORM_UNCLIPPED, &offscreen);
9719 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#x.\n", hr);
9720 ok(!offscreen, "Offscreen is %x.\n", offscreen);
9721 hr = IDirect3DViewport_TransformVertices(viewport, 0,
9722 &transformdata, D3DTRANSFORM_CLIPPED, &offscreen);
9723 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#x.\n", hr);
9724 ok(offscreen == ~0U, "Offscreen is %x.\n", offscreen);
9726 /* Invalid sizes. */
9727 offscreen = 0xdeadbeef;
9728 transformdata.dwSize = sizeof(transformdata) - 1;
9729 hr = IDirect3DViewport_TransformVertices(viewport, 1,
9730 &transformdata, D3DTRANSFORM_UNCLIPPED, &offscreen);
9731 ok(hr == DDERR_INVALIDPARAMS, "TransformVertices returned %#x.\n", hr);
9732 ok(offscreen == 0xdeadbeef, "Offscreen is %x.\n", offscreen);
9733 transformdata.dwSize = sizeof(transformdata) + 1;
9734 hr = IDirect3DViewport_TransformVertices(viewport, 1,
9735 &transformdata, D3DTRANSFORM_UNCLIPPED, &offscreen);
9736 ok(hr == DDERR_INVALIDPARAMS, "TransformVertices returned %#x.\n", hr);
9737 ok(offscreen == 0xdeadbeef, "Offscreen is %x.\n", offscreen);
9739 /* NULL lpIn or lpOut -> crash, except when transforming 0 vertices. */
9740 transformdata.dwSize = sizeof(transformdata);
9741 transformdata.lpIn = NULL;
9742 transformdata.lpOut = NULL;
9743 offscreen = 0xdeadbeef;
9744 hr = IDirect3DViewport_TransformVertices(viewport, 0,
9745 &transformdata, D3DTRANSFORM_CLIPPED, &offscreen);
9746 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#x.\n", hr);
9747 ok(offscreen == ~0U, "Offscreen is %x.\n", offscreen);
9749 /* Test how vertices are transformed by execute buffers. */
9750 vp_data.dwX = 20;
9751 vp_data.dwY = 20;
9752 vp_data.dwWidth = 200;
9753 vp_data.dwHeight = 400;
9754 vp_data.dvScaleX = 20.0f;
9755 vp_data.dvScaleY = 50.0f;
9756 vp_data.dvMinZ = 0.0f;
9757 vp_data.dvMaxZ = 1.0f;
9758 hr = IDirect3DViewport_SetViewport(viewport, &vp_data);
9759 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#x.\n", hr);
9761 background = create_diffuse_material(device, 0.0f, 0.0f, 1.0f, 0.0f);
9762 viewport_set_background(device, viewport, background);
9763 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
9764 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
9766 hr = IDirect3DExecuteBuffer_Lock(execute_buffer, &exec_desc);
9767 ok(SUCCEEDED(hr), "Failed to lock execute buffer, hr %#x.\n", hr);
9768 memcpy(exec_desc.lpData, quad, sizeof(quad));
9769 ptr = ((BYTE *)exec_desc.lpData) + sizeof(quad);
9770 emit_process_vertices(&ptr, D3DPROCESSVERTICES_TRANSFORM, 0, 4);
9771 emit_tquad(&ptr, 0);
9772 emit_end(&ptr);
9773 inst_length = (BYTE *)ptr - (BYTE *)exec_desc.lpData;
9774 hr = IDirect3DExecuteBuffer_Unlock(execute_buffer);
9775 ok(SUCCEEDED(hr), "Failed to unlock execute buffer, hr %#x.\n", hr);
9777 set_execute_data(execute_buffer, 4, sizeof(quad), inst_length);
9778 hr = IDirect3DDevice_BeginScene(device);
9779 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
9780 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
9781 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
9782 hr = IDirect3DDevice_EndScene(device);
9783 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
9785 color = get_surface_color(rt, 128, 143);
9786 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
9787 color = get_surface_color(rt, 132, 143);
9788 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
9789 color = get_surface_color(rt, 128, 147);
9790 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
9791 color = get_surface_color(rt, 132, 147);
9792 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
9794 color = get_surface_color(rt, 177, 217);
9795 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
9796 color = get_surface_color(rt, 181, 217);
9797 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
9798 color = get_surface_color(rt, 177, 221);
9799 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
9800 color = get_surface_color(rt, 181, 221);
9801 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
9803 IDirect3DDevice_DeleteMatrix(device, world_handle);
9804 IDirect3DDevice_DeleteMatrix(device, view_handle);
9805 IDirect3DDevice_DeleteMatrix(device, proj_handle);
9806 IDirect3DExecuteBuffer_Release(execute_buffer);
9808 IDirectDrawSurface_Release(rt);
9809 destroy_viewport(device, viewport);
9810 IDirect3DMaterial_Release(background);
9811 refcount = IDirect3DDevice_Release(device);
9812 ok(!refcount, "Device has %u references left.\n", refcount);
9813 IDirectDraw_Release(ddraw);
9814 DestroyWindow(window);
9817 static void test_display_mode_surface_pixel_format(void)
9819 unsigned int width, height, bpp;
9820 IDirectDrawSurface *surface;
9821 DDSURFACEDESC surface_desc;
9822 IDirectDraw *ddraw;
9823 ULONG refcount;
9824 HWND window;
9825 HRESULT hr;
9827 if (!(ddraw = create_ddraw()))
9829 skip("Failed to create ddraw.\n");
9830 return;
9833 surface_desc.dwSize = sizeof(surface_desc);
9834 hr = IDirectDraw_GetDisplayMode(ddraw, &surface_desc);
9835 ok(SUCCEEDED(hr), "Failed to get display mode, hr %#x.\n", hr);
9836 width = surface_desc.dwWidth;
9837 height = surface_desc.dwHeight;
9839 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
9840 0, 0, width, height, NULL, NULL, NULL, NULL);
9841 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
9842 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
9844 bpp = 0;
9845 if (SUCCEEDED(IDirectDraw_SetDisplayMode(ddraw, width, height, 16)))
9846 bpp = 16;
9847 if (SUCCEEDED(IDirectDraw_SetDisplayMode(ddraw, width, height, 24)))
9848 bpp = 24;
9849 if (SUCCEEDED(IDirectDraw_SetDisplayMode(ddraw, width, height, 32)))
9850 bpp = 32;
9851 ok(bpp, "Set display mode failed.\n");
9853 surface_desc.dwSize = sizeof(surface_desc);
9854 hr = IDirectDraw_GetDisplayMode(ddraw, &surface_desc);
9855 ok(SUCCEEDED(hr), "Failed to get display mode, hr %#x.\n", hr);
9856 ok(surface_desc.dwWidth == width, "Got width %u, expected %u.\n", surface_desc.dwWidth, width);
9857 ok(surface_desc.dwHeight == height, "Got height %u, expected %u.\n", surface_desc.dwHeight, height);
9858 ok(U1(surface_desc.ddpfPixelFormat).dwRGBBitCount == bpp, "Got bpp %u, expected %u.\n",
9859 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount, bpp);
9861 memset(&surface_desc, 0, sizeof(surface_desc));
9862 surface_desc.dwSize = sizeof(surface_desc);
9863 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
9864 surface_desc.dwBackBufferCount = 1;
9865 surface_desc.ddsCaps.dwCaps = DDSCAPS_COMPLEX | DDSCAPS_FLIP | DDSCAPS_PRIMARYSURFACE;
9866 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
9867 ok(hr == D3D_OK, "Failed to create surface, hr %#x.\n", hr);
9868 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
9869 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
9870 ok(surface_desc.dwWidth == width, "Got width %u, expected %u.\n", surface_desc.dwWidth, width);
9871 ok(surface_desc.dwHeight == height, "Got height %u, expected %u.\n", surface_desc.dwHeight, height);
9872 ok(surface_desc.ddpfPixelFormat.dwFlags == DDPF_RGB, "Got unexpected pixel format flags %#x.\n",
9873 surface_desc.ddpfPixelFormat.dwFlags);
9874 ok(U1(surface_desc.ddpfPixelFormat).dwRGBBitCount == bpp, "Got bpp %u, expected %u.\n",
9875 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount, bpp);
9876 IDirectDrawSurface_Release(surface);
9878 memset(&surface_desc, 0, sizeof(surface_desc));
9879 surface_desc.dwSize = sizeof(surface_desc);
9880 surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
9881 surface_desc.dwWidth = width;
9882 surface_desc.dwHeight = height;
9883 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
9884 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
9885 ok(hr == D3D_OK, "Failed to create surface, hr %#x.\n", hr);
9886 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
9887 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
9888 ok(surface_desc.ddpfPixelFormat.dwFlags == DDPF_RGB, "Got unexpected pixel format flags %#x.\n",
9889 surface_desc.ddpfPixelFormat.dwFlags);
9890 ok(U1(surface_desc.ddpfPixelFormat).dwRGBBitCount == bpp, "Got bpp %u, expected %u.\n",
9891 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount, bpp);
9892 IDirectDrawSurface_Release(surface);
9894 refcount = IDirectDraw_Release(ddraw);
9895 ok(!refcount, "DirectDraw has %u references left.\n", refcount);
9896 DestroyWindow(window);
9899 static void test_surface_desc_size(void)
9901 union
9903 DWORD dwSize;
9904 DDSURFACEDESC desc1;
9905 DDSURFACEDESC2 desc2;
9906 BYTE blob[1024];
9907 } desc;
9908 IDirectDrawSurface7 *surface7;
9909 IDirectDrawSurface *surface;
9910 DDSURFACEDESC surface_desc;
9911 HRESULT expected_hr, hr;
9912 IDirectDraw *ddraw;
9913 unsigned int i, j;
9914 ULONG refcount;
9916 static const struct
9918 unsigned int caps;
9919 const char *name;
9921 surface_caps[] =
9923 {DDSCAPS_OFFSCREENPLAIN, "offscreenplain"},
9924 {DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, "systemmemory texture"},
9925 {DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, "videomemory texture"},
9927 static const unsigned int desc_sizes[] =
9929 sizeof(DDSURFACEDESC),
9930 sizeof(DDSURFACEDESC2),
9931 sizeof(DDSURFACEDESC) + 1,
9932 sizeof(DDSURFACEDESC2) + 1,
9933 2 * sizeof(DDSURFACEDESC),
9934 2 * sizeof(DDSURFACEDESC2),
9935 sizeof(DDSURFACEDESC) - 1,
9936 sizeof(DDSURFACEDESC2) - 1,
9937 sizeof(DDSURFACEDESC) / 2,
9938 sizeof(DDSURFACEDESC2) / 2,
9942 sizeof(desc) / 2,
9943 sizeof(desc) - 100,
9946 if (!(ddraw = create_ddraw()))
9948 skip("Failed to create ddraw.\n");
9949 return;
9951 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
9952 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
9954 for (i = 0; i < sizeof(surface_caps) / sizeof(*surface_caps); ++i)
9956 memset(&surface_desc, 0, sizeof(surface_desc));
9957 surface_desc.dwSize = sizeof(surface_desc);
9958 surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
9959 surface_desc.ddsCaps.dwCaps = surface_caps[i].caps;
9960 surface_desc.dwHeight = 128;
9961 surface_desc.dwWidth = 128;
9962 if (FAILED(IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL)))
9964 skip("Failed to create surface, type %s.\n", surface_caps[i].name);
9965 continue;
9967 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirectDrawSurface7, (void **)&surface7);
9968 ok(hr == DD_OK, "Failed to query IDirectDrawSurface7, hr %#x, type %s.\n", hr, surface_caps[i].name);
9970 /* GetSurfaceDesc() */
9971 for (j = 0; j < sizeof(desc_sizes) / sizeof(*desc_sizes); ++j)
9973 memset(&desc, 0, sizeof(desc));
9974 desc.dwSize = desc_sizes[j];
9975 expected_hr = desc.dwSize == sizeof(DDSURFACEDESC) ? DD_OK : DDERR_INVALIDPARAMS;
9976 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &desc.desc1);
9977 ok(hr == expected_hr, "Got hr %#x, expected %#x, dwSize %u, type %s.\n",
9978 hr, expected_hr, desc_sizes[j], surface_caps[i].name);
9980 memset(&desc, 0, sizeof(desc));
9981 desc.dwSize = desc_sizes[j];
9982 expected_hr = desc.dwSize == sizeof(DDSURFACEDESC2) ? DD_OK : DDERR_INVALIDPARAMS;
9983 hr = IDirectDrawSurface7_GetSurfaceDesc(surface7, &desc.desc2);
9984 ok(hr == expected_hr, "Got hr %#x, expected %#x, dwSize %u, type %s.\n",
9985 hr, expected_hr, desc_sizes[j], surface_caps[i].name);
9988 /* Lock() */
9989 for (j = 0; j < sizeof(desc_sizes) / sizeof(*desc_sizes); ++j)
9991 const BOOL valid_size = desc_sizes[j] == sizeof(DDSURFACEDESC)
9992 || desc_sizes[j] == sizeof(DDSURFACEDESC2);
9993 DWORD expected_texture_stage;
9995 memset(&desc, 0, sizeof(desc));
9996 desc.dwSize = desc_sizes[j];
9997 desc.desc2.dwTextureStage = 0xdeadbeef;
9998 desc.blob[sizeof(DDSURFACEDESC2)] = 0xef;
9999 hr = IDirectDrawSurface_Lock(surface, NULL, &desc.desc1, 0, 0);
10000 expected_hr = valid_size ? DD_OK : DDERR_INVALIDPARAMS;
10001 ok(hr == expected_hr, "Got hr %#x, expected %#x, dwSize %u, type %s.\n",
10002 hr, expected_hr, desc_sizes[j], surface_caps[i].name);
10003 ok(desc.dwSize == desc_sizes[j], "dwSize was changed from %u to %u, type %s.\n",
10004 desc_sizes[j], desc.dwSize, surface_caps[i].name);
10005 ok(desc.blob[sizeof(DDSURFACEDESC2)] == 0xef, "Got unexpected byte %02x, dwSize %u, type %s.\n",
10006 desc.blob[sizeof(DDSURFACEDESC2)], desc_sizes[j], surface_caps[i].name);
10007 if (SUCCEEDED(hr))
10009 ok(desc.desc1.dwWidth == 128, "Got unexpected width %u, dwSize %u, type %s.\n",
10010 desc.desc1.dwWidth, desc_sizes[j], surface_caps[i].name);
10011 ok(desc.desc1.dwHeight == 128, "Got unexpected height %u, dwSize %u, type %s.\n",
10012 desc.desc1.dwHeight, desc_sizes[j], surface_caps[i].name);
10013 expected_texture_stage = desc_sizes[j] >= sizeof(DDSURFACEDESC2) ? 0 : 0xdeadbeef;
10014 todo_wine_if(!expected_texture_stage)
10015 ok(desc.desc2.dwTextureStage == expected_texture_stage,
10016 "Got unexpected texture stage %#x, dwSize %u, type %s.\n",
10017 desc.desc2.dwTextureStage, desc_sizes[j], surface_caps[i].name);
10018 IDirectDrawSurface_Unlock(surface, NULL);
10021 memset(&desc, 0, sizeof(desc));
10022 desc.dwSize = desc_sizes[j];
10023 desc.desc2.dwTextureStage = 0xdeadbeef;
10024 desc.blob[sizeof(DDSURFACEDESC2)] = 0xef;
10025 hr = IDirectDrawSurface7_Lock(surface7, NULL, &desc.desc2, 0, 0);
10026 expected_hr = valid_size ? DD_OK : DDERR_INVALIDPARAMS;
10027 ok(hr == expected_hr, "Got hr %#x, expected %#x, dwSize %u, type %s.\n",
10028 hr, expected_hr, desc_sizes[j], surface_caps[i].name);
10029 ok(desc.dwSize == desc_sizes[j], "dwSize was changed from %u to %u, type %s.\n",
10030 desc_sizes[j], desc.dwSize, surface_caps[i].name);
10031 ok(desc.blob[sizeof(DDSURFACEDESC2)] == 0xef, "Got unexpected byte %02x, dwSize %u, type %s.\n",
10032 desc.blob[sizeof(DDSURFACEDESC2)], desc_sizes[j], surface_caps[i].name);
10033 if (SUCCEEDED(hr))
10035 ok(desc.desc2.dwWidth == 128, "Got unexpected width %u, dwSize %u, type %s.\n",
10036 desc.desc2.dwWidth, desc_sizes[j], surface_caps[i].name);
10037 ok(desc.desc2.dwHeight == 128, "Got unexpected height %u, dwSize %u, type %s.\n",
10038 desc.desc2.dwHeight, desc_sizes[j], surface_caps[i].name);
10039 expected_texture_stage = desc_sizes[j] >= sizeof(DDSURFACEDESC2) ? 0 : 0xdeadbeef;
10040 ok(desc.desc2.dwTextureStage == expected_texture_stage,
10041 "Got unexpected texture stage %#x, dwSize %u, type %s.\n",
10042 desc.desc2.dwTextureStage, desc_sizes[j], surface_caps[i].name);
10043 IDirectDrawSurface7_Unlock(surface7, NULL);
10047 IDirectDrawSurface7_Release(surface7);
10048 IDirectDrawSurface_Release(surface);
10051 refcount = IDirectDraw7_Release(ddraw);
10052 ok(!refcount, "DirectDraw has %u references left.\n", refcount);
10055 static void test_texture_load(void)
10057 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
10058 static D3DTLVERTEX tquad[] =
10060 {{ 0.0f}, {480.0f}, {0.0f}, {1.0f}, {0xffffffff}, {0x00000000}, {0.0f}, {0.0f}},
10061 {{ 0.0f}, { 0.0f}, {0.0f}, {1.0f}, {0xffffffff}, {0x00000000}, {0.0f}, {1.0f}},
10062 {{640.0f}, {480.0f}, {0.0f}, {1.0f}, {0xffffffff}, {0x00000000}, {1.0f}, {0.0f}},
10063 {{640.0f}, { 0.0f}, {0.0f}, {1.0f}, {0xffffffff}, {0x00000000}, {1.0f}, {1.0f}},
10065 D3DTEXTUREHANDLE dst_texture_handle, src_texture_handle;
10066 IDirectDrawSurface *dst_surface, *src_surface;
10067 IDirect3DExecuteBuffer *execute_buffer;
10068 D3DEXECUTEBUFFERDESC exec_desc;
10069 IDirect3DMaterial *background;
10070 IDirect3DViewport *viewport;
10071 DDSURFACEDESC surface_desc;
10072 IDirect3DTexture *texture;
10073 IDirect3DDevice *device;
10074 IDirectDrawSurface *rt;
10075 IDirectDraw *ddraw;
10076 UINT inst_length;
10077 D3DCOLOR color;
10078 ULONG refcount;
10079 HWND window;
10080 DDBLTFX fx;
10081 HRESULT hr;
10082 void *ptr;
10084 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
10085 0, 0, 640, 480, 0, 0, 0, 0);
10086 ddraw = create_ddraw();
10087 ok(!!ddraw, "Failed to create a ddraw object.\n");
10088 if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
10090 skip("Failed to create a 3D device, skipping test.\n");
10091 IDirectDraw_Release(ddraw);
10092 DestroyWindow(window);
10093 return;
10096 hr = IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&rt);
10097 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
10099 background = create_diffuse_material(device, 1.0f, 1.0f, 1.0f, 1.0f);
10100 viewport = create_viewport(device, 0, 0, 640, 480);
10101 viewport_set_background(device, viewport, background);
10103 memset(&exec_desc, 0, sizeof(exec_desc));
10104 exec_desc.dwSize = sizeof(exec_desc);
10105 exec_desc.dwFlags = D3DDEB_BUFSIZE | D3DDEB_CAPS;
10106 exec_desc.dwBufferSize = 1024;
10107 exec_desc.dwCaps = D3DDEBCAPS_SYSTEMMEMORY;
10108 hr = IDirect3DDevice_CreateExecuteBuffer(device, &exec_desc, &execute_buffer, NULL);
10109 ok(SUCCEEDED(hr), "Failed to create execute buffer, hr %#x.\n", hr);
10111 memset(&surface_desc, 0, sizeof(surface_desc));
10112 surface_desc.dwSize = sizeof(surface_desc);
10113 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
10114 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
10115 surface_desc.dwWidth = 256;
10116 surface_desc.dwHeight = 256;
10117 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
10118 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB;
10119 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount = 32;
10120 U2(surface_desc.ddpfPixelFormat).dwRBitMask = 0x00ff0000;
10121 U3(surface_desc.ddpfPixelFormat).dwGBitMask = 0x0000ff00;
10122 U4(surface_desc.ddpfPixelFormat).dwBBitMask = 0x000000ff;
10124 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &src_surface, NULL);
10125 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
10126 hr = IDirectDrawSurface_QueryInterface(src_surface, &IID_IDirect3DTexture, (void **)&texture);
10127 ok(SUCCEEDED(hr), "Failed to get texture interface, hr %#x.\n", hr);
10128 hr = IDirect3DTexture_GetHandle(texture, device, &src_texture_handle);
10129 ok(SUCCEEDED(hr), "Failed to get texture handle, hr %#x.\n", hr);
10130 IDirect3DTexture_Release(texture);
10132 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &dst_surface, NULL);
10133 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
10134 hr = IDirectDrawSurface_QueryInterface(dst_surface, &IID_IDirect3DTexture, (void **)&texture);
10135 ok(SUCCEEDED(hr), "Failed to get texture interface, hr %#x.\n", hr);
10136 hr = IDirect3DTexture_GetHandle(texture, device, &dst_texture_handle);
10137 ok(SUCCEEDED(hr), "Failed to get texture handle, hr %#x.\n", hr);
10138 IDirect3DTexture_Release(texture);
10140 memset(&fx, 0, sizeof(fx));
10141 fx.dwSize = sizeof(fx);
10142 U5(fx).dwFillColor = 0x0000ffff;
10143 hr = IDirectDrawSurface_Blt(src_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
10144 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
10146 hr = IDirect3DExecuteBuffer_Lock(execute_buffer, &exec_desc);
10147 ok(SUCCEEDED(hr), "Failed to lock execute buffer, hr %#x.\n", hr);
10148 memcpy(exec_desc.lpData, tquad, sizeof(tquad));
10149 ptr = (BYTE *)exec_desc.lpData + sizeof(tquad);
10150 emit_process_vertices(&ptr, D3DPROCESSVERTICES_COPY, 0, 4);
10151 emit_texture_load(&ptr, dst_texture_handle, src_texture_handle);
10152 emit_set_rs(&ptr, D3DRENDERSTATE_TEXTUREHANDLE, dst_texture_handle);
10153 emit_tquad(&ptr, 0);
10154 emit_end(&ptr);
10155 inst_length = (BYTE *)ptr - (BYTE *)exec_desc.lpData - sizeof(tquad);
10156 hr = IDirect3DExecuteBuffer_Unlock(execute_buffer);
10157 ok(SUCCEEDED(hr), "Failed to unlock execute buffer, hr %#x.\n", hr);
10159 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
10160 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
10161 color = get_surface_color(rt, 320, 240);
10162 ok(compare_color(color, 0x00ffffff, 1), "Got unexpected color 0x%08x.\n", color);
10163 set_execute_data(execute_buffer, 4, sizeof(tquad), inst_length);
10164 hr = IDirect3DDevice_BeginScene(device);
10165 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
10166 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
10167 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
10168 hr = IDirect3DDevice_EndScene(device);
10169 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
10170 color = get_surface_color(rt, 320, 240);
10171 ok(compare_color(color, 0x0000ffff, 1), "Got unexpected color 0x%08x.\n", color);
10173 memset(&fx, 0, sizeof(fx));
10174 fx.dwSize = sizeof(fx);
10175 U5(fx).dwFillColor = 0x000000ff;
10176 hr = IDirectDrawSurface_Blt(src_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
10177 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
10179 hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
10180 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
10181 color = get_surface_color(rt, 320, 240);
10182 ok(compare_color(color, 0x00ffffff, 1), "Got unexpected color 0x%08x.\n", color);
10183 set_execute_data(execute_buffer, 4, sizeof(tquad), inst_length);
10184 hr = IDirect3DDevice_BeginScene(device);
10185 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
10186 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
10187 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
10188 hr = IDirect3DDevice_EndScene(device);
10189 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
10190 color = get_surface_color(rt, 320, 240);
10191 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
10193 IDirectDrawSurface_Release(dst_surface);
10194 IDirectDrawSurface_Release(src_surface);
10195 IDirectDrawSurface_Release(rt);
10196 IDirect3DExecuteBuffer_Release(execute_buffer);
10197 IDirect3DMaterial_Release(background);
10198 destroy_viewport(device, viewport);
10199 IDirect3DDevice_Release(device);
10200 refcount = IDirectDraw_Release(ddraw);
10201 ok(!refcount, "DirectDraw has %u references left.\n", refcount);
10202 DestroyWindow(window);
10205 static void test_ck_operation(void)
10207 IDirectDrawSurface *src, *dst;
10208 IDirectDrawSurface7 *src7, *dst7;
10209 DDSURFACEDESC surface_desc;
10210 IDirectDraw *ddraw;
10211 ULONG refcount;
10212 HWND window;
10213 HRESULT hr;
10214 D3DCOLOR *color;
10215 unsigned int i;
10216 DDCOLORKEY ckey;
10217 DDBLTFX fx;
10219 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
10220 0, 0, 640, 480, 0, 0, 0, 0);
10221 ddraw = create_ddraw();
10222 ok(!!ddraw, "Failed to create a ddraw object.\n");
10223 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
10224 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
10226 memset(&surface_desc, 0, sizeof(surface_desc));
10227 surface_desc.dwSize = sizeof(surface_desc);
10228 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
10229 surface_desc.dwWidth = 4;
10230 surface_desc.dwHeight = 1;
10231 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
10232 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
10233 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount = 32;
10234 U2(surface_desc.ddpfPixelFormat).dwRBitMask = 0x00ff0000;
10235 U3(surface_desc.ddpfPixelFormat).dwGBitMask = 0x0000ff00;
10236 U4(surface_desc.ddpfPixelFormat).dwBBitMask = 0x000000ff;
10237 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &dst, NULL);
10238 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
10240 surface_desc.dwFlags |= DDSD_CKSRCBLT;
10241 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00ff00ff;
10242 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00ff00ff;
10243 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &src, NULL);
10244 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
10246 hr = IDirectDrawSurface_Lock(src, NULL, &surface_desc, DDLOCK_WAIT, NULL);
10247 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
10248 ok(!(surface_desc.dwFlags & DDSD_LPSURFACE), "Surface desc has LPSURFACE Flags set.\n");
10249 color = surface_desc.lpSurface;
10250 color[0] = 0x77010203;
10251 color[1] = 0x00010203;
10252 color[2] = 0x77ff00ff;
10253 color[3] = 0x00ff00ff;
10254 hr = IDirectDrawSurface_Unlock(src, NULL);
10255 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
10257 for (i = 0; i < 2; ++i)
10259 hr = IDirectDrawSurface_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
10260 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
10261 color = surface_desc.lpSurface;
10262 color[0] = 0xcccccccc;
10263 color[1] = 0xcccccccc;
10264 color[2] = 0xcccccccc;
10265 color[3] = 0xcccccccc;
10266 hr = IDirectDrawSurface_Unlock(dst, NULL);
10267 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
10269 if (i)
10271 hr = IDirectDrawSurface_BltFast(dst, 0, 0, src, NULL, DDBLTFAST_SRCCOLORKEY);
10272 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
10274 else
10276 hr = IDirectDrawSurface_Blt(dst, NULL, src, NULL, DDBLT_KEYSRC, NULL);
10277 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
10280 hr = IDirectDrawSurface_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT | DDLOCK_READONLY, NULL);
10281 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
10282 ok(!(surface_desc.dwFlags & DDSD_LPSURFACE), "Surface desc has LPSURFACE Flags set.\n");
10283 color = surface_desc.lpSurface;
10284 /* Different behavior on some drivers / windows versions. Some versions ignore the X channel when
10285 * color keying, but copy it to the destination surface. Others (sysmem surfaces) apply it for
10286 * color keying, but do not copy it into the destination surface. Nvidia neither uses it for
10287 * color keying nor copies it. */
10288 ok((color[0] == 0x77010203 && color[1] == 0x00010203
10289 && color[2] == 0xcccccccc && color[3] == 0xcccccccc) /* AMD, Wine */
10290 || broken(color[0] == 0x00010203 && color[1] == 0x00010203
10291 && color[2] == 0x00ff00ff && color[3] == 0xcccccccc) /* Sysmem surfaces? */
10292 || broken(color[0] == 0x00010203 && color[1] == 0x00010203
10293 && color[2] == 0xcccccccc && color[3] == 0xcccccccc) /* Nvidia */
10294 || broken(color[0] == 0xff010203 && color[1] == 0xff010203
10295 && color[2] == 0xcccccccc && color[3] == 0xcccccccc) /* Testbot */,
10296 "Destination data after blitting is %08x %08x %08x %08x, i=%u.\n",
10297 color[0], color[1], color[2], color[3], i);
10298 hr = IDirectDrawSurface_Unlock(dst, NULL);
10299 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
10302 hr = IDirectDrawSurface_GetColorKey(src, DDCKEY_SRCBLT, &ckey);
10303 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
10304 ok(ckey.dwColorSpaceLowValue == 0x00ff00ff && ckey.dwColorSpaceHighValue == 0x00ff00ff,
10305 "Got unexpected color key low=%08x high=%08x.\n", ckey.dwColorSpaceLowValue, ckey.dwColorSpaceHighValue);
10307 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0x0000ff00;
10308 hr = IDirectDrawSurface_SetColorKey(src, DDCKEY_SRCBLT, &ckey);
10309 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
10311 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0;
10312 hr = IDirectDrawSurface_GetColorKey(src, DDCKEY_SRCBLT, &ckey);
10313 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
10314 ok(ckey.dwColorSpaceLowValue == 0x0000ff00 && ckey.dwColorSpaceHighValue == 0x0000ff00,
10315 "Got unexpected color key low=%08x high=%08x.\n", ckey.dwColorSpaceLowValue, ckey.dwColorSpaceHighValue);
10317 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0;
10318 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0;
10319 hr = IDirectDrawSurface_GetSurfaceDesc(src, &surface_desc);
10320 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
10321 ok(surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue == 0x0000ff00
10322 && surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue == 0x0000ff00,
10323 "Got unexpected color key low=%08x high=%08x.\n", surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue,
10324 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue);
10326 /* Test SetColorKey with dwColorSpaceHighValue < dwColorSpaceLowValue */
10327 ckey.dwColorSpaceLowValue = 0x000000ff;
10328 ckey.dwColorSpaceHighValue = 0x00000000;
10329 hr = IDirectDrawSurface_SetColorKey(src, DDCKEY_SRCBLT, &ckey);
10330 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
10332 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0;
10333 hr = IDirectDrawSurface_GetColorKey(src, DDCKEY_SRCBLT, &ckey);
10334 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
10335 ok(ckey.dwColorSpaceLowValue == 0x000000ff && ckey.dwColorSpaceHighValue == 0x000000ff,
10336 "Got unexpected color key low=%08x high=%08x.\n", ckey.dwColorSpaceLowValue, ckey.dwColorSpaceHighValue);
10338 ckey.dwColorSpaceLowValue = 0x000000ff;
10339 ckey.dwColorSpaceHighValue = 0x00000001;
10340 hr = IDirectDrawSurface_SetColorKey(src, DDCKEY_SRCBLT, &ckey);
10341 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
10343 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0;
10344 hr = IDirectDrawSurface_GetColorKey(src, DDCKEY_SRCBLT, &ckey);
10345 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
10346 ok(ckey.dwColorSpaceLowValue == 0x000000ff && ckey.dwColorSpaceHighValue == 0x000000ff,
10347 "Got unexpected color key low=%08x high=%08x.\n", ckey.dwColorSpaceLowValue, ckey.dwColorSpaceHighValue);
10349 ckey.dwColorSpaceLowValue = 0x000000fe;
10350 ckey.dwColorSpaceHighValue = 0x000000fd;
10351 hr = IDirectDrawSurface_SetColorKey(src, DDCKEY_SRCBLT, &ckey);
10352 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
10354 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0;
10355 hr = IDirectDrawSurface_GetColorKey(src, DDCKEY_SRCBLT, &ckey);
10356 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
10357 ok(ckey.dwColorSpaceLowValue == 0x000000fe && ckey.dwColorSpaceHighValue == 0x000000fe,
10358 "Got unexpected color key low=%08x high=%08x.\n", ckey.dwColorSpaceLowValue, ckey.dwColorSpaceHighValue);
10360 IDirectDrawSurface_Release(src);
10361 IDirectDrawSurface_Release(dst);
10363 /* Test source and destination keys and where they are read from. Use a surface with alpha
10364 * to avoid driver-dependent content in the X channel. */
10365 memset(&surface_desc, 0, sizeof(surface_desc));
10366 surface_desc.dwSize = sizeof(surface_desc);
10367 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
10368 surface_desc.dwWidth = 6;
10369 surface_desc.dwHeight = 1;
10370 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
10371 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
10372 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount = 32;
10373 U2(surface_desc.ddpfPixelFormat).dwRBitMask = 0x00ff0000;
10374 U3(surface_desc.ddpfPixelFormat).dwGBitMask = 0x0000ff00;
10375 U4(surface_desc.ddpfPixelFormat).dwBBitMask = 0x000000ff;
10376 U5(surface_desc.ddpfPixelFormat).dwRGBAlphaBitMask = 0xff000000;
10377 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &dst, NULL);
10378 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
10379 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &src, NULL);
10380 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
10382 ckey.dwColorSpaceLowValue = 0x0000ff00;
10383 ckey.dwColorSpaceHighValue = 0x0000ff00;
10384 hr = IDirectDrawSurface_SetColorKey(dst, DDCKEY_SRCBLT, &ckey);
10385 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
10386 ckey.dwColorSpaceLowValue = 0x00ff0000;
10387 ckey.dwColorSpaceHighValue = 0x00ff0000;
10388 hr = IDirectDrawSurface_SetColorKey(dst, DDCKEY_DESTBLT, &ckey);
10389 ok(SUCCEEDED(hr) || hr == DDERR_NOCOLORKEYHW, "Failed to set color key, hr %#x.\n", hr);
10390 if (FAILED(hr))
10392 /* Nvidia reject dest keys, AMD allows them. This applies to vidmem and sysmem surfaces. */
10393 skip("Failed to set destination color key, skipping related tests.\n");
10394 goto done;
10397 ckey.dwColorSpaceLowValue = 0x000000ff;
10398 ckey.dwColorSpaceHighValue = 0x000000ff;
10399 hr = IDirectDrawSurface_SetColorKey(src, DDCKEY_SRCBLT, &ckey);
10400 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
10401 ckey.dwColorSpaceLowValue = 0x000000aa;
10402 ckey.dwColorSpaceHighValue = 0x000000aa;
10403 hr = IDirectDrawSurface_SetColorKey(src, DDCKEY_DESTBLT, &ckey);
10404 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
10406 memset(&fx, 0, sizeof(fx));
10407 fx.dwSize = sizeof(fx);
10408 fx.ddckSrcColorkey.dwColorSpaceHighValue = 0x00110000;
10409 fx.ddckSrcColorkey.dwColorSpaceLowValue = 0x00110000;
10410 fx.ddckDestColorkey.dwColorSpaceHighValue = 0x00001100;
10411 fx.ddckDestColorkey.dwColorSpaceLowValue = 0x00001100;
10413 hr = IDirectDrawSurface_Lock(src, NULL, &surface_desc, DDLOCK_WAIT, NULL);
10414 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
10415 color = surface_desc.lpSurface;
10416 color[0] = 0x000000ff; /* Applies to src blt key in src surface. */
10417 color[1] = 0x000000aa; /* Applies to dst blt key in src surface. */
10418 color[2] = 0x00ff0000; /* Dst color key in dst surface. */
10419 color[3] = 0x0000ff00; /* Src color key in dst surface. */
10420 color[4] = 0x00001100; /* Src color key in ddbltfx. */
10421 color[5] = 0x00110000; /* Dst color key in ddbltfx. */
10422 hr = IDirectDrawSurface_Unlock(src, NULL);
10423 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
10425 hr = IDirectDrawSurface_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
10426 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
10427 color = surface_desc.lpSurface;
10428 color[0] = color[1] = color[2] = color[3] = color[4] = color[5] = 0x55555555;
10429 hr = IDirectDrawSurface_Unlock(dst, NULL);
10430 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
10432 /* Test a blit without keying. */
10433 hr = IDirectDrawSurface_Blt(dst, NULL, src, NULL, 0, &fx);
10434 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
10436 hr = IDirectDrawSurface_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
10437 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
10438 color = surface_desc.lpSurface;
10439 /* Should have copied src data unmodified to dst. */
10440 ok(color[0] == 0x000000ff && color[1] == 0x000000aa && color[2] == 0x00ff0000 &&
10441 color[3] == 0x0000ff00 && color[4] == 0x00001100 && color[5] == 0x00110000,
10442 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
10443 color[0], color[1], color[2], color[3], color[4], color[5]);
10445 color[0] = color[1] = color[2] = color[3] = color[4] = color[5] = 0x55555555;
10446 hr = IDirectDrawSurface_Unlock(dst, NULL);
10447 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
10449 /* Src key. */
10450 hr = IDirectDrawSurface_Blt(dst, NULL, src, NULL, DDBLT_KEYSRC, &fx);
10451 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
10453 hr = IDirectDrawSurface_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
10454 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
10455 color = surface_desc.lpSurface;
10456 /* Src key applied to color[0]. It is unmodified, the others are copied. */
10457 ok(color[0] == 0x55555555 && color[1] == 0x000000aa && color[2] == 0x00ff0000 &&
10458 color[3] == 0x0000ff00 && color[4] == 0x00001100 && color[5] == 0x00110000,
10459 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
10460 color[0], color[1], color[2], color[3], color[4], color[5]);
10462 color[0] = color[1] = color[2] = color[3] = color[4] = color[5] = 0x55555555;
10463 hr = IDirectDrawSurface_Unlock(dst, NULL);
10464 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
10466 /* Src override. */
10467 hr = IDirectDrawSurface_Blt(dst, NULL, src, NULL, DDBLT_KEYSRCOVERRIDE, &fx);
10468 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
10470 hr = IDirectDrawSurface_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
10471 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
10472 color = surface_desc.lpSurface;
10473 /* Override key applied to color[5]. It is unmodified, the others are copied. */
10474 ok(color[0] == 0x000000ff && color[1] == 0x000000aa && color[2] == 0x00ff0000 &&
10475 color[3] == 0x0000ff00 && color[4] == 0x00001100 && color[5] == 0x55555555,
10476 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
10477 color[0], color[1], color[2], color[3], color[4], color[5]);
10479 color[0] = color[1] = color[2] = color[3] = color[4] = color[5] = 0x55555555;
10480 hr = IDirectDrawSurface_Unlock(dst, NULL);
10481 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
10483 /* Src override AND src key. That is not supposed to work. */
10484 hr = IDirectDrawSurface_Blt(dst, NULL, src, NULL, DDBLT_KEYSRC | DDBLT_KEYSRCOVERRIDE, &fx);
10485 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10487 hr = IDirectDrawSurface_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
10488 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
10489 color = surface_desc.lpSurface;
10490 /* Ensure the destination was not changed. */
10491 ok(color[0] == 0x55555555 && color[1] == 0x55555555 && color[2] == 0x55555555 &&
10492 color[3] == 0x55555555 && color[4] == 0x55555555 && color[5] == 0x55555555,
10493 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
10494 color[0], color[1], color[2], color[3], color[4], color[5]);
10496 /* Use different dst colors for the dst key test. */
10497 color[0] = 0x00ff0000; /* Dest key in dst surface. */
10498 color[1] = 0x00ff0000; /* Dest key in dst surface. */
10499 color[2] = 0x00001100; /* Dest key in override. */
10500 color[3] = 0x00001100; /* Dest key in override. */
10501 color[4] = 0x000000aa; /* Dest key in src surface. */
10502 color[5] = 0x000000aa; /* Dest key in src surface. */
10503 hr = IDirectDrawSurface_Unlock(dst, NULL);
10504 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
10506 hr = IDirectDrawSurface_Blt(dst, NULL, src, NULL, DDBLT_KEYDEST, &fx);
10507 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
10509 hr = IDirectDrawSurface_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
10510 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
10511 color = surface_desc.lpSurface;
10512 /* Dst key applied to color[4,5], they are the only changed pixels. */
10513 ok(color[0] == 0x00ff0000 && color[1] == 0x00ff0000 && color[2] == 0x00001100 &&
10514 color[3] == 0x00001100 && color[4] == 0x00001100 && color[5] == 0x00110000,
10515 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
10516 color[0], color[1], color[2], color[3], color[4], color[5]);
10518 color[0] = 0x00ff0000; /* Dest key in dst surface. */
10519 color[1] = 0x00ff0000; /* Dest key in dst surface. */
10520 color[2] = 0x00001100; /* Dest key in override. */
10521 color[3] = 0x00001100; /* Dest key in override. */
10522 color[4] = 0x000000aa; /* Dest key in src surface. */
10523 color[5] = 0x000000aa; /* Dest key in src surface. */
10524 hr = IDirectDrawSurface_Unlock(dst, NULL);
10525 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
10527 /* What happens with a QI'd newer version of the interface? It takes the key
10528 * from the destination surface. */
10529 hr = IDirectDrawSurface_QueryInterface(src, &IID_IDirectDrawSurface7, (void **)&src7);
10530 ok(SUCCEEDED(hr), "Failed to query IDirectDrawSurface interface, hr %#x.\n", hr);
10531 hr = IDirectDrawSurface_QueryInterface(dst, &IID_IDirectDrawSurface7, (void **)&dst7);
10532 ok(SUCCEEDED(hr), "Failed to query IDirectDrawSurface interface, hr %#x.\n", hr);
10534 hr = IDirectDrawSurface7_Blt(dst7, NULL, src7, NULL, DDBLT_KEYDEST, &fx);
10535 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
10537 IDirectDrawSurface7_Release(dst7);
10538 IDirectDrawSurface7_Release(src7);
10540 hr = IDirectDrawSurface_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
10541 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
10542 color = surface_desc.lpSurface;
10543 /* Dst key applied to color[0,1], they are the only changed pixels. */
10544 todo_wine ok(color[0] == 0x000000ff && color[1] == 0x000000aa && color[2] == 0x00001100 &&
10545 color[3] == 0x00001100 && color[4] == 0x000000aa && color[5] == 0x000000aa,
10546 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
10547 color[0], color[1], color[2], color[3], color[4], color[5]);
10549 color[0] = 0x00ff0000; /* Dest key in dst surface. */
10550 color[1] = 0x00ff0000; /* Dest key in dst surface. */
10551 color[2] = 0x00001100; /* Dest key in override. */
10552 color[3] = 0x00001100; /* Dest key in override. */
10553 color[4] = 0x000000aa; /* Dest key in src surface. */
10554 color[5] = 0x000000aa; /* Dest key in src surface. */
10555 hr = IDirectDrawSurface_Unlock(dst, NULL);
10556 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
10558 /* Dest override key blit. */
10559 hr = IDirectDrawSurface_Blt(dst, NULL, src, NULL, DDBLT_KEYDESTOVERRIDE, &fx);
10560 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
10562 hr = IDirectDrawSurface_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
10563 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
10564 color = surface_desc.lpSurface;
10565 /* Dst key applied to color[2,3], they are the only changed pixels. */
10566 ok(color[0] == 0x00ff0000 && color[1] == 0x00ff0000 && color[2] == 0x00ff0000 &&
10567 color[3] == 0x0000ff00 && color[4] == 0x000000aa && color[5] == 0x000000aa,
10568 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
10569 color[0], color[1], color[2], color[3], color[4], color[5]);
10571 color[0] = 0x00ff0000; /* Dest key in dst surface. */
10572 color[1] = 0x00ff0000; /* Dest key in dst surface. */
10573 color[2] = 0x00001100; /* Dest key in override. */
10574 color[3] = 0x00001100; /* Dest key in override. */
10575 color[4] = 0x000000aa; /* Dest key in src surface. */
10576 color[5] = 0x000000aa; /* Dest key in src surface. */
10577 hr = IDirectDrawSurface_Unlock(dst, NULL);
10578 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
10580 /* Dest override together with surface key. Supposed to fail. */
10581 hr = IDirectDrawSurface_Blt(dst, NULL, src, NULL, DDBLT_KEYDEST | DDBLT_KEYDESTOVERRIDE, &fx);
10582 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10584 hr = IDirectDrawSurface_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
10585 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
10586 color = surface_desc.lpSurface;
10587 /* Destination is unchanged. */
10588 ok(color[0] == 0x00ff0000 && color[1] == 0x00ff0000 && color[2] == 0x00001100 &&
10589 color[3] == 0x00001100 && color[4] == 0x000000aa && color[5] == 0x000000aa,
10590 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
10591 color[0], color[1], color[2], color[3], color[4], color[5]);
10592 hr = IDirectDrawSurface_Unlock(dst, NULL);
10593 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
10595 /* Source and destination key. This is driver dependent. New HW treats it like
10596 * DDBLT_KEYSRC. Older HW and some software renderers apply both keys. */
10597 if (0)
10599 hr = IDirectDrawSurface_Blt(dst, NULL, src, NULL, DDBLT_KEYDEST | DDBLT_KEYSRC, &fx);
10600 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
10602 hr = IDirectDrawSurface_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
10603 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
10604 color = surface_desc.lpSurface;
10605 /* Color[0] is filtered by the src key, 2-5 are filtered by the dst key, if
10606 * the driver applies it. */
10607 ok(color[0] == 0x00ff0000 && color[1] == 0x000000aa && color[2] == 0x00ff0000 &&
10608 color[3] == 0x0000ff00 && color[4] == 0x00001100 && color[5] == 0x00110000,
10609 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
10610 color[0], color[1], color[2], color[3], color[4], color[5]);
10612 color[0] = 0x00ff0000; /* Dest key in dst surface. */
10613 color[1] = 0x00ff0000; /* Dest key in dst surface. */
10614 color[2] = 0x00001100; /* Dest key in override. */
10615 color[3] = 0x00001100; /* Dest key in override. */
10616 color[4] = 0x000000aa; /* Dest key in src surface. */
10617 color[5] = 0x000000aa; /* Dest key in src surface. */
10618 hr = IDirectDrawSurface_Unlock(dst, NULL);
10619 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
10622 /* Override keys without ddbltfx parameter fail */
10623 hr = IDirectDrawSurface_Blt(dst, NULL, src, NULL, DDBLT_KEYDESTOVERRIDE, NULL);
10624 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10625 hr = IDirectDrawSurface_Blt(dst, NULL, src, NULL, DDBLT_KEYSRCOVERRIDE, NULL);
10626 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10628 /* Try blitting without keys in the source surface. */
10629 hr = IDirectDrawSurface_SetColorKey(src, DDCKEY_SRCBLT, NULL);
10630 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
10631 hr = IDirectDrawSurface_SetColorKey(src, DDCKEY_DESTBLT, NULL);
10632 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
10634 /* That fails now. Do not bother to check that the data is unmodified. */
10635 hr = IDirectDrawSurface_Blt(dst, NULL, src, NULL, DDBLT_KEYSRC, &fx);
10636 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10638 /* Surprisingly this still works. It uses the old key from the src surface. */
10639 hr = IDirectDrawSurface_Blt(dst, NULL, src, NULL, DDBLT_KEYDEST, &fx);
10640 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
10642 hr = IDirectDrawSurface_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
10643 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
10644 color = surface_desc.lpSurface;
10645 /* Dst key applied to color[4,5], they are the only changed pixels. */
10646 ok(color[0] == 0x00ff0000 && color[1] == 0x00ff0000 && color[2] == 0x00001100 &&
10647 color[3] == 0x00001100 && color[4] == 0x00001100 && color[5] == 0x00110000,
10648 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
10649 color[0], color[1], color[2], color[3], color[4], color[5]);
10650 hr = IDirectDrawSurface_Unlock(dst, NULL);
10651 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
10653 /* This returns DDERR_NOCOLORKEY as expected. */
10654 hr = IDirectDrawSurface_GetColorKey(src, DDCKEY_DESTBLT, &ckey);
10655 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
10657 /* GetSurfaceDesc returns a zeroed key as expected. */
10658 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x12345678;
10659 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x12345678;
10660 hr = IDirectDrawSurface_GetSurfaceDesc(src, &surface_desc);
10661 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
10662 ok(!surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue
10663 && !surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue,
10664 "Got unexpected color key low=%08x high=%08x.\n", surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue,
10665 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue);
10667 /* Try blitting without keys in the destination surface. */
10668 hr = IDirectDrawSurface_SetColorKey(dst, DDCKEY_SRCBLT, NULL);
10669 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
10670 hr = IDirectDrawSurface_SetColorKey(dst, DDCKEY_DESTBLT, NULL);
10671 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
10673 /* This is weird. It makes sense in v4 and v7, but because v1
10674 * uses the key from the src surface it makes no sense here. */
10675 hr = IDirectDrawSurface_Blt(dst, NULL, src, NULL, DDBLT_KEYDEST, &fx);
10676 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10678 done:
10679 IDirectDrawSurface_Release(src);
10680 IDirectDrawSurface_Release(dst);
10681 refcount = IDirectDraw_Release(ddraw);
10682 ok(!refcount, "DirectDraw has %u references left.\n", refcount);
10683 DestroyWindow(window);
10686 START_TEST(ddraw1)
10688 IDirectDraw *ddraw;
10689 DEVMODEW current_mode;
10690 HMODULE dwmapi;
10692 if (!(ddraw = create_ddraw()))
10694 skip("Failed to create a ddraw object, skipping tests.\n");
10695 return;
10697 IDirectDraw_Release(ddraw);
10699 memset(&current_mode, 0, sizeof(current_mode));
10700 current_mode.dmSize = sizeof(current_mode);
10701 ok(EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &current_mode), "Failed to get display mode.\n");
10702 registry_mode.dmSize = sizeof(registry_mode);
10703 ok(EnumDisplaySettingsW(NULL, ENUM_REGISTRY_SETTINGS, &registry_mode), "Failed to get display mode.\n");
10704 if (registry_mode.dmPelsWidth != current_mode.dmPelsWidth
10705 || registry_mode.dmPelsHeight != current_mode.dmPelsHeight)
10707 skip("Current mode does not match registry mode, skipping test.\n");
10708 return;
10711 if ((dwmapi = LoadLibraryA("dwmapi.dll")))
10712 pDwmIsCompositionEnabled = (void *)GetProcAddress(dwmapi, "DwmIsCompositionEnabled");
10714 test_coop_level_create_device_window();
10715 test_clipper_blt();
10716 test_coop_level_d3d_state();
10717 test_surface_interface_mismatch();
10718 test_coop_level_threaded();
10719 test_viewport();
10720 test_zenable();
10721 test_ck_rgba();
10722 test_ck_default();
10723 test_ck_complex();
10724 test_surface_qi();
10725 test_device_qi();
10726 test_wndproc();
10727 test_window_style();
10728 test_redundant_mode_set();
10729 test_coop_level_mode_set();
10730 test_coop_level_mode_set_multi();
10731 test_initialize();
10732 test_coop_level_surf_create();
10733 test_coop_level_multi_window();
10734 test_clear_rect_count();
10735 test_coop_level_activateapp();
10736 test_unsupported_formats();
10737 test_rt_caps();
10738 test_primary_caps();
10739 test_surface_lock();
10740 test_surface_discard();
10741 test_flip();
10742 test_sysmem_overlay();
10743 test_primary_palette();
10744 test_surface_attachment();
10745 test_pixel_format();
10746 test_create_surface_pitch();
10747 test_mipmap();
10748 test_palette_complex();
10749 test_p8_blit();
10750 test_material();
10751 test_lighting();
10752 test_palette_gdi();
10753 test_palette_alpha();
10754 test_lost_device();
10755 test_surface_desc_lock();
10756 test_texturemapblend();
10757 test_viewport_clear_rect();
10758 test_color_fill();
10759 test_colorkey_precision();
10760 test_range_colorkey();
10761 test_shademode();
10762 test_lockrect_invalid();
10763 test_yv12_overlay();
10764 test_offscreen_overlay();
10765 test_overlay_rect();
10766 test_blt();
10767 test_getdc();
10768 test_transform_vertices();
10769 test_display_mode_surface_pixel_format();
10770 test_surface_desc_size();
10771 test_texture_load();
10772 test_ck_operation();