gdiplus: Don't call GetDeviceCaps for NULL dc.
[wine.git] / dlls / ddraw / tests / ddraw4.c
bloba0e4fe18c3118e6e02a54fd65e17ad13a4fc08c0
1 /*
2 * Copyright 2005 Antoine Chavasse (a.chavasse@gmail.com)
3 * Copyright 2008, 2011, 2012-2014 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
21 #define COBJMACROS
23 #include "wine/test.h"
24 #include <limits.h>
25 #include <math.h>
26 #include "ddrawi.h"
27 #include "d3dhal.h"
29 HRESULT WINAPI GetSurfaceFromDC(HDC dc, struct IDirectDrawSurface **surface, HDC *device_dc);
31 static BOOL is_ddraw64 = sizeof(DWORD) != sizeof(DWORD *);
32 static DEVMODEW registry_mode;
34 static HRESULT (WINAPI *pDwmIsCompositionEnabled)(BOOL *);
36 struct vec2
38 float x, y;
41 struct vec3
43 float x, y, z;
46 struct vec4
48 float x, y, z, w;
51 struct create_window_thread_param
53 HWND window;
54 HANDLE window_created;
55 HANDLE destroy_window;
56 HANDLE thread;
59 static BOOL compare_uint(unsigned int x, unsigned int y, unsigned int max_diff)
61 unsigned int diff = x > y ? x - y : y - x;
63 return diff <= max_diff;
66 static BOOL compare_float(float f, float g, unsigned int ulps)
68 int x = *(int *)&f;
69 int y = *(int *)&g;
71 if (x < 0)
72 x = INT_MIN - x;
73 if (y < 0)
74 y = INT_MIN - y;
76 return compare_uint(x, y, ulps);
79 static BOOL compare_vec4(const struct vec4 *vec, float x, float y, float z, float w, unsigned int ulps)
81 return compare_float(vec->x, x, ulps)
82 && compare_float(vec->y, y, ulps)
83 && compare_float(vec->z, z, ulps)
84 && compare_float(vec->w, w, ulps);
87 static BOOL compare_color(D3DCOLOR c1, D3DCOLOR c2, BYTE max_diff)
89 return compare_uint(c1 & 0xff, c2 & 0xff, max_diff)
90 && compare_uint((c1 >> 8) & 0xff, (c2 >> 8) & 0xff, max_diff)
91 && compare_uint((c1 >> 16) & 0xff, (c2 >> 16) & 0xff, max_diff)
92 && compare_uint((c1 >> 24) & 0xff, (c2 >> 24) & 0xff, max_diff);
95 static void get_virtual_rect(RECT *rect)
97 rect->left = GetSystemMetrics(SM_XVIRTUALSCREEN);
98 rect->top = GetSystemMetrics(SM_YVIRTUALSCREEN);
99 rect->right = rect->left + GetSystemMetrics(SM_CXVIRTUALSCREEN);
100 rect->bottom = rect->top + GetSystemMetrics(SM_CYVIRTUALSCREEN);
103 /* Try to make sure pending X events have been processed before continuing */
104 static void flush_events(void)
106 int diff = 200;
107 DWORD time;
108 MSG msg;
110 time = GetTickCount() + diff;
111 while (diff > 0)
113 if (MsgWaitForMultipleObjects(0, NULL, FALSE, 100, QS_ALLINPUT) == WAIT_TIMEOUT)
114 break;
115 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
116 DispatchMessageA(&msg);
117 diff = time - GetTickCount();
121 static BOOL ddraw_get_identifier(IDirectDraw4 *ddraw, DDDEVICEIDENTIFIER *identifier)
123 HRESULT hr;
125 hr = IDirectDraw4_GetDeviceIdentifier(ddraw, identifier, 0);
126 ok(SUCCEEDED(hr), "Failed to get device identifier, hr %#lx.\n", hr);
128 return SUCCEEDED(hr);
131 static BOOL ddraw_is_warp(IDirectDraw4 *ddraw)
133 DDDEVICEIDENTIFIER identifier;
135 return strcmp(winetest_platform, "wine")
136 && ddraw_get_identifier(ddraw, &identifier)
137 && strstr(identifier.szDriver, "warp");
140 static BOOL ddraw_is_vendor(IDirectDraw4 *ddraw, DWORD vendor)
142 DDDEVICEIDENTIFIER identifier;
144 return strcmp(winetest_platform, "wine")
145 && ddraw_get_identifier(ddraw, &identifier)
146 && identifier.dwVendorId == vendor;
149 static BOOL ddraw_is_amd(IDirectDraw4 *ddraw)
151 return ddraw_is_vendor(ddraw, 0x1002);
154 static BOOL ddraw_is_intel(IDirectDraw4 *ddraw)
156 return ddraw_is_vendor(ddraw, 0x8086);
159 static BOOL ddraw_is_nvidia(IDirectDraw4 *ddraw)
161 return ddraw_is_vendor(ddraw, 0x10de);
164 static BOOL ddraw_is_vmware(IDirectDraw4 *ddraw)
166 return ddraw_is_vendor(ddraw, 0x15ad);
169 static BOOL is_software_device_type(const GUID *device_guid)
171 return device_guid != &IID_IDirect3DHALDevice;
174 static IDirectDrawSurface4 *create_overlay(IDirectDraw4 *ddraw,
175 unsigned int width, unsigned int height, DWORD format)
177 IDirectDrawSurface4 *surface;
178 DDSURFACEDESC2 desc;
180 memset(&desc, 0, sizeof(desc));
181 desc.dwSize = sizeof(desc);
182 desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
183 desc.dwWidth = width;
184 desc.dwHeight = height;
185 desc.ddsCaps.dwCaps = DDSCAPS_OVERLAY;
186 desc.ddpfPixelFormat.dwSize = sizeof(desc.ddpfPixelFormat);
187 desc.ddpfPixelFormat.dwFlags = DDPF_FOURCC;
188 desc.ddpfPixelFormat.dwFourCC = format;
190 if (FAILED(IDirectDraw4_CreateSurface(ddraw, &desc, &surface, NULL)))
191 return NULL;
192 return surface;
195 static HWND create_window(void)
197 RECT r = {0, 0, 640, 480};
199 AdjustWindowRect(&r, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
201 return CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
202 CW_USEDEFAULT, CW_USEDEFAULT, r.right - r.left, r.bottom - r.top, NULL, NULL, NULL, NULL);
205 static DWORD WINAPI create_window_thread_proc(void *param)
207 struct create_window_thread_param *p = param;
208 DWORD res;
209 BOOL ret;
211 p->window = create_window();
212 ret = SetEvent(p->window_created);
213 ok(ret, "SetEvent failed, last error %lu.\n", GetLastError());
215 for (;;)
217 MSG msg;
219 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
220 DispatchMessageA(&msg);
221 res = WaitForSingleObject(p->destroy_window, 100);
222 if (res == WAIT_OBJECT_0)
223 break;
224 if (res != WAIT_TIMEOUT)
226 ok(0, "Wait failed (%#lx), last error %lu.\n", res, GetLastError());
227 break;
231 DestroyWindow(p->window);
233 return 0;
236 static void create_window_thread(struct create_window_thread_param *p)
238 DWORD res, tid;
240 p->window_created = CreateEventA(NULL, FALSE, FALSE, NULL);
241 ok(!!p->window_created, "CreateEvent failed, last error %lu.\n", GetLastError());
242 p->destroy_window = CreateEventA(NULL, FALSE, FALSE, NULL);
243 ok(!!p->destroy_window, "CreateEvent failed, last error %lu.\n", GetLastError());
244 p->thread = CreateThread(NULL, 0, create_window_thread_proc, p, 0, &tid);
245 ok(!!p->thread, "Failed to create thread, last error %lu.\n", GetLastError());
246 res = WaitForSingleObject(p->window_created, INFINITE);
247 ok(res == WAIT_OBJECT_0, "Wait failed (%#lx), last error %lu.\n", res, GetLastError());
250 static void destroy_window_thread(struct create_window_thread_param *p)
252 SetEvent(p->destroy_window);
253 WaitForSingleObject(p->thread, INFINITE);
254 CloseHandle(p->destroy_window);
255 CloseHandle(p->window_created);
256 CloseHandle(p->thread);
259 static IDirectDrawSurface4 *get_depth_stencil(IDirect3DDevice3 *device)
261 IDirectDrawSurface4 *rt, *ret;
262 DDSCAPS2 caps = {DDSCAPS_ZBUFFER, 0, 0, {0}};
263 HRESULT hr;
265 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
266 ok(SUCCEEDED(hr), "Failed to get the render target, hr %#lx.\n", hr);
267 hr = IDirectDrawSurface4_GetAttachedSurface(rt, &caps, &ret);
268 ok(SUCCEEDED(hr) || hr == DDERR_NOTFOUND, "Failed to get the z buffer, hr %#lx.\n", hr);
269 IDirectDrawSurface4_Release(rt);
270 return ret;
273 /* Free original_modes after finished using it */
274 static BOOL save_display_modes(DEVMODEW **original_modes, unsigned int *display_count)
276 unsigned int number, size = 2, count = 0, index = 0;
277 DISPLAY_DEVICEW display_device;
278 DEVMODEW *modes, *tmp;
280 if (!(modes = malloc(size * sizeof(*modes))))
281 return FALSE;
283 display_device.cb = sizeof(display_device);
284 while (EnumDisplayDevicesW(NULL, index++, &display_device, 0))
286 /* Skip software devices */
287 if (swscanf(display_device.DeviceName, L"\\\\.\\DISPLAY%u", &number) != 1)
288 continue;
290 if (!(display_device.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP))
291 continue;
293 if (count >= size)
295 size *= 2;
296 if (!(tmp = realloc(modes, size * sizeof(*modes))))
298 free(modes);
299 return FALSE;
301 modes = tmp;
304 memset(&modes[count], 0, sizeof(modes[count]));
305 modes[count].dmSize = sizeof(modes[count]);
306 if (!EnumDisplaySettingsW(display_device.DeviceName, ENUM_CURRENT_SETTINGS, &modes[count]))
308 free(modes);
309 return FALSE;
312 lstrcpyW(modes[count++].dmDeviceName, display_device.DeviceName);
315 *original_modes = modes;
316 *display_count = count;
317 return TRUE;
320 static BOOL restore_display_modes(DEVMODEW *modes, unsigned int count)
322 unsigned int index;
323 LONG ret;
325 for (index = 0; index < count; ++index)
327 ret = ChangeDisplaySettingsExW(modes[index].dmDeviceName, &modes[index], NULL,
328 CDS_UPDATEREGISTRY | CDS_NORESET, NULL);
329 if (ret != DISP_CHANGE_SUCCESSFUL)
330 return FALSE;
332 ret = ChangeDisplaySettingsExW(NULL, NULL, NULL, 0, NULL);
333 return ret == DISP_CHANGE_SUCCESSFUL;
336 static HRESULT set_display_mode(IDirectDraw4 *ddraw, DWORD width, DWORD height)
338 if (SUCCEEDED(IDirectDraw4_SetDisplayMode(ddraw, width, height, 32, 0, 0)))
339 return DD_OK;
340 return IDirectDraw4_SetDisplayMode(ddraw, width, height, 24, 0, 0);
343 static D3DCOLOR get_surface_color(IDirectDrawSurface4 *surface, UINT x, UINT y)
345 RECT rect = {x, y, x + 1, y + 1};
346 DDSURFACEDESC2 surface_desc;
347 D3DCOLOR color;
348 HRESULT hr;
350 memset(&surface_desc, 0, sizeof(surface_desc));
351 surface_desc.dwSize = sizeof(surface_desc);
353 hr = IDirectDrawSurface4_Lock(surface, &rect, &surface_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
354 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#lx.\n", hr);
355 if (FAILED(hr))
356 return 0xdeadbeef;
358 color = *((DWORD *)surface_desc.lpSurface) & 0x00ffffff;
360 hr = IDirectDrawSurface4_Unlock(surface, &rect);
361 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx.\n", hr);
363 return color;
366 static void fill_surface(IDirectDrawSurface4 *surface, D3DCOLOR color)
368 DDSURFACEDESC2 surface_desc = {sizeof(surface_desc)};
369 HRESULT hr;
370 unsigned int x, y;
371 DWORD *ptr;
373 hr = IDirectDrawSurface4_Lock(surface, NULL, &surface_desc, DDLOCK_WAIT, NULL);
374 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
376 for (y = 0; y < surface_desc.dwHeight; ++y)
378 ptr = (DWORD *)((BYTE *)surface_desc.lpSurface + y * surface_desc.lPitch);
379 for (x = 0; x < surface_desc.dwWidth; ++x)
381 ptr[x] = color;
385 hr = IDirectDrawSurface4_Unlock(surface, NULL);
386 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
389 static void check_rect(IDirectDrawSurface4 *surface, RECT r)
391 LONG x_coords[2][2] =
393 {r.left - 1, r.left + 1},
394 {r.right + 1, r.right - 1},
396 LONG y_coords[2][2] =
398 {r.top - 1, r.top + 1},
399 {r.bottom + 1, r.bottom - 1}
401 unsigned int color, i, j, x_side, y_side;
402 LONG x, y;
404 for (i = 0; i < 2; ++i)
406 for (j = 0; j < 2; ++j)
408 for (x_side = 0; x_side < 2; ++x_side)
410 for (y_side = 0; y_side < 2; ++y_side)
412 unsigned int expected = (x_side == 1 && y_side == 1) ? 0x00ffffff : 0x00000000;
414 x = x_coords[i][x_side];
415 y = y_coords[j][y_side];
416 if (x < 0 || x >= 640 || y < 0 || y >= 480)
417 continue;
418 color = get_surface_color(surface, x, y);
419 ok(color == expected, "Pixel (%ld, %ld) has color %08x, expected %08x.\n", x, y, color, expected);
426 static HRESULT CALLBACK enum_z_fmt(DDPIXELFORMAT *format, void *ctx)
428 DDPIXELFORMAT *z_fmt = ctx;
430 if (format->dwZBufferBitDepth > z_fmt->dwZBufferBitDepth)
431 *z_fmt = *format;
433 return DDENUMRET_OK;
436 static IDirectDraw4 *create_ddraw(void)
438 IDirectDraw4 *ddraw4;
439 IDirectDraw *ddraw1;
440 HRESULT hr;
442 if (FAILED(DirectDrawCreate(NULL, &ddraw1, NULL)))
443 return NULL;
445 hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirectDraw4, (void **)&ddraw4);
446 IDirectDraw_Release(ddraw1);
447 if (FAILED(hr))
448 return NULL;
450 return ddraw4;
453 static IDirect3DDevice3 *create_device_ex(HWND window, DWORD coop_level, const GUID *device_guid,
454 IDirectDrawSurface4 **ret_surface)
456 IDirectDrawSurface4 *surface, *ds;
457 IDirect3DDevice3 *device = NULL;
458 DDSURFACEDESC2 surface_desc;
459 IDirectDraw4 *ddraw4;
460 DDPIXELFORMAT z_fmt;
461 IDirect3D3 *d3d3;
462 HRESULT hr;
464 if (!(ddraw4 = create_ddraw()))
465 return NULL;
467 hr = IDirectDraw4_SetCooperativeLevel(ddraw4, window, coop_level);
468 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
470 memset(&surface_desc, 0, sizeof(surface_desc));
471 surface_desc.dwSize = sizeof(surface_desc);
472 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
473 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
474 if (is_software_device_type(device_guid))
475 surface_desc.ddsCaps.dwCaps |= DDSCAPS_SYSTEMMEMORY;
476 surface_desc.dwWidth = 640;
477 surface_desc.dwHeight = 480;
479 hr = IDirectDraw4_CreateSurface(ddraw4, &surface_desc, &surface, NULL);
480 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
482 if (coop_level & DDSCL_NORMAL)
484 IDirectDrawClipper *clipper;
486 hr = IDirectDraw4_CreateClipper(ddraw4, 0, &clipper, NULL);
487 ok(SUCCEEDED(hr), "Failed to create clipper, hr %#lx.\n", hr);
488 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
489 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#lx.\n", hr);
490 hr = IDirectDrawSurface4_SetClipper(surface, clipper);
491 ok(SUCCEEDED(hr), "Failed to set surface clipper, hr %#lx.\n", hr);
492 IDirectDrawClipper_Release(clipper);
495 hr = IDirectDraw4_QueryInterface(ddraw4, &IID_IDirect3D3, (void **)&d3d3);
496 IDirectDraw4_Release(ddraw4);
497 if (FAILED(hr))
499 IDirectDrawSurface4_Release(surface);
500 return NULL;
503 memset(&z_fmt, 0, sizeof(z_fmt));
504 hr = IDirect3D3_EnumZBufferFormats(d3d3, device_guid, enum_z_fmt, &z_fmt);
505 if (FAILED(hr) || !z_fmt.dwSize)
507 IDirect3D3_Release(d3d3);
508 IDirectDrawSurface4_Release(surface);
509 return NULL;
512 memset(&surface_desc, 0, sizeof(surface_desc));
513 surface_desc.dwSize = sizeof(surface_desc);
514 surface_desc.dwFlags = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT;
515 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
516 if (is_software_device_type(device_guid))
517 surface_desc.ddsCaps.dwCaps |= DDSCAPS_SYSTEMMEMORY;
519 surface_desc.ddpfPixelFormat = z_fmt;
520 surface_desc.dwWidth = 640;
521 surface_desc.dwHeight = 480;
522 hr = IDirectDraw4_CreateSurface(ddraw4, &surface_desc, &ds, NULL);
523 ok(SUCCEEDED(hr), "Failed to create depth buffer, hr %#lx.\n", hr);
524 if (FAILED(hr))
526 IDirect3D3_Release(d3d3);
527 IDirectDrawSurface4_Release(surface);
528 return NULL;
531 hr = IDirectDrawSurface4_AddAttachedSurface(surface, ds);
532 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#lx.\n", hr);
533 IDirectDrawSurface4_Release(ds);
534 if (FAILED(hr))
536 IDirect3D3_Release(d3d3);
537 IDirectDrawSurface4_Release(surface);
538 return NULL;
541 hr = IDirect3D3_CreateDevice(d3d3, device_guid, surface, &device, NULL);
542 IDirect3D3_Release(d3d3);
543 if (FAILED(hr))
545 IDirectDrawSurface4_Release(surface);
546 return NULL;
548 if (ret_surface)
549 *ret_surface = surface;
550 else
551 IDirectDrawSurface4_Release(surface);
553 return device;
556 static IDirect3DDevice3 *create_device(HWND window, DWORD coop_level)
558 return create_device_ex(window, coop_level, &IID_IDirect3DHALDevice, NULL);
561 static IDirect3DViewport3 *create_viewport(IDirect3DDevice3 *device, UINT x, UINT y, UINT w, UINT h)
563 IDirect3DViewport3 *viewport;
564 D3DVIEWPORT2 vp;
565 IDirect3D3 *d3d;
566 HRESULT hr;
568 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
569 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#lx.\n", hr);
570 hr = IDirect3D3_CreateViewport(d3d, &viewport, NULL);
571 ok(SUCCEEDED(hr), "Failed to create viewport, hr %#lx.\n", hr);
572 hr = IDirect3DDevice3_AddViewport(device, viewport);
573 ok(SUCCEEDED(hr), "Failed to add viewport, hr %#lx.\n", hr);
574 memset(&vp, 0, sizeof(vp));
575 vp.dwSize = sizeof(vp);
576 vp.dwX = x;
577 vp.dwY = y;
578 vp.dwWidth = w;
579 vp.dwHeight = h;
580 vp.dvClipX = -1.0f;
581 vp.dvClipY = 1.0f;
582 vp.dvClipWidth = 2.0f;
583 vp.dvClipHeight = 2.0f;
584 vp.dvMinZ = 0.0f;
585 vp.dvMaxZ = 1.0f;
586 hr = IDirect3DViewport3_SetViewport2(viewport, &vp);
587 ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#lx.\n", hr);
588 IDirect3D3_Release(d3d);
590 return viewport;
593 static void destroy_viewport(IDirect3DDevice3 *device, IDirect3DViewport3 *viewport)
595 HRESULT hr;
597 hr = IDirect3DDevice3_DeleteViewport(device, viewport);
598 ok(SUCCEEDED(hr), "Failed to delete viewport, hr %#lx.\n", hr);
599 IDirect3DViewport3_Release(viewport);
602 static IDirect3DMaterial3 *create_material(IDirect3DDevice3 *device, D3DMATERIAL *mat)
604 IDirect3DMaterial3 *material;
605 IDirect3D3 *d3d;
606 HRESULT hr;
608 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
609 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#lx.\n", hr);
610 hr = IDirect3D3_CreateMaterial(d3d, &material, NULL);
611 ok(SUCCEEDED(hr), "Failed to create material, hr %#lx.\n", hr);
612 hr = IDirect3DMaterial3_SetMaterial(material, mat);
613 ok(SUCCEEDED(hr), "Failed to set material data, hr %#lx.\n", hr);
614 IDirect3D3_Release(d3d);
616 return material;
619 static IDirect3DMaterial3 *create_diffuse_material(IDirect3DDevice3 *device, float r, float g, float b, float a)
621 D3DMATERIAL mat;
623 memset(&mat, 0, sizeof(mat));
624 mat.dwSize = sizeof(mat);
625 mat.diffuse.r = r;
626 mat.diffuse.g = g;
627 mat.diffuse.b = b;
628 mat.diffuse.a = a;
630 return create_material(device, &mat);
633 static IDirect3DMaterial3 *create_diffuse_and_ambient_material(IDirect3DDevice3 *device,
634 float r, float g, float b, float a)
636 D3DMATERIAL mat;
638 memset(&mat, 0, sizeof(mat));
639 mat.dwSize = sizeof(mat);
640 mat.diffuse.r = r;
641 mat.diffuse.g = g;
642 mat.diffuse.b = b;
643 mat.diffuse.a = a;
645 mat.ambient.r = r;
646 mat.ambient.g = g;
647 mat.ambient.b = b;
648 mat.ambient.a = a;
650 return create_material(device, &mat);
653 static IDirect3DMaterial3 *create_specular_material(IDirect3DDevice3 *device,
654 float r, float g, float b, float a, float power)
656 D3DMATERIAL mat;
658 memset(&mat, 0, sizeof(mat));
659 mat.dwSize = sizeof(mat);
660 mat.specular.r = r;
661 mat.specular.g = g;
662 mat.specular.b = b;
663 mat.specular.a = a;
664 mat.power = power;
666 return create_material(device, &mat);
669 static IDirect3DMaterial3 *create_emissive_material(IDirect3DDevice3 *device, float r, float g, float b, float a)
671 D3DMATERIAL mat;
673 memset(&mat, 0, sizeof(mat));
674 mat.dwSize = sizeof(mat);
675 mat.emissive.r = r;
676 mat.emissive.g = g;
677 mat.emissive.b = b;
678 mat.emissive.a = a;
680 return create_material(device, &mat);
683 static void destroy_material(IDirect3DMaterial3 *material)
685 IDirect3DMaterial3_Release(material);
688 struct message
690 UINT message;
691 BOOL check_wparam;
692 WPARAM expect_wparam;
693 HRESULT ddraw_state;
696 static const struct message *expect_messages;
697 static IDirectDraw4 *focus_test_ddraw;
699 static LRESULT CALLBACK test_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
701 HRESULT hr;
703 if (expect_messages && message == expect_messages->message)
705 if (expect_messages->check_wparam)
706 ok (wparam == expect_messages->expect_wparam,
707 "Got unexpected wparam %#Ix for message %#x, expected %#Ix.\n",
708 wparam, message, expect_messages->expect_wparam);
710 if (focus_test_ddraw)
712 hr = IDirectDraw4_TestCooperativeLevel(focus_test_ddraw);
713 ok(hr == expect_messages->ddraw_state, "Got ddraw state %#lx on message %#x, expected %#lx.\n",
714 hr, message, expect_messages->ddraw_state);
717 ++expect_messages;
720 return DefWindowProcA(hwnd, message, wparam, lparam);
723 /* Set the wndproc back to what ddraw expects it to be, and release the ddraw
724 * interface. This prevents subsequent SetCooperativeLevel() calls on a
725 * different window from failing with DDERR_HWNDALREADYSET. */
726 static void fix_wndproc(HWND window, LONG_PTR proc)
728 IDirectDraw4 *ddraw;
729 HRESULT hr;
731 if (!(ddraw = create_ddraw()))
732 return;
734 SetWindowLongPtrA(window, GWLP_WNDPROC, proc);
735 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
736 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#lx.\n", hr);
737 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
738 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#lx.\n", hr);
740 IDirectDraw4_Release(ddraw);
743 static void test_process_vertices(void)
745 IDirect3DVertexBuffer *src_vb, *dst_vb;
746 IDirect3DViewport3 *viewport;
747 D3DVERTEXBUFFERDESC vb_desc;
748 IDirect3DDevice3 *device;
749 struct vec3 *src_data;
750 struct vec4 *dst_data;
751 IDirect3D3 *d3d3;
752 D3DVIEWPORT2 vp2;
753 D3DVIEWPORT vp1;
754 HWND window;
755 HRESULT hr;
757 static D3DMATRIX identity =
759 1.0f, 0.0f, 0.0f, 0.0f,
760 0.0f, 1.0f, 0.0f, 0.0f,
761 0.0f, 0.0f, 1.0f, 0.0f,
762 0.0f, 0.0f, 0.0f, 1.0f,
764 static D3DMATRIX projection =
766 1.0f, 0.0f, 0.0f, 0.0f,
767 0.0f, 1.0f, 0.0f, 0.0f,
768 0.0f, 0.0f, 1.0f, 0.0f,
769 6.0f, 7.0f, 8.0f, 1.0f,
772 window = create_window();
773 if (!(device = create_device(window, DDSCL_NORMAL)))
775 skip("Failed to create a 3D device, skipping test.\n");
776 DestroyWindow(window);
777 return;
780 hr = IDirect3DDevice3_GetDirect3D(device, &d3d3);
781 ok(SUCCEEDED(hr), "Failed to get Direct3D3 interface, hr %#lx.\n", hr);
783 memset(&vb_desc, 0, sizeof(vb_desc));
784 vb_desc.dwSize = sizeof(vb_desc);
785 vb_desc.dwFVF = D3DFVF_XYZ;
786 vb_desc.dwNumVertices = 3;
787 hr = IDirect3D3_CreateVertexBuffer(d3d3, &vb_desc, &src_vb, 0, NULL);
788 ok(SUCCEEDED(hr), "Failed to create source vertex buffer, hr %#lx.\n", hr);
790 hr = IDirect3DVertexBuffer_Lock(src_vb, DDLOCK_WRITEONLY, (void **)&src_data, NULL);
791 ok(SUCCEEDED(hr), "Failed to lock source vertex buffer, hr %#lx.\n", hr);
792 src_data[0].x = -1.0f;
793 src_data[0].y = -1.0f;
794 src_data[0].z = -1.0f;
795 src_data[1].x = 0.0f;
796 src_data[1].y = 0.0f;
797 src_data[1].z = 0.0f;
798 src_data[2].x = 1.0f;
799 src_data[2].y = 1.0f;
800 src_data[2].z = 1.0f;
801 hr = IDirect3DVertexBuffer_Unlock(src_vb);
802 ok(SUCCEEDED(hr), "Failed to unlock source vertex buffer, hr %#lx.\n", hr);
804 memset(&vb_desc, 0, sizeof(vb_desc));
805 vb_desc.dwSize = sizeof(vb_desc);
806 vb_desc.dwFVF = D3DFVF_XYZRHW;
807 vb_desc.dwNumVertices = 3;
808 hr = IDirect3D3_CreateVertexBuffer(d3d3, &vb_desc, &dst_vb, 0, NULL);
809 ok(SUCCEEDED(hr), "Failed to create destination vertex buffer, hr %#lx.\n", hr);
811 hr = IDirect3D3_CreateViewport(d3d3, &viewport, NULL);
812 ok(SUCCEEDED(hr), "Failed to create viewport, hr %#lx.\n", hr);
813 hr = IDirect3DDevice3_AddViewport(device, viewport);
814 ok(SUCCEEDED(hr), "Failed to add viewport, hr %#lx.\n", hr);
815 vp2.dwSize = sizeof(vp2);
816 vp2.dwX = 10;
817 vp2.dwY = 20;
818 vp2.dwWidth = 100;
819 vp2.dwHeight = 200;
820 vp2.dvClipX = 2.0f;
821 vp2.dvClipY = 3.0f;
822 vp2.dvClipWidth = 4.0f;
823 vp2.dvClipHeight = 5.0f;
824 vp2.dvMinZ = -2.0f;
825 vp2.dvMaxZ = 3.0f;
826 hr = IDirect3DViewport3_SetViewport2(viewport, &vp2);
827 ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#lx.\n", hr);
828 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
829 ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#lx.\n", hr);
831 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &identity);
832 ok(SUCCEEDED(hr), "Failed to set world transformation, hr %#lx.\n", hr);
833 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_VIEW, &identity);
834 ok(SUCCEEDED(hr), "Failed to set view transformation, hr %#lx.\n", hr);
835 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &identity);
836 ok(SUCCEEDED(hr), "Failed to set projection transformation, hr %#lx.\n", hr);
838 hr = IDirect3DVertexBuffer_ProcessVertices(dst_vb, D3DVOP_TRANSFORM, 0, 3, src_vb, 0, device, 0);
839 ok(SUCCEEDED(hr), "Failed to process vertices, hr %#lx.\n", hr);
841 hr = IDirect3DVertexBuffer_Lock(dst_vb, DDLOCK_READONLY, (void **)&dst_data, NULL);
842 ok(SUCCEEDED(hr), "Failed to lock destination vertex buffer, hr %#lx.\n", hr);
843 ok(compare_vec4(&dst_data[0], -6.500e+1f, +1.800e+2f, +2.000e-1f, +1.000e+0f, 4096),
844 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
845 dst_data[0].x, dst_data[0].y, dst_data[0].z, dst_data[0].w);
846 ok(compare_vec4(&dst_data[1], -4.000e+1f, +1.400e+2f, +4.000e-1f, +1.000e+0f, 4096),
847 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
848 dst_data[1].x, dst_data[1].y, dst_data[1].z, dst_data[1].w);
849 ok(compare_vec4(&dst_data[2], -1.500e+1f, +1.000e+2f, +6.000e-1f, +1.000e+0f, 4096),
850 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
851 dst_data[2].x, dst_data[2].y, dst_data[2].z, dst_data[2].w);
852 hr = IDirect3DVertexBuffer_Unlock(dst_vb);
853 ok(SUCCEEDED(hr), "Failed to unlock destination vertex buffer, hr %#lx.\n", hr);
855 hr = IDirect3DDevice3_MultiplyTransform(device, D3DTRANSFORMSTATE_PROJECTION, &projection);
856 ok(SUCCEEDED(hr), "Failed to set projection transformation, hr %#lx.\n", hr);
858 hr = IDirect3DVertexBuffer_ProcessVertices(dst_vb, D3DVOP_TRANSFORM, 0, 3, src_vb, 0, device, 0);
859 ok(SUCCEEDED(hr), "Failed to process vertices, hr %#lx.\n", hr);
861 hr = IDirect3DVertexBuffer_Lock(dst_vb, DDLOCK_READONLY, (void **)&dst_data, NULL);
862 ok(SUCCEEDED(hr), "Failed to lock destination vertex buffer, hr %#lx.\n", hr);
863 ok(compare_vec4(&dst_data[0], +8.500e+1f, -1.000e+2f, +1.800e+0f, +1.000e+0f, 4096),
864 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
865 dst_data[0].x, dst_data[0].y, dst_data[0].z, dst_data[0].w);
866 ok(compare_vec4(&dst_data[1], +1.100e+2f, -1.400e+2f, +2.000e+0f, +1.000e+0f, 4096),
867 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
868 dst_data[1].x, dst_data[1].y, dst_data[1].z, dst_data[1].w);
869 ok(compare_vec4(&dst_data[2], +1.350e+2f, -1.800e+2f, +2.200e+0f, +1.000e+0f, 4096),
870 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
871 dst_data[2].x, dst_data[2].y, dst_data[2].z, dst_data[2].w);
872 hr = IDirect3DVertexBuffer_Unlock(dst_vb);
873 ok(SUCCEEDED(hr), "Failed to unlock destination vertex buffer, hr %#lx.\n", hr);
875 vp2.dwSize = sizeof(vp2);
876 vp2.dwX = 30;
877 vp2.dwY = 40;
878 vp2.dwWidth = 90;
879 vp2.dwHeight = 80;
880 vp2.dvClipX = 4.0f;
881 vp2.dvClipY = 6.0f;
882 vp2.dvClipWidth = 2.0f;
883 vp2.dvClipHeight = 4.0f;
884 vp2.dvMinZ = 3.0f;
885 vp2.dvMaxZ = -2.0f;
886 hr = IDirect3DViewport3_SetViewport2(viewport, &vp2);
887 ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#lx.\n", hr);
889 hr = IDirect3DVertexBuffer_ProcessVertices(dst_vb, D3DVOP_TRANSFORM, 0, 3, src_vb, 0, device, 0);
890 ok(SUCCEEDED(hr), "Failed to process vertices, hr %#lx.\n", hr);
892 hr = IDirect3DVertexBuffer_Lock(dst_vb, DDLOCK_READONLY, (void **)&dst_data, NULL);
893 ok(SUCCEEDED(hr), "Failed to lock destination vertex buffer, hr %#lx.\n", hr);
894 ok(compare_vec4(&dst_data[0], +7.500e+1f, +4.000e+1f, -8.000e-1f, +1.000e+0f, 4096),
895 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
896 dst_data[0].x, dst_data[0].y, dst_data[0].z, dst_data[0].w);
897 ok(compare_vec4(&dst_data[1], +1.200e+2f, +2.000e+1f, -1.000e+0f, +1.000e+0f, 4096),
898 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
899 dst_data[1].x, dst_data[1].y, dst_data[1].z, dst_data[1].w);
900 ok(compare_vec4(&dst_data[2], +1.650e+2f, +0.000e+0f, -1.200e+0f, +1.000e+0f, 4096),
901 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
902 dst_data[2].x, dst_data[2].y, dst_data[2].z, dst_data[2].w);
903 hr = IDirect3DVertexBuffer_Unlock(dst_vb);
904 ok(SUCCEEDED(hr), "Failed to unlock destination vertex buffer, hr %#lx.\n", hr);
906 vp1.dwSize = sizeof(vp1);
907 vp1.dwX = 30;
908 vp1.dwY = 40;
909 vp1.dwWidth = 90;
910 vp1.dwHeight = 80;
911 vp1.dvScaleX = 7.0f;
912 vp1.dvScaleY = 2.0f;
913 vp1.dvMaxX = 6.0f;
914 vp1.dvMaxY = 10.0f;
915 vp1.dvMinZ = -2.0f;
916 vp1.dvMaxZ = 3.0f;
917 hr = IDirect3DViewport3_SetViewport(viewport, &vp1);
918 ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#lx.\n", hr);
920 hr = IDirect3DVertexBuffer_ProcessVertices(dst_vb, D3DVOP_TRANSFORM, 0, 3, src_vb, 0, device, 0);
921 ok(SUCCEEDED(hr), "Failed to process vertices, hr %#lx.\n", hr);
923 hr = IDirect3DVertexBuffer_Lock(dst_vb, DDLOCK_READONLY, (void **)&dst_data, NULL);
924 ok(SUCCEEDED(hr), "Failed to lock destination vertex buffer, hr %#lx.\n", hr);
925 ok(compare_vec4(&dst_data[0], +1.100e+2f, +6.800e+1f, +7.000e+0f, +1.000e+0f, 4096),
926 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
927 dst_data[0].x, dst_data[0].y, dst_data[0].z, dst_data[0].w);
928 ok(compare_vec4(&dst_data[1], +1.170e+2f, +6.600e+1f, +8.000e+0f, +1.000e+0f, 4096),
929 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
930 dst_data[1].x, dst_data[1].y, dst_data[1].z, dst_data[1].w);
931 ok(compare_vec4(&dst_data[2], +1.240e+2f, +6.400e+1f, +9.000e+0f, +1.000e+0f, 4096),
932 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
933 dst_data[2].x, dst_data[2].y, dst_data[2].z, dst_data[2].w);
934 hr = IDirect3DVertexBuffer_Unlock(dst_vb);
935 ok(SUCCEEDED(hr), "Failed to unlock destination vertex buffer, hr %#lx.\n", hr);
937 hr = IDirect3DDevice3_DeleteViewport(device, viewport);
938 ok(SUCCEEDED(hr), "Failed to delete viewport, hr %#lx.\n", hr);
940 IDirect3DVertexBuffer_Release(dst_vb);
941 IDirect3DVertexBuffer_Release(src_vb);
942 IDirect3DViewport3_Release(viewport);
943 IDirect3D3_Release(d3d3);
944 IDirect3DDevice3_Release(device);
945 DestroyWindow(window);
948 static void test_coop_level_create_device_window(void)
950 HWND focus_window, device_window;
951 IDirectDraw4 *ddraw;
952 HRESULT hr;
954 focus_window = create_window();
955 ddraw = create_ddraw();
956 ok(!!ddraw, "Failed to create a ddraw object.\n");
958 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
959 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
960 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
961 ok(!device_window, "Unexpected device window found.\n");
962 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW);
963 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
964 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
965 ok(!device_window, "Unexpected device window found.\n");
966 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_NORMAL);
967 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
968 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
969 ok(!device_window, "Unexpected device window found.\n");
970 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_NORMAL | DDSCL_FULLSCREEN);
971 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
972 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
973 ok(!device_window, "Unexpected device window found.\n");
974 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
975 ok(hr == DDERR_NOFOCUSWINDOW || broken(hr == DDERR_INVALIDPARAMS), "Got unexpected hr %#lx.\n", hr);
976 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
977 ok(!device_window, "Unexpected device window found.\n");
979 /* Windows versions before 98 / NT5 don't support DDSCL_CREATEDEVICEWINDOW. */
980 if (broken(hr == DDERR_INVALIDPARAMS))
982 win_skip("DDSCL_CREATEDEVICEWINDOW not supported, skipping test.\n");
983 IDirectDraw4_Release(ddraw);
984 DestroyWindow(focus_window);
985 return;
988 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
989 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
990 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
991 ok(!device_window, "Unexpected device window found.\n");
992 hr = IDirectDraw4_SetCooperativeLevel(ddraw, focus_window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
993 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
994 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
995 ok(!device_window, "Unexpected device window found.\n");
997 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
998 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
999 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
1000 ok(!device_window, "Unexpected device window found.\n");
1001 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_SETFOCUSWINDOW
1002 | DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
1003 ok(hr == DDERR_NOHWND, "Got unexpected hr %#lx.\n", hr);
1004 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
1005 ok(!!device_window, "Device window not found.\n");
1007 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
1008 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
1009 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
1010 ok(!device_window, "Unexpected device window found.\n");
1011 hr = IDirectDraw4_SetCooperativeLevel(ddraw, focus_window, DDSCL_SETFOCUSWINDOW
1012 | DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
1013 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
1014 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
1015 ok(!!device_window, "Device window not found.\n");
1017 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
1018 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
1019 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
1020 ok(!device_window, "Unexpected device window found.\n");
1021 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
1022 ok(hr == DDERR_NOFOCUSWINDOW, "Got unexpected hr %#lx.\n", hr);
1023 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
1024 ok(!device_window, "Unexpected device window found.\n");
1025 hr = IDirectDraw4_SetCooperativeLevel(ddraw, focus_window, DDSCL_SETFOCUSWINDOW);
1026 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
1027 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
1028 ok(!device_window, "Unexpected device window found.\n");
1029 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
1030 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
1031 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
1032 ok(!!device_window, "Device window not found.\n");
1034 IDirectDraw4_Release(ddraw);
1035 DestroyWindow(focus_window);
1038 static void test_clipper_blt(void)
1040 IDirectDrawSurface4 *src_surface, *dst_surface;
1041 unsigned int color, i, j, x, y;
1042 RECT client_rect, src_rect;
1043 IDirectDrawClipper *clipper;
1044 DDSURFACEDESC2 surface_desc;
1045 IDirectDraw4 *ddraw;
1046 RGNDATA *rgn_data;
1047 ULONG refcount;
1048 HRGN r1, r2;
1049 HWND window;
1050 DDBLTFX fx;
1051 HRESULT hr;
1052 DWORD *ptr;
1053 DWORD ret;
1055 static const DWORD src_data[] =
1057 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
1058 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
1059 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
1061 static const unsigned int expected1[] =
1063 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
1064 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
1065 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
1066 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
1068 /* Nvidia on Windows seems to have an off-by-one error
1069 * when processing source rectangles. Our left = 1 and
1070 * right = 5 input reads from x = {1, 2, 3}. x = 4 is
1071 * read as well, but only for the edge pixels on the
1072 * output image. The bug happens on the y axis as well,
1073 * but we only read one row there, and all source rows
1074 * contain the same data. This bug is not dependent on
1075 * the presence of a clipper. */
1076 static const D3DCOLOR expected1_broken[] =
1078 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
1079 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
1080 0x00000000, 0x00000000, 0x00ff0000, 0x00ff0000,
1081 0x00000000, 0x00000000, 0x0000ff00, 0x00ff0000,
1083 static const unsigned int expected2[] =
1085 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
1086 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
1087 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
1088 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
1091 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1092 10, 10, 640, 480, 0, 0, 0, 0);
1093 ShowWindow(window, SW_SHOW);
1094 ddraw = create_ddraw();
1095 ok(!!ddraw, "Failed to create a ddraw object.\n");
1097 ret = GetClientRect(window, &client_rect);
1098 ok(ret, "Failed to get client rect.\n");
1099 ret = MapWindowPoints(window, NULL, (POINT *)&client_rect, 2);
1100 ok(ret, "Failed to map client rect.\n");
1102 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
1103 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
1105 hr = IDirectDraw4_CreateClipper(ddraw, 0, &clipper, NULL);
1106 ok(SUCCEEDED(hr), "Failed to create clipper, hr %#lx.\n", hr);
1107 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
1108 ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#lx.\n", hr);
1109 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
1110 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#lx.\n", hr);
1111 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
1112 ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#lx.\n", hr);
1113 rgn_data = malloc(ret);
1114 hr = IDirectDrawClipper_GetClipList(clipper, NULL, rgn_data, &ret);
1115 ok(SUCCEEDED(hr), "Failed to get clip list, hr %#lx.\n", hr);
1116 ok(rgn_data->rdh.dwSize == sizeof(rgn_data->rdh), "Got unexpected structure size %#lx.\n", rgn_data->rdh.dwSize);
1117 ok(rgn_data->rdh.iType == RDH_RECTANGLES, "Got unexpected type %#lx.\n", rgn_data->rdh.iType);
1118 ok(rgn_data->rdh.nCount >= 1, "Got unexpected count %lu.\n", rgn_data->rdh.nCount);
1119 ok(EqualRect(&rgn_data->rdh.rcBound, &client_rect),
1120 "Got unexpected bounding rect %s, expected %s.\n",
1121 wine_dbgstr_rect(&rgn_data->rdh.rcBound), wine_dbgstr_rect(&client_rect));
1122 free(rgn_data);
1124 r1 = CreateRectRgn(0, 0, 320, 240);
1125 ok(!!r1, "Failed to create region.\n");
1126 r2 = CreateRectRgn(320, 240, 640, 480);
1127 ok(!!r2, "Failed to create region.\n");
1128 CombineRgn(r1, r1, r2, RGN_OR);
1129 ret = GetRegionData(r1, 0, NULL);
1130 rgn_data = malloc(ret);
1131 ret = GetRegionData(r1, ret, rgn_data);
1132 ok(!!ret, "Failed to get region data.\n");
1134 DeleteObject(r2);
1135 DeleteObject(r1);
1137 hr = IDirectDrawClipper_SetClipList(clipper, rgn_data, 0);
1138 ok(hr == DDERR_CLIPPERISUSINGHWND, "Got unexpected hr %#lx.\n", hr);
1139 hr = IDirectDrawClipper_SetHWnd(clipper, 0, NULL);
1140 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#lx.\n", hr);
1141 hr = IDirectDrawClipper_SetClipList(clipper, rgn_data, 0);
1142 ok(SUCCEEDED(hr), "Failed to set clip list, hr %#lx.\n", hr);
1144 free(rgn_data);
1146 memset(&surface_desc, 0, sizeof(surface_desc));
1147 surface_desc.dwSize = sizeof(surface_desc);
1148 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
1149 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
1150 surface_desc.dwWidth = 640;
1151 surface_desc.dwHeight = 480;
1152 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
1153 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB;
1154 surface_desc.ddpfPixelFormat.dwRGBBitCount = 32;
1155 surface_desc.ddpfPixelFormat.dwRBitMask = 0x00ff0000;
1156 surface_desc.ddpfPixelFormat.dwGBitMask = 0x0000ff00;
1157 surface_desc.ddpfPixelFormat.dwBBitMask = 0x000000ff;
1159 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &src_surface, NULL);
1160 ok(SUCCEEDED(hr), "Failed to create source surface, hr %#lx.\n", hr);
1161 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &dst_surface, NULL);
1162 ok(SUCCEEDED(hr), "Failed to create destination surface, hr %#lx.\n", hr);
1164 memset(&fx, 0, sizeof(fx));
1165 fx.dwSize = sizeof(fx);
1166 hr = IDirectDrawSurface4_Blt(src_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
1167 ok(SUCCEEDED(hr), "Failed to clear source surface, hr %#lx.\n", hr);
1168 hr = IDirectDrawSurface4_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
1169 ok(SUCCEEDED(hr), "Failed to clear destination surface, hr %#lx.\n", hr);
1171 hr = IDirectDrawSurface4_Lock(src_surface, NULL, &surface_desc, DDLOCK_WAIT, NULL);
1172 ok(SUCCEEDED(hr), "Failed to lock source surface, hr %#lx.\n", hr);
1173 ok(surface_desc.lPitch == 2560, "Got unexpected surface pitch %lu.\n", surface_desc.lPitch);
1174 ptr = surface_desc.lpSurface;
1175 memcpy(&ptr[ 0], &src_data[ 0], 6 * sizeof(DWORD));
1176 memcpy(&ptr[ 640], &src_data[ 6], 6 * sizeof(DWORD));
1177 memcpy(&ptr[1280], &src_data[12], 6 * sizeof(DWORD));
1178 hr = IDirectDrawSurface4_Unlock(src_surface, NULL);
1179 ok(SUCCEEDED(hr), "Failed to unlock source surface, hr %#lx.\n", hr);
1181 hr = IDirectDrawSurface4_SetClipper(dst_surface, clipper);
1182 ok(SUCCEEDED(hr), "Failed to set clipper, hr %#lx.\n", hr);
1184 SetRect(&src_rect, 1, 1, 5, 2);
1185 hr = IDirectDrawSurface4_Blt(dst_surface, NULL, src_surface, &src_rect, DDBLT_WAIT, NULL);
1186 ok(SUCCEEDED(hr), "Failed to blit, hr %#lx.\n", hr);
1187 for (i = 0; i < 4; ++i)
1189 for (j = 0; j < 4; ++j)
1191 x = 80 * ((2 * j) + 1);
1192 y = 60 * ((2 * i) + 1);
1193 color = get_surface_color(dst_surface, x, y);
1194 ok(compare_color(color, expected1[i * 4 + j], 1)
1195 || broken(compare_color(color, expected1_broken[i * 4 + j], 1)),
1196 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected1[i * 4 + j], x, y, color);
1200 fx.dwFillColor = 0xff0000ff;
1201 hr = IDirectDrawSurface4_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
1202 ok(SUCCEEDED(hr), "Failed to clear destination surface, hr %#lx.\n", hr);
1203 for (i = 0; i < 4; ++i)
1205 for (j = 0; j < 4; ++j)
1207 x = 80 * ((2 * j) + 1);
1208 y = 60 * ((2 * i) + 1);
1209 color = get_surface_color(dst_surface, x, y);
1210 ok(compare_color(color, expected2[i * 4 + j], 1),
1211 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected2[i * 4 + j], x, y, color);
1215 hr = IDirectDrawSurface4_BltFast(dst_surface, 0, 0, src_surface, NULL, DDBLTFAST_WAIT);
1216 ok(hr == DDERR_BLTFASTCANTCLIP, "Got unexpected hr %#lx.\n", hr);
1218 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
1219 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#lx.\n", hr);
1220 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
1221 ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#lx.\n", hr);
1222 DestroyWindow(window);
1223 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
1224 ok(hr == E_FAIL, "Got unexpected hr %#lx.\n", hr);
1225 hr = IDirectDrawClipper_SetHWnd(clipper, 0, NULL);
1226 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#lx.\n", hr);
1227 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
1228 ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#lx.\n", hr);
1229 hr = IDirectDrawClipper_SetClipList(clipper, NULL, 0);
1230 ok(SUCCEEDED(hr), "Failed to set clip list, hr %#lx.\n", hr);
1231 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
1232 ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#lx.\n", hr);
1233 hr = IDirectDrawSurface4_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
1234 ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#lx.\n", hr);
1236 IDirectDrawSurface4_Release(dst_surface);
1237 IDirectDrawSurface4_Release(src_surface);
1238 refcount = IDirectDrawClipper_Release(clipper);
1239 ok(!refcount, "Clipper has %lu references left.\n", refcount);
1240 IDirectDraw4_Release(ddraw);
1243 static void test_coop_level_d3d_state(void)
1245 D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
1246 IDirectDrawSurface4 *rt, *surface;
1247 IDirect3DViewport3 *viewport;
1248 IDirect3DDevice3 *device;
1249 IDirectDraw4 *ddraw;
1250 DDSURFACEDESC2 lock;
1251 unsigned int color;
1252 IDirect3D3 *d3d;
1253 DWORD value;
1254 HWND window;
1255 HRESULT hr;
1257 static struct
1259 struct vec3 position;
1260 DWORD diffuse;
1262 quad[] =
1264 {{-1.0f, -1.0f, 0.0f}, 0x800000ff},
1265 {{-1.0f, 1.0f, 0.0f}, 0x800000ff},
1266 {{ 1.0f, -1.0f, 0.0f}, 0x800000ff},
1267 {{ 1.0f, 1.0f, 0.0f}, 0x800000ff},
1270 window = create_window();
1271 if (!(device = create_device(window, DDSCL_NORMAL)))
1273 skip("Failed to create a 3D device, skipping test.\n");
1274 DestroyWindow(window);
1275 return;
1278 viewport = create_viewport(device, 0, 0, 640, 480);
1280 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);
1281 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
1282 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_DESTBLEND, D3DBLEND_DESTALPHA);
1283 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
1285 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
1286 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
1287 hr = IDirect3DDevice3_GetRenderState(device, D3DRENDERSTATE_ZENABLE, &value);
1288 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
1289 ok(!!value, "Got unexpected z-enable state %#lx.\n", value);
1290 hr = IDirect3DDevice3_GetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, &value);
1291 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
1292 ok(!value, "Got unexpected alpha blend enable state %#lx.\n", value);
1293 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);
1294 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
1295 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xffff0000, 0.0f, 0);
1296 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
1297 color = get_surface_color(rt, 320, 240);
1298 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
1300 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
1301 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
1302 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
1303 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
1304 IDirect3D3_Release(d3d);
1306 if (ddraw_is_warp(ddraw))
1308 /* ddraw4 occasionally crashes in GetRenderTarget. */
1309 win_skip("Skipping test that crashes WARP occasionally.\n");
1310 goto done;
1313 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
1314 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
1315 hr = IDirectDrawSurface4_IsLost(rt);
1316 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#lx.\n", hr);
1318 memset(&lock, 0, sizeof(lock));
1319 lock.dwSize = sizeof(lock);
1320 lock.lpSurface = (void *)0xdeadbeef;
1321 hr = IDirectDrawSurface4_Lock(rt, NULL, &lock, DDLOCK_READONLY, NULL);
1322 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#lx.\n", hr);
1323 ok(lock.lpSurface == (void *)0xdeadbeef, "Got unexpected lock.lpSurface %p.\n", lock.lpSurface);
1325 hr = IDirectDraw4_RestoreAllSurfaces(ddraw);
1326 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
1328 hr = IDirectDrawSurface4_Lock(rt, NULL, &lock, DDLOCK_READONLY, NULL);
1329 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
1330 hr = IDirectDrawSurface4_Unlock(rt, NULL);
1331 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
1333 hr = IDirect3DDevice3_GetRenderTarget(device, &surface);
1334 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
1335 ok(surface == rt, "Got unexpected surface %p.\n", surface);
1336 IDirectDrawSurface4_Release(surface);
1337 hr = IDirect3DDevice3_GetRenderState(device, D3DRENDERSTATE_ZENABLE, &value);
1338 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
1339 ok(!!value, "Got unexpected z-enable state %#lx.\n", value);
1340 hr = IDirect3DDevice3_GetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, &value);
1341 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
1342 ok(!!value, "Got unexpected alpha blend enable state %#lx.\n", value);
1343 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff00ff00, 1.0f, 0);
1344 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
1345 color = get_surface_color(rt, 320, 240);
1346 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
1348 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
1349 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
1350 hr = IDirect3DDevice3_BeginScene(device);
1351 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
1352 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
1353 D3DFVF_XYZ | D3DFVF_DIFFUSE, quad, ARRAY_SIZE(quad), 0);
1354 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
1355 hr = IDirect3DDevice3_EndScene(device);
1356 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
1357 color = get_surface_color(rt, 320, 240);
1358 ok(compare_color(color, 0x0000ff80, 1)
1359 || broken(ddraw_is_warp(ddraw) && compare_color(color, 0x0000ff00, 0)),
1360 "Got unexpected color 0x%08x.\n", color);
1362 done:
1363 destroy_viewport(device, viewport);
1364 IDirectDrawSurface4_Release(rt);
1365 IDirect3DDevice3_Release(device);
1366 IDirectDraw4_Release(ddraw);
1367 DestroyWindow(window);
1370 static void test_surface_interface_mismatch(void)
1372 IDirectDraw4 *ddraw = NULL;
1373 IDirect3D3 *d3d = NULL;
1374 IDirectDrawSurface4 *surface = NULL, *ds;
1375 IDirectDrawSurface3 *surface3 = NULL;
1376 IDirect3DDevice3 *device = NULL;
1377 IDirect3DViewport3 *viewport = NULL;
1378 DDSURFACEDESC2 surface_desc;
1379 DDPIXELFORMAT z_fmt;
1380 unsigned int color;
1381 ULONG refcount;
1382 HRESULT hr;
1383 HWND window;
1384 D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
1386 window = create_window();
1387 ddraw = create_ddraw();
1388 ok(!!ddraw, "Failed to create a ddraw object.\n");
1389 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
1390 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
1392 memset(&surface_desc, 0, sizeof(surface_desc));
1393 surface_desc.dwSize = sizeof(surface_desc);
1394 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1395 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
1396 surface_desc.dwWidth = 640;
1397 surface_desc.dwHeight = 480;
1399 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1400 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
1402 hr = IDirectDrawSurface4_QueryInterface(surface, &IID_IDirectDrawSurface3, (void **)&surface3);
1403 ok(SUCCEEDED(hr), "Failed to QI IDirectDrawSurface3, hr %#lx.\n", hr);
1405 if (FAILED(IDirectDraw4_QueryInterface(ddraw, &IID_IDirect3D3, (void **)&d3d)))
1407 skip("D3D interface is not available, skipping test.\n");
1408 goto cleanup;
1411 memset(&z_fmt, 0, sizeof(z_fmt));
1412 hr = IDirect3D3_EnumZBufferFormats(d3d, &IID_IDirect3DHALDevice, enum_z_fmt, &z_fmt);
1413 if (FAILED(hr) || !z_fmt.dwSize)
1415 skip("No depth buffer formats available, skipping test.\n");
1416 goto cleanup;
1419 memset(&surface_desc, 0, sizeof(surface_desc));
1420 surface_desc.dwSize = sizeof(surface_desc);
1421 surface_desc.dwFlags = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT;
1422 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
1423 surface_desc.ddpfPixelFormat = z_fmt;
1424 surface_desc.dwWidth = 640;
1425 surface_desc.dwHeight = 480;
1426 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &ds, NULL);
1427 ok(SUCCEEDED(hr), "Failed to create depth buffer, hr %#lx.\n", hr);
1428 if (FAILED(hr))
1429 goto cleanup;
1431 /* Using a different surface interface version still works */
1432 hr = IDirectDrawSurface3_AddAttachedSurface(surface3, (IDirectDrawSurface3 *)ds);
1433 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#lx.\n", hr);
1434 refcount = IDirectDrawSurface4_Release(ds);
1435 ok(refcount == 1, "Got unexpected refcount %lu.\n", refcount);
1436 if (FAILED(hr))
1437 goto cleanup;
1439 /* Here too */
1440 hr = IDirect3D3_CreateDevice(d3d, &IID_IDirect3DHALDevice, (IDirectDrawSurface4 *)surface3, &device, NULL);
1441 ok(SUCCEEDED(hr), "Failed to create d3d device.\n");
1442 if (FAILED(hr))
1443 goto cleanup;
1445 viewport = create_viewport(device, 0, 0, 640, 480);
1447 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xffff0000, 0.0f, 0);
1448 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#lx.\n", hr);
1449 color = get_surface_color(surface, 320, 240);
1450 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
1452 cleanup:
1453 if (viewport)
1454 destroy_viewport(device, viewport);
1455 if (surface3) IDirectDrawSurface3_Release(surface3);
1456 if (surface) IDirectDrawSurface4_Release(surface);
1457 if (device) IDirect3DDevice3_Release(device);
1458 if (d3d) IDirect3D3_Release(d3d);
1459 if (ddraw) IDirectDraw4_Release(ddraw);
1460 DestroyWindow(window);
1463 static void test_coop_level_threaded(void)
1465 struct create_window_thread_param p;
1466 IDirectDraw4 *ddraw;
1467 HRESULT hr;
1469 ddraw = create_ddraw();
1470 ok(!!ddraw, "Failed to create a ddraw object.\n");
1471 create_window_thread(&p);
1473 hr = IDirectDraw4_SetCooperativeLevel(ddraw, p.window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
1474 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
1476 destroy_window_thread(&p);
1477 IDirectDraw4_Release(ddraw);
1480 static void test_depth_blit(const GUID *device_guid)
1482 static struct
1484 float x, y, z;
1485 DWORD color;
1487 quad1[] =
1489 { -1.0, 1.0, 0.50f, 0xff00ff00},
1490 { 1.0, 1.0, 0.50f, 0xff00ff00},
1491 { -1.0, -1.0, 0.50f, 0xff00ff00},
1492 { 1.0, -1.0, 0.50f, 0xff00ff00},
1494 static const unsigned int expected_colors[4][4] =
1496 {0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00},
1497 {0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00},
1498 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1499 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1501 DDSURFACEDESC2 ddsd_new, ddsd_existing;
1503 IDirect3DDevice3 *device;
1504 IDirectDrawSurface4 *ds1, *ds2, *ds3, *rt;
1505 IDirect3DViewport3 *viewport;
1506 unsigned int color, i, j;
1507 RECT src_rect, dst_rect;
1508 HRESULT hr;
1509 IDirect3D3 *d3d;
1510 IDirectDraw4 *ddraw;
1511 DDBLTFX fx;
1512 HWND window;
1513 D3DRECT d3drect;
1515 window = create_window();
1516 if (!(device = create_device_ex(window, DDSCL_NORMAL, device_guid, NULL)))
1518 skip("Failed to create a 3D device, skipping test.\n");
1519 DestroyWindow(window);
1520 return;
1523 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
1524 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
1525 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
1526 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
1527 IDirect3D3_Release(d3d);
1529 ds1 = get_depth_stencil(device);
1531 memset(&ddsd_new, 0, sizeof(ddsd_new));
1532 ddsd_new.dwSize = sizeof(ddsd_new);
1533 memset(&ddsd_existing, 0, sizeof(ddsd_existing));
1534 ddsd_existing.dwSize = sizeof(ddsd_existing);
1535 hr = IDirectDrawSurface4_GetSurfaceDesc(ds1, &ddsd_existing);
1536 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
1537 ddsd_new.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
1538 ddsd_new.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
1539 if (is_software_device_type(device_guid))
1540 ddsd_new.ddsCaps.dwCaps |= DDSCAPS_SYSTEMMEMORY;
1541 ddsd_new.dwWidth = ddsd_existing.dwWidth;
1542 ddsd_new.dwHeight = ddsd_existing.dwHeight;
1543 ddsd_new.ddpfPixelFormat = ddsd_existing.ddpfPixelFormat;
1544 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd_new, &ds2, NULL);
1545 ok(SUCCEEDED(hr), "Failed to create a surface, hr %#lx.\n", hr);
1546 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd_new, &ds3, NULL);
1547 ok(SUCCEEDED(hr), "Failed to create a surface, hr %#lx.\n", hr);
1548 IDirectDraw4_Release(ddraw);
1550 viewport = create_viewport(device, 0, 0, ddsd_existing.dwWidth, ddsd_existing.dwHeight);
1551 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
1552 ok(SUCCEEDED(hr), "Failed to activate the viewport, hr %#lx.\n", hr);
1554 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_TRUE);
1555 ok(SUCCEEDED(hr), "Failed to enable z testing, hr %#lx.\n", hr);
1556 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ZFUNC, D3DCMP_LESSEQUAL);
1557 ok(SUCCEEDED(hr), "Failed to set the z function, hr %#lx.\n", hr);
1559 d3drect.x1 = d3drect.y1 = 0;
1560 d3drect.x2 = ddsd_existing.dwWidth; d3drect.y2 = ddsd_existing.dwHeight;
1561 hr = IDirect3DViewport3_Clear2(viewport, 1, &d3drect, D3DCLEAR_ZBUFFER, 0, 0.0f, 0);
1562 ok(SUCCEEDED(hr), "Failed to clear the z buffer, hr %#lx.\n", hr);
1564 /* Partial blit. */
1565 SetRect(&src_rect, 0, 0, 320, 240);
1566 SetRect(&dst_rect, 0, 0, 320, 240);
1567 hr = IDirectDrawSurface4_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1568 ok(SUCCEEDED(hr), "Got unexpected hr %#lx.\n", hr);
1569 /* Different locations. */
1570 SetRect(&src_rect, 0, 0, 320, 240);
1571 SetRect(&dst_rect, 320, 240, 640, 480);
1572 hr = IDirectDrawSurface4_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1573 ok(SUCCEEDED(hr), "Got unexpected hr %#lx.\n", hr);
1574 /* Stretched. */
1575 SetRect(&src_rect, 0, 0, 320, 240);
1576 SetRect(&dst_rect, 0, 0, 640, 480);
1577 hr = IDirectDrawSurface4_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1578 ok(SUCCEEDED(hr), "Got unexpected hr %#lx.\n", hr);
1579 /* Flipped. */
1580 SetRect(&src_rect, 0, 480, 640, 0);
1581 SetRect(&dst_rect, 0, 0, 640, 480);
1582 hr = IDirectDrawSurface4_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1583 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#lx.\n", hr);
1584 SetRect(&src_rect, 0, 0, 640, 480);
1585 SetRect(&dst_rect, 0, 480, 640, 0);
1586 hr = IDirectDrawSurface4_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1587 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#lx.\n", hr);
1588 /* Full, explicit. */
1589 SetRect(&src_rect, 0, 0, 640, 480);
1590 SetRect(&dst_rect, 0, 0, 640, 480);
1591 hr = IDirectDrawSurface4_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1592 ok(SUCCEEDED(hr), "Got unexpected hr %#lx.\n", hr);
1593 /* Depth -> color blit: Succeeds on Win7 + Radeon HD 5700, fails on WinXP + Radeon X1600 */
1595 /* Depth blit inside a BeginScene / EndScene pair */
1596 hr = IDirect3DDevice3_BeginScene(device);
1597 ok(SUCCEEDED(hr), "Failed to start a scene, hr %#lx.\n", hr);
1598 /* From the current depth stencil */
1599 hr = IDirectDrawSurface4_Blt(ds2, NULL, ds1, NULL, DDBLT_WAIT, NULL);
1600 ok(SUCCEEDED(hr), "Got unexpected hr %#lx.\n", hr);
1601 /* To the current depth stencil */
1602 hr = IDirectDrawSurface4_Blt(ds1, NULL, ds2, NULL, DDBLT_WAIT, NULL);
1603 ok(SUCCEEDED(hr), "Got unexpected hr %#lx.\n", hr);
1604 /* Between unbound surfaces */
1605 hr = IDirectDrawSurface4_Blt(ds3, NULL, ds2, NULL, DDBLT_WAIT, NULL);
1606 ok(SUCCEEDED(hr), "Got unexpected hr %#lx.\n", hr);
1607 hr = IDirect3DDevice3_EndScene(device);
1608 ok(SUCCEEDED(hr), "Failed to end a scene, hr %#lx.\n", hr);
1610 /* Avoid changing the depth stencil, it doesn't work properly on Windows.
1611 * Instead use DDBLT_DEPTHFILL to clear the depth stencil. Unfortunately
1612 * drivers disagree on the meaning of dwFillDepth. Only 0 seems to produce
1613 * a reliable result(z = 0.0) */
1614 memset(&fx, 0, sizeof(fx));
1615 fx.dwSize = sizeof(fx);
1616 hr = IDirectDrawSurface4_Blt(ds2, NULL, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
1617 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
1619 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
1620 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
1622 hr = IDirect3DViewport3_Clear2(viewport, 1, &d3drect, D3DCLEAR_ZBUFFER | D3DCLEAR_TARGET, 0xffff0000, 1.0f, 0);
1623 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
1625 color = get_surface_color(rt, 80, 60);
1626 /* For some reason clears and colour fill blits randomly fail with software render target. */
1627 ok(color == 0x00ff0000 || broken(is_software_device_type(device_guid) && !color),
1628 "Got unexpected colour 0x%08x.\n", color);
1629 if (!color)
1631 fill_surface(rt, 0xffff0000);
1633 color = get_surface_color(rt, 80, 60);
1634 ok(color == 0x00ff0000, "Got unexpected colour 0x%08x.\n", color);
1637 SetRect(&dst_rect, 0, 0, 320, 240);
1638 hr = IDirectDrawSurface4_Blt(ds1, &dst_rect, ds2, NULL, DDBLT_WAIT, NULL);
1639 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
1640 IDirectDrawSurface4_Release(ds3);
1641 IDirectDrawSurface4_Release(ds2);
1642 IDirectDrawSurface4_Release(ds1);
1644 hr = IDirect3DDevice3_BeginScene(device);
1645 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
1646 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE,
1647 quad1, 4, 0);
1648 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
1649 hr = IDirect3DDevice3_EndScene(device);
1650 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
1652 for (i = 0; i < 4; ++i)
1654 for (j = 0; j < 4; ++j)
1656 unsigned int x = 80 * ((2 * j) + 1);
1657 unsigned int y = 60 * ((2 * i) + 1);
1658 color = get_surface_color(rt, x, y);
1659 ok(compare_color(color, expected_colors[i][j], 1),
1660 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected_colors[i][j], x, y, color);
1663 IDirectDrawSurface4_Release(rt);
1665 destroy_viewport(device, viewport);
1666 IDirect3DDevice3_Release(device);
1667 DestroyWindow(window);
1670 static void test_texture_load_ckey(void)
1672 IDirectDraw4 *ddraw;
1673 IDirectDrawSurface4 *src;
1674 IDirectDrawSurface4 *dst;
1675 IDirect3DTexture2 *src_tex;
1676 IDirect3DTexture2 *dst_tex;
1677 DDSURFACEDESC2 ddsd;
1678 HRESULT hr;
1679 DDCOLORKEY ckey;
1681 ddraw = create_ddraw();
1682 ok(!!ddraw, "Failed to create a ddraw object.\n");
1683 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
1684 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
1686 memset(&ddsd, 0, sizeof(ddsd));
1687 ddsd.dwSize = sizeof(ddsd);
1688 ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
1689 ddsd.dwHeight = 128;
1690 ddsd.dwWidth = 128;
1691 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY;
1692 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &src, NULL);
1693 ok(SUCCEEDED(hr), "Failed to create source texture, hr %#lx.\n", hr);
1694 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1695 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &dst, NULL);
1696 ok(SUCCEEDED(hr), "Failed to create destination texture, hr %#lx.\n", hr);
1698 hr = IDirectDrawSurface4_QueryInterface(src, &IID_IDirect3DTexture2, (void **)&src_tex);
1699 ok(SUCCEEDED(hr) || hr == E_NOINTERFACE, "Failed to get Direct3DTexture2 interface, hr %#lx.\n", hr);
1700 if (FAILED(hr))
1702 /* 64 bit ddraw does not support d3d */
1703 skip("Could not get Direct3DTexture2 interface, skipping texture::Load color keying tests.\n");
1704 IDirectDrawSurface4_Release(dst);
1705 IDirectDrawSurface4_Release(src);
1706 IDirectDraw4_Release(ddraw);
1707 return;
1709 hr = IDirectDrawSurface4_QueryInterface(dst, &IID_IDirect3DTexture2, (void **)&dst_tex);
1710 ok(SUCCEEDED(hr), "Failed to get Direct3DTexture2 interface, hr %#lx.\n", hr);
1712 /* No surface has a color key */
1713 hr = IDirect3DTexture2_Load(dst_tex, src_tex);
1714 ok(SUCCEEDED(hr), "Got unexpected hr %#lx.\n", hr);
1715 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0xdeadbeef;
1716 hr = IDirectDrawSurface4_GetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1717 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#lx.\n", hr);
1718 ok(ckey.dwColorSpaceLowValue == 0xdeadbeef, "Got unexpected value 0x%08lx.\n", ckey.dwColorSpaceLowValue);
1719 ok(ckey.dwColorSpaceHighValue == 0xdeadbeef, "Got unexpected value 0x%08lx.\n", ckey.dwColorSpaceHighValue);
1721 /* Source surface has a color key */
1722 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0x0000ff00;
1723 hr = IDirectDrawSurface4_SetColorKey(src, DDCKEY_SRCBLT, &ckey);
1724 ok(SUCCEEDED(hr), "Failed to set color key, hr %#lx.\n", hr);
1725 hr = IDirect3DTexture2_Load(dst_tex, src_tex);
1726 ok(SUCCEEDED(hr), "Got unexpected hr %#lx.\n", hr);
1727 hr = IDirectDrawSurface4_GetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1728 ok(SUCCEEDED(hr), "Got unexpected hr %#lx.\n", hr);
1729 ok(ckey.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08lx.\n", ckey.dwColorSpaceLowValue);
1730 ok(ckey.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08lx.\n", ckey.dwColorSpaceHighValue);
1732 /* Both surfaces have a color key: Dest ckey is overwritten */
1733 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0x000000ff;
1734 hr = IDirectDrawSurface4_SetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1735 ok(SUCCEEDED(hr), "Failed to set color key, hr %#lx.\n", hr);
1736 hr = IDirect3DTexture2_Load(dst_tex, src_tex);
1737 ok(SUCCEEDED(hr), "Got unexpected hr %#lx.\n", hr);
1738 hr = IDirectDrawSurface4_GetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1739 ok(SUCCEEDED(hr), "Got unexpected hr %#lx.\n", hr);
1740 ok(ckey.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08lx.\n", ckey.dwColorSpaceLowValue);
1741 ok(ckey.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08lx.\n", ckey.dwColorSpaceHighValue);
1743 /* Only the destination has a color key: It is not deleted */
1744 hr = IDirectDrawSurface4_SetColorKey(src, DDCKEY_SRCBLT, NULL);
1745 ok(SUCCEEDED(hr), "Failed to set color key, hr %#lx.\n", hr);
1746 hr = IDirectDrawSurface4_GetColorKey(src, DDCKEY_SRCBLT, &ckey);
1747 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#lx.\n", hr);
1748 hr = IDirect3DTexture2_Load(dst_tex, src_tex);
1749 ok(SUCCEEDED(hr), "Got unexpected hr %#lx.\n", hr);
1750 hr = IDirectDrawSurface4_GetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1751 ok(SUCCEEDED(hr), "Got unexpected hr %#lx.\n", hr);
1752 ok(ckey.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08lx.\n", ckey.dwColorSpaceLowValue);
1753 ok(ckey.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08lx.\n", ckey.dwColorSpaceHighValue);
1755 IDirect3DTexture2_Release(dst_tex);
1756 IDirect3DTexture2_Release(src_tex);
1757 IDirectDrawSurface4_Release(dst);
1758 IDirectDrawSurface4_Release(src);
1759 IDirectDraw4_Release(ddraw);
1762 static BOOL compare_mode_rect(const DEVMODEW *mode1, const DEVMODEW *mode2)
1764 return mode1->dmPosition.x == mode2->dmPosition.x
1765 && mode1->dmPosition.y == mode2->dmPosition.y
1766 && mode1->dmPelsWidth == mode2->dmPelsWidth
1767 && mode1->dmPelsHeight == mode2->dmPelsHeight;
1770 static ULONG get_refcount(IUnknown *test_iface)
1772 IUnknown_AddRef(test_iface);
1773 return IUnknown_Release(test_iface);
1776 static void test_viewport_object(void)
1778 IDirect3DViewport3 *viewport3, *another_vp, *test_vp;
1779 IDirectDrawGammaControl *gamma;
1780 IDirect3DViewport2 *viewport2;
1781 IDirect3DViewport *viewport;
1782 IDirect3DDevice3 *device;
1783 HRESULT hr, old_d3d_ref;
1784 IDirectDraw4 *ddraw;
1785 IUnknown *unknown;
1786 D3DVIEWPORT2 vp2;
1787 IDirect3D3 *d3d;
1788 D3DVIEWPORT vp;
1789 HWND window;
1790 ULONG ref;
1791 union
1793 D3DVIEWPORT2 vp2;
1794 D3DVIEWPORT vp1;
1795 BYTE blob[1024];
1796 } desc;
1798 window = create_window();
1799 if (!(device = create_device(window, DDSCL_NORMAL)))
1801 skip("Failed to create a 3D device, skipping test.\n");
1802 DestroyWindow(window);
1803 return;
1805 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
1806 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
1807 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
1808 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
1809 old_d3d_ref = get_refcount((IUnknown *) d3d);
1811 hr = IDirect3D3_CreateViewport(d3d, &viewport3, NULL);
1812 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
1813 ref = get_refcount((IUnknown *)viewport3);
1814 ok(ref == 1, "Got unexpected refcount %lu.\n", ref);
1815 ref = get_refcount((IUnknown *)d3d);
1816 ok(ref == old_d3d_ref, "Got unexpected refcount %lu.\n", ref);
1818 memset(&desc, 0, sizeof(desc));
1819 hr = IDirect3DViewport3_GetViewport(viewport3, &desc.vp1);
1820 todo_wine ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
1821 desc.vp1.dwSize = sizeof(desc.vp1) + 1;
1822 hr = IDirect3DViewport3_GetViewport(viewport3, &desc.vp1);
1823 todo_wine ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
1824 desc.vp1.dwSize = sizeof(desc.vp1) - 1;
1825 hr = IDirect3DViewport3_GetViewport(viewport3, &desc.vp1);
1826 todo_wine ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
1827 desc.vp1.dwSize = sizeof(desc.vp1);
1828 hr = IDirect3DViewport3_GetViewport(viewport3, &desc.vp1);
1829 ok(hr == D3DERR_VIEWPORTDATANOTSET, "Got unexpected hr %#lx.\n", hr);
1830 ok(desc.vp1.dwSize == sizeof(desc.vp1), "Got unexpected dwSize %lu.\n", desc.vp1.dwSize);
1831 hr = IDirect3DViewport3_GetViewport2(viewport3, &desc.vp2);
1832 ok(hr == D3DERR_VIEWPORTDATANOTSET, "Got unexpected hr %#lx.\n", hr);
1833 ok(desc.vp2.dwSize == sizeof(desc.vp2), "Got unexpected dwSize %lu.\n", desc.vp2.dwSize);
1834 desc.vp2.dwSize = sizeof(desc.vp2) + 1;
1835 hr = IDirect3DViewport3_GetViewport2(viewport3, &desc.vp2);
1836 todo_wine ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
1838 gamma = (IDirectDrawGammaControl *)0xdeadbeef;
1839 hr = IDirect3DViewport2_QueryInterface(viewport3, &IID_IDirectDrawGammaControl, (void **)&gamma);
1840 ok(hr == E_NOINTERFACE, "Got unexpected hr %#lx.\n", hr);
1841 ok(!gamma, "Interface not set to NULL by failed QI call: %p.\n", gamma);
1842 /* NULL iid: Segfaults */
1844 hr = IDirect3DViewport3_QueryInterface(viewport3, &IID_IDirect3DViewport, (void **)&viewport);
1845 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
1846 ref = get_refcount((IUnknown *)viewport);
1847 ok(ref == 2, "Got unexpected refcount %lu.\n", ref);
1848 ref = get_refcount((IUnknown *)viewport3);
1849 ok(ref == 2, "Got unexpected refcount %lu.\n", ref);
1850 IDirect3DViewport_Release(viewport);
1851 viewport = NULL;
1853 hr = IDirect3DViewport3_QueryInterface(viewport3, &IID_IDirect3DViewport3, (void **)&viewport2);
1854 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
1855 ref = get_refcount((IUnknown *)viewport2);
1856 ok(ref == 2, "Got unexpected refcount %lu.\n", ref);
1857 ref = get_refcount((IUnknown *)viewport3);
1858 ok(ref == 2, "Got unexpected refcount %lu.\n", ref);
1859 IDirect3DViewport3_Release(viewport2);
1861 hr = IDirect3DViewport3_QueryInterface(viewport3, &IID_IUnknown, (void **)&unknown);
1862 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
1863 ref = get_refcount((IUnknown *)viewport3);
1864 ok(ref == 2, "Got unexpected refcount %lu.\n", ref);
1865 ref = get_refcount(unknown);
1866 ok(ref == 2, "Got unexpected refcount %lu.\n", ref);
1867 IUnknown_Release(unknown);
1869 hr = IDirect3DDevice3_DeleteViewport(device, NULL);
1870 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
1871 hr = IDirect3DDevice3_GetCurrentViewport(device, NULL);
1872 ok(hr == D3DERR_NOCURRENTVIEWPORT, "Got unexpected hr %#lx.\n", hr);
1874 hr = IDirect3D3_CreateViewport(d3d, &another_vp, NULL);
1875 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
1877 /* Setting a viewport not in the viewport list fails */
1878 hr = IDirect3DDevice3_SetCurrentViewport(device, another_vp);
1879 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
1881 /* AddViewport(NULL): Segfault */
1882 hr = IDirect3DDevice3_AddViewport(device, viewport3);
1883 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
1884 ref = get_refcount((IUnknown *) viewport3);
1885 ok(ref == 2, "Got unexpected refcount %lu.\n", ref);
1886 hr = IDirect3DDevice3_AddViewport(device, another_vp);
1887 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
1888 ref = get_refcount((IUnknown *) another_vp);
1889 ok(ref == 2, "Got unexpected refcount %lu.\n", ref);
1891 test_vp = (IDirect3DViewport3 *) 0xbaadc0de;
1892 hr = IDirect3DDevice3_GetCurrentViewport(device, &test_vp);
1893 ok(hr == D3DERR_NOCURRENTVIEWPORT, "Got unexpected hr %#lx.\n", hr);
1894 ok(test_vp == (IDirect3DViewport3 *) 0xbaadc0de, "Got unexpected pointer %p.\n", test_vp);
1896 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport3);
1897 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
1898 ref = get_refcount((IUnknown *) viewport3);
1899 ok(ref == 3, "Got unexpected refcount %lu.\n", ref);
1900 ref = get_refcount((IUnknown *) device);
1901 ok(ref == 1, "Got unexpected refcount %lu.\n", ref);
1903 test_vp = NULL;
1904 hr = IDirect3DDevice3_GetCurrentViewport(device, &test_vp);
1905 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
1906 ok(test_vp == viewport3, "Got unexpected viewport %p.\n", test_vp);
1907 ref = get_refcount((IUnknown *) viewport3);
1908 ok(ref == 4, "Got unexpected refcount %lu.\n", ref);
1909 if (test_vp)
1910 IDirect3DViewport3_Release(test_vp);
1912 /* GetCurrentViewport with a viewport set and NULL input param: Segfault */
1914 /* Cannot set the viewport to NULL */
1915 hr = IDirect3DDevice3_SetCurrentViewport(device, NULL);
1916 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
1917 test_vp = NULL;
1918 hr = IDirect3DDevice3_GetCurrentViewport(device, &test_vp);
1919 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
1920 ok(test_vp == viewport3, "Got unexpected viewport %p.\n", test_vp);
1921 if (test_vp)
1922 IDirect3DViewport3_Release(test_vp);
1924 /* SetCurrentViewport properly releases the old viewport's reference */
1925 hr = IDirect3DDevice3_SetCurrentViewport(device, another_vp);
1926 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
1927 ref = get_refcount((IUnknown *) viewport3);
1928 ok(ref == 2, "Got unexpected refcount %lu.\n", ref);
1929 ref = get_refcount((IUnknown *) another_vp);
1930 ok(ref == 3, "Got unexpected refcount %lu.\n", ref);
1932 /* Unlike device2::DeleteViewport, device3::DeleteViewport releases the
1933 * reference held by SetCurrentViewport */
1934 hr = IDirect3DDevice3_DeleteViewport(device, another_vp);
1935 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
1936 ref = get_refcount((IUnknown *) another_vp);
1937 ok(ref == 1, "Got unexpected refcount %lu.\n", ref);
1939 /* GetCurrentViewport still fails */
1940 test_vp = NULL;
1941 hr = IDirect3DDevice3_GetCurrentViewport(device, &test_vp);
1942 ok(hr == D3DERR_NOCURRENTVIEWPORT, "Got unexpected hr %#lx.\n", hr);
1943 ok(!test_vp, "Got unexpected viewport %p.\n", test_vp);
1945 /* Setting a different viewport doesn't have any surprises now */
1946 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport3);
1947 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
1948 ref = get_refcount((IUnknown *) viewport3);
1949 ok(ref == 3, "Got unexpected refcount %lu.\n", ref);
1950 ref = get_refcount((IUnknown *) another_vp);
1951 ok(ref == 1, "Got unexpected refcount %lu.\n", ref);
1953 memset(&vp, 0, sizeof(vp));
1954 memset(&vp, 0, sizeof(vp2));
1955 vp.dwSize = vp2.dwSize = 0;
1956 vp.dwX = vp2.dwX = 0;
1957 vp.dwY = vp2.dwY = 0;
1958 vp.dwWidth = vp2.dwWidth = 640;
1959 vp.dwHeight = vp2.dwHeight = 480;
1960 vp.dvMinZ = vp2.dvMinZ = 0.0f;
1961 vp.dvMaxZ = vp2.dvMaxZ = 1.0f;
1962 vp.dvScaleX = vp.dwWidth / 2.0f;
1963 vp.dvScaleY = vp.dwHeight / 2.0f;
1964 vp.dvMaxX = 1.0f;
1965 vp.dvMaxY = 1.0f;
1966 vp2.dvClipX = -1.0f;
1967 vp2.dvClipY = 1.0f;
1968 vp2.dvClipWidth = 2.0f;
1969 vp2.dvClipHeight = 2.0f;
1970 hr = IDirect3DViewport3_SetViewport(viewport3, &vp);
1971 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
1972 hr = IDirect3DViewport3_SetViewport2(viewport3, &vp2);
1973 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
1975 vp.dwSize = sizeof(vp);
1976 hr = IDirect3DViewport3_SetViewport(viewport3, &vp);
1977 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
1978 vp2.dwSize = sizeof(vp2);
1979 hr = IDirect3DViewport3_SetViewport2(viewport3, &vp2);
1980 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
1982 vp2.dwSize = sizeof(vp2);
1983 vp2.dwX = 160;
1984 vp2.dwY = 120;
1985 vp2.dwWidth = 640 - vp2.dwX;
1986 vp2.dwHeight = 480 - vp2.dwY;
1987 vp2.dvClipX = 2.0f;
1988 vp2.dvClipY = -1.75f;
1989 vp2.dvClipWidth = 2.5f;
1990 vp2.dvClipHeight = -1.5f;
1991 vp2.dvMinZ = 0.5f;
1992 vp2.dvMaxZ = 2.0f;
1993 hr = IDirect3DViewport3_SetViewport2(viewport3, &vp2);
1994 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
1996 memset(&vp, 0xff, sizeof(vp));
1997 vp.dwSize = sizeof(vp);
1998 hr = IDirect3DViewport3_GetViewport(viewport3, &vp);
1999 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
2000 ok(vp.dvMaxX == 4.5f && vp.dvMaxY == -1.75f && vp.dvScaleX == 192.0f
2001 && vp.dvScaleY == -240.0f && vp.dvMinZ == 0.0f && vp.dvMaxZ == 1.0f,
2002 "Got unexpected values %g, %g, %g, %g, %g, %g.\n",
2003 vp.dvMaxX, vp.dvMaxY, vp.dvScaleX, vp.dvScaleY, vp.dvMinZ, vp.dvMaxZ);
2005 vp2.dvClipX = -1.5f;
2006 vp2.dvClipY = 1.75f;
2007 vp2.dvClipWidth = -1.5f;
2008 vp2.dvClipHeight = 2.0f;
2009 vp2.dvMinZ = 2.0f;
2010 vp2.dvMaxZ = 0.5f;
2012 hr = IDirect3DViewport3_SetViewport2(viewport3, &vp2);
2013 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
2015 memset(&vp, 0xff, sizeof(vp));
2016 vp.dwSize = sizeof(vp);
2017 hr = IDirect3DViewport3_GetViewport(viewport3, &vp);
2018 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
2019 ok(vp.dvMaxX == -3.0f && vp.dvMaxY == 1.75f && vp.dvScaleX == -320.0f
2020 && vp.dvScaleY == 180.0f && vp.dvMinZ == 0.0f && vp.dvMaxZ == 1.0f,
2021 "Got unexpected values %g, %g, %g, %g, %g, %g.\n",
2022 vp.dvMaxX, vp.dvMaxY, vp.dvScaleX, vp.dvScaleY, vp.dvMinZ, vp.dvMaxZ);
2024 vp.dwSize = sizeof(vp);
2025 vp.dvMinZ = 0.5f;
2026 vp.dvMaxZ = 2.0f;
2027 hr = IDirect3DViewport3_SetViewport(viewport3, &vp);
2028 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
2030 memset(&vp2, 0xff, sizeof(vp2));
2031 vp2.dwSize = sizeof(vp2);
2032 hr = IDirect3DViewport3_GetViewport2(viewport3, &vp2);
2033 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
2034 ok(vp2.dvClipX == 0.75f && vp2.dvClipY == 1.0f && vp2.dvClipWidth == -1.5f
2035 && vp2.dvClipHeight == 2.0f && vp2.dvMinZ == 0.0f && vp2.dvMaxZ == 1.0f,
2036 "Got unexpected values %g, %g, %g, %g, %g, %g.\n",
2037 vp2.dvClipX, vp2.dvClipY, vp2.dvClipWidth, vp2.dvClipHeight, vp2.dvMinZ, vp2.dvMaxZ);
2039 vp.dvMaxX = 4.5f;
2040 vp.dvMaxY = -1.75f;
2041 vp.dvScaleX = 192.0f;
2042 vp.dvScaleY = -240.0f;
2043 vp.dvMinZ = 2.0f;
2044 vp.dvMaxZ = 0.5f;
2046 hr = IDirect3DViewport3_SetViewport(viewport3, &vp);
2047 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
2049 memset(&vp2, 0xff, sizeof(vp2));
2050 vp2.dwSize = sizeof(vp2);
2051 hr = IDirect3DViewport3_GetViewport2(viewport3, &vp2);
2052 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
2053 ok(vp2.dvClipX == -1.25f && vp2.dvClipY == -0.75f && vp2.dvClipWidth == 2.5f
2054 && vp2.dvClipHeight == -1.5f && vp2.dvMinZ == 0.0f && vp2.dvMaxZ == 1.0f,
2055 "Got unexpected values %g, %g, %g, %g, %g, %g.\n",
2056 vp2.dvClipX, vp2.dvClipY, vp2.dvClipWidth, vp2.dvClipHeight, vp2.dvMinZ, vp2.dvMaxZ);
2058 /* Destroying the device removes the viewport and releases the reference */
2059 IDirect3DDevice3_Release(device);
2060 ref = get_refcount((IUnknown *) viewport3);
2061 ok(ref == 1, "Got unexpected refcount %lu.\n", ref);
2063 memset(&vp2, 0xff, sizeof(vp2));
2064 vp2.dwSize = sizeof(vp2);
2065 hr = IDirect3DViewport3_GetViewport2(viewport3, &vp2);
2066 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
2067 ok(vp2.dvClipX == -1.25f && vp2.dvClipY == -0.75f && vp2.dvClipWidth == 2.5f
2068 && vp2.dvClipHeight == -1.5f && vp2.dvMinZ == 0.0f && vp2.dvMaxZ == 1.0f,
2069 "Got unexpected values %g, %g, %g, %g, %g, %g.\n",
2070 vp2.dvClipX, vp2.dvClipY, vp2.dvClipWidth, vp2.dvClipHeight, vp2.dvMinZ, vp2.dvMaxZ);
2072 vp.dwSize = sizeof(vp);
2073 hr = IDirect3DViewport3_SetViewport(viewport3, &vp);
2074 ok(hr == D3DERR_VIEWPORTHASNODEVICE, "Got unexpected hr %#lx.\n", hr);
2075 vp2.dwSize = sizeof(vp2);
2076 hr = IDirect3DViewport3_SetViewport2(viewport3, &vp2);
2077 ok(hr == D3DERR_VIEWPORTHASNODEVICE, "Got unexpected hr %#lx.\n", hr);
2079 ref = IDirect3DViewport3_Release(another_vp);
2080 ok(!ref, "Got unexpected refcount %lu.\n", ref);
2081 ref = IDirect3DViewport3_Release(viewport3);
2082 ok(!ref, "Got unexpected refcount %lu.\n", ref);
2083 IDirect3D3_Release(d3d);
2084 DestroyWindow(window);
2085 IDirectDraw4_Release(ddraw);
2088 static void test_zenable(const GUID *device_guid)
2090 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
2091 static struct
2093 struct vec4 position;
2094 D3DCOLOR diffuse;
2096 tquad[] =
2098 {{ 0.0f, 480.0f, -0.5f, 1.0f}, 0xff00ff00},
2099 {{ 0.0f, 0.0f, -0.5f, 1.0f}, 0xff00ff00},
2100 {{640.0f, 480.0f, 1.5f, 1.0f}, 0xff00ff00},
2101 {{640.0f, 0.0f, 1.5f, 1.0f}, 0xff00ff00},
2103 unsigned int color, x, y, i, j;
2104 IDirect3DViewport3 *viewport;
2105 IDirect3DDevice3 *device;
2106 IDirectDrawSurface4 *rt;
2107 HWND window;
2108 HRESULT hr;
2110 window = create_window();
2111 if (!(device = create_device_ex(window, DDSCL_NORMAL, device_guid, NULL)))
2113 skip("Failed to create a 3D device, skipping test.\n");
2114 DestroyWindow(window);
2115 return;
2118 viewport = create_viewport(device, 0, 0, 640, 480);
2119 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
2120 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
2122 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
2123 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
2125 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffff0000, 0.0f, 0);
2126 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
2128 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
2129 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
2131 color = get_surface_color(rt, 80, 60);
2132 /* For some reason clears and colour fill blits randomly fail with software render target. */
2133 ok(color == 0x00ff0000 || broken(is_software_device_type(device_guid) && !color),
2134 "Got unexpected colour 0x%08x.\n", color);
2135 if (!color)
2137 fill_surface(rt, 0xffff0000);
2139 color = get_surface_color(rt, 80, 60);
2140 ok(color == 0x00ff0000, "Got unexpected colour 0x%08x.\n", color);
2143 hr = IDirect3DDevice3_BeginScene(device);
2144 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
2145 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_DIFFUSE, tquad, 4, 0);
2146 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
2147 hr = IDirect3DDevice3_EndScene(device);
2148 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
2150 for (i = 0; i < 4; ++i)
2152 for (j = 0; j < 4; ++j)
2154 x = 80 * ((2 * j) + 1);
2155 y = 60 * ((2 * i) + 1);
2156 color = get_surface_color(rt, x, y);
2157 ok(compare_color(color, 0x0000ff00, 1),
2158 "Expected color 0x0000ff00 at %u, %u, got 0x%08x.\n", x, y, color);
2161 IDirectDrawSurface4_Release(rt);
2163 destroy_viewport(device, viewport);
2164 IDirect3DDevice3_Release(device);
2165 DestroyWindow(window);
2168 static void test_ck_rgba(const GUID *device_guid)
2170 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
2171 static struct
2173 struct vec4 position;
2174 struct vec2 texcoord;
2176 tquad[] =
2178 {{ 0.0f, 480.0f, 0.25f, 1.0f}, {0.0f, 0.0f}},
2179 {{ 0.0f, 0.0f, 0.25f, 1.0f}, {0.0f, 1.0f}},
2180 {{640.0f, 480.0f, 0.25f, 1.0f}, {1.0f, 0.0f}},
2181 {{640.0f, 0.0f, 0.25f, 1.0f}, {1.0f, 1.0f}},
2182 {{ 0.0f, 480.0f, 0.75f, 1.0f}, {0.0f, 0.0f}},
2183 {{ 0.0f, 0.0f, 0.75f, 1.0f}, {0.0f, 1.0f}},
2184 {{640.0f, 480.0f, 0.75f, 1.0f}, {1.0f, 0.0f}},
2185 {{640.0f, 0.0f, 0.75f, 1.0f}, {1.0f, 1.0f}},
2187 static const struct
2189 D3DCOLOR fill_color;
2190 BOOL color_key;
2191 BOOL blend;
2192 unsigned int result1, result1_broken;
2193 unsigned int result2, result2_broken;
2195 tests[] =
2197 /* r200 on Windows doesn't check the alpha component when applying the color
2198 * key, so the key matches on every texel. */
2199 {0xff00ff00, TRUE, TRUE, 0x00ff0000, 0x00ff0000, 0x000000ff, 0x000000ff},
2200 {0xff00ff00, TRUE, FALSE, 0x00ff0000, 0x00ff0000, 0x000000ff, 0x000000ff},
2201 {0xff00ff00, FALSE, TRUE, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
2202 {0xff00ff00, FALSE, FALSE, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
2203 {0x7f00ff00, TRUE, TRUE, 0x00807f00, 0x00ff0000, 0x00807f00, 0x000000ff},
2204 {0x7f00ff00, TRUE, FALSE, 0x0000ff00, 0x00ff0000, 0x0000ff00, 0x000000ff},
2205 {0x7f00ff00, FALSE, TRUE, 0x00807f00, 0x00807f00, 0x00807f00, 0x00807f00},
2206 {0x7f00ff00, FALSE, FALSE, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
2209 IDirectDrawSurface4 *surface;
2210 IDirect3DViewport3 *viewport;
2211 DDSURFACEDESC2 surface_desc;
2212 IDirect3DTexture2 *texture;
2213 IDirect3DDevice3 *device;
2214 IDirectDrawSurface4 *rt;
2215 unsigned int color, i;
2216 IDirectDraw4 *ddraw;
2217 IDirect3D3 *d3d;
2218 HWND window;
2219 DDBLTFX fx;
2220 HRESULT hr;
2222 window = create_window();
2223 if (!(device = create_device_ex(window, DDSCL_NORMAL, device_guid, NULL)))
2225 skip("Failed to create a 3D device, skipping test.\n");
2226 DestroyWindow(window);
2227 return;
2230 viewport = create_viewport(device, 0, 0, 640, 480);
2231 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
2232 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
2234 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
2235 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
2236 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
2237 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
2238 IDirect3D3_Release(d3d);
2240 memset(&surface_desc, 0, sizeof(surface_desc));
2241 surface_desc.dwSize = sizeof(surface_desc);
2242 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CKSRCBLT;
2243 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
2244 if (is_software_device_type(device_guid))
2245 surface_desc.ddsCaps.dwCaps |= DDSCAPS_SYSTEMMEMORY;
2246 surface_desc.dwWidth = 256;
2247 surface_desc.dwHeight = 256;
2248 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
2249 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
2250 surface_desc.ddpfPixelFormat.dwRGBBitCount = 32;
2251 surface_desc.ddpfPixelFormat.dwRBitMask = 0x00ff0000;
2252 surface_desc.ddpfPixelFormat.dwGBitMask = 0x0000ff00;
2253 surface_desc.ddpfPixelFormat.dwBBitMask = 0x000000ff;
2254 surface_desc.ddpfPixelFormat.dwRGBAlphaBitMask = 0xff000000;
2255 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0xff00ff00;
2256 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0xff00ff00;
2257 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
2258 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
2259 hr = IDirectDrawSurface4_QueryInterface(surface, &IID_IDirect3DTexture2, (void **)&texture);
2260 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
2262 hr = IDirect3DDevice3_SetTexture(device, 0, texture);
2263 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
2264 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);
2265 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
2266 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA);
2267 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
2269 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
2270 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
2272 for (i = 0; i < ARRAY_SIZE(tests); ++i)
2274 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, tests[i].color_key);
2275 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
2276 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, tests[i].blend);
2277 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
2279 memset(&fx, 0, sizeof(fx));
2280 fx.dwSize = sizeof(fx);
2281 fx.dwFillColor = tests[i].fill_color;
2282 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
2283 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
2285 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect,
2286 D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffff0000, 1.0f, 0);
2287 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
2288 if (is_software_device_type(device_guid))
2289 fill_surface(rt, 0xffff0000);
2290 hr = IDirect3DDevice3_BeginScene(device);
2291 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
2292 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_TEX1, &tquad[0], 4, 0);
2293 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
2294 hr = IDirect3DDevice3_EndScene(device);
2295 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
2297 color = get_surface_color(rt, 320, 240);
2298 ok(compare_color(color, tests[i].result1, 2) || compare_color(color, tests[i].result1_broken, 1),
2299 "Expected color 0x%08x for test %u, got 0x%08x.\n",
2300 tests[i].result1, i, color);
2302 fx.dwFillColor = 0xff0000ff;
2303 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
2304 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
2306 hr = IDirect3DDevice3_BeginScene(device);
2307 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
2308 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_TEX1, &tquad[4], 4, 0);
2309 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
2310 hr = IDirect3DDevice3_EndScene(device);
2311 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
2313 /* This tests that fragments that are masked out by the color key are
2314 * discarded, instead of just fully transparent. */
2315 color = get_surface_color(rt, 320, 240);
2316 ok(compare_color(color, tests[i].result2, 2) || compare_color(color, tests[i].result2_broken, 1),
2317 "Expected color 0x%08x for test %u, got 0x%08x.\n",
2318 tests[i].result2, i, color);
2321 IDirectDrawSurface4_Release(rt);
2322 IDirect3DTexture2_Release(texture);
2323 IDirectDrawSurface4_Release(surface);
2324 destroy_viewport(device, viewport);
2325 IDirectDraw4_Release(ddraw);
2326 IDirect3DDevice3_Release(device);
2327 DestroyWindow(window);
2330 static void test_ck_default(void)
2332 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
2333 static struct
2335 struct vec4 position;
2336 struct vec2 texcoord;
2338 tquad[] =
2340 {{ 0.0f, 480.0f, 0.0f, 1.0f}, {0.0f, 0.0f}},
2341 {{ 0.0f, 0.0f, 0.0f, 1.0f}, {0.0f, 1.0f}},
2342 {{640.0f, 480.0f, 0.0f, 1.0f}, {1.0f, 0.0f}},
2343 {{640.0f, 0.0f, 0.0f, 1.0f}, {1.0f, 1.0f}},
2345 IDirectDrawSurface4 *surface, *rt;
2346 IDirect3DViewport3 *viewport;
2347 DDSURFACEDESC2 surface_desc;
2348 IDirect3DTexture2 *texture;
2349 IDirect3DDevice3 *device;
2350 IDirectDraw4 *ddraw;
2351 unsigned int color;
2352 IDirect3D3 *d3d;
2353 DWORD value;
2354 HWND window;
2355 DDBLTFX fx;
2356 HRESULT hr;
2358 window = create_window();
2359 if (!(device = create_device(window, DDSCL_NORMAL)))
2361 skip("Failed to create a 3D device, skipping test.\n");
2362 DestroyWindow(window);
2363 return;
2366 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
2367 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#lx.\n", hr);
2368 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
2369 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#lx.\n", hr);
2370 IDirect3D3_Release(d3d);
2372 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
2373 ok(SUCCEEDED(hr), "Failed to get render target, hr %#lx.\n", hr);
2375 viewport = create_viewport(device, 0, 0, 640, 480);
2376 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
2377 ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#lx.\n", hr);
2379 memset(&surface_desc, 0, sizeof(surface_desc));
2380 surface_desc.dwSize = sizeof(surface_desc);
2381 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CKSRCBLT;
2382 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
2383 surface_desc.dwWidth = 256;
2384 surface_desc.dwHeight = 256;
2385 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
2386 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB;
2387 surface_desc.ddpfPixelFormat.dwRGBBitCount = 32;
2388 surface_desc.ddpfPixelFormat.dwRBitMask = 0x00ff0000;
2389 surface_desc.ddpfPixelFormat.dwGBitMask = 0x0000ff00;
2390 surface_desc.ddpfPixelFormat.dwBBitMask = 0x000000ff;
2391 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x000000ff;
2392 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x000000ff;
2393 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
2394 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
2395 hr = IDirectDrawSurface4_QueryInterface(surface, &IID_IDirect3DTexture2, (void **)&texture);
2396 ok(SUCCEEDED(hr), "Failed to get texture interface, hr %#lx.\n", hr);
2397 hr = IDirect3DDevice3_SetTexture(device, 0, texture);
2398 ok(SUCCEEDED(hr), "Failed to set texture, hr %#lx.\n", hr);
2400 memset(&fx, 0, sizeof(fx));
2401 fx.dwSize = sizeof(fx);
2402 fx.dwFillColor = 0x000000ff;
2403 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
2404 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#lx.\n", hr);
2406 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xff00ff00, 1.0f, 0);
2407 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#lx.\n", hr);
2408 hr = IDirect3DDevice3_BeginScene(device);
2409 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#lx.\n", hr);
2410 hr = IDirect3DDevice3_GetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, &value);
2411 ok(SUCCEEDED(hr), "Failed to get render state, hr %#lx.\n", hr);
2412 ok(!value, "Got unexpected color keying state %#lx.\n", value);
2413 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_TEX1, &tquad[0], 4, 0);
2414 ok(SUCCEEDED(hr), "Failed to draw, hr %#lx.\n", hr);
2415 hr = IDirect3DDevice3_EndScene(device);
2416 ok(SUCCEEDED(hr), "Failed to end scene, hr %#lx.\n", hr);
2417 color = get_surface_color(rt, 320, 240);
2418 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
2420 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xff00ff00, 1.0f, 0);
2421 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#lx.\n", hr);
2422 hr = IDirect3DDevice3_BeginScene(device);
2423 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#lx.\n", hr);
2424 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, TRUE);
2425 ok(SUCCEEDED(hr), "Failed to enable color keying, hr %#lx.\n", hr);
2426 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_TEX1, &tquad[0], 4, 0);
2427 ok(SUCCEEDED(hr), "Failed to draw, hr %#lx.\n", hr);
2428 hr = IDirect3DDevice3_GetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, &value);
2429 ok(SUCCEEDED(hr), "Failed to get render state, hr %#lx.\n", hr);
2430 ok(!!value, "Got unexpected color keying state %#lx.\n", value);
2431 hr = IDirect3DDevice3_EndScene(device);
2432 ok(SUCCEEDED(hr), "Failed to end scene, hr %#lx.\n", hr);
2433 color = get_surface_color(rt, 320, 240);
2434 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
2436 IDirect3DTexture_Release(texture);
2437 IDirectDrawSurface4_Release(surface);
2438 destroy_viewport(device, viewport);
2439 IDirectDrawSurface4_Release(rt);
2440 IDirect3DDevice3_Release(device);
2441 IDirectDraw4_Release(ddraw);
2442 DestroyWindow(window);
2445 static void test_ck_complex(void)
2447 IDirectDrawSurface4 *surface, *mipmap, *tmp;
2448 DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, {0}};
2449 DDSURFACEDESC2 surface_desc;
2450 IDirect3DDevice3 *device;
2451 DDCOLORKEY color_key;
2452 IDirectDraw4 *ddraw;
2453 IDirect3D3 *d3d;
2454 unsigned int i;
2455 ULONG refcount;
2456 HWND window;
2457 HRESULT hr;
2459 window = create_window();
2460 if (!(device = create_device(window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN)))
2462 skip("Failed to create a 3D device, skipping test.\n");
2463 DestroyWindow(window);
2464 return;
2466 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
2467 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#lx.\n", hr);
2468 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
2469 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#lx.\n", hr);
2470 IDirect3D3_Release(d3d);
2472 memset(&surface_desc, 0, sizeof(surface_desc));
2473 surface_desc.dwSize = sizeof(surface_desc);
2474 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
2475 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
2476 surface_desc.dwWidth = 128;
2477 surface_desc.dwHeight = 128;
2478 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
2479 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
2481 hr = IDirectDrawSurface4_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
2482 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#lx.\n", hr);
2483 color_key.dwColorSpaceLowValue = 0x0000ff00;
2484 color_key.dwColorSpaceHighValue = 0x0000ff00;
2485 hr = IDirectDrawSurface4_SetColorKey(surface, DDCKEY_SRCBLT, &color_key);
2486 ok(SUCCEEDED(hr), "Failed to set color key, hr %#lx.\n", hr);
2487 memset(&color_key, 0, sizeof(color_key));
2488 hr = IDirectDrawSurface4_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
2489 ok(SUCCEEDED(hr), "Failed to get color key, hr %#lx.\n", hr);
2490 ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08lx.\n",
2491 color_key.dwColorSpaceLowValue);
2492 ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08lx.\n",
2493 color_key.dwColorSpaceHighValue);
2495 mipmap = surface;
2496 IDirectDrawSurface_AddRef(mipmap);
2497 for (i = 0; i < 7; ++i)
2499 hr = IDirectDrawSurface4_GetAttachedSurface(mipmap, &caps, &tmp);
2500 ok(SUCCEEDED(hr), "Failed to get attached surface, i %u, hr %#lx.\n", i, hr);
2502 hr = IDirectDrawSurface4_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
2503 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#lx, i %u.\n", hr, i);
2504 color_key.dwColorSpaceLowValue = 0x000000ff;
2505 color_key.dwColorSpaceHighValue = 0x000000ff;
2506 hr = IDirectDrawSurface4_SetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
2507 ok(SUCCEEDED(hr), "Failed to set color key, hr %#lx, i %u.\n", hr, i);
2508 memset(&color_key, 0, sizeof(color_key));
2509 hr = IDirectDrawSurface4_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
2510 ok(SUCCEEDED(hr), "Failed to get color key, hr %#lx, i %u.\n", hr, i);
2511 ok(color_key.dwColorSpaceLowValue == 0x000000ff, "Got unexpected value 0x%08lx, i %u.\n",
2512 color_key.dwColorSpaceLowValue, i);
2513 ok(color_key.dwColorSpaceHighValue == 0x000000ff, "Got unexpected value 0x%08lx, i %u.\n",
2514 color_key.dwColorSpaceHighValue, i);
2516 IDirectDrawSurface_Release(mipmap);
2517 mipmap = tmp;
2520 memset(&color_key, 0, sizeof(color_key));
2521 hr = IDirectDrawSurface4_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
2522 ok(SUCCEEDED(hr), "Failed to get color key, hr %#lx.\n", hr);
2523 ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08lx.\n",
2524 color_key.dwColorSpaceLowValue);
2525 ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08lx.\n",
2526 color_key.dwColorSpaceHighValue);
2528 hr = IDirectDrawSurface4_GetAttachedSurface(mipmap, &caps, &tmp);
2529 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#lx.\n", hr);
2530 IDirectDrawSurface_Release(mipmap);
2531 refcount = IDirectDrawSurface4_Release(surface);
2532 ok(!refcount, "Got unexpected refcount %lu.\n", refcount);
2534 memset(&surface_desc, 0, sizeof(surface_desc));
2535 surface_desc.dwSize = sizeof(surface_desc);
2536 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
2537 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
2538 surface_desc.dwBackBufferCount = 1;
2539 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
2540 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
2542 hr = IDirectDrawSurface4_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
2543 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#lx.\n", hr);
2544 color_key.dwColorSpaceLowValue = 0x0000ff00;
2545 color_key.dwColorSpaceHighValue = 0x0000ff00;
2546 hr = IDirectDrawSurface4_SetColorKey(surface, DDCKEY_SRCBLT, &color_key);
2547 ok(SUCCEEDED(hr), "Failed to set color key, hr %#lx.\n", hr);
2548 memset(&color_key, 0, sizeof(color_key));
2549 hr = IDirectDrawSurface4_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
2550 ok(SUCCEEDED(hr), "Failed to get color key, hr %#lx.\n", hr);
2551 ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08lx.\n",
2552 color_key.dwColorSpaceLowValue);
2553 ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08lx.\n",
2554 color_key.dwColorSpaceHighValue);
2556 hr = IDirectDrawSurface4_GetAttachedSurface(surface, &caps, &tmp);
2557 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#lx.\n", hr);
2559 hr = IDirectDrawSurface4_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
2560 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#lx, i %u.\n", hr, i);
2561 color_key.dwColorSpaceLowValue = 0x0000ff00;
2562 color_key.dwColorSpaceHighValue = 0x0000ff00;
2563 hr = IDirectDrawSurface4_SetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
2564 ok(SUCCEEDED(hr), "Failed to set color key, hr %#lx.\n", hr);
2565 memset(&color_key, 0, sizeof(color_key));
2566 hr = IDirectDrawSurface4_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
2567 ok(SUCCEEDED(hr), "Failed to get color key, hr %#lx.\n", hr);
2568 ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08lx.\n",
2569 color_key.dwColorSpaceLowValue);
2570 ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08lx.\n",
2571 color_key.dwColorSpaceHighValue);
2573 IDirectDrawSurface_Release(tmp);
2575 refcount = IDirectDrawSurface4_Release(surface);
2576 ok(!refcount, "Got unexpected refcount %lu.\n", refcount);
2577 IDirectDraw4_Release(ddraw);
2578 refcount = IDirect3DDevice3_Release(device);
2579 ok(!refcount, "Got unexpected refcount %lu.\n", refcount);
2580 DestroyWindow(window);
2583 struct qi_test
2585 REFIID iid;
2586 REFIID refcount_iid;
2587 HRESULT hr;
2590 static void test_qi(const char *test_name, IUnknown *base_iface,
2591 REFIID refcount_iid, const struct qi_test *tests, UINT entry_count)
2593 ULONG refcount, expected_refcount;
2594 IUnknown *iface1, *iface2;
2595 HRESULT hr;
2596 UINT i, j;
2598 for (i = 0; i < entry_count; ++i)
2600 hr = IUnknown_QueryInterface(base_iface, tests[i].iid, (void **)&iface1);
2601 ok(hr == tests[i].hr, "Got hr %#lx for test \"%s\" %u.\n", hr, test_name, i);
2602 if (SUCCEEDED(hr))
2604 for (j = 0; j < entry_count; ++j)
2606 hr = IUnknown_QueryInterface(iface1, tests[j].iid, (void **)&iface2);
2607 ok(hr == tests[j].hr, "Got hr %#lx for test \"%s\" %u, %u.\n", hr, test_name, i, j);
2608 if (SUCCEEDED(hr))
2610 expected_refcount = 0;
2611 if (IsEqualGUID(refcount_iid, tests[j].refcount_iid))
2612 ++expected_refcount;
2613 if (IsEqualGUID(tests[i].refcount_iid, tests[j].refcount_iid))
2614 ++expected_refcount;
2615 refcount = IUnknown_Release(iface2);
2616 ok(refcount == expected_refcount, "Got refcount %lu for test \"%s\" %u, %u, expected %lu.\n",
2617 refcount, test_name, i, j, expected_refcount);
2621 expected_refcount = 0;
2622 if (IsEqualGUID(refcount_iid, tests[i].refcount_iid))
2623 ++expected_refcount;
2624 refcount = IUnknown_Release(iface1);
2625 ok(refcount == expected_refcount, "Got refcount %lu for test \"%s\" %u, expected %lu.\n",
2626 refcount, test_name, i, expected_refcount);
2631 static void test_surface_qi(void)
2633 static const struct qi_test tests[] =
2635 {&IID_IDirect3DTexture2, &IID_IDirectDrawSurface4, S_OK },
2636 {&IID_IDirect3DTexture, &IID_IDirectDrawSurface4, S_OK },
2637 {&IID_IDirectDrawGammaControl, &IID_IDirectDrawGammaControl, S_OK },
2638 {&IID_IDirectDrawColorControl, NULL, E_NOINTERFACE},
2639 {&IID_IDirectDrawSurface7, &IID_IDirectDrawSurface7, S_OK },
2640 {&IID_IDirectDrawSurface4, &IID_IDirectDrawSurface4, S_OK },
2641 {&IID_IDirectDrawSurface3, &IID_IDirectDrawSurface3, S_OK },
2642 {&IID_IDirectDrawSurface2, &IID_IDirectDrawSurface2, S_OK },
2643 {&IID_IDirectDrawSurface, &IID_IDirectDrawSurface, S_OK },
2644 {&IID_IDirect3DDevice7, NULL, E_INVALIDARG },
2645 {&IID_IDirect3DDevice3, NULL, E_INVALIDARG },
2646 {&IID_IDirect3DDevice2, NULL, E_INVALIDARG },
2647 {&IID_IDirect3DDevice, NULL, E_INVALIDARG },
2648 {&IID_IDirect3D7, NULL, E_INVALIDARG },
2649 {&IID_IDirect3D3, NULL, E_INVALIDARG },
2650 {&IID_IDirect3D2, NULL, E_INVALIDARG },
2651 {&IID_IDirect3D, NULL, E_INVALIDARG },
2652 {&IID_IDirectDraw7, NULL, E_INVALIDARG },
2653 {&IID_IDirectDraw4, NULL, E_INVALIDARG },
2654 {&IID_IDirectDraw3, NULL, E_INVALIDARG },
2655 {&IID_IDirectDraw2, NULL, E_INVALIDARG },
2656 {&IID_IDirectDraw, NULL, E_INVALIDARG },
2657 {&IID_IDirect3DLight, NULL, E_INVALIDARG },
2658 {&IID_IDirect3DMaterial, NULL, E_INVALIDARG },
2659 {&IID_IDirect3DMaterial2, NULL, E_INVALIDARG },
2660 {&IID_IDirect3DMaterial3, NULL, E_INVALIDARG },
2661 {&IID_IDirect3DExecuteBuffer, NULL, E_INVALIDARG },
2662 {&IID_IDirect3DViewport, NULL, E_INVALIDARG },
2663 {&IID_IDirect3DViewport2, NULL, E_INVALIDARG },
2664 {&IID_IDirect3DViewport3, NULL, E_INVALIDARG },
2665 {&IID_IDirect3DVertexBuffer, NULL, E_INVALIDARG },
2666 {&IID_IDirect3DVertexBuffer7, NULL, E_INVALIDARG },
2667 {&IID_IDirectDrawPalette, NULL, E_INVALIDARG },
2668 {&IID_IDirectDrawClipper, NULL, E_INVALIDARG },
2669 {&IID_IUnknown, &IID_IDirectDrawSurface, S_OK },
2670 {NULL, NULL, E_INVALIDARG },
2673 IDirectDrawSurface4 *surface;
2674 DDSURFACEDESC2 surface_desc;
2675 IDirect3DDevice3 *device;
2676 IDirectDraw4 *ddraw;
2677 HWND window;
2678 HRESULT hr;
2680 if (!GetProcAddress(GetModuleHandleA("ddraw.dll"), "DirectDrawCreateEx"))
2682 win_skip("DirectDrawCreateEx not available, skipping test.\n");
2683 return;
2686 window = create_window();
2687 /* Try to create a D3D device to see if the ddraw implementation supports
2688 * D3D. 64-bit ddraw in particular doesn't seem to support D3D, and
2689 * doesn't support e.g. the IDirect3DTexture interfaces. */
2690 if (!(device = create_device(window, DDSCL_NORMAL)))
2692 skip("Failed to create a 3D device, skipping test.\n");
2693 DestroyWindow(window);
2694 return;
2696 IDirect3DDevice_Release(device);
2697 ddraw = create_ddraw();
2698 ok(!!ddraw, "Failed to create a ddraw object.\n");
2699 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2700 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
2702 memset(&surface_desc, 0, sizeof(surface_desc));
2703 surface_desc.dwSize = sizeof(surface_desc);
2704 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
2705 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
2706 surface_desc.dwWidth = 512;
2707 surface_desc.dwHeight = 512;
2708 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, (IDirectDrawSurface4 **)0xdeadbeef, NULL);
2709 ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr);
2710 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
2711 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
2713 test_qi("surface_qi", (IUnknown *)surface, &IID_IDirectDrawSurface4, tests, ARRAY_SIZE(tests));
2715 IDirectDrawSurface4_Release(surface);
2716 IDirectDraw4_Release(ddraw);
2717 DestroyWindow(window);
2720 static void test_device_qi(void)
2722 static const struct qi_test tests[] =
2724 {&IID_IDirect3DTexture2, NULL, E_NOINTERFACE},
2725 {&IID_IDirect3DTexture, NULL, E_NOINTERFACE},
2726 {&IID_IDirectDrawGammaControl, NULL, E_NOINTERFACE},
2727 {&IID_IDirectDrawColorControl, NULL, E_NOINTERFACE},
2728 {&IID_IDirectDrawSurface7, NULL, E_NOINTERFACE},
2729 {&IID_IDirectDrawSurface4, NULL, E_NOINTERFACE},
2730 {&IID_IDirectDrawSurface3, NULL, E_NOINTERFACE},
2731 {&IID_IDirectDrawSurface2, NULL, E_NOINTERFACE},
2732 {&IID_IDirectDrawSurface, NULL, E_NOINTERFACE},
2733 {&IID_IDirect3DDevice7, NULL, E_NOINTERFACE},
2734 {&IID_IDirect3DDevice3, &IID_IDirect3DDevice3, S_OK },
2735 {&IID_IDirect3DDevice2, &IID_IDirect3DDevice3, S_OK },
2736 {&IID_IDirect3DDevice, &IID_IDirect3DDevice3, S_OK },
2737 {&IID_IDirect3DRampDevice, NULL, E_NOINTERFACE},
2738 {&IID_IDirect3DRGBDevice, NULL, E_NOINTERFACE},
2739 {&IID_IDirect3DHALDevice, NULL, E_NOINTERFACE},
2740 {&IID_IDirect3DMMXDevice, NULL, E_NOINTERFACE},
2741 {&IID_IDirect3DRefDevice, NULL, E_NOINTERFACE},
2742 {&IID_IDirect3DTnLHalDevice, NULL, E_NOINTERFACE},
2743 {&IID_IDirect3DNullDevice, NULL, E_NOINTERFACE},
2744 {&IID_IDirect3D7, NULL, E_NOINTERFACE},
2745 {&IID_IDirect3D3, NULL, E_NOINTERFACE},
2746 {&IID_IDirect3D2, NULL, E_NOINTERFACE},
2747 {&IID_IDirect3D, NULL, E_NOINTERFACE},
2748 {&IID_IDirectDraw7, NULL, E_NOINTERFACE},
2749 {&IID_IDirectDraw4, NULL, E_NOINTERFACE},
2750 {&IID_IDirectDraw3, NULL, E_NOINTERFACE},
2751 {&IID_IDirectDraw2, NULL, E_NOINTERFACE},
2752 {&IID_IDirectDraw, NULL, E_NOINTERFACE},
2753 {&IID_IDirect3DLight, NULL, E_NOINTERFACE},
2754 {&IID_IDirect3DMaterial, NULL, E_NOINTERFACE},
2755 {&IID_IDirect3DMaterial2, NULL, E_NOINTERFACE},
2756 {&IID_IDirect3DMaterial3, NULL, E_NOINTERFACE},
2757 {&IID_IDirect3DExecuteBuffer, NULL, E_NOINTERFACE},
2758 {&IID_IDirect3DViewport, NULL, E_NOINTERFACE},
2759 {&IID_IDirect3DViewport2, NULL, E_NOINTERFACE},
2760 {&IID_IDirect3DViewport3, NULL, E_NOINTERFACE},
2761 {&IID_IDirect3DVertexBuffer, NULL, E_NOINTERFACE},
2762 {&IID_IDirect3DVertexBuffer7, NULL, E_NOINTERFACE},
2763 {&IID_IDirectDrawPalette, NULL, E_NOINTERFACE},
2764 {&IID_IDirectDrawClipper, NULL, E_NOINTERFACE},
2765 {&IID_IUnknown, &IID_IDirect3DDevice3, S_OK },
2768 IDirect3DDevice3 *device;
2769 HWND window;
2771 window = create_window();
2772 if (!(device = create_device(window, DDSCL_NORMAL)))
2774 skip("Failed to create a 3D device, skipping test.\n");
2775 DestroyWindow(window);
2776 return;
2779 test_qi("device_qi", (IUnknown *)device, &IID_IDirect3DDevice3, tests, ARRAY_SIZE(tests));
2781 IDirect3DDevice3_Release(device);
2782 DestroyWindow(window);
2785 static void test_wndproc(void)
2787 LONG_PTR proc, ddraw_proc;
2788 IDirectDraw4 *ddraw;
2789 WNDCLASSA wc = {0};
2790 HWND window;
2791 HRESULT hr;
2792 ULONG ref;
2794 static struct message messages[] =
2796 {WM_WINDOWPOSCHANGING, FALSE, 0},
2797 {WM_MOVE, FALSE, 0},
2798 {WM_SIZE, FALSE, 0},
2799 {WM_WINDOWPOSCHANGING, FALSE, 0},
2800 {WM_ACTIVATE, FALSE, 0},
2801 {WM_SETFOCUS, FALSE, 0},
2802 {0, FALSE, 0},
2805 /* DDSCL_EXCLUSIVE replaces the window's window proc. */
2806 ddraw = create_ddraw();
2807 ok(!!ddraw, "Failed to create a ddraw object.\n");
2809 wc.lpfnWndProc = test_proc;
2810 wc.lpszClassName = "ddraw_test_wndproc_wc";
2811 ok(RegisterClassA(&wc), "Failed to register window class.\n");
2813 window = CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
2814 WS_MAXIMIZE | WS_CAPTION , 0, 0, 640, 480, 0, 0, 0, 0);
2816 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2817 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#Ix, got %#Ix.\n",
2818 (LONG_PTR)test_proc, proc);
2819 expect_messages = messages;
2820 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2821 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#lx.\n", hr);
2822 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2823 expect_messages = NULL;
2824 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2825 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#Ix, got %#Ix.\n",
2826 (LONG_PTR)test_proc, proc);
2827 ref = IDirectDraw4_Release(ddraw);
2828 ok(!ref, "Unexpected refcount %lu.\n", ref);
2829 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2830 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#Ix, got %#Ix.\n",
2831 (LONG_PTR)test_proc, proc);
2833 /* DDSCL_NORMAL doesn't. */
2834 ddraw = create_ddraw();
2835 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2836 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#Ix, got %#Ix.\n",
2837 (LONG_PTR)test_proc, proc);
2838 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL | DDSCL_FULLSCREEN);
2839 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#lx.\n", hr);
2840 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2841 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#Ix, got %#Ix.\n",
2842 (LONG_PTR)test_proc, proc);
2843 ref = IDirectDraw4_Release(ddraw);
2844 ok(!ref, "Unexpected refcount %lu.\n", ref);
2845 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2846 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#Ix, got %#Ix.\n",
2847 (LONG_PTR)test_proc, proc);
2849 /* The original window proc is only restored by ddraw if the current
2850 * window proc matches the one ddraw set. This also affects switching
2851 * from DDSCL_NORMAL to DDSCL_EXCLUSIVE. */
2852 ddraw = create_ddraw();
2853 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2854 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#Ix, got %#Ix.\n",
2855 (LONG_PTR)test_proc, proc);
2856 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2857 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#lx.\n", hr);
2858 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2859 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#Ix, got %#Ix.\n",
2860 (LONG_PTR)test_proc, proc);
2861 ddraw_proc = proc;
2862 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2863 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#lx.\n", hr);
2864 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2865 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#Ix, got %#Ix.\n",
2866 (LONG_PTR)test_proc, proc);
2867 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2868 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#lx.\n", hr);
2869 proc = SetWindowLongPtrA(window, GWLP_WNDPROC, (LONG_PTR)DefWindowProcA);
2870 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#Ix, got %#Ix.\n",
2871 (LONG_PTR)test_proc, proc);
2872 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2873 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#lx.\n", hr);
2874 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2875 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#Ix, got %#Ix.\n",
2876 (LONG_PTR)DefWindowProcA, proc);
2877 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2878 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#lx.\n", hr);
2879 proc = SetWindowLongPtrA(window, GWLP_WNDPROC, ddraw_proc);
2880 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#Ix, got %#Ix.\n",
2881 (LONG_PTR)DefWindowProcA, proc);
2882 ref = IDirectDraw4_Release(ddraw);
2883 ok(!ref, "Unexpected refcount %lu.\n", ref);
2884 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2885 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#Ix, got %#Ix.\n",
2886 (LONG_PTR)test_proc, proc);
2888 ddraw = create_ddraw();
2889 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2890 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#Ix, got %#Ix.\n",
2891 (LONG_PTR)test_proc, proc);
2892 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2893 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#lx.\n", hr);
2894 proc = SetWindowLongPtrA(window, GWLP_WNDPROC, (LONG_PTR)DefWindowProcA);
2895 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#Ix, got %#Ix.\n",
2896 (LONG_PTR)test_proc, proc);
2897 ref = IDirectDraw4_Release(ddraw);
2898 ok(!ref, "Unexpected refcount %lu.\n", ref);
2899 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2900 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#Ix, got %#Ix.\n",
2901 (LONG_PTR)DefWindowProcA, proc);
2903 fix_wndproc(window, (LONG_PTR)test_proc);
2904 expect_messages = NULL;
2905 DestroyWindow(window);
2906 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL));
2909 static void test_window_style(void)
2911 LONG style, exstyle, tmp, expected_style;
2912 RECT fullscreen_rect, r;
2913 HWND window, window2;
2914 IDirectDraw4 *ddraw;
2915 HRESULT hr;
2916 ULONG ref;
2917 BOOL ret;
2919 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
2920 0, 0, 100, 100, 0, 0, 0, 0);
2921 window2 = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
2922 0, 0, 50, 50, 0, 0, 0, 0);
2923 ddraw = create_ddraw();
2924 ok(!!ddraw, "Failed to create a ddraw object.\n");
2926 style = GetWindowLongA(window, GWL_STYLE);
2927 exstyle = GetWindowLongA(window, GWL_EXSTYLE);
2928 SetRect(&fullscreen_rect, 0, 0, registry_mode.dmPelsWidth, registry_mode.dmPelsHeight);
2930 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2931 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#lx.\n", hr);
2933 tmp = GetWindowLongA(window, GWL_STYLE);
2934 todo_wine ok(tmp == style, "Expected window style %#lx, got %#lx.\n", style, tmp);
2935 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2936 todo_wine ok(tmp == exstyle, "Expected window extended style %#lx, got %#lx.\n", exstyle, tmp);
2938 GetWindowRect(window, &r);
2939 ok(EqualRect(&r, &fullscreen_rect), "Expected %s, got %s.\n",
2940 wine_dbgstr_rect(&fullscreen_rect), wine_dbgstr_rect(&r));
2941 GetClientRect(window, &r);
2942 todo_wine ok(!EqualRect(&r, &fullscreen_rect), "Client rect and window rect are equal.\n");
2944 ret = SetForegroundWindow(GetDesktopWindow());
2945 ok(ret, "Failed to set foreground window.\n");
2947 tmp = GetWindowLongA(window, GWL_STYLE);
2948 todo_wine ok(tmp == style, "Expected window style %#lx, got %#lx.\n", style, tmp);
2949 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2950 todo_wine ok(tmp == exstyle, "Expected window extended style %#lx, got %#lx.\n", exstyle, tmp);
2952 ret = SetForegroundWindow(window);
2953 ok(ret, "Failed to set foreground window.\n");
2954 /* Windows 7 (but not Vista and XP) shows the window when it receives focus. Hide it again,
2955 * the next tests expect this. */
2956 ShowWindow(window, SW_HIDE);
2958 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2959 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#lx.\n", hr);
2961 tmp = GetWindowLongA(window, GWL_STYLE);
2962 ok(tmp == style, "Expected window style %#lx, got %#lx.\n", style, tmp);
2963 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2964 ok(tmp == exstyle, "Expected window extended style %#lx, got %#lx.\n", exstyle, tmp);
2966 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_NOWINDOWCHANGES);
2967 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#lx.\n", hr);
2969 tmp = GetWindowLongA(window, GWL_STYLE);
2970 todo_wine ok(tmp == style, "Expected window style %#lx, got %#lx.\n", style, tmp);
2971 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2972 todo_wine ok(tmp == exstyle, "Expected window extended style %#lx, got %#lx.\n", exstyle, tmp);
2974 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2975 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#lx.\n", hr);
2977 tmp = GetWindowLongA(window, GWL_STYLE);
2978 expected_style = style | WS_VISIBLE;
2979 todo_wine ok(tmp == expected_style, "Expected window style %#lx, got %#lx.\n", expected_style, tmp);
2980 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2981 expected_style = exstyle | WS_EX_TOPMOST;
2982 todo_wine ok(tmp == expected_style, "Expected window extended style %#lx, got %#lx.\n", expected_style, tmp);
2984 ShowWindow(window, SW_HIDE);
2985 tmp = GetWindowLongA(window, GWL_STYLE);
2986 todo_wine ok(tmp == style, "Expected window style %#lx, got %#lx.\n", style, tmp);
2987 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2988 expected_style = exstyle | WS_EX_TOPMOST;
2989 todo_wine ok(tmp == expected_style, "Expected window extended style %#lx, got %#lx.\n", expected_style, tmp);
2991 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL | DDSCL_NOWINDOWCHANGES);
2992 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#lx.\n", hr);
2994 tmp = GetWindowLongA(window, GWL_STYLE);
2995 ok(tmp == style, "Expected window style %#lx, got %#lx.\n", style, tmp);
2996 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2997 expected_style = exstyle | WS_EX_TOPMOST;
2998 ok(tmp == expected_style, "Expected window extended style %#lx, got %#lx.\n", expected_style, tmp);
3000 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
3001 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#lx.\n", hr);
3003 tmp = GetWindowLongA(window, GWL_STYLE);
3004 ok(tmp == style, "Expected window style %#lx, got %#lx.\n", style, tmp);
3005 tmp = GetWindowLongA(window, GWL_EXSTYLE);
3006 expected_style = exstyle | WS_EX_TOPMOST;
3007 ok(tmp == expected_style, "Expected window extended style %#lx, got %#lx.\n", expected_style, tmp);
3009 ret = SetForegroundWindow(window);
3010 ok(ret, "Failed to set foreground window.\n");
3012 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3013 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#lx.\n", hr);
3015 tmp = GetWindowLongA(window, GWL_STYLE);
3016 expected_style = style | WS_VISIBLE;
3017 todo_wine ok(tmp == expected_style, "Expected window style %#lx, got %#lx.\n", expected_style, tmp);
3018 tmp = GetWindowLongA(window, GWL_EXSTYLE);
3019 expected_style = exstyle | WS_EX_TOPMOST;
3020 todo_wine ok(tmp == expected_style, "Expected window extended style %#lx, got %#lx.\n", expected_style, tmp);
3022 ShowWindow(window, SW_HIDE);
3023 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
3024 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#lx.\n", hr);
3026 tmp = GetWindowLongA(window, GWL_STYLE);
3027 ok(tmp == style, "Expected window style %#lx, got %#lx.\n", style, tmp);
3028 tmp = GetWindowLongA(window, GWL_EXSTYLE);
3029 ok(tmp == exstyle, "Expected window extended style %#lx, got %#lx.\n", exstyle, tmp);
3031 ShowWindow(window, SW_SHOW);
3032 ret = SetForegroundWindow(GetDesktopWindow());
3033 ok(ret, "Failed to set foreground window.\n");
3034 SetActiveWindow(window);
3035 ok(GetActiveWindow() == window, "Unexpected active window.\n");
3036 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3037 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#lx.\n", hr);
3039 tmp = GetWindowLongA(window, GWL_STYLE);
3040 expected_style = style | WS_VISIBLE;
3041 todo_wine ok(tmp == expected_style, "Expected window style %#lx, got %#lx.\n", expected_style, tmp);
3042 tmp = GetWindowLongA(window, GWL_EXSTYLE);
3043 todo_wine ok(tmp == exstyle, "Expected window extended style %#lx, got %#lx.\n", exstyle, tmp);
3045 GetWindowRect(window, &r);
3046 ok(EqualRect(&r, &fullscreen_rect), "Expected %s, got %s.\n",
3047 wine_dbgstr_rect(&fullscreen_rect), wine_dbgstr_rect(&r));
3049 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
3050 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#lx.\n", hr);
3052 SetWindowPos(window, NULL, 0, 0, 100, 100, SWP_NOZORDER | SWP_NOACTIVATE);
3053 GetWindowRect(window, &r);
3054 ok(!EqualRect(&r, &fullscreen_rect), "Window resize failed? got %s.\n",
3055 wine_dbgstr_rect(&r));
3057 ret = SetForegroundWindow(window2);
3058 ok(ret, "Failed to set foreground window.\n");
3059 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3060 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#lx.\n", hr);
3062 tmp = GetWindowLongA(window, GWL_STYLE);
3063 expected_style = style | WS_VISIBLE;
3064 todo_wine ok(tmp == expected_style, "Expected window style %#lx, got %#lx.\n", expected_style, tmp);
3065 tmp = GetWindowLongA(window, GWL_EXSTYLE);
3066 todo_wine ok(tmp == exstyle, "Expected window extended style %#lx, got %#lx.\n", exstyle, tmp);
3068 GetWindowRect(window, &r);
3069 ok(EqualRect(&r, &fullscreen_rect), "Expected %s, got %s.\n",
3070 wine_dbgstr_rect(&fullscreen_rect), wine_dbgstr_rect(&r));
3072 ret = SetForegroundWindow(window);
3073 ok(ret, "Failed to set foreground window.\n");
3074 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3075 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#lx.\n", hr);
3077 tmp = GetWindowLongA(window, GWL_STYLE);
3078 expected_style = style | WS_VISIBLE;
3079 todo_wine ok(tmp == expected_style, "Expected window style %#lx, got %#lx.\n", expected_style, tmp);
3080 tmp = GetWindowLongA(window, GWL_EXSTYLE);
3081 expected_style = exstyle | WS_EX_TOPMOST;
3082 todo_wine ok(tmp == expected_style, "Expected window extended style %#lx, got %#lx.\n", expected_style, tmp);
3084 ShowWindow(window, SW_HIDE);
3085 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
3086 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#lx.\n", hr);
3088 tmp = GetWindowLongA(window, GWL_STYLE);
3089 ok(tmp == style, "Expected window style %#lx, got %#lx.\n", style, tmp);
3090 tmp = GetWindowLongA(window, GWL_EXSTYLE);
3091 ok(tmp == exstyle, "Expected window extended style %#lx, got %#lx.\n", exstyle, tmp);
3093 ShowWindow(window, SW_SHOW);
3094 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3095 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#lx.\n", hr);
3097 tmp = GetWindowLongA(window, GWL_STYLE);
3098 expected_style = style | WS_VISIBLE;
3099 todo_wine ok(tmp == expected_style, "Expected window style %#lx, got %#lx.\n", expected_style, tmp);
3100 tmp = GetWindowLongA(window, GWL_EXSTYLE);
3101 expected_style = exstyle | WS_EX_TOPMOST;
3102 todo_wine ok(tmp == expected_style, "Expected window extended style %#lx, got %#lx.\n", expected_style, tmp);
3104 ret = SetForegroundWindow(GetDesktopWindow());
3105 ok(ret, "Failed to set foreground window.\n");
3106 tmp = GetWindowLongA(window, GWL_STYLE);
3107 expected_style = style | WS_VISIBLE | WS_MINIMIZE;
3108 todo_wine ok(tmp == expected_style, "Expected window style %#lx, got %#lx.\n", expected_style, tmp);
3109 tmp = GetWindowLongA(window, GWL_EXSTYLE);
3110 expected_style = exstyle | WS_EX_TOPMOST;
3111 todo_wine ok(tmp == expected_style, "Expected window extended style %#lx, got %#lx.\n", expected_style, tmp);
3113 /* Test that there is a ~1.5s timer that checks and restores WS_EX_TOPMOST if it's missing */
3114 ret = ShowWindow(window, SW_RESTORE);
3115 ok(ret, "ShowWindow failed, error %#lx.\n", GetLastError());
3116 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3117 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#lx.\n", hr);
3118 flush_events();
3120 /* Remove WS_VISIBLE and WS_EX_TOPMOST */
3121 tmp = GetWindowLongA(window, GWL_STYLE);
3122 ok(tmp & WS_VISIBLE, "Expected WS_VISIBLE.\n");
3123 tmp = GetWindowLongA(window, GWL_EXSTYLE);
3124 ok(tmp & WS_EX_TOPMOST, "Expected WS_EX_TOPMOST.\n");
3125 ret = ShowWindow(window, SW_HIDE);
3126 ok(ret, "ShowWindow failed, error %#lx.\n", GetLastError());
3127 ret = SetWindowPos(window, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
3128 ok(ret, "SetWindowPos failed, error %#lx.\n", GetLastError());
3129 tmp = GetWindowLongA(window, GWL_STYLE);
3130 ok(!(tmp & WS_VISIBLE), "Got unexpected WS_VISIBLE.\n");
3131 tmp = GetWindowLongA(window, GWL_EXSTYLE);
3132 ok(!(tmp & WS_EX_TOPMOST), "Got unexpected WS_EX_TOPMOST.\n");
3134 Sleep(2000);
3135 flush_events();
3137 /* WS_VISIBLE is not restored but WS_EX_TOPMOST is */
3138 tmp = GetWindowLongA(window, GWL_STYLE);
3139 ok(!(tmp & WS_VISIBLE), "Got unexpected WS_VISIBLE.\n");
3140 tmp = GetWindowLongA(window, GWL_EXSTYLE);
3141 ok(tmp & WS_EX_TOPMOST, "Expected WS_EX_TOPMOST.\n");
3143 ref = IDirectDraw4_Release(ddraw);
3144 ok(!ref, "Unexpected refcount %lu.\n", ref);
3146 DestroyWindow(window2);
3147 DestroyWindow(window);
3150 static void test_redundant_mode_set(void)
3152 DDSURFACEDESC2 surface_desc = {0};
3153 IDirectDraw4 *ddraw;
3154 RECT q, r, s;
3155 HWND window;
3156 HRESULT hr;
3157 ULONG ref;
3159 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
3160 0, 0, 100, 100, 0, 0, 0, 0);
3161 ddraw = create_ddraw();
3162 ok(!!ddraw, "Failed to create a ddraw object.\n");
3164 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3165 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#lx.\n", hr);
3167 surface_desc.dwSize = sizeof(surface_desc);
3168 hr = IDirectDraw4_GetDisplayMode(ddraw, &surface_desc);
3169 ok(SUCCEEDED(hr), "GetDisplayMode failed, hr %#lx.\n", hr);
3171 hr = IDirectDraw4_SetDisplayMode(ddraw, surface_desc.dwWidth, surface_desc.dwHeight,
3172 surface_desc.ddpfPixelFormat.dwRGBBitCount, 0, 0);
3173 ok(SUCCEEDED(hr), "SetDisplayMode failed, hr %#lx.\n", hr);
3175 GetWindowRect(window, &q);
3176 r = q;
3177 r.right /= 2;
3178 r.bottom /= 2;
3179 SetWindowPos(window, HWND_TOP, r.left, r.top, r.right, r.bottom, 0);
3180 GetWindowRect(window, &s);
3181 ok(EqualRect(&r, &s), "Expected %s, got %s.\n", wine_dbgstr_rect(&r), wine_dbgstr_rect(&s));
3183 hr = IDirectDraw4_SetDisplayMode(ddraw, surface_desc.dwWidth, surface_desc.dwHeight,
3184 surface_desc.ddpfPixelFormat.dwRGBBitCount, 0, 0);
3185 ok(SUCCEEDED(hr), "SetDisplayMode failed, hr %#lx.\n", hr);
3187 GetWindowRect(window, &s);
3188 ok(EqualRect(&r, &s) || broken(EqualRect(&q, &s) /* Windows 10 */),
3189 "Expected %s, got %s.\n", wine_dbgstr_rect(&r), wine_dbgstr_rect(&s));
3191 ref = IDirectDraw4_Release(ddraw);
3192 ok(!ref, "Unexpected refcount %lu.\n", ref);
3194 DestroyWindow(window);
3197 static SIZE screen_size, screen_size2;
3199 static LRESULT CALLBACK mode_set_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
3201 if (message == WM_SIZE)
3203 screen_size.cx = GetSystemMetrics(SM_CXSCREEN);
3204 screen_size.cy = GetSystemMetrics(SM_CYSCREEN);
3207 return test_proc(hwnd, message, wparam, lparam);
3210 static LRESULT CALLBACK mode_set_proc2(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
3212 if (message == WM_SIZE)
3214 screen_size2.cx = GetSystemMetrics(SM_CXSCREEN);
3215 screen_size2.cy = GetSystemMetrics(SM_CYSCREEN);
3218 return test_proc(hwnd, message, wparam, lparam);
3221 struct test_coop_level_mode_set_enum_param
3223 DWORD ddraw_width, ddraw_height, user32_width, user32_height;
3226 static HRESULT CALLBACK test_coop_level_mode_set_enum_cb(DDSURFACEDESC2 *surface_desc, void *context)
3228 struct test_coop_level_mode_set_enum_param *param = context;
3230 if (surface_desc->ddpfPixelFormat.dwRGBBitCount != registry_mode.dmBitsPerPel)
3231 return DDENUMRET_OK;
3232 if (surface_desc->dwWidth == registry_mode.dmPelsWidth
3233 && surface_desc->dwHeight == registry_mode.dmPelsHeight)
3234 return DDENUMRET_OK;
3236 if (!param->ddraw_width)
3238 param->ddraw_width = surface_desc->dwWidth;
3239 param->ddraw_height = surface_desc->dwHeight;
3240 return DDENUMRET_OK;
3242 if (surface_desc->dwWidth == param->ddraw_width && surface_desc->dwHeight == param->ddraw_height)
3243 return DDENUMRET_OK;
3245 /* The docs say the DDENUMRET_CANCEL below cancels the enumeration, so the check should be
3246 * redundant. However, since Windows 10 this no longer works and the enumeration continues
3247 * until all supported modes are enumerated. Win8 and earlier do cancel.
3249 * Unrelatedly, some testbot machines report high res modes like 1920x1080, but suffer from
3250 * some problems when we actually try to set them (w10pro64 and its localization siblings).
3251 * Try to stay below the registry mode if possible. */
3252 if (!param->user32_width || (surface_desc->dwWidth < registry_mode.dmPelsWidth
3253 && surface_desc->dwHeight < registry_mode.dmPelsHeight))
3255 param->user32_width = surface_desc->dwWidth;
3256 param->user32_height = surface_desc->dwHeight;
3258 return DDENUMRET_CANCEL;
3261 static void test_coop_level_mode_set(void)
3263 DEVMODEW *original_modes = NULL, devmode, devmode2;
3264 unsigned int display_count = 0;
3265 IDirectDrawSurface4 *primary;
3266 RECT registry_rect, ddraw_rect, user32_rect, r;
3267 IDirectDraw4 *ddraw;
3268 DDSURFACEDESC2 ddsd;
3269 WNDCLASSA wc = {0};
3270 HWND window, window2;
3271 HRESULT hr;
3272 ULONG ref;
3273 MSG msg;
3274 struct test_coop_level_mode_set_enum_param param;
3275 BOOL ret;
3276 LONG change_ret;
3278 static const struct message exclusive_messages[] =
3280 {WM_WINDOWPOSCHANGING, FALSE, 0},
3281 {WM_WINDOWPOSCHANGED, FALSE, 0},
3282 {WM_SIZE, FALSE, 0},
3283 {WM_DISPLAYCHANGE, FALSE, 0},
3284 {0, FALSE, 0},
3286 static const struct message exclusive_focus_loss_messages[] =
3288 {WM_ACTIVATE, TRUE, WA_INACTIVE, DD_OK},
3289 {WM_WINDOWPOSCHANGING, FALSE, 0, DD_OK}, /* Window resize due to mode change. */
3290 {WM_WINDOWPOSCHANGED, FALSE, 0, DD_OK},
3291 {WM_SIZE, TRUE, SIZE_RESTORED, DD_OK}, /* Generated by DefWindowProc. */
3292 {WM_DISPLAYCHANGE, FALSE, 0, DD_OK},
3293 {WM_KILLFOCUS, FALSE, 0, DDERR_NOEXCLUSIVEMODE},
3294 {WM_WINDOWPOSCHANGING, FALSE, 0, DDERR_NOEXCLUSIVEMODE}, /* Window minimized. */
3295 /* Like d3d8 and d3d9 ddraw seems to use SW_SHOWMINIMIZED instead of
3296 * SW_MINIMIZED, causing a recursive window activation that does not
3297 * produce the same result in Wine yet. Ignore the difference for now.
3298 * {WM_ACTIVATE, TRUE, 0x200000 | WA_ACTIVE}, */
3299 {WM_WINDOWPOSCHANGED, FALSE, 0, DDERR_NOEXCLUSIVEMODE},
3300 {WM_MOVE, FALSE, 0, DDERR_NOEXCLUSIVEMODE},
3301 {WM_SIZE, TRUE, SIZE_MINIMIZED, DDERR_NOEXCLUSIVEMODE},
3302 {WM_ACTIVATEAPP, TRUE, FALSE, DDERR_NOEXCLUSIVEMODE},
3303 {0, FALSE, 0, 0},
3305 static const struct message exclusive_focus_restore_messages[] =
3307 {WM_WINDOWPOSCHANGING, FALSE, 0}, /* From the ShowWindow(SW_RESTORE). */
3308 {WM_WINDOWPOSCHANGING, FALSE, 0}, /* Generated by ddraw, matches d3d9 behavior. */
3309 {WM_WINDOWPOSCHANGED, FALSE, 0}, /* Matching previous message. */
3310 {WM_SIZE, FALSE, 0}, /* DefWindowProc. */
3311 {WM_DISPLAYCHANGE, FALSE, 0}, /* Ddraw restores mode. */
3312 /* Native redundantly sets the window size here. */
3313 {WM_ACTIVATEAPP, TRUE, TRUE}, /* End of ddraw's hooks. */
3314 {WM_WINDOWPOSCHANGED, FALSE, 0}, /* Matching the one from ShowWindow. */
3315 {WM_MOVE, FALSE, 0}, /* DefWindowProc. */
3316 {WM_SIZE, TRUE, SIZE_RESTORED}, /* DefWindowProc. */
3317 {0, FALSE, 0},
3319 static const struct message sc_restore_messages[] =
3321 {WM_SYSCOMMAND, TRUE, SC_RESTORE},
3322 {WM_WINDOWPOSCHANGING, FALSE, 0},
3323 {WM_WINDOWPOSCHANGED, FALSE, 0},
3324 {WM_SIZE, TRUE, SIZE_RESTORED},
3325 {0, FALSE, 0},
3327 static const struct message sc_minimize_messages[] =
3329 {WM_SYSCOMMAND, TRUE, SC_MINIMIZE},
3330 {WM_WINDOWPOSCHANGING, FALSE, 0},
3331 {WM_WINDOWPOSCHANGED, FALSE, 0},
3332 {WM_SIZE, TRUE, SIZE_MINIMIZED},
3333 {0, FALSE, 0},
3335 static const struct message sc_maximize_messages[] =
3337 {WM_SYSCOMMAND, TRUE, SC_MAXIMIZE},
3338 {WM_WINDOWPOSCHANGING, FALSE, 0},
3339 {WM_WINDOWPOSCHANGED, FALSE, 0},
3340 {WM_SIZE, TRUE, SIZE_MAXIMIZED},
3341 {0, FALSE, 0},
3344 static const struct message normal_messages[] =
3346 {WM_DISPLAYCHANGE, FALSE, 0},
3347 {0, FALSE, 0},
3350 memset(&devmode, 0, sizeof(devmode));
3351 devmode.dmSize = sizeof(devmode);
3352 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
3353 ok(ret, "EnumDisplaySettingsW failed, error %lu.\n", GetLastError());
3354 ok(compare_mode_rect(&devmode, &registry_mode), "Got a different mode.\n");
3355 ret = EnumDisplaySettingsW(NULL, ENUM_REGISTRY_SETTINGS, &devmode);
3356 ok(ret, "EnumDisplaySettingsW failed, error %lu.\n", GetLastError());
3357 ok(compare_mode_rect(&devmode, &registry_mode), "Got a different mode.\n");
3359 ret = save_display_modes(&original_modes, &display_count);
3360 ok(ret, "Failed to save original display modes.\n");
3362 ddraw = create_ddraw();
3363 ok(!!ddraw, "Failed to create a ddraw object.\n");
3365 memset(&param, 0, sizeof(param));
3366 hr = IDirectDraw4_EnumDisplayModes(ddraw, 0, NULL, &param, test_coop_level_mode_set_enum_cb);
3367 ok(SUCCEEDED(hr), "Failed to enumerate display mode, hr %#lx.\n", hr);
3368 ref = IDirectDraw4_Release(ddraw);
3369 ok(!ref, "Unexpected refcount %lu.\n", ref);
3371 if (!param.user32_height)
3373 skip("Fewer than 3 different modes supported, skipping mode restore test.\n");
3374 free(original_modes);
3375 return;
3378 SetRect(&registry_rect, 0, 0, registry_mode.dmPelsWidth, registry_mode.dmPelsHeight);
3379 SetRect(&ddraw_rect, 0, 0, param.ddraw_width, param.ddraw_height);
3380 SetRect(&user32_rect, 0, 0, param.user32_width, param.user32_height);
3382 memset(&devmode, 0, sizeof(devmode));
3383 devmode.dmSize = sizeof(devmode);
3384 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
3385 devmode.dmPelsWidth = param.user32_width;
3386 devmode.dmPelsHeight = param.user32_height;
3387 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
3388 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#lx.\n", change_ret);
3390 ddraw = create_ddraw();
3391 ok(!!ddraw, "Failed to create a ddraw object.\n");
3393 wc.lpfnWndProc = mode_set_proc;
3394 wc.lpszClassName = "ddraw_test_wndproc_wc";
3395 ok(RegisterClassA(&wc), "Failed to register window class.\n");
3396 wc.lpfnWndProc = mode_set_proc2;
3397 wc.lpszClassName = "ddraw_test_wndproc_wc2";
3398 ok(RegisterClassA(&wc), "Failed to register window class.\n");
3400 window = CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test", WS_OVERLAPPEDWINDOW,
3401 0, 0, 100, 100, 0, 0, 0, 0);
3402 window2 = CreateWindowA("ddraw_test_wndproc_wc2", "ddraw_test", WS_OVERLAPPEDWINDOW,
3403 0, 0, 100, 100, 0, 0, 0, 0);
3405 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3406 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#lx.\n", hr);
3408 GetWindowRect(window, &r);
3409 ok(EqualRect(&r, &user32_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&user32_rect),
3410 wine_dbgstr_rect(&r));
3412 memset(&ddsd, 0, sizeof(ddsd));
3413 ddsd.dwSize = sizeof(ddsd);
3414 ddsd.dwFlags = DDSD_CAPS;
3415 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3417 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
3418 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n",hr);
3419 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
3420 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#lx.\n", hr);
3421 ok(ddsd.dwWidth == param.user32_width, "Expected surface width %lu, got %lu.\n",
3422 param.user32_width, ddsd.dwWidth);
3423 ok(ddsd.dwHeight == param.user32_height, "Expected surface height %lu, got %lu.\n",
3424 param.user32_height, ddsd.dwHeight);
3426 GetWindowRect(window, &r);
3427 ok(EqualRect(&r, &user32_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&user32_rect),
3428 wine_dbgstr_rect(&r));
3430 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
3431 expect_messages = exclusive_messages;
3432 screen_size.cx = 0;
3433 screen_size.cy = 0;
3435 hr = IDirectDrawSurface4_IsLost(primary);
3436 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
3437 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
3438 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#lx.\n", hr);
3439 hr = IDirectDrawSurface4_IsLost(primary);
3440 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#lx.\n", hr);
3442 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
3443 expect_messages = NULL;
3444 ok(screen_size.cx == param.ddraw_width && screen_size.cy == param.ddraw_height,
3445 "Expected screen size %lux%lu, got %lux%lu.\n",
3446 param.ddraw_width, param.ddraw_height, screen_size.cx, screen_size.cy);
3448 GetWindowRect(window, &r);
3449 ok(EqualRect(&r, &ddraw_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect),
3450 wine_dbgstr_rect(&r));
3452 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
3453 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#lx.\n", hr);
3454 ok(ddsd.dwWidth == param.user32_width, "Expected surface width %lu, got %lu.\n",
3455 param.user32_width, ddsd.dwWidth);
3456 ok(ddsd.dwHeight == param.user32_height, "Expected surface height %lu, got %lu.\n",
3457 param.user32_height, ddsd.dwHeight);
3458 IDirectDrawSurface4_Release(primary);
3460 memset(&ddsd, 0, sizeof(ddsd));
3461 ddsd.dwSize = sizeof(ddsd);
3462 ddsd.dwFlags = DDSD_CAPS;
3463 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3465 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
3466 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n",hr);
3467 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
3468 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#lx.\n", hr);
3469 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %lu, got %lu.\n",
3470 param.ddraw_width, ddsd.dwWidth);
3471 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %lu, got %lu.\n",
3472 param.ddraw_height, ddsd.dwHeight);
3474 GetWindowRect(window, &r);
3475 ok(EqualRect(&r, &ddraw_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect),
3476 wine_dbgstr_rect(&r));
3478 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
3479 expect_messages = exclusive_messages;
3480 screen_size.cx = 0;
3481 screen_size.cy = 0;
3483 hr = IDirectDrawSurface4_IsLost(primary);
3484 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
3485 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
3486 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#lx.\n", change_ret);
3487 hr = IDirectDrawSurface4_IsLost(primary);
3488 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#lx.\n", hr);
3490 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
3491 expect_messages = NULL;
3492 ok(screen_size.cx == param.user32_width && screen_size.cy == param.user32_height,
3493 "Expected screen size %lux%lu, got %lux%lu.\n",
3494 param.user32_width, param.user32_height, screen_size.cx, screen_size.cy);
3496 GetWindowRect(window, &r);
3497 ok(EqualRect(&r, &user32_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&user32_rect),
3498 wine_dbgstr_rect(&r));
3500 expect_messages = exclusive_focus_loss_messages;
3501 focus_test_ddraw = ddraw;
3502 ret = SetForegroundWindow(GetDesktopWindow());
3503 ok(ret, "Failed to set foreground window.\n");
3504 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
3505 focus_test_ddraw = NULL;
3507 memset(&devmode, 0, sizeof(devmode));
3508 devmode.dmSize = sizeof(devmode);
3509 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
3510 ok(ret, "Failed to get display mode.\n");
3511 ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth
3512 && devmode.dmPelsHeight == registry_mode.dmPelsHeight, "Got unexpected screen size %lux%lu.\n",
3513 devmode.dmPelsWidth, devmode.dmPelsHeight);
3515 expect_messages = exclusive_focus_restore_messages;
3516 ShowWindow(window, SW_RESTORE);
3517 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
3519 GetWindowRect(window, &r);
3520 ok(EqualRect(&r, &ddraw_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect),
3521 wine_dbgstr_rect(&r));
3522 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
3523 ok(ret, "Failed to get display mode.\n");
3524 ok(devmode.dmPelsWidth == param.ddraw_width
3525 && devmode.dmPelsHeight == param.ddraw_height, "Got unexpected screen size %lux%lu.\n",
3526 devmode.dmPelsWidth, devmode.dmPelsHeight);
3528 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3529 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#lx.\n", hr);
3530 /* Normally the primary should be restored here. Unfortunately this causes the
3531 * GetSurfaceDesc call after the next display mode change to crash on the Windows 8
3532 * testbot. Another Restore call would presumably avoid the crash, but it also moots
3533 * the point of the GetSurfaceDesc call. */
3535 expect_messages = sc_minimize_messages;
3536 SendMessageA(window, WM_SYSCOMMAND, SC_MINIMIZE, 0);
3537 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
3538 expect_messages = NULL;
3540 expect_messages = sc_restore_messages;
3541 SendMessageA(window, WM_SYSCOMMAND, SC_RESTORE, 0);
3542 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
3543 expect_messages = NULL;
3545 expect_messages = sc_maximize_messages;
3546 SendMessageA(window, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
3547 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
3548 expect_messages = NULL;
3550 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3551 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#lx.\n", hr);
3553 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
3554 expect_messages = exclusive_messages;
3555 screen_size.cx = 0;
3556 screen_size.cy = 0;
3558 hr = IDirectDrawSurface4_IsLost(primary);
3559 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#lx.\n", hr);
3560 hr = IDirectDraw4_RestoreDisplayMode(ddraw);
3561 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#lx.\n", hr);
3562 hr = IDirectDrawSurface4_IsLost(primary);
3563 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#lx.\n", hr);
3565 flaky /* win8 */
3566 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
3567 expect_messages = NULL;
3568 flaky /* win8 */
3569 ok(screen_size.cx == registry_mode.dmPelsWidth
3570 && screen_size.cy == registry_mode.dmPelsHeight,
3571 "Expected screen size %lux%lu, got %lux%lu.\n",
3572 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight, screen_size.cx, screen_size.cy);
3574 GetWindowRect(window, &r);
3575 flaky /* win8 */
3576 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
3577 wine_dbgstr_rect(&r));
3579 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
3580 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#lx.\n", hr);
3581 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %lu, got %lu.\n",
3582 param.ddraw_width, ddsd.dwWidth);
3583 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %lu, got %lu.\n",
3584 param.ddraw_height, ddsd.dwHeight);
3585 IDirectDrawSurface4_Release(primary);
3587 /* For Wine. */
3588 change_ret = ChangeDisplaySettingsW(NULL, CDS_FULLSCREEN);
3589 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#lx.\n", change_ret);
3591 memset(&ddsd, 0, sizeof(ddsd));
3592 ddsd.dwSize = sizeof(ddsd);
3593 ddsd.dwFlags = DDSD_CAPS;
3594 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3596 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
3597 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n",hr);
3598 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
3599 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#lx.\n", hr);
3600 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %lu, got %lu.\n",
3601 registry_mode.dmPelsWidth, ddsd.dwWidth);
3602 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %lu, got %lu.\n",
3603 registry_mode.dmPelsHeight, ddsd.dwHeight);
3605 GetWindowRect(window, &r);
3606 flaky /* win8 */
3607 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
3608 wine_dbgstr_rect(&r));
3610 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
3611 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#lx.\n", hr);
3613 GetWindowRect(window, &r);
3614 flaky /* win8 */
3615 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
3616 wine_dbgstr_rect(&r));
3618 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
3619 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#lx.\n", hr);
3620 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %lu, got %lu.\n",
3621 registry_mode.dmPelsWidth, ddsd.dwWidth);
3622 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %lu, got %lu.\n",
3623 registry_mode.dmPelsHeight, ddsd.dwHeight);
3624 IDirectDrawSurface4_Release(primary);
3626 memset(&ddsd, 0, sizeof(ddsd));
3627 ddsd.dwSize = sizeof(ddsd);
3628 ddsd.dwFlags = DDSD_CAPS;
3629 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3631 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
3632 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n",hr);
3633 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
3634 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#lx.\n", hr);
3635 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %lu, got %lu.\n",
3636 registry_mode.dmPelsWidth, ddsd.dwWidth);
3637 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %lu, got %lu.\n",
3638 registry_mode.dmPelsHeight, ddsd.dwHeight);
3640 GetWindowRect(window, &r);
3641 flaky /* win8 */
3642 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
3643 wine_dbgstr_rect(&r));
3645 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
3646 expect_messages = normal_messages;
3647 screen_size.cx = 0;
3648 screen_size.cy = 0;
3650 hr = IDirectDrawSurface4_IsLost(primary);
3651 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
3652 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
3653 devmode.dmPelsWidth = param.user32_width;
3654 devmode.dmPelsHeight = param.user32_height;
3655 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
3656 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#lx.\n", change_ret);
3657 hr = IDirectDrawSurface4_IsLost(primary);
3658 todo_wine ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#lx.\n", hr);
3660 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
3661 expect_messages = NULL;
3662 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %lux%lu.\n", screen_size.cx, screen_size.cy);
3664 GetWindowRect(window, &r);
3665 flaky /* win8 */
3666 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
3667 wine_dbgstr_rect(&r));
3669 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
3670 expect_messages = normal_messages;
3671 screen_size.cx = 0;
3672 screen_size.cy = 0;
3674 hr = IDirectDrawSurface4_Restore(primary);
3675 ok(hr == DDERR_WRONGMODE, "Got unexpected hr %#lx.\n", hr);
3676 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
3677 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#lx.\n", hr);
3678 hr = IDirectDrawSurface4_Restore(primary);
3679 ok(hr == DDERR_WRONGMODE, "Got unexpected hr %#lx.\n", hr);
3680 hr = IDirectDrawSurface4_IsLost(primary);
3681 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#lx.\n", hr);
3683 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
3684 expect_messages = NULL;
3685 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %lux%lu.\n", screen_size.cx, screen_size.cy);
3687 GetWindowRect(window, &r);
3688 flaky /* win8 */
3689 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
3690 wine_dbgstr_rect(&r));
3692 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
3693 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#lx.\n", hr);
3694 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %lu, got %lu.\n",
3695 registry_mode.dmPelsWidth, ddsd.dwWidth);
3696 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %lu, got %lu.\n",
3697 registry_mode.dmPelsHeight, ddsd.dwHeight);
3698 IDirectDrawSurface4_Release(primary);
3700 memset(&ddsd, 0, sizeof(ddsd));
3701 ddsd.dwSize = sizeof(ddsd);
3702 ddsd.dwFlags = DDSD_CAPS;
3703 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3705 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
3706 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n",hr);
3707 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
3708 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#lx.\n", hr);
3709 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %lu, got %lu.\n",
3710 param.ddraw_width, ddsd.dwWidth);
3711 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %lu, got %lu.\n",
3712 param.ddraw_height, ddsd.dwHeight);
3714 GetWindowRect(window, &r);
3715 flaky /* win8 */
3716 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
3717 wine_dbgstr_rect(&r));
3719 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
3720 expect_messages = normal_messages;
3721 screen_size.cx = 0;
3722 screen_size.cy = 0;
3724 hr = IDirectDrawSurface4_IsLost(primary);
3725 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
3726 hr = IDirectDraw4_RestoreDisplayMode(ddraw);
3727 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#lx.\n", hr);
3728 hr = IDirectDrawSurface4_IsLost(primary);
3729 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#lx.\n", hr);
3731 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
3732 expect_messages = NULL;
3733 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %lux%lu.\n", screen_size.cx, screen_size.cy);
3735 GetWindowRect(window, &r);
3736 flaky /* win8 */
3737 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
3738 wine_dbgstr_rect(&r));
3740 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
3741 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#lx.\n", hr);
3742 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %lu, got %lu.\n",
3743 param.ddraw_width, ddsd.dwWidth);
3744 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %lu, got %lu.\n",
3745 param.ddraw_height, ddsd.dwHeight);
3746 IDirectDrawSurface4_Release(primary);
3748 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
3749 ok(ret, "Failed to get display mode.\n");
3750 ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth
3751 && devmode.dmPelsHeight == registry_mode.dmPelsHeight,
3752 "Expected resolution %lux%lu, got %lux%lu.\n",
3753 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight,
3754 devmode.dmPelsWidth, devmode.dmPelsHeight);
3755 change_ret = ChangeDisplaySettingsW(NULL, CDS_FULLSCREEN);
3756 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#lx.\n", change_ret);
3758 memset(&ddsd, 0, sizeof(ddsd));
3759 ddsd.dwSize = sizeof(ddsd);
3760 ddsd.dwFlags = DDSD_CAPS;
3761 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3763 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
3764 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n",hr);
3765 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
3766 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#lx.\n", hr);
3767 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %lu, got %lu.\n",
3768 registry_mode.dmPelsWidth, ddsd.dwWidth);
3769 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %lu, got %lu.\n",
3770 registry_mode.dmPelsHeight, ddsd.dwHeight);
3772 GetWindowRect(window, &r);
3773 flaky /* win8 */
3774 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
3775 wine_dbgstr_rect(&r));
3777 /* DDSCL_NORMAL | DDSCL_FULLSCREEN behaves the same as just DDSCL_NORMAL.
3778 * Resizing the window on mode changes is a property of DDSCL_EXCLUSIVE,
3779 * not DDSCL_FULLSCREEN. */
3780 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL | DDSCL_FULLSCREEN);
3781 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#lx.\n", hr);
3783 GetWindowRect(window, &r);
3784 flaky /* win8 */
3785 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
3786 wine_dbgstr_rect(&r));
3788 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
3789 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#lx.\n", hr);
3790 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %lu, got %lu.\n",
3791 registry_mode.dmPelsWidth, ddsd.dwWidth);
3792 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %lu, got %lu.\n",
3793 registry_mode.dmPelsHeight, ddsd.dwHeight);
3794 IDirectDrawSurface4_Release(primary);
3796 memset(&ddsd, 0, sizeof(ddsd));
3797 ddsd.dwSize = sizeof(ddsd);
3798 ddsd.dwFlags = DDSD_CAPS;
3799 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3801 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
3802 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n",hr);
3803 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
3804 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#lx.\n", hr);
3805 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %lu, got %lu.\n",
3806 registry_mode.dmPelsWidth, ddsd.dwWidth);
3807 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %lu, got %lu.\n",
3808 registry_mode.dmPelsHeight, ddsd.dwHeight);
3810 GetWindowRect(window, &r);
3811 flaky /* win8 */
3812 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
3813 wine_dbgstr_rect(&r));
3815 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
3816 expect_messages = normal_messages;
3817 screen_size.cx = 0;
3818 screen_size.cy = 0;
3820 hr = IDirectDrawSurface4_IsLost(primary);
3821 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
3822 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
3823 devmode.dmPelsWidth = param.user32_width;
3824 devmode.dmPelsHeight = param.user32_height;
3825 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
3826 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#lx.\n", change_ret);
3827 hr = IDirectDrawSurface4_IsLost(primary);
3828 todo_wine ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#lx.\n", hr);
3830 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
3831 expect_messages = NULL;
3832 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %lux%lu.\n", screen_size.cx, screen_size.cy);
3834 GetWindowRect(window, &r);
3835 flaky /* win8 */
3836 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
3837 wine_dbgstr_rect(&r));
3839 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
3840 expect_messages = normal_messages;
3841 screen_size.cx = 0;
3842 screen_size.cy = 0;
3844 hr = IDirectDrawSurface4_Restore(primary);
3845 ok(hr == DDERR_WRONGMODE, "Got unexpected hr %#lx.\n", hr);
3846 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
3847 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#lx.\n", hr);
3848 hr = IDirectDrawSurface4_Restore(primary);
3849 ok(hr == DDERR_WRONGMODE, "Got unexpected hr %#lx.\n", hr);
3850 hr = IDirectDrawSurface4_IsLost(primary);
3851 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#lx.\n", hr);
3853 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
3854 expect_messages = NULL;
3855 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %lux%lu.\n", screen_size.cx, screen_size.cy);
3857 GetWindowRect(window, &r);
3858 flaky /* win8 */
3859 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
3860 wine_dbgstr_rect(&r));
3862 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
3863 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#lx.\n", hr);
3864 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %lu, got %lu.\n",
3865 registry_mode.dmPelsWidth, ddsd.dwWidth);
3866 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %lu, got %lu.\n",
3867 registry_mode.dmPelsHeight, ddsd.dwHeight);
3868 IDirectDrawSurface4_Release(primary);
3870 memset(&ddsd, 0, sizeof(ddsd));
3871 ddsd.dwSize = sizeof(ddsd);
3872 ddsd.dwFlags = DDSD_CAPS;
3873 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3875 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
3876 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n",hr);
3877 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
3878 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#lx.\n", hr);
3879 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %lu, got %lu.\n",
3880 param.ddraw_width, ddsd.dwWidth);
3881 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %lu, got %lu.\n",
3882 param.ddraw_height, ddsd.dwHeight);
3884 GetWindowRect(window, &r);
3885 flaky /* win8 */
3886 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
3887 wine_dbgstr_rect(&r));
3889 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
3890 expect_messages = normal_messages;
3891 screen_size.cx = 0;
3892 screen_size.cy = 0;
3894 hr = IDirectDrawSurface4_IsLost(primary);
3895 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
3896 hr = IDirectDraw4_RestoreDisplayMode(ddraw);
3897 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#lx.\n", hr);
3898 hr = IDirectDrawSurface4_IsLost(primary);
3899 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#lx.\n", hr);
3901 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
3902 expect_messages = NULL;
3903 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %lux%lu.\n", screen_size.cx, screen_size.cy);
3905 GetWindowRect(window, &r);
3906 flaky /* win8 */
3907 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
3908 wine_dbgstr_rect(&r));
3910 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
3911 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#lx.\n", hr);
3912 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %lu, got %lu.\n",
3913 param.ddraw_width, ddsd.dwWidth);
3914 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %lu, got %lu.\n",
3915 param.ddraw_height, ddsd.dwHeight);
3916 IDirectDrawSurface4_Release(primary);
3918 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
3919 ok(ret, "Failed to get display mode.\n");
3920 ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth
3921 && devmode.dmPelsHeight == registry_mode.dmPelsHeight,
3922 "Expected resolution %lux%lu, got %lux%lu.\n",
3923 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight,
3924 devmode.dmPelsWidth, devmode.dmPelsHeight);
3925 change_ret = ChangeDisplaySettingsW(NULL, CDS_FULLSCREEN);
3926 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#lx.\n", change_ret);
3928 memset(&ddsd, 0, sizeof(ddsd));
3929 ddsd.dwSize = sizeof(ddsd);
3930 ddsd.dwFlags = DDSD_CAPS;
3931 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3933 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
3934 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n",hr);
3935 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
3936 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#lx.\n", hr);
3937 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %lu, got %lu.\n",
3938 registry_mode.dmPelsWidth, ddsd.dwWidth);
3939 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %lu, got %lu.\n",
3940 registry_mode.dmPelsHeight, ddsd.dwHeight);
3941 IDirectDrawSurface4_Release(primary);
3943 GetWindowRect(window, &r);
3944 flaky /* win8 */
3945 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
3946 wine_dbgstr_rect(&r));
3948 /* Changing the coop level from EXCLUSIVE to NORMAL restores the screen resolution */
3949 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3950 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#lx.\n", hr);
3951 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
3952 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#lx.\n", hr);
3954 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
3955 expect_messages = exclusive_messages;
3956 screen_size.cx = 0;
3957 screen_size.cy = 0;
3959 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
3960 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#lx.\n", hr);
3962 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
3963 expect_messages = NULL;
3964 ok(screen_size.cx == registry_mode.dmPelsWidth
3965 && screen_size.cy == registry_mode.dmPelsHeight,
3966 "Expected screen size %lux%lu, got %lux%lu.\n",
3967 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight,
3968 screen_size.cx, screen_size.cy);
3970 GetWindowRect(window, &r);
3971 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
3972 wine_dbgstr_rect(&r));
3974 memset(&ddsd, 0, sizeof(ddsd));
3975 ddsd.dwSize = sizeof(ddsd);
3976 ddsd.dwFlags = DDSD_CAPS;
3977 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3979 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
3980 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n",hr);
3981 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
3982 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#lx.\n", hr);
3983 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %lu, got %lu.\n",
3984 registry_mode.dmPelsWidth, ddsd.dwWidth);
3985 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %lu, got %lu.\n",
3986 registry_mode.dmPelsHeight, ddsd.dwHeight);
3987 IDirectDrawSurface4_Release(primary);
3989 /* The screen restore is a property of DDSCL_EXCLUSIVE */
3990 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL | DDSCL_FULLSCREEN);
3991 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#lx.\n", hr);
3992 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
3993 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#lx.\n", hr);
3995 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
3996 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#lx.\n", hr);
3998 memset(&ddsd, 0, sizeof(ddsd));
3999 ddsd.dwSize = sizeof(ddsd);
4000 ddsd.dwFlags = DDSD_CAPS;
4001 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
4003 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
4004 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n",hr);
4005 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
4006 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#lx.\n", hr);
4007 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %lu, got %lu.\n",
4008 param.ddraw_width, ddsd.dwWidth);
4009 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %lu, got %lu.\n",
4010 param.ddraw_height, ddsd.dwHeight);
4011 IDirectDrawSurface4_Release(primary);
4013 hr = IDirectDraw4_RestoreDisplayMode(ddraw);
4014 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#lx.\n", hr);
4016 /* If the window is changed at the same time, messages are sent to the new window. */
4017 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
4018 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#lx.\n", hr);
4019 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
4020 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#lx.\n", hr);
4022 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
4023 expect_messages = exclusive_messages;
4024 screen_size.cx = 0;
4025 screen_size.cy = 0;
4026 screen_size2.cx = 0;
4027 screen_size2.cy = 0;
4029 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window2, DDSCL_NORMAL);
4030 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#lx.\n", hr);
4032 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
4033 expect_messages = NULL;
4034 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %lux%lu.\n",
4035 screen_size.cx, screen_size.cy);
4036 ok(screen_size2.cx == registry_mode.dmPelsWidth && screen_size2.cy == registry_mode.dmPelsHeight,
4037 "Expected screen size 2 %lux%lu, got %lux%lu.\n",
4038 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight, screen_size2.cx, screen_size2.cy);
4040 GetWindowRect(window, &r);
4041 ok(EqualRect(&r, &ddraw_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect),
4042 wine_dbgstr_rect(&r));
4043 GetWindowRect(window2, &r);
4044 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
4045 wine_dbgstr_rect(&r));
4047 memset(&ddsd, 0, sizeof(ddsd));
4048 ddsd.dwSize = sizeof(ddsd);
4049 ddsd.dwFlags = DDSD_CAPS;
4050 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
4052 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
4053 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n",hr);
4054 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
4055 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#lx.\n", hr);
4056 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %lu, got %lu.\n",
4057 registry_mode.dmPelsWidth, ddsd.dwWidth);
4058 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %lu, got %lu.\n",
4059 registry_mode.dmPelsHeight, ddsd.dwHeight);
4060 IDirectDrawSurface4_Release(primary);
4062 ref = IDirectDraw4_Release(ddraw);
4063 ok(!ref, "Unexpected refcount %lu.\n", ref);
4065 GetWindowRect(window, &r);
4066 ok(EqualRect(&r, &ddraw_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect),
4067 wine_dbgstr_rect(&r));
4069 ret = restore_display_modes(original_modes, display_count);
4070 ok(ret, "Failed to restore display modes.\n");
4072 /* Test that no mode restorations if no mode changes happened */
4073 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
4074 devmode.dmPelsWidth = param.user32_width;
4075 devmode.dmPelsHeight = param.user32_height;
4076 change_ret = ChangeDisplaySettingsW(&devmode, CDS_UPDATEREGISTRY | CDS_NORESET);
4077 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "ChangeDisplaySettingsW failed with %ld.\n", change_ret);
4079 ddraw = create_ddraw();
4080 ok(!!ddraw, "Failed to create a ddraw object.\n");
4081 ref = IDirectDraw4_Release(ddraw);
4082 ok(!ref, "Unexpected refcount %lu.\n", ref);
4084 memset(&devmode2, 0, sizeof(devmode2));
4085 devmode2.dmSize = sizeof(devmode2);
4086 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode2);
4087 ok(ret, "EnumDisplaySettingsW failed, error %lu.\n", GetLastError());
4088 ok(compare_mode_rect(&devmode2, &registry_mode), "Got a different mode.\n");
4089 ret = restore_display_modes(original_modes, display_count);
4090 ok(ret, "Failed to restore display modes.\n");
4092 /* Test that no mode restorations if no mode changes happened with fullscreen ddraw objects */
4093 change_ret = ChangeDisplaySettingsW(&devmode, CDS_UPDATEREGISTRY | CDS_NORESET);
4094 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "ChangeDisplaySettingsW failed with %ld.\n", change_ret);
4096 ddraw = create_ddraw();
4097 ok(!!ddraw, "Failed to create a ddraw object.\n");
4098 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
4099 ok(hr == DD_OK, "SetCooperativeLevel failed, hr %#lx.\n", hr);
4100 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
4101 ok(hr == DD_OK, "SetCooperativeLevel failed, hr %#lx.\n", hr);
4102 ref = IDirectDraw4_Release(ddraw);
4103 ok(!ref, "Unexpected refcount %lu.\n", ref);
4105 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode2);
4106 ok(ret, "EnumDisplaySettingsW failed, error %lu.\n", GetLastError());
4107 ok(compare_mode_rect(&devmode2, &registry_mode), "Got a different mode.\n");
4108 ret = restore_display_modes(original_modes, display_count);
4109 ok(ret, "Failed to restore display modes.\n");
4111 /* Test that mode restorations use display settings in the registry after ddraw object releases
4112 * if SetDisplayMode() was called */
4113 ddraw = create_ddraw();
4114 ok(!!ddraw, "Failed to create a ddraw object.\n");
4115 hr = set_display_mode(ddraw, registry_mode.dmPelsWidth, registry_mode.dmPelsHeight);
4116 ok(hr == DD_OK, "Failed to set display mode, hr %#lx.\n", hr);
4118 change_ret = ChangeDisplaySettingsW(&devmode, CDS_UPDATEREGISTRY | CDS_NORESET);
4119 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "ChangeDisplaySettingsW failed with %ld.\n", change_ret);
4121 ref = IDirectDraw4_Release(ddraw);
4122 ok(!ref, "Unexpected refcount %lu.\n", ref);
4124 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode2);
4125 ok(ret, "EnumDisplaySettingsW failed, error %lu.\n", GetLastError());
4126 ok(compare_mode_rect(&devmode2, &devmode), "Got a different mode.\n");
4127 ret = EnumDisplaySettingsW(NULL, ENUM_REGISTRY_SETTINGS, &devmode2);
4128 ok(ret, "EnumDisplaySettingsW failed, error %lu.\n", GetLastError());
4129 ok(compare_mode_rect(&devmode2, &devmode), "Got a different mode.\n");
4130 ret = restore_display_modes(original_modes, display_count);
4131 ok(ret, "Failed to restore display modes.\n");
4133 /* Test that mode restorations use display settings in the registry after RestoreDisplayMode() */
4134 ddraw = create_ddraw();
4135 ok(!!ddraw, "Failed to create a ddraw object.\n");
4136 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
4137 ok(hr == DD_OK, "Failed to set display mode, hr %#lx.\n", hr);
4139 change_ret = ChangeDisplaySettingsW(&devmode, CDS_UPDATEREGISTRY | CDS_NORESET);
4140 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "ChangeDisplaySettingsW failed with %ld.\n", change_ret);
4142 hr = IDirectDraw4_RestoreDisplayMode(ddraw);
4143 ok(hr == DD_OK, "RestoreDisplayMode failed, hr %#lx.\n", hr);
4145 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode2);
4146 ok(ret, "EnumDisplaySettingsW failed, error %lu.\n", GetLastError());
4147 ok(compare_mode_rect(&devmode2, &devmode), "Got a different mode.\n");
4148 ret = EnumDisplaySettingsW(NULL, ENUM_REGISTRY_SETTINGS, &devmode2);
4149 ok(ret, "EnumDisplaySettingsW failed, error %lu.\n", GetLastError());
4150 ok(compare_mode_rect(&devmode2, &devmode), "Got a different mode.\n");
4152 ref = IDirectDraw4_Release(ddraw);
4153 ok(!ref, "Unexpected refcount %lu.\n", ref);
4155 expect_messages = NULL;
4156 DestroyWindow(window);
4157 DestroyWindow(window2);
4158 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL));
4159 UnregisterClassA("ddraw_test_wndproc_wc2", GetModuleHandleA(NULL));
4160 ret = restore_display_modes(original_modes, display_count);
4161 ok(ret, "Failed to restore display modes.\n");
4162 free(original_modes);
4165 static void test_coop_level_mode_set_multi(void)
4167 DEVMODEW old_devmode, devmode, devmode2, devmode3, *original_modes = NULL;
4168 unsigned int mode_idx = 0, display_idx, display_count = 0;
4169 WCHAR second_monitor_name[CCHDEVICENAME];
4170 IDirectDraw4 *ddraw1, *ddraw2;
4171 LONG change_ret;
4172 UINT w, h;
4173 HWND window;
4174 HRESULT hr;
4175 ULONG ref;
4176 BOOL ret;
4178 memset(&devmode, 0, sizeof(devmode));
4179 devmode.dmSize = sizeof(devmode);
4180 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
4181 ok(ret, "EnumDisplaySettingsW failed, error %lu.\n", GetLastError());
4182 ok(compare_mode_rect(&devmode, &registry_mode), "Got a different mode.\n");
4183 ret = EnumDisplaySettingsW(NULL, ENUM_REGISTRY_SETTINGS, &devmode);
4184 ok(ret, "EnumDisplaySettingsW failed, error %lu.\n", GetLastError());
4185 ok(compare_mode_rect(&devmode, &registry_mode), "Got a different mode.\n");
4187 ret = save_display_modes(&original_modes, &display_count);
4188 ok(ret, "Failed to save original display modes.\n");
4190 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
4191 0, 0, 100, 100, 0, 0, 0, 0);
4192 ddraw1 = create_ddraw();
4193 ok(!!ddraw1, "Failed to create a ddraw object.\n");
4195 /* With just a single ddraw object, the display mode is restored on
4196 * release. */
4197 hr = set_display_mode(ddraw1, 800, 600);
4198 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#lx.\n", hr);
4199 w = GetSystemMetrics(SM_CXSCREEN);
4200 ok(w == 800, "Got unexpected screen width %u.\n", w);
4201 h = GetSystemMetrics(SM_CYSCREEN);
4202 ok(h == 600, "Got unexpected screen height %u.\n", h);
4204 ref = IDirectDraw4_Release(ddraw1);
4205 ok(!ref, "Unexpected refcount %lu.\n", ref);
4206 w = GetSystemMetrics(SM_CXSCREEN);
4207 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
4208 h = GetSystemMetrics(SM_CYSCREEN);
4209 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
4211 /* When there are multiple ddraw objects, the display mode is restored to
4212 * the initial mode, before the first SetDisplayMode() call. */
4213 ddraw1 = create_ddraw();
4214 hr = set_display_mode(ddraw1, 800, 600);
4215 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#lx.\n", hr);
4216 w = GetSystemMetrics(SM_CXSCREEN);
4217 ok(w == 800, "Got unexpected screen width %u.\n", w);
4218 h = GetSystemMetrics(SM_CYSCREEN);
4219 ok(h == 600, "Got unexpected screen height %u.\n", h);
4221 ddraw2 = create_ddraw();
4222 hr = set_display_mode(ddraw2, 640, 480);
4223 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#lx.\n", hr);
4224 w = GetSystemMetrics(SM_CXSCREEN);
4225 ok(w == 640, "Got unexpected screen width %u.\n", w);
4226 h = GetSystemMetrics(SM_CYSCREEN);
4227 ok(h == 480, "Got unexpected screen height %u.\n", h);
4229 ref = IDirectDraw4_Release(ddraw2);
4230 ok(!ref, "Unexpected refcount %lu.\n", ref);
4231 w = GetSystemMetrics(SM_CXSCREEN);
4232 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
4233 h = GetSystemMetrics(SM_CYSCREEN);
4234 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
4236 ref = IDirectDraw4_Release(ddraw1);
4237 ok(!ref, "Unexpected refcount %lu.\n", ref);
4238 w = GetSystemMetrics(SM_CXSCREEN);
4239 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
4240 h = GetSystemMetrics(SM_CYSCREEN);
4241 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
4243 /* Regardless of release ordering. */
4244 ddraw1 = create_ddraw();
4245 hr = set_display_mode(ddraw1, 800, 600);
4246 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#lx.\n", hr);
4247 w = GetSystemMetrics(SM_CXSCREEN);
4248 ok(w == 800, "Got unexpected screen width %u.\n", w);
4249 h = GetSystemMetrics(SM_CYSCREEN);
4250 ok(h == 600, "Got unexpected screen height %u.\n", h);
4252 ddraw2 = create_ddraw();
4253 hr = set_display_mode(ddraw2, 640, 480);
4254 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#lx.\n", hr);
4255 w = GetSystemMetrics(SM_CXSCREEN);
4256 ok(w == 640, "Got unexpected screen width %u.\n", w);
4257 h = GetSystemMetrics(SM_CYSCREEN);
4258 ok(h == 480, "Got unexpected screen height %u.\n", h);
4260 ref = IDirectDraw4_Release(ddraw1);
4261 ok(!ref, "Unexpected refcount %lu.\n", ref);
4262 w = GetSystemMetrics(SM_CXSCREEN);
4263 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
4264 h = GetSystemMetrics(SM_CYSCREEN);
4265 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
4267 ref = IDirectDraw4_Release(ddraw2);
4268 ok(!ref, "Unexpected refcount %lu.\n", ref);
4269 w = GetSystemMetrics(SM_CXSCREEN);
4270 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
4271 h = GetSystemMetrics(SM_CYSCREEN);
4272 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
4274 /* But only for ddraw objects that called SetDisplayMode(). */
4275 ddraw1 = create_ddraw();
4276 ddraw2 = create_ddraw();
4277 hr = set_display_mode(ddraw2, 640, 480);
4278 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#lx.\n", hr);
4279 w = GetSystemMetrics(SM_CXSCREEN);
4280 ok(w == 640, "Got unexpected screen width %u.\n", w);
4281 h = GetSystemMetrics(SM_CYSCREEN);
4282 ok(h == 480, "Got unexpected screen height %u.\n", h);
4284 ref = IDirectDraw4_Release(ddraw1);
4285 ok(!ref, "Unexpected refcount %lu.\n", ref);
4286 w = GetSystemMetrics(SM_CXSCREEN);
4287 ok(w == 640, "Got unexpected screen width %u.\n", w);
4288 h = GetSystemMetrics(SM_CYSCREEN);
4289 ok(h == 480, "Got unexpected screen height %u.\n", h);
4291 ref = IDirectDraw4_Release(ddraw2);
4292 ok(!ref, "Unexpected refcount %lu.\n", ref);
4293 w = GetSystemMetrics(SM_CXSCREEN);
4294 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
4295 h = GetSystemMetrics(SM_CYSCREEN);
4296 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
4298 /* If there's a ddraw object that's currently in exclusive mode, it blocks
4299 * restoring the display mode. */
4300 ddraw1 = create_ddraw();
4301 hr = set_display_mode(ddraw1, 800, 600);
4302 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#lx.\n", hr);
4303 w = GetSystemMetrics(SM_CXSCREEN);
4304 ok(w == 800, "Got unexpected screen width %u.\n", w);
4305 h = GetSystemMetrics(SM_CYSCREEN);
4306 ok(h == 600, "Got unexpected screen height %u.\n", h);
4308 ddraw2 = create_ddraw();
4309 hr = set_display_mode(ddraw2, 640, 480);
4310 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#lx.\n", hr);
4311 w = GetSystemMetrics(SM_CXSCREEN);
4312 ok(w == 640, "Got unexpected screen width %u.\n", w);
4313 h = GetSystemMetrics(SM_CYSCREEN);
4314 ok(h == 480, "Got unexpected screen height %u.\n", h);
4316 hr = IDirectDraw4_SetCooperativeLevel(ddraw2, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
4317 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#lx.\n", hr);
4319 ref = IDirectDraw4_Release(ddraw1);
4320 ok(!ref, "Unexpected refcount %lu.\n", ref);
4321 w = GetSystemMetrics(SM_CXSCREEN);
4322 ok(w == 640, "Got unexpected screen width %u.\n", w);
4323 h = GetSystemMetrics(SM_CYSCREEN);
4324 ok(h == 480, "Got unexpected screen height %u.\n", h);
4326 ref = IDirectDraw4_Release(ddraw2);
4327 ok(!ref, "Unexpected refcount %lu.\n", ref);
4328 w = GetSystemMetrics(SM_CXSCREEN);
4329 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
4330 h = GetSystemMetrics(SM_CYSCREEN);
4331 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
4333 /* Exclusive mode blocks mode setting on other ddraw objects in general. */
4334 ddraw1 = create_ddraw();
4335 hr = set_display_mode(ddraw1, 800, 600);
4336 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#lx.\n", hr);
4337 w = GetSystemMetrics(SM_CXSCREEN);
4338 ok(w == 800, "Got unexpected screen width %u.\n", w);
4339 h = GetSystemMetrics(SM_CYSCREEN);
4340 ok(h == 600, "Got unexpected screen height %u.\n", h);
4342 hr = IDirectDraw4_SetCooperativeLevel(ddraw1, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
4343 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#lx.\n", hr);
4345 ddraw2 = create_ddraw();
4346 hr = set_display_mode(ddraw2, 640, 480);
4347 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#lx.\n", hr);
4349 ref = IDirectDraw4_Release(ddraw1);
4350 ok(!ref, "Unexpected refcount %lu.\n", ref);
4351 w = GetSystemMetrics(SM_CXSCREEN);
4352 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
4353 h = GetSystemMetrics(SM_CYSCREEN);
4354 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
4356 ref = IDirectDraw4_Release(ddraw2);
4357 ok(!ref, "Unexpected refcount %lu.\n", ref);
4358 w = GetSystemMetrics(SM_CXSCREEN);
4359 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
4360 h = GetSystemMetrics(SM_CYSCREEN);
4361 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
4363 if (display_count < 2)
4365 skip("Following tests require two monitors.\n");
4366 goto done;
4369 ret = restore_display_modes(original_modes, display_count);
4370 ok(ret, "Failed to restore display modes.\n");
4372 second_monitor_name[0] = '\0';
4373 for (display_idx = 0; display_idx < display_count; ++display_idx)
4375 if (original_modes[display_idx].dmPosition.x || original_modes[display_idx].dmPosition.y)
4377 lstrcpyW(second_monitor_name, original_modes[display_idx].dmDeviceName);
4378 break;
4381 ok(lstrlenW(second_monitor_name), "Got an empty second monitor name.\n");
4382 memset(&old_devmode, 0, sizeof(old_devmode));
4383 old_devmode.dmSize = sizeof(old_devmode);
4384 ret = EnumDisplaySettingsW(second_monitor_name, ENUM_CURRENT_SETTINGS, &old_devmode);
4385 ok(ret, "EnumDisplaySettingsW failed, error %lu.\n", GetLastError());
4387 devmode = old_devmode;
4388 while (EnumDisplaySettingsW(second_monitor_name, mode_idx++, &devmode))
4390 if (devmode.dmPelsWidth != old_devmode.dmPelsWidth
4391 || devmode.dmPelsHeight != old_devmode.dmPelsHeight)
4392 break;
4394 ok(devmode.dmPelsWidth != old_devmode.dmPelsWidth
4395 || devmode.dmPelsHeight != old_devmode.dmPelsHeight,
4396 "Failed to find a different mode for the second monitor.\n");
4398 /* Test that no mode restorations for non-primary monitors if SetDisplayMode() was not called */
4399 ddraw1 = create_ddraw();
4400 ok(!!ddraw1, "Failed to create a ddraw object.\n");
4401 hr = IDirectDraw4_SetCooperativeLevel(ddraw1, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
4402 ok(hr == DD_OK, "SetCooperativeLevel failed, hr %#lx.\n", hr);
4404 change_ret = ChangeDisplaySettingsExW(second_monitor_name, &devmode, NULL, CDS_RESET, NULL);
4405 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "ChangeDisplaySettingsExW failed with %ld.\n", change_ret);
4407 memset(&devmode2, 0, sizeof(devmode2));
4408 devmode2.dmSize = sizeof(devmode2);
4409 ret = EnumDisplaySettingsW(second_monitor_name, ENUM_CURRENT_SETTINGS, &devmode2);
4410 ok(ret, "EnumDisplaySettingsW failed, error %lu.\n", GetLastError());
4411 if (compare_mode_rect(&devmode2, &old_devmode))
4413 skip("Failed to change display settings of the second monitor.\n");
4414 ref = IDirectDraw4_Release(ddraw1);
4415 ok(!ref, "Unexpected refcount %lu.\n", ref);
4416 goto done;
4419 hr = IDirectDraw4_SetCooperativeLevel(ddraw1, window, DDSCL_NORMAL);
4420 ok(hr == DD_OK, "SetCooperativeLevel failed, hr %#lx.\n", hr);
4421 ref = IDirectDraw4_Release(ddraw1);
4422 ok(!ref, "Unexpected refcount %lu.\n", ref);
4424 memset(&devmode3, 0, sizeof(devmode3));
4425 devmode3.dmSize = sizeof(devmode3);
4426 ret = EnumDisplaySettingsW(second_monitor_name, ENUM_CURRENT_SETTINGS, &devmode3);
4427 ok(ret, "EnumDisplaySettingsW failed, error %lu.\n", GetLastError());
4428 ok(compare_mode_rect(&devmode3, &devmode2), "Got a different mode.\n");
4429 ret = restore_display_modes(original_modes, display_count);
4430 ok(ret, "Failed to restore display modes.\n");
4432 /* Test that mode restorations happen for non-primary monitors on ddraw releases if
4433 * SetDisplayMode() was called */
4434 ddraw1 = create_ddraw();
4435 ok(!!ddraw1, "Failed to create a ddraw object.\n");
4436 hr = set_display_mode(ddraw1, 800, 600);
4437 ok(hr == DD_OK, "Failed to set display mode, hr %#lx.\n", hr);
4439 change_ret = ChangeDisplaySettingsExW(second_monitor_name, &devmode, NULL, CDS_RESET, NULL);
4440 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "ChangeDisplaySettingsExW failed with %ld.\n", change_ret);
4442 ref = IDirectDraw4_Release(ddraw1);
4443 ok(!ref, "Unexpected refcount %lu.\n", ref);
4445 ret = EnumDisplaySettingsW(second_monitor_name, ENUM_CURRENT_SETTINGS, &devmode2);
4446 ok(ret, "EnumDisplaySettingsW failed, error %lu.\n", GetLastError());
4447 ok(compare_mode_rect(&devmode2, &old_devmode), "Got a different mode.\n");
4448 ret = EnumDisplaySettingsW(second_monitor_name, ENUM_REGISTRY_SETTINGS, &devmode2);
4449 ok(ret, "EnumDisplaySettingsW failed, error %lu.\n", GetLastError());
4450 ok(compare_mode_rect(&devmode2, &old_devmode), "Got a different mode.\n");
4451 ret = restore_display_modes(original_modes, display_count);
4452 ok(ret, "Failed to restore display modes.\n");
4454 /* Test that mode restorations happen for non-primary monitors as well */
4455 ddraw1 = create_ddraw();
4456 ok(!!ddraw1, "Failed to create a ddraw object.\n");
4457 hr = set_display_mode(ddraw1, 800, 600);
4458 ok(hr == DD_OK, "Failed to set display mode, hr %#lx.\n", hr);
4460 change_ret = ChangeDisplaySettingsExW(second_monitor_name, &devmode, NULL, CDS_RESET, NULL);
4461 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "ChangeDisplaySettingsExW failed with %ld.\n", change_ret);
4463 hr = IDirectDraw4_RestoreDisplayMode(ddraw1);
4464 ok(hr == DD_OK, "RestoreDisplayMode failed, hr %#lx.\n", hr);
4466 ret = EnumDisplaySettingsW(second_monitor_name, ENUM_CURRENT_SETTINGS, &devmode2);
4467 ok(ret, "EnumDisplaySettingsW failed, error %lu.\n", GetLastError());
4468 ok(compare_mode_rect(&devmode2, &old_devmode), "Got a different mode.\n");
4469 ret = EnumDisplaySettingsW(second_monitor_name, ENUM_REGISTRY_SETTINGS, &devmode2);
4470 ok(ret, "EnumDisplaySettingsW failed, error %lu.\n", GetLastError());
4471 ok(compare_mode_rect(&devmode2, &old_devmode), "Got a different mode.\n");
4473 ref = IDirectDraw4_Release(ddraw1);
4474 ok(!ref, "Unexpected refcount %lu.\n", ref);
4475 ret = restore_display_modes(original_modes, display_count);
4476 ok(ret, "Failed to restore display modes.\n");
4478 /* Test that mode restorations for non-primary monitors use display settings in the registry */
4479 ddraw1 = create_ddraw();
4480 ok(!!ddraw1, "Failed to create a ddraw object.\n");
4481 hr = set_display_mode(ddraw1, 800, 600);
4482 ok(hr == DD_OK, "Failed to set display mode, hr %#lx.\n", hr);
4484 change_ret = ChangeDisplaySettingsExW(second_monitor_name, &devmode, NULL,
4485 CDS_UPDATEREGISTRY | CDS_NORESET, NULL);
4486 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "ChangeDisplaySettingsExW failed with %ld.\n", change_ret);
4488 ref = IDirectDraw4_Release(ddraw1);
4489 ok(!ref, "Unexpected refcount %lu.\n", ref);
4491 ret = EnumDisplaySettingsW(second_monitor_name, ENUM_CURRENT_SETTINGS, &devmode2);
4492 ok(ret, "EnumDisplaySettingsW failed, error %lu.\n", GetLastError());
4493 ok(devmode2.dmPelsWidth == devmode.dmPelsWidth && devmode2.dmPelsHeight == devmode.dmPelsHeight,
4494 "Expected resolution %lux%lu, got %lux%lu.\n", devmode.dmPelsWidth, devmode.dmPelsHeight,
4495 devmode2.dmPelsWidth, devmode2.dmPelsHeight);
4496 ret = EnumDisplaySettingsW(second_monitor_name, ENUM_REGISTRY_SETTINGS, &devmode2);
4497 ok(ret, "EnumDisplaySettingsW failed, error %lu.\n", GetLastError());
4498 ok(devmode2.dmPelsWidth == devmode.dmPelsWidth && devmode2.dmPelsHeight == devmode.dmPelsHeight,
4499 "Expected resolution %lux%lu, got %lux%lu.\n", devmode.dmPelsWidth, devmode.dmPelsHeight,
4500 devmode2.dmPelsWidth, devmode2.dmPelsHeight);
4501 ret = restore_display_modes(original_modes, display_count);
4502 ok(ret, "Failed to restore display modes.\n");
4504 /* Test mode restorations for non-primary monitors when there are multiple fullscreen ddraw
4505 * objects and one of them restores display mode */
4506 ddraw1 = create_ddraw();
4507 ok(!!ddraw1, "Failed to create a ddraw object.\n");
4508 ddraw2 = create_ddraw();
4509 ok(!!ddraw2, "Failed to create a ddraw object.\n");
4510 hr = set_display_mode(ddraw1, 800, 600);
4511 ok(hr == DD_OK, "Failed to set display mode, hr %#lx.\n", hr);
4512 hr = set_display_mode(ddraw2, 640, 480);
4513 ok(hr == DD_OK, "Failed to set display mode, hr %#lx.\n", hr);
4515 change_ret = ChangeDisplaySettingsExW(second_monitor_name, &devmode, NULL, CDS_RESET, NULL);
4516 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "ChangeDisplaySettingsExW failed with %ld.\n", change_ret);
4518 hr = IDirectDraw4_RestoreDisplayMode(ddraw2);
4519 ok(hr == DD_OK, "RestoreDisplayMode failed, hr %#lx.\n", hr);
4521 ret = EnumDisplaySettingsW(second_monitor_name, ENUM_CURRENT_SETTINGS, &devmode2);
4522 ok(ret, "EnumDisplaySettingsW failed, error %lu.\n", GetLastError());
4523 ok(compare_mode_rect(&devmode2, &old_devmode), "Got a different mode.\n");
4524 ret = EnumDisplaySettingsW(second_monitor_name, ENUM_REGISTRY_SETTINGS, &devmode2);
4525 ok(ret, "EnumDisplaySettingsW failed, error %lu.\n", GetLastError());
4526 ok(compare_mode_rect(&devmode2, &old_devmode), "Got a different mode.\n");
4528 ref = IDirectDraw4_Release(ddraw2);
4529 ok(!ref, "Unexpected refcount %lu.\n", ref);
4530 ref = IDirectDraw4_Release(ddraw1);
4531 ok(!ref, "Unexpected refcount %lu.\n", ref);
4532 ret = restore_display_modes(original_modes, display_count);
4533 ok(ret, "Failed to restore display modes.\n");
4535 /* Test mode restorations for non-primary monitors when there are multiple fullscreen ddraw
4536 * objects and one of them got released */
4537 ddraw1 = create_ddraw();
4538 ok(!!ddraw1, "Failed to create a ddraw object.\n");
4539 ddraw2 = create_ddraw();
4540 ok(!!ddraw2, "Failed to create a ddraw object.\n");
4541 hr = set_display_mode(ddraw1, 800, 600);
4542 ok(hr == DD_OK, "Failed to set display mode, hr %#lx.\n", hr);
4543 hr = set_display_mode(ddraw2, 640, 480);
4544 ok(hr == DD_OK, "Failed to set display mode, hr %#lx.\n", hr);
4546 change_ret = ChangeDisplaySettingsExW(second_monitor_name, &devmode, NULL, CDS_RESET, NULL);
4547 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "ChangeDisplaySettingsExW failed with %ld.\n", change_ret);
4549 ref = IDirectDraw4_Release(ddraw2);
4550 ok(!ref, "Unexpected refcount %lu.\n", ref);
4552 ret = EnumDisplaySettingsW(second_monitor_name, ENUM_CURRENT_SETTINGS, &devmode2);
4553 ok(ret, "EnumDisplaySettingsW failed, error %lu.\n", GetLastError());
4554 ok(compare_mode_rect(&devmode2, &old_devmode), "Got a different mode.\n");
4555 ret = EnumDisplaySettingsW(second_monitor_name, ENUM_REGISTRY_SETTINGS, &devmode2);
4556 ok(ret, "EnumDisplaySettingsW failed, error %lu.\n", GetLastError());
4557 ok(compare_mode_rect(&devmode2, &old_devmode), "Got a different mode.\n");
4559 ref = IDirectDraw4_Release(ddraw1);
4560 ok(!ref, "Unexpected refcount %lu.\n", ref);
4562 done:
4563 DestroyWindow(window);
4564 ret = restore_display_modes(original_modes, display_count);
4565 ok(ret, "Failed to restore display modes.\n");
4566 free(original_modes);
4569 static void test_initialize(void)
4571 IDirectDraw4 *ddraw;
4572 HRESULT hr;
4574 ddraw = create_ddraw();
4575 ok(!!ddraw, "Failed to create a ddraw object.\n");
4577 hr = IDirectDraw4_Initialize(ddraw, NULL);
4578 ok(hr == DDERR_ALREADYINITIALIZED, "Initialize returned hr %#lx.\n", hr);
4579 IDirectDraw4_Release(ddraw);
4581 CoInitialize(NULL);
4582 hr = CoCreateInstance(&CLSID_DirectDraw, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectDraw4, (void **)&ddraw);
4583 ok(SUCCEEDED(hr), "Failed to create IDirectDraw4 instance, hr %#lx.\n", hr);
4584 hr = IDirectDraw4_Initialize(ddraw, NULL);
4585 ok(hr == DD_OK, "Initialize returned hr %#lx, expected DD_OK.\n", hr);
4586 hr = IDirectDraw4_Initialize(ddraw, NULL);
4587 ok(hr == DDERR_ALREADYINITIALIZED, "Initialize returned hr %#lx, expected DDERR_ALREADYINITIALIZED.\n", hr);
4588 IDirectDraw4_Release(ddraw);
4589 CoUninitialize();
4592 static void test_coop_level_surf_create(void)
4594 IDirectDrawSurface4 *surface;
4595 IDirectDraw4 *ddraw;
4596 DDSURFACEDESC2 ddsd;
4597 HRESULT hr;
4599 ddraw = create_ddraw();
4600 ok(!!ddraw, "Failed to create a ddraw object.\n");
4602 memset(&ddsd, 0, sizeof(ddsd));
4603 ddsd.dwSize = sizeof(ddsd);
4604 ddsd.dwFlags = DDSD_CAPS;
4605 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
4606 surface = (void *)0xdeadbeef;
4607 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
4608 ok(hr == DDERR_NOCOOPERATIVELEVELSET, "Surface creation returned hr %#lx.\n", hr);
4609 ok(surface == (void *)0xdeadbeef, "Got unexpected surface %p.\n", surface);
4611 surface = (void *)0xdeadbeef;
4612 hr = IDirectDraw4_CreateSurface(ddraw, NULL, &surface, NULL);
4613 ok(hr == DDERR_NOCOOPERATIVELEVELSET, "Surface creation returned hr %#lx.\n", hr);
4614 ok(surface == (void *)0xdeadbeef, "Got unexpected surface %p.\n", surface);
4616 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
4617 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
4619 surface = (void *)0xdeadbeef;
4620 hr = IDirectDraw4_CreateSurface(ddraw, NULL, &surface, NULL);
4621 ok(hr == DDERR_INVALIDPARAMS, "Unexpected hr %#lx.\n", hr);
4622 ok(surface == (void *)0xdeadbeef, "Got unexpected surface %p.\n", surface);
4624 IDirectDraw4_Release(ddraw);
4627 static void test_vb_discard(void)
4629 static const struct vec4 quad[] =
4631 { 0.0f, 480.0f, 0.0f, 1.0f},
4632 { 0.0f, 0.0f, 0.0f, 1.0f},
4633 {640.0f, 480.0f, 0.0f, 1.0f},
4634 {640.0f, 0.0f, 0.0f, 1.0f},
4637 IDirect3DDevice3 *device;
4638 IDirect3D3 *d3d;
4639 IDirect3DVertexBuffer *buffer;
4640 HWND window;
4641 HRESULT hr;
4642 D3DVERTEXBUFFERDESC desc;
4643 BYTE *data;
4644 static const unsigned int vbsize = 16;
4645 unsigned int i;
4647 window = create_window();
4648 if (!(device = create_device(window, DDSCL_NORMAL)))
4650 skip("Failed to create a 3D device, skipping test.\n");
4651 DestroyWindow(window);
4652 return;
4655 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
4656 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#lx.\n", hr);
4658 memset(&desc, 0, sizeof(desc));
4659 desc.dwSize = sizeof(desc);
4660 desc.dwCaps = D3DVBCAPS_WRITEONLY;
4661 desc.dwFVF = D3DFVF_XYZRHW;
4662 desc.dwNumVertices = vbsize;
4663 hr = IDirect3D3_CreateVertexBuffer(d3d, &desc, &buffer, 0, NULL);
4664 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#lx.\n", hr);
4666 hr = IDirect3DVertexBuffer_Lock(buffer, DDLOCK_DISCARDCONTENTS, (void **)&data, NULL);
4667 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#lx.\n", hr);
4668 memcpy(data, quad, sizeof(quad));
4669 hr = IDirect3DVertexBuffer_Unlock(buffer);
4670 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#lx.\n", hr);
4672 hr = IDirect3DDevice3_BeginScene(device);
4673 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#lx.\n", hr);
4674 hr = IDirect3DDevice3_DrawPrimitiveVB(device, D3DPT_TRIANGLESTRIP, buffer, 0, 4, 0);
4675 ok(SUCCEEDED(hr), "Failed to draw, hr %#lx.\n", hr);
4676 hr = IDirect3DDevice3_EndScene(device);
4677 ok(SUCCEEDED(hr), "Failed to end scene, hr %#lx.\n", hr);
4679 hr = IDirect3DVertexBuffer_Lock(buffer, DDLOCK_DISCARDCONTENTS, (void **)&data, NULL);
4680 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#lx.\n", hr);
4681 memset(data, 0xaa, sizeof(struct vec4) * vbsize);
4682 hr = IDirect3DVertexBuffer_Unlock(buffer);
4683 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#lx.\n", hr);
4685 hr = IDirect3DVertexBuffer_Lock(buffer, DDLOCK_DISCARDCONTENTS, (void **)&data, NULL);
4686 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#lx.\n", hr);
4687 for (i = 0; i < sizeof(struct vec4) * vbsize; i++)
4689 if (data[i] != 0xaa)
4691 ok(FALSE, "Vertex buffer data byte %u is 0x%02x, expected 0xaa\n", i, data[i]);
4692 break;
4695 hr = IDirect3DVertexBuffer_Unlock(buffer);
4696 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#lx.\n", hr);
4698 IDirect3DVertexBuffer_Release(buffer);
4699 IDirect3D3_Release(d3d);
4700 IDirect3DDevice3_Release(device);
4701 DestroyWindow(window);
4704 static void test_coop_level_multi_window(void)
4706 HWND window1, window2;
4707 IDirectDraw4 *ddraw;
4708 HRESULT hr;
4710 window1 = create_window();
4711 window2 = create_window();
4712 ddraw = create_ddraw();
4713 ok(!!ddraw, "Failed to create a ddraw object.\n");
4715 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window1, DDSCL_NORMAL);
4716 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
4717 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window2, DDSCL_NORMAL);
4718 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
4719 ok(IsWindow(window1), "Window 1 was destroyed.\n");
4720 ok(IsWindow(window2), "Window 2 was destroyed.\n");
4722 IDirectDraw4_Release(ddraw);
4723 DestroyWindow(window2);
4724 DestroyWindow(window1);
4727 static void test_draw_strided(void)
4729 static struct vec3 position[] =
4731 {-1.0, -1.0, 0.0},
4732 {-1.0, 1.0, 0.0},
4733 { 1.0, 1.0, 0.0},
4734 { 1.0, -1.0, 0.0},
4736 static DWORD diffuse[] =
4738 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00,
4740 static WORD indices[] =
4742 0, 1, 2, 2, 3, 0
4745 IDirectDrawSurface4 *rt;
4746 IDirect3DDevice3 *device;
4747 unsigned int color;
4748 HWND window;
4749 HRESULT hr;
4750 D3DDRAWPRIMITIVESTRIDEDDATA strided;
4751 IDirect3DViewport3 *viewport;
4752 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
4754 window = create_window();
4755 if (!(device = create_device(window, DDSCL_NORMAL)))
4757 skip("Failed to create a 3D device, skipping test.\n");
4758 DestroyWindow(window);
4759 return;
4762 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
4763 ok(SUCCEEDED(hr), "Failed to get render target, hr %#lx.\n", hr);
4764 viewport = create_viewport(device, 0, 0, 640, 480);
4765 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
4766 ok(SUCCEEDED(hr), "Failed to activate the viewport, hr %#lx.\n", hr);
4767 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0x00000000, 0.0f, 0);
4768 ok(SUCCEEDED(hr), "Failed to clear the viewport, hr %#lx.\n", hr);
4770 hr = IDirect3DDevice3_BeginScene(device);
4771 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#lx.\n", hr);
4773 memset(&strided, 0x55, sizeof(strided));
4774 strided.position.lpvData = position;
4775 strided.position.dwStride = sizeof(*position);
4776 strided.diffuse.lpvData = diffuse;
4777 strided.diffuse.dwStride = sizeof(*diffuse);
4778 hr = IDirect3DDevice3_DrawIndexedPrimitiveStrided(device, D3DPT_TRIANGLELIST, D3DFVF_XYZ | D3DFVF_DIFFUSE,
4779 &strided, 4, indices, 6, 0);
4780 ok(SUCCEEDED(hr), "Failed to draw, hr %#lx.\n", hr);
4782 hr = IDirect3DDevice3_EndScene(device);
4783 ok(SUCCEEDED(hr), "Failed to end scene, hr %#lx.\n", hr);
4785 color = get_surface_color(rt, 320, 240);
4786 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
4788 IDirect3DViewport3_Release(viewport);
4789 IDirectDrawSurface4_Release(rt);
4790 IDirect3DDevice3_Release(device);
4791 DestroyWindow(window);
4794 static void test_lighting(void)
4796 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
4797 static D3DMATRIX mat =
4799 1.0f, 0.0f, 0.0f, 0.0f,
4800 0.0f, 1.0f, 0.0f, 0.0f,
4801 0.0f, 0.0f, 1.0f, 0.0f,
4802 0.0f, 0.0f, 0.0f, 1.0f,
4804 mat_singular =
4806 1.0f, 0.0f, 1.0f, 0.0f,
4807 0.0f, 1.0f, 0.0f, 0.0f,
4808 1.0f, 0.0f, 1.0f, 0.0f,
4809 0.0f, 0.0f, 0.5f, 1.0f,
4811 mat_transf =
4813 0.0f, 0.0f, 1.0f, 0.0f,
4814 0.0f, 1.0f, 0.0f, 0.0f,
4815 -1.0f, 0.0f, 0.0f, 0.0f,
4816 10.f, 10.0f, 10.0f, 1.0f,
4818 mat_nonaffine =
4820 1.0f, 0.0f, 0.0f, 0.0f,
4821 0.0f, 1.0f, 0.0f, 0.0f,
4822 0.0f, 0.0f, 1.0f, -1.0f,
4823 10.f, 10.0f, 10.0f, 0.0f,
4825 static struct vertex
4827 struct vec3 position;
4828 DWORD diffuse;
4830 unlitquad[] =
4832 {{-1.0f, -1.0f, 0.1f}, 0xffff0000},
4833 {{-1.0f, 0.0f, 0.1f}, 0xffff0000},
4834 {{ 0.0f, 0.0f, 0.1f}, 0xffff0000},
4835 {{ 0.0f, -1.0f, 0.1f}, 0xffff0000},
4837 litquad[] =
4839 {{-1.0f, 0.0f, 0.1f}, 0xff00ff00},
4840 {{-1.0f, 1.0f, 0.1f}, 0xff00ff00},
4841 {{ 0.0f, 1.0f, 0.1f}, 0xff00ff00},
4842 {{ 0.0f, 0.0f, 0.1f}, 0xff00ff00},
4844 static struct vertex_normal
4846 struct vec3 position;
4847 struct vec3 normal;
4848 DWORD diffuse;
4850 unlitnquad[] =
4852 {{0.0f, -1.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xff0000ff},
4853 {{0.0f, 0.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xff0000ff},
4854 {{1.0f, 0.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xff0000ff},
4855 {{1.0f, -1.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xff0000ff},
4857 litnquad[] =
4859 {{0.0f, 0.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xffffff00},
4860 {{0.0f, 1.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xffffff00},
4861 {{1.0f, 1.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xffffff00},
4862 {{1.0f, 0.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xffffff00},
4864 nquad[] =
4866 {{-1.0f, -1.0f, 0.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
4867 {{-1.0f, 1.0f, 0.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
4868 {{ 1.0f, 1.0f, 0.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
4869 {{ 1.0f, -1.0f, 0.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
4871 rotatedquad[] =
4873 {{-10.0f, -11.0f, 11.0f}, {-1.0f, 0.0f, 0.0f}, 0xff0000ff},
4874 {{-10.0f, -9.0f, 11.0f}, {-1.0f, 0.0f, 0.0f}, 0xff0000ff},
4875 {{-10.0f, -9.0f, 9.0f}, {-1.0f, 0.0f, 0.0f}, 0xff0000ff},
4876 {{-10.0f, -11.0f, 9.0f}, {-1.0f, 0.0f, 0.0f}, 0xff0000ff},
4878 translatedquad[] =
4880 {{-11.0f, -11.0f, -10.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
4881 {{-11.0f, -9.0f, -10.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
4882 {{ -9.0f, -9.0f, -10.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
4883 {{ -9.0f, -11.0f, -10.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
4885 static WORD indices[] = {0, 1, 2, 2, 3, 0};
4886 static const struct
4888 D3DMATRIX *world_matrix;
4889 void *quad;
4890 DWORD expected;
4891 const char *message;
4893 tests[] =
4895 {&mat, nquad, 0x000080ff, "Lit quad with light"},
4896 {&mat_singular, nquad, 0x000080b4, "Lit quad with singular world matrix"},
4897 {&mat_transf, rotatedquad, 0x000080ff, "Lit quad with transformation matrix"},
4898 {&mat_nonaffine, translatedquad, 0x000080ff, "Lit quad with non-affine matrix"},
4900 DWORD nfvf = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_NORMAL;
4901 IDirect3DVertexBuffer *src_vb1, *src_vb2, *dst_vb;
4902 IDirect3DViewport3 *viewport, *viewport2;
4903 DWORD fvf = D3DFVF_XYZ | D3DFVF_DIFFUSE;
4904 struct vertex_normal *src_data2;
4905 IDirect3DMaterial3 *material;
4906 D3DMATERIALHANDLE mat_handle;
4907 D3DVERTEXBUFFERDESC vb_desc;
4908 IDirect3DDevice3 *device;
4909 struct vertex *src_data1;
4910 IDirectDrawSurface4 *rt;
4911 IDirect3DLight *light;
4912 unsigned int color, i;
4913 D3DLIGHT2 light_desc;
4914 IDirect3D3 *d3d;
4915 ULONG refcount;
4916 HWND window;
4917 HRESULT hr;
4918 struct
4920 struct vec4 position;
4921 unsigned int diffuse, specular;
4923 *dst_data;
4925 window = create_window();
4926 if (!(device = create_device(window, DDSCL_NORMAL)))
4928 skip("Failed to create a 3D device, skipping test.\n");
4929 DestroyWindow(window);
4930 return;
4933 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
4934 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
4936 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
4937 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
4939 viewport = create_viewport(device, 0, 0, 640, 480);
4940 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
4941 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
4943 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xffffffff, 0.0f, 0);
4944 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
4946 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &mat);
4947 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
4948 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_VIEW, &mat);
4949 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
4950 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &mat);
4951 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
4952 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ZENABLE, FALSE);
4953 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
4954 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, FALSE);
4955 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
4956 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_STENCILENABLE, FALSE);
4957 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
4958 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_CULLMODE, D3DCULL_NONE);
4959 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
4961 hr = IDirect3DDevice3_BeginScene(device);
4962 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
4964 memset(&vb_desc, 0, sizeof(vb_desc));
4965 vb_desc.dwSize = sizeof(vb_desc);
4966 vb_desc.dwFVF = fvf;
4967 vb_desc.dwNumVertices = 2;
4968 hr = IDirect3D3_CreateVertexBuffer(d3d, &vb_desc, &src_vb1, 0, NULL);
4969 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
4970 vb_desc.dwSize = sizeof(vb_desc);
4971 vb_desc.dwFVF = nfvf;
4972 vb_desc.dwNumVertices = 2;
4973 hr = IDirect3D3_CreateVertexBuffer(d3d, &vb_desc, &src_vb2, 0, NULL);
4974 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
4976 memset(&vb_desc, 0, sizeof(vb_desc));
4977 vb_desc.dwSize = sizeof(vb_desc);
4978 vb_desc.dwFVF = D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR;
4979 vb_desc.dwNumVertices = 4;
4980 hr = IDirect3D3_CreateVertexBuffer(d3d, &vb_desc, &dst_vb, 0, NULL);
4981 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
4983 hr = IDirect3DVertexBuffer_Lock(src_vb1, 0, (void **)&src_data1, NULL);
4984 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
4985 memcpy(src_data1, unlitquad, sizeof(*src_data1));
4986 memcpy(&src_data1[1], litquad, sizeof(*src_data1));
4987 hr = IDirect3DVertexBuffer_Unlock(src_vb1);
4988 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
4990 hr = IDirect3DVertexBuffer_Lock(src_vb2, 0, (void **)&src_data2, NULL);
4991 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
4992 memcpy(src_data2, unlitnquad, sizeof(*src_data2));
4993 memcpy(&src_data2[1], litnquad, sizeof(*src_data2));
4994 hr = IDirect3DVertexBuffer_Unlock(src_vb2);
4995 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
4997 /* There is no D3DRENDERSTATE_LIGHTING on ddraw < 7. */
4998 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
4999 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5000 hr = IDirect3DVertexBuffer_ProcessVertices(dst_vb, D3DVOP_TRANSFORM, 0,
5001 1, src_vb1, 0, device, 0);
5002 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5003 hr = IDirect3DDevice3_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, fvf, unlitquad, 4,
5004 indices, 6, 0);
5005 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5007 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_LIGHTING, TRUE);
5008 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5009 hr = IDirect3DVertexBuffer_ProcessVertices(dst_vb, D3DVOP_TRANSFORM | D3DVOP_LIGHT, 1,
5010 1, src_vb1, 1, device, 0);
5011 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5012 hr = IDirect3DDevice3_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, fvf, litquad, 4,
5013 indices, 6, 0);
5014 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5016 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
5017 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5018 hr = IDirect3DVertexBuffer_ProcessVertices(dst_vb, D3DVOP_TRANSFORM, 2,
5019 1, src_vb2, 0, device, 0);
5020 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5021 hr = IDirect3DDevice3_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, nfvf, unlitnquad, 4,
5022 indices, 6, 0);
5023 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5025 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_LIGHTING, TRUE);
5026 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5027 hr = IDirect3DVertexBuffer_ProcessVertices(dst_vb, D3DVOP_TRANSFORM | D3DVOP_LIGHT, 3,
5028 1, src_vb2, 1, device, 0);
5029 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5030 hr = IDirect3DDevice3_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, nfvf, litnquad, 4,
5031 indices, 6, 0);
5032 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5034 hr = IDirect3DDevice3_EndScene(device);
5035 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5037 hr = IDirect3DVertexBuffer_Lock(dst_vb, 0, (void **)&dst_data, NULL);
5038 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5040 color = get_surface_color(rt, 160, 360);
5041 ok(color == 0x00ff0000, "Unlit quad without normals has color 0x%08x.\n", color);
5042 ok(dst_data[0].diffuse == 0xffff0000,
5043 "Unlit quad without normals has color 0x%08x, expected 0xffff0000.\n", dst_data[0].diffuse);
5044 ok(!dst_data[0].specular,
5045 "Unexpected specular color 0x%08x.\n", dst_data[0].specular);
5047 color = get_surface_color(rt, 160, 120);
5048 ok(color == 0x0000ff00, "Lit quad without normals has color 0x%08x.\n", color);
5049 ok(dst_data[1].diffuse == 0xff00ff00,
5050 "Lit quad without normals has color 0x%08x, expected 0xff000000.\n", dst_data[1].diffuse);
5051 ok(!dst_data[1].specular,
5052 "Unexpected specular color 0x%08x.\n", dst_data[1].specular);
5054 color = get_surface_color(rt, 480, 360);
5055 ok(color == 0x000000ff, "Unlit quad with normals has color 0x%08x.\n", color);
5056 ok(dst_data[2].diffuse == 0xff0000ff,
5057 "Unlit quad with normals has color 0x%08x, expected 0xff0000ff.\n", dst_data[2].diffuse);
5058 ok(!dst_data[2].specular,
5059 "Unexpected specular color 0x%08x.\n", dst_data[2].specular);
5061 color = get_surface_color(rt, 480, 120);
5062 ok(color == 0x00ffff00, "Lit quad with normals has color 0x%08x.\n", color);
5063 ok(dst_data[3].diffuse == 0xffffff00,
5064 "Lit quad with normals has color 0x%08x, expected 0xff000000.\n", dst_data[3].diffuse);
5065 ok(!dst_data[3].specular,
5066 "Unexpected specular color 0x%08x.\n", dst_data[3].specular);
5068 hr = IDirect3DVertexBuffer_Unlock(dst_vb);
5069 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5071 material = create_diffuse_and_ambient_material(device, 0.0f, 1.0f, 1.0f, 0.5f);
5072 hr = IDirect3DMaterial3_GetHandle(material, device, &mat_handle);
5073 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5074 hr = IDirect3DDevice3_SetLightState(device, D3DLIGHTSTATE_MATERIAL, mat_handle);
5075 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5076 hr = IDirect3DDevice3_SetLightState(device, D3DLIGHTSTATE_AMBIENT, 0xff008000);
5077 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5079 hr = IDirect3D3_CreateLight(d3d, &light, NULL);
5080 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5081 memset(&light_desc, 0, sizeof(light_desc));
5082 light_desc.dwSize = sizeof(light_desc);
5083 light_desc.dltType = D3DLIGHT_DIRECTIONAL;
5084 light_desc.dcvColor.r = 1.0f;
5085 light_desc.dcvColor.g = 1.0f;
5086 light_desc.dcvColor.b = 1.0f;
5087 light_desc.dcvColor.a = 0.5f;
5088 light_desc.dvDirection.z = 1.0f;
5089 hr = IDirect3DLight_SetLight(light, (D3DLIGHT *)&light_desc);
5090 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5091 hr = IDirect3DViewport3_AddLight(viewport, light);
5092 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5093 hr = IDirect3DViewport3_AddLight(viewport, light);
5094 ok(hr == D3DERR_LIGHTHASVIEWPORT, "Got unexpected hr %#lx.\n", hr);
5096 viewport2 = create_viewport(device, 0, 0, 640, 480);
5097 hr = IDirect3DViewport3_AddLight(viewport2, light);
5098 ok(hr == D3DERR_LIGHTHASVIEWPORT, "Got unexpected hr %#lx.\n", hr);
5099 IDirect3DViewport3_Release(viewport2);
5101 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xffffffff, 0.0f, 0);
5102 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5104 hr = IDirect3DDevice3_BeginScene(device);
5105 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5107 hr = IDirect3DDevice3_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, nfvf, nquad,
5108 4, indices, 6, 0);
5109 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5111 hr = IDirect3DDevice3_EndScene(device);
5112 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5114 color = get_surface_color(rt, 320, 240);
5115 ok(color == 0x00008000, "Lit quad with no light has color 0x%08x.\n", color);
5117 light_desc.dwFlags = D3DLIGHT_ACTIVE;
5118 hr = IDirect3DLight_SetLight(light, (D3DLIGHT *)&light_desc);
5119 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5120 hr = IDirect3DViewport3_DeleteLight(viewport, light);
5121 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5122 light_desc.dwFlags = 0;
5123 hr = IDirect3DLight_GetLight(light, (D3DLIGHT *)&light_desc);
5124 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5125 ok(light_desc.dwFlags == D3DLIGHT_ACTIVE, "Got unexpected flags %#lx.\n", light_desc.dwFlags);
5127 hr = IDirect3DViewport3_AddLight(viewport, light);
5128 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5130 for (i = 0; i < ARRAY_SIZE(tests); ++i)
5132 hr = IDirect3DVertexBuffer_Lock(src_vb2, 0, (void **)&src_data2, NULL);
5133 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5134 memcpy(src_data2, tests[i].quad, sizeof(*src_data2));
5135 hr = IDirect3DVertexBuffer_Unlock(src_vb2);
5136 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5138 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_WORLD, tests[i].world_matrix);
5139 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5141 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xffffffff, 0.0f, 0);
5142 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5144 hr = IDirect3DDevice3_BeginScene(device);
5145 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5147 hr = IDirect3DVertexBuffer_ProcessVertices(dst_vb, D3DVOP_TRANSFORM | D3DVOP_LIGHT, 0,
5148 1, src_vb2, 0, device, 0);
5149 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5150 hr = IDirect3DDevice3_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, nfvf, tests[i].quad,
5151 4, indices, 6, 0);
5152 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5154 hr = IDirect3DDevice3_EndScene(device);
5155 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5157 hr = IDirect3DVertexBuffer_Lock(dst_vb, 0, (void **)&dst_data, NULL);
5158 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5160 color = get_surface_color(rt, 320, 240);
5161 ok(color == tests[i].expected, "%s has color 0x%08x.\n", tests[i].message, color);
5162 ok(dst_data[0].diffuse == (tests[i].expected | 0xff000000),
5163 "%s has color 0x%08x.\n", tests[i].message, dst_data[0].diffuse);
5164 ok(!dst_data[0].specular,
5165 "%s has specular color 0x%08x.\n", tests[i].message, dst_data[0].specular);
5167 hr = IDirect3DVertexBuffer_Unlock(dst_vb);
5168 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5171 IDirect3DVertexBuffer_Release(src_vb1);
5172 IDirect3DVertexBuffer_Release(src_vb2);
5173 IDirect3DVertexBuffer_Release(dst_vb);
5175 hr = IDirect3DViewport3_DeleteLight(viewport, light);
5176 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5177 IDirect3DLight_Release(light);
5178 destroy_material(material);
5179 IDirect3DViewport3_Release(viewport);
5180 IDirectDrawSurface4_Release(rt);
5181 refcount = IDirect3DDevice3_Release(device);
5182 ok(!refcount, "Device has %lu references left.\n", refcount);
5183 IDirect3D3_Release(d3d);
5184 DestroyWindow(window);
5187 static void test_specular_lighting(void)
5189 static const unsigned int vertices_side = 5;
5190 const unsigned int indices_count = (vertices_side - 1) * (vertices_side - 1) * 2 * 3;
5191 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
5192 static const DWORD fvf = D3DFVF_XYZ | D3DFVF_NORMAL;
5193 static D3DMATRIX mat =
5195 1.0f, 0.0f, 0.0f, 0.0f,
5196 0.0f, 1.0f, 0.0f, 0.0f,
5197 0.0f, 0.0f, 1.0f, 0.0f,
5198 0.0f, 0.0f, 0.0f, 1.0f,
5200 static const struct vertex
5202 struct vec3 position;
5203 struct vec3 normal;
5205 vertices[] =
5207 {{-0.5f, -0.5f, 1.0f}, {0.0f, 0.0f, -1.0f}},
5208 {{ 0.0f, -0.5f, 1.0f}, {0.0f, 0.0f, -1.0f}},
5209 {{ 0.5f, -0.5f, 1.0f}, {0.0f, 0.0f, -1.0f}},
5210 {{-0.5f, 0.0f, 1.0f}, {0.0f, 0.0f, -1.0f}},
5211 {{ 0.0f, 0.0f, 1.0f}, {0.0f, 0.0f, -1.0f}},
5212 {{ 0.5f, 0.0f, 1.0f}, {0.0f, 0.0f, -1.0f}},
5213 {{-0.5f, 0.5f, 1.0f}, {0.0f, 0.0f, -1.0f}},
5214 {{ 0.0f, 0.5f, 1.0f}, {0.0f, 0.0f, -1.0f}},
5215 {{ 0.5f, 0.5f, 1.0f}, {0.0f, 0.0f, -1.0f}},
5218 static D3DLIGHT2 directional =
5220 sizeof(D3DLIGHT2),
5221 D3DLIGHT_DIRECTIONAL,
5222 {{1.0f}, {1.0f}, {1.0f}, {0.0f}},
5223 {{0.0f}, {0.0f}, {0.0f}},
5224 {{0.0f}, {0.0f}, {1.0f}},
5226 point =
5228 sizeof(D3DLIGHT2),
5229 D3DLIGHT_POINT,
5230 {{1.0f}, {1.0f}, {1.0f}, {0.0f}},
5231 {{0.0f}, {0.0f}, {0.0f}},
5232 {{0.0f}, {0.0f}, {0.0f}},
5233 100.0f,
5234 0.0f,
5235 0.0f, 0.0f, 1.0f,
5237 spot =
5239 sizeof(D3DLIGHT2),
5240 D3DLIGHT_SPOT,
5241 {{1.0f}, {1.0f}, {1.0f}, {0.0f}},
5242 {{0.0f}, {0.0f}, {0.0f}},
5243 {{0.0f}, {0.0f}, {1.0f}},
5244 100.0f,
5245 1.0f,
5246 0.0f, 0.0f, 1.0f,
5247 M_PI / 12.0f, M_PI / 3.0f
5249 parallelpoint =
5251 sizeof(D3DLIGHT2),
5252 D3DLIGHT_PARALLELPOINT,
5253 {{1.0f}, {1.0f}, {1.0f}, {0.0f}},
5254 {{0.5f}, {0.0f}, {-1.0f}},
5255 {{0.0f}, {0.0f}, {0.0f}},
5257 point_side =
5259 sizeof(D3DLIGHT2),
5260 D3DLIGHT_POINT,
5261 {{1.0f}, {1.0f}, {1.0f}, {0.0f}},
5262 {{-1.1f}, {0.0f}, {1.1f}},
5263 {{0.0f}, {0.0f}, {0.0f}},
5264 100.0f,
5265 0.0f,
5266 1.0f, 0.0f, 0.0f,
5268 point_far =
5270 sizeof(D3DLIGHT2),
5271 D3DLIGHT_POINT,
5272 {{1.0f}, {1.0f}, {1.0f}, {0.0f}},
5273 {{0.0f}, {0.0f}, {0.1f}},
5274 {{0.0f}, {0.0f}, {0.0f}},
5275 1.0f,
5276 0.0f,
5277 1.0f, 0.0f, 0.0f,
5279 static const struct expected_color
5281 unsigned int x, y, color;
5283 expected_directional[] =
5285 {160, 120, 0x003c3c3c},
5286 {320, 120, 0x00717171},
5287 {480, 120, 0x003c3c3c},
5288 {160, 240, 0x00717171},
5289 {320, 240, 0x00ffffff},
5290 {480, 240, 0x00717171},
5291 {160, 360, 0x003c3c3c},
5292 {320, 360, 0x00717171},
5293 {480, 360, 0x003c3c3c},
5295 expected_point[] =
5297 {160, 120, 0x00000000},
5298 {320, 120, 0x00090909},
5299 {480, 120, 0x00000000},
5300 {160, 240, 0x00090909},
5301 {320, 240, 0x00fafafa},
5302 {480, 240, 0x00090909},
5303 {160, 360, 0x00000000},
5304 {320, 360, 0x00090909},
5305 {480, 360, 0x00000000},
5307 expected_spot[] =
5309 {160, 120, 0x00000000},
5310 {320, 120, 0x00020202},
5311 {480, 120, 0x00000000},
5312 {160, 240, 0x00020202},
5313 {320, 240, 0x00fafafa},
5314 {480, 240, 0x00020202},
5315 {160, 360, 0x00000000},
5316 {320, 360, 0x00020202},
5317 {480, 360, 0x00000000},
5319 expected_parallelpoint[] =
5321 {160, 120, 0x00050505},
5322 {320, 120, 0x002c2c2c},
5323 {480, 120, 0x006e6e6e},
5324 {160, 240, 0x00090909},
5325 {320, 240, 0x00717171},
5326 {480, 240, 0x00ffffff},
5327 {160, 360, 0x00050505},
5328 {320, 360, 0x002c2c2c},
5329 {480, 360, 0x006e6e6e},
5331 expected_point_far[] =
5333 {160, 120, 0x00000000},
5334 {320, 120, 0x00000000},
5335 {480, 120, 0x00000000},
5336 {160, 240, 0x00000000},
5337 {320, 240, 0x00ffffff},
5338 {480, 240, 0x00000000},
5339 {160, 360, 0x00000000},
5340 {320, 360, 0x00000000},
5341 {480, 360, 0x00000000},
5343 expected_zero[] =
5345 {160, 120, 0x00000000},
5346 {320, 120, 0x00000000},
5347 {480, 120, 0x00000000},
5348 {160, 240, 0x00000000},
5349 {320, 240, 0x00000000},
5350 {480, 240, 0x00000000},
5351 {160, 360, 0x00000000},
5352 {320, 360, 0x00000000},
5353 {480, 360, 0x00000000},
5355 static const struct
5357 D3DLIGHT2 *light;
5358 BOOL local_viewer;
5359 float specular_power;
5360 const struct expected_color *expected;
5361 unsigned int expected_count;
5363 tests[] =
5365 /* D3DRENDERSTATE_LOCALVIEWER does not exist in D3D < 7 (the behavior is
5366 * the one you get on newer D3D versions with it set as TRUE). */
5367 {&directional, FALSE, 30.0f, expected_directional, ARRAY_SIZE(expected_directional)},
5368 {&directional, TRUE, 30.0f, expected_directional, ARRAY_SIZE(expected_directional)},
5369 {&point, TRUE, 30.0f, expected_point, ARRAY_SIZE(expected_point)},
5370 {&spot, TRUE, 30.0f, expected_spot, ARRAY_SIZE(expected_spot)},
5371 {&parallelpoint, TRUE, 30.0f, expected_parallelpoint, ARRAY_SIZE(expected_parallelpoint)},
5372 {&point_side, TRUE, 0.0f, expected_zero, ARRAY_SIZE(expected_zero)},
5373 {&point_far, TRUE, 1.0f, expected_point_far, ARRAY_SIZE(expected_point_far)},
5374 {&directional, FALSE, 0.0f, expected_zero, ARRAY_SIZE(expected_zero)},
5375 {&directional, TRUE, 0.0f, expected_zero, ARRAY_SIZE(expected_zero)},
5376 {&point, TRUE, 0.0f, expected_zero, ARRAY_SIZE(expected_zero)},
5377 {&spot, TRUE, 0.0f, expected_zero, ARRAY_SIZE(expected_zero)},
5378 {&parallelpoint, TRUE, 0.0f, expected_zero, ARRAY_SIZE(expected_zero)},
5379 {&point_far, TRUE, 0.0f, expected_zero, ARRAY_SIZE(expected_zero)},
5382 IDirect3DLight *light, *dummy_lights[64];
5383 IDirect3DVertexBuffer *src_vb, *dst_vb;
5384 struct vertex *quad, *src_data;
5385 unsigned int color, i, j, x, y;
5386 D3DVERTEXBUFFERDESC vb_desc;
5387 D3DMATERIALHANDLE mat_handle;
5388 IDirect3DViewport3 *viewport;
5389 IDirect3DMaterial3 *material;
5390 IDirect3DDevice3 *device;
5391 IDirectDrawSurface4 *rt;
5392 D3DLIGHT2 light_desc;
5393 IDirect3D3 *d3d;
5394 ULONG refcount;
5395 HWND window;
5396 HRESULT hr;
5397 struct
5399 struct vec4 position;
5400 unsigned int diffuse, specular;
5401 } *dst_data;
5402 WORD *indices;
5404 window = create_window();
5405 if (!(device = create_device(window, DDSCL_NORMAL)))
5407 skip("Failed to create a 3D device, skipping test.\n");
5408 DestroyWindow(window);
5409 return;
5412 quad = malloc(vertices_side * vertices_side * sizeof(*quad));
5413 indices = malloc(indices_count * sizeof(*indices));
5414 for (i = 0, y = 0; y < vertices_side; ++y)
5416 for (x = 0; x < vertices_side; ++x)
5418 quad[i].position.x = x * 2.0f / (vertices_side - 1) - 1.0f;
5419 quad[i].position.y = y * 2.0f / (vertices_side - 1) - 1.0f;
5420 quad[i].position.z = 1.0f;
5421 quad[i].normal.x = 0.0f;
5422 quad[i].normal.y = 0.0f;
5423 quad[i++].normal.z = -1.0f;
5426 for (i = 0, y = 0; y < (vertices_side - 1); ++y)
5428 for (x = 0; x < (vertices_side - 1); ++x)
5430 indices[i++] = y * vertices_side + x + 1;
5431 indices[i++] = y * vertices_side + x;
5432 indices[i++] = (y + 1) * vertices_side + x;
5433 indices[i++] = y * vertices_side + x + 1;
5434 indices[i++] = (y + 1) * vertices_side + x;
5435 indices[i++] = (y + 1) * vertices_side + x + 1;
5439 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
5440 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5442 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
5443 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5445 viewport = create_viewport(device, 0, 0, 640, 480);
5446 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
5447 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5449 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &mat);
5450 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5451 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_VIEW, &mat);
5452 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5453 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &mat);
5454 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5455 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ZENABLE, FALSE);
5456 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5457 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, FALSE);
5458 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5460 memset(&light_desc, 0, sizeof(light_desc));
5461 light_desc.dwSize = sizeof(light_desc);
5462 light_desc.dltType = D3DLIGHT_DIRECTIONAL;
5463 light_desc.dwFlags = D3DLIGHT_ACTIVE;
5464 light_desc.dvDirection.z = 1.0f;
5466 for (i = 0; i < ARRAY_SIZE(dummy_lights); ++i)
5468 hr = IDirect3D3_CreateLight(d3d, &dummy_lights[i], NULL);
5469 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5470 hr = IDirect3DViewport3_AddLight(viewport, dummy_lights[i]);
5471 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5472 hr = IDirect3DLight_SetLight(dummy_lights[i], (D3DLIGHT *)&light_desc);
5473 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5476 hr = IDirect3D3_CreateLight(d3d, &light, NULL);
5477 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5478 hr = IDirect3DViewport3_AddLight(viewport, light);
5479 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5481 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_SPECULARENABLE, TRUE);
5482 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5484 memset(&vb_desc, 0, sizeof(vb_desc));
5485 vb_desc.dwSize = sizeof(vb_desc);
5486 vb_desc.dwFVF = fvf;
5487 vb_desc.dwNumVertices = ARRAY_SIZE(vertices);
5488 hr = IDirect3D3_CreateVertexBuffer(d3d, &vb_desc, &src_vb, 0, NULL);
5489 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5490 hr = IDirect3DVertexBuffer_Lock(src_vb, 0, (void **)&src_data, NULL);
5491 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5492 memcpy(src_data, vertices, sizeof(vertices));
5493 hr = IDirect3DVertexBuffer_Unlock(src_vb);
5494 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5496 memset(&vb_desc, 0, sizeof(vb_desc));
5497 vb_desc.dwSize = sizeof(vb_desc);
5498 vb_desc.dwFVF = D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR;
5499 vb_desc.dwNumVertices = ARRAY_SIZE(vertices);
5500 hr = IDirect3D3_CreateVertexBuffer(d3d, &vb_desc, &dst_vb, 0, NULL);
5501 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5503 for (i = 0; i < ARRAY_SIZE(tests); ++i)
5505 tests[i].light->dwFlags = D3DLIGHT_ACTIVE;
5506 hr = IDirect3DLight_SetLight(light, (D3DLIGHT *)tests[i].light);
5507 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5509 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_LOCALVIEWER, tests[i].local_viewer);
5510 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5512 material = create_specular_material(device, 1.0f, 1.0f, 1.0f, 0.5f, tests[i].specular_power);
5513 hr = IDirect3DMaterial3_GetHandle(material, device, &mat_handle);
5514 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5515 hr = IDirect3DDevice3_SetLightState(device, D3DLIGHTSTATE_MATERIAL, mat_handle);
5516 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5518 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xffffffff, 0.0f, 0);
5519 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5521 hr = IDirect3DDevice3_BeginScene(device);
5522 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5524 hr = IDirect3DVertexBuffer_Lock(dst_vb, 0, (void **)&dst_data, NULL);
5525 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5526 memset(dst_data, 0, sizeof(*dst_data) * ARRAY_SIZE(vertices));
5527 hr = IDirect3DVertexBuffer_Unlock(dst_vb);
5528 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5530 hr = IDirect3DVertexBuffer_ProcessVertices(dst_vb, D3DVOP_TRANSFORM | D3DVOP_LIGHT, 0,
5531 ARRAY_SIZE(vertices), src_vb, 0, device, 0);
5532 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5533 hr = IDirect3DDevice3_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, fvf, quad,
5534 vertices_side * vertices_side, indices, indices_count, 0);
5535 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5537 hr = IDirect3DDevice3_EndScene(device);
5538 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5540 hr = IDirect3DVertexBuffer_Lock(dst_vb, 0, (void **)&dst_data, NULL);
5541 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5543 for (j = 0; j < tests[i].expected_count; ++j)
5545 color = get_surface_color(rt, tests[i].expected[j].x, tests[i].expected[j].y);
5546 ok(compare_color(color, tests[i].expected[j].color, 1),
5547 "Expected color 0x%08x at location (%u, %u), got 0x%08x, case %u.\n",
5548 tests[i].expected[j].color, tests[i].expected[j].x,
5549 tests[i].expected[j].y, color, i);
5550 ok(!dst_data[j].diffuse, "Expected color 0x00000000 for vertex %u, got 0x%08x, case %u.\n",
5551 j, dst_data[j].diffuse, i);
5552 ok(compare_color(dst_data[j].specular, tests[i].expected[j].color, 1),
5553 "Expected color 0x%08x for vertex %u, got 0x%08x, case %u.\n",
5554 tests[i].expected[j].color, j, dst_data[j].specular, i);
5556 hr = IDirect3DVertexBuffer_Unlock(dst_vb);
5557 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5559 destroy_material(material);
5562 for (i = 0; i < ARRAY_SIZE(dummy_lights); ++i)
5563 IDirect3DLight_Release(dummy_lights[i]);
5565 IDirect3DVertexBuffer_Release(dst_vb);
5566 IDirect3DVertexBuffer_Release(src_vb);
5568 hr = IDirect3DViewport3_DeleteLight(viewport, light);
5569 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
5570 IDirect3DLight_Release(light);
5571 IDirect3DViewport3_Release(viewport);
5572 IDirectDrawSurface4_Release(rt);
5573 refcount = IDirect3DDevice3_Release(device);
5574 ok(!refcount, "Device has %lu references left.\n", refcount);
5575 IDirect3D3_Release(d3d);
5576 DestroyWindow(window);
5577 free(indices);
5578 free(quad);
5581 static void test_clear_rect_count(void)
5583 IDirectDrawSurface4 *rt;
5584 IDirect3DDevice3 *device;
5585 unsigned int color;
5586 HWND window;
5587 HRESULT hr;
5588 IDirect3DViewport3 *viewport;
5589 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
5591 window = create_window();
5592 if (!(device = create_device(window, DDSCL_NORMAL)))
5594 skip("Failed to create a 3D device, skipping test.\n");
5595 DestroyWindow(window);
5596 return;
5599 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
5600 ok(SUCCEEDED(hr), "Failed to get render target, hr %#lx.\n", hr);
5602 viewport = create_viewport(device, 0, 0, 640, 480);
5603 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
5604 ok(SUCCEEDED(hr), "Failed to activate the viewport, hr %#lx.\n", hr);
5605 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0x00ffffff, 0.0f, 0);
5606 ok(SUCCEEDED(hr), "Failed to clear the viewport, hr %#lx.\n", hr);
5607 hr = IDirect3DViewport3_Clear2(viewport, 0, &clear_rect, D3DCLEAR_TARGET, 0x00ff0000, 0.0f, 0);
5608 ok(SUCCEEDED(hr), "Failed to clear the viewport, hr %#lx.\n", hr);
5609 hr = IDirect3DViewport3_Clear2(viewport, 0, NULL, D3DCLEAR_TARGET, 0x0000ff00, 0.0f, 0);
5610 ok(SUCCEEDED(hr), "Failed to clear the viewport, hr %#lx.\n", hr);
5611 hr = IDirect3DViewport3_Clear2(viewport, 1, NULL, D3DCLEAR_TARGET, 0x000000ff, 0.0f, 0);
5612 ok(SUCCEEDED(hr), "Failed to clear the viewport, hr %#lx.\n", hr);
5614 color = get_surface_color(rt, 320, 240);
5615 ok(compare_color(color, 0x00ffffff, 1) || broken(compare_color(color, 0x000000ff, 1)),
5616 "Got unexpected color 0x%08x.\n", color);
5618 IDirect3DViewport3_Release(viewport);
5619 IDirectDrawSurface4_Release(rt);
5620 IDirect3DDevice3_Release(device);
5621 DestroyWindow(window);
5624 static BOOL test_mode_restored(IDirectDraw4 *ddraw, HWND window)
5626 DDSURFACEDESC2 ddsd1, ddsd2;
5627 HRESULT hr;
5629 memset(&ddsd1, 0, sizeof(ddsd1));
5630 ddsd1.dwSize = sizeof(ddsd1);
5631 hr = IDirectDraw4_GetDisplayMode(ddraw, &ddsd1);
5632 ok(SUCCEEDED(hr), "GetDisplayMode failed, hr %#lx.\n", hr);
5634 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
5635 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#lx.\n", hr);
5636 hr = set_display_mode(ddraw, 640, 480);
5637 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#lx.\n", hr);
5638 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
5639 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#lx.\n", hr);
5641 memset(&ddsd2, 0, sizeof(ddsd2));
5642 ddsd2.dwSize = sizeof(ddsd2);
5643 hr = IDirectDraw4_GetDisplayMode(ddraw, &ddsd2);
5644 ok(SUCCEEDED(hr), "GetDisplayMode failed, hr %#lx.\n", hr);
5645 hr = IDirectDraw4_RestoreDisplayMode(ddraw);
5646 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#lx.\n", hr);
5648 return ddsd1.dwWidth == ddsd2.dwWidth && ddsd1.dwHeight == ddsd2.dwHeight;
5651 static void test_coop_level_versions(void)
5653 HWND window;
5654 IDirectDraw *ddraw;
5655 HRESULT hr;
5656 BOOL restored;
5657 IDirectDrawSurface *surface;
5658 IDirectDraw4 *ddraw4;
5659 DDSURFACEDESC ddsd;
5661 window = create_window();
5662 ddraw4 = create_ddraw();
5663 ok(!!ddraw4, "Failed to create a ddraw object.\n");
5664 /* Newly created ddraw objects restore the mode on ddraw2+::SetCooperativeLevel(NORMAL) */
5665 restored = test_mode_restored(ddraw4, window);
5666 ok(restored, "Display mode not restored in new ddraw object\n");
5668 /* A failing ddraw1::SetCooperativeLevel call does not have an effect */
5669 hr = IDirectDraw4_QueryInterface(ddraw4, &IID_IDirectDraw, (void **)&ddraw);
5670 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#lx.\n", hr);
5672 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
5673 ok(FAILED(hr), "SetCooperativeLevel returned %#lx, expected failure.\n", hr);
5674 restored = test_mode_restored(ddraw4, window);
5675 ok(restored, "Display mode not restored after bad ddraw1::SetCooperativeLevel call\n");
5677 /* A successful one does */
5678 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
5679 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#lx.\n", hr);
5680 restored = test_mode_restored(ddraw4, window);
5681 ok(!restored, "Display mode restored after good ddraw1::SetCooperativeLevel call\n");
5683 IDirectDraw_Release(ddraw);
5684 IDirectDraw4_Release(ddraw4);
5686 ddraw4 = create_ddraw();
5687 ok(!!ddraw4, "Failed to create a ddraw object.\n");
5688 hr = IDirectDraw4_QueryInterface(ddraw4, &IID_IDirectDraw, (void **)&ddraw);
5689 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#lx.\n", hr);
5691 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_SETFOCUSWINDOW);
5692 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#lx.\n", hr);
5693 restored = test_mode_restored(ddraw4, window);
5694 ok(!restored, "Display mode restored after ddraw1::SetCooperativeLevel(SETFOCUSWINDOW) call\n");
5696 IDirectDraw_Release(ddraw);
5697 IDirectDraw4_Release(ddraw4);
5699 /* A failing call does not restore the ddraw2+ behavior */
5700 ddraw4 = create_ddraw();
5701 ok(!!ddraw4, "Failed to create a ddraw object.\n");
5702 hr = IDirectDraw4_QueryInterface(ddraw4, &IID_IDirectDraw, (void **)&ddraw);
5703 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#lx.\n", hr);
5705 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
5706 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#lx.\n", hr);
5707 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
5708 ok(FAILED(hr), "SetCooperativeLevel returned %#lx, expected failure.\n", hr);
5709 restored = test_mode_restored(ddraw4, window);
5710 ok(!restored, "Display mode restored after good-bad ddraw1::SetCooperativeLevel() call sequence\n");
5712 IDirectDraw_Release(ddraw);
5713 IDirectDraw4_Release(ddraw4);
5715 /* Neither does a sequence of successful calls with the new interface */
5716 ddraw4 = create_ddraw();
5717 ok(!!ddraw4, "Failed to create a ddraw object.\n");
5718 hr = IDirectDraw4_QueryInterface(ddraw4, &IID_IDirectDraw, (void **)&ddraw);
5719 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#lx.\n", hr);
5721 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
5722 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#lx.\n", hr);
5723 hr = IDirectDraw4_SetCooperativeLevel(ddraw4, window, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
5724 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#lx.\n", hr);
5725 hr = IDirectDraw4_SetCooperativeLevel(ddraw4, window, DDSCL_NORMAL);
5726 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#lx.\n", hr);
5728 restored = test_mode_restored(ddraw4, window);
5729 ok(!restored, "Display mode restored after ddraw1-ddraw4 SetCooperativeLevel() call sequence\n");
5730 IDirectDraw_Release(ddraw);
5731 IDirectDraw4_Release(ddraw4);
5733 /* ddraw1::CreateSurface does not triger the ddraw1 behavior */
5734 ddraw4 = create_ddraw();
5735 ok(!!ddraw4, "Failed to create a ddraw object.\n");
5736 hr = IDirectDraw4_QueryInterface(ddraw4, &IID_IDirectDraw, (void **)&ddraw);
5737 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#lx.\n", hr);
5739 hr = IDirectDraw4_SetCooperativeLevel(ddraw4, window, DDSCL_NORMAL);
5740 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#lx.\n", hr);
5742 memset(&ddsd, 0, sizeof(ddsd));
5743 ddsd.dwSize = sizeof(ddsd);
5744 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
5745 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
5746 ddsd.dwWidth = ddsd.dwHeight = 8;
5747 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &surface, NULL);
5748 ok(SUCCEEDED(hr), "CreateSurface failed, hr %#lx.\n", hr);
5749 IDirectDrawSurface_Release(surface);
5750 restored = test_mode_restored(ddraw4, window);
5751 ok(restored, "Display mode not restored after ddraw1::CreateSurface() call\n");
5753 IDirectDraw_Release(ddraw);
5754 IDirectDraw4_Release(ddraw4);
5755 DestroyWindow(window);
5758 static void test_lighting_interface_versions(void)
5760 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
5761 IDirect3DMaterial3 *emissive;
5762 IDirect3DViewport3 *viewport;
5763 IDirect3DDevice3 *device;
5764 IDirectDrawSurface4 *rt;
5765 unsigned int color, i;
5766 HWND window;
5767 HRESULT hr;
5768 D3DMATERIALHANDLE mat_handle;
5769 DWORD rs;
5770 ULONG ref;
5771 static D3DVERTEX quad[] =
5773 {{-1.0f}, { 1.0f}, {0.0f}, {1.0f}, {0.0f}, {0.0f}},
5774 {{ 1.0f}, { 1.0f}, {0.0f}, {1.0f}, {0.0f}, {0.0f}},
5775 {{-1.0f}, {-1.0f}, {0.0f}, {1.0f}, {0.0f}, {0.0f}},
5776 {{ 1.0f}, {-1.0f}, {0.0f}, {1.0f}, {0.0f}, {0.0f}},
5779 #define FVF_COLORVERTEX (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE | D3DFVF_SPECULAR)
5780 static struct
5782 struct vec3 position;
5783 struct vec3 normal;
5784 DWORD diffuse, specular;
5786 quad2[] =
5788 {{-1.0f, 1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000, 0xff808080},
5789 {{ 1.0f, 1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000, 0xff808080},
5790 {{-1.0f, -1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000, 0xff808080},
5791 {{ 1.0f, -1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000, 0xff808080},
5794 static D3DLVERTEX lquad[] =
5796 {{-1.0f}, { 1.0f}, {0.0f}, 0, {0xffff0000}, {0xff808080}},
5797 {{ 1.0f}, { 1.0f}, {0.0f}, 0, {0xffff0000}, {0xff808080}},
5798 {{-1.0f}, {-1.0f}, {0.0f}, 0, {0xffff0000}, {0xff808080}},
5799 {{ 1.0f}, {-1.0f}, {0.0f}, 0, {0xffff0000}, {0xff808080}},
5802 #define FVF_LVERTEX2 (D3DFVF_LVERTEX & ~D3DFVF_RESERVED1)
5803 static struct
5805 struct vec3 position;
5806 DWORD diffuse, specular;
5807 struct vec2 texcoord;
5809 lquad2[] =
5811 {{-1.0f, 1.0f, 0.0f}, 0xffff0000, 0xff808080},
5812 {{ 1.0f, 1.0f, 0.0f}, 0xffff0000, 0xff808080},
5813 {{-1.0f, -1.0f, 0.0f}, 0xffff0000, 0xff808080},
5814 {{ 1.0f, -1.0f, 0.0f}, 0xffff0000, 0xff808080},
5817 static D3DTLVERTEX tlquad[] =
5819 {{ 0.0f}, { 480.0f}, {0.0f}, {1.0f}, {0xff0000ff}, {0xff808080}},
5820 {{ 0.0f}, { 0.0f}, {0.0f}, {1.0f}, {0xff0000ff}, {0xff808080}},
5821 {{ 640.0f}, { 480.0f}, {0.0f}, {1.0f}, {0xff0000ff}, {0xff808080}},
5822 {{ 640.0f}, { 0.0f}, {0.0f}, {1.0f}, {0xff0000ff}, {0xff808080}},
5825 static const struct
5827 DWORD vertextype;
5828 void *data;
5829 DWORD d3drs_lighting, d3drs_specular;
5830 DWORD draw_flags;
5831 unsigned int color;
5833 tests[] =
5835 /* Lighting is enabled when all of these conditions are met:
5836 * 1) No pretransformed position(D3DFVF_XYZRHW)
5837 * 2) Normals are available (D3DFVF_NORMAL)
5838 * 3) D3DDP_DONOTLIGHT is not set.
5840 * D3DRENDERSTATE_LIGHTING is ignored, it is not defined
5841 * in this d3d version */
5843 /* 0 */
5844 { D3DFVF_VERTEX, quad, FALSE, FALSE, 0, 0x0000ff00},
5845 { D3DFVF_VERTEX, quad, TRUE, FALSE, 0, 0x0000ff00},
5846 { D3DFVF_VERTEX, quad, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x00ffffff},
5847 { D3DFVF_VERTEX, quad, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x00ffffff},
5848 { D3DFVF_VERTEX, quad, FALSE, TRUE, 0, 0x0000ff00},
5849 { D3DFVF_VERTEX, quad, TRUE, TRUE, 0, 0x0000ff00},
5850 { D3DFVF_VERTEX, quad, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x00ffffff},
5851 { D3DFVF_VERTEX, quad, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x00ffffff},
5853 /* 8 */
5854 { FVF_COLORVERTEX, quad2, FALSE, FALSE, 0, 0x0000ff00},
5855 { FVF_COLORVERTEX, quad2, TRUE, FALSE, 0, 0x0000ff00},
5856 { FVF_COLORVERTEX, quad2, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x00ff0000},
5857 { FVF_COLORVERTEX, quad2, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x00ff0000},
5858 /* The specular color in the vertex is ignored because
5859 * D3DRENDERSTATE_COLORVERTEX is not enabled */
5860 { FVF_COLORVERTEX, quad2, FALSE, TRUE, 0, 0x0000ff00},
5861 { FVF_COLORVERTEX, quad2, TRUE, TRUE, 0, 0x0000ff00},
5862 { FVF_COLORVERTEX, quad2, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x00ff8080},
5863 { FVF_COLORVERTEX, quad2, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x00ff8080},
5865 /* 16 */
5866 { D3DFVF_LVERTEX, lquad, FALSE, FALSE, 0, 0x00ff0000},
5867 { D3DFVF_LVERTEX, lquad, TRUE, FALSE, 0, 0x00ff0000},
5868 { D3DFVF_LVERTEX, lquad, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x00ff0000},
5869 { D3DFVF_LVERTEX, lquad, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x00ff0000},
5870 { D3DFVF_LVERTEX, lquad, FALSE, TRUE, 0, 0x00ff8080},
5871 { D3DFVF_LVERTEX, lquad, TRUE, TRUE, 0, 0x00ff8080},
5872 { D3DFVF_LVERTEX, lquad, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x00ff8080},
5873 { D3DFVF_LVERTEX, lquad, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x00ff8080},
5875 /* 24 */
5876 { FVF_LVERTEX2, lquad2, FALSE, FALSE, 0, 0x00ff0000},
5877 { FVF_LVERTEX2, lquad2, TRUE, FALSE, 0, 0x00ff0000},
5878 { FVF_LVERTEX2, lquad2, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x00ff0000},
5879 { FVF_LVERTEX2, lquad2, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x00ff0000},
5880 { FVF_LVERTEX2, lquad2, FALSE, TRUE, 0, 0x00ff8080},
5881 { FVF_LVERTEX2, lquad2, TRUE, TRUE, 0, 0x00ff8080},
5882 { FVF_LVERTEX2, lquad2, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x00ff8080},
5883 { FVF_LVERTEX2, lquad2, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x00ff8080},
5885 /* 32 */
5886 { D3DFVF_TLVERTEX, tlquad, FALSE, FALSE, 0, 0x000000ff},
5887 { D3DFVF_TLVERTEX, tlquad, TRUE, FALSE, 0, 0x000000ff},
5888 { D3DFVF_TLVERTEX, tlquad, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x000000ff},
5889 { D3DFVF_TLVERTEX, tlquad, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x000000ff},
5890 { D3DFVF_TLVERTEX, tlquad, FALSE, TRUE, 0, 0x008080ff},
5891 { D3DFVF_TLVERTEX, tlquad, TRUE, TRUE, 0, 0x008080ff},
5892 { D3DFVF_TLVERTEX, tlquad, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x008080ff},
5893 { D3DFVF_TLVERTEX, tlquad, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x008080ff},
5896 window = create_window();
5897 if (!(device = create_device(window, DDSCL_NORMAL)))
5899 skip("Failed to create a 3D device, skipping test.\n");
5900 DestroyWindow(window);
5901 return;
5904 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
5905 ok(SUCCEEDED(hr), "Failed to get render target, hr %#lx.\n", hr);
5907 viewport = create_viewport(device, 0, 0, 640, 480);
5908 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
5909 ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#lx.\n", hr);
5911 emissive = create_emissive_material(device, 0.0f, 1.0f, 0.0f, 0.0f);
5912 hr = IDirect3DMaterial3_GetHandle(emissive, device, &mat_handle);
5913 ok(SUCCEEDED(hr), "Failed to get material handle, hr %#lx.\n", hr);
5914 hr = IDirect3DDevice3_SetLightState(device, D3DLIGHTSTATE_MATERIAL, mat_handle);
5915 ok(SUCCEEDED(hr), "Failed to set material state, hr %#lx.\n", hr);
5916 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
5917 ok(SUCCEEDED(hr), "Failed to disable z test, hr %#lx.\n", hr);
5919 hr = IDirect3DDevice3_GetRenderState(device, D3DRENDERSTATE_SPECULARENABLE, &rs);
5920 ok(SUCCEEDED(hr), "Failed to get specularenable render state, hr %#lx.\n", hr);
5921 ok(rs == FALSE, "Initial D3DRENDERSTATE_SPECULARENABLE is %#lx, expected FALSE.\n", rs);
5923 for (i = 0; i < ARRAY_SIZE(tests); i++)
5925 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xff202020, 0.0f, 0);
5926 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#lx.\n", hr);
5928 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_LIGHTING, tests[i].d3drs_lighting);
5929 ok(SUCCEEDED(hr), "Failed to set lighting render state, hr %#lx.\n", hr);
5930 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_SPECULARENABLE,
5931 tests[i].d3drs_specular);
5932 ok(SUCCEEDED(hr), "Failed to set specularenable render state, hr %#lx.\n", hr);
5934 hr = IDirect3DDevice3_BeginScene(device);
5935 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#lx.\n", hr);
5936 hr = IDirect3DDevice2_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
5937 tests[i].vertextype, tests[i].data, 4, tests[i].draw_flags | D3DDP_WAIT);
5938 ok(SUCCEEDED(hr), "Failed to draw, hr %#lx.\n", hr);
5939 hr = IDirect3DDevice3_EndScene(device);
5940 ok(SUCCEEDED(hr), "Failed to end scene, hr %#lx.\n", hr);
5942 color = get_surface_color(rt, 320, 240);
5943 ok(compare_color(color, tests[i].color, 1),
5944 "Got unexpected color 0x%08x, expected 0x%08x, test %u.\n",
5945 color, tests[i].color, i);
5948 destroy_material(emissive);
5949 destroy_viewport(device, viewport);
5950 IDirectDrawSurface4_Release(rt);
5951 ref = IDirect3DDevice3_Release(device);
5952 ok(!ref, "Unexpected refcount %lu.\n", ref);
5953 DestroyWindow(window);
5956 static struct
5958 BOOL received;
5959 IDirectDraw4 *ddraw;
5960 HWND window;
5961 DWORD coop_level;
5962 } activateapp_testdata;
5964 static LRESULT CALLBACK activateapp_test_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
5966 if (message == WM_ACTIVATEAPP)
5968 if (activateapp_testdata.ddraw)
5970 HRESULT hr;
5971 activateapp_testdata.received = FALSE;
5972 hr = IDirectDraw4_SetCooperativeLevel(activateapp_testdata.ddraw,
5973 activateapp_testdata.window, activateapp_testdata.coop_level);
5974 ok(SUCCEEDED(hr), "Recursive SetCooperativeLevel call failed, hr %#lx.\n", hr);
5975 ok(!activateapp_testdata.received, "Received WM_ACTIVATEAPP during recursive SetCooperativeLevel call.\n");
5977 activateapp_testdata.received = TRUE;
5980 return DefWindowProcA(hwnd, message, wparam, lparam);
5983 static void test_coop_level_activateapp(void)
5985 IDirectDraw4 *ddraw;
5986 HRESULT hr;
5987 HWND window;
5988 WNDCLASSA wc = {0};
5989 DDSURFACEDESC2 ddsd;
5990 IDirectDrawSurface4 *surface;
5992 ddraw = create_ddraw();
5993 ok(!!ddraw, "Failed to create a ddraw object.\n");
5995 wc.lpfnWndProc = activateapp_test_proc;
5996 wc.lpszClassName = "ddraw_test_wndproc_wc";
5997 ok(RegisterClassA(&wc), "Failed to register window class.\n");
5999 window = CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
6000 WS_MAXIMIZE | WS_CAPTION , 0, 0, 640, 480, 0, 0, 0, 0);
6002 /* Exclusive with window already active. */
6003 SetForegroundWindow(window);
6004 activateapp_testdata.received = FALSE;
6005 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
6006 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
6007 ok(!activateapp_testdata.received, "Received WM_ACTIVATEAPP although window was already active.\n");
6008 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
6009 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
6011 /* Exclusive with window not active. */
6012 SetForegroundWindow(GetDesktopWindow());
6013 activateapp_testdata.received = FALSE;
6014 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
6015 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
6016 ok(activateapp_testdata.received, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
6017 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
6018 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
6020 /* Normal with window not active, then exclusive with the same window. */
6021 SetForegroundWindow(GetDesktopWindow());
6022 activateapp_testdata.received = FALSE;
6023 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6024 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
6025 ok(!activateapp_testdata.received, "Received WM_ACTIVATEAPP when setting DDSCL_NORMAL.\n");
6026 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
6027 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
6028 ok(activateapp_testdata.received, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
6029 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
6030 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
6032 /* Recursive set of DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN. */
6033 SetForegroundWindow(GetDesktopWindow());
6034 activateapp_testdata.received = FALSE;
6035 activateapp_testdata.ddraw = ddraw;
6036 activateapp_testdata.window = window;
6037 activateapp_testdata.coop_level = DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN;
6038 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
6039 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
6040 ok(activateapp_testdata.received, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
6041 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
6042 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
6044 /* The recursive call seems to have some bad effect on native ddraw, despite (apparently)
6045 * succeeding. Another switch to exclusive and back to normal is needed to release the
6046 * window properly. Without doing this, SetCooperativeLevel(EXCLUSIVE) will not send
6047 * WM_ACTIVATEAPP messages. */
6048 activateapp_testdata.ddraw = NULL;
6049 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
6050 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
6051 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
6052 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
6054 /* Setting DDSCL_NORMAL with recursive invocation. */
6055 SetForegroundWindow(GetDesktopWindow());
6056 activateapp_testdata.received = FALSE;
6057 activateapp_testdata.ddraw = ddraw;
6058 activateapp_testdata.window = window;
6059 activateapp_testdata.coop_level = DDSCL_NORMAL;
6060 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
6061 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
6062 ok(activateapp_testdata.received, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
6064 /* DDraw is in exclusive mode now. */
6065 memset(&ddsd, 0, sizeof(ddsd));
6066 ddsd.dwSize = sizeof(ddsd);
6067 ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
6068 ddsd.dwBackBufferCount = 1;
6069 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
6070 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
6071 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
6072 IDirectDrawSurface4_Release(surface);
6074 /* Recover again, just to be sure. */
6075 activateapp_testdata.ddraw = NULL;
6076 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
6077 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
6078 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
6079 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
6081 DestroyWindow(window);
6082 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL));
6083 IDirectDraw4_Release(ddraw);
6086 static void test_texturemanage(void)
6088 IDirectDraw4 *ddraw;
6089 HRESULT hr;
6090 DDSURFACEDESC2 ddsd;
6091 IDirectDrawSurface4 *surface;
6092 unsigned int i;
6093 DDCAPS hal_caps, hel_caps;
6094 DWORD needed_caps = DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY;
6095 static const struct
6097 DWORD caps_in, caps2_in;
6098 HRESULT hr;
6099 DWORD caps_out, caps2_out;
6101 tests[] =
6103 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
6104 ~0U, ~0U},
6105 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, DDERR_INVALIDCAPS,
6106 ~0U, ~0U},
6107 {DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
6108 ~0U, ~0U},
6109 {DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, DDERR_INVALIDCAPS,
6110 ~0U, ~0U},
6111 {DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, DD_OK,
6112 DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE},
6113 {DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, DD_OK,
6114 DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE},
6115 {DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE, 0, DD_OK,
6116 DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE | DDSCAPS_LOCALVIDMEM, 0},
6117 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, 0, DD_OK,
6118 DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, 0},
6120 {0, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
6121 ~0U, ~0U},
6122 {0, DDSCAPS2_D3DTEXTUREMANAGE, DDERR_INVALIDCAPS,
6123 ~0U, ~0U},
6124 {DDSCAPS_SYSTEMMEMORY, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
6125 ~0U, ~0U},
6126 {DDSCAPS_SYSTEMMEMORY, DDSCAPS2_D3DTEXTUREMANAGE, DDERR_INVALIDCAPS,
6127 ~0U, ~0U},
6128 {DDSCAPS_VIDEOMEMORY, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
6129 ~0U, ~0U},
6130 {DDSCAPS_VIDEOMEMORY, DDSCAPS2_D3DTEXTUREMANAGE, DDERR_INVALIDCAPS,
6131 ~0U, ~0U},
6132 {DDSCAPS_VIDEOMEMORY, 0, DD_OK,
6133 DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY, 0},
6134 {DDSCAPS_SYSTEMMEMORY, 0, DD_OK,
6135 DDSCAPS_SYSTEMMEMORY, 0},
6138 ddraw = create_ddraw();
6139 ok(!!ddraw, "Failed to create a ddraw object.\n");
6140 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
6141 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
6143 memset(&hal_caps, 0, sizeof(hal_caps));
6144 hal_caps.dwSize = sizeof(hal_caps);
6145 memset(&hel_caps, 0, sizeof(hel_caps));
6146 hel_caps.dwSize = sizeof(hel_caps);
6147 hr = IDirectDraw4_GetCaps(ddraw, &hal_caps, &hel_caps);
6148 ok(SUCCEEDED(hr), "Failed to get caps, hr %#lx.\n", hr);
6149 if ((hal_caps.ddsCaps.dwCaps & needed_caps) != needed_caps)
6151 skip("Managed textures not supported, skipping managed texture test.\n");
6152 IDirectDraw4_Release(ddraw);
6153 return;
6156 for (i = 0; i < ARRAY_SIZE(tests); i++)
6158 memset(&ddsd, 0, sizeof(ddsd));
6159 ddsd.dwSize = sizeof(ddsd);
6160 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
6161 ddsd.ddsCaps.dwCaps = tests[i].caps_in;
6162 ddsd.ddsCaps.dwCaps2 = tests[i].caps2_in;
6163 ddsd.dwWidth = 4;
6164 ddsd.dwHeight = 4;
6166 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
6167 ok(hr == tests[i].hr, "Got unexpected, hr %#lx, case %u.\n", hr, i);
6168 if (FAILED(hr))
6169 continue;
6171 memset(&ddsd, 0, sizeof(ddsd));
6172 ddsd.dwSize = sizeof(ddsd);
6173 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &ddsd);
6174 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#lx.\n", hr);
6176 ok(ddsd.ddsCaps.dwCaps == tests[i].caps_out,
6177 "Input caps %#lx, %#lx, expected output caps %#lx, got %#lx, case %u.\n",
6178 tests[i].caps_in, tests[i].caps2_in, tests[i].caps_out, ddsd.ddsCaps.dwCaps, i);
6179 ok(ddsd.ddsCaps.dwCaps2 == tests[i].caps2_out,
6180 "Input caps %#lx, %#lx, expected output caps %#lx, got %#lx, case %u.\n",
6181 tests[i].caps_in, tests[i].caps2_in, tests[i].caps2_out, ddsd.ddsCaps.dwCaps2, i);
6183 IDirectDrawSurface4_Release(surface);
6186 IDirectDraw4_Release(ddraw);
6189 #define SUPPORT_DXT1 0x01
6190 #define SUPPORT_DXT2 0x02
6191 #define SUPPORT_DXT3 0x04
6192 #define SUPPORT_DXT4 0x08
6193 #define SUPPORT_DXT5 0x10
6194 #define SUPPORT_YUY2 0x20
6195 #define SUPPORT_UYVY 0x40
6197 static HRESULT WINAPI test_block_formats_creation_cb(DDPIXELFORMAT *fmt, void *ctx)
6199 DWORD *supported_fmts = ctx;
6201 if (!(fmt->dwFlags & DDPF_FOURCC))
6202 return DDENUMRET_OK;
6204 switch (fmt->dwFourCC)
6206 case MAKEFOURCC('D','X','T','1'):
6207 *supported_fmts |= SUPPORT_DXT1;
6208 break;
6209 case MAKEFOURCC('D','X','T','2'):
6210 *supported_fmts |= SUPPORT_DXT2;
6211 break;
6212 case MAKEFOURCC('D','X','T','3'):
6213 *supported_fmts |= SUPPORT_DXT3;
6214 break;
6215 case MAKEFOURCC('D','X','T','4'):
6216 *supported_fmts |= SUPPORT_DXT4;
6217 break;
6218 case MAKEFOURCC('D','X','T','5'):
6219 *supported_fmts |= SUPPORT_DXT5;
6220 break;
6221 case MAKEFOURCC('Y','U','Y','2'):
6222 *supported_fmts |= SUPPORT_YUY2;
6223 break;
6224 case MAKEFOURCC('U','Y','V','Y'):
6225 *supported_fmts |= SUPPORT_UYVY;
6226 break;
6227 default:
6228 break;
6231 return DDENUMRET_OK;
6234 static void test_block_formats_creation(void)
6236 HRESULT hr, expect_hr;
6237 unsigned int i, j, w, h;
6238 HWND window;
6239 IDirectDraw4 *ddraw;
6240 IDirect3D3 *d3d;
6241 IDirect3DDevice3 *device;
6242 IDirectDrawSurface4 *surface;
6243 DWORD supported_fmts = 0, supported_overlay_fmts = 0;
6244 DWORD num_fourcc_codes = 0, *fourcc_codes;
6245 DDSURFACEDESC2 ddsd;
6246 DDCAPS hal_caps;
6247 void *mem;
6249 static const struct
6251 DWORD fourcc;
6252 const char *name;
6253 DWORD support_flag;
6254 unsigned int block_width;
6255 unsigned int block_height;
6256 unsigned int block_size;
6257 BOOL create_size_checked, overlay;
6259 formats[] =
6261 {MAKEFOURCC('D','X','T','1'), "D3DFMT_DXT1", SUPPORT_DXT1, 4, 4, 8, TRUE, FALSE},
6262 {MAKEFOURCC('D','X','T','2'), "D3DFMT_DXT2", SUPPORT_DXT2, 4, 4, 16, TRUE, FALSE},
6263 {MAKEFOURCC('D','X','T','3'), "D3DFMT_DXT3", SUPPORT_DXT3, 4, 4, 16, TRUE, FALSE},
6264 {MAKEFOURCC('D','X','T','4'), "D3DFMT_DXT4", SUPPORT_DXT4, 4, 4, 16, TRUE, FALSE},
6265 {MAKEFOURCC('D','X','T','5'), "D3DFMT_DXT5", SUPPORT_DXT5, 4, 4, 16, TRUE, FALSE},
6266 {MAKEFOURCC('Y','U','Y','2'), "D3DFMT_YUY2", SUPPORT_YUY2, 2, 1, 4, FALSE, TRUE },
6267 {MAKEFOURCC('U','Y','V','Y'), "D3DFMT_UYVY", SUPPORT_UYVY, 2, 1, 4, FALSE, TRUE },
6269 static const struct
6271 DWORD caps, caps2;
6272 const char *name;
6273 BOOL overlay;
6275 types[] =
6277 /* DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY fails to create any fourcc
6278 * surface with DDERR_INVALIDPIXELFORMAT. Don't care about it for now.
6280 * Nvidia returns E_FAIL on DXTN DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY.
6281 * Other hw / drivers successfully create those surfaces. Ignore them, this
6282 * suggests that no game uses this, otherwise Nvidia would support it. */
6284 DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE, 0,
6285 "videomemory texture", FALSE
6288 DDSCAPS_VIDEOMEMORY | DDSCAPS_OVERLAY, 0,
6289 "videomemory overlay", TRUE
6292 DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, 0,
6293 "systemmemory texture", FALSE
6296 DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE,
6297 "managed texture", FALSE
6300 enum size_type
6302 SIZE_TYPE_ZERO,
6303 SIZE_TYPE_PITCH,
6304 SIZE_TYPE_SIZE,
6306 static const struct
6308 DWORD flags;
6309 enum size_type size_type;
6310 int rel_size;
6311 HRESULT hr;
6313 user_mem_tests[] =
6315 {DDSD_LINEARSIZE, SIZE_TYPE_ZERO, 0, DD_OK},
6316 {DDSD_LINEARSIZE, SIZE_TYPE_SIZE, 0, DD_OK},
6317 {DDSD_PITCH, SIZE_TYPE_ZERO, 0, DD_OK},
6318 {DDSD_PITCH, SIZE_TYPE_PITCH, 0, DD_OK},
6319 {DDSD_LPSURFACE, SIZE_TYPE_ZERO, 0, DDERR_INVALIDPARAMS},
6320 {DDSD_LPSURFACE | DDSD_LINEARSIZE, SIZE_TYPE_ZERO, 0, DDERR_INVALIDPARAMS},
6321 {DDSD_LPSURFACE | DDSD_LINEARSIZE, SIZE_TYPE_PITCH, 0, DDERR_INVALIDPARAMS},
6322 {DDSD_LPSURFACE | DDSD_LINEARSIZE, SIZE_TYPE_SIZE, 0, DD_OK},
6323 {DDSD_LPSURFACE | DDSD_LINEARSIZE, SIZE_TYPE_SIZE, 1, DD_OK},
6324 {DDSD_LPSURFACE | DDSD_LINEARSIZE, SIZE_TYPE_SIZE, -1, DDERR_INVALIDPARAMS},
6325 {DDSD_LPSURFACE | DDSD_PITCH, SIZE_TYPE_ZERO, 0, DD_OK},
6326 {DDSD_LPSURFACE | DDSD_PITCH, SIZE_TYPE_PITCH, 0, DD_OK},
6327 {DDSD_LPSURFACE | DDSD_PITCH, SIZE_TYPE_SIZE, 0, DD_OK},
6328 {DDSD_LPSURFACE | DDSD_PITCH | DDSD_LINEARSIZE, SIZE_TYPE_SIZE, 0, DD_OK},
6331 window = create_window();
6332 if (!(device = create_device(window, DDSCL_NORMAL)))
6334 skip("Failed to create a 3D device, skipping test.\n");
6335 DestroyWindow(window);
6336 return;
6339 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
6340 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#lx.\n", hr);
6341 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **) &ddraw);
6342 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#lx.\n", hr);
6343 IDirect3D3_Release(d3d);
6345 hr = IDirect3DDevice3_EnumTextureFormats(device, test_block_formats_creation_cb,
6346 &supported_fmts);
6347 ok(SUCCEEDED(hr), "Got hr %#lx.\n", hr);
6349 hr = IDirectDraw4_GetFourCCCodes(ddraw, &num_fourcc_codes, NULL);
6350 ok(SUCCEEDED(hr), "Got hr %#lx.\n", hr);
6351 fourcc_codes = calloc(num_fourcc_codes, sizeof(*fourcc_codes));
6352 if (!fourcc_codes)
6353 goto cleanup;
6354 hr = IDirectDraw4_GetFourCCCodes(ddraw, &num_fourcc_codes, fourcc_codes);
6355 ok(SUCCEEDED(hr), "Got hr %#lx.\n", hr);
6356 for (i = 0; i < num_fourcc_codes; i++)
6358 for (j = 0; j < ARRAY_SIZE(formats); j++)
6360 if (fourcc_codes[i] == formats[j].fourcc)
6361 supported_overlay_fmts |= formats[j].support_flag;
6364 free(fourcc_codes);
6366 memset(&hal_caps, 0, sizeof(hal_caps));
6367 hal_caps.dwSize = sizeof(hal_caps);
6368 hr = IDirectDraw4_GetCaps(ddraw, &hal_caps, NULL);
6369 ok(SUCCEEDED(hr), "Failed to get caps, hr %#lx.\n", hr);
6371 mem = calloc(1, 2 * 2 * 16 + 1);
6373 for (i = 0; i < ARRAY_SIZE(formats); i++)
6375 for (j = 0; j < ARRAY_SIZE(types); j++)
6377 BOOL support;
6379 if (formats[i].overlay != types[j].overlay
6380 || (types[j].overlay && !(hal_caps.dwCaps & DDCAPS_OVERLAY)))
6381 continue;
6383 if (formats[i].overlay)
6384 support = supported_overlay_fmts & formats[i].support_flag;
6385 else
6386 support = supported_fmts & formats[i].support_flag;
6388 for (w = 1; w <= 8; w++)
6390 for (h = 1; h <= 8; h++)
6392 BOOL block_aligned = TRUE;
6393 BOOL todo = FALSE;
6395 if (w & (formats[i].block_width - 1) || h & (formats[i].block_height - 1))
6396 block_aligned = FALSE;
6398 memset(&ddsd, 0, sizeof(ddsd));
6399 ddsd.dwSize = sizeof(ddsd);
6400 ddsd.dwFlags = DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
6401 ddsd.ddsCaps.dwCaps = types[j].caps;
6402 ddsd.ddsCaps.dwCaps2 = types[j].caps2;
6403 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
6404 ddsd.ddpfPixelFormat.dwFlags = DDPF_FOURCC;
6405 ddsd.ddpfPixelFormat.dwFourCC = formats[i].fourcc;
6406 ddsd.dwWidth = w;
6407 ddsd.dwHeight = h;
6409 /* TODO: Handle power of two limitations. I cannot test the pow2
6410 * behavior on windows because I have no hardware that doesn't at
6411 * least support np2_conditional. There's probably no HW that
6412 * supports DXTN textures but no conditional np2 textures. */
6413 if (!support && !(types[j].caps & DDSCAPS_SYSTEMMEMORY))
6414 expect_hr = DDERR_INVALIDPARAMS;
6415 else if (formats[i].create_size_checked && !block_aligned)
6417 expect_hr = DDERR_INVALIDPARAMS;
6418 if (!(types[j].caps & DDSCAPS_TEXTURE))
6419 todo = TRUE;
6421 else
6422 expect_hr = D3D_OK;
6424 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
6425 todo_wine_if (todo)
6426 ok(hr == expect_hr,
6427 "Got unexpected hr %#lx for format %s, resource type %s, size %ux%u, expected %#lx.\n",
6428 hr, formats[i].name, types[j].name, w, h, expect_hr);
6430 if (SUCCEEDED(hr))
6431 IDirectDrawSurface4_Release(surface);
6436 if (formats[i].overlay)
6437 continue;
6439 for (j = 0; j < ARRAY_SIZE(user_mem_tests); ++j)
6441 memset(&ddsd, 0, sizeof(ddsd));
6442 ddsd.dwSize = sizeof(ddsd);
6443 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | user_mem_tests[j].flags;
6444 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE;
6446 switch (user_mem_tests[j].size_type)
6448 case SIZE_TYPE_ZERO:
6449 ddsd.dwLinearSize = 0;
6450 break;
6452 case SIZE_TYPE_PITCH:
6453 ddsd.dwLinearSize = 2 * formats[i].block_size;
6454 break;
6456 case SIZE_TYPE_SIZE:
6457 ddsd.dwLinearSize = 2 * 2 * formats[i].block_size;
6458 break;
6460 ddsd.dwLinearSize += user_mem_tests[j].rel_size;
6462 ddsd.lpSurface = mem;
6463 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
6464 ddsd.ddpfPixelFormat.dwFlags = DDPF_FOURCC;
6465 ddsd.ddpfPixelFormat.dwFourCC = formats[i].fourcc;
6466 ddsd.dwWidth = 8;
6467 ddsd.dwHeight = 8;
6469 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
6470 ok(hr == user_mem_tests[j].hr, "Test %u: Got unexpected hr %#lx, format %s.\n", j, hr, formats[i].name);
6472 if (FAILED(hr))
6473 continue;
6475 memset(&ddsd, 0, sizeof(ddsd));
6476 ddsd.dwSize = sizeof(ddsd);
6477 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &ddsd);
6478 ok(SUCCEEDED(hr), "Test %u: Failed to get surface desc, hr %#lx.\n", j, hr);
6479 ok(ddsd.dwFlags == (DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_LINEARSIZE),
6480 "Test %u: Got unexpected flags %#lx.\n", j, ddsd.dwFlags);
6481 if (user_mem_tests[j].flags & DDSD_LPSURFACE)
6482 ok(ddsd.dwLinearSize == ~0u, "Test %u: Got unexpected linear size %#lx.\n",
6483 j, ddsd.dwLinearSize);
6484 else
6485 ok(ddsd.dwLinearSize == 2 * 2 * formats[i].block_size,
6486 "Test %u: Got unexpected linear size %#lx, expected %#x.\n",
6487 j, ddsd.dwLinearSize, 2 * 2 * formats[i].block_size);
6488 IDirectDrawSurface4_Release(surface);
6492 free(mem);
6493 cleanup:
6494 IDirectDraw4_Release(ddraw);
6495 IDirect3DDevice3_Release(device);
6496 DestroyWindow(window);
6499 struct format_support_check
6501 const DDPIXELFORMAT *format;
6502 BOOL supported;
6505 static HRESULT WINAPI test_unsupported_formats_cb(DDPIXELFORMAT *fmt, void *ctx)
6507 struct format_support_check *format = ctx;
6509 if (!memcmp(format->format, fmt, sizeof(*fmt)))
6511 format->supported = TRUE;
6512 return DDENUMRET_CANCEL;
6515 return DDENUMRET_OK;
6518 static void test_unsupported_formats(void)
6520 HRESULT hr;
6521 BOOL expect_success;
6522 HWND window;
6523 IDirectDraw4 *ddraw;
6524 IDirect3D3 *d3d;
6525 IDirect3DDevice3 *device;
6526 IDirectDrawSurface4 *surface;
6527 DDSURFACEDESC2 ddsd;
6528 unsigned int i, j;
6529 DWORD expected_caps;
6530 static const struct
6532 const char *name;
6533 DDPIXELFORMAT fmt;
6535 formats[] =
6538 "D3DFMT_A8R8G8B8",
6540 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
6541 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
6545 "D3DFMT_P8",
6547 sizeof(DDPIXELFORMAT), DDPF_PALETTEINDEXED8 | DDPF_RGB, 0,
6548 {8 }, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}
6552 static const DWORD caps[] = {0, DDSCAPS_SYSTEMMEMORY, DDSCAPS_VIDEOMEMORY};
6554 window = create_window();
6555 if (!(device = create_device(window, DDSCL_NORMAL)))
6557 skip("Failed to create a 3D device, skipping test.\n");
6558 DestroyWindow(window);
6559 return;
6562 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
6563 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#lx.\n", hr);
6564 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **) &ddraw);
6565 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#lx.\n", hr);
6566 IDirect3D3_Release(d3d);
6568 for (i = 0; i < ARRAY_SIZE(formats); i++)
6570 struct format_support_check check = {&formats[i].fmt, FALSE};
6571 hr = IDirect3DDevice3_EnumTextureFormats(device, test_unsupported_formats_cb, &check);
6572 ok(SUCCEEDED(hr), "Got hr %#lx.\n", hr);
6574 for (j = 0; j < ARRAY_SIZE(caps); j++)
6576 memset(&ddsd, 0, sizeof(ddsd));
6577 ddsd.dwSize = sizeof(ddsd);
6578 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
6579 ddsd.ddpfPixelFormat = formats[i].fmt;
6580 ddsd.dwWidth = 4;
6581 ddsd.dwHeight = 4;
6582 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | caps[j];
6584 if (caps[j] & DDSCAPS_VIDEOMEMORY && !check.supported)
6585 expect_success = FALSE;
6586 else
6587 expect_success = TRUE;
6589 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
6590 ok(SUCCEEDED(hr) == expect_success,
6591 "Got unexpected hr %#lx for format %s, caps %#lx, expected %s.\n",
6592 hr, formats[i].name, caps[j], expect_success ? "success" : "failure");
6593 if (FAILED(hr))
6594 continue;
6596 memset(&ddsd, 0, sizeof(ddsd));
6597 ddsd.dwSize = sizeof(ddsd);
6598 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &ddsd);
6599 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#lx.\n", hr);
6601 if (caps[j] & DDSCAPS_VIDEOMEMORY)
6602 expected_caps = DDSCAPS_VIDEOMEMORY;
6603 else if (caps[j] & DDSCAPS_SYSTEMMEMORY)
6604 expected_caps = DDSCAPS_SYSTEMMEMORY;
6605 else if (check.supported)
6606 expected_caps = DDSCAPS_VIDEOMEMORY;
6607 else
6608 expected_caps = DDSCAPS_SYSTEMMEMORY;
6610 ok(ddsd.ddsCaps.dwCaps & expected_caps,
6611 "Expected caps %#lx, format %s, input caps %#lx.\n",
6612 expected_caps, formats[i].name, caps[j]);
6614 IDirectDrawSurface4_Release(surface);
6618 IDirectDraw4_Release(ddraw);
6619 IDirect3DDevice3_Release(device);
6620 DestroyWindow(window);
6623 static void test_rt_caps(const GUID *device_guid)
6625 DWORD fourcc_codes[64], fourcc_code_count;
6626 PALETTEENTRY palette_entries[256];
6627 IDirectDrawPalette *palette;
6628 BOOL software_device;
6629 IDirectDraw4 *ddraw;
6630 DDPIXELFORMAT z_fmt;
6631 IDirect3D3 *d3d;
6632 DDCAPS hal_caps;
6633 unsigned int i;
6634 ULONG refcount;
6635 HWND window;
6636 HRESULT hr;
6638 static const DDPIXELFORMAT p8_fmt =
6640 sizeof(DDPIXELFORMAT), DDPF_PALETTEINDEXED8 | DDPF_RGB, 0,
6641 {8}, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000},
6643 static const DDPIXELFORMAT fourcc_fmt =
6645 .dwSize = sizeof(DDPIXELFORMAT),
6646 .dwFlags = DDPF_FOURCC,
6647 .dwFourCC = MAKEFOURCC('Y','U','Y','2'),
6650 const struct
6652 const DDPIXELFORMAT *pf;
6653 DWORD caps_in;
6654 DWORD caps2_in;
6655 HRESULT create_device_hr;
6656 HRESULT set_rt_hr, alternative_set_rt_hr;
6658 test_data[] =
6661 NULL,
6662 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY,
6664 D3D_OK,
6665 D3D_OK,
6666 D3D_OK,
6669 NULL,
6670 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE,
6672 D3D_OK,
6673 D3D_OK,
6674 D3D_OK,
6677 NULL,
6678 DDSCAPS_OFFSCREENPLAIN,
6680 DDERR_INVALIDCAPS,
6681 DDERR_INVALIDCAPS,
6682 DDERR_INVALIDCAPS,
6685 NULL,
6686 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
6688 D3DERR_SURFACENOTINVIDMEM,
6689 D3D_OK,
6690 D3D_OK,
6693 NULL,
6694 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
6696 DDERR_INVALIDCAPS,
6697 DDERR_INVALIDCAPS,
6698 DDERR_INVALIDCAPS,
6701 NULL,
6702 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY,
6704 D3D_OK,
6705 D3D_OK,
6706 D3D_OK,
6709 NULL,
6710 DDSCAPS_3DDEVICE,
6712 D3D_OK,
6713 D3D_OK,
6714 D3D_OK,
6717 NULL,
6720 DDERR_INVALIDCAPS,
6721 DDERR_INVALIDCAPS,
6722 DDERR_INVALIDCAPS,
6725 NULL,
6726 DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
6728 D3DERR_SURFACENOTINVIDMEM,
6729 D3D_OK,
6730 D3D_OK,
6733 NULL,
6734 DDSCAPS_SYSTEMMEMORY,
6736 DDERR_INVALIDCAPS,
6737 DDERR_INVALIDCAPS,
6738 DDERR_INVALIDCAPS,
6741 NULL,
6742 DDSCAPS_TEXTURE | DDSCAPS_3DDEVICE,
6743 DDSCAPS2_TEXTUREMANAGE,
6744 D3DERR_SURFACENOTINVIDMEM,
6745 D3D_OK,
6746 D3D_OK,
6749 NULL,
6750 DDSCAPS_TEXTURE | DDSCAPS_3DDEVICE,
6751 DDSCAPS2_D3DTEXTUREMANAGE,
6752 D3DERR_SURFACENOTINVIDMEM,
6753 D3D_OK,
6754 D3D_OK,
6757 &p8_fmt,
6760 DDERR_INVALIDCAPS,
6761 DDERR_INVALIDCAPS,
6762 DDERR_INVALIDCAPS,
6765 &p8_fmt,
6766 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE,
6768 DDERR_NOPALETTEATTACHED,
6769 DDERR_INVALIDCAPS,
6770 DDERR_INVALIDCAPS,
6773 &p8_fmt,
6774 DDSCAPS_OFFSCREENPLAIN,
6776 DDERR_INVALIDCAPS,
6777 DDERR_INVALIDCAPS,
6778 DDERR_INVALIDCAPS,
6781 &p8_fmt,
6782 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
6784 DDERR_NOPALETTEATTACHED,
6785 DDERR_INVALIDCAPS,
6786 DDERR_INVALIDCAPS,
6789 &p8_fmt,
6790 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
6792 DDERR_INVALIDCAPS,
6793 DDERR_INVALIDCAPS,
6794 DDERR_INVALIDCAPS,
6797 &z_fmt,
6798 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_ZBUFFER,
6800 DDERR_INVALIDCAPS,
6801 DDERR_INVALIDPIXELFORMAT,
6802 D3D_OK /* r200 */,
6805 &z_fmt,
6806 DDSCAPS_3DDEVICE | DDSCAPS_ZBUFFER,
6808 DDERR_INVALIDCAPS,
6809 DDERR_INVALIDPIXELFORMAT,
6810 D3D_OK /* r200 */,
6813 &z_fmt,
6814 DDSCAPS_ZBUFFER,
6816 DDERR_INVALIDCAPS,
6817 DDERR_INVALIDCAPS,
6818 DDERR_INVALIDCAPS,
6821 &z_fmt,
6822 DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE | DDSCAPS_ZBUFFER,
6824 DDERR_INVALIDCAPS,
6825 DDERR_INVALIDPIXELFORMAT,
6826 D3D_OK /* r200 */,
6829 &z_fmt,
6830 DDSCAPS_SYSTEMMEMORY | DDSCAPS_ZBUFFER,
6832 DDERR_INVALIDCAPS,
6833 DDERR_INVALIDCAPS,
6834 DDERR_INVALIDCAPS,
6837 &fourcc_fmt,
6838 DDSCAPS_FLIP | DDSCAPS_COMPLEX | DDSCAPS_OFFSCREENPLAIN,
6840 DDERR_INVALIDCAPS,
6841 DDERR_INVALIDCAPS,
6842 DDERR_INVALIDCAPS,
6846 software_device = is_software_device_type(device_guid);
6848 window = create_window();
6849 ddraw = create_ddraw();
6850 ok(!!ddraw, "Failed to create a ddraw object.\n");
6851 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6852 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
6854 if (FAILED(IDirectDraw4_QueryInterface(ddraw, &IID_IDirect3D3, (void **)&d3d)))
6856 skip("D3D interface is not available, skipping test.\n");
6857 goto done;
6860 memset(&z_fmt, 0, sizeof(z_fmt));
6861 hr = IDirect3D3_EnumZBufferFormats(d3d, device_guid, enum_z_fmt, &z_fmt);
6862 if (FAILED(hr) || !z_fmt.dwSize)
6864 skip("No depth buffer formats available, software_device %u, skipping test.\n", software_device);
6865 IDirect3D3_Release(d3d);
6866 goto done;
6869 memset(palette_entries, 0, sizeof(palette_entries));
6870 hr = IDirectDraw4_CreatePalette(ddraw, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, palette_entries, &palette, NULL);
6871 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
6873 memset(&hal_caps, 0, sizeof(hal_caps));
6874 hal_caps.dwSize = sizeof(hal_caps);
6875 hr = IDirectDraw4_GetCaps(ddraw, &hal_caps, NULL);
6876 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
6878 fourcc_code_count = ARRAY_SIZE(fourcc_codes);
6879 hr = IDirectDraw4_GetFourCCCodes(ddraw, &fourcc_code_count, fourcc_codes);
6880 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
6882 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
6884 IDirectDrawSurface4 *surface, *rt, *expected_rt, *tmp;
6885 DWORD caps_in, expected_caps;
6886 DDSURFACEDESC2 surface_desc;
6887 IDirect3DDevice3 *device;
6888 HRESULT expected_hr;
6890 caps_in = test_data[i].caps_in;
6892 memset(&surface_desc, 0, sizeof(surface_desc));
6893 surface_desc.dwSize = sizeof(surface_desc);
6894 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
6895 surface_desc.ddsCaps.dwCaps = caps_in;
6896 surface_desc.ddsCaps.dwCaps2 = test_data[i].caps2_in;
6897 if (test_data[i].pf)
6899 if (test_data[i].pf->dwFlags & DDPF_FOURCC)
6901 unsigned int j;
6903 for (j = 0; j < fourcc_code_count; ++j)
6905 if (test_data[i].pf->dwFourCC == fourcc_codes[j])
6906 break;
6908 if (j == fourcc_code_count)
6910 skip("Fourcc format %#lx is not supported, skipping test.\n", test_data[i].pf->dwFourCC);
6911 continue;
6914 surface_desc.dwFlags |= DDSD_PIXELFORMAT;
6915 surface_desc.ddpfPixelFormat = *test_data[i].pf;
6917 if (caps_in & DDSCAPS_FLIP)
6919 surface_desc.dwFlags |= DDSD_BACKBUFFERCOUNT;
6920 surface_desc.dwBackBufferCount = 1;
6922 surface_desc.dwWidth = 640;
6923 surface_desc.dwHeight = 480;
6924 if ((caps_in & DDSCAPS_VIDEOMEMORY) && !(hal_caps.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY))
6925 expected_hr = DDERR_NODIRECTDRAWHW;
6926 else
6927 expected_hr = DD_OK;
6928 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
6929 ok(hr == expected_hr || (software_device && (surface_desc.ddsCaps.dwCaps & (DDSCAPS_VIDEOMEMORY | DDSCAPS_ZBUFFER))
6930 == (DDSCAPS_VIDEOMEMORY | DDSCAPS_ZBUFFER) && hr == DDERR_UNSUPPORTED)
6931 || broken(software_device && test_data[i].pf == &p8_fmt && hr == DDERR_INVALIDPIXELFORMAT),
6932 "Got unexpected hr %#lx, test %u, software_device %u.\n", hr, i, software_device);
6933 if (FAILED(hr))
6934 continue;
6936 memset(&surface_desc, 0, sizeof(surface_desc));
6937 surface_desc.dwSize = sizeof(surface_desc);
6938 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &surface_desc);
6939 ok(hr == DD_OK, "Got unexpected hr %#lx, test %u, software_device %u.\n", hr, i, software_device);
6941 if ((caps_in & DDSCAPS_SYSTEMMEMORY) || (test_data[i].caps2_in & (DDSCAPS2_D3DTEXTUREMANAGE
6942 | DDSCAPS2_TEXTUREMANAGE)) || !(hal_caps.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY))
6943 expected_caps = caps_in | DDSCAPS_SYSTEMMEMORY;
6944 else
6945 expected_caps = caps_in | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM;
6947 if (caps_in & DDSCAPS_FLIP)
6948 expected_caps |= DDSCAPS_FRONTBUFFER;
6950 ok(surface_desc.ddsCaps.dwCaps == expected_caps || (test_data[i].pf == &p8_fmt
6951 && surface_desc.ddsCaps.dwCaps == (caps_in | DDSCAPS_SYSTEMMEMORY))
6952 || (software_device && test_data[i].pf == &z_fmt
6953 && surface_desc.ddsCaps.dwCaps == (caps_in | DDSCAPS_SYSTEMMEMORY)),
6954 "Got unexpected caps %#lx, expected %#lx, test %u, software_device %u.\n",
6955 surface_desc.ddsCaps.dwCaps, expected_caps, i, software_device);
6957 ok(surface_desc.ddsCaps.dwCaps2 == test_data[i].caps2_in,
6958 "Got unexpected caps2 %#lx, expected %#lx, test %u, software_device %u.\n",
6959 surface_desc.ddsCaps.dwCaps2, test_data[i].caps2_in, i, software_device);
6961 hr = IDirect3D3_CreateDevice(d3d, device_guid, surface, &device, NULL);
6963 ok((!software_device && hr == test_data[i].create_device_hr)
6964 || (software_device && (hr == (test_data[i].create_device_hr == D3DERR_SURFACENOTINVIDMEM
6965 ? DD_OK : test_data[i].create_device_hr))),
6966 "Got unexpected hr %#lx, test %u, software_device %u.\n", hr, i, software_device);
6967 if (FAILED(hr))
6969 if (hr == DDERR_NOPALETTEATTACHED)
6971 hr = IDirectDrawSurface4_SetPalette(surface, palette);
6972 ok(hr == DD_OK, "Got unexpected hr %#lx, test %u, software_device %u.\n", hr, i, software_device);
6973 if (software_device)
6975 /* _CreateDevice succeeds with software device, but the palette gets extra reference
6976 * on Windows (probably due to a bug) which doesn't go away on the device and surface
6977 * destruction and ddraw is not destroyed cleanly, so skipping this test. */
6978 IDirectDrawSurface4_Release(surface);
6979 continue;
6981 hr = IDirect3D3_CreateDevice(d3d, device_guid, surface, &device, NULL);
6982 if (surface_desc.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY)
6983 ok(hr == DDERR_INVALIDPIXELFORMAT, "Got unexpected hr %#lx, test %u, software_device %u.\n",
6984 hr, i, software_device);
6985 else
6986 ok(hr == D3DERR_SURFACENOTINVIDMEM, "Got unexpected hr %#lx, test %u, software_device %u.\n",
6987 hr, i, software_device);
6989 IDirectDrawSurface4_Release(surface);
6991 memset(&surface_desc, 0, sizeof(surface_desc));
6992 surface_desc.dwSize = sizeof(surface_desc);
6993 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
6994 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
6995 surface_desc.dwWidth = 640;
6996 surface_desc.dwHeight = 480;
6997 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
6998 ok(hr == DD_OK, "Got unexpected hr %#lx, test %u, software_device %u.\n", hr, i, software_device);
7000 hr = IDirect3D3_CreateDevice(d3d, device_guid, surface, &device, NULL);
7001 ok(hr == DD_OK, "Got unexpected hr %#lx, test %u, software_device %u.\n", hr, i, software_device);
7004 memset(&surface_desc, 0, sizeof(surface_desc));
7005 surface_desc.dwSize = sizeof(surface_desc);
7006 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
7007 surface_desc.ddsCaps.dwCaps = test_data[i].caps_in;
7008 surface_desc.ddsCaps.dwCaps2 = test_data[i].caps2_in;
7009 if (test_data[i].pf)
7011 surface_desc.dwFlags |= DDSD_PIXELFORMAT;
7012 surface_desc.ddpfPixelFormat = *test_data[i].pf;
7014 if (caps_in & DDSCAPS_FLIP)
7016 surface_desc.dwFlags |= DDSD_BACKBUFFERCOUNT;
7017 surface_desc.dwBackBufferCount = 1;
7019 surface_desc.dwWidth = 640;
7020 surface_desc.dwHeight = 480;
7021 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &rt, NULL);
7022 ok(hr == DD_OK, "Got unexpected hr %#lx, test %u, software_device %u.\n", hr, i, software_device);
7024 hr = IDirect3DDevice3_SetRenderTarget(device, rt, 0);
7025 ok(hr == test_data[i].set_rt_hr || (software_device && hr == DDERR_NOPALETTEATTACHED)
7026 || broken(hr == test_data[i].alternative_set_rt_hr),
7027 "Got unexpected hr %#lx, test %u, software_device %u.\n",
7028 hr, i, software_device);
7029 if (SUCCEEDED(hr) || hr == DDERR_INVALIDPIXELFORMAT)
7030 expected_rt = rt;
7031 else
7032 expected_rt = surface;
7034 hr = IDirect3DDevice3_GetRenderTarget(device, &tmp);
7035 ok(hr == DD_OK, "Got unexpected hr %#lx, test %u, software_device %u.\n", hr, i, software_device);
7036 ok(tmp == expected_rt, "Got unexpected rt %p, test %u, software_device %u.\n", tmp, i, software_device);
7038 IDirectDrawSurface4_Release(tmp);
7039 IDirectDrawSurface4_Release(rt);
7040 refcount = IDirect3DDevice3_Release(device);
7041 ok(!refcount, "Unexpected refcount %lu.\n", refcount);
7042 refcount = IDirectDrawSurface4_Release(surface);
7043 ok(!refcount, "Unexpected refcount %lu.\n", refcount);
7046 refcount = IDirectDrawPalette_Release(palette);
7047 ok(!refcount, "Got unexpected refcount %lu.\n", refcount);
7048 IDirect3D3_Release(d3d);
7050 done:
7051 refcount = IDirectDraw4_Release(ddraw);
7052 ok(!refcount, "Unexpected refcount %lu.\n", refcount);
7053 DestroyWindow(window);
7056 static void test_primary_caps(void)
7058 const DWORD placement = DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY | DDSCAPS_SYSTEMMEMORY;
7059 IDirectDrawSurface4 *surface;
7060 DDSURFACEDESC2 surface_desc;
7061 IDirectDraw4 *ddraw;
7062 unsigned int i;
7063 ULONG refcount;
7064 HWND window;
7065 HRESULT hr;
7067 static const struct
7069 DWORD coop_level;
7070 DWORD caps_in;
7071 DWORD back_buffer_count;
7072 HRESULT hr;
7073 DWORD caps_out;
7075 test_data[] =
7078 DDSCL_NORMAL,
7079 DDSCAPS_PRIMARYSURFACE,
7080 ~0u,
7081 DD_OK,
7082 DDSCAPS_VISIBLE | DDSCAPS_PRIMARYSURFACE,
7085 DDSCL_NORMAL,
7086 DDSCAPS_PRIMARYSURFACE | DDSCAPS_TEXTURE,
7087 ~0u,
7088 DDERR_INVALIDCAPS,
7089 ~0u,
7092 DDSCL_NORMAL,
7093 DDSCAPS_PRIMARYSURFACE | DDSCAPS_FRONTBUFFER,
7094 ~0u,
7095 DDERR_INVALIDCAPS,
7096 ~0u,
7099 DDSCL_NORMAL,
7100 DDSCAPS_PRIMARYSURFACE | DDSCAPS_BACKBUFFER,
7101 ~0u,
7102 DDERR_INVALIDCAPS,
7103 ~0u,
7106 DDSCL_NORMAL,
7107 DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP,
7108 ~0u,
7109 DDERR_INVALIDCAPS,
7110 ~0u,
7113 DDSCL_NORMAL,
7114 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX,
7115 ~0u,
7116 DDERR_INVALIDCAPS,
7117 ~0u,
7120 DDSCL_NORMAL,
7121 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
7122 ~0u,
7123 DDERR_INVALIDCAPS,
7124 ~0u,
7127 DDSCL_NORMAL,
7128 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
7130 DDERR_INVALIDCAPS,
7131 ~0u,
7134 DDSCL_NORMAL,
7135 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
7137 DDERR_NOEXCLUSIVEMODE,
7138 ~0u,
7141 DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN,
7142 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
7144 DDERR_INVALIDCAPS,
7145 ~0u,
7148 DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN,
7149 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
7151 DD_OK,
7152 DDSCAPS_VISIBLE | DDSCAPS_PRIMARYSURFACE | DDSCAPS_FRONTBUFFER | DDSCAPS_FLIP | DDSCAPS_COMPLEX,
7155 DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN,
7156 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP | DDSCAPS_FRONTBUFFER,
7158 DDERR_INVALIDCAPS,
7159 ~0u,
7162 DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN,
7163 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP | DDSCAPS_BACKBUFFER,
7165 DDERR_INVALIDCAPS,
7166 ~0u,
7170 window = create_window();
7171 ddraw = create_ddraw();
7172 ok(!!ddraw, "Failed to create a ddraw object.\n");
7174 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
7176 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, test_data[i].coop_level);
7177 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
7179 memset(&surface_desc, 0, sizeof(surface_desc));
7180 surface_desc.dwSize = sizeof(surface_desc);
7181 surface_desc.dwFlags = DDSD_CAPS;
7182 if (test_data[i].back_buffer_count != ~0u)
7183 surface_desc.dwFlags |= DDSD_BACKBUFFERCOUNT;
7184 surface_desc.ddsCaps.dwCaps = test_data[i].caps_in;
7185 surface_desc.dwBackBufferCount = test_data[i].back_buffer_count;
7186 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7187 ok(hr == test_data[i].hr, "Test %u: Got unexpected hr %#lx, expected %#lx.\n", i, hr, test_data[i].hr);
7188 if (FAILED(hr))
7189 continue;
7191 memset(&surface_desc, 0, sizeof(surface_desc));
7192 surface_desc.dwSize = sizeof(surface_desc);
7193 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &surface_desc);
7194 ok(SUCCEEDED(hr), "Test %u: Failed to get surface desc, hr %#lx.\n", i, hr);
7195 ok((surface_desc.ddsCaps.dwCaps & ~placement) == test_data[i].caps_out,
7196 "Test %u: Got unexpected caps %#lx, expected %#lx.\n",
7197 i, surface_desc.ddsCaps.dwCaps, test_data[i].caps_out);
7199 IDirectDrawSurface4_Release(surface);
7202 refcount = IDirectDraw4_Release(ddraw);
7203 ok(!refcount, "Unexpected refcount %lu.\n", refcount);
7204 DestroyWindow(window);
7207 static void test_surface_lock(void)
7209 IDirectDraw4 *ddraw;
7210 IDirect3D3 *d3d = NULL;
7211 IDirectDrawSurface4 *surface;
7212 HRESULT hr;
7213 HWND window;
7214 unsigned int i;
7215 DDSURFACEDESC2 ddsd;
7216 ULONG refcount;
7217 DDPIXELFORMAT z_fmt;
7218 static const struct
7220 DWORD caps;
7221 DWORD caps2;
7222 const char *name;
7224 tests[] =
7227 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY,
7229 "videomemory offscreenplain"
7232 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
7234 "systemmemory offscreenplain"
7237 DDSCAPS_PRIMARYSURFACE,
7239 "primary"
7242 DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY,
7244 "videomemory texture"
7247 DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY,
7248 DDSCAPS2_OPAQUE,
7249 "opaque videomemory texture"
7252 DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY,
7254 "systemmemory texture"
7257 DDSCAPS_TEXTURE,
7258 DDSCAPS2_TEXTUREMANAGE,
7259 "managed texture"
7262 DDSCAPS_TEXTURE,
7263 DDSCAPS2_D3DTEXTUREMANAGE,
7264 "managed texture"
7267 DDSCAPS_TEXTURE,
7268 DDSCAPS2_TEXTUREMANAGE | DDSCAPS2_OPAQUE,
7269 "opaque managed texture"
7272 DDSCAPS_TEXTURE,
7273 DDSCAPS2_D3DTEXTUREMANAGE | DDSCAPS2_OPAQUE,
7274 "opaque managed texture"
7277 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE,
7279 "render target"
7282 DDSCAPS_ZBUFFER,
7284 "Z buffer"
7288 window = create_window();
7289 ddraw = create_ddraw();
7290 ok(!!ddraw, "Failed to create a ddraw object.\n");
7291 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
7292 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
7294 if (FAILED(IDirectDraw4_QueryInterface(ddraw, &IID_IDirect3D3, (void **)&d3d)))
7296 skip("D3D interface is not available, skipping test.\n");
7297 goto done;
7300 memset(&z_fmt, 0, sizeof(z_fmt));
7301 hr = IDirect3D3_EnumZBufferFormats(d3d, &IID_IDirect3DHALDevice, enum_z_fmt, &z_fmt);
7302 if (FAILED(hr) || !z_fmt.dwSize)
7304 skip("No depth buffer formats available, skipping test.\n");
7305 goto done;
7308 for (i = 0; i < ARRAY_SIZE(tests); i++)
7310 memset(&ddsd, 0, sizeof(ddsd));
7311 ddsd.dwSize = sizeof(ddsd);
7312 ddsd.dwFlags = DDSD_CAPS;
7313 if (!(tests[i].caps & DDSCAPS_PRIMARYSURFACE))
7315 ddsd.dwFlags |= DDSD_WIDTH | DDSD_HEIGHT;
7316 ddsd.dwWidth = 64;
7317 ddsd.dwHeight = 64;
7319 if (tests[i].caps & DDSCAPS_ZBUFFER)
7321 ddsd.dwFlags |= DDSD_PIXELFORMAT;
7322 ddsd.ddpfPixelFormat = z_fmt;
7324 ddsd.ddsCaps.dwCaps = tests[i].caps;
7325 ddsd.ddsCaps.dwCaps2 = tests[i].caps2;
7327 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
7328 ok(SUCCEEDED(hr), "Failed to create surface, type %s, hr %#lx.\n", tests[i].name, hr);
7330 memset(&ddsd, 0, sizeof(ddsd));
7331 ddsd.dwSize = sizeof(ddsd);
7332 hr = IDirectDrawSurface4_Lock(surface, NULL, &ddsd, DDLOCK_WAIT, NULL);
7333 ok(SUCCEEDED(hr), "Failed to lock surface, type %s, hr %#lx.\n", tests[i].name, hr);
7334 if (SUCCEEDED(hr))
7336 hr = IDirectDrawSurface4_Unlock(surface, NULL);
7337 ok(SUCCEEDED(hr), "Failed to unlock surface, type %s, hr %#lx.\n", tests[i].name, hr);
7340 memset(&ddsd, 0, sizeof(ddsd));
7341 hr = IDirectDrawSurface4_Lock(surface, NULL, &ddsd, DDLOCK_WAIT, NULL);
7342 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx, type %s.\n", hr, tests[i].name);
7344 IDirectDrawSurface4_Release(surface);
7347 done:
7348 if (d3d)
7349 IDirect3D3_Release(d3d);
7350 refcount = IDirectDraw4_Release(ddraw);
7351 ok(!refcount, "Unexpected refcount %lu.\n", refcount);
7352 DestroyWindow(window);
7355 static void test_surface_discard(void)
7357 IDirect3DDevice3 *device;
7358 IDirect3D3 *d3d;
7359 IDirectDraw4 *ddraw;
7360 HRESULT hr;
7361 HWND window;
7362 DDSURFACEDESC2 ddsd;
7363 IDirectDrawSurface4 *surface, *target;
7364 void *addr;
7365 static const struct
7367 DWORD caps, caps2;
7368 BOOL discard;
7370 tests[] =
7372 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0, TRUE},
7373 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY, 0, FALSE},
7374 {DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, 0, TRUE},
7375 {DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, 0, FALSE},
7376 {DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, FALSE},
7377 {DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE | DDSCAPS2_HINTDYNAMIC, FALSE},
7378 {DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, FALSE},
7379 {DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE | DDSCAPS2_HINTDYNAMIC, FALSE},
7381 unsigned int i;
7383 window = create_window();
7385 for (i = 0; i < ARRAY_SIZE(tests); i++)
7387 BOOL discarded;
7389 /* Sigh. Anything other than the first run of the loop randomly fails with
7390 * DDERR_SURFACELOST on my Radeon Pro 560 on Win10 19.09. Most of the time
7391 * the blit fails, but with sleeps added between surface creation and lock
7392 * the lock can fail too. Interestingly ddraw claims the render target has
7393 * been lost, not the test surface.
7395 * Recreating ddraw every iteration seems to fix this. */
7396 if (!(device = create_device(window, DDSCL_NORMAL)))
7398 skip("Failed to create a 3D device, skipping test.\n");
7399 DestroyWindow(window);
7400 return;
7402 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
7403 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#lx.\n", hr);
7404 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
7405 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#lx.\n", hr);
7406 hr = IDirect3DDevice3_GetRenderTarget(device, &target);
7407 ok(SUCCEEDED(hr), "Failed to get render target, hr %#lx.\n", hr);
7409 memset(&ddsd, 0, sizeof(ddsd));
7410 ddsd.dwSize = sizeof(ddsd);
7411 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
7412 ddsd.ddsCaps.dwCaps = tests[i].caps;
7413 ddsd.ddsCaps.dwCaps2 = tests[i].caps2;
7414 ddsd.dwWidth = 64;
7415 ddsd.dwHeight = 64;
7416 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
7417 ok(SUCCEEDED(hr), "Failed to create offscreen surface, hr %#lx, case %u.\n", hr, i);
7419 memset(&ddsd, 0, sizeof(ddsd));
7420 ddsd.dwSize = sizeof(ddsd);
7421 hr = IDirectDrawSurface4_Lock(surface, NULL, &ddsd, 0, NULL);
7422 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#lx.\n", hr);
7423 addr = ddsd.lpSurface;
7424 hr = IDirectDrawSurface4_Unlock(surface, NULL);
7425 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx.\n", hr);
7427 memset(&ddsd, 0, sizeof(ddsd));
7428 ddsd.dwSize = sizeof(ddsd);
7429 hr = IDirectDrawSurface4_Lock(surface, NULL, &ddsd, DDLOCK_DISCARDCONTENTS, NULL);
7430 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#lx.\n", hr);
7431 discarded = ddsd.lpSurface != addr;
7432 hr = IDirectDrawSurface4_Unlock(surface, NULL);
7433 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx.\n", hr);
7435 hr = IDirectDrawSurface4_Blt(target, NULL, surface, NULL, DDBLT_WAIT, NULL);
7436 ok(SUCCEEDED(hr), "Failed to blit, hr %#lx.\n", hr);
7438 memset(&ddsd, 0, sizeof(ddsd));
7439 ddsd.dwSize = sizeof(ddsd);
7440 hr = IDirectDrawSurface4_Lock(surface, NULL, &ddsd, DDLOCK_DISCARDCONTENTS, NULL);
7441 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#lx.\n", hr);
7442 discarded |= ddsd.lpSurface != addr;
7443 hr = IDirectDrawSurface4_Unlock(surface, NULL);
7444 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx.\n", hr);
7446 IDirectDrawSurface4_Release(surface);
7448 /* Windows 7 reliably changes the address of surfaces that are discardable (Nvidia Kepler,
7449 * AMD r500, evergreen). Windows XP, at least on AMD r200, does not. */
7450 ok(!discarded || tests[i].discard, "Expected surface not to be discarded, case %u\n", i);
7452 IDirectDrawSurface4_Release(target);
7453 IDirectDraw4_Release(ddraw);
7454 IDirect3D3_Release(d3d);
7455 IDirect3DDevice3_Release(device);
7458 DestroyWindow(window);
7461 static void test_flip(void)
7463 const DWORD placement = DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY | DDSCAPS_SYSTEMMEMORY;
7464 IDirectDrawSurface4 *frontbuffer, *backbuffer1, *backbuffer2, *backbuffer3, *surface;
7465 DDSCAPS2 caps = {DDSCAPS_FLIP, 0, 0, {0}};
7466 DDSURFACEDESC2 surface_desc;
7467 unsigned int color, i;
7468 BOOL sysmem_primary;
7469 IDirectDraw4 *ddraw;
7470 DWORD expected_caps;
7471 ULONG refcount;
7472 HWND window;
7473 HRESULT hr;
7475 static const struct
7477 const char *name;
7478 DWORD caps;
7480 test_data[] =
7482 {"PRIMARYSURFACE", DDSCAPS_PRIMARYSURFACE},
7483 {"OFFSCREENPLAIN", DDSCAPS_OFFSCREENPLAIN},
7484 {"TEXTURE", DDSCAPS_TEXTURE},
7487 window = create_window();
7488 ddraw = create_ddraw();
7489 ok(!!ddraw, "Failed to create a ddraw object.\n");
7491 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
7492 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
7494 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
7496 /* Creating a flippable texture induces a BSoD on some versions of the
7497 * Intel graphics driver. At least Intel GMA 950 with driver version
7498 * 6.14.10.4926 on Windows XP SP3 is affected. */
7499 if ((test_data[i].caps & DDSCAPS_TEXTURE) && ddraw_is_intel(ddraw))
7501 win_skip("Skipping flippable texture test.\n");
7502 continue;
7505 memset(&surface_desc, 0, sizeof(surface_desc));
7506 surface_desc.dwSize = sizeof(surface_desc);
7507 surface_desc.dwFlags = DDSD_CAPS;
7508 if (!(test_data[i].caps & DDSCAPS_PRIMARYSURFACE))
7509 surface_desc.dwFlags |= DDSD_WIDTH | DDSD_HEIGHT;
7510 surface_desc.ddsCaps.dwCaps = DDSCAPS_COMPLEX | DDSCAPS_FLIP | test_data[i].caps;
7511 surface_desc.dwWidth = 512;
7512 surface_desc.dwHeight = 512;
7513 surface_desc.dwBackBufferCount = 3;
7514 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &frontbuffer, NULL);
7515 ok(hr == DDERR_INVALIDCAPS, "%s: Got unexpected hr %#lx.\n", test_data[i].name, hr);
7517 surface_desc.ddsCaps.dwCaps &= ~DDSCAPS_FLIP;
7518 surface_desc.dwFlags |= DDSD_BACKBUFFERCOUNT;
7519 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &frontbuffer, NULL);
7520 ok(hr == DDERR_INVALIDCAPS, "%s: Got unexpected hr %#lx.\n", test_data[i].name, hr);
7522 surface_desc.ddsCaps.dwCaps &= ~DDSCAPS_COMPLEX;
7523 surface_desc.ddsCaps.dwCaps |= DDSCAPS_FLIP;
7524 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &frontbuffer, NULL);
7525 ok(hr == DDERR_INVALIDCAPS, "%s: Got unexpected hr %#lx.\n", test_data[i].name, hr);
7527 surface_desc.ddsCaps.dwCaps |= DDSCAPS_COMPLEX;
7528 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &frontbuffer, NULL);
7529 todo_wine_if(test_data[i].caps & DDSCAPS_TEXTURE)
7530 ok(SUCCEEDED(hr), "%s: Failed to create surface, hr %#lx.\n", test_data[i].name, hr);
7531 if (FAILED(hr))
7532 continue;
7534 memset(&surface_desc, 0, sizeof(surface_desc));
7535 surface_desc.dwSize = sizeof(surface_desc);
7536 hr = IDirectDrawSurface4_GetSurfaceDesc(frontbuffer, &surface_desc);
7537 ok(SUCCEEDED(hr), "%s: Failed to get surface desc, hr %#lx.\n", test_data[i].name, hr);
7538 expected_caps = DDSCAPS_FRONTBUFFER | DDSCAPS_COMPLEX | DDSCAPS_FLIP | test_data[i].caps;
7539 if (test_data[i].caps & DDSCAPS_PRIMARYSURFACE)
7540 expected_caps |= DDSCAPS_VISIBLE;
7541 ok((surface_desc.ddsCaps.dwCaps & ~placement) == expected_caps,
7542 "%s: Got unexpected caps %#lx.\n", test_data[i].name, surface_desc.ddsCaps.dwCaps);
7543 sysmem_primary = surface_desc.ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY;
7545 hr = IDirectDrawSurface4_GetAttachedSurface(frontbuffer, &caps, &backbuffer1);
7546 ok(SUCCEEDED(hr), "%s: Failed to get attached surface, hr %#lx.\n", test_data[i].name, hr);
7547 memset(&surface_desc, 0, sizeof(surface_desc));
7548 surface_desc.dwSize = sizeof(surface_desc);
7549 hr = IDirectDrawSurface4_GetSurfaceDesc(backbuffer1, &surface_desc);
7550 ok(SUCCEEDED(hr), "%s: Failed to get surface desc, hr %#lx.\n", test_data[i].name, hr);
7551 ok(!surface_desc.dwBackBufferCount, "%s: Got unexpected back buffer count %lu.\n",
7552 test_data[i].name, surface_desc.dwBackBufferCount);
7553 expected_caps &= ~(DDSCAPS_VISIBLE | DDSCAPS_PRIMARYSURFACE | DDSCAPS_FRONTBUFFER);
7554 expected_caps |= DDSCAPS_BACKBUFFER;
7555 ok((surface_desc.ddsCaps.dwCaps & ~placement) == expected_caps,
7556 "%s: Got unexpected caps %#lx.\n", test_data[i].name, surface_desc.ddsCaps.dwCaps);
7558 hr = IDirectDrawSurface4_GetAttachedSurface(backbuffer1, &caps, &backbuffer2);
7559 ok(SUCCEEDED(hr), "%s: Failed to get attached surface, hr %#lx.\n", test_data[i].name, hr);
7560 memset(&surface_desc, 0, sizeof(surface_desc));
7561 surface_desc.dwSize = sizeof(surface_desc);
7562 hr = IDirectDrawSurface4_GetSurfaceDesc(backbuffer2, &surface_desc);
7563 ok(SUCCEEDED(hr), "%s: Failed to get surface desc, hr %#lx.\n", test_data[i].name, hr);
7564 ok(!surface_desc.dwBackBufferCount, "%s: Got unexpected back buffer count %lu.\n",
7565 test_data[i].name, surface_desc.dwBackBufferCount);
7566 expected_caps &= ~DDSCAPS_BACKBUFFER;
7567 ok((surface_desc.ddsCaps.dwCaps & ~placement) == expected_caps,
7568 "%s: Got unexpected caps %#lx.\n", test_data[i].name, surface_desc.ddsCaps.dwCaps);
7570 hr = IDirectDrawSurface4_GetAttachedSurface(backbuffer2, &caps, &backbuffer3);
7571 ok(SUCCEEDED(hr), "%s: Failed to get attached surface, hr %#lx.\n", test_data[i].name, hr);
7572 memset(&surface_desc, 0, sizeof(surface_desc));
7573 surface_desc.dwSize = sizeof(surface_desc);
7574 hr = IDirectDrawSurface4_GetSurfaceDesc(backbuffer3, &surface_desc);
7575 ok(SUCCEEDED(hr), "%s: Failed to get surface desc, hr %#lx.\n", test_data[i].name, hr);
7576 ok(!surface_desc.dwBackBufferCount, "%s: Got unexpected back buffer count %lu.\n",
7577 test_data[i].name, surface_desc.dwBackBufferCount);
7578 ok((surface_desc.ddsCaps.dwCaps & ~placement) == expected_caps,
7579 "%s: Got unexpected caps %#lx.\n", test_data[i].name, surface_desc.ddsCaps.dwCaps);
7581 hr = IDirectDrawSurface4_GetAttachedSurface(backbuffer3, &caps, &surface);
7582 ok(SUCCEEDED(hr), "%s: Failed to get attached surface, hr %#lx.\n", test_data[i].name, hr);
7583 ok(surface == frontbuffer, "%s: Got unexpected surface %p, expected %p.\n",
7584 test_data[i].name, surface, frontbuffer);
7585 IDirectDrawSurface4_Release(surface);
7587 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL | DDSCL_FULLSCREEN);
7588 ok(SUCCEEDED(hr), "%s: Failed to set cooperative level, hr %#lx.\n", test_data[i].name, hr);
7589 hr = IDirectDrawSurface4_IsLost(frontbuffer);
7590 ok(hr == DD_OK, "%s: Got unexpected hr %#lx.\n", test_data[i].name, hr);
7591 hr = IDirectDrawSurface4_Flip(frontbuffer, NULL, DDFLIP_WAIT);
7592 if (test_data[i].caps & DDSCAPS_PRIMARYSURFACE)
7593 ok(hr == DDERR_NOEXCLUSIVEMODE, "%s: Got unexpected hr %#lx.\n", test_data[i].name, hr);
7594 else
7595 ok(SUCCEEDED(hr), "%s: Failed to flip, hr %#lx.\n", test_data[i].name, hr);
7596 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
7597 ok(SUCCEEDED(hr), "%s: Failed to set cooperative level, hr %#lx.\n", test_data[i].name, hr);
7598 hr = IDirectDrawSurface4_IsLost(frontbuffer);
7599 todo_wine ok(hr == DDERR_SURFACELOST, "%s: Got unexpected hr %#lx.\n", test_data[i].name, hr);
7600 hr = IDirectDraw4_RestoreAllSurfaces(ddraw);
7601 ok(SUCCEEDED(hr), "%s: Failed to restore surfaces, hr %#lx.\n", test_data[i].name, hr);
7603 memset(&surface_desc, 0, sizeof(surface_desc));
7604 surface_desc.dwSize = sizeof(surface_desc);
7605 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
7606 surface_desc.ddsCaps.dwCaps = 0;
7607 surface_desc.dwWidth = 640;
7608 surface_desc.dwHeight = 480;
7609 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7610 ok(SUCCEEDED(hr), "%s: Failed to create surface, hr %#lx.\n", test_data[i].name, hr);
7611 hr = IDirectDrawSurface4_Flip(frontbuffer, surface, DDFLIP_WAIT);
7612 ok(hr == DDERR_NOTFLIPPABLE, "%s: Got unexpected hr %#lx.\n", test_data[i].name, hr);
7613 IDirectDrawSurface4_Release(surface);
7615 hr = IDirectDrawSurface4_Flip(frontbuffer, frontbuffer, DDFLIP_WAIT);
7616 ok(hr == DDERR_NOTFLIPPABLE, "%s: Got unexpected hr %#lx.\n", test_data[i].name, hr);
7617 hr = IDirectDrawSurface4_Flip(backbuffer1, NULL, DDFLIP_WAIT);
7618 ok(hr == DDERR_NOTFLIPPABLE, "%s: Got unexpected hr %#lx.\n", test_data[i].name, hr);
7619 hr = IDirectDrawSurface4_Flip(backbuffer2, NULL, DDFLIP_WAIT);
7620 ok(hr == DDERR_NOTFLIPPABLE, "%s: Got unexpected hr %#lx.\n", test_data[i].name, hr);
7621 hr = IDirectDrawSurface4_Flip(backbuffer3, NULL, DDFLIP_WAIT);
7622 ok(hr == DDERR_NOTFLIPPABLE, "%s: Got unexpected hr %#lx.\n", test_data[i].name, hr);
7624 /* The Nvidia Geforce 7 driver cannot do a color fill on a texture backbuffer after
7625 * the backbuffer has been locked. Do it ourselves as a workaround. Unlike ddraw1
7626 * and 2 GetSurfaceDesc does not cause issues in ddraw4 and ddraw7. */
7627 fill_surface(backbuffer1, 0xffff0000);
7628 fill_surface(backbuffer2, 0xff00ff00);
7629 fill_surface(backbuffer3, 0xff0000ff);
7631 hr = IDirectDrawSurface4_Flip(frontbuffer, NULL, DDFLIP_WAIT);
7632 ok(SUCCEEDED(hr), "%s: Failed to flip, hr %#lx.\n", test_data[i].name, hr);
7633 color = get_surface_color(backbuffer1, 320, 240);
7634 /* The testbot seems to just copy the contents of one surface to all the
7635 * others, instead of properly flipping. */
7636 ok(compare_color(color, 0x0000ff00, 1) || broken(sysmem_primary && compare_color(color, 0x000000ff, 1)),
7637 "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
7638 color = get_surface_color(backbuffer2, 320, 240);
7639 ok(compare_color(color, 0x000000ff, 1), "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
7640 fill_surface(backbuffer3, 0xffff0000);
7642 hr = IDirectDrawSurface4_Flip(frontbuffer, NULL, DDFLIP_WAIT);
7643 ok(SUCCEEDED(hr), "%s: Failed to flip, hr %#lx.\n", test_data[i].name, hr);
7644 color = get_surface_color(backbuffer1, 320, 240);
7645 ok(compare_color(color, 0x000000ff, 1) || broken(sysmem_primary && compare_color(color, 0x00ff0000, 1)),
7646 "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
7647 color = get_surface_color(backbuffer2, 320, 240);
7648 ok(compare_color(color, 0x00ff0000, 1), "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
7649 fill_surface(backbuffer3, 0xff00ff00);
7651 hr = IDirectDrawSurface4_Flip(frontbuffer, NULL, DDFLIP_WAIT);
7652 ok(SUCCEEDED(hr), "%s: Failed to flip, hr %#lx.\n", test_data[i].name, hr);
7653 color = get_surface_color(backbuffer1, 320, 240);
7654 ok(compare_color(color, 0x00ff0000, 1) || broken(sysmem_primary && compare_color(color, 0x0000ff00, 1)),
7655 "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
7656 color = get_surface_color(backbuffer2, 320, 240);
7657 ok(compare_color(color, 0x0000ff00, 1), "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
7658 fill_surface(backbuffer3, 0xff0000ff);
7660 hr = IDirectDrawSurface4_Flip(frontbuffer, backbuffer1, DDFLIP_WAIT);
7661 ok(SUCCEEDED(hr), "%s: Failed to flip, hr %#lx.\n", test_data[i].name, hr);
7662 color = get_surface_color(backbuffer2, 320, 240);
7663 ok(compare_color(color, 0x0000ff00, 1) || broken(sysmem_primary && compare_color(color, 0x000000ff, 1)),
7664 "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
7665 color = get_surface_color(backbuffer3, 320, 240);
7666 ok(compare_color(color, 0x000000ff, 1), "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
7667 fill_surface(backbuffer1, 0xffff0000);
7669 hr = IDirectDrawSurface4_Flip(frontbuffer, backbuffer2, DDFLIP_WAIT);
7670 ok(SUCCEEDED(hr), "%s: Failed to flip, hr %#lx.\n", test_data[i].name, hr);
7671 color = get_surface_color(backbuffer1, 320, 240);
7672 ok(compare_color(color, 0x00ff0000, 1), "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
7673 color = get_surface_color(backbuffer3, 320, 240);
7674 ok(compare_color(color, 0x000000ff, 1) || broken(sysmem_primary && compare_color(color, 0x00ff0000, 1)),
7675 "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
7676 fill_surface(backbuffer2, 0xff00ff00);
7678 hr = IDirectDrawSurface4_Flip(frontbuffer, backbuffer3, DDFLIP_WAIT);
7679 ok(SUCCEEDED(hr), "%s: Failed to flip, hr %#lx.\n", test_data[i].name, hr);
7680 color = get_surface_color(backbuffer1, 320, 240);
7681 ok(compare_color(color, 0x00ff0000, 1) || broken(sysmem_primary && compare_color(color, 0x0000ff00, 1)),
7682 "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
7683 color = get_surface_color(backbuffer2, 320, 240);
7684 ok(compare_color(color, 0x0000ff00, 1), "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
7686 IDirectDrawSurface4_Release(backbuffer3);
7687 IDirectDrawSurface4_Release(backbuffer2);
7688 IDirectDrawSurface4_Release(backbuffer1);
7689 IDirectDrawSurface4_Release(frontbuffer);
7692 refcount = IDirectDraw4_Release(ddraw);
7693 ok(!refcount, "Unexpected refcount %lu.\n", refcount);
7694 DestroyWindow(window);
7697 static void reset_ddsd(DDSURFACEDESC2 *ddsd)
7699 memset(ddsd, 0, sizeof(*ddsd));
7700 ddsd->dwSize = sizeof(*ddsd);
7703 static void test_set_surface_desc(void)
7705 IDirectDraw4 *ddraw;
7706 HWND window;
7707 HRESULT hr;
7708 DDSURFACEDESC2 ddsd;
7709 IDirectDrawSurface4 *surface;
7710 BYTE data[16*16*4];
7711 ULONG ref;
7712 unsigned int i;
7713 static const struct
7715 DWORD caps, caps2;
7716 BOOL supported;
7717 const char *name;
7719 invalid_caps_tests[] =
7721 {DDSCAPS_VIDEOMEMORY, 0, FALSE, "videomemory plain"},
7722 {DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, 0, TRUE, "systemmemory texture"},
7723 {DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, FALSE, "managed texture"},
7724 {DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, FALSE, "managed texture"},
7725 {DDSCAPS_PRIMARYSURFACE | DDSCAPS_SYSTEMMEMORY, 0, FALSE, "systemmemory primary"},
7728 window = create_window();
7729 ddraw = create_ddraw();
7730 ok(!!ddraw, "Failed to create a ddraw object.\n");
7731 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
7732 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
7734 reset_ddsd(&ddsd);
7735 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_PIXELFORMAT;
7736 ddsd.dwWidth = 8;
7737 ddsd.dwHeight = 8;
7738 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
7739 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
7740 ddsd.ddpfPixelFormat.dwRGBBitCount = 32;
7741 ddsd.ddpfPixelFormat.dwRBitMask = 0x00ff0000;
7742 ddsd.ddpfPixelFormat.dwGBitMask = 0x0000ff00;
7743 ddsd.ddpfPixelFormat.dwBBitMask = 0x000000ff;
7744 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
7746 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
7747 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
7749 reset_ddsd(&ddsd);
7750 ddsd.dwFlags = DDSD_LPSURFACE;
7751 ddsd.lpSurface = data;
7752 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
7753 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#lx.\n", hr);
7755 /* Redundantly setting the same lpSurface is not an error. */
7756 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
7757 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#lx.\n", hr);
7758 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &ddsd);
7759 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#lx.\n", hr);
7760 ok(!(ddsd.dwFlags & DDSD_LPSURFACE), "DDSD_LPSURFACE is set.\n");
7761 ok(ddsd.lpSurface == NULL, "lpSurface is %p, expected NULL.\n", ddsd.lpSurface);
7763 hr = IDirectDrawSurface4_Lock(surface, NULL, &ddsd, 0, NULL);
7764 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#lx.\n", hr);
7765 ok(!(ddsd.dwFlags & DDSD_LPSURFACE), "DDSD_LPSURFACE is set.\n");
7766 ok(ddsd.lpSurface == data, "lpSurface is %p, expected %p.\n", data, data);
7767 hr = IDirectDrawSurface4_Unlock(surface, NULL);
7768 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx.\n", hr);
7770 reset_ddsd(&ddsd);
7771 ddsd.dwFlags = DDSD_LPSURFACE;
7772 ddsd.lpSurface = data;
7773 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 1);
7774 ok(hr == DDERR_INVALIDPARAMS, "Got hr %#lx.\n", hr);
7776 ddsd.lpSurface = NULL;
7777 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
7778 ok(hr == DDERR_INVALIDPARAMS, "Got hr %#lx.\n", hr);
7780 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, NULL, 0);
7781 ok(hr == DDERR_INVALIDPARAMS, "Got hr %#lx.\n", hr);
7783 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &ddsd);
7784 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#lx.\n", hr);
7785 ok(ddsd.ddsCaps.dwCaps == (DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN),
7786 "Got unexpected caps %#lx.\n", ddsd.ddsCaps.dwCaps);
7787 ok(ddsd.ddsCaps.dwCaps2 == 0, "Got unexpected caps2 %#lx.\n", ddsd.ddsCaps.dwCaps2);
7789 /* Setting the caps is an error. This also means the original description cannot be reapplied. */
7790 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
7791 ok(hr == DDERR_INVALIDPARAMS, "Got hr %#lx.\n", hr);
7793 ddsd.dwFlags = DDSD_CAPS;
7794 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
7795 ok(hr == DDERR_INVALIDPARAMS, "Got hr %#lx.\n", hr);
7797 /* dwCaps = 0 is allowed, but ignored. Caps2 can be anything and is ignored too. */
7798 ddsd.dwFlags = DDSD_CAPS | DDSD_LPSURFACE;
7799 ddsd.lpSurface = data;
7800 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
7801 ok(hr == DDERR_INVALIDCAPS, "Got hr %#lx.\n", hr);
7802 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
7803 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
7804 ok(hr == DDERR_INVALIDCAPS, "Got hr %#lx.\n", hr);
7805 ddsd.ddsCaps.dwCaps = 0;
7806 ddsd.ddsCaps.dwCaps2 = 0xdeadbeef;
7807 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
7808 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#lx.\n", hr);
7810 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &ddsd);
7811 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#lx.\n", hr);
7812 ok(ddsd.ddsCaps.dwCaps == (DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN),
7813 "Got unexpected caps %#lx.\n", ddsd.ddsCaps.dwCaps);
7814 ok(ddsd.ddsCaps.dwCaps2 == 0, "Got unexpected caps2 %#lx.\n", ddsd.ddsCaps.dwCaps2);
7816 /* Setting the height is allowed, but it cannot be set to 0, and only if LPSURFACE is set too. */
7817 reset_ddsd(&ddsd);
7818 ddsd.dwFlags = DDSD_HEIGHT;
7819 ddsd.dwHeight = 16;
7820 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
7821 ok(hr == DDERR_INVALIDPARAMS, "Got hr %#lx.\n", hr);
7823 ddsd.lpSurface = data;
7824 ddsd.dwFlags = DDSD_HEIGHT | DDSD_LPSURFACE;
7825 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
7826 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#lx.\n", hr);
7828 ddsd.dwHeight = 0;
7829 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
7830 ok(hr == DDERR_INVALIDPARAMS, "Got hr %#lx.\n", hr);
7832 reset_ddsd(&ddsd);
7833 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &ddsd);
7834 ok(SUCCEEDED(hr), "GetSurfaceDesc failed, hr %#lx.\n", hr);
7835 ok(ddsd.dwWidth == 8, "SetSurfaceDesc: Expected width 8, got %lu.\n", ddsd.dwWidth);
7836 ok(ddsd.dwHeight == 16, "SetSurfaceDesc: Expected height 16, got %lu.\n", ddsd.dwHeight);
7838 /* Pitch and width can be set, but only together, and only with LPSURFACE. They must not be 0 */
7839 reset_ddsd(&ddsd);
7840 ddsd.dwFlags = DDSD_PITCH;
7841 ddsd.lPitch = 8 * 4;
7842 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
7843 ok(hr == DDERR_INVALIDPARAMS, "Got hr %#lx.\n", hr);
7845 ddsd.dwFlags = DDSD_WIDTH;
7846 ddsd.dwWidth = 16;
7847 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
7848 ok(hr == DDERR_INVALIDPARAMS, "Got hr %#lx.\n", hr);
7850 ddsd.dwFlags = DDSD_PITCH | DDSD_LPSURFACE;
7851 ddsd.lpSurface = data;
7852 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
7853 ok(hr == DDERR_INVALIDPARAMS, "Got hr %#lx.\n", hr);
7855 ddsd.dwFlags = DDSD_WIDTH | DDSD_LPSURFACE;
7856 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
7857 ok(hr == DDERR_INVALIDPARAMS, "Got hr %#lx.\n", hr);
7859 ddsd.dwFlags = DDSD_WIDTH | DDSD_PITCH | DDSD_LPSURFACE;
7860 ddsd.lPitch = 16 * 4;
7861 ddsd.dwWidth = 16;
7862 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
7863 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#lx.\n", hr);
7865 reset_ddsd(&ddsd);
7866 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &ddsd);
7867 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#lx.\n", hr);
7868 ok(ddsd.dwWidth == 16, "SetSurfaceDesc: Expected width 8, got %lu.\n", ddsd.dwWidth);
7869 ok(ddsd.dwHeight == 16, "SetSurfaceDesc: Expected height 16, got %lu.\n", ddsd.dwHeight);
7870 ok(ddsd.lPitch == 16 * 4, "SetSurfaceDesc: Expected pitch 64, got %lu.\n", ddsd.lPitch);
7872 /* The pitch must be 32 bit aligned and > 0, but is not verified for sanity otherwise.
7874 * VMware rejects those calls, but all real drivers accept it. Mark the VMware behavior broken. */
7875 ddsd.dwFlags = DDSD_WIDTH | DDSD_PITCH | DDSD_LPSURFACE;
7876 ddsd.lPitch = 4 * 4;
7877 ddsd.lpSurface = data;
7878 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
7879 ok(SUCCEEDED(hr) || broken(hr == DDERR_INVALIDPARAMS), "Failed to set surface desc, hr %#lx.\n", hr);
7881 ddsd.lPitch = 4;
7882 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
7883 ok(SUCCEEDED(hr) || broken(hr == DDERR_INVALIDPARAMS), "Failed to set surface desc, hr %#lx.\n", hr);
7885 ddsd.lPitch = 16 * 4 + 1;
7886 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
7887 ok(hr == DDERR_INVALIDPARAMS, "Got hr %#lx.\n", hr);
7889 ddsd.lPitch = 16 * 4 + 3;
7890 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
7891 ok(hr == DDERR_INVALIDPARAMS, "Got hr %#lx.\n", hr);
7893 ddsd.lPitch = -4;
7894 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
7895 ok(hr == DDERR_INVALIDPARAMS, "Got hr %#lx.\n", hr);
7897 ddsd.lPitch = 16 * 4;
7898 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
7899 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#lx.\n", hr);
7901 reset_ddsd(&ddsd);
7902 ddsd.dwFlags = DDSD_WIDTH | DDSD_PITCH | DDSD_LPSURFACE;
7903 ddsd.lPitch = 0;
7904 ddsd.dwWidth = 16;
7905 ddsd.lpSurface = data;
7906 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
7907 ok(hr == DDERR_INVALIDPARAMS, "Got hr %#lx.\n", hr);
7909 ddsd.dwFlags = DDSD_WIDTH | DDSD_PITCH | DDSD_LPSURFACE;
7910 ddsd.lPitch = 16 * 4;
7911 ddsd.dwWidth = 0;
7912 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
7913 ok(hr == DDERR_INVALIDPARAMS, "Got hr %#lx.\n", hr);
7915 /* Setting the pixelformat without LPSURFACE is an error, but with LPSURFACE it works. */
7916 ddsd.dwFlags = DDSD_PIXELFORMAT;
7917 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
7918 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
7919 ddsd.ddpfPixelFormat.dwRGBBitCount = 32;
7920 ddsd.ddpfPixelFormat.dwRBitMask = 0x00ff0000;
7921 ddsd.ddpfPixelFormat.dwGBitMask = 0x0000ff00;
7922 ddsd.ddpfPixelFormat.dwBBitMask = 0x000000ff;
7923 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
7924 ok(hr == DDERR_INVALIDPARAMS, "Got hr %#lx.\n", hr);
7926 ddsd.dwFlags = DDSD_PIXELFORMAT | DDSD_LPSURFACE;
7927 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
7928 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#lx.\n", hr);
7930 /* Can't set color keys. */
7931 reset_ddsd(&ddsd);
7932 ddsd.dwFlags = DDSD_CKSRCBLT;
7933 ddsd.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00ff0000;
7934 ddsd.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00ff0000;
7935 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
7936 ok(hr == DDERR_INVALIDPARAMS, "Got hr %#lx.\n", hr);
7938 ddsd.dwFlags = DDSD_CKSRCBLT | DDSD_LPSURFACE;
7939 ddsd.lpSurface = data;
7940 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
7941 ok(hr == DDERR_INVALIDPARAMS, "Got hr %#lx.\n", hr);
7943 /* Check that other surface properties are retained. */
7945 ddsd.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00ff00ff;
7946 ddsd.ddckCKSrcBlt.dwColorSpaceHighValue = 0x0000ff00;
7947 hr = IDirectDrawSurface4_SetColorKey(surface, DDCKEY_SRCBLT, &ddsd.ddckCKSrcBlt);
7948 ok(hr == S_OK, "Got hr %#lx.\n", hr);
7950 reset_ddsd(&ddsd);
7951 ddsd.dwFlags = DDSD_WIDTH | DDSD_PITCH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_LPSURFACE;
7952 ddsd.dwWidth = 8;
7953 ddsd.lPitch = 8 * 2;
7954 ddsd.dwHeight = 8;
7955 ddsd.lpSurface = data;
7956 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
7957 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB; /* D3DFMT_R5G6B5 */
7958 ddsd.ddpfPixelFormat.dwRGBBitCount = 16;
7959 ddsd.ddpfPixelFormat.dwRBitMask = 0xf800;
7960 ddsd.ddpfPixelFormat.dwGBitMask = 0x07e0;
7961 ddsd.ddpfPixelFormat.dwBBitMask = 0x001f;
7962 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
7963 ok(hr == S_OK, "Got hr %#lx.\n", hr);
7965 memset(&ddsd.ddckCKSrcBlt, 0xcc, sizeof(ddsd.ddckCKSrcBlt));
7966 hr = IDirectDrawSurface4_GetColorKey(surface, DDCKEY_SRCBLT, &ddsd.ddckCKSrcBlt);
7967 ok(hr == S_OK, "Got hr %#lx.\n", hr);
7968 ok(ddsd.ddckCKSrcBlt.dwColorSpaceLowValue == 0x00ff00ff,
7969 "Got low color key value %#lx.\n", ddsd.ddckCKSrcBlt.dwColorSpaceLowValue);
7971 IDirectDrawSurface4_Release(surface);
7973 /* Test mipmap texture. */
7974 reset_ddsd(&ddsd);
7975 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_MIPMAPCOUNT;
7976 ddsd.dwWidth = 8;
7977 ddsd.dwHeight = 8;
7978 ddsd.dwMipMapCount = 3;
7979 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
7981 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
7982 ok(hr == DD_OK || hr == DDERR_NODIRECTDRAWHW || hr == E_NOINTERFACE, "Got unexpected hr %#lx.\n", hr);
7984 if (FAILED(hr))
7986 skip("Mipmaps are not supported.\n");
7988 else
7990 /* Changing surface desc for mipmap fails even without changing any
7991 * parameters. */
7992 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
7993 ok(hr == DDERR_INVALIDSURFACETYPE, "Got unexpected hr %#lx.\n", hr);
7995 reset_ddsd(&ddsd);
7996 ddsd.dwFlags = DDSD_LPSURFACE;
7997 ddsd.lpSurface = data;
7998 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
7999 ok(hr == DDERR_INVALIDSURFACETYPE, "Got unexpected hr %#lx.\n", hr);
8000 IDirectDrawSurface4_Release(surface);
8003 reset_ddsd(&ddsd);
8004 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_MIPMAPCOUNT;
8005 ddsd.dwWidth = 8;
8006 ddsd.dwHeight = 8;
8007 ddsd.dwMipMapCount = 3;
8008 ddsd.lpSurface = data;
8009 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
8011 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
8012 ok(hr == DD_OK || hr == DDERR_NODIRECTDRAWHW || hr == E_NOINTERFACE, "Got unexpected hr %#lx.\n", hr);
8014 if (hr == DD_OK)
8016 static DDSCAPS2 caps = {DDSCAPS_TEXTURE, 0, 0, {0}};
8017 IDirectDrawSurface4 *surface2;
8019 hr = IDirectDrawSurface4_GetAttachedSurface(surface, &caps, &surface2);
8020 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
8021 reset_ddsd(&ddsd);
8022 hr = IDirectDrawSurface4_GetSurfaceDesc(surface2, &ddsd);
8023 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
8024 ok(ddsd.dwWidth == 4, "Got unexpected dwWidth %lu.\n", ddsd.dwWidth);
8026 reset_ddsd(&ddsd);
8027 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH | DDSD_LPSURFACE;
8028 ddsd.dwWidth = 16;
8029 ddsd.dwHeight = 16;
8030 ddsd.lPitch = 16 * 4;
8031 ddsd.lpSurface = data;
8032 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
8033 todo_wine ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
8035 reset_ddsd(&ddsd);
8036 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH | DDSD_LPSURFACE;
8037 ddsd.dwWidth = 8;
8038 ddsd.dwHeight = 8;
8039 ddsd.lPitch = 8 * 4;
8040 ddsd.lpSurface = data;
8041 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
8042 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
8043 if (0)
8045 /* _Lock causes access violation on Windows. */
8046 reset_ddsd(&ddsd);
8047 hr = IDirectDrawSurface4_Lock(surface2, NULL, &ddsd, DDLOCK_WAIT, NULL);
8048 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
8049 IDirectDrawSurface4_Unlock(surface2, NULL);
8052 reset_ddsd(&ddsd);
8053 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH | DDSD_LPSURFACE;
8054 ddsd.dwWidth = 4;
8055 ddsd.dwHeight = 4;
8056 ddsd.lPitch = 4 * 4;
8057 ddsd.lpSurface = data;
8058 hr = IDirectDrawSurface4_SetSurfaceDesc(surface2, &ddsd, 0);
8059 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
8061 reset_ddsd(&ddsd);
8062 /* Does not crash now after setting user memory for the level. */
8063 hr = IDirectDrawSurface4_Lock(surface2, NULL, &ddsd, DDLOCK_WAIT, NULL);
8064 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
8065 ok(ddsd.lpSurface == data, "Got unexpected lpSurface %p.\n", ddsd.lpSurface);
8066 IDirectDrawSurface4_Unlock(surface2, NULL);
8068 reset_ddsd(&ddsd);
8069 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH | DDSD_LPSURFACE;
8070 ddsd.dwWidth = 16;
8071 ddsd.dwHeight = 16;
8072 ddsd.lPitch = 16 * 4;
8073 ddsd.lpSurface = data;
8074 hr = IDirectDrawSurface4_SetSurfaceDesc(surface2, &ddsd, 0);
8075 todo_wine ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
8077 IDirectDrawSurface4_Release(surface2);
8078 IDirectDrawSurface4_Release(surface);
8081 /* Test surface created with DDSD_LPSURFACE. */
8082 reset_ddsd(&ddsd);
8083 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LPSURFACE | DDSD_PITCH;
8084 ddsd.dwWidth = 8;
8085 ddsd.dwHeight = 8;
8086 ddsd.lpSurface = data;
8087 ddsd.lPitch = 8 * 4;
8088 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
8089 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
8090 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
8092 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
8093 ok(hr == DDERR_INVALIDCAPS, "Got unexpected hr %#lx.\n", hr);
8095 reset_ddsd(&ddsd);
8096 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
8097 ddsd.dwWidth = 8;
8098 ddsd.dwHeight = 8;
8099 /* Cannot reset lpSurface. */
8100 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
8101 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
8103 reset_ddsd(&ddsd);
8104 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_LPSURFACE | DDSD_PITCH;
8105 ddsd.dwWidth = 4;
8106 ddsd.dwHeight = 4;
8107 ddsd.lpSurface = data;
8108 ddsd.lPitch = 8 * 4;
8109 /* Can change the parameters of surface created with DDSD_LPSURFACE. */
8110 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
8111 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
8113 IDirectDrawSurface4_Release(surface);
8115 /* SetSurfaceDesc needs systemmemory surfaces.
8117 * As a sidenote, fourcc surfaces aren't allowed in sysmem, thus testing DDSD_LINEARSIZE is moot. */
8118 for (i = 0; i < ARRAY_SIZE(invalid_caps_tests); i++)
8120 reset_ddsd(&ddsd);
8121 ddsd.dwFlags = DDSD_CAPS;
8122 ddsd.ddsCaps.dwCaps = invalid_caps_tests[i].caps;
8123 ddsd.ddsCaps.dwCaps2 = invalid_caps_tests[i].caps2;
8124 if (!(invalid_caps_tests[i].caps & DDSCAPS_PRIMARYSURFACE))
8126 ddsd.dwFlags |= DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
8127 ddsd.dwWidth = 8;
8128 ddsd.dwHeight = 8;
8129 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
8130 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
8131 ddsd.ddpfPixelFormat.dwRGBBitCount = 32;
8132 ddsd.ddpfPixelFormat.dwRBitMask = 0x00ff0000;
8133 ddsd.ddpfPixelFormat.dwGBitMask = 0x0000ff00;
8134 ddsd.ddpfPixelFormat.dwBBitMask = 0x000000ff;
8137 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
8138 ok(hr == DD_OK || hr == DDERR_NODIRECTDRAWHW, "Got unexpected hr %#lx.\n", hr);
8139 if (FAILED(hr))
8141 skip("Cannot create a %s surface, skipping vidmem SetSurfaceDesc test.\n",
8142 invalid_caps_tests[i].name);
8143 goto done;
8146 reset_ddsd(&ddsd);
8147 ddsd.dwFlags = DDSD_LPSURFACE;
8148 ddsd.lpSurface = data;
8149 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
8150 if (invalid_caps_tests[i].supported)
8152 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
8154 else
8156 ok(hr == DDERR_INVALIDSURFACETYPE, "SetSurfaceDesc on a %s surface returned %#lx.\n",
8157 invalid_caps_tests[i].name, hr);
8159 /* Check priority of error conditions. */
8160 ddsd.dwFlags = DDSD_WIDTH;
8161 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
8162 ok(hr == DDERR_INVALIDSURFACETYPE, "SetSurfaceDesc on a %s surface returned %#lx.\n",
8163 invalid_caps_tests[i].name, hr);
8166 IDirectDrawSurface4_Release(surface);
8169 done:
8170 ref = IDirectDraw4_Release(ddraw);
8171 ok(!ref, "Unexpected refcount %lu.\n", ref);
8172 DestroyWindow(window);
8175 static void test_user_memory_getdc(void)
8177 unsigned int data[16][16], x, y;
8178 IDirectDraw4 *ddraw;
8179 HWND window;
8180 HRESULT hr;
8181 DDSURFACEDESC2 ddsd;
8182 IDirectDrawSurface4 *surface;
8183 HBITMAP bitmap;
8184 DIBSECTION dib;
8185 ULONG ref;
8186 int size;
8187 HDC dc;
8189 window = create_window();
8190 ddraw = create_ddraw();
8191 ok(!!ddraw, "Failed to create a ddraw object.\n");
8193 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
8194 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
8196 reset_ddsd(&ddsd);
8197 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_PIXELFORMAT;
8198 ddsd.dwWidth = 16;
8199 ddsd.dwHeight = 16;
8200 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
8201 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
8202 ddsd.ddpfPixelFormat.dwRGBBitCount = 32;
8203 ddsd.ddpfPixelFormat.dwRBitMask = 0x00ff0000;
8204 ddsd.ddpfPixelFormat.dwGBitMask = 0x0000ff00;
8205 ddsd.ddpfPixelFormat.dwBBitMask = 0x000000ff;
8206 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
8207 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
8208 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
8210 memset(data, 0xaa, sizeof(data));
8211 reset_ddsd(&ddsd);
8212 ddsd.dwFlags = DDSD_LPSURFACE;
8213 ddsd.lpSurface = data;
8214 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
8215 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#lx.\n", hr);
8217 hr = IDirectDrawSurface4_GetDC(surface, &dc);
8218 ok(SUCCEEDED(hr), "Failed to get DC, hr %#lx.\n", hr);
8219 bitmap = GetCurrentObject(dc, OBJ_BITMAP);
8220 ok(!!bitmap, "Failed to get bitmap.\n");
8221 size = GetObjectA(bitmap, sizeof(dib), &dib);
8222 ok(size == sizeof(dib), "Got unexpected size %d.\n", size);
8223 ok(dib.dsBm.bmBits == data, "Got unexpected bits %p, expected %p.\n", dib.dsBm.bmBits, data);
8224 BitBlt(dc, 0, 0, 16, 8, NULL, 0, 0, WHITENESS);
8225 BitBlt(dc, 0, 8, 16, 8, NULL, 0, 0, BLACKNESS);
8226 hr = IDirectDrawSurface4_ReleaseDC(surface, dc);
8227 ok(SUCCEEDED(hr), "Failed to release DC, hr %#lx.\n", hr);
8229 ok(data[0][0] == 0xffffffff, "Expected color 0xffffffff, got %#x.\n", data[0][0]);
8230 ok(data[15][15] == 0x00000000, "Expected color 0x00000000, got %#x.\n", data[15][15]);
8232 ddsd.dwFlags = DDSD_LPSURFACE | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PITCH;
8233 ddsd.lpSurface = data;
8234 ddsd.dwWidth = 4;
8235 ddsd.dwHeight = 8;
8236 ddsd.lPitch = sizeof(*data);
8237 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
8238 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#lx.\n", hr);
8240 memset(data, 0xaa, sizeof(data));
8241 hr = IDirectDrawSurface4_GetDC(surface, &dc);
8242 ok(SUCCEEDED(hr), "Failed to get DC, hr %#lx.\n", hr);
8243 BitBlt(dc, 0, 0, 4, 8, NULL, 0, 0, BLACKNESS);
8244 BitBlt(dc, 1, 1, 2, 2, NULL, 0, 0, WHITENESS);
8245 hr = IDirectDrawSurface4_ReleaseDC(surface, dc);
8246 ok(SUCCEEDED(hr), "Failed to release DC, hr %#lx.\n", hr);
8248 for (y = 0; y < 4; y++)
8250 for (x = 0; x < 4; x++)
8252 if ((x == 1 || x == 2) && (y == 1 || y == 2))
8253 ok(data[y][x] == 0xffffffff, "Expected color 0xffffffff on position %ux%u, got %#x.\n",
8254 x, y, data[y][x]);
8255 else
8256 ok(data[y][x] == 0x00000000, "Expected color 0x00000000 on position %ux%u, got %#x.\n",
8257 x, y, data[y][x]);
8260 ok(data[0][5] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 5x0, got %#x.\n",
8261 data[0][5]);
8262 ok(data[7][3] == 0x00000000, "Expected color 0x00000000 on position 3x7, got %#x.\n",
8263 data[7][3]);
8264 ok(data[7][4] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 4x7, got %#x.\n",
8265 data[7][4]);
8266 ok(data[8][0] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 0x8, got %#x.\n",
8267 data[8][0]);
8269 IDirectDrawSurface4_Release(surface);
8270 ref = IDirectDraw4_Release(ddraw);
8271 ok(!ref, "Unexpected refcount %lu.\n", ref);
8272 DestroyWindow(window);
8275 static void test_sysmem_overlay(void)
8277 IDirectDraw4 *ddraw;
8278 HWND window;
8279 HRESULT hr;
8280 DDSURFACEDESC2 ddsd;
8281 IDirectDrawSurface4 *surface;
8282 ULONG ref;
8284 window = create_window();
8285 ddraw = create_ddraw();
8286 ok(!!ddraw, "Failed to create a ddraw object.\n");
8288 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
8289 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
8291 reset_ddsd(&ddsd);
8292 ddsd.dwFlags = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT;
8293 ddsd.dwWidth = 16;
8294 ddsd.dwHeight = 16;
8295 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OVERLAY;
8296 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
8297 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
8298 ddsd.ddpfPixelFormat.dwRGBBitCount = 32;
8299 ddsd.ddpfPixelFormat.dwRBitMask = 0x00ff0000;
8300 ddsd.ddpfPixelFormat.dwGBitMask = 0x0000ff00;
8301 ddsd.ddpfPixelFormat.dwBBitMask = 0x000000ff;
8302 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
8303 ok(hr == DDERR_NOOVERLAYHW, "Got unexpected hr %#lx.\n", hr);
8305 ref = IDirectDraw4_Release(ddraw);
8306 ok(!ref, "Unexpected refcount %lu.\n", ref);
8307 DestroyWindow(window);
8310 static void test_primary_palette(void)
8312 DDSCAPS2 surface_caps = {DDSCAPS_FLIP, 0, 0, {0}};
8313 IDirectDrawSurface4 *primary, *backbuffer;
8314 PALETTEENTRY palette_entries[256];
8315 IDirectDrawPalette *palette, *tmp;
8316 DDSURFACEDESC2 surface_desc;
8317 IDirectDraw4 *ddraw;
8318 DWORD palette_caps;
8319 ULONG refcount;
8320 HWND window;
8321 HRESULT hr;
8323 window = create_window();
8324 ddraw = create_ddraw();
8325 ok(!!ddraw, "Failed to create a ddraw object.\n");
8326 if (FAILED(IDirectDraw4_SetDisplayMode(ddraw, 640, 480, 8, 0, 0)))
8328 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
8329 IDirectDraw4_Release(ddraw);
8330 DestroyWindow(window);
8331 return;
8333 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
8334 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
8336 memset(&surface_desc, 0, sizeof(surface_desc));
8337 surface_desc.dwSize = sizeof(surface_desc);
8338 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
8339 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
8340 surface_desc.dwBackBufferCount = 1;
8341 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &primary, NULL);
8342 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
8343 hr = IDirectDrawSurface4_GetAttachedSurface(primary, &surface_caps, &backbuffer);
8344 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#lx.\n", hr);
8346 memset(palette_entries, 0, sizeof(palette_entries));
8347 hr = IDirectDraw4_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256, palette_entries, &palette, NULL);
8348 ok(SUCCEEDED(hr), "Failed to create palette, hr %#lx.\n", hr);
8349 refcount = get_refcount((IUnknown *)palette);
8350 ok(refcount == 1, "Got unexpected refcount %lu.\n", refcount);
8352 hr = IDirectDrawPalette_GetCaps(palette, &palette_caps);
8353 ok(SUCCEEDED(hr), "Failed to get palette caps, hr %#lx.\n", hr);
8354 ok(palette_caps == (DDPCAPS_8BIT | DDPCAPS_ALLOW256), "Got unexpected palette caps %#lx.\n", palette_caps);
8356 hr = IDirectDrawSurface4_SetPalette(primary, palette);
8357 ok(SUCCEEDED(hr), "Failed to set palette, hr %#lx.\n", hr);
8359 /* The Windows 8 testbot attaches the palette to the backbuffer as well,
8360 * and is generally somewhat broken with respect to 8 bpp / palette
8361 * handling. */
8362 if (SUCCEEDED(IDirectDrawSurface4_GetPalette(backbuffer, &tmp)))
8364 win_skip("Broken palette handling detected, skipping tests.\n");
8365 IDirectDrawPalette_Release(tmp);
8366 IDirectDrawPalette_Release(palette);
8367 /* The Windows 8 testbot keeps extra references to the primary and
8368 * backbuffer while in 8 bpp mode. */
8369 hr = IDirectDraw4_RestoreDisplayMode(ddraw);
8370 ok(SUCCEEDED(hr), "Failed to restore display mode, hr %#lx.\n", hr);
8371 goto done;
8374 refcount = get_refcount((IUnknown *)palette);
8375 ok(refcount == 2, "Got unexpected refcount %lu.\n", refcount);
8377 hr = IDirectDrawPalette_GetCaps(palette, &palette_caps);
8378 ok(SUCCEEDED(hr), "Failed to get palette caps, hr %#lx.\n", hr);
8379 ok(palette_caps == (DDPCAPS_8BIT | DDPCAPS_PRIMARYSURFACE | DDPCAPS_ALLOW256),
8380 "Got unexpected palette caps %#lx.\n", palette_caps);
8382 hr = IDirectDrawSurface4_SetPalette(primary, NULL);
8383 ok(SUCCEEDED(hr), "Failed to set palette, hr %#lx.\n", hr);
8384 refcount = get_refcount((IUnknown *)palette);
8385 ok(refcount == 1, "Got unexpected refcount %lu.\n", refcount);
8387 hr = IDirectDrawPalette_GetCaps(palette, &palette_caps);
8388 ok(SUCCEEDED(hr), "Failed to get palette caps, hr %#lx.\n", hr);
8389 ok(palette_caps == (DDPCAPS_8BIT | DDPCAPS_ALLOW256), "Got unexpected palette caps %#lx.\n", palette_caps);
8391 hr = IDirectDrawSurface4_SetPalette(primary, palette);
8392 ok(SUCCEEDED(hr), "Failed to set palette, hr %#lx.\n", hr);
8393 refcount = get_refcount((IUnknown *)palette);
8394 ok(refcount == 2, "Got unexpected refcount %lu.\n", refcount);
8396 hr = IDirectDrawSurface4_GetPalette(primary, &tmp);
8397 ok(SUCCEEDED(hr), "Failed to get palette, hr %#lx.\n", hr);
8398 ok(tmp == palette, "Got unexpected palette %p, expected %p.\n", tmp, palette);
8399 IDirectDrawPalette_Release(tmp);
8400 hr = IDirectDrawSurface4_GetPalette(backbuffer, &tmp);
8401 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#lx.\n", hr);
8403 refcount = IDirectDrawPalette_Release(palette);
8404 ok(refcount == 1, "Got unexpected refcount %lu.\n", refcount);
8405 refcount = IDirectDrawPalette_Release(palette);
8406 ok(!refcount, "Got unexpected refcount %lu.\n", refcount);
8408 /* Note that this only seems to work when the palette is attached to the
8409 * primary surface. When attached to a regular surface, attempting to get
8410 * the palette here will cause an access violation. */
8411 hr = IDirectDrawSurface4_GetPalette(primary, &tmp);
8412 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#lx.\n", hr);
8414 hr = IDirectDrawSurface4_IsLost(primary);
8415 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
8417 memset(&surface_desc, 0, sizeof(surface_desc));
8418 surface_desc.dwSize = sizeof(surface_desc);
8419 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &surface_desc);
8420 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#lx.\n", hr);
8421 ok(surface_desc.dwWidth == 640, "Got unexpected surface width %lu.\n", surface_desc.dwWidth);
8422 ok(surface_desc.dwHeight == 480, "Got unexpected surface height %lu.\n", surface_desc.dwHeight);
8423 ok(surface_desc.ddpfPixelFormat.dwRGBBitCount == 8, "Got unexpected bit count %lu.\n",
8424 surface_desc.ddpfPixelFormat.dwRGBBitCount);
8426 hr = set_display_mode(ddraw, 640, 480);
8427 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#lx.\n", hr);
8429 memset(&surface_desc, 0, sizeof(surface_desc));
8430 surface_desc.dwSize = sizeof(surface_desc);
8431 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &surface_desc);
8432 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#lx.\n", hr);
8433 ok(surface_desc.dwWidth == 640, "Got unexpected surface width %lu.\n", surface_desc.dwWidth);
8434 ok(surface_desc.dwHeight == 480, "Got unexpected surface height %lu.\n", surface_desc.dwHeight);
8435 ok(surface_desc.ddpfPixelFormat.dwRGBBitCount == 32
8436 || surface_desc.ddpfPixelFormat.dwRGBBitCount == 24,
8437 "Got unexpected bit count %lu.\n", surface_desc.ddpfPixelFormat.dwRGBBitCount);
8439 hr = IDirectDrawSurface4_IsLost(primary);
8440 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#lx.\n", hr);
8441 hr = IDirectDrawSurface4_Restore(primary);
8442 ok(hr == DDERR_WRONGMODE, "Got unexpected hr %#lx.\n", hr);
8443 hr = IDirectDrawSurface4_IsLost(primary);
8444 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#lx.\n", hr);
8446 memset(&surface_desc, 0, sizeof(surface_desc));
8447 surface_desc.dwSize = sizeof(surface_desc);
8448 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &surface_desc);
8449 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#lx.\n", hr);
8450 ok(surface_desc.dwWidth == 640, "Got unexpected surface width %lu.\n", surface_desc.dwWidth);
8451 ok(surface_desc.dwHeight == 480, "Got unexpected surface height %lu.\n", surface_desc.dwHeight);
8452 ok(surface_desc.ddpfPixelFormat.dwRGBBitCount == 32
8453 || surface_desc.ddpfPixelFormat.dwRGBBitCount == 24,
8454 "Got unexpected bit count %lu.\n", surface_desc.ddpfPixelFormat.dwRGBBitCount);
8456 done:
8457 refcount = IDirectDrawSurface4_Release(backbuffer);
8458 ok(refcount == 1, "Got unexpected refcount %lu.\n", refcount);
8459 refcount = IDirectDrawSurface4_Release(primary);
8460 ok(!refcount, "Got unexpected refcount %lu.\n", refcount);
8461 refcount = IDirectDraw4_Release(ddraw);
8462 ok(!refcount, "Got unexpected refcount %lu.\n", refcount);
8463 DestroyWindow(window);
8466 static HRESULT WINAPI surface_counter(IDirectDrawSurface4 *surface, DDSURFACEDESC2 *desc, void *context)
8468 UINT *surface_count = context;
8470 ++(*surface_count);
8471 IDirectDrawSurface_Release(surface);
8473 return DDENUMRET_OK;
8476 static void test_surface_attachment(void)
8478 IDirectDrawSurface4 *surface1, *surface2, *surface3, *surface4;
8479 IDirectDrawSurface *surface1v1, *surface2v1;
8480 DDSCAPS2 caps = {DDSCAPS_TEXTURE, 0, 0, {0}};
8481 DDSURFACEDESC2 surface_desc;
8482 IDirectDraw4 *ddraw;
8483 UINT surface_count;
8484 ULONG refcount;
8485 HWND window;
8486 HRESULT hr;
8488 window = create_window();
8489 ddraw = create_ddraw();
8490 ok(!!ddraw, "Failed to create a ddraw object.\n");
8491 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
8492 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
8494 memset(&surface_desc, 0, sizeof(surface_desc));
8495 surface_desc.dwSize = sizeof(surface_desc);
8496 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_MIPMAPCOUNT;
8497 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
8498 surface_desc.dwMipMapCount = 3;
8499 surface_desc.dwWidth = 128;
8500 surface_desc.dwHeight = 128;
8501 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface1, NULL);
8502 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
8504 hr = IDirectDrawSurface4_GetAttachedSurface(surface1, &caps, &surface2);
8505 ok(SUCCEEDED(hr), "Failed to get mip level, hr %#lx.\n", hr);
8506 hr = IDirectDrawSurface4_GetAttachedSurface(surface2, &caps, &surface3);
8507 ok(SUCCEEDED(hr), "Failed to get mip level, hr %#lx.\n", hr);
8508 hr = IDirectDrawSurface4_GetAttachedSurface(surface3, &caps, &surface4);
8509 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#lx.\n", hr);
8511 surface_count = 0;
8512 IDirectDrawSurface4_EnumAttachedSurfaces(surface1, &surface_count, surface_counter);
8513 ok(surface_count == 1, "Got unexpected surface_count %u.\n", surface_count);
8514 surface_count = 0;
8515 IDirectDrawSurface4_EnumAttachedSurfaces(surface2, &surface_count, surface_counter);
8516 ok(surface_count == 1, "Got unexpected surface_count %u.\n", surface_count);
8517 surface_count = 0;
8518 IDirectDrawSurface4_EnumAttachedSurfaces(surface3, &surface_count, surface_counter);
8519 ok(!surface_count, "Got unexpected surface_count %u.\n", surface_count);
8521 memset(&surface_desc, 0, sizeof(surface_desc));
8522 surface_desc.dwSize = sizeof(surface_desc);
8523 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
8524 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
8525 surface_desc.dwWidth = 16;
8526 surface_desc.dwHeight = 16;
8527 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface4, NULL);
8528 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
8530 hr = IDirectDrawSurface4_AddAttachedSurface(surface1, surface4);
8531 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#lx.\n", hr);
8532 hr = IDirectDrawSurface4_AddAttachedSurface(surface4, surface1);
8533 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#lx.\n", hr);
8534 hr = IDirectDrawSurface4_AddAttachedSurface(surface3, surface4);
8535 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#lx.\n", hr);
8536 hr = IDirectDrawSurface4_AddAttachedSurface(surface4, surface3);
8537 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#lx.\n", hr);
8538 hr = IDirectDrawSurface4_AddAttachedSurface(surface2, surface4);
8539 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#lx.\n", hr);
8540 hr = IDirectDrawSurface4_AddAttachedSurface(surface4, surface2);
8541 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#lx.\n", hr);
8543 IDirectDrawSurface4_Release(surface4);
8545 memset(&surface_desc, 0, sizeof(surface_desc));
8546 surface_desc.dwSize = sizeof(surface_desc);
8547 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
8548 surface_desc.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
8549 surface_desc.dwWidth = 16;
8550 surface_desc.dwHeight = 16;
8551 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface4, NULL);
8552 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
8554 if (SUCCEEDED(hr = IDirectDrawSurface4_AddAttachedSurface(surface1, surface4)))
8556 skip("Running on refrast, skipping some tests.\n");
8557 hr = IDirectDrawSurface4_DeleteAttachedSurface(surface1, 0, surface4);
8558 ok(SUCCEEDED(hr), "Failed to detach surface, hr %#lx.\n", hr);
8560 else
8562 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#lx.\n", hr);
8563 hr = IDirectDrawSurface4_AddAttachedSurface(surface4, surface1);
8564 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#lx.\n", hr);
8565 hr = IDirectDrawSurface4_AddAttachedSurface(surface3, surface4);
8566 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#lx.\n", hr);
8567 hr = IDirectDrawSurface4_AddAttachedSurface(surface4, surface3);
8568 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#lx.\n", hr);
8569 hr = IDirectDrawSurface4_AddAttachedSurface(surface2, surface4);
8570 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#lx.\n", hr);
8571 hr = IDirectDrawSurface4_AddAttachedSurface(surface4, surface2);
8572 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#lx.\n", hr);
8575 IDirectDrawSurface4_Release(surface4);
8576 IDirectDrawSurface4_Release(surface3);
8577 IDirectDrawSurface4_Release(surface2);
8578 IDirectDrawSurface4_Release(surface1);
8580 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
8581 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
8583 /* Try a single primary and two offscreen plain surfaces. */
8584 memset(&surface_desc, 0, sizeof(surface_desc));
8585 surface_desc.dwSize = sizeof(surface_desc);
8586 surface_desc.dwFlags = DDSD_CAPS;
8587 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
8588 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface1, NULL);
8589 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
8591 memset(&surface_desc, 0, sizeof(surface_desc));
8592 surface_desc.dwSize = sizeof(surface_desc);
8593 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
8594 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
8595 surface_desc.dwWidth = registry_mode.dmPelsWidth;
8596 surface_desc.dwHeight = registry_mode.dmPelsHeight;
8597 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface2, NULL);
8598 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
8600 memset(&surface_desc, 0, sizeof(surface_desc));
8601 surface_desc.dwSize = sizeof(surface_desc);
8602 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
8603 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
8604 surface_desc.dwWidth = registry_mode.dmPelsWidth;
8605 surface_desc.dwHeight = registry_mode.dmPelsHeight;
8606 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface3, NULL);
8607 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
8609 /* This one has a different size. */
8610 memset(&surface_desc, 0, sizeof(surface_desc));
8611 surface_desc.dwSize = sizeof(surface_desc);
8612 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
8613 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
8614 surface_desc.dwWidth = 128;
8615 surface_desc.dwHeight = 128;
8616 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface4, NULL);
8617 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
8619 hr = IDirectDrawSurface4_AddAttachedSurface(surface1, surface2);
8620 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#lx.\n", hr);
8621 /* Try the reverse without detaching first. */
8622 hr = IDirectDrawSurface4_AddAttachedSurface(surface2, surface1);
8623 ok(hr == DDERR_SURFACEALREADYATTACHED, "Got unexpected hr %#lx.\n", hr);
8624 hr = IDirectDrawSurface4_DeleteAttachedSurface(surface1, 0, surface2);
8625 ok(SUCCEEDED(hr), "Failed to detach surface, hr %#lx.\n", hr);
8627 hr = IDirectDrawSurface4_AddAttachedSurface(surface2, surface1);
8628 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#lx.\n", hr);
8629 /* Try to detach reversed. */
8630 hr = IDirectDrawSurface4_DeleteAttachedSurface(surface1, 0, surface2);
8631 ok(hr == DDERR_CANNOTDETACHSURFACE, "Got unexpected hr %#lx.\n", hr);
8632 hr = IDirectDrawSurface4_DeleteAttachedSurface(surface2, 0, surface1);
8633 ok(SUCCEEDED(hr), "Failed to detach surface, hr %#lx.\n", hr);
8635 hr = IDirectDrawSurface4_AddAttachedSurface(surface2, surface3);
8636 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#lx.\n", hr);
8637 hr = IDirectDrawSurface4_DeleteAttachedSurface(surface2, 0, surface3);
8638 ok(SUCCEEDED(hr), "Failed to detach surface, hr %#lx.\n", hr);
8640 hr = IDirectDrawSurface4_AddAttachedSurface(surface1, surface4);
8641 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#lx.\n", hr);
8642 hr = IDirectDrawSurface4_AddAttachedSurface(surface4, surface1);
8643 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#lx.\n", hr);
8645 IDirectDrawSurface4_Release(surface4);
8646 IDirectDrawSurface4_Release(surface3);
8647 IDirectDrawSurface4_Release(surface2);
8648 IDirectDrawSurface4_Release(surface1);
8650 /* Test depth surfaces of different sizes. */
8651 memset(&surface_desc, 0, sizeof(surface_desc));
8652 surface_desc.dwSize = sizeof(surface_desc);
8653 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
8654 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
8655 surface_desc.dwWidth = 64;
8656 surface_desc.dwHeight = 64;
8657 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface1, NULL);
8658 ok(hr == D3D_OK, "Failed to create surface, hr %#lx.\n", hr);
8660 memset(&surface_desc, 0, sizeof(surface_desc));
8661 surface_desc.dwSize = sizeof(surface_desc);
8662 surface_desc.dwFlags = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT;
8663 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
8664 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
8665 surface_desc.ddpfPixelFormat.dwFlags = DDPF_ZBUFFER;
8666 surface_desc.ddpfPixelFormat.dwZBufferBitDepth = 16;
8667 surface_desc.ddpfPixelFormat.dwZBitMask = 0x0000ffff;
8668 surface_desc.dwWidth = 32;
8669 surface_desc.dwHeight = 32;
8670 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface2, NULL);
8671 ok(hr == D3D_OK, "Failed to create surface, hr %#lx.\n", hr);
8672 surface_desc.dwWidth = 64;
8673 surface_desc.dwHeight = 64;
8674 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface3, NULL);
8675 ok(hr == D3D_OK, "Failed to create surface, hr %#lx.\n", hr);
8676 surface_desc.dwWidth = 128;
8677 surface_desc.dwHeight = 128;
8678 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface4, NULL);
8679 ok(hr == D3D_OK, "Failed to create surface, hr %#lx.\n", hr);
8681 hr = IDirectDrawSurface_AddAttachedSurface(surface1, surface2);
8682 todo_wine ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#lx.\n", hr);
8683 if (SUCCEEDED(hr))
8684 IDirectDrawSurface4_DeleteAttachedSurface(surface1, 0, surface2);
8685 hr = IDirectDrawSurface_AddAttachedSurface(surface1, surface3);
8686 ok(hr == D3D_OK, "Failed to attach depth buffer, hr %#lx.\n", hr);
8687 hr = IDirectDrawSurface4_DeleteAttachedSurface(surface1, 0, surface3);
8688 ok(hr == D3D_OK, "Failed to detach depth buffer, hr %#lx.\n", hr);
8689 hr = IDirectDrawSurface_AddAttachedSurface(surface1, surface4);
8690 todo_wine ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#lx.\n", hr);
8692 IDirectDrawSurface4_Release(surface4);
8693 IDirectDrawSurface4_Release(surface3);
8694 IDirectDrawSurface4_Release(surface2);
8695 IDirectDrawSurface4_Release(surface1);
8697 /* Test DeleteAttachedSurface() and automatic detachment of attached surfaces on release. */
8698 memset(&surface_desc, 0, sizeof(surface_desc));
8699 surface_desc.dwSize = sizeof(surface_desc);
8700 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
8701 surface_desc.dwWidth = 64;
8702 surface_desc.dwHeight = 64;
8703 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
8704 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
8705 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB; /* D3DFMT_R5G6B5 */
8706 surface_desc.ddpfPixelFormat.dwRGBBitCount = 16;
8707 surface_desc.ddpfPixelFormat.dwRBitMask = 0xf800;
8708 surface_desc.ddpfPixelFormat.dwGBitMask = 0x07e0;
8709 surface_desc.ddpfPixelFormat.dwBBitMask = 0x001f;
8710 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface1, NULL);
8711 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
8712 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface3, NULL);
8713 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
8715 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
8716 surface_desc.ddpfPixelFormat.dwFlags = DDPF_ZBUFFER;
8717 surface_desc.ddpfPixelFormat.dwZBufferBitDepth = 16;
8718 surface_desc.ddpfPixelFormat.dwZBitMask = 0x0000ffff;
8719 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface2, NULL);
8720 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
8722 hr = IDirectDrawSurface4_QueryInterface(surface1, &IID_IDirectDrawSurface, (void **)&surface1v1);
8723 ok(SUCCEEDED(hr), "Failed to get interface, hr %#lx.\n", hr);
8724 hr = IDirectDrawSurface4_QueryInterface(surface2, &IID_IDirectDrawSurface, (void **)&surface2v1);
8725 ok(SUCCEEDED(hr), "Failed to get interface, hr %#lx.\n", hr);
8727 hr = IDirectDrawSurface4_AddAttachedSurface(surface1, surface2);
8728 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#lx.\n", hr);
8729 refcount = get_refcount((IUnknown *)surface2);
8730 ok(refcount == 2, "Got unexpected refcount %lu.\n", refcount);
8731 refcount = get_refcount((IUnknown *)surface2v1);
8732 ok(refcount == 1, "Got unexpected refcount %lu.\n", refcount);
8733 hr = IDirectDrawSurface4_AddAttachedSurface(surface1, surface2);
8734 ok(hr == DDERR_SURFACEALREADYATTACHED, "Got unexpected hr %#lx.\n", hr);
8735 hr = IDirectDrawSurface_AddAttachedSurface(surface1v1, surface2v1);
8736 todo_wine ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#lx.\n", hr);
8737 hr = IDirectDrawSurface_DeleteAttachedSurface(surface1v1, 0, surface2v1);
8738 ok(hr == DDERR_SURFACENOTATTACHED, "Got unexpected hr %#lx.\n", hr);
8740 /* Attaching while already attached to other surface. */
8741 hr = IDirectDrawSurface4_AddAttachedSurface(surface3, surface2);
8742 todo_wine ok(SUCCEEDED(hr), "Failed to attach surface, hr %#lx.\n", hr);
8743 hr = IDirectDrawSurface4_DeleteAttachedSurface(surface3, 0, surface2);
8744 todo_wine ok(SUCCEEDED(hr), "Failed to detach surface, hr %#lx.\n", hr);
8745 IDirectDrawSurface4_Release(surface3);
8747 hr = IDirectDrawSurface4_DeleteAttachedSurface(surface1, 0, surface2);
8748 ok(SUCCEEDED(hr), "Failed to detach surface, hr %#lx.\n", hr);
8749 refcount = get_refcount((IUnknown *)surface2);
8750 ok(refcount == 1, "Got unexpected refcount %lu.\n", refcount);
8751 refcount = get_refcount((IUnknown *)surface2v1);
8752 ok(refcount == 1, "Got unexpected refcount %lu.\n", refcount);
8754 /* DeleteAttachedSurface() when attaching via IDirectDrawSurface. */
8755 hr = IDirectDrawSurface_AddAttachedSurface(surface1v1, surface2v1);
8756 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#lx.\n", hr);
8757 hr = IDirectDrawSurface4_DeleteAttachedSurface(surface1, 0, surface2);
8758 ok(hr == DDERR_SURFACENOTATTACHED, "Got unexpected hr %#lx.\n", hr);
8759 hr = IDirectDrawSurface_DeleteAttachedSurface(surface1v1, 0, surface2v1);
8760 ok(SUCCEEDED(hr), "Failed to detach surface, hr %#lx.\n", hr);
8761 refcount = IDirectDrawSurface4_Release(surface2);
8762 ok(!refcount, "Got unexpected refcount %lu.\n", refcount);
8763 refcount = IDirectDrawSurface4_Release(surface1);
8764 ok(!refcount, "Got unexpected refcount %lu.\n", refcount);
8766 /* Automatic detachment on release. */
8767 hr = IDirectDrawSurface_AddAttachedSurface(surface1v1, surface2v1);
8768 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#lx.\n", hr);
8769 refcount = get_refcount((IUnknown *)surface2v1);
8770 ok(refcount == 2, "Got unexpected refcount %lu.\n", refcount);
8771 refcount = IDirectDrawSurface_Release(surface1v1);
8772 ok(!refcount, "Got unexpected refcount %lu.\n", refcount);
8773 refcount = IDirectDrawSurface_Release(surface2v1);
8774 ok(!refcount, "Got unexpected refcount %lu.\n", refcount);
8775 refcount = IDirectDraw4_Release(ddraw);
8776 ok(!refcount, "Got unexpected refcount %lu.\n", refcount);
8777 DestroyWindow(window);
8780 static void test_private_data(void)
8782 IDirectDraw4 *ddraw;
8783 IDirectDrawSurface4 *surface, *surface2;
8784 DDSURFACEDESC2 surface_desc;
8785 ULONG refcount, refcount2, refcount3;
8786 IUnknown *ptr;
8787 DWORD size = sizeof(ptr);
8788 HRESULT hr;
8789 HWND window;
8790 DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, {0}};
8791 DWORD data[] = {1, 2, 3, 4};
8792 DDCAPS hal_caps;
8793 static const GUID ddraw_private_data_test_guid =
8795 0xfdb37466,
8796 0x428f,
8797 0x4edf,
8798 {0xa3,0x7f,0x9b,0x1d,0xf4,0x88,0xc5,0xfc}
8800 static const GUID ddraw_private_data_test_guid2 =
8802 0x2e5afac2,
8803 0x87b5,
8804 0x4c10,
8805 {0x9b,0x4b,0x89,0xd7,0xd1,0x12,0xe7,0x2b}
8808 window = create_window();
8809 ddraw = create_ddraw();
8810 ok(!!ddraw, "Failed to create a ddraw object.\n");
8811 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
8812 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
8814 reset_ddsd(&surface_desc);
8815 surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
8816 surface_desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
8817 surface_desc.dwHeight = 4;
8818 surface_desc.dwWidth = 4;
8819 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8820 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
8822 /* NULL pointers are not valid, but don't cause a crash. */
8823 hr = IDirectDrawSurface4_SetPrivateData(surface, &ddraw_private_data_test_guid, NULL,
8824 sizeof(IUnknown *), DDSPD_IUNKNOWNPOINTER);
8825 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
8826 hr = IDirectDrawSurface4_SetPrivateData(surface, &ddraw_private_data_test_guid, NULL, 0, 0);
8827 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
8828 hr = IDirectDrawSurface4_SetPrivateData(surface, &ddraw_private_data_test_guid, NULL, 1, 0);
8829 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
8831 /* DDSPD_IUNKNOWNPOINTER needs sizeof(IUnknown *) bytes of data. */
8832 hr = IDirectDrawSurface4_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
8833 0, DDSPD_IUNKNOWNPOINTER);
8834 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
8835 hr = IDirectDrawSurface4_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
8836 5, DDSPD_IUNKNOWNPOINTER);
8837 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
8838 hr = IDirectDrawSurface4_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
8839 sizeof(ddraw) * 2, DDSPD_IUNKNOWNPOINTER);
8840 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
8842 /* Note that with a size != 0 and size != sizeof(IUnknown *) and
8843 * DDSPD_IUNKNOWNPOINTER set SetPrivateData in ddraw4 and ddraw7
8844 * erases the old content and returns an error. This behavior has
8845 * been fixed in d3d8 and d3d9. Unless an application is found
8846 * that depends on this we don't care about this behavior. */
8847 hr = IDirectDrawSurface4_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
8848 sizeof(ddraw), DDSPD_IUNKNOWNPOINTER);
8849 ok(SUCCEEDED(hr), "Failed to set private data, hr %#lx.\n", hr);
8850 hr = IDirectDrawSurface4_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
8851 0, DDSPD_IUNKNOWNPOINTER);
8852 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
8853 size = sizeof(ptr);
8854 hr = IDirectDrawSurface4_GetPrivateData(surface, &ddraw_private_data_test_guid, &ptr, &size);
8855 ok(SUCCEEDED(hr), "Failed to get private data, hr %#lx.\n", hr);
8856 hr = IDirectDrawSurface4_FreePrivateData(surface, &ddraw_private_data_test_guid);
8857 ok(SUCCEEDED(hr), "Failed to free private data, hr %#lx.\n", hr);
8859 refcount = get_refcount((IUnknown *)ddraw);
8860 hr = IDirectDrawSurface4_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
8861 sizeof(ddraw), DDSPD_IUNKNOWNPOINTER);
8862 ok(SUCCEEDED(hr), "Failed to set private data, hr %#lx.\n", hr);
8863 refcount2 = get_refcount((IUnknown *)ddraw);
8864 ok(refcount2 == refcount + 1, "Got unexpected refcount %lu.\n", refcount2);
8866 hr = IDirectDrawSurface4_FreePrivateData(surface, &ddraw_private_data_test_guid);
8867 ok(SUCCEEDED(hr), "Failed to free private data, hr %#lx.\n", hr);
8868 refcount2 = get_refcount((IUnknown *)ddraw);
8869 ok(refcount2 == refcount, "Got unexpected refcount %lu.\n", refcount2);
8871 hr = IDirectDrawSurface4_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
8872 sizeof(ddraw), DDSPD_IUNKNOWNPOINTER);
8873 ok(SUCCEEDED(hr), "Failed to set private data, hr %#lx.\n", hr);
8874 hr = IDirectDrawSurface4_SetPrivateData(surface, &ddraw_private_data_test_guid, surface,
8875 sizeof(surface), DDSPD_IUNKNOWNPOINTER);
8876 ok(SUCCEEDED(hr), "Failed to set private data, hr %#lx.\n", hr);
8877 refcount2 = get_refcount((IUnknown *)ddraw);
8878 ok(refcount2 == refcount, "Got unexpected refcount %lu.\n", refcount2);
8880 hr = IDirectDrawSurface4_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
8881 sizeof(ddraw), DDSPD_IUNKNOWNPOINTER);
8882 ok(SUCCEEDED(hr), "Failed to set private data, hr %#lx.\n", hr);
8883 size = 2 * sizeof(ptr);
8884 hr = IDirectDrawSurface4_GetPrivateData(surface, &ddraw_private_data_test_guid, &ptr, &size);
8885 ok(SUCCEEDED(hr), "Failed to get private data, hr %#lx.\n", hr);
8886 ok(size == sizeof(ddraw), "Got unexpected size %lu.\n", size);
8887 refcount2 = get_refcount(ptr);
8888 /* Object is NOT addref'ed by the getter. */
8889 ok(ptr == (IUnknown *)ddraw, "Returned interface pointer is %p, expected %p.\n", ptr, ddraw);
8890 ok(refcount2 == refcount + 1, "Got unexpected refcount %lu.\n", refcount2);
8892 ptr = (IUnknown *)0xdeadbeef;
8893 size = 1;
8894 hr = IDirectDrawSurface4_GetPrivateData(surface, &ddraw_private_data_test_guid, NULL, &size);
8895 ok(hr == DDERR_MOREDATA, "Got unexpected hr %#lx.\n", hr);
8896 ok(size == sizeof(ddraw), "Got unexpected size %lu.\n", size);
8897 size = 2 * sizeof(ptr);
8898 hr = IDirectDrawSurface4_GetPrivateData(surface, &ddraw_private_data_test_guid, NULL, &size);
8899 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
8900 ok(size == 2 * sizeof(ptr), "Got unexpected size %lu.\n", size);
8901 size = 1;
8902 hr = IDirectDrawSurface4_GetPrivateData(surface, &ddraw_private_data_test_guid, &ptr, &size);
8903 ok(hr == DDERR_MOREDATA, "Got unexpected hr %#lx.\n", hr);
8904 ok(size == sizeof(ddraw), "Got unexpected size %lu.\n", size);
8905 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
8906 hr = IDirectDrawSurface4_GetPrivateData(surface, &ddraw_private_data_test_guid2, NULL, NULL);
8907 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#lx.\n", hr);
8908 size = 0xdeadbabe;
8909 hr = IDirectDrawSurface4_GetPrivateData(surface, &ddraw_private_data_test_guid2, &ptr, &size);
8910 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#lx.\n", hr);
8911 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
8912 ok(size == 0xdeadbabe, "Got unexpected size %lu.\n", size);
8913 hr = IDirectDrawSurface4_GetPrivateData(surface, &ddraw_private_data_test_guid, NULL, NULL);
8914 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
8916 refcount3 = IDirectDrawSurface4_Release(surface);
8917 ok(!refcount3, "Got unexpected refcount %lu.\n", refcount3);
8919 /* Destroying the surface frees the reference held on the private data. It also frees
8920 * the reference the surface is holding on its creating object. */
8921 refcount2 = get_refcount((IUnknown *)ddraw);
8922 ok(refcount2 == refcount - 1, "Got unexpected refcount %lu.\n", refcount2);
8924 memset(&hal_caps, 0, sizeof(hal_caps));
8925 hal_caps.dwSize = sizeof(hal_caps);
8926 hr = IDirectDraw4_GetCaps(ddraw, &hal_caps, NULL);
8927 ok(SUCCEEDED(hr), "Failed to get caps, hr %#lx.\n", hr);
8928 if ((hal_caps.ddsCaps.dwCaps & (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP)) == (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP))
8930 reset_ddsd(&surface_desc);
8931 surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_MIPMAPCOUNT;
8932 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
8933 surface_desc.dwHeight = 4;
8934 surface_desc.dwWidth = 4;
8935 surface_desc.dwMipMapCount = 2;
8936 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8937 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
8938 hr = IDirectDrawSurface4_GetAttachedSurface(surface, &caps, &surface2);
8939 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#lx.\n", hr);
8941 hr = IDirectDrawSurface4_SetPrivateData(surface, &ddraw_private_data_test_guid, data, sizeof(data), 0);
8942 ok(SUCCEEDED(hr), "Failed to set private data, hr %#lx.\n", hr);
8943 hr = IDirectDrawSurface4_GetPrivateData(surface2, &ddraw_private_data_test_guid, NULL, NULL);
8944 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#lx.\n", hr);
8946 IDirectDrawSurface4_Release(surface2);
8947 IDirectDrawSurface4_Release(surface);
8949 else
8950 skip("Mipmapped textures not supported, skipping mipmap private data test.\n");
8952 refcount = IDirectDraw4_Release(ddraw);
8953 ok(!refcount, "Got unexpected refcount %lu.\n", refcount);
8954 DestroyWindow(window);
8957 static void test_pixel_format(void)
8959 HWND window, window2, window3;
8960 HMODULE gl = NULL;
8961 int format, test_format;
8962 PIXELFORMATDESCRIPTOR pfd;
8963 IDirectDraw4 *ddraw = NULL;
8964 IDirectDrawClipper *clipper = NULL;
8965 DDSURFACEDESC2 ddsd;
8966 HDC hdc, hdc2, hdc3;
8967 IDirectDrawSurface4 *primary = NULL, *offscreen;
8968 ULONG refcount;
8969 DDBLTFX fx;
8970 HRESULT hr;
8971 BOOL ret;
8973 window = create_window();
8974 ok(!!window, "Failed to create window.\n");
8975 window2 = create_window();
8976 ok(!!window2, "Failed to create window.\n");
8978 hdc = GetDC(window);
8979 ok(!!hdc, "Failed to get DC.\n");
8980 hdc2 = GetDC(window2);
8981 ok(!!hdc2, "Failed to get DC.\n");
8983 gl = LoadLibraryA("opengl32.dll");
8984 ok(!!gl, "failed to load opengl32.dll; SetPixelFormat()/GetPixelFormat() may not work right\n");
8986 format = GetPixelFormat(hdc);
8987 ok(format == 0, "new window has pixel format %d\n", format);
8989 ZeroMemory(&pfd, sizeof(pfd));
8990 pfd.nSize = sizeof(pfd);
8991 pfd.nVersion = 1;
8992 pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
8993 pfd.iPixelType = PFD_TYPE_RGBA;
8994 pfd.iLayerType = PFD_MAIN_PLANE;
8995 format = ChoosePixelFormat(hdc, &pfd);
8996 if (format <= 0)
8998 skip("no pixel format available\n");
8999 goto cleanup;
9002 if (!SetPixelFormat(hdc, format, &pfd) || GetPixelFormat(hdc) != format)
9004 skip("failed to set pixel format\n");
9005 goto cleanup;
9008 if (!SetPixelFormat(hdc2, format, &pfd) || GetPixelFormat(hdc2) != format)
9010 skip("failed to set pixel format on second window\n");
9011 goto cleanup;
9014 ddraw = create_ddraw();
9015 ok(!!ddraw, "Failed to create a ddraw object.\n");
9017 test_format = GetPixelFormat(hdc);
9018 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
9020 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
9021 ok(hr == S_OK, "Got hr %#lx.\n", hr);
9023 test_format = GetPixelFormat(hdc);
9024 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
9026 hr = IDirectDraw4_CreateClipper(ddraw, 0, &clipper, NULL);
9027 ok(SUCCEEDED(hr), "Failed to create clipper, hr %#lx.\n", hr);
9028 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window2);
9029 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#lx.\n", hr);
9031 test_format = GetPixelFormat(hdc);
9032 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
9033 test_format = GetPixelFormat(hdc2);
9034 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
9036 memset(&ddsd, 0, sizeof(ddsd));
9037 ddsd.dwSize = sizeof(ddsd);
9038 ddsd.dwFlags = DDSD_CAPS;
9039 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
9041 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
9042 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n",hr);
9044 test_format = GetPixelFormat(hdc);
9045 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
9046 test_format = GetPixelFormat(hdc2);
9047 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
9049 hr = IDirectDrawSurface4_SetClipper(primary, clipper);
9050 ok(SUCCEEDED(hr), "Failed to set clipper, hr %#lx.\n", hr);
9052 test_format = GetPixelFormat(hdc);
9053 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
9054 test_format = GetPixelFormat(hdc2);
9055 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
9057 memset(&ddsd, 0, sizeof(ddsd));
9058 ddsd.dwSize = sizeof(ddsd);
9059 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
9060 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
9061 ddsd.dwWidth = ddsd.dwHeight = 64;
9062 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &offscreen, NULL);
9063 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n",hr);
9065 memset(&fx, 0, sizeof(fx));
9066 fx.dwSize = sizeof(fx);
9067 hr = IDirectDrawSurface4_Blt(offscreen, NULL, NULL, NULL, DDBLT_WAIT | DDBLT_COLORFILL, &fx);
9068 ok(SUCCEEDED(hr), "Failed to clear source surface, hr %#lx.\n", hr);
9070 test_format = GetPixelFormat(hdc);
9071 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
9073 hr = IDirectDrawSurface4_Blt(primary, NULL, offscreen, NULL, DDBLT_WAIT, NULL);
9074 ok(SUCCEEDED(hr), "Failed to blit to primary surface, hr %#lx.\n", hr);
9076 test_format = GetPixelFormat(hdc);
9077 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
9078 test_format = GetPixelFormat(hdc2);
9079 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
9081 IDirectDrawSurface4_Release(offscreen);
9082 IDirectDrawSurface4_Release(primary);
9083 refcount = IDirectDrawClipper_Release(clipper);
9084 ok(!refcount, "Got unexpected refcount %lu.\n", refcount);
9085 refcount = IDirectDraw4_Release(ddraw);
9086 ok(!refcount, "Got unexpected refcount %lu.\n", refcount);
9088 /* Test that creating a device doesn't set a pixel format on a window which
9089 * never had one. */
9091 window3 = create_window();
9092 hdc3 = GetDC(window3);
9094 test_format = GetPixelFormat(hdc3);
9095 ok(!test_format, "Expected no format, got %d.\n", test_format);
9097 ddraw = create_ddraw();
9098 ok(!!ddraw, "Failed to create a ddraw object.\n");
9099 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window3, DDSCL_NORMAL);
9100 ok(hr == S_OK, "Got hr %#lx.\n", hr);
9102 test_format = GetPixelFormat(hdc3);
9103 ok(!test_format, "Expected no format, got %d.\n", test_format);
9105 memset(&ddsd, 0, sizeof(ddsd));
9106 ddsd.dwSize = sizeof(ddsd);
9107 ddsd.dwFlags = DDSD_CAPS;
9108 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
9109 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
9110 ok(hr == S_OK, "Got hr %#lx.\n", hr);
9112 memset(&ddsd, 0, sizeof(ddsd));
9113 ddsd.dwSize = sizeof(ddsd);
9114 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
9115 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
9116 ddsd.dwWidth = ddsd.dwHeight = 64;
9117 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &offscreen, NULL);
9118 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n",hr);
9120 memset(&fx, 0, sizeof(fx));
9121 fx.dwSize = sizeof(fx);
9122 hr = IDirectDrawSurface4_Blt(offscreen, NULL, NULL, NULL, DDBLT_WAIT | DDBLT_COLORFILL, &fx);
9123 ok(SUCCEEDED(hr), "Failed to clear source surface, hr %#lx.\n", hr);
9125 hr = IDirectDrawSurface4_Blt(primary, NULL, offscreen, NULL, DDBLT_WAIT, NULL);
9126 ok(SUCCEEDED(hr), "Failed to blit to primary surface, hr %#lx.\n", hr);
9128 test_format = GetPixelFormat(hdc3);
9129 ok(!test_format, "Expected no format, got %d.\n", test_format);
9131 IDirectDrawSurface4_Release(offscreen);
9132 IDirectDrawSurface4_Release(primary);
9133 refcount = IDirectDraw4_Release(ddraw);
9134 ok(!refcount, "Got unexpected refcount %lu.\n", refcount);
9136 test_format = GetPixelFormat(hdc3);
9137 ok(!test_format, "Expected no format, got %d.\n", test_format);
9139 ret = SetPixelFormat(hdc3, format, &pfd);
9140 ok(ret, "Failed to set pixel format %d.\n", format);
9142 test_format = GetPixelFormat(hdc3);
9143 ok(test_format == format, "Expected pixel format %d, got %d.\n", format, test_format);
9145 ReleaseDC(window3, hdc3);
9146 DestroyWindow(window3);
9148 cleanup:
9149 FreeLibrary(gl);
9150 ReleaseDC(window2, hdc2);
9151 ReleaseDC(window, hdc);
9152 DestroyWindow(window2);
9153 DestroyWindow(window);
9156 static void test_create_surface_pitch(void)
9158 DWORD vidmem_total = 0, vidmem_free = 0, vidmem_free2 = 0;
9159 DDSCAPS2 vidmem_caps = {DDSCAPS_TEXTURE, 0, 0, {0}};
9160 IDirectDrawSurface4 * surface, *primary;
9161 DDSURFACEDESC2 surface_desc;
9162 IDirectDraw4 *ddraw;
9163 unsigned int i;
9164 ULONG refcount;
9165 HWND window;
9166 HRESULT hr;
9167 void *mem;
9169 static const struct
9171 DWORD caps;
9172 DWORD flags_in;
9173 DWORD pitch_in;
9174 HRESULT hr;
9175 DWORD flags_out;
9176 DWORD pitch_out32;
9177 DWORD pitch_out64;
9179 test_data[] =
9181 /* 0 */
9182 {DDSCAPS_VIDEOMEMORY | DDSCAPS_OFFSCREENPLAIN,
9183 0, 0, DD_OK,
9184 DDSD_PITCH, 0x100, 0x100},
9185 {DDSCAPS_VIDEOMEMORY | DDSCAPS_OFFSCREENPLAIN,
9186 DDSD_PITCH, 0x104, DD_OK,
9187 DDSD_PITCH, 0x100, 0x100},
9188 {DDSCAPS_VIDEOMEMORY | DDSCAPS_OFFSCREENPLAIN,
9189 DDSD_PITCH, 0x0f8, DD_OK,
9190 DDSD_PITCH, 0x100, 0x100},
9191 {DDSCAPS_VIDEOMEMORY | DDSCAPS_OFFSCREENPLAIN,
9192 DDSD_LPSURFACE | DDSD_PITCH, 0x100, DDERR_INVALIDCAPS,
9193 0, 0, 0 },
9194 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
9195 0, 0, DD_OK,
9196 DDSD_PITCH, 0x100, 0x0fc},
9197 /* 5 */
9198 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
9199 DDSD_PITCH, 0x104, DD_OK,
9200 DDSD_PITCH, 0x100, 0x0fc},
9201 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
9202 DDSD_PITCH, 0x0f8, DD_OK,
9203 DDSD_PITCH, 0x100, 0x0fc},
9204 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
9205 DDSD_PITCH | DDSD_LINEARSIZE, 0, DD_OK,
9206 DDSD_PITCH, 0x100, 0x0fc},
9207 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
9208 DDSD_LPSURFACE, 0, DDERR_INVALIDPARAMS,
9209 0, 0, 0 },
9210 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
9211 DDSD_LPSURFACE | DDSD_PITCH, 0x100, DD_OK,
9212 DDSD_PITCH, 0x100, 0x100},
9213 /* 10 */
9214 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
9215 DDSD_LPSURFACE | DDSD_PITCH, 0x0fe, DDERR_INVALIDPARAMS,
9216 0, 0, 0 },
9217 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
9218 DDSD_LPSURFACE | DDSD_PITCH, 0x0fc, DD_OK,
9219 DDSD_PITCH, 0x0fc, 0x0fc},
9220 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
9221 DDSD_LPSURFACE | DDSD_PITCH, 0x0f8, DDERR_INVALIDPARAMS,
9222 0, 0, 0 },
9223 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
9224 DDSD_LPSURFACE | DDSD_LINEARSIZE, 0x100, DDERR_INVALIDPARAMS,
9225 0, 0, 0 },
9226 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
9227 DDSD_LPSURFACE | DDSD_LINEARSIZE, 0x3f00, DDERR_INVALIDPARAMS,
9228 0, 0, 0 },
9229 /* 15 */
9230 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
9231 DDSD_LPSURFACE | DDSD_PITCH | DDSD_LINEARSIZE, 0x100, DD_OK,
9232 DDSD_PITCH, 0x100, 0x100},
9233 {DDSCAPS_VIDEOMEMORY | DDSCAPS_OFFSCREENPLAIN | DDSCAPS_ALLOCONLOAD,
9234 0, 0, DDERR_INVALIDCAPS,
9235 0, 0, 0 },
9236 {DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD,
9237 0, 0, DD_OK,
9238 DDSD_PITCH, 0x100, 0 },
9239 {DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE,
9240 0, 0, DD_OK,
9241 DDSD_PITCH, 0x100, 0 },
9242 {DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD,
9243 DDSD_LPSURFACE | DDSD_PITCH, 0x100, DDERR_INVALIDCAPS,
9244 0, 0, 0 },
9245 /* 20 */
9246 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN | DDSCAPS_ALLOCONLOAD,
9247 0, 0, DDERR_INVALIDCAPS,
9248 0, 0, 0 },
9249 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD,
9250 0, 0, DD_OK,
9251 DDSD_PITCH, 0x100, 0 },
9252 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD,
9253 DDSD_LPSURFACE | DDSD_PITCH, 0x100, DD_OK,
9254 DDSD_PITCH, 0x100, 0 },
9255 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE,
9256 0, 0, DD_OK,
9257 DDSD_PITCH, 0x100, 0x0fc},
9258 {DDSCAPS_VIDEOMEMORY | DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE,
9259 0, 0, DD_OK,
9260 DDSD_PITCH, 0x100, 0x100},
9262 DWORD flags_mask = DDSD_PITCH | DDSD_LPSURFACE | DDSD_LINEARSIZE;
9264 window = create_window();
9265 ddraw = create_ddraw();
9266 ok(!!ddraw, "Failed to create a ddraw object.\n");
9267 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
9268 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
9270 mem = calloc((63 * 4) + 8, 63);
9272 /* We need a primary surface and exclusive mode for video memory accounting to work
9273 * right on Windows. Otherwise it gives us junk data, like creating a video memory
9274 * surface freeing up memory. */
9275 memset(&surface_desc, 0, sizeof(surface_desc));
9276 surface_desc.dwSize = sizeof(surface_desc);
9277 surface_desc.dwFlags = DDSD_CAPS;
9278 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
9279 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &primary, NULL);
9280 ok(SUCCEEDED(hr), "Failed to create a primary surface, hr %#lx.\n", hr);
9282 hr = IDirectDraw4_GetAvailableVidMem(ddraw, &vidmem_caps, &vidmem_total, &vidmem_free);
9283 ok(SUCCEEDED(hr) || hr == DDERR_NODIRECTDRAWHW,
9284 "Failed to get available video memory, hr %#lx.\n", hr);
9286 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
9288 memset(&surface_desc, 0, sizeof(surface_desc));
9289 surface_desc.dwSize = sizeof(surface_desc);
9290 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | test_data[i].flags_in;
9291 surface_desc.ddsCaps.dwCaps = test_data[i].caps;
9292 surface_desc.dwWidth = 63;
9293 surface_desc.dwHeight = 63;
9294 surface_desc.lPitch = test_data[i].pitch_in;
9295 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
9296 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB;
9297 surface_desc.ddpfPixelFormat.dwRGBBitCount = 32;
9298 surface_desc.ddpfPixelFormat.dwRBitMask = 0x00ff0000;
9299 surface_desc.ddpfPixelFormat.dwGBitMask = 0x0000ff00;
9300 surface_desc.ddpfPixelFormat.dwBBitMask = 0x000000ff;
9301 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
9302 if (test_data[i].flags_in & DDSD_LPSURFACE)
9304 HRESULT expected_hr = SUCCEEDED(test_data[i].hr) ? DDERR_INVALIDPARAMS : test_data[i].hr;
9305 ok(hr == expected_hr, "Test %u: Got unexpected hr %#lx, expected %#lx.\n", i, hr, expected_hr);
9306 surface_desc.lpSurface = mem;
9307 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
9309 if ((test_data[i].caps & DDSCAPS_VIDEOMEMORY) && hr == DDERR_NODIRECTDRAWHW)
9310 continue;
9311 ok(hr == test_data[i].hr, "Test %u: Got unexpected hr %#lx, expected %#lx.\n", i, hr, test_data[i].hr);
9312 if (FAILED(hr))
9313 continue;
9315 memset(&surface_desc, 0, sizeof(surface_desc));
9316 surface_desc.dwSize = sizeof(surface_desc);
9317 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &surface_desc);
9318 ok(SUCCEEDED(hr), "Test %u: Failed to get surface desc, hr %#lx.\n", i, hr);
9319 ok((surface_desc.dwFlags & flags_mask) == test_data[i].flags_out,
9320 "Test %u: Got unexpected flags %#lx, expected %#lx.\n",
9321 i, surface_desc.dwFlags & flags_mask, test_data[i].flags_out);
9322 /* The pitch for textures seems to be implementation specific. */
9323 if (!(test_data[i].caps & DDSCAPS_TEXTURE))
9325 if (is_ddraw64 && test_data[i].pitch_out32 != test_data[i].pitch_out64)
9326 todo_wine ok(surface_desc.lPitch == test_data[i].pitch_out64,
9327 "Test %u: Got unexpected pitch %#lx, expected %#lx.\n",
9328 i, surface_desc.lPitch, test_data[i].pitch_out64);
9329 else
9330 ok(surface_desc.lPitch == test_data[i].pitch_out32,
9331 "Test %u: Got unexpected pitch %#lx, expected %#lx.\n",
9332 i, surface_desc.lPitch, test_data[i].pitch_out32);
9334 ok(!surface_desc.lpSurface, "Test %u: Got unexpected lpSurface %p.\n", i, surface_desc.lpSurface);
9336 hr = IDirectDraw4_GetAvailableVidMem(ddraw, &vidmem_caps, &vidmem_total, &vidmem_free2);
9337 ok(SUCCEEDED(hr) || hr == DDERR_NODIRECTDRAWHW,
9338 "Failed to get available video memory, hr %#lx.\n", hr);
9339 if (SUCCEEDED(hr) && surface_desc.ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY)
9341 /* Star Trek Starfleet Academy cares about this bit here: That creating a system memory
9342 * resource does not influence available video memory. */
9343 ok(vidmem_free2 == vidmem_free, "Free video memory changed from %#lx to %#lx, test %u.\n",
9344 vidmem_free, vidmem_free2, i);
9346 else if (SUCCEEDED(hr) && surface_desc.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY)
9348 /* DDSCAPS_ALLOCONLOAD does not seem to delay video memory allocation, at least not on
9349 * modern Windows.
9351 * The amount of video memory consumed is different from what dwHeight * lPitch would
9352 * suggest, although not by much. */
9353 ok(vidmem_free2 < vidmem_free,
9354 "Expected free video memory to change, but it did not, test %u.\n", i);
9357 IDirectDrawSurface4_Release(surface);
9359 hr = IDirectDraw4_GetAvailableVidMem(ddraw, &vidmem_caps, &vidmem_total, &vidmem_free2);
9360 ok(SUCCEEDED(hr) || hr == DDERR_NODIRECTDRAWHW,
9361 "Failed to get available video memory, hr %#lx.\n", hr);
9362 ok(hr == DDERR_NODIRECTDRAWHW || vidmem_free2 == vidmem_free,
9363 "Free video memory changed from %#lx to %#lx, test %u.\n",
9364 vidmem_free, vidmem_free2, i);
9367 IDirectDrawSurface4_Release(primary);
9368 free(mem);
9369 refcount = IDirectDraw4_Release(ddraw);
9370 ok(!refcount, "Got unexpected refcount %lu.\n", refcount);
9371 DestroyWindow(window);
9374 static void test_mipmap(void)
9376 IDirectDrawSurface4 *surface, *surface_base, *surface_mip;
9377 unsigned int i, mipmap_count;
9378 DDSURFACEDESC2 surface_desc;
9379 IDirectDraw4 *ddraw;
9380 ULONG refcount;
9381 HWND window;
9382 HRESULT hr;
9383 DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, {0}};
9384 DDCAPS hal_caps;
9386 static const struct
9388 DWORD flags;
9389 DWORD caps;
9390 DWORD width;
9391 DWORD height;
9392 DWORD mipmap_count_in;
9393 HRESULT hr;
9394 DWORD mipmap_count_out;
9396 tests[] =
9398 {0, DDSCAPS_MIPMAP, 128, 32, 0, DDERR_INVALIDCAPS},
9399 {0, DDSCAPS_COMPLEX, 128, 32, 0, DDERR_INVALIDCAPS},
9400 {0, DDSCAPS_MIPMAP | DDSCAPS_COMPLEX, 128, 32, 0, DDERR_INVALIDCAPS},
9401 {0, DDSCAPS_TEXTURE | DDSCAPS_MIPMAP, 128, 32, 0, DD_OK, 1},
9402 {0, DDSCAPS_TEXTURE | DDSCAPS_COMPLEX, 128, 32, 0, DDERR_INVALIDCAPS},
9403 {0, DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP, 128, 32, 0, DD_OK, 6},
9404 {0, DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP, 32, 64, 0, DD_OK, 6},
9406 {DDSD_MIPMAPCOUNT, DDSCAPS_TEXTURE | DDSCAPS_MIPMAP, 128, 32, 1, DDERR_INVALIDCAPS},
9407 {DDSD_MIPMAPCOUNT, DDSCAPS_TEXTURE | DDSCAPS_MIPMAP, 128, 32, 3, DDERR_INVALIDCAPS},
9408 {DDSD_MIPMAPCOUNT, DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP, 128, 32, 3, DD_OK, 3},
9409 {DDSD_MIPMAPCOUNT, DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP, 128, 32, 0, DDERR_INVALIDPARAMS},
9412 window = create_window();
9413 ddraw = create_ddraw();
9414 ok(!!ddraw, "Failed to create a ddraw object.\n");
9415 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
9416 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
9418 memset(&hal_caps, 0, sizeof(hal_caps));
9419 hal_caps.dwSize = sizeof(hal_caps);
9420 hr = IDirectDraw4_GetCaps(ddraw, &hal_caps, NULL);
9421 ok(SUCCEEDED(hr), "Failed to get caps, hr %#lx.\n", hr);
9422 if ((hal_caps.ddsCaps.dwCaps & (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP)) != (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP))
9424 skip("Mipmapped textures not supported, skipping tests.\n");
9425 IDirectDraw4_Release(ddraw);
9426 DestroyWindow(window);
9427 return;
9430 for (i = 0; i < ARRAY_SIZE(tests); ++i)
9432 memset(&surface_desc, 0, sizeof(surface_desc));
9433 surface_desc.dwSize = sizeof(surface_desc);
9434 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | tests[i].flags;
9435 surface_desc.ddsCaps.dwCaps = tests[i].caps;
9436 surface_desc.dwWidth = tests[i].width;
9437 surface_desc.dwHeight = tests[i].height;
9438 if (tests[i].flags & DDSD_MIPMAPCOUNT)
9439 surface_desc.dwMipMapCount = tests[i].mipmap_count_in;
9440 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
9441 ok(hr == tests[i].hr, "Test %u: Got unexpected hr %#lx.\n", i, hr);
9442 if (FAILED(hr))
9443 continue;
9445 memset(&surface_desc, 0, sizeof(surface_desc));
9446 surface_desc.dwSize = sizeof(surface_desc);
9447 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &surface_desc);
9448 ok(SUCCEEDED(hr), "Test %u: Failed to get surface desc, hr %#lx.\n", i, hr);
9449 ok(surface_desc.dwFlags & DDSD_MIPMAPCOUNT,
9450 "Test %u: Got unexpected flags %#lx.\n", i, surface_desc.dwFlags);
9451 ok(surface_desc.dwMipMapCount == tests[i].mipmap_count_out,
9452 "Test %u: Got unexpected mipmap count %lu.\n", i, surface_desc.dwMipMapCount);
9454 surface_base = surface;
9455 IDirectDrawSurface4_AddRef(surface_base);
9456 mipmap_count = surface_desc.dwMipMapCount;
9457 while (mipmap_count > 1)
9459 hr = IDirectDrawSurface4_GetAttachedSurface(surface_base, &caps, &surface_mip);
9460 ok(SUCCEEDED(hr), "Test %u, %u: Failed to get attached surface, hr %#lx.\n", i, mipmap_count, hr);
9462 memset(&surface_desc, 0, sizeof(surface_desc));
9463 surface_desc.dwSize = sizeof(surface_desc);
9464 hr = IDirectDrawSurface4_GetSurfaceDesc(surface_base, &surface_desc);
9465 ok(SUCCEEDED(hr), "Test %u, %u: Failed to get surface desc, hr %#lx.\n", i, mipmap_count, hr);
9466 ok(surface_desc.dwFlags & DDSD_MIPMAPCOUNT,
9467 "Test %u, %u: Got unexpected flags %#lx.\n", i, mipmap_count, surface_desc.dwFlags);
9468 ok(surface_desc.dwMipMapCount == mipmap_count,
9469 "Test %u, %u: Got unexpected mipmap count %lu.\n",
9470 i, mipmap_count, surface_desc.dwMipMapCount);
9472 memset(&surface_desc, 0, sizeof(surface_desc));
9473 surface_desc.dwSize = sizeof(surface_desc);
9474 hr = IDirectDrawSurface4_Lock(surface_base, NULL, &surface_desc, 0, NULL);
9475 ok(SUCCEEDED(hr), "Test %u, %u: Failed to lock surface, hr %#lx.\n", i, mipmap_count, hr);
9476 ok(surface_desc.dwMipMapCount == mipmap_count,
9477 "Test %u, %u: unexpected change of mipmap count %lu.\n",
9478 i, mipmap_count, surface_desc.dwMipMapCount);
9479 memset(&surface_desc, 0, sizeof(surface_desc));
9480 surface_desc.dwSize = sizeof(surface_desc);
9481 hr = IDirectDrawSurface4_Lock(surface_mip, NULL, &surface_desc, 0, NULL);
9482 ok(SUCCEEDED(hr), "Test %u, %u: Failed to lock surface, hr %#lx.\n", i, mipmap_count, hr);
9483 ok(surface_desc.dwMipMapCount == mipmap_count - 1,
9484 "Test %u, %u: Got unexpected child mipmap count %lu.\n", i, mipmap_count, surface_desc.dwMipMapCount);
9485 IDirectDrawSurface4_Unlock(surface_mip, NULL);
9486 IDirectDrawSurface4_Unlock(surface_base, NULL);
9488 IDirectDrawSurface4_Release(surface_base);
9489 surface_base = surface_mip;
9490 --mipmap_count;
9492 IDirectDrawSurface4_Release(surface_base);
9494 IDirectDrawSurface4_Release(surface);
9497 refcount = IDirectDraw4_Release(ddraw);
9498 ok(!refcount, "Got unexpected refcount %lu.\n", refcount);
9499 DestroyWindow(window);
9502 static void test_palette_complex(void)
9504 IDirectDrawSurface4 *surface, *mipmap, *tmp;
9505 DDSURFACEDESC2 surface_desc;
9506 IDirectDraw4 *ddraw;
9507 IDirectDrawPalette *palette, *palette2, *palette_mipmap;
9508 ULONG refcount;
9509 HWND window;
9510 HRESULT hr;
9511 DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, {0}};
9512 DDCAPS hal_caps;
9513 PALETTEENTRY palette_entries[256];
9514 unsigned int i;
9515 HDC dc;
9516 RGBQUAD rgbquad;
9517 UINT count;
9519 window = create_window();
9520 ddraw = create_ddraw();
9521 ok(!!ddraw, "Failed to create a ddraw object.\n");
9522 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
9523 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
9525 memset(&hal_caps, 0, sizeof(hal_caps));
9526 hal_caps.dwSize = sizeof(hal_caps);
9527 hr = IDirectDraw4_GetCaps(ddraw, &hal_caps, NULL);
9528 ok(SUCCEEDED(hr), "Failed to get caps, hr %#lx.\n", hr);
9529 if ((hal_caps.ddsCaps.dwCaps & (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP)) != (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP))
9531 skip("Mipmapped textures not supported, skipping mipmap palette test.\n");
9532 IDirectDraw4_Release(ddraw);
9533 DestroyWindow(window);
9534 return;
9537 memset(&surface_desc, 0, sizeof(surface_desc));
9538 surface_desc.dwSize = sizeof(surface_desc);
9539 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
9540 surface_desc.dwWidth = 128;
9541 surface_desc.dwHeight = 128;
9542 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
9543 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
9544 surface_desc.ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
9545 surface_desc.ddpfPixelFormat.dwRGBBitCount = 8;
9546 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
9547 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
9549 memset(palette_entries, 0, sizeof(palette_entries));
9550 hr = IDirectDraw4_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
9551 palette_entries, &palette, NULL);
9552 ok(SUCCEEDED(hr), "Failed to create palette, hr %#lx.\n", hr);
9554 memset(palette_entries, 0, sizeof(palette_entries));
9555 palette_entries[1].peRed = 0xff;
9556 palette_entries[1].peGreen = 0x80;
9557 hr = IDirectDraw4_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
9558 palette_entries, &palette_mipmap, NULL);
9559 ok(SUCCEEDED(hr), "Failed to create palette, hr %#lx.\n", hr);
9561 palette2 = (void *)0xdeadbeef;
9562 hr = IDirectDrawSurface4_GetPalette(surface, &palette2);
9563 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#lx.\n", hr);
9564 ok(!palette2, "Got unexpected palette %p.\n", palette2);
9565 hr = IDirectDrawSurface4_SetPalette(surface, palette);
9566 ok(SUCCEEDED(hr), "Failed to set palette, hr %#lx.\n", hr);
9567 hr = IDirectDrawSurface4_GetPalette(surface, &palette2);
9568 ok(SUCCEEDED(hr), "Failed to get palette, hr %#lx.\n", hr);
9569 ok(palette == palette2, "Got unexpected palette %p.\n", palette2);
9570 IDirectDrawPalette_Release(palette2);
9572 mipmap = surface;
9573 IDirectDrawSurface4_AddRef(mipmap);
9574 for (i = 0; i < 7; ++i)
9576 hr = IDirectDrawSurface4_GetAttachedSurface(mipmap, &caps, &tmp);
9577 ok(SUCCEEDED(hr), "Failed to get attached surface, i %u, hr %#lx.\n", i, hr);
9578 palette2 = (void *)0xdeadbeef;
9579 hr = IDirectDrawSurface4_GetPalette(tmp, &palette2);
9580 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#lx, i %u.\n", hr, i);
9581 ok(!palette2, "Got unexpected palette %p, i %u.\n", palette2, i);
9583 hr = IDirectDrawSurface4_SetPalette(tmp, palette_mipmap);
9584 ok(SUCCEEDED(hr), "Failed to set palette, i %u, hr %#lx.\n", i, hr);
9586 hr = IDirectDrawSurface4_GetPalette(tmp, &palette2);
9587 ok(SUCCEEDED(hr), "Failed to get palette, i %u, hr %#lx.\n", i, hr);
9588 ok(palette_mipmap == palette2, "Got unexpected palette %p.\n", palette2);
9589 IDirectDrawPalette_Release(palette2);
9591 hr = IDirectDrawSurface4_GetDC(tmp, &dc);
9592 ok(SUCCEEDED(hr), "Failed to get DC, i %u, hr %#lx.\n", i, hr);
9593 count = GetDIBColorTable(dc, 1, 1, &rgbquad);
9594 ok(count == 1, "Expected count 1, got %u.\n", count);
9595 ok(rgbquad.rgbRed == 0xff, "Expected rgbRed = 0xff, got %#x.\n", rgbquad.rgbRed);
9596 ok(rgbquad.rgbGreen == 0x80, "Expected rgbGreen = 0x80, got %#x.\n", rgbquad.rgbGreen);
9597 ok(rgbquad.rgbBlue == 0x0, "Expected rgbBlue = 0x0, got %#x.\n", rgbquad.rgbBlue);
9598 hr = IDirectDrawSurface4_ReleaseDC(tmp, dc);
9599 ok(SUCCEEDED(hr), "Failed to release DC, i %u, hr %#lx.\n", i, hr);
9601 IDirectDrawSurface4_Release(mipmap);
9602 mipmap = tmp;
9605 hr = IDirectDrawSurface4_GetAttachedSurface(mipmap, &caps, &tmp);
9606 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#lx.\n", hr);
9607 IDirectDrawSurface4_Release(mipmap);
9608 refcount = IDirectDrawSurface4_Release(surface);
9609 ok(!refcount, "Got unexpected refcount %lu.\n", refcount);
9610 refcount = IDirectDrawPalette_Release(palette_mipmap);
9611 ok(!refcount, "Got unexpected refcount %lu.\n", refcount);
9612 refcount = IDirectDrawPalette_Release(palette);
9613 ok(!refcount, "Got unexpected refcount %lu.\n", refcount);
9615 refcount = IDirectDraw4_Release(ddraw);
9616 ok(!refcount, "Got unexpected refcount %lu.\n", refcount);
9617 DestroyWindow(window);
9620 static void test_p8_blit(void)
9622 IDirectDrawSurface4 *src, *dst, *dst_p8;
9623 DDSURFACEDESC2 surface_desc;
9624 unsigned int color, x;
9625 IDirectDraw4 *ddraw;
9626 IDirectDrawPalette *palette, *palette2;
9627 ULONG refcount;
9628 HWND window;
9629 HRESULT hr;
9630 PALETTEENTRY palette_entries[256];
9631 DDBLTFX fx;
9632 BOOL is_warp;
9633 static const BYTE src_data[] = {0x10, 0x1, 0x2, 0x3, 0x4, 0x5, 0xff, 0x80};
9634 static const BYTE src_data2[] = {0x10, 0x5, 0x4, 0x3, 0x2, 0x1, 0xff, 0x80};
9635 static const BYTE expected_p8[] = {0x10, 0x1, 0x4, 0x3, 0x4, 0x5, 0xff, 0x80};
9636 static const unsigned int expected[] =
9638 0x00101010, 0x00010101, 0x00020202, 0x00030303,
9639 0x00040404, 0x00050505, 0x00ffffff, 0x00808080,
9642 window = create_window();
9643 ddraw = create_ddraw();
9644 ok(!!ddraw, "Failed to create a ddraw object.\n");
9645 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
9646 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
9647 is_warp = ddraw_is_warp(ddraw);
9649 memset(palette_entries, 0, sizeof(palette_entries));
9650 palette_entries[1].peGreen = 0xff;
9651 palette_entries[2].peBlue = 0xff;
9652 palette_entries[3].peFlags = 0xff;
9653 palette_entries[4].peRed = 0xff;
9654 hr = IDirectDraw4_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
9655 palette_entries, &palette, NULL);
9656 ok(SUCCEEDED(hr), "Failed to create palette, hr %#lx.\n", hr);
9657 palette_entries[1].peBlue = 0xff;
9658 palette_entries[2].peGreen = 0xff;
9659 palette_entries[3].peRed = 0xff;
9660 palette_entries[4].peFlags = 0x0;
9661 hr = IDirectDraw4_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
9662 palette_entries, &palette2, NULL);
9663 ok(SUCCEEDED(hr), "Failed to create palette, hr %#lx.\n", hr);
9665 memset(&surface_desc, 0, sizeof(surface_desc));
9666 surface_desc.dwSize = sizeof(surface_desc);
9667 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
9668 surface_desc.dwWidth = 8;
9669 surface_desc.dwHeight = 1;
9670 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
9671 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
9672 surface_desc.ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
9673 surface_desc.ddpfPixelFormat.dwRGBBitCount = 8;
9674 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &src, NULL);
9675 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
9676 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &dst_p8, NULL);
9677 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
9678 hr = IDirectDrawSurface4_SetPalette(dst_p8, palette2);
9679 ok(SUCCEEDED(hr), "Failed to set palette, hr %#lx.\n", hr);
9681 memset(&surface_desc, 0, sizeof(surface_desc));
9682 surface_desc.dwSize = sizeof(surface_desc);
9683 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
9684 surface_desc.dwWidth = 8;
9685 surface_desc.dwHeight = 1;
9686 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
9687 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
9688 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
9689 surface_desc.ddpfPixelFormat.dwRGBBitCount = 32;
9690 surface_desc.ddpfPixelFormat.dwRBitMask = 0x00ff0000;
9691 surface_desc.ddpfPixelFormat.dwGBitMask = 0x0000ff00;
9692 surface_desc.ddpfPixelFormat.dwBBitMask = 0x000000ff;
9693 surface_desc.ddpfPixelFormat.dwRGBAlphaBitMask = 0xff000000;
9694 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &dst, NULL);
9695 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
9697 memset(&surface_desc, 0, sizeof(surface_desc));
9698 surface_desc.dwSize = sizeof(surface_desc);
9699 hr = IDirectDrawSurface4_Lock(src, NULL, &surface_desc, DDLOCK_WAIT, NULL);
9700 ok(SUCCEEDED(hr), "Failed to lock source surface, hr %#lx.\n", hr);
9701 memcpy(surface_desc.lpSurface, src_data, sizeof(src_data));
9702 hr = IDirectDrawSurface4_Unlock(src, NULL);
9703 ok(SUCCEEDED(hr), "Failed to unlock source surface, hr %#lx.\n", hr);
9705 hr = IDirectDrawSurface4_Lock(dst_p8, NULL, &surface_desc, DDLOCK_WAIT, NULL);
9706 ok(SUCCEEDED(hr), "Failed to lock destination surface, hr %#lx.\n", hr);
9707 memcpy(surface_desc.lpSurface, src_data2, sizeof(src_data2));
9708 hr = IDirectDrawSurface4_Unlock(dst_p8, NULL);
9709 ok(SUCCEEDED(hr), "Failed to unlock destination surface, hr %#lx.\n", hr);
9711 fx.dwSize = sizeof(fx);
9712 fx.dwFillColor = 0xdeadbeef;
9713 hr = IDirectDrawSurface4_Blt(dst, NULL, NULL, NULL, DDBLT_WAIT | DDBLT_COLORFILL, &fx);
9714 ok(SUCCEEDED(hr), "Got hr %#lx.\n", hr);
9716 hr = IDirectDrawSurface4_SetPalette(src, palette);
9717 ok(SUCCEEDED(hr), "Failed to set palette, hr %#lx.\n", hr);
9718 hr = IDirectDrawSurface4_Blt(dst, NULL, src, NULL, DDBLT_WAIT, NULL);
9719 /* The r500 Windows 7 driver returns E_NOTIMPL. r200 on Windows XP works.
9720 * The Geforce 7 driver on Windows Vista returns E_FAIL. Newer Nvidia GPUs work. */
9721 ok(SUCCEEDED(hr) || broken(hr == E_NOTIMPL) || broken(hr == E_FAIL),
9722 "Failed to blit, hr %#lx.\n", hr);
9724 if (SUCCEEDED(hr))
9726 for (x = 0; x < ARRAY_SIZE(expected); x++)
9728 color = get_surface_color(dst, x, 0);
9729 /* WARP on 1709 and newer write zeroes on non-colorkeyed P8 -> RGB blits. For ckey
9730 * blits see below. */
9731 todo_wine ok(compare_color(color, expected[x], 0)
9732 || broken(is_warp && compare_color(color, 0x00000000, 0)),
9733 "Pixel %u: Got color %#x, expected %#x.\n",
9734 x, color, expected[x]);
9738 fx.ddckSrcColorkey.dwColorSpaceHighValue = 0x2;
9739 fx.ddckSrcColorkey.dwColorSpaceLowValue = 0x2;
9740 hr = IDirectDrawSurface4_Blt(dst_p8, NULL, src, NULL, DDBLT_WAIT | DDBLT_KEYSRCOVERRIDE, &fx);
9741 ok(SUCCEEDED(hr), "Failed to blit, hr %#lx.\n", hr);
9743 hr = IDirectDrawSurface4_Lock(dst_p8, NULL, &surface_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
9744 ok(SUCCEEDED(hr), "Failed to lock destination surface, hr %#lx.\n", hr);
9745 /* A color keyed P8 blit doesn't do anything on WARP - it just leaves the data in the destination
9746 * surface untouched. Error checking (DDBLT_KEYSRC without a key
9747 * for example) also works as expected.
9749 * Using DDBLT_KEYSRC instead of DDBLT_KEYSRCOVERRIDE doesn't change this. Doing this blit with
9750 * the display mode set to P8 doesn't help either. */
9751 ok(!memcmp(surface_desc.lpSurface, expected_p8, sizeof(expected_p8))
9752 || broken(is_warp && !memcmp(surface_desc.lpSurface, src_data2, sizeof(src_data2))),
9753 "Got unexpected P8 color key blit result.\n");
9754 hr = IDirectDrawSurface4_Unlock(dst_p8, NULL);
9755 ok(SUCCEEDED(hr), "Failed to unlock destination surface, hr %#lx.\n", hr);
9757 IDirectDrawSurface4_Release(src);
9758 IDirectDrawSurface4_Release(dst);
9759 IDirectDrawSurface4_Release(dst_p8);
9760 IDirectDrawPalette_Release(palette);
9761 IDirectDrawPalette_Release(palette2);
9763 refcount = IDirectDraw4_Release(ddraw);
9764 ok(!refcount, "Got unexpected refcount %lu.\n", refcount);
9765 DestroyWindow(window);
9768 static void test_material(void)
9770 D3DMATERIALHANDLE mat_handle, tmp;
9771 IDirect3DMaterial3 *material;
9772 IDirect3DViewport3 *viewport;
9773 IDirect3DDevice3 *device;
9774 IDirectDrawSurface4 *rt;
9775 unsigned int color, i;
9776 ULONG refcount;
9777 HWND window;
9778 HRESULT hr;
9779 BOOL valid;
9781 static struct
9783 struct vec3 position;
9784 struct vec3 normal;
9785 D3DCOLOR diffuse;
9787 quad1[] =
9789 {{-1.0f, -1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffffffff},
9790 {{-1.0f, 1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffffffff},
9791 {{ 1.0f, -1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffffffff},
9792 {{ 1.0f, 1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffffffff},
9794 quad2[] =
9796 {{-1.0f, -1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000},
9797 {{-1.0f, 1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000},
9798 {{ 1.0f, -1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000},
9799 {{ 1.0f, 1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000},
9801 static const struct
9803 void *data;
9804 BOOL material;
9805 D3DCOLOR expected_color;
9807 test_data[] =
9809 {quad1, TRUE, 0x0000ff00},
9810 {quad2, TRUE, 0x0000ff00},
9811 {quad1, FALSE, 0x00ffffff},
9812 {quad2, FALSE, 0x00ff0000},
9814 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
9816 window = create_window();
9817 if (!(device = create_device(window, DDSCL_NORMAL)))
9819 skip("Failed to create a 3D device, skipping test.\n");
9820 DestroyWindow(window);
9821 return;
9824 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
9825 ok(SUCCEEDED(hr), "Failed to get render target, hr %#lx.\n", hr);
9827 viewport = create_viewport(device, 0, 0, 640, 480);
9828 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
9829 ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#lx.\n", hr);
9831 material = create_emissive_material(device, 0.0f, 1.0f, 0.0f, 0.0f);
9832 hr = IDirect3DMaterial3_GetHandle(material, device, &mat_handle);
9833 ok(SUCCEEDED(hr), "Failed to get material handle, hr %#lx.\n", hr);
9835 hr = IDirect3DDevice3_GetLightState(device, D3DLIGHTSTATE_MATERIAL, &tmp);
9836 ok(SUCCEEDED(hr), "Failed to get light state, hr %#lx.\n", hr);
9837 ok(!tmp, "Got unexpected material handle %#lx.\n", tmp);
9838 hr = IDirect3DDevice3_SetLightState(device, D3DLIGHTSTATE_MATERIAL, mat_handle);
9839 ok(SUCCEEDED(hr), "Failed to set material state, hr %#lx.\n", hr);
9840 hr = IDirect3DDevice3_GetLightState(device, D3DLIGHTSTATE_MATERIAL, &tmp);
9841 ok(SUCCEEDED(hr), "Failed to get light state, hr %#lx.\n", hr);
9842 ok(tmp == mat_handle, "Got unexpected material handle %#lx, expected %#lx.\n", tmp, mat_handle);
9843 hr = IDirect3DDevice3_SetLightState(device, D3DLIGHTSTATE_MATERIAL, 0);
9844 ok(SUCCEEDED(hr), "Failed to set material state, hr %#lx.\n", hr);
9845 hr = IDirect3DDevice3_GetLightState(device, D3DLIGHTSTATE_MATERIAL, &tmp);
9846 ok(SUCCEEDED(hr), "Failed to get light state, hr %#lx.\n", hr);
9847 ok(!tmp, "Got unexpected material handle %#lx.\n", tmp);
9849 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
9851 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect,
9852 D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff0000ff, 1.0f, 0);
9853 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#lx.\n", hr);
9855 hr = IDirect3DDevice3_SetLightState(device, D3DLIGHTSTATE_MATERIAL, test_data[i].material ? mat_handle : 0);
9856 ok(SUCCEEDED(hr), "Failed to set material state, hr %#lx.\n", hr);
9858 hr = IDirect3DDevice3_BeginScene(device);
9859 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#lx.\n", hr);
9860 hr = IDirect3DDevice2_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
9861 D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE, test_data[i].data, 4, 0);
9862 ok(SUCCEEDED(hr), "Failed to draw, hr %#lx.\n", hr);
9863 hr = IDirect3DDevice3_EndScene(device);
9864 ok(SUCCEEDED(hr), "Failed to end scene, hr %#lx.\n", hr);
9865 color = get_surface_color(rt, 320, 240);
9866 ok(compare_color(color, test_data[i].expected_color, 1),
9867 "Got unexpected color 0x%08x, test %u.\n", color, i);
9870 destroy_material(material);
9871 material = create_diffuse_material(device, 1.0f, 0.0f, 0.0f, 1.0f);
9872 hr = IDirect3DMaterial3_GetHandle(material, device, &mat_handle);
9873 ok(SUCCEEDED(hr), "Failed to get material handle, hr %#lx.\n", hr);
9875 hr = IDirect3DViewport3_SetBackground(viewport, mat_handle);
9876 ok(SUCCEEDED(hr), "Failed to set viewport background, hr %#lx.\n", hr);
9877 hr = IDirect3DViewport3_GetBackground(viewport, &tmp, &valid);
9878 ok(SUCCEEDED(hr), "Failed to get viewport background, hr %#lx.\n", hr);
9879 ok(tmp == mat_handle, "Got unexpected material handle %#lx, expected %#lx.\n", tmp, mat_handle);
9880 ok(valid, "Got unexpected valid %#x.\n", valid);
9881 hr = IDirect3DViewport3_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
9882 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#lx.\n", hr);
9883 color = get_surface_color(rt, 320, 240);
9884 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
9886 hr = IDirect3DViewport3_SetBackground(viewport, 0);
9887 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
9888 hr = IDirect3DViewport3_GetBackground(viewport, &tmp, &valid);
9889 ok(SUCCEEDED(hr), "Failed to get viewport background, hr %#lx.\n", hr);
9890 ok(tmp == mat_handle, "Got unexpected material handle %#lx, expected %#lx.\n", tmp, mat_handle);
9891 ok(valid, "Got unexpected valid %#x.\n", valid);
9892 hr = IDirect3DViewport3_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
9893 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#lx.\n", hr);
9894 color = get_surface_color(rt, 320, 240);
9895 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
9897 destroy_viewport(device, viewport);
9898 viewport = create_viewport(device, 0, 0, 640, 480);
9900 hr = IDirect3DViewport3_GetBackground(viewport, &tmp, &valid);
9901 ok(SUCCEEDED(hr), "Failed to get viewport background, hr %#lx.\n", hr);
9902 ok(!tmp, "Got unexpected material handle %#lx.\n", tmp);
9903 ok(!valid, "Got unexpected valid %#x.\n", valid);
9904 hr = IDirect3DViewport3_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
9905 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#lx.\n", hr);
9906 color = get_surface_color(rt, 320, 240);
9907 ok(compare_color(color, 0x00000000, 1), "Got unexpected color 0x%08x.\n", color);
9909 destroy_viewport(device, viewport);
9910 destroy_material(material);
9911 IDirectDrawSurface4_Release(rt);
9912 refcount = IDirect3DDevice3_Release(device);
9913 ok(!refcount, "Device has %lu references left.\n", refcount);
9914 DestroyWindow(window);
9917 static void test_palette_gdi(void)
9919 IDirectDrawSurface4 *surface, *primary;
9920 DDSURFACEDESC2 surface_desc;
9921 unsigned int color, i;
9922 IDirectDraw4 *ddraw;
9923 IDirectDrawPalette *palette, *palette2;
9924 ULONG refcount;
9925 HWND window;
9926 HRESULT hr;
9927 PALETTEENTRY palette_entries[256];
9928 HDC dc;
9929 DDBLTFX fx;
9930 RECT r;
9932 /* On the Windows 8 testbot palette index 0 of the onscreen palette is forced to
9933 * r = 0, g = 0, b = 0. Do not attempt to set it to something else as this is
9934 * not the point of this test. */
9935 static const RGBQUAD expected1[] =
9937 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
9938 {0x03, 0x00, 0x00, 0x00}, {0x15, 0x14, 0x13, 0x00},
9940 static const RGBQUAD expected2[] =
9942 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
9943 {0x03, 0x00, 0x00, 0x00}, {0x25, 0x24, 0x23, 0x00},
9945 static const RGBQUAD expected3[] =
9947 {0x00, 0x00, 0x00, 0x00}, {0x40, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x40, 0x00},
9948 {0x00, 0x40, 0x00, 0x00}, {0x56, 0x34, 0x12, 0x00},
9950 HPALETTE ddraw_palette_handle;
9951 /* Similar to index 0, index 255 is r = 0xff, g = 0xff, b = 0xff on the Win8 VMs. */
9952 RGBQUAD rgbquad[255];
9953 static const RGBQUAD rgb_zero = {0, 0, 0, 0};
9955 window = create_window();
9956 ddraw = create_ddraw();
9957 ok(!!ddraw, "Failed to create a ddraw object.\n");
9958 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
9959 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
9961 memset(&surface_desc, 0, sizeof(surface_desc));
9962 surface_desc.dwSize = sizeof(surface_desc);
9963 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
9964 surface_desc.dwWidth = 16;
9965 surface_desc.dwHeight = 16;
9966 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
9967 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
9968 surface_desc.ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
9969 surface_desc.ddpfPixelFormat.dwRGBBitCount = 8;
9970 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
9971 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
9973 /* Avoid colors from the Windows default palette. */
9974 memset(palette_entries, 0, sizeof(palette_entries));
9975 palette_entries[1].peRed = 0x01;
9976 palette_entries[2].peGreen = 0x02;
9977 palette_entries[3].peBlue = 0x03;
9978 palette_entries[4].peRed = 0x13;
9979 palette_entries[4].peGreen = 0x14;
9980 palette_entries[4].peBlue = 0x15;
9981 hr = IDirectDraw4_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
9982 palette_entries, &palette, NULL);
9983 ok(SUCCEEDED(hr), "Failed to create palette, hr %#lx.\n", hr);
9985 /* If there is no palette assigned and the display mode is not 8 bpp, some
9986 * drivers refuse to create a DC while others allow it. If a DC is created,
9987 * the DIB color table is uninitialized and contains random colors. No error
9988 * is generated when trying to read pixels and random garbage is returned.
9990 * The most likely explanation is that if the driver creates a DC, it (or
9991 * the higher-level runtime) uses GetSystemPaletteEntries to find the
9992 * palette, but GetSystemPaletteEntries fails when bpp > 8 and the palette
9993 * contains uninitialized garbage. See comments below for the P8 case. */
9995 hr = IDirectDrawSurface4_SetPalette(surface, palette);
9996 ok(SUCCEEDED(hr), "Failed to set palette, hr %#lx.\n", hr);
9997 hr = IDirectDrawSurface4_GetDC(surface, &dc);
9998 ok(SUCCEEDED(hr), "Failed to get DC, hr %#lx.\n", hr);
9999 ddraw_palette_handle = SelectPalette(dc, GetStockObject(DEFAULT_PALETTE), FALSE);
10000 ok(ddraw_palette_handle == GetStockObject(DEFAULT_PALETTE),
10001 "Got unexpected palette %p, expected %p.\n",
10002 ddraw_palette_handle, GetStockObject(DEFAULT_PALETTE));
10004 i = GetDIBColorTable(dc, 0, ARRAY_SIZE(rgbquad), rgbquad);
10005 ok(i == ARRAY_SIZE(rgbquad), "Expected count 255, got %u.\n", i);
10006 for (i = 0; i < ARRAY_SIZE(expected1); i++)
10008 ok(!memcmp(&rgbquad[i], &expected1[i], sizeof(rgbquad[i])),
10009 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
10010 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
10011 expected1[i].rgbRed, expected1[i].rgbGreen, expected1[i].rgbBlue);
10013 for (; i < ARRAY_SIZE(rgbquad); i++)
10015 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
10016 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
10017 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
10020 /* Update the palette while the DC is in use. This does not modify the DC. */
10021 palette_entries[4].peRed = 0x23;
10022 palette_entries[4].peGreen = 0x24;
10023 palette_entries[4].peBlue = 0x25;
10024 hr = IDirectDrawPalette_SetEntries(palette, 0, 4, 1, &palette_entries[4]);
10025 ok(SUCCEEDED(hr), "Failed to set palette entries, hr %#lx.\n", hr);
10027 i = GetDIBColorTable(dc, 4, 1, &rgbquad[4]);
10028 ok(i == 1, "Expected count 1, got %u.\n", i);
10029 ok(!memcmp(&rgbquad[4], &expected1[4], sizeof(rgbquad[4])),
10030 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
10031 i, rgbquad[4].rgbRed, rgbquad[4].rgbGreen, rgbquad[4].rgbBlue,
10032 expected1[4].rgbRed, expected1[4].rgbGreen, expected1[4].rgbBlue);
10034 /* Neither does re-setting the palette. */
10035 hr = IDirectDrawSurface4_SetPalette(surface, NULL);
10036 ok(SUCCEEDED(hr), "Failed to set palette, hr %#lx.\n", hr);
10037 hr = IDirectDrawSurface4_SetPalette(surface, palette);
10038 ok(SUCCEEDED(hr), "Failed to set palette, hr %#lx.\n", hr);
10040 i = GetDIBColorTable(dc, 4, 1, &rgbquad[4]);
10041 ok(i == 1, "Expected count 1, got %u.\n", i);
10042 ok(!memcmp(&rgbquad[4], &expected1[4], sizeof(rgbquad[4])),
10043 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
10044 i, rgbquad[4].rgbRed, rgbquad[4].rgbGreen, rgbquad[4].rgbBlue,
10045 expected1[4].rgbRed, expected1[4].rgbGreen, expected1[4].rgbBlue);
10047 hr = IDirectDrawSurface4_ReleaseDC(surface, dc);
10048 ok(SUCCEEDED(hr), "Failed to release DC, hr %#lx.\n", hr);
10050 /* Refresh the DC. This updates the palette. */
10051 hr = IDirectDrawSurface4_GetDC(surface, &dc);
10052 ok(SUCCEEDED(hr), "Failed to get DC, hr %#lx.\n", hr);
10053 i = GetDIBColorTable(dc, 0, ARRAY_SIZE(rgbquad), rgbquad);
10054 ok(i == ARRAY_SIZE(rgbquad), "Expected count 255, got %u.\n", i);
10055 for (i = 0; i < ARRAY_SIZE(expected2); i++)
10057 ok(!memcmp(&rgbquad[i], &expected2[i], sizeof(rgbquad[i])),
10058 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
10059 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
10060 expected2[i].rgbRed, expected2[i].rgbGreen, expected2[i].rgbBlue);
10062 for (; i < ARRAY_SIZE(rgbquad); i++)
10064 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
10065 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
10066 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
10068 hr = IDirectDrawSurface4_ReleaseDC(surface, dc);
10069 ok(SUCCEEDED(hr), "Failed to release DC, hr %#lx.\n", hr);
10071 refcount = IDirectDrawSurface4_Release(surface);
10072 ok(!refcount, "Got unexpected refcount %lu.\n", refcount);
10074 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
10075 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
10076 if (FAILED(IDirectDraw4_SetDisplayMode(ddraw, 640, 480, 8, 0, 0)))
10078 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
10079 IDirectDrawPalette_Release(palette);
10080 IDirectDraw4_Release(ddraw);
10081 DestroyWindow(window);
10082 return;
10084 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#lx.\n", hr);
10086 memset(&surface_desc, 0, sizeof(surface_desc));
10087 surface_desc.dwSize = sizeof(surface_desc);
10088 surface_desc.dwFlags = DDSD_CAPS;
10089 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
10090 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &primary, NULL);
10091 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
10093 memset(&fx, 0, sizeof(fx));
10094 fx.dwSize = sizeof(fx);
10095 fx.dwFillColor = 3;
10096 SetRect(&r, 0, 0, 319, 479);
10097 hr = IDirectDrawSurface4_Blt(primary, &r, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
10098 ok(SUCCEEDED(hr), "Failed to clear surface, hr %#lx.\n", hr);
10099 SetRect(&r, 320, 0, 639, 479);
10100 fx.dwFillColor = 4;
10101 hr = IDirectDrawSurface4_Blt(primary, &r, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
10102 ok(SUCCEEDED(hr), "Failed to clear surface, hr %#lx.\n", hr);
10104 hr = IDirectDrawSurface4_SetPalette(primary, palette);
10105 ok(SUCCEEDED(hr), "Failed to set palette, hr %#lx.\n", hr);
10106 hr = IDirectDrawSurface4_GetDC(primary, &dc);
10107 ok(SUCCEEDED(hr), "Failed to get DC, hr %#lx.\n", hr);
10109 color = GetPixel(dc, 160, 240);
10110 ok(color == 0x00030000, "Clear index 3: Got unexpected color 0x%08x.\n", color);
10111 color = GetPixel(dc, 480, 240);
10112 ok(color == 0x00252423, "Clear index 4: Got unexpected color 0x%08x.\n", color);
10114 ddraw_palette_handle = SelectPalette(dc, GetStockObject(DEFAULT_PALETTE), FALSE);
10115 ok(ddraw_palette_handle == GetStockObject(DEFAULT_PALETTE),
10116 "Got unexpected palette %p, expected %p.\n",
10117 ddraw_palette_handle, GetStockObject(DEFAULT_PALETTE));
10118 SelectPalette(dc, ddraw_palette_handle, FALSE);
10120 /* The primary uses the system palette. In exclusive mode, the system palette matches
10121 * the ddraw palette attached to the primary, so the result is what you would expect
10122 * from a regular surface. Tests for the interaction between the ddraw palette and
10123 * the system palette are not included pending an application that depends on this.
10124 * The relation between those causes problems on Windows Vista and newer for games
10125 * like Age of Empires or StarCraft. Don't emulate it without a real need. */
10126 i = GetDIBColorTable(dc, 0, ARRAY_SIZE(rgbquad), rgbquad);
10127 ok(i == ARRAY_SIZE(rgbquad), "Expected count 255, got %u.\n", i);
10128 for (i = 0; i < ARRAY_SIZE(expected2); i++)
10130 ok(!memcmp(&rgbquad[i], &expected2[i], sizeof(rgbquad[i])),
10131 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
10132 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
10133 expected2[i].rgbRed, expected2[i].rgbGreen, expected2[i].rgbBlue);
10135 for (; i < ARRAY_SIZE(rgbquad); i++)
10137 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
10138 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
10139 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
10141 hr = IDirectDrawSurface4_ReleaseDC(primary, dc);
10142 ok(SUCCEEDED(hr), "Failed to release DC, hr %#lx.\n", hr);
10144 memset(&surface_desc, 0, sizeof(surface_desc));
10145 surface_desc.dwSize = sizeof(surface_desc);
10146 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
10147 surface_desc.dwWidth = 16;
10148 surface_desc.dwHeight = 16;
10149 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
10150 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
10151 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
10153 /* Here the offscreen surface appears to use the primary's palette,
10154 * but in all likelihood it is actually the system palette. */
10155 hr = IDirectDrawSurface4_GetDC(surface, &dc);
10156 ok(SUCCEEDED(hr), "Failed to get DC, hr %#lx.\n", hr);
10157 i = GetDIBColorTable(dc, 0, ARRAY_SIZE(rgbquad), rgbquad);
10158 ok(i == ARRAY_SIZE(rgbquad), "Expected count 255, got %u.\n", i);
10159 for (i = 0; i < ARRAY_SIZE(expected2); i++)
10161 ok(!memcmp(&rgbquad[i], &expected2[i], sizeof(rgbquad[i])),
10162 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
10163 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
10164 expected2[i].rgbRed, expected2[i].rgbGreen, expected2[i].rgbBlue);
10166 for (; i < ARRAY_SIZE(rgbquad); i++)
10168 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
10169 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
10170 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
10172 hr = IDirectDrawSurface4_ReleaseDC(surface, dc);
10173 ok(SUCCEEDED(hr), "Failed to release DC, hr %#lx.\n", hr);
10175 /* On real hardware a change to the primary surface's palette applies immediately,
10176 * even on device contexts from offscreen surfaces that do not have their own
10177 * palette. On the testbot VMs this is not the case. Don't test this until we
10178 * know of an application that depends on this. */
10180 memset(palette_entries, 0, sizeof(palette_entries));
10181 palette_entries[1].peBlue = 0x40;
10182 palette_entries[2].peRed = 0x40;
10183 palette_entries[3].peGreen = 0x40;
10184 palette_entries[4].peRed = 0x12;
10185 palette_entries[4].peGreen = 0x34;
10186 palette_entries[4].peBlue = 0x56;
10187 hr = IDirectDraw4_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
10188 palette_entries, &palette2, NULL);
10189 ok(SUCCEEDED(hr), "Failed to create palette, hr %#lx.\n", hr);
10190 hr = IDirectDrawSurface4_SetPalette(surface, palette2);
10191 ok(SUCCEEDED(hr), "Failed to set palette, hr %#lx.\n", hr);
10193 /* A palette assigned to the offscreen surface overrides the primary / system
10194 * palette. */
10195 hr = IDirectDrawSurface4_GetDC(surface, &dc);
10196 ok(SUCCEEDED(hr), "Failed to get DC, hr %#lx.\n", hr);
10197 i = GetDIBColorTable(dc, 0, ARRAY_SIZE(rgbquad), rgbquad);
10198 ok(i == ARRAY_SIZE(rgbquad), "Expected count 255, got %u.\n", i);
10199 for (i = 0; i < ARRAY_SIZE(expected3); i++)
10201 ok(!memcmp(&rgbquad[i], &expected3[i], sizeof(rgbquad[i])),
10202 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
10203 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
10204 expected3[i].rgbRed, expected3[i].rgbGreen, expected3[i].rgbBlue);
10206 for (; i < ARRAY_SIZE(rgbquad); i++)
10208 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
10209 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
10210 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
10212 hr = IDirectDrawSurface4_ReleaseDC(surface, dc);
10213 ok(SUCCEEDED(hr), "Failed to release DC, hr %#lx.\n", hr);
10215 refcount = IDirectDrawSurface4_Release(surface);
10216 ok(!refcount, "Got unexpected refcount %lu.\n", refcount);
10218 /* The Windows 8 testbot keeps extra references to the primary and
10219 * backbuffer while in 8 bpp mode. */
10220 hr = IDirectDraw4_RestoreDisplayMode(ddraw);
10221 ok(SUCCEEDED(hr), "Failed to restore display mode, hr %#lx.\n", hr);
10223 refcount = IDirectDrawSurface4_Release(primary);
10224 ok(!refcount, "Got unexpected refcount %lu.\n", refcount);
10225 refcount = IDirectDrawPalette_Release(palette2);
10226 ok(!refcount, "Got unexpected refcount %lu.\n", refcount);
10227 refcount = IDirectDrawPalette_Release(palette);
10228 ok(!refcount, "Got unexpected refcount %lu.\n", refcount);
10229 refcount = IDirectDraw4_Release(ddraw);
10230 ok(!refcount, "Got unexpected refcount %lu.\n", refcount);
10231 DestroyWindow(window);
10234 static void test_palette_alpha(void)
10236 IDirectDrawSurface4 *surface;
10237 DDSURFACEDESC2 surface_desc;
10238 IDirectDraw4 *ddraw;
10239 IDirectDrawPalette *palette;
10240 ULONG refcount;
10241 HWND window;
10242 HRESULT hr;
10243 PALETTEENTRY palette_entries[256];
10244 unsigned int i;
10245 static const struct
10247 DWORD caps, flags;
10248 BOOL attach_allowed;
10249 const char *name;
10251 test_data[] =
10253 {DDSCAPS_OFFSCREENPLAIN, DDSD_WIDTH | DDSD_HEIGHT, FALSE, "offscreenplain"},
10254 {DDSCAPS_TEXTURE, DDSD_WIDTH | DDSD_HEIGHT, TRUE, "texture"},
10255 {DDSCAPS_PRIMARYSURFACE, 0, FALSE, "primary"}
10258 window = create_window();
10259 ddraw = create_ddraw();
10260 ok(!!ddraw, "Failed to create a ddraw object.\n");
10261 if (FAILED(IDirectDraw4_SetDisplayMode(ddraw, 640, 480, 8, 0, 0)))
10263 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
10264 IDirectDraw4_Release(ddraw);
10265 DestroyWindow(window);
10266 return;
10268 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
10269 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
10271 memset(palette_entries, 0, sizeof(palette_entries));
10272 palette_entries[1].peFlags = 0x42;
10273 palette_entries[2].peFlags = 0xff;
10274 palette_entries[3].peFlags = 0x80;
10275 hr = IDirectDraw4_CreatePalette(ddraw, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, palette_entries, &palette, NULL);
10276 ok(SUCCEEDED(hr), "Failed to create palette, hr %#lx.\n", hr);
10278 memset(palette_entries, 0x66, sizeof(palette_entries));
10279 hr = IDirectDrawPalette_GetEntries(palette, 0, 1, 4, palette_entries);
10280 ok(SUCCEEDED(hr), "Failed to get palette entries, hr %#lx.\n", hr);
10281 ok(palette_entries[0].peFlags == 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
10282 palette_entries[0].peFlags);
10283 ok(palette_entries[1].peFlags == 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
10284 palette_entries[1].peFlags);
10285 ok(palette_entries[2].peFlags == 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
10286 palette_entries[2].peFlags);
10287 ok(palette_entries[3].peFlags == 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
10288 palette_entries[3].peFlags);
10290 IDirectDrawPalette_Release(palette);
10292 memset(palette_entries, 0, sizeof(palette_entries));
10293 palette_entries[1].peFlags = 0x42;
10294 palette_entries[1].peRed = 0xff;
10295 palette_entries[2].peFlags = 0xff;
10296 palette_entries[3].peFlags = 0x80;
10297 hr = IDirectDraw4_CreatePalette(ddraw, DDPCAPS_ALLOW256 | DDPCAPS_8BIT | DDPCAPS_ALPHA,
10298 palette_entries, &palette, NULL);
10299 ok(SUCCEEDED(hr), "Failed to create palette, hr %#lx.\n", hr);
10301 memset(palette_entries, 0x66, sizeof(palette_entries));
10302 hr = IDirectDrawPalette_GetEntries(palette, 0, 1, 4, palette_entries);
10303 ok(SUCCEEDED(hr), "Failed to get palette entries, hr %#lx.\n", hr);
10304 ok(palette_entries[0].peFlags == 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
10305 palette_entries[0].peFlags);
10306 ok(palette_entries[1].peFlags == 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
10307 palette_entries[1].peFlags);
10308 ok(palette_entries[2].peFlags == 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
10309 palette_entries[2].peFlags);
10310 ok(palette_entries[3].peFlags == 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
10311 palette_entries[3].peFlags);
10313 for (i = 0; i < ARRAY_SIZE(test_data); i++)
10315 memset(&surface_desc, 0, sizeof(surface_desc));
10316 surface_desc.dwSize = sizeof(surface_desc);
10317 surface_desc.dwFlags = DDSD_CAPS | test_data[i].flags;
10318 surface_desc.dwWidth = 128;
10319 surface_desc.dwHeight = 128;
10320 surface_desc.ddsCaps.dwCaps = test_data[i].caps;
10321 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
10322 ok(SUCCEEDED(hr), "Failed to create %s surface, hr %#lx.\n", test_data[i].name, hr);
10324 hr = IDirectDrawSurface4_SetPalette(surface, palette);
10325 if (test_data[i].attach_allowed)
10326 ok(SUCCEEDED(hr), "Failed to attach palette to %s surface, hr %#lx.\n", test_data[i].name, hr);
10327 else
10328 ok(hr == DDERR_INVALIDSURFACETYPE, "Got unexpected hr %#lx, %s surface.\n", hr, test_data[i].name);
10330 if (SUCCEEDED(hr))
10332 HDC dc;
10333 RGBQUAD rgbquad;
10334 UINT retval;
10336 hr = IDirectDrawSurface4_GetDC(surface, &dc);
10337 ok(SUCCEEDED(hr), "Failed to get DC, hr %#lx, %s surface.\n", hr, test_data[i].name);
10338 retval = GetDIBColorTable(dc, 1, 1, &rgbquad);
10339 ok(retval == 1, "GetDIBColorTable returned unexpected result %u.\n", retval);
10340 ok(rgbquad.rgbRed == 0xff, "Expected rgbRed = 0xff, got %#x, %s surface.\n",
10341 rgbquad.rgbRed, test_data[i].name);
10342 ok(rgbquad.rgbGreen == 0, "Expected rgbGreen = 0, got %#x, %s surface.\n",
10343 rgbquad.rgbGreen, test_data[i].name);
10344 ok(rgbquad.rgbBlue == 0, "Expected rgbBlue = 0, got %#x, %s surface.\n",
10345 rgbquad.rgbBlue, test_data[i].name);
10346 ok(rgbquad.rgbReserved == 0, "Expected rgbReserved = 0, got %u, %s surface.\n",
10347 rgbquad.rgbReserved, test_data[i].name);
10348 hr = IDirectDrawSurface4_ReleaseDC(surface, dc);
10349 ok(SUCCEEDED(hr), "Failed to release DC, hr %#lx.\n", hr);
10351 IDirectDrawSurface4_Release(surface);
10354 /* Test INVALIDSURFACETYPE vs INVALIDPIXELFORMAT. */
10355 memset(&surface_desc, 0, sizeof(surface_desc));
10356 surface_desc.dwSize = sizeof(surface_desc);
10357 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
10358 surface_desc.dwWidth = 128;
10359 surface_desc.dwHeight = 128;
10360 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
10361 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
10362 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB;
10363 surface_desc.ddpfPixelFormat.dwRGBBitCount = 32;
10364 surface_desc.ddpfPixelFormat.dwRBitMask = 0x00ff0000;
10365 surface_desc.ddpfPixelFormat.dwGBitMask = 0x0000ff00;
10366 surface_desc.ddpfPixelFormat.dwBBitMask = 0x000000ff;
10367 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
10368 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
10369 hr = IDirectDrawSurface4_SetPalette(surface, palette);
10370 ok(hr == DDERR_INVALIDSURFACETYPE, "Got unexpected hr %#lx.\n", hr);
10371 IDirectDrawSurface4_Release(surface);
10373 /* The Windows 8 testbot keeps extra references to the primary
10374 * while in 8 bpp mode. */
10375 hr = IDirectDraw4_RestoreDisplayMode(ddraw);
10376 ok(SUCCEEDED(hr), "Failed to restore display mode, hr %#lx.\n", hr);
10378 refcount = IDirectDrawPalette_Release(palette);
10379 ok(!refcount, "Got unexpected refcount %lu.\n", refcount);
10380 refcount = IDirectDraw4_Release(ddraw);
10381 ok(!refcount, "Got unexpected refcount %lu.\n", refcount);
10382 DestroyWindow(window);
10385 static void test_vb_writeonly(void)
10387 IDirect3DDevice3 *device;
10388 IDirect3D3 *d3d;
10389 IDirect3DVertexBuffer *buffer;
10390 HWND window;
10391 HRESULT hr;
10392 D3DVERTEXBUFFERDESC desc;
10393 void *ptr;
10394 static const struct vec4 quad[] =
10396 { 0.0f, 480.0f, 0.0f, 1.0f},
10397 { 0.0f, 0.0f, 0.0f, 1.0f},
10398 {640.0f, 480.0f, 0.0f, 1.0f},
10399 {640.0f, 0.0f, 0.0f, 1.0f},
10402 window = create_window();
10403 if (!(device = create_device(window, DDSCL_NORMAL)))
10405 skip("Failed to create a 3D device, skipping test.\n");
10406 DestroyWindow(window);
10407 return;
10410 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
10411 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#lx.\n", hr);
10413 memset(&desc, 0, sizeof(desc));
10414 desc.dwSize = sizeof(desc);
10415 desc.dwCaps = D3DVBCAPS_WRITEONLY;
10416 desc.dwFVF = D3DFVF_XYZRHW;
10417 desc.dwNumVertices = ARRAY_SIZE(quad);
10418 hr = IDirect3D3_CreateVertexBuffer(d3d, &desc, &buffer, 0, NULL);
10419 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#lx.\n", hr);
10421 hr = IDirect3DVertexBuffer_Lock(buffer, DDLOCK_DISCARDCONTENTS, &ptr, NULL);
10422 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#lx.\n", hr);
10423 memcpy(ptr, quad, sizeof(quad));
10424 hr = IDirect3DVertexBuffer_Unlock(buffer);
10425 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#lx.\n", hr);
10427 hr = IDirect3DDevice3_BeginScene(device);
10428 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#lx.\n", hr);
10429 hr = IDirect3DDevice3_DrawPrimitiveVB(device, D3DPT_TRIANGLESTRIP, buffer, 0, 4, 0);
10430 ok(SUCCEEDED(hr), "Failed to draw, hr %#lx.\n", hr);
10431 hr = IDirect3DDevice3_EndScene(device);
10432 ok(SUCCEEDED(hr), "Failed to end scene, hr %#lx.\n", hr);
10434 hr = IDirect3DVertexBuffer_Lock(buffer, 0, &ptr, NULL);
10435 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#lx.\n", hr);
10436 ok (!memcmp(ptr, quad, sizeof(quad)), "Got unexpected vertex buffer data.\n");
10437 hr = IDirect3DVertexBuffer_Unlock(buffer);
10438 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#lx.\n", hr);
10440 hr = IDirect3DVertexBuffer_Lock(buffer, DDLOCK_READONLY, &ptr, NULL);
10441 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#lx.\n", hr);
10442 ok (!memcmp(ptr, quad, sizeof(quad)), "Got unexpected vertex buffer data.\n");
10443 hr = IDirect3DVertexBuffer_Unlock(buffer);
10444 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#lx.\n", hr);
10446 IDirect3DVertexBuffer_Release(buffer);
10447 IDirect3D3_Release(d3d);
10448 IDirect3DDevice3_Release(device);
10449 DestroyWindow(window);
10452 static void test_lost_device(void)
10454 IDirectDrawSurface4 *surface, *back_buffer, *back_buffer2, *ds;
10455 IDirectDrawSurface4 *sysmem_surface, *vidmem_surface;
10456 DDSURFACEDESC2 surface_desc;
10457 HWND window1, window2;
10458 IDirectDraw4 *ddraw;
10459 DDPIXELFORMAT z_fmt;
10460 IDirect3D3 *d3d;
10462 ULONG refcount;
10463 DDSCAPS2 caps;
10464 HRESULT hr;
10465 BOOL ret;
10467 window1 = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
10468 0, 0, 640, 480, 0, 0, 0, 0);
10469 window2 = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
10470 0, 0, 640, 480, 0, 0, 0, 0);
10471 ddraw = create_ddraw();
10472 ok(!!ddraw, "Failed to create a ddraw object.\n");
10473 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window1, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
10474 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10476 memset(&surface_desc, 0, sizeof(surface_desc));
10477 surface_desc.dwSize = sizeof(surface_desc);
10478 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
10479 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
10480 surface_desc.dwBackBufferCount = 1;
10481 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
10482 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10484 memset(&surface_desc, 0, sizeof(surface_desc));
10485 surface_desc.dwSize = sizeof(surface_desc);
10486 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
10487 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
10488 surface_desc.dwWidth = 100;
10489 surface_desc.dwHeight = 100;
10490 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &sysmem_surface, NULL);
10491 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10493 memset(&surface_desc, 0, sizeof(surface_desc));
10494 surface_desc.dwSize = sizeof(surface_desc);
10495 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
10496 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY;
10497 surface_desc.dwWidth = 64;
10498 surface_desc.dwHeight = 64;
10499 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
10500 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB;
10501 surface_desc.ddpfPixelFormat.dwRGBBitCount = 32;
10502 surface_desc.ddpfPixelFormat.dwRBitMask = 0x00ff0000;
10503 surface_desc.ddpfPixelFormat.dwGBitMask = 0x0000ff00;
10504 surface_desc.ddpfPixelFormat.dwBBitMask = 0x000000ff;
10505 if (FAILED(IDirectDraw4_CreateSurface(ddraw, &surface_desc, &vidmem_surface, NULL)))
10507 skip("Failed to create video memory surface, skipping related tests.\n");
10508 vidmem_surface = NULL;
10511 hr = IDirectDraw4_TestCooperativeLevel(ddraw);
10512 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10513 hr = IDirectDrawSurface4_IsLost(surface);
10514 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10515 hr = IDirectDrawSurface4_Flip(surface, NULL, DDFLIP_WAIT);
10516 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10517 hr = IDirectDrawSurface4_IsLost(sysmem_surface);
10518 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10519 if (vidmem_surface)
10521 hr = IDirectDrawSurface4_IsLost(vidmem_surface);
10522 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10525 ret = SetForegroundWindow(GetDesktopWindow());
10526 ok(ret, "Failed to set foreground window.\n");
10527 hr = IDirectDraw4_TestCooperativeLevel(ddraw);
10528 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#lx.\n", hr);
10529 hr = IDirectDrawSurface4_IsLost(surface);
10530 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#lx.\n", hr);
10531 hr = IDirectDrawSurface4_Flip(surface, NULL, DDFLIP_WAIT);
10532 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#lx.\n", hr);
10533 hr = IDirectDrawSurface4_Restore(surface);
10534 ok(hr == DDERR_WRONGMODE, "Got unexpected hr %#lx.\n", hr);
10535 hr = IDirectDrawSurface4_IsLost(surface);
10536 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#lx.\n", hr);
10537 hr = IDirectDrawSurface4_IsLost(sysmem_surface);
10538 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10539 hr = IDirectDrawSurface4_Restore(sysmem_surface);
10540 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10541 hr = IDirectDrawSurface4_IsLost(sysmem_surface);
10542 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10543 if (vidmem_surface)
10545 hr = IDirectDrawSurface4_IsLost(vidmem_surface);
10546 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#lx.\n", hr);
10547 hr = IDirectDrawSurface4_Restore(vidmem_surface);
10548 ok(hr == DDERR_WRONGMODE, "Got unexpected hr %#lx.\n", hr);
10549 hr = IDirectDrawSurface4_IsLost(vidmem_surface);
10550 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#lx.\n", hr);
10553 ret = SetForegroundWindow(window1);
10554 ok(ret, "Failed to set foreground window.\n");
10555 hr = IDirectDraw4_TestCooperativeLevel(ddraw);
10556 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10557 hr = IDirectDrawSurface4_IsLost(surface);
10558 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#lx.\n", hr);
10559 hr = IDirectDrawSurface4_Flip(surface, NULL, DDFLIP_WAIT);
10560 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#lx.\n", hr);
10561 hr = IDirectDrawSurface4_IsLost(sysmem_surface);
10562 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10563 if (vidmem_surface)
10565 hr = IDirectDrawSurface4_IsLost(vidmem_surface);
10566 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#lx.\n", hr);
10569 hr = IDirectDraw4_RestoreAllSurfaces(ddraw);
10570 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10571 hr = IDirectDraw4_TestCooperativeLevel(ddraw);
10572 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10573 hr = IDirectDrawSurface4_IsLost(surface);
10574 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10575 hr = IDirectDrawSurface4_Flip(surface, NULL, DDFLIP_WAIT);
10576 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10577 hr = IDirectDrawSurface4_IsLost(sysmem_surface);
10578 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10579 if (vidmem_surface)
10581 hr = IDirectDrawSurface4_IsLost(vidmem_surface);
10582 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10585 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window1, DDSCL_NORMAL);
10586 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10587 hr = IDirectDraw4_TestCooperativeLevel(ddraw);
10588 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10589 hr = IDirectDrawSurface4_IsLost(surface);
10590 todo_wine ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#lx.\n", hr);
10591 hr = IDirectDrawSurface4_Flip(surface, NULL, DDFLIP_WAIT);
10592 todo_wine ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#lx.\n", hr);
10593 hr = IDirectDrawSurface4_IsLost(sysmem_surface);
10594 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10595 if (vidmem_surface)
10597 hr = IDirectDrawSurface4_IsLost(vidmem_surface);
10598 todo_wine ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#lx.\n", hr);
10601 /* Trying to restore the primary will crash, probably because flippable
10602 * surfaces can't exist in DDSCL_NORMAL. */
10603 IDirectDrawSurface4_Release(surface);
10604 memset(&surface_desc, 0, sizeof(surface_desc));
10605 surface_desc.dwSize = sizeof(surface_desc);
10606 surface_desc.dwFlags = DDSD_CAPS;
10607 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
10608 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
10609 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10610 hr = IDirectDraw4_RestoreAllSurfaces(ddraw);
10611 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10613 hr = IDirectDraw4_TestCooperativeLevel(ddraw);
10614 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10615 hr = IDirectDrawSurface4_IsLost(surface);
10616 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10617 hr = IDirectDrawSurface4_IsLost(sysmem_surface);
10618 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10619 if (vidmem_surface)
10621 hr = IDirectDrawSurface4_IsLost(vidmem_surface);
10622 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10625 ret = SetForegroundWindow(GetDesktopWindow());
10626 ok(ret, "Failed to set foreground window.\n");
10627 hr = IDirectDraw4_TestCooperativeLevel(ddraw);
10628 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10629 hr = IDirectDrawSurface4_IsLost(surface);
10630 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10631 hr = IDirectDrawSurface4_IsLost(sysmem_surface);
10632 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10633 if (vidmem_surface)
10635 hr = IDirectDrawSurface4_IsLost(vidmem_surface);
10636 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10639 ret = SetForegroundWindow(window1);
10640 ok(ret, "Failed to set foreground window.\n");
10641 hr = IDirectDraw4_TestCooperativeLevel(ddraw);
10642 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10643 hr = IDirectDrawSurface4_IsLost(surface);
10644 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10645 hr = IDirectDrawSurface4_IsLost(sysmem_surface);
10646 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10647 if (vidmem_surface)
10649 hr = IDirectDrawSurface4_IsLost(vidmem_surface);
10650 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10653 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window1, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
10654 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10655 hr = IDirectDraw4_TestCooperativeLevel(ddraw);
10656 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10657 hr = IDirectDrawSurface4_IsLost(surface);
10658 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#lx.\n", hr);
10659 hr = IDirectDrawSurface4_IsLost(sysmem_surface);
10660 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10661 if (vidmem_surface)
10663 hr = IDirectDrawSurface4_IsLost(vidmem_surface);
10664 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#lx.\n", hr);
10667 hr = IDirectDraw4_RestoreAllSurfaces(ddraw);
10668 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10669 hr = IDirectDraw4_TestCooperativeLevel(ddraw);
10670 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10671 hr = IDirectDrawSurface4_IsLost(surface);
10672 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10673 hr = IDirectDrawSurface4_IsLost(sysmem_surface);
10674 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10675 if (vidmem_surface)
10677 hr = IDirectDrawSurface4_IsLost(vidmem_surface);
10678 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10681 IDirectDrawSurface4_Release(surface);
10682 memset(&surface_desc, 0, sizeof(surface_desc));
10683 surface_desc.dwSize = sizeof(surface_desc);
10684 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
10685 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
10686 surface_desc.dwBackBufferCount = 2;
10687 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
10688 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10691 ds = NULL;
10692 hr = IDirectDraw4_QueryInterface(ddraw, &IID_IDirect3D3, (void **)&d3d);
10693 if (hr == S_OK)
10695 memset(&z_fmt, 0, sizeof(z_fmt));
10696 hr = IDirect3D3_EnumZBufferFormats(d3d, &IID_IDirect3DHALDevice, enum_z_fmt, &z_fmt);
10697 if (FAILED(hr) || !z_fmt.dwSize)
10699 skip("No depth buffer formats available, skipping Z buffer restore test.\n");
10701 else
10703 memset(&surface_desc, 0, sizeof(surface_desc));
10704 surface_desc.dwSize = sizeof(surface_desc);
10705 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &surface_desc);
10706 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
10708 surface_desc.dwFlags = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT;
10709 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
10710 surface_desc.ddpfPixelFormat = z_fmt;
10711 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &ds, NULL);
10712 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10714 hr = IDirectDrawSurface_AddAttachedSurface(surface, ds);
10715 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10717 IDirect3D3_Release(d3d);
10719 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window1, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
10720 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10721 hr = IDirectDraw4_TestCooperativeLevel(ddraw);
10722 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10723 hr = IDirectDrawSurface4_IsLost(surface);
10724 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10725 hr = IDirectDrawSurface4_Flip(surface, NULL, DDFLIP_WAIT);
10726 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10727 hr = IDirectDrawSurface4_IsLost(sysmem_surface);
10728 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10729 if (vidmem_surface)
10731 hr = IDirectDrawSurface4_IsLost(vidmem_surface);
10732 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10735 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window1, DDSCL_NORMAL | DDSCL_FULLSCREEN);
10736 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10737 hr = IDirectDraw4_TestCooperativeLevel(ddraw);
10738 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10739 hr = IDirectDrawSurface4_IsLost(surface);
10740 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10741 hr = IDirectDrawSurface4_Flip(surface, NULL, DDFLIP_WAIT);
10742 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#lx.\n", hr);
10743 hr = IDirectDrawSurface4_IsLost(sysmem_surface);
10744 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10745 if (vidmem_surface)
10747 hr = IDirectDrawSurface4_IsLost(vidmem_surface);
10748 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10751 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window1, DDSCL_NORMAL);
10752 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10753 hr = IDirectDraw4_TestCooperativeLevel(ddraw);
10754 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10755 hr = IDirectDrawSurface4_IsLost(surface);
10756 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10757 hr = IDirectDrawSurface4_Flip(surface, NULL, DDFLIP_WAIT);
10758 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#lx.\n", hr);
10759 hr = IDirectDrawSurface4_IsLost(sysmem_surface);
10760 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10761 if (vidmem_surface)
10763 hr = IDirectDrawSurface4_IsLost(vidmem_surface);
10764 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10767 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window2, DDSCL_NORMAL);
10768 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10769 hr = IDirectDraw4_TestCooperativeLevel(ddraw);
10770 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10771 hr = IDirectDrawSurface4_IsLost(surface);
10772 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10773 hr = IDirectDrawSurface4_Flip(surface, NULL, DDFLIP_WAIT);
10774 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#lx.\n", hr);
10775 hr = IDirectDrawSurface4_IsLost(sysmem_surface);
10776 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10777 if (vidmem_surface)
10779 hr = IDirectDrawSurface4_IsLost(vidmem_surface);
10780 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10783 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window2, DDSCL_NORMAL | DDSCL_FULLSCREEN);
10784 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10785 hr = IDirectDraw4_TestCooperativeLevel(ddraw);
10786 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10787 hr = IDirectDrawSurface4_IsLost(surface);
10788 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10789 hr = IDirectDrawSurface4_Flip(surface, NULL, DDFLIP_WAIT);
10790 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#lx.\n", hr);
10791 hr = IDirectDrawSurface4_IsLost(sysmem_surface);
10792 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10793 if (vidmem_surface)
10795 hr = IDirectDrawSurface4_IsLost(vidmem_surface);
10796 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10799 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window2, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
10800 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10801 hr = IDirectDraw4_TestCooperativeLevel(ddraw);
10802 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10803 hr = IDirectDrawSurface4_IsLost(surface);
10804 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#lx.\n", hr);
10805 hr = IDirectDrawSurface4_IsLost(sysmem_surface);
10806 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10807 if (vidmem_surface)
10809 hr = IDirectDrawSurface4_IsLost(vidmem_surface);
10810 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#lx.\n", hr);
10813 hr = IDirectDrawSurface4_Flip(surface, NULL, DDFLIP_WAIT);
10814 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#lx.\n", hr);
10816 memset(&caps, 0, sizeof(caps));
10817 caps.dwCaps = DDSCAPS_FLIP;
10819 hr = IDirectDrawSurface4_GetAttachedSurface(surface, &caps, &back_buffer);
10820 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#lx.\n", hr);
10821 hr = IDirectDrawSurface4_Restore(surface);
10822 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10823 hr = IDirectDrawSurface4_GetAttachedSurface(surface, &caps, &back_buffer);
10824 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10825 ok(back_buffer != surface, "Got the same surface.\n");
10826 hr = IDirectDrawSurface4_IsLost(back_buffer);
10827 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10828 IDirectDrawSurface4_Release(back_buffer);
10830 hr = IDirectDrawSurface4_GetAttachedSurface(back_buffer, &caps, &back_buffer2);
10831 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10832 ok(back_buffer2 != back_buffer, "Got the same surface.\n");
10833 ok(back_buffer2 != surface, "Got the same surface.\n");
10834 hr = IDirectDrawSurface4_IsLost(back_buffer2);
10835 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10836 IDirectDrawSurface4_Release(back_buffer2);
10838 if (ds)
10840 hr = IDirectDrawSurface4_IsLost(ds);
10841 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#lx.\n", hr);
10842 hr = IDirectDrawSurface4_Restore(ds);
10843 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10844 hr = IDirectDrawSurface4_IsLost(ds);
10845 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
10846 IDirectDrawSurface4_Release(ds);
10849 if (vidmem_surface)
10850 IDirectDrawSurface4_Release(vidmem_surface);
10851 IDirectDrawSurface4_Release(sysmem_surface);
10852 IDirectDrawSurface4_Release(surface);
10853 refcount = IDirectDraw4_Release(ddraw);
10854 ok(!refcount, "Got unexpected refcount %lu.\n", refcount);
10855 DestroyWindow(window2);
10856 DestroyWindow(window1);
10859 static void test_surface_desc_lock(void)
10861 IDirectDrawSurface4 *surface;
10862 DDSURFACEDESC2 surface_desc;
10863 IDirectDraw4 *ddraw;
10864 ULONG refcount;
10865 HWND window;
10866 HRESULT hr;
10868 window = create_window();
10869 ddraw = create_ddraw();
10870 ok(!!ddraw, "Failed to create a ddraw object.\n");
10871 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
10872 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
10874 memset(&surface_desc, 0, sizeof(surface_desc));
10875 surface_desc.dwSize = sizeof(surface_desc);
10876 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
10877 surface_desc.dwWidth = 16;
10878 surface_desc.dwHeight = 16;
10879 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
10880 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
10881 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
10883 memset(&surface_desc, 0xaa, sizeof(surface_desc));
10884 surface_desc.dwSize = sizeof(surface_desc);
10885 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &surface_desc);
10886 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#lx.\n", hr);
10887 ok(!surface_desc.lpSurface, "Got unexpected lpSurface %p.\n", surface_desc.lpSurface);
10889 memset(&surface_desc, 0xaa, sizeof(surface_desc));
10890 surface_desc.dwSize = sizeof(surface_desc);
10891 hr = IDirectDrawSurface4_Lock(surface, NULL, &surface_desc, 0, NULL);
10892 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#lx.\n", hr);
10893 ok(surface_desc.lpSurface != NULL, "Got unexpected lpSurface %p.\n", surface_desc.lpSurface);
10894 memset(&surface_desc, 0xaa, sizeof(surface_desc));
10895 surface_desc.dwSize = sizeof(surface_desc);
10896 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &surface_desc);
10897 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#lx.\n", hr);
10898 ok(!surface_desc.lpSurface, "Got unexpected lpSurface %p.\n", surface_desc.lpSurface);
10899 hr = IDirectDrawSurface4_Unlock(surface, NULL);
10900 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx.\n", hr);
10902 memset(&surface_desc, 0xaa, sizeof(surface_desc));
10903 surface_desc.dwSize = sizeof(surface_desc);
10904 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &surface_desc);
10905 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#lx.\n", hr);
10906 ok(!surface_desc.lpSurface, "Got unexpected lpSurface %p.\n", surface_desc.lpSurface);
10908 IDirectDrawSurface4_Release(surface);
10909 refcount = IDirectDraw4_Release(ddraw);
10910 ok(!refcount, "Got unexpected refcount %lu.\n", refcount);
10911 DestroyWindow(window);
10914 static void test_texturemapblend(void)
10916 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
10917 static RECT rect = {0, 0, 64, 128};
10918 IDirectDrawSurface4 *surface, *rt;
10919 IDirect3DViewport3 *viewport;
10920 DDSURFACEDESC2 surface_desc;
10921 IDirect3DTexture2 *texture;
10922 IDirect3DDevice3 *device;
10923 DWORD texturemapblend;
10924 IDirectDraw4 *ddraw;
10925 unsigned int color;
10926 IDirect3D3 *d3d;
10927 DDCOLORKEY ckey;
10928 ULONG refcount;
10929 DWORD value;
10930 HWND window;
10931 DDBLTFX fx;
10932 HRESULT hr;
10934 static struct
10936 struct vec4 position;
10937 D3DCOLOR diffuse;
10938 struct vec2 texcoord;
10940 test1_quads[] =
10942 {{ 0.0f, 0.0f, 0.0f, 1.0f}, 0xffffffff, {0.0f, 0.0f}},
10943 {{ 0.0f, 240.0f, 0.0f, 1.0f}, 0xffffffff, {0.0f, 1.0f}},
10944 {{640.0f, 0.0f, 0.0f, 1.0f}, 0xffffffff, {1.0f, 0.0f}},
10945 {{640.0f, 240.0f, 0.0f, 1.0f}, 0xffffffff, {1.0f, 1.0f}},
10946 {{ 0.0f, 240.0f, 0.0f, 1.0f}, 0x80ffffff, {0.0f, 0.0f}},
10947 {{ 0.0f, 480.0f, 0.0f, 1.0f}, 0x80ffffff, {0.0f, 1.0f}},
10948 {{640.0f, 240.0f, 0.0f, 1.0f}, 0x80ffffff, {1.0f, 0.0f}},
10949 {{640.0f, 480.0f, 0.0f, 1.0f}, 0x80ffffff, {1.0f, 1.0f}},
10951 test2_quads[] =
10953 {{ 0.0f, 0.0f, 0.0f, 1.0f}, 0x00ff0080, {0.0f, 0.0f}},
10954 {{ 0.0f, 240.0f, 0.0f, 1.0f}, 0x00ff0080, {0.0f, 1.0f}},
10955 {{640.0f, 0.0f, 0.0f, 1.0f}, 0x00ff0080, {1.0f, 0.0f}},
10956 {{640.0f, 240.0f, 0.0f, 1.0f}, 0x00ff0080, {1.0f, 1.0f}},
10957 {{ 0.0f, 240.0f, 0.0f, 1.0f}, 0x008000ff, {0.0f, 0.0f}},
10958 {{ 0.0f, 480.0f, 0.0f, 1.0f}, 0x008000ff, {0.0f, 1.0f}},
10959 {{640.0f, 240.0f, 0.0f, 1.0f}, 0x008000ff, {1.0f, 0.0f}},
10960 {{640.0f, 480.0f, 0.0f, 1.0f}, 0x008000ff, {1.0f, 1.0f}},
10963 window = create_window();
10964 if (!(device = create_device(window, DDSCL_NORMAL)))
10966 skip("Failed to create a 3D device, skipping test.\n");
10967 DestroyWindow(window);
10968 return;
10971 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
10972 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
10973 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
10974 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
10975 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
10976 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
10978 viewport = create_viewport(device, 0, 0, 640, 480);
10979 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
10980 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
10982 hr = IDirect3DDevice3_GetRenderState(device, D3DRENDERSTATE_TEXTUREMAPBLEND, &texturemapblend);
10983 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
10984 ok(texturemapblend == D3DTBLEND_MODULATE, "Got unexpected texture map blend %#lx.\n", texturemapblend);
10986 hr = IDirect3DDevice3_GetTextureStageState(device, 0, D3DTSS_ALPHAOP, &value);
10987 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
10988 ok(value == D3DTOP_SELECTARG1, "Got unexpected D3DTSS_ALPHAOP value %#lx.\n", value);
10990 /* Test alpha with DDPF_ALPHAPIXELS texture - should be taken from texture
10991 * alpha channel.
10993 * The vertex alpha is completely ignored in this case, so case 1 and 2
10994 * combined are not a D3DTOP_MODULATE with texture alpha = 0xff in case 2
10995 * (no alpha in texture). */
10996 memset(&surface_desc, 0, sizeof(surface_desc));
10997 surface_desc.dwSize = sizeof(surface_desc);
10998 surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
10999 surface_desc.dwHeight = 128;
11000 surface_desc.dwWidth = 128;
11001 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
11002 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
11003 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
11004 surface_desc.ddpfPixelFormat.dwRGBBitCount = 32;
11005 surface_desc.ddpfPixelFormat.dwRBitMask = 0x00ff0000;
11006 surface_desc.ddpfPixelFormat.dwGBitMask = 0x0000ff00;
11007 surface_desc.ddpfPixelFormat.dwBBitMask = 0x000000ff;
11008 surface_desc.ddpfPixelFormat.dwRGBAlphaBitMask = 0xff000000;
11009 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
11010 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11012 hr = IDirectDrawSurface4_QueryInterface(surface, &IID_IDirect3DTexture2, (void **)&texture);
11013 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11014 hr = IDirect3DDevice3_SetTexture(device, 0, texture);
11015 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11017 hr = IDirect3DDevice3_GetTextureStageState(device, 0, D3DTSS_ALPHAOP, &value);
11018 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11019 ok(value == D3DTOP_SELECTARG1, "Got unexpected D3DTSS_ALPHAOP value %#lx.\n", value);
11021 hr = IDirect3DDevice3_SetTexture(device, 0, NULL);
11022 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11024 hr = IDirect3DDevice3_GetTextureStageState(device, 0, D3DTSS_ALPHAOP, &value);
11025 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11026 ok(value == D3DTOP_SELECTARG1, "Got unexpected D3DTSS_ALPHAOP value %#lx.\n", value);
11028 hr = IDirect3DDevice3_SetTexture(device, 0, texture);
11029 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11031 hr = IDirect3DViewport3_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
11032 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11034 memset(&fx, 0, sizeof(fx));
11035 fx.dwSize = sizeof(fx);
11036 fx.dwFillColor = 0xff0000ff;
11037 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
11038 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11039 fx.dwFillColor = 0x800000ff;
11040 hr = IDirectDrawSurface4_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
11041 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11043 /* Note that the ddraw1 version of this test runs tests 1-3 with
11044 * D3DRENDERSTATE_COLORKEYENABLE enabled, whereas this version only runs
11045 * test 4 with color keying on. Because no color key is set on the texture
11046 * this should not result in different behavior. */
11047 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_CULLMODE, D3DCULL_NONE);
11048 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11049 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
11050 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11051 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);
11052 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11053 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA);
11054 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11055 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);
11056 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11058 #if 0
11059 /* Disable the call to test that the device has this state by default. */
11060 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_TEXTUREMAPBLEND, D3DTBLEND_MODULATE);
11061 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11062 #endif
11064 /* Texture stage state does not change so legacy texture blending stays enabled. */
11065 hr = IDirect3DDevice3_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_MODULATE);
11066 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11068 hr = IDirect3DDevice3_BeginScene(device);
11069 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11070 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
11071 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1, &test1_quads[0], 4, 0);
11072 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11073 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
11074 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1, &test1_quads[4], 4, 0);
11075 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11076 hr = IDirect3DDevice3_EndScene(device);
11077 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11079 color = get_surface_color(rt, 5, 5);
11080 ok(compare_color(color, 0x00000080, 2), "Got unexpected color 0x%08x.\n", color);
11081 color = get_surface_color(rt, 400, 5);
11082 ok(compare_color(color, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color);
11083 color = get_surface_color(rt, 5, 245);
11084 ok(compare_color(color, 0x00000080, 2), "Got unexpected color 0x%08x.\n", color);
11085 color = get_surface_color(rt, 400, 245);
11086 ok(compare_color(color, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color);
11088 /* Turn legacy texture blending off. */
11089 hr = IDirect3DDevice3_SetTextureStageState(device, 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2);
11090 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11091 hr = IDirect3DDevice3_SetTexture(device, 0, texture);
11092 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11093 hr = IDirect3DViewport3_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
11094 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11095 hr = IDirect3DDevice3_BeginScene(device);
11096 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11097 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
11098 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1, &test1_quads[0], 4, 0);
11099 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11100 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
11101 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1, &test1_quads[4], 4, 0);
11102 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11103 hr = IDirect3DDevice3_EndScene(device);
11104 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11106 color = get_surface_color(rt, 5, 5);
11107 ok(compare_color(color, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color);
11108 color = get_surface_color(rt, 400, 5);
11109 ok(compare_color(color, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color);
11110 color = get_surface_color(rt, 5, 245);
11111 ok(compare_color(color, 0x00000080, 2), "Got unexpected color 0x%08x.\n", color);
11112 color = get_surface_color(rt, 400, 245);
11113 ok(compare_color(color, 0x00000080, 2), "Got unexpected color 0x%08x.\n", color);
11115 /* This doesn't turn legacy texture blending on again, as setting the same
11116 * _TEXTUREMAPBLEND value. */
11117 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_TEXTUREMAPBLEND, D3DTBLEND_MODULATE);
11118 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11119 hr = IDirect3DDevice3_SetTexture(device, 0, texture);
11120 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11121 hr = IDirect3DViewport3_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
11122 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11123 hr = IDirect3DDevice3_BeginScene(device);
11124 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11125 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
11126 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1, &test1_quads[0], 4, 0);
11127 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11128 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
11129 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1, &test1_quads[4], 4, 0);
11130 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11131 hr = IDirect3DDevice3_EndScene(device);
11132 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11134 color = get_surface_color(rt, 5, 5);
11135 ok(compare_color(color, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color);
11136 color = get_surface_color(rt, 400, 5);
11137 ok(compare_color(color, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color);
11138 color = get_surface_color(rt, 5, 245);
11139 ok(compare_color(color, 0x00000080, 2), "Got unexpected color 0x%08x.\n", color);
11140 color = get_surface_color(rt, 400, 245);
11141 ok(compare_color(color, 0x00000080, 2), "Got unexpected color 0x%08x.\n", color);
11143 /* Turn legacy texture blending on again. */
11144 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_TEXTUREMAPBLEND, D3DTBLEND_ADD);
11145 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11146 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_TEXTUREMAPBLEND, D3DTBLEND_MODULATE);
11147 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11148 hr = IDirect3DDevice3_SetTexture(device, 0, texture);
11149 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11150 hr = IDirect3DViewport3_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
11151 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11152 hr = IDirect3DDevice3_BeginScene(device);
11153 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11154 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
11155 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1, &test1_quads[0], 4, 0);
11156 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11157 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
11158 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1, &test1_quads[4], 4, 0);
11159 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11160 hr = IDirect3DDevice3_EndScene(device);
11161 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11163 color = get_surface_color(rt, 5, 5);
11164 ok(compare_color(color, 0x00000080, 2), "Got unexpected color 0x%08x.\n", color);
11165 color = get_surface_color(rt, 400, 5);
11166 ok(compare_color(color, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color);
11167 color = get_surface_color(rt, 5, 245);
11168 ok(compare_color(color, 0x00000080, 2), "Got unexpected color 0x%08x.\n", color);
11169 color = get_surface_color(rt, 400, 245);
11170 ok(compare_color(color, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color);
11172 hr = IDirect3DDevice3_SetTexture(device, 0, NULL);
11173 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11174 IDirect3DTexture2_Release(texture);
11175 refcount = IDirectDrawSurface4_Release(surface);
11176 ok(!refcount, "Unexpected refcount %lu.\n", refcount);
11178 /* Test alpha with texture that has no alpha channel - alpha should be
11179 * taken from diffuse vertex color. */
11180 memset(&surface_desc, 0, sizeof(surface_desc));
11181 surface_desc.dwSize = sizeof(surface_desc);
11182 surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
11183 surface_desc.dwHeight = 128;
11184 surface_desc.dwWidth = 128;
11185 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
11186 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
11187 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB;
11188 surface_desc.ddpfPixelFormat.dwRGBBitCount = 32;
11189 surface_desc.ddpfPixelFormat.dwRBitMask = 0x00ff0000;
11190 surface_desc.ddpfPixelFormat.dwGBitMask = 0x0000ff00;
11191 surface_desc.ddpfPixelFormat.dwBBitMask = 0x000000ff;
11193 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
11194 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11196 hr = IDirectDrawSurface4_QueryInterface(surface, &IID_IDirect3DTexture2, (void **)&texture);
11197 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11198 hr = IDirect3DDevice3_SetTexture(device, 0, texture);
11199 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11201 hr = IDirect3DDevice3_GetTextureStageState(device, 0, D3DTSS_ALPHAOP, &value);
11202 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11203 ok(value == D3DTOP_SELECTARG2, "Got unexpected D3DTSS_ALPHAOP value %#lx.\n", value);
11205 hr = IDirect3DViewport3_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
11206 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11208 fx.dwFillColor = 0xff0000ff;
11209 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
11210 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11211 fx.dwFillColor = 0x800000ff;
11212 hr = IDirectDrawSurface4_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
11213 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11215 hr = IDirect3DDevice3_BeginScene(device);
11216 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11217 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
11218 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1, &test1_quads[0], 4, 0);
11219 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11220 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
11221 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1, &test1_quads[4], 4, 0);
11222 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11223 hr = IDirect3DDevice3_EndScene(device);
11224 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
11226 color = get_surface_color(rt, 5, 5);
11227 ok(compare_color(color, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color);
11228 color = get_surface_color(rt, 400, 5);
11229 ok(compare_color(color, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color);
11230 color = get_surface_color(rt, 5, 245);
11231 ok(compare_color(color, 0x00000080, 2), "Got unexpected color 0x%08x.\n", color);
11232 color = get_surface_color(rt, 400, 245);
11233 ok(compare_color(color, 0x00000080, 2), "Got unexpected color 0x%08x.\n", color);
11235 hr = IDirect3DDevice3_SetTexture(device, 0, NULL);
11236 ok(SUCCEEDED(hr), "Failed to set texture, hr %#lx.\n", hr);
11237 IDirect3DTexture2_Release(texture);
11238 refcount = IDirectDrawSurface4_Release(surface);
11239 ok(!refcount, "Unexpected refcount %lu.\n", refcount);
11241 /* Test RGB - should multiply color components from diffuse vertex color
11242 * and texture. */
11243 memset(&surface_desc, 0, sizeof(surface_desc));
11244 surface_desc.dwSize = sizeof(surface_desc);
11245 surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
11246 surface_desc.dwHeight = 128;
11247 surface_desc.dwWidth = 128;
11248 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
11249 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
11250 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
11251 surface_desc.ddpfPixelFormat.dwRGBBitCount = 32;
11252 surface_desc.ddpfPixelFormat.dwRBitMask = 0x00ff0000;
11253 surface_desc.ddpfPixelFormat.dwGBitMask = 0x0000ff00;
11254 surface_desc.ddpfPixelFormat.dwBBitMask = 0x000000ff;
11255 surface_desc.ddpfPixelFormat.dwRGBAlphaBitMask = 0xff000000;
11256 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
11257 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
11259 hr = IDirectDrawSurface4_QueryInterface(surface, &IID_IDirect3DTexture2, (void **)&texture);
11260 ok(SUCCEEDED(hr), "Failed to get texture interface, hr %#lx.\n", hr);
11261 hr = IDirect3DDevice3_SetTexture(device, 0, texture);
11262 ok(SUCCEEDED(hr), "Failed to set texture, hr %#lx.\n", hr);
11264 hr = IDirect3DViewport3_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
11265 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#lx.\n", hr);
11267 fx.dwFillColor = 0x00ffffff;
11268 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
11269 ok(SUCCEEDED(hr), "Failed to clear texture, hr %#lx.\n", hr);
11270 fx.dwFillColor = 0x00ffff80;
11271 hr = IDirectDrawSurface4_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
11272 ok(SUCCEEDED(hr), "Failed to clear texture, hr %#lx.\n", hr);
11274 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, FALSE);
11275 ok(SUCCEEDED(hr), "Failed to set render state, hr %#lx.\n", hr);
11277 hr = IDirect3DDevice3_BeginScene(device);
11278 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#lx.\n", hr);
11279 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
11280 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1, &test2_quads[0], 4, 0);
11281 ok(SUCCEEDED(hr), "Failed to draw, hr %#lx.\n", hr);
11282 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
11283 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1, &test2_quads[4], 4, 0);
11284 ok(SUCCEEDED(hr), "Failed to draw, hr %#lx.\n", hr);
11285 hr = IDirect3DDevice3_EndScene(device);
11286 ok(SUCCEEDED(hr), "Failed to end scene, hr %#lx.\n", hr);
11288 color = get_surface_color(rt, 5, 5);
11289 ok(compare_color(color, 0x00ff0040, 2), "Got unexpected color 0x%08x.\n", color);
11290 color = get_surface_color(rt, 400, 5);
11291 ok(compare_color(color, 0x00ff0080, 2), "Got unexpected color 0x%08x.\n", color);
11292 color = get_surface_color(rt, 5, 245);
11293 ok(compare_color(color, 0x00800080, 2), "Got unexpected color 0x%08x.\n", color);
11294 color = get_surface_color(rt, 400, 245);
11295 ok(compare_color(color, 0x008000ff, 2), "Got unexpected color 0x%08x.\n", color);
11297 hr = IDirect3DDevice3_SetTexture(device, 0, NULL);
11298 ok(SUCCEEDED(hr), "Failed to set texture, hr %#lx.\n", hr);
11299 IDirect3DTexture2_Release(texture);
11300 refcount = IDirectDrawSurface4_Release(surface);
11301 ok(!refcount, "Unexpected refcount %lu.\n", refcount);
11303 /* Test alpha again, now with color keyed texture (colorkey emulation in
11304 * wine can interfere). */
11305 memset(&surface_desc, 0, sizeof(surface_desc));
11306 surface_desc.dwSize = sizeof(surface_desc);
11307 surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
11308 surface_desc.dwHeight = 128;
11309 surface_desc.dwWidth = 128;
11310 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
11311 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
11312 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB;
11313 surface_desc.ddpfPixelFormat.dwRGBBitCount = 16;
11314 surface_desc.ddpfPixelFormat.dwRBitMask = 0xf800;
11315 surface_desc.ddpfPixelFormat.dwGBitMask = 0x07e0;
11316 surface_desc.ddpfPixelFormat.dwBBitMask = 0x001f;
11318 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
11319 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
11321 hr = IDirectDrawSurface4_QueryInterface(surface, &IID_IDirect3DTexture2, (void **)&texture);
11322 ok(SUCCEEDED(hr), "Failed to get texture interface, hr %#lx.\n", hr);
11323 hr = IDirect3DDevice3_SetTexture(device, 0, texture);
11324 ok(SUCCEEDED(hr), "Failed to set texture, hr %#lx.\n", hr);
11326 hr = IDirect3DViewport3_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
11327 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#lx.\n", hr);
11329 fx.dwFillColor = 0xf800;
11330 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
11331 ok(SUCCEEDED(hr), "Failed to clear texture, hr %#lx.\n", hr);
11332 fx.dwFillColor = 0x001f;
11333 hr = IDirectDrawSurface4_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
11334 ok(SUCCEEDED(hr), "Failed to clear texture, hr %#lx.\n", hr);
11336 ckey.dwColorSpaceLowValue = 0x001f;
11337 ckey.dwColorSpaceHighValue = 0x001f;
11338 hr = IDirectDrawSurface4_SetColorKey(surface, DDCKEY_SRCBLT, &ckey);
11339 ok(SUCCEEDED(hr), "Failed to set color key, hr %#lx.\n", hr);
11341 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);
11342 ok(SUCCEEDED(hr), "Failed to set render state, hr %#lx.\n", hr);
11343 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, TRUE);
11344 ok(SUCCEEDED(hr), "Failed to set render state, hr %#lx.\n", hr);
11346 hr = IDirect3DDevice3_BeginScene(device);
11347 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#lx.\n", hr);
11348 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
11349 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1, &test1_quads[0], 4, 0);
11350 ok(SUCCEEDED(hr), "Failed to draw, hr %#lx.\n", hr);
11351 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
11352 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1, &test1_quads[4], 4, 0);
11353 ok(SUCCEEDED(hr), "Failed to draw, hr %#lx.\n", hr);
11354 hr = IDirect3DDevice3_EndScene(device);
11355 ok(SUCCEEDED(hr), "Failed to end scene, hr %#lx.\n", hr);
11357 color = get_surface_color(rt, 5, 5);
11358 ok(compare_color(color, 0x00000000, 2), "Got unexpected color 0x%08x.\n", color);
11359 color = get_surface_color(rt, 400, 5);
11360 ok(compare_color(color, 0x00ff0000, 2), "Got unexpected color 0x%08x.\n", color);
11361 color = get_surface_color(rt, 5, 245);
11362 ok(compare_color(color, 0x00000000, 2), "Got unexpected color 0x%08x.\n", color);
11363 color = get_surface_color(rt, 400, 245);
11364 ok(compare_color(color, 0x00800000, 2), "Got unexpected color 0x%08x.\n", color);
11366 hr = IDirect3DDevice3_SetTexture(device, 0, NULL);
11367 ok(SUCCEEDED(hr), "Failed to set texture, hr %#lx.\n", hr);
11368 IDirect3DTexture2_Release(texture);
11369 refcount = IDirectDrawSurface4_Release(surface);
11370 ok(!refcount, "Unexpected refcount %lu.\n", refcount);
11372 destroy_viewport(device, viewport);
11373 IDirectDrawSurface4_Release(rt);
11374 IDirect3DDevice3_Release(device);
11375 IDirect3D3_Release(d3d);
11376 refcount = IDirectDraw4_Release(ddraw);
11377 ok(!refcount, "Ddraw object not properly released, refcount %lu.\n", refcount);
11378 DestroyWindow(window);
11381 static void test_signed_formats(void)
11383 unsigned int color, expected_color;
11384 HRESULT hr;
11385 IDirect3DDevice3 *device;
11386 IDirect3D3 *d3d;
11387 IDirectDraw4 *ddraw;
11388 IDirectDrawSurface4 *surface, *rt;
11389 IDirect3DTexture2 *texture;
11390 IDirect3DViewport3 *viewport;
11391 DDSURFACEDESC2 surface_desc;
11392 ULONG refcount;
11393 HWND window;
11394 D3DRECT clear_rect;
11395 static struct
11397 struct vec3 position;
11398 struct vec2 texcoord;
11400 quad[] =
11402 {{-1.0f, -1.0f, 0.0f}, {0.0f, 1.0f}},
11403 {{-1.0f, 1.0f, 0.0f}, {0.0f, 0.0f}},
11404 {{ 1.0f, -1.0f, 0.0f}, {1.0f, 1.0f}},
11405 {{ 1.0f, 1.0f, 0.0f}, {1.0f, 0.0f}},
11407 /* See test_signed_formats() in dlls/d3d9/tests/visual.c for an explanation
11408 * of these values. */
11409 static const USHORT content_v8u8[4][4] =
11411 {0x0000, 0x7f7f, 0x8880, 0x0000},
11412 {0x0080, 0x8000, 0x7f00, 0x007f},
11413 {0x193b, 0xe8c8, 0x0808, 0xf8f8},
11414 {0x4444, 0xc0c0, 0xa066, 0x22e0},
11416 static const DWORD content_x8l8v8u8[4][4] =
11418 {0x00000000, 0x00ff7f7f, 0x00008880, 0x00ff0000},
11419 {0x00000080, 0x00008000, 0x00007f00, 0x0000007f},
11420 {0x0041193b, 0x0051e8c8, 0x00040808, 0x00fff8f8},
11421 {0x00824444, 0x0000c0c0, 0x00c2a066, 0x009222e0},
11423 static const USHORT content_l6v5u5[4][4] =
11425 {0x0000, 0xfdef, 0x0230, 0xfc00},
11426 {0x0010, 0x0200, 0x01e0, 0x000f},
11427 {0x4067, 0x53b9, 0x0421, 0xffff},
11428 {0x8108, 0x0318, 0xc28c, 0x909c},
11430 static const struct
11432 const char *name;
11433 const void *content;
11434 SIZE_T pixel_size;
11435 BOOL blue;
11436 unsigned int slop, slop_broken;
11437 DDPIXELFORMAT format;
11439 formats[] =
11442 "D3DFMT_V8U8", content_v8u8, sizeof(WORD), FALSE, 1, 0,
11444 sizeof(DDPIXELFORMAT), DDPF_BUMPDUDV, 0,
11445 {16}, {0x000000ff}, {0x0000ff00}, {0x00000000}, {0x00000000}
11449 "D3DFMT_X8L8V8U8", content_x8l8v8u8, sizeof(DWORD), TRUE, 1, 0,
11451 sizeof(DDPIXELFORMAT), DDPF_BUMPDUDV | DDPF_BUMPLUMINANCE, 0,
11452 {32}, {0x000000ff}, {0x0000ff00}, {0x00ff0000}, {0x00000000}
11456 "D3DFMT_L6V5U5", content_l6v5u5, sizeof(WORD), TRUE, 4, 7,
11458 sizeof(DDPIXELFORMAT), DDPF_BUMPDUDV | DDPF_BUMPLUMINANCE, 0,
11459 {16}, {0x0000001f}, {0x000003e0}, {0x0000fc00}, {0x00000000}
11463 /* No V16U16 or Q8W8V8U8 support in ddraw. */
11465 static const unsigned int expected_colors[4][4] =
11467 {0x00808080, 0x00fefeff, 0x00010780, 0x008080ff},
11468 {0x00018080, 0x00800180, 0x0080fe80, 0x00fe8080},
11469 {0x00ba98a0, 0x004767a8, 0x00888881, 0x007878ff},
11470 {0x00c3c3c0, 0x003f3f80, 0x00e51fe1, 0x005fa2c8},
11472 unsigned int i, width, x, y;
11473 D3DDEVICEDESC device_desc, hel_desc;
11475 window = create_window();
11476 if (!(device = create_device(window, DDSCL_NORMAL)))
11478 skip("Failed to create a 3D device, skipping test.\n");
11479 DestroyWindow(window);
11480 return;
11483 memset(&device_desc, 0, sizeof(device_desc));
11484 device_desc.dwSize = sizeof(device_desc);
11485 memset(&hel_desc, 0, sizeof(hel_desc));
11486 hel_desc.dwSize = sizeof(hel_desc);
11487 hr = IDirect3DDevice3_GetCaps(device, &device_desc, &hel_desc);
11488 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#lx.\n", hr);
11489 if (!(device_desc.dwTextureOpCaps & D3DTEXOPCAPS_BLENDFACTORALPHA))
11491 skip("D3DTOP_BLENDFACTORALPHA not supported, skipping bumpmap format tests.\n");
11492 goto done;
11495 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
11496 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#lx.\n", hr);
11497 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
11498 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#lx.\n", hr);
11499 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
11500 ok(SUCCEEDED(hr), "Failed to get render target, hr %#lx.\n", hr);
11502 memset(&surface_desc, 0, sizeof(surface_desc));
11503 surface_desc.dwSize = sizeof(surface_desc);
11504 hr = IDirectDrawSurface4_GetSurfaceDesc(rt, &surface_desc);
11505 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#lx.\n", hr);
11506 viewport = create_viewport(device, 0, 0, surface_desc.dwWidth, surface_desc.dwHeight);
11507 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
11508 ok(SUCCEEDED(hr), "Failed to activate the viewport, hr %#lx.\n", hr);
11509 clear_rect.x1 = 0;
11510 clear_rect.y1 = 0;
11511 clear_rect.x2 = surface_desc.dwWidth;
11512 clear_rect.y2 = surface_desc.dwHeight;
11514 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
11515 ok(SUCCEEDED(hr), "Failed to set render state, hr %#lx.\n", hr);
11517 /* dst = tex * 0.5 + 1.0 * (1.0 - 0.5) = tex * 0.5 + 0.5 */
11518 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_TEXTUREFACTOR, 0x80ffffff);
11519 ok(SUCCEEDED(hr), "Failed to set render state, hr %#lx.\n", hr);
11520 hr = IDirect3DDevice3_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_BLENDFACTORALPHA);
11521 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#lx.\n", hr);
11522 hr = IDirect3DDevice3_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
11523 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#lx.\n", hr);
11524 hr = IDirect3DDevice3_SetTextureStageState(device, 0, D3DTSS_COLORARG2, D3DTA_TFACTOR);
11525 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#lx.\n", hr);
11527 for (i = 0; i < ARRAY_SIZE(formats); i++)
11529 for (width = 1; width < 5; width += 3)
11531 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0x00000000, 0.0f, 0);
11532 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#lx.\n", hr);
11534 memset(&surface_desc, 0, sizeof(surface_desc));
11535 surface_desc.dwSize = sizeof(surface_desc);
11536 surface_desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS;
11537 surface_desc.dwWidth = width;
11538 surface_desc.dwHeight = 4;
11539 surface_desc.ddpfPixelFormat = formats[i].format;
11540 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY;
11541 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
11542 if (FAILED(hr))
11544 skip("%s textures not supported, skipping.\n", formats[i].name);
11545 continue;
11547 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx, format %s.\n", hr, formats[i].name);
11549 hr = IDirectDrawSurface4_QueryInterface(surface, &IID_IDirect3DTexture2, (void **)&texture);
11550 ok(SUCCEEDED(hr), "Failed to get Direct3DTexture2 interface, hr %#lx, format %s.\n",
11551 hr, formats[i].name);
11552 hr = IDirect3DDevice3_SetTexture(device, 0, texture);
11553 ok(SUCCEEDED(hr), "Failed to set texture, hr %#lx, format %s.\n", hr, formats[i].name);
11554 IDirect3DTexture2_Release(texture);
11556 memset(&surface_desc, 0, sizeof(surface_desc));
11557 surface_desc.dwSize = sizeof(surface_desc);
11558 hr = IDirectDrawSurface4_Lock(surface, NULL, &surface_desc, 0, NULL);
11559 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#lx, format %s.\n", hr, formats[i].name);
11560 for (y = 0; y < 4; y++)
11562 memcpy((char *)surface_desc.lpSurface + y * surface_desc.lPitch,
11563 (char *)formats[i].content + y * 4 * formats[i].pixel_size,
11564 width * formats[i].pixel_size);
11566 hr = IDirectDrawSurface4_Unlock(surface, NULL);
11567 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx, format %s.\n", hr, formats[i].name);
11569 hr = IDirect3DDevice3_BeginScene(device);
11570 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#lx.\n", hr);
11571 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
11572 D3DFVF_XYZ | D3DFVF_TEX1, quad, 4, 0);
11573 ok(SUCCEEDED(hr), "Failed to draw, hr %#lx.\n", hr);
11574 hr = IDirect3DDevice3_EndScene(device);
11575 ok(SUCCEEDED(hr), "Failed to end scene, hr %#lx.\n", hr);
11577 for (y = 0; y < 4; y++)
11579 for (x = 0; x < width; x++)
11581 expected_color = expected_colors[y][x];
11582 if (!formats[i].blue)
11583 expected_color |= 0x000000ff;
11585 color = get_surface_color(rt, 80 + 160 * x, 60 + 120 * y);
11586 ok(compare_color(color, expected_color, formats[i].slop)
11587 || broken(compare_color(color, expected_color, formats[i].slop_broken)),
11588 "Expected color 0x%08x, got 0x%08x, format %s, location %ux%u.\n",
11589 expected_color, color, formats[i].name, x, y);
11593 IDirectDrawSurface4_Release(surface);
11597 destroy_viewport(device, viewport);
11598 IDirectDrawSurface4_Release(rt);
11599 IDirectDraw4_Release(ddraw);
11600 IDirect3D3_Release(d3d);
11602 done:
11603 refcount = IDirect3DDevice3_Release(device);
11604 ok(!refcount, "Device has %lu references left.\n", refcount);
11605 DestroyWindow(window);
11608 static void test_color_fill(void)
11610 HRESULT hr;
11611 IDirect3DDevice3 *device;
11612 IDirect3D3 *d3d;
11613 IDirectDraw4 *ddraw;
11614 IDirectDrawSurface4 *surface, *surface2;
11615 DDSURFACEDESC2 surface_desc;
11616 unsigned int i, *color;
11617 DDPIXELFORMAT z_fmt;
11618 ULONG refcount;
11619 HWND window;
11620 DDBLTFX fx;
11621 RECT rect = {5, 5, 7, 7};
11622 DWORD supported_fmts = 0, num_fourcc_codes, *fourcc_codes;
11623 DDCAPS hal_caps;
11624 static const struct
11626 DWORD caps, caps2;
11627 HRESULT colorfill_hr, depthfill_hr;
11628 BOOL rop_success;
11629 const char *name;
11630 unsigned int result;
11631 BOOL check_result;
11632 DDPIXELFORMAT format;
11634 tests[] =
11637 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0,
11638 DD_OK, DDERR_INVALIDPARAMS, TRUE, "vidmem offscreenplain RGB", 0xdeadbeef, TRUE,
11640 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
11641 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
11645 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY, 0,
11646 DD_OK, DDERR_INVALIDPARAMS, TRUE, "sysmem offscreenplain RGB", 0xdeadbeef, TRUE,
11648 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
11649 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
11653 DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, 0,
11654 DD_OK, DDERR_INVALIDPARAMS, TRUE, "vidmem texture RGB", 0xdeadbeef, TRUE,
11656 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
11657 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
11661 DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, 0,
11662 DD_OK, DDERR_INVALIDPARAMS, TRUE, "sysmem texture RGB", 0xdeadbeef, TRUE,
11664 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
11665 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
11669 DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE,
11670 DD_OK, DDERR_INVALIDPARAMS, TRUE, "managed texture RGB", 0xdeadbeef, TRUE,
11672 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
11673 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
11677 DDSCAPS_ZBUFFER | DDSCAPS_VIDEOMEMORY, 0,
11678 DDERR_INVALIDPARAMS, DD_OK, TRUE, "vidmem zbuffer", 0xdeadbeef, TRUE,
11679 {0, 0, 0, {0}, {0}, {0}, {0}, {0}}
11682 DDSCAPS_ZBUFFER | DDSCAPS_SYSTEMMEMORY, 0,
11683 DDERR_INVALIDPARAMS, DD_OK, TRUE, "sysmem zbuffer", 0xdeadbeef, TRUE,
11684 {0, 0, 0, {0}, {0}, {0}, {0}, {0}}
11687 /* Colorfill on YUV surfaces always returns DD_OK, but the content is
11688 * different afterwards. DX9+ GPUs set one of the two luminance values
11689 * in each block, but AMD and Nvidia GPUs disagree on which luminance
11690 * value they set. r200 (dx8) just sets the entire block to the clear
11691 * value. */
11692 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0,
11693 DD_OK, DDERR_INVALIDPARAMS, FALSE, "vidmem offscreenplain YUY2", 0, FALSE,
11695 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y', 'U', 'Y', '2'),
11696 {0}, {0}, {0}, {0}, {0}
11700 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0,
11701 DD_OK, DDERR_INVALIDPARAMS, FALSE, "vidmem offscreenplain UYVY", 0, FALSE,
11703 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('U', 'Y', 'V', 'Y'),
11704 {0}, {0}, {0}, {0}, {0}
11708 DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY, 0,
11709 DD_OK, DDERR_INVALIDPARAMS, FALSE, "vidmem overlay YUY2", 0, FALSE,
11711 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y', 'U', 'Y', '2'),
11712 {0}, {0}, {0}, {0}, {0}
11716 DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY, 0,
11717 DD_OK, DDERR_INVALIDPARAMS, FALSE, "vidmem overlay UYVY", 0, FALSE,
11719 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('U', 'Y', 'V', 'Y'),
11720 {0}, {0}, {0}, {0}, {0}
11724 DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, 0,
11725 E_NOTIMPL, DDERR_INVALIDPARAMS, FALSE, "vidmem texture DXT1", 0, FALSE,
11727 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('D', 'X', 'T', '1'),
11728 {0}, {0}, {0}, {0}, {0}
11732 DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, 0,
11733 E_NOTIMPL, DDERR_INVALIDPARAMS, FALSE, "sysmem texture DXT1", 0, FALSE,
11735 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('D', 'X', 'T', '1'),
11736 {0}, {0}, {0}, {0}, {0}
11740 /* The testbot fills this with 0x00 instead of the blue channel. The sysmem
11741 * surface works, presumably because it is handled by the runtime instead of
11742 * the driver. */
11743 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0,
11744 DD_OK, DDERR_INVALIDPARAMS, TRUE, "vidmem offscreenplain P8", 0xefefefef, FALSE,
11746 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_PALETTEINDEXED8, 0,
11747 {8}, {0}, {0}, {0}, {0}
11751 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY, 0,
11752 DD_OK, DDERR_INVALIDPARAMS, TRUE, "sysmem offscreenplain P8", 0xefefefef, TRUE,
11754 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_PALETTEINDEXED8, 0,
11755 {8}, {0}, {0}, {0}, {0}
11759 static const struct
11761 DWORD rop;
11762 const char *name;
11763 HRESULT hr;
11765 rops[] =
11767 {SRCCOPY, "SRCCOPY", DD_OK},
11768 {SRCPAINT, "SRCPAINT", DDERR_NORASTEROPHW},
11769 {SRCAND, "SRCAND", DDERR_NORASTEROPHW},
11770 {SRCINVERT, "SRCINVERT", DDERR_NORASTEROPHW},
11771 {SRCERASE, "SRCERASE", DDERR_NORASTEROPHW},
11772 {NOTSRCCOPY, "NOTSRCCOPY", DDERR_NORASTEROPHW},
11773 {NOTSRCERASE, "NOTSRCERASE", DDERR_NORASTEROPHW},
11774 {MERGECOPY, "MERGECOPY", DDERR_NORASTEROPHW},
11775 {MERGEPAINT, "MERGEPAINT", DDERR_NORASTEROPHW},
11776 {PATCOPY, "PATCOPY", DDERR_NORASTEROPHW},
11777 {PATPAINT, "PATPAINT", DDERR_NORASTEROPHW},
11778 {PATINVERT, "PATINVERT", DDERR_NORASTEROPHW},
11779 {DSTINVERT, "DSTINVERT", DDERR_NORASTEROPHW},
11780 {BLACKNESS, "BLACKNESS", DD_OK},
11781 {WHITENESS, "WHITENESS", DD_OK},
11782 {0xaa0029, "0xaa0029", DDERR_NORASTEROPHW} /* noop */
11785 window = create_window();
11786 if (!(device = create_device(window, DDSCL_NORMAL)))
11788 skip("Failed to create a 3D device, skipping test.\n");
11789 DestroyWindow(window);
11790 return;
11793 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
11794 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#lx.\n", hr);
11795 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
11796 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#lx.\n", hr);
11798 memset(&z_fmt, 0, sizeof(z_fmt));
11799 IDirect3D3_EnumZBufferFormats(d3d, &IID_IDirect3DHALDevice, enum_z_fmt, &z_fmt);
11800 if (!z_fmt.dwSize)
11801 skip("No Z buffer formats supported, skipping Z buffer colorfill test.\n");
11803 IDirect3DDevice3_EnumTextureFormats(device, test_block_formats_creation_cb, &supported_fmts);
11804 if (!(supported_fmts & SUPPORT_DXT1))
11805 skip("DXT1 textures not supported, skipping DXT1 colorfill test.\n");
11807 IDirect3D3_Release(d3d);
11809 hr = IDirectDraw4_GetFourCCCodes(ddraw, &num_fourcc_codes, NULL);
11810 ok(SUCCEEDED(hr), "Got hr %#lx.\n", hr);
11811 fourcc_codes = calloc(num_fourcc_codes, sizeof(*fourcc_codes));
11812 if (!fourcc_codes)
11813 goto done;
11814 hr = IDirectDraw4_GetFourCCCodes(ddraw, &num_fourcc_codes, fourcc_codes);
11815 ok(SUCCEEDED(hr), "Got hr %#lx.\n", hr);
11816 for (i = 0; i < num_fourcc_codes; i++)
11818 if (fourcc_codes[i] == MAKEFOURCC('Y', 'U', 'Y', '2'))
11819 supported_fmts |= SUPPORT_YUY2;
11820 else if (fourcc_codes[i] == MAKEFOURCC('U', 'Y', 'V', 'Y'))
11821 supported_fmts |= SUPPORT_UYVY;
11823 free(fourcc_codes);
11825 memset(&hal_caps, 0, sizeof(hal_caps));
11826 hal_caps.dwSize = sizeof(hal_caps);
11827 hr = IDirectDraw4_GetCaps(ddraw, &hal_caps, NULL);
11828 ok(SUCCEEDED(hr), "Failed to get caps, hr %#lx.\n", hr);
11830 if (!(supported_fmts & (SUPPORT_YUY2 | SUPPORT_UYVY)) || !(hal_caps.dwCaps & DDCAPS_OVERLAY))
11831 skip("Overlays or some YUV formats not supported, skipping YUV colorfill tests.\n");
11833 for (i = 0; i < ARRAY_SIZE(tests); i++)
11835 DWORD expected_broken = tests[i].result;
11837 /* Some Windows drivers modify dwFillColor when it is used on P8 or FourCC formats. */
11838 memset(&fx, 0, sizeof(fx));
11839 fx.dwSize = sizeof(fx);
11840 fx.dwFillColor = 0xdeadbeef;
11842 memset(&surface_desc, 0, sizeof(surface_desc));
11843 surface_desc.dwSize = sizeof(surface_desc);
11844 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
11845 surface_desc.dwWidth = 64;
11846 surface_desc.dwHeight = 64;
11847 surface_desc.ddpfPixelFormat = tests[i].format;
11848 surface_desc.ddsCaps.dwCaps = tests[i].caps;
11849 surface_desc.ddsCaps.dwCaps2 = tests[i].caps2;
11851 if (tests[i].format.dwFourCC == MAKEFOURCC('D','X','T','1') && !(supported_fmts & SUPPORT_DXT1))
11852 continue;
11853 if (tests[i].format.dwFourCC == MAKEFOURCC('Y','U','Y','2') && !(supported_fmts & SUPPORT_YUY2))
11854 continue;
11855 if (tests[i].format.dwFourCC == MAKEFOURCC('U','Y','V','Y') && !(supported_fmts & SUPPORT_UYVY))
11856 continue;
11857 if (tests[i].caps & DDSCAPS_OVERLAY && !(hal_caps.dwCaps & DDCAPS_OVERLAY))
11858 continue;
11860 if (tests[i].caps & DDSCAPS_ZBUFFER)
11862 if (!z_fmt.dwSize)
11863 continue;
11865 surface_desc.ddpfPixelFormat = z_fmt;
11866 /* Some drivers seem to convert depth values incorrectly or not at
11867 * all. Affects at least AMD PALM, 8.17.10.1247. */
11868 if (tests[i].caps & DDSCAPS_VIDEOMEMORY)
11870 DWORD expected;
11871 float f, g;
11873 expected = tests[i].result & z_fmt.dwZBitMask;
11874 f = ceilf(logf(expected + 1.0f) / logf(2.0f));
11875 g = (f + 1.0f) / 2.0f;
11876 g -= (int)g;
11877 expected_broken = (expected / exp2f(f) - g) * 256;
11878 expected_broken *= 0x01010101;
11882 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
11883 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx, surface %s.\n", hr, tests[i].name);
11885 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
11886 todo_wine_if (tests[i].format.dwFourCC)
11887 ok(hr == tests[i].colorfill_hr, "Blt returned %#lx, expected %#lx, surface %s.\n",
11888 hr, tests[i].colorfill_hr, tests[i].name);
11890 hr = IDirectDrawSurface4_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
11891 todo_wine_if (tests[i].format.dwFourCC)
11892 ok(hr == tests[i].colorfill_hr, "Blt returned %#lx, expected %#lx, surface %s.\n",
11893 hr, tests[i].colorfill_hr, tests[i].name);
11895 if (SUCCEEDED(hr) && tests[i].check_result)
11897 memset(&surface_desc, 0, sizeof(surface_desc));
11898 surface_desc.dwSize = sizeof(surface_desc);
11899 hr = IDirectDrawSurface4_Lock(surface, NULL, &surface_desc, DDLOCK_READONLY, 0);
11900 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#lx, surface %s.\n", hr, tests[i].name);
11901 color = surface_desc.lpSurface;
11902 ok(*color == tests[i].result, "Got clear result 0x%08x, expected 0x%08x, surface %s.\n",
11903 *color, tests[i].result, tests[i].name);
11904 hr = IDirectDrawSurface4_Unlock(surface, NULL);
11905 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx, surface %s.\n", hr, tests[i].name);
11908 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
11909 ok(hr == tests[i].depthfill_hr, "Blt returned %#lx, expected %#lx, surface %s.\n",
11910 hr, tests[i].depthfill_hr, tests[i].name);
11911 hr = IDirectDrawSurface4_Blt(surface, &rect, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
11912 ok(hr == tests[i].depthfill_hr, "Blt returned %#lx, expected %#lx, surface %s.\n",
11913 hr, tests[i].depthfill_hr, tests[i].name);
11915 if (SUCCEEDED(hr) && tests[i].check_result)
11917 memset(&surface_desc, 0, sizeof(surface_desc));
11918 surface_desc.dwSize = sizeof(surface_desc);
11919 hr = IDirectDrawSurface4_Lock(surface, NULL, &surface_desc, DDLOCK_READONLY, 0);
11920 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#lx, surface %s.\n", hr, tests[i].name);
11921 color = surface_desc.lpSurface;
11922 ok((*color & z_fmt.dwZBitMask) == (tests[i].result & z_fmt.dwZBitMask)
11923 || broken((*color & z_fmt.dwZBitMask) == (expected_broken & z_fmt.dwZBitMask)),
11924 "Got clear result 0x%08lx, expected 0x%08lx, surface %s.\n",
11925 *color & z_fmt.dwZBitMask, tests[i].result & z_fmt.dwZBitMask, tests[i].name);
11926 hr = IDirectDrawSurface4_Unlock(surface, NULL);
11927 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx, surface %s.\n", hr, tests[i].name);
11930 fx.dwFillColor = 0xdeadbeef;
11931 fx.dwROP = BLACKNESS;
11932 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, NULL, DDBLT_ROP | DDBLT_WAIT, &fx);
11933 ok(FAILED(hr) == !tests[i].rop_success, "Blt returned %#lx, expected %s, surface %s.\n",
11934 hr, tests[i].rop_success ? "success" : "failure", tests[i].name);
11935 ok(fx.dwFillColor == 0xdeadbeef, "dwFillColor was set to 0x%08lx, surface %s\n",
11936 fx.dwFillColor, tests[i].name);
11938 if (SUCCEEDED(hr) && tests[i].check_result)
11940 memset(&surface_desc, 0, sizeof(surface_desc));
11941 surface_desc.dwSize = sizeof(surface_desc);
11942 hr = IDirectDrawSurface4_Lock(surface, NULL, &surface_desc, DDLOCK_READONLY, 0);
11943 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#lx, surface %s.\n", hr, tests[i].name);
11944 color = surface_desc.lpSurface;
11945 ok(*color == 0, "Got clear result 0x%08x, expected 0x00000000, surface %s.\n",
11946 *color, tests[i].name);
11947 hr = IDirectDrawSurface4_Unlock(surface, NULL);
11948 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx, surface %s.\n", hr, tests[i].name);
11951 fx.dwROP = WHITENESS;
11952 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, NULL, DDBLT_ROP | DDBLT_WAIT, &fx);
11953 ok(FAILED(hr) == !tests[i].rop_success, "Blt returned %#lx, expected %s, surface %s.\n",
11954 hr, tests[i].rop_success ? "success" : "failure", tests[i].name);
11955 ok(fx.dwFillColor == 0xdeadbeef, "dwFillColor was set to 0x%08lx, surface %s\n",
11956 fx.dwFillColor, tests[i].name);
11958 if (SUCCEEDED(hr) && tests[i].check_result)
11960 memset(&surface_desc, 0, sizeof(surface_desc));
11961 surface_desc.dwSize = sizeof(surface_desc);
11962 hr = IDirectDrawSurface4_Lock(surface, NULL, &surface_desc, DDLOCK_READONLY, 0);
11963 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#lx, surface %s.\n", hr, tests[i].name);
11964 color = surface_desc.lpSurface;
11965 /* WHITENESS sets the alpha channel to 0x00. Ignore this for now. */
11966 ok((*color & 0x00ffffff) == 0x00ffffff, "Got clear result 0x%08x, expected 0xffffffff, surface %s.\n",
11967 *color, tests[i].name);
11968 hr = IDirectDrawSurface4_Unlock(surface, NULL);
11969 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx, surface %s.\n", hr, tests[i].name);
11972 IDirectDrawSurface4_Release(surface);
11975 memset(&fx, 0, sizeof(fx));
11976 fx.dwSize = sizeof(fx);
11977 fx.dwFillColor = 0xdeadbeef;
11978 fx.dwROP = WHITENESS;
11980 memset(&surface_desc, 0, sizeof(surface_desc));
11981 surface_desc.dwSize = sizeof(surface_desc);
11982 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
11983 surface_desc.dwWidth = 64;
11984 surface_desc.dwHeight = 64;
11985 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
11986 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB;
11987 surface_desc.ddpfPixelFormat.dwRGBBitCount = 32;
11988 surface_desc.ddpfPixelFormat.dwRBitMask = 0x00ff0000;
11989 surface_desc.ddpfPixelFormat.dwGBitMask = 0x0000ff00;
11990 surface_desc.ddpfPixelFormat.dwBBitMask = 0x000000ff;
11991 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
11992 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
11993 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
11994 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface2, NULL);
11995 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
11997 /* No DDBLTFX. */
11998 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, &rect, DDBLT_COLORFILL | DDBLT_WAIT, NULL);
11999 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
12000 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, &rect, DDBLT_ROP | DDBLT_WAIT, NULL);
12001 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
12003 /* Unused source rectangle. */
12004 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
12005 ok(SUCCEEDED(hr), "Got unexpected hr %#lx.\n", hr);
12006 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, &rect, DDBLT_ROP | DDBLT_WAIT, &fx);
12007 ok(SUCCEEDED(hr), "Got unexpected hr %#lx.\n", hr);
12009 /* Unused source surface. */
12010 hr = IDirectDrawSurface4_Blt(surface, NULL, surface2, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
12011 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
12012 hr = IDirectDrawSurface4_Blt(surface, NULL, surface2, NULL, DDBLT_ROP | DDBLT_WAIT, &fx);
12013 ok(SUCCEEDED(hr), "Got unexpected hr %#lx.\n", hr);
12014 hr = IDirectDrawSurface4_Blt(surface, NULL, surface2, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
12015 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
12016 hr = IDirectDrawSurface4_Blt(surface, NULL, surface2, &rect, DDBLT_ROP | DDBLT_WAIT, &fx);
12017 ok(SUCCEEDED(hr), "Got unexpected hr %#lx.\n", hr);
12019 /* Inverted destination or source rectangle. */
12020 SetRect(&rect, 5, 7, 7, 5);
12021 hr = IDirectDrawSurface4_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
12022 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#lx.\n", hr);
12023 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
12024 ok(SUCCEEDED(hr), "Got unexpected hr %#lx.\n", hr);
12025 hr = IDirectDrawSurface4_Blt(surface, &rect, surface2, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
12026 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
12027 hr = IDirectDrawSurface4_Blt(surface, NULL, surface2, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
12028 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
12029 hr = IDirectDrawSurface4_Blt(surface, NULL, surface2, &rect, DDBLT_ROP | DDBLT_WAIT, &fx);
12030 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#lx.\n", hr);
12032 /* Negative rectangle. */
12033 SetRect(&rect, -1, -1, 5, 5);
12034 hr = IDirectDrawSurface4_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
12035 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#lx.\n", hr);
12036 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
12037 ok(SUCCEEDED(hr), "Got unexpected hr %#lx.\n", hr);
12038 hr = IDirectDrawSurface4_Blt(surface, &rect, surface2, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
12039 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
12040 hr = IDirectDrawSurface4_Blt(surface, &rect, surface2, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
12041 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
12042 hr = IDirectDrawSurface4_Blt(surface, NULL, surface2, &rect, DDBLT_ROP | DDBLT_WAIT, &fx);
12043 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#lx.\n", hr);
12045 /* Out of bounds rectangle. */
12046 SetRect(&rect, 0, 0, 65, 65);
12047 hr = IDirectDrawSurface4_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
12048 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#lx.\n", hr);
12049 hr = IDirectDrawSurface4_Blt(surface, NULL, surface2, &rect, DDBLT_ROP | DDBLT_WAIT, &fx);
12050 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#lx.\n", hr);
12052 /* Combine multiple flags. */
12053 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
12054 ok(SUCCEEDED(hr), "Got unexpected hr %#lx.\n", hr);
12055 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_ROP | DDBLT_WAIT, &fx);
12056 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
12057 hr = IDirectDrawSurface4_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_ROP | DDBLT_WAIT, &fx);
12058 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
12060 for (i = 0; i < ARRAY_SIZE(rops); i++)
12062 fx.dwROP = rops[i].rop;
12063 hr = IDirectDrawSurface4_Blt(surface, NULL, surface2, NULL, DDBLT_ROP | DDBLT_WAIT, &fx);
12064 ok(hr == rops[i].hr, "Got unexpected hr %#lx for rop %s.\n", hr, rops[i].name);
12067 IDirectDrawSurface4_Release(surface2);
12068 IDirectDrawSurface4_Release(surface);
12070 if (!z_fmt.dwSize)
12071 goto done;
12073 memset(&surface_desc, 0, sizeof(surface_desc));
12074 surface_desc.dwSize = sizeof(surface_desc);
12075 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
12076 surface_desc.dwWidth = 64;
12077 surface_desc.dwHeight = 64;
12078 surface_desc.ddpfPixelFormat = z_fmt;
12079 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
12080 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
12081 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
12082 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface2, NULL);
12083 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
12085 /* No DDBLTFX. */
12086 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, NULL);
12087 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
12089 /* Unused source rectangle. */
12090 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
12091 ok(SUCCEEDED(hr), "Got unexpected hr %#lx.\n", hr);
12093 /* Unused source surface. */
12094 hr = IDirectDrawSurface4_Blt(surface, NULL, surface2, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
12095 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
12096 hr = IDirectDrawSurface4_Blt(surface, NULL, surface2, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
12097 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
12099 /* Inverted destination or source rectangle. */
12100 SetRect(&rect, 5, 7, 7, 5);
12101 hr = IDirectDrawSurface4_Blt(surface, &rect, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
12102 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#lx.\n", hr);
12103 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
12104 ok(SUCCEEDED(hr), "Got unexpected hr %#lx.\n", hr);
12105 hr = IDirectDrawSurface4_Blt(surface, &rect, surface2, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
12106 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
12107 hr = IDirectDrawSurface4_Blt(surface, NULL, surface2, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
12108 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
12110 /* Negative rectangle. */
12111 SetRect(&rect, -1, -1, 5, 5);
12112 hr = IDirectDrawSurface4_Blt(surface, &rect, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
12113 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#lx.\n", hr);
12114 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
12115 ok(SUCCEEDED(hr), "Got unexpected hr %#lx.\n", hr);
12116 hr = IDirectDrawSurface4_Blt(surface, &rect, surface2, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
12117 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
12118 hr = IDirectDrawSurface4_Blt(surface, &rect, surface2, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
12119 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
12121 /* Out of bounds rectangle. */
12122 SetRect(&rect, 0, 0, 65, 65);
12123 hr = IDirectDrawSurface4_Blt(surface, &rect, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
12124 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#lx.\n", hr);
12126 /* Combine multiple flags. */
12127 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
12128 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
12130 IDirectDrawSurface4_Release(surface2);
12131 IDirectDrawSurface4_Release(surface);
12133 done:
12134 IDirectDraw4_Release(ddraw);
12135 refcount = IDirect3DDevice3_Release(device);
12136 ok(!refcount, "Device has %lu references left.\n", refcount);
12137 DestroyWindow(window);
12140 static void test_texcoordindex(void)
12142 static struct
12144 struct vec3 pos;
12145 struct vec2 texcoord1;
12146 struct vec2 texcoord2;
12147 struct vec2 texcoord3;
12149 quad[] =
12151 {{-1.0f, -1.0f, 0.0f}, {0.0f, 1.0f}, {0.0f, 0.0f}, {1.0f, 1.0f}},
12152 {{-1.0f, 1.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 1.0f}, {1.0f, 0.0f}},
12153 {{ 1.0f, -1.0f, 0.0f}, {1.0f, 1.0f}, {1.0f, 0.0f}, {0.0f, 1.0f}},
12154 {{ 1.0f, 1.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 0.0f}},
12156 static const DWORD fvf = D3DFVF_XYZ | D3DFVF_TEX3;
12157 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
12158 IDirect3DDevice3 *device;
12159 unsigned int color;
12160 IDirect3D3 *d3d;
12161 IDirectDraw4 *ddraw;
12162 IDirectDrawSurface4 *rt;
12163 IDirect3DViewport3 *viewport;
12164 HWND window;
12165 HRESULT hr;
12166 IDirectDrawSurface4 *surface1, *surface2;
12167 IDirect3DTexture2 *texture1, *texture2;
12168 DDSURFACEDESC2 surface_desc;
12169 ULONG refcount;
12170 DWORD *ptr;
12172 window = create_window();
12173 if (!(device = create_device(window, DDSCL_NORMAL)))
12175 skip("Failed to create a 3D device, skipping test.\n");
12176 DestroyWindow(window);
12177 return;
12180 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
12181 ok(SUCCEEDED(hr), "Failed to get Direct3D3 interface, hr %#lx.\n", hr);
12182 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
12183 ok(SUCCEEDED(hr), "Failed to get DirectDraw4 interface, hr %#lx.\n", hr);
12184 IDirect3D3_Release(d3d);
12186 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
12187 ok(SUCCEEDED(hr), "Failed to get render target, hr %#lx.\n", hr);
12189 memset(&surface_desc, 0, sizeof(surface_desc));
12190 surface_desc.dwSize = sizeof(surface_desc);
12191 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
12192 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
12193 surface_desc.dwWidth = 2;
12194 surface_desc.dwHeight = 2;
12195 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
12196 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
12197 surface_desc.ddpfPixelFormat.dwRGBBitCount = 32;
12198 surface_desc.ddpfPixelFormat.dwRBitMask = 0x00ff0000;
12199 surface_desc.ddpfPixelFormat.dwGBitMask = 0x0000ff00;
12200 surface_desc.ddpfPixelFormat.dwBBitMask = 0x000000ff;
12201 surface_desc.ddpfPixelFormat.dwRGBAlphaBitMask = 0xff000000;
12202 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface1, NULL);
12203 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
12204 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface2, NULL);
12205 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
12207 memset(&surface_desc, 0, sizeof(surface_desc));
12208 surface_desc.dwSize = sizeof(surface_desc);
12209 hr = IDirectDrawSurface4_Lock(surface1, 0, &surface_desc, 0, NULL);
12210 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#lx.\n", hr);
12211 ptr = surface_desc.lpSurface;
12212 ptr[0] = 0xff000000;
12213 ptr[1] = 0xff00ff00;
12214 ptr += surface_desc.lPitch / sizeof(*ptr);
12215 ptr[0] = 0xff0000ff;
12216 ptr[1] = 0xff00ffff;
12217 hr = IDirectDrawSurface4_Unlock(surface1, NULL);
12218 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx.\n", hr);
12220 memset(&surface_desc, 0, sizeof(surface_desc));
12221 surface_desc.dwSize = sizeof(surface_desc);
12222 hr = IDirectDrawSurface4_Lock(surface2, 0, &surface_desc, 0, NULL);
12223 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#lx.\n", hr);
12224 ptr = surface_desc.lpSurface;
12225 ptr[0] = 0xff000000;
12226 ptr[1] = 0xff0000ff;
12227 ptr += surface_desc.lPitch / sizeof(*ptr);
12228 ptr[0] = 0xffff0000;
12229 ptr[1] = 0xffff00ff;
12230 hr = IDirectDrawSurface4_Unlock(surface2, 0);
12231 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx.\n", hr);
12233 viewport = create_viewport(device, 0, 0, 640, 480);
12234 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
12235 ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#lx.\n", hr);
12237 hr = IDirectDrawSurface4_QueryInterface(surface1, &IID_IDirect3DTexture2, (void **)&texture1);
12238 ok(SUCCEEDED(hr), "Failed to get texture interface, hr %#lx.\n", hr);
12239 hr = IDirectDrawSurface4_QueryInterface(surface2, &IID_IDirect3DTexture2, (void **)&texture2);
12240 ok(SUCCEEDED(hr), "Failed to get texture interface, hr %#lx.\n", hr);
12241 hr = IDirect3DDevice3_SetTexture(device, 0, texture1);
12242 ok(SUCCEEDED(hr), "Failed to set texture, hr %#lx.\n", hr);
12243 hr = IDirect3DDevice3_SetTexture(device, 1, texture2);
12244 ok(SUCCEEDED(hr), "Failed to set texture, hr %#lx.\n", hr);
12245 hr = IDirect3DDevice3_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
12246 ok(SUCCEEDED(hr), "Failed to set color op, hr %#lx.\n", hr);
12247 hr = IDirect3DDevice3_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
12248 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#lx.\n", hr);
12249 hr = IDirect3DDevice3_SetTextureStageState(device, 1, D3DTSS_COLOROP, D3DTOP_ADD);
12250 ok(SUCCEEDED(hr), "Failed to set color op, hr %#lx.\n", hr);
12251 hr = IDirect3DDevice3_SetTextureStageState(device, 1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
12252 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#lx.\n", hr);
12253 hr = IDirect3DDevice3_SetTextureStageState(device, 1, D3DTSS_COLORARG2, D3DTA_CURRENT);
12254 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#lx.\n", hr);
12255 hr = IDirect3DDevice3_SetTextureStageState(device, 2, D3DTSS_COLOROP, D3DTOP_DISABLE);
12256 ok(SUCCEEDED(hr), "Failed to set color op, hr %#lx.\n", hr);
12258 hr = IDirect3DDevice3_SetTextureStageState(device, 0, D3DTSS_TEXCOORDINDEX, 1);
12259 ok(SUCCEEDED(hr), "Failed to set texcoord index, hr %#lx.\n", hr);
12260 hr = IDirect3DDevice3_SetTextureStageState(device, 1, D3DTSS_TEXCOORDINDEX, 0);
12261 ok(SUCCEEDED(hr), "Failed to set texcoord index, hr %#lx.\n", hr);
12263 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ZENABLE, FALSE);
12264 ok(SUCCEEDED(hr), "Failed to disable z-buffering, hr %#lx.\n", hr);
12266 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xffffff00, 1.0f, 0);
12267 ok(SUCCEEDED(hr), "Failed to clear, hr %#lx.\n", hr);
12269 hr = IDirect3DDevice3_BeginScene(device);
12270 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#lx.\n", hr);
12271 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, fvf, quad, 4, 0);
12272 ok(SUCCEEDED(hr), "Failed to draw, hr %#lx.\n", hr);
12273 hr = IDirect3DDevice3_EndScene(device);
12274 ok(SUCCEEDED(hr), "Failed to end scene, hr %#lx.\n", hr);
12276 color = get_surface_color(rt, 160, 120);
12277 ok(compare_color(color, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color);
12278 color = get_surface_color(rt, 480, 120);
12279 ok(compare_color(color, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color);
12280 color = get_surface_color(rt, 160, 360);
12281 ok(compare_color(color, 0x00ff0000, 2), "Got unexpected color 0x%08x.\n", color);
12282 color = get_surface_color(rt, 480, 360);
12283 ok(compare_color(color, 0x00ffffff, 2), "Got unexpected color 0x%08x.\n", color);
12285 /* D3DTSS_TEXTURETRANSFORMFLAGS was introduced in D3D7, can't test it here. */
12287 hr = IDirect3DDevice3_SetTextureStageState(device, 1, D3DTSS_TEXCOORDINDEX, 2);
12288 ok(SUCCEEDED(hr), "Failed to set texcoord index, hr %#lx.\n", hr);
12290 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xffffff00, 1.0f, 0);
12291 ok(SUCCEEDED(hr), "Failed to clear, hr %#lx.\n", hr);
12293 hr = IDirect3DDevice3_BeginScene(device);
12294 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#lx.\n", hr);
12295 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, fvf, quad, 4, 0);
12296 ok(SUCCEEDED(hr), "Failed to draw, hr %#lx.\n", hr);
12297 hr = IDirect3DDevice3_EndScene(device);
12298 ok(SUCCEEDED(hr), "Failed to end scene, hr %#lx.\n", hr);
12300 color = get_surface_color(rt, 160, 120);
12301 ok(compare_color(color, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color);
12302 color = get_surface_color(rt, 480, 120);
12303 ok(compare_color(color, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color);
12304 color = get_surface_color(rt, 160, 360);
12305 ok(compare_color(color, 0x00ff00ff, 2), "Got unexpected color 0x%08x.\n", color);
12306 color = get_surface_color(rt, 480, 360);
12307 ok(compare_color(color, 0x00ffff00, 2), "Got unexpected color 0x%08x.\n", color);
12309 IDirect3DTexture2_Release(texture2);
12310 IDirect3DTexture2_Release(texture1);
12311 IDirectDrawSurface4_Release(surface2);
12312 IDirectDrawSurface4_Release(surface1);
12314 destroy_viewport(device, viewport);
12316 IDirectDrawSurface4_Release(rt);
12317 IDirectDraw4_Release(ddraw);
12318 refcount = IDirect3DDevice3_Release(device);
12319 ok(!refcount, "Device has %lu references left.\n", refcount);
12320 DestroyWindow(window);
12323 static void test_colorkey_precision(void)
12325 static struct
12327 struct vec3 pos;
12328 struct vec2 texcoord;
12330 quad[] =
12332 {{-1.0f, -1.0f, 0.0f}, {0.0f, 1.0f}},
12333 {{-1.0f, 1.0f, 0.0f}, {0.0f, 0.0f}},
12334 {{ 1.0f, -1.0f, 0.0f}, {1.0f, 1.0f}},
12335 {{ 1.0f, 1.0f, 0.0f}, {1.0f, 0.0f}},
12337 unsigned int data[4] = {0}, color_mask, color, t, c;
12338 IDirect3DDevice3 *device;
12339 IDirect3D3 *d3d;
12340 IDirectDraw4 *ddraw;
12341 IDirectDrawSurface4 *rt;
12342 IDirect3DViewport3 *viewport;
12343 HWND window;
12344 HRESULT hr;
12345 IDirectDrawSurface4 *src, *dst, *texture;
12346 IDirect3DTexture2 *d3d_texture;
12347 DDSURFACEDESC2 surface_desc, lock_desc;
12348 ULONG refcount;
12349 DDCOLORKEY ckey;
12350 DDBLTFX fx;
12351 D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
12352 BOOL is_nvidia, is_warp;
12353 static const struct
12355 unsigned int max, shift, bpp, clear;
12356 const char *name;
12357 BOOL skip_nv;
12358 DDPIXELFORMAT fmt;
12360 tests[] =
12363 255, 0, 4, 0x00345678, "D3DFMT_X8R8G8B8", FALSE,
12365 sizeof(DDPIXELFORMAT), DDPF_RGB, 0,
12366 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0x00000000}
12371 63, 5, 2, 0x5678, "D3DFMT_R5G6B5, G channel", FALSE,
12373 sizeof(DDPIXELFORMAT), DDPF_RGB, 0,
12374 {16}, {0xf800}, {0x07e0}, {0x001f}, {0x0000}
12379 31, 0, 2, 0x5678, "D3DFMT_R5G6B5, B channel", FALSE,
12381 sizeof(DDPIXELFORMAT), DDPF_RGB, 0,
12382 {16}, {0xf800}, {0x07e0}, {0x001f}, {0x0000}
12387 15, 0, 2, 0x0678, "D3DFMT_A4R4G4B4", TRUE,
12389 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
12390 {16}, {0x0f00}, {0x00f0}, {0x000f}, {0xf000}
12395 window = create_window();
12396 if (!(device = create_device(window, DDSCL_NORMAL)))
12398 skip("Failed to create a 3D device, skipping test.\n");
12399 DestroyWindow(window);
12400 return;
12403 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
12404 ok(SUCCEEDED(hr), "Failed to get Direct3D3 interface, hr %#lx.\n", hr);
12405 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
12406 ok(SUCCEEDED(hr), "Failed to get DirectDraw4 interface, hr %#lx.\n", hr);
12407 IDirect3D3_Release(d3d);
12408 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
12409 ok(SUCCEEDED(hr), "Failed to get render target, hr %#lx.\n", hr);
12411 is_nvidia = ddraw_is_nvidia(ddraw);
12412 /* The Windows 8 WARP driver has plenty of false negatives in X8R8G8B8
12413 * (color key doesn't match although the values are equal), and a false
12414 * positive when the color key is 0 and the texture contains the value 1.
12415 * I don't want to mark this broken unconditionally since this would
12416 * essentially disable the test on Windows. Also on random occasions
12417 * 254 == 255 and 255 != 255.*/
12418 is_warp = ddraw_is_warp(ddraw);
12420 viewport = create_viewport(device, 0, 0, 640, 480);
12421 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
12422 ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#lx.\n", hr);
12424 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
12425 ok(SUCCEEDED(hr), "Failed to disable z-buffering, hr %#lx.\n", hr);
12426 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, TRUE);
12427 ok(SUCCEEDED(hr), "Failed to enable color keying, hr %#lx.\n", hr);
12428 /* Multiply the texture read result with 0, that way the result color if the key doesn't
12429 * match is constant. In theory color keying works without reading the texture result
12430 * (meaning we could just op=arg1, arg1=tfactor), but the Geforce7 Windows driver begs
12431 * to differ. */
12432 hr = IDirect3DDevice3_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_MODULATE);
12433 ok(SUCCEEDED(hr), "Failed to set color op, hr %#lx.\n", hr);
12434 hr = IDirect3DDevice3_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
12435 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#lx.\n", hr);
12436 hr = IDirect3DDevice3_SetTextureStageState(device, 0, D3DTSS_COLORARG2, D3DTA_TFACTOR);
12437 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#lx.\n", hr);
12438 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_TEXTUREFACTOR, 0x00000000);
12439 ok(SUCCEEDED(hr), "Failed to set render state, hr %#lx.\n", hr);
12441 memset(&fx, 0, sizeof(fx));
12442 fx.dwSize = sizeof(fx);
12443 memset(&lock_desc, 0, sizeof(lock_desc));
12444 lock_desc.dwSize = sizeof(lock_desc);
12446 for (t = 0; t < ARRAY_SIZE(tests); ++t)
12448 if (is_nvidia && tests[t].skip_nv)
12450 win_skip("Skipping test %s on Nvidia Windows drivers.\n", tests[t].name);
12451 continue;
12454 memset(&surface_desc, 0, sizeof(surface_desc));
12455 surface_desc.dwSize = sizeof(surface_desc);
12456 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
12457 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
12458 surface_desc.dwWidth = 4;
12459 surface_desc.dwHeight = 1;
12460 surface_desc.ddpfPixelFormat = tests[t].fmt;
12461 /* Windows XP (at least with the r200 driver, other drivers untested) produces
12462 * garbage when doing color keyed texture->texture blits. */
12463 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &src, NULL);
12464 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
12465 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &dst, NULL);
12466 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
12468 fx.dwFillColor = tests[t].clear;
12469 /* On the w8 testbot (WARP driver) the blit result has different values in the
12470 * X channel. */
12471 color_mask = tests[t].fmt.dwRBitMask
12472 | tests[t].fmt.dwGBitMask
12473 | tests[t].fmt.dwBBitMask;
12475 for (c = 0; c <= tests[t].max; ++c)
12477 /* The idiotic Nvidia Windows driver can't change the color key on a d3d
12478 * texture after it has been set once... */
12479 surface_desc.dwFlags |= DDSD_CKSRCBLT;
12480 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
12481 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = c << tests[t].shift;
12482 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = c << tests[t].shift;
12483 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &texture, NULL);
12484 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
12485 hr = IDirectDrawSurface4_QueryInterface(texture, &IID_IDirect3DTexture2, (void **)&d3d_texture);
12486 ok(SUCCEEDED(hr), "Failed to get texture interface, hr %#lx.\n", hr);
12487 hr = IDirect3DDevice3_SetTexture(device, 0, d3d_texture);
12488 ok(SUCCEEDED(hr), "Failed to set texture, hr %#lx.\n", hr);
12490 hr = IDirectDrawSurface4_Blt(dst, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
12491 ok(SUCCEEDED(hr), "Failed to clear destination surface, hr %#lx.\n", hr);
12493 hr = IDirectDrawSurface4_Lock(src, NULL, &lock_desc, DDLOCK_WAIT, NULL);
12494 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#lx.\n", hr);
12495 switch (tests[t].bpp)
12497 case 4:
12498 ((DWORD *)lock_desc.lpSurface)[0] = (c ? c - 1 : 0) << tests[t].shift;
12499 ((DWORD *)lock_desc.lpSurface)[1] = c << tests[t].shift;
12500 ((DWORD *)lock_desc.lpSurface)[2] = min(c + 1, tests[t].max) << tests[t].shift;
12501 ((DWORD *)lock_desc.lpSurface)[3] = 0xffffffff;
12502 break;
12504 case 2:
12505 ((WORD *)lock_desc.lpSurface)[0] = (c ? c - 1 : 0) << tests[t].shift;
12506 ((WORD *)lock_desc.lpSurface)[1] = c << tests[t].shift;
12507 ((WORD *)lock_desc.lpSurface)[2] = min(c + 1, tests[t].max) << tests[t].shift;
12508 ((WORD *)lock_desc.lpSurface)[3] = 0xffff;
12509 break;
12511 hr = IDirectDrawSurface4_Unlock(src, 0);
12512 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx.\n", hr);
12513 hr = IDirectDrawSurface4_Blt(texture, NULL, src, NULL, DDBLT_WAIT, NULL);
12514 ok(SUCCEEDED(hr), "Failed to blit, hr %#lx.\n", hr);
12516 ckey.dwColorSpaceLowValue = c << tests[t].shift;
12517 ckey.dwColorSpaceHighValue = c << tests[t].shift;
12518 hr = IDirectDrawSurface4_SetColorKey(src, DDCKEY_SRCBLT, &ckey);
12519 ok(SUCCEEDED(hr), "Failed to set color key, hr %#lx.\n", hr);
12521 hr = IDirectDrawSurface4_Blt(dst, NULL, src, NULL, DDBLT_KEYSRC | DDBLT_WAIT, NULL);
12522 ok(SUCCEEDED(hr), "Failed to blit, hr %#lx.\n", hr);
12524 /* Don't make this read only, it somehow breaks the detection of the Nvidia bug below. */
12525 hr = IDirectDrawSurface4_Lock(dst, NULL, &lock_desc, DDLOCK_WAIT, NULL);
12526 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#lx.\n", hr);
12527 switch (tests[t].bpp)
12529 case 4:
12530 data[0] = ((DWORD *)lock_desc.lpSurface)[0] & color_mask;
12531 data[1] = ((DWORD *)lock_desc.lpSurface)[1] & color_mask;
12532 data[2] = ((DWORD *)lock_desc.lpSurface)[2] & color_mask;
12533 data[3] = ((DWORD *)lock_desc.lpSurface)[3] & color_mask;
12534 break;
12536 case 2:
12537 data[0] = ((WORD *)lock_desc.lpSurface)[0] & color_mask;
12538 data[1] = ((WORD *)lock_desc.lpSurface)[1] & color_mask;
12539 data[2] = ((WORD *)lock_desc.lpSurface)[2] & color_mask;
12540 data[3] = ((WORD *)lock_desc.lpSurface)[3] & color_mask;
12541 break;
12543 hr = IDirectDrawSurface4_Unlock(dst, 0);
12544 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx.\n", hr);
12546 if (!c)
12548 ok(data[0] == tests[t].clear, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
12549 tests[t].clear, data[0], tests[t].name, c);
12551 if (data[3] == tests[t].clear)
12553 /* My Geforce GTX 460 on Windows 7 misbehaves when A4R4G4B4 is blitted with color
12554 * keying: The blit takes ~0.5 seconds, and subsequent color keying draws are broken,
12555 * even when a different surface is used. The blit itself doesn't draw anything,
12556 * so we can detect the bug by looking at the otherwise unused 4th texel. It should
12557 * never be masked out by the key.
12559 * On Windows 10 the problem is worse, Blt just hangs. For this reason the ARGB4444
12560 * test is disabled entirely.
12562 * Also appears to affect the testbot in some way with R5G6B5. Color keying is
12563 * terrible on WARP. */
12564 skip("Nvidia A4R4G4B4 color keying blit bug detected, skipping.\n");
12565 IDirect3DTexture2_Release(d3d_texture);
12566 IDirectDrawSurface4_Release(texture);
12567 IDirectDrawSurface4_Release(src);
12568 IDirectDrawSurface4_Release(dst);
12569 goto done;
12572 else
12573 ok(data[0] == (c - 1) << tests[t].shift, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
12574 (c - 1) << tests[t].shift, data[0], tests[t].name, c);
12576 ok(data[1] == tests[t].clear, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
12577 tests[t].clear, data[1], tests[t].name, c);
12579 if (c == tests[t].max)
12580 ok(data[2] == tests[t].clear, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
12581 tests[t].clear, data[2], tests[t].name, c);
12582 else
12583 ok(data[2] == (c + 1) << tests[t].shift, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
12584 (c + 1) << tests[t].shift, data[2], tests[t].name, c);
12586 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0x0000ff00, 1.0f, 0);
12587 ok(SUCCEEDED(hr), "Failed to clear, hr %#lx.\n", hr);
12589 hr = IDirect3DDevice3_BeginScene(device);
12590 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#lx.\n", hr);
12591 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_TEX1, quad, 4, 0);
12592 ok(SUCCEEDED(hr), "Failed to draw, hr %#lx.\n", hr);
12593 hr = IDirect3DDevice3_EndScene(device);
12594 ok(SUCCEEDED(hr), "Failed to end scene, hr %#lx.\n", hr);
12596 color = get_surface_color(rt, 80, 240);
12597 if (!c)
12598 ok(compare_color(color, 0x0000ff00, 1) || broken(is_warp && compare_color(color, 0x00000000, 1)),
12599 "Got unexpected color 0x%08x, format %s, c=%u.\n",
12600 color, tests[t].name, c);
12601 else
12602 ok(compare_color(color, 0x00000000, 1) || broken(is_warp && compare_color(color, 0x0000ff00, 1)),
12603 "Got unexpected color 0x%08x, format %s, c=%u.\n",
12604 color, tests[t].name, c);
12606 color = get_surface_color(rt, 240, 240);
12607 ok(compare_color(color, 0x0000ff00, 1) || broken(is_warp && compare_color(color, 0x00000000, 1)),
12608 "Got unexpected color 0x%08x, format %s, c=%u.\n",
12609 color, tests[t].name, c);
12611 color = get_surface_color(rt, 400, 240);
12612 if (c == tests[t].max)
12613 ok(compare_color(color, 0x0000ff00, 1) || broken(is_warp && compare_color(color, 0x00000000, 1)),
12614 "Got unexpected color 0x%08x, format %s, c=%u.\n",
12615 color, tests[t].name, c);
12616 else
12617 ok(compare_color(color, 0x00000000, 1) || broken(is_warp && compare_color(color, 0x0000ff00, 1)),
12618 "Got unexpected color 0x%08x, format %s, c=%u.\n",
12619 color, tests[t].name, c);
12621 IDirect3DTexture2_Release(d3d_texture);
12622 IDirectDrawSurface4_Release(texture);
12624 IDirectDrawSurface4_Release(src);
12625 IDirectDrawSurface4_Release(dst);
12627 done:
12629 destroy_viewport(device, viewport);
12630 IDirectDrawSurface4_Release(rt);
12631 IDirectDraw4_Release(ddraw);
12632 refcount = IDirect3DDevice3_Release(device);
12633 ok(!refcount, "Device has %lu references left.\n", refcount);
12634 DestroyWindow(window);
12637 static void test_range_colorkey(void)
12639 IDirectDraw4 *ddraw;
12640 HWND window;
12641 HRESULT hr;
12642 IDirectDrawSurface4 *surface;
12643 DDSURFACEDESC2 surface_desc;
12644 ULONG refcount;
12645 DDCOLORKEY ckey;
12647 window = create_window();
12648 ddraw = create_ddraw();
12649 ok(!!ddraw, "Failed to create a ddraw object.\n");
12650 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
12651 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
12653 memset(&surface_desc, 0, sizeof(surface_desc));
12654 surface_desc.dwSize = sizeof(surface_desc);
12655 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CKSRCBLT;
12656 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
12657 surface_desc.dwWidth = 1;
12658 surface_desc.dwHeight = 1;
12659 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB;
12660 surface_desc.ddpfPixelFormat.dwRGBBitCount = 32;
12661 surface_desc.ddpfPixelFormat.dwRBitMask = 0x00ff0000;
12662 surface_desc.ddpfPixelFormat.dwGBitMask = 0x0000ff00;
12663 surface_desc.ddpfPixelFormat.dwBBitMask = 0x000000ff;
12664 surface_desc.ddpfPixelFormat.dwRGBAlphaBitMask = 0x00000000;
12666 /* Creating a surface with a range color key fails with DDERR_NOCOLORKEY. */
12667 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00000000;
12668 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00000001;
12669 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
12670 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#lx.\n", hr);
12672 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00000001;
12673 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00000000;
12674 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
12675 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#lx.\n", hr);
12677 /* Same for DDSCAPS_OFFSCREENPLAIN. */
12678 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
12679 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00000000;
12680 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00000001;
12681 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
12682 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#lx.\n", hr);
12684 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00000001;
12685 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00000000;
12686 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
12687 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#lx.\n", hr);
12689 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00000000;
12690 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00000000;
12691 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
12692 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
12694 /* Setting a range color key without DDCKEY_COLORSPACE collapses the key. */
12695 ckey.dwColorSpaceLowValue = 0x00000000;
12696 ckey.dwColorSpaceHighValue = 0x00000001;
12697 hr = IDirectDrawSurface4_SetColorKey(surface, DDCKEY_SRCBLT, &ckey);
12698 ok(SUCCEEDED(hr), "Failed to set color key, hr %#lx.\n", hr);
12700 hr = IDirectDrawSurface4_GetColorKey(surface, DDCKEY_SRCBLT, &ckey);
12701 ok(SUCCEEDED(hr), "Failed to get color key, hr %#lx.\n", hr);
12702 ok(!ckey.dwColorSpaceLowValue, "Got unexpected value 0x%08lx.\n", ckey.dwColorSpaceLowValue);
12703 ok(!ckey.dwColorSpaceHighValue, "Got unexpected value 0x%08lx.\n", ckey.dwColorSpaceHighValue);
12705 ckey.dwColorSpaceLowValue = 0x00000001;
12706 ckey.dwColorSpaceHighValue = 0x00000000;
12707 hr = IDirectDrawSurface4_SetColorKey(surface, DDCKEY_SRCBLT, &ckey);
12708 ok(SUCCEEDED(hr), "Failed to set color key, hr %#lx.\n", hr);
12710 hr = IDirectDrawSurface4_GetColorKey(surface, DDCKEY_SRCBLT, &ckey);
12711 ok(SUCCEEDED(hr), "Failed to get color key, hr %#lx.\n", hr);
12712 ok(ckey.dwColorSpaceLowValue == 0x00000001, "Got unexpected value 0x%08lx.\n", ckey.dwColorSpaceLowValue);
12713 ok(ckey.dwColorSpaceHighValue == 0x00000001, "Got unexpected value 0x%08lx.\n", ckey.dwColorSpaceHighValue);
12715 /* DDCKEY_COLORSPACE is ignored if the key is a single value. */
12716 ckey.dwColorSpaceLowValue = 0x00000000;
12717 ckey.dwColorSpaceHighValue = 0x00000000;
12718 hr = IDirectDrawSurface4_SetColorKey(surface, DDCKEY_SRCBLT | DDCKEY_COLORSPACE, &ckey);
12719 ok(SUCCEEDED(hr), "Failed to set color key, hr %#lx.\n", hr);
12721 /* Using it with a range key results in DDERR_NOCOLORKEYHW. */
12722 ckey.dwColorSpaceLowValue = 0x00000001;
12723 ckey.dwColorSpaceHighValue = 0x00000000;
12724 hr = IDirectDrawSurface4_SetColorKey(surface, DDCKEY_SRCBLT | DDCKEY_COLORSPACE, &ckey);
12725 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#lx.\n", hr);
12726 ckey.dwColorSpaceLowValue = 0x00000000;
12727 ckey.dwColorSpaceHighValue = 0x00000001;
12728 hr = IDirectDrawSurface4_SetColorKey(surface, DDCKEY_SRCBLT | DDCKEY_COLORSPACE, &ckey);
12729 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#lx.\n", hr);
12730 /* Range destination keys don't work either. */
12731 hr = IDirectDrawSurface4_SetColorKey(surface, DDCKEY_DESTBLT | DDCKEY_COLORSPACE, &ckey);
12732 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#lx.\n", hr);
12734 /* Just to show it's not because of A, R, and G having equal values. */
12735 ckey.dwColorSpaceLowValue = 0x00000000;
12736 ckey.dwColorSpaceHighValue = 0x01010101;
12737 hr = IDirectDrawSurface4_SetColorKey(surface, DDCKEY_SRCBLT | DDCKEY_COLORSPACE, &ckey);
12738 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#lx.\n", hr);
12740 /* None of these operations modified the key. */
12741 hr = IDirectDrawSurface4_GetColorKey(surface, DDCKEY_SRCBLT, &ckey);
12742 ok(SUCCEEDED(hr), "Failed to get color key, hr %#lx.\n", hr);
12743 ok(!ckey.dwColorSpaceLowValue, "Got unexpected value 0x%08lx.\n", ckey.dwColorSpaceLowValue);
12744 ok(!ckey.dwColorSpaceHighValue, "Got unexpected value 0x%08lx.\n", ckey.dwColorSpaceHighValue);
12746 IDirectDrawSurface4_Release(surface);
12747 refcount = IDirectDraw4_Release(ddraw);
12748 ok(!refcount, "Got unexpected refcount %lu.\n", refcount);
12749 DestroyWindow(window);
12752 static void test_shademode(void)
12754 IDirect3DVertexBuffer *vb_strip, *vb_list, *buffer;
12755 unsigned int color0, color1, count, i;
12756 IDirect3DViewport3 *viewport;
12757 IDirect3DDevice3 *device;
12758 D3DVERTEXBUFFERDESC desc;
12759 IDirectDrawSurface4 *rt;
12760 void *data = NULL;
12761 IDirect3D3 *d3d;
12762 ULONG refcount;
12763 HWND window;
12764 HRESULT hr;
12765 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
12766 static const struct
12768 struct vec3 position;
12769 DWORD diffuse;
12771 quad_strip[] =
12773 {{-1.0f, -1.0f, 0.0f}, 0xffff0000},
12774 {{-1.0f, 1.0f, 0.0f}, 0xff00ff00},
12775 {{ 1.0f, -1.0f, 0.0f}, 0xff0000ff},
12776 {{ 1.0f, 1.0f, 0.0f}, 0xffffffff},
12778 quad_list[] =
12780 {{-1.0f, -1.0f, 0.0f}, 0xffff0000},
12781 {{-1.0f, 1.0f, 0.0f}, 0xff00ff00},
12782 {{ 1.0f, -1.0f, 0.0f}, 0xff0000ff},
12784 {{ 1.0f, -1.0f, 0.0f}, 0xff0000ff},
12785 {{-1.0f, 1.0f, 0.0f}, 0xff00ff00},
12786 {{ 1.0f, 1.0f, 0.0f}, 0xffffffff},
12788 static const struct
12790 DWORD primtype;
12791 DWORD shademode;
12792 unsigned int color0, color1;
12794 tests[] =
12796 {D3DPT_TRIANGLESTRIP, D3DSHADE_FLAT, 0x00ff0000, 0x0000ff00},
12797 {D3DPT_TRIANGLESTRIP, D3DSHADE_PHONG, 0x000dca28, 0x000d45c7},
12798 {D3DPT_TRIANGLESTRIP, D3DSHADE_GOURAUD, 0x000dca28, 0x000d45c7},
12799 {D3DPT_TRIANGLESTRIP, D3DSHADE_PHONG, 0x000dca28, 0x000d45c7},
12800 {D3DPT_TRIANGLELIST, D3DSHADE_FLAT, 0x00ff0000, 0x000000ff},
12801 {D3DPT_TRIANGLELIST, D3DSHADE_GOURAUD, 0x000dca28, 0x000d45c7},
12804 window = create_window();
12805 if (!(device = create_device(window, DDSCL_NORMAL)))
12807 skip("Failed to create a 3D device, skipping test.\n");
12808 DestroyWindow(window);
12809 return;
12812 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
12813 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#lx.\n", hr);
12814 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
12815 ok(SUCCEEDED(hr), "Failed to get render target, hr %#lx.\n", hr);
12817 viewport = create_viewport(device, 0, 0, 640, 480);
12818 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
12819 ok(SUCCEEDED(hr), "Failed to activate the viewport, hr %#lx.\n", hr);
12821 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, FALSE);
12822 ok(SUCCEEDED(hr), "Failed to disable fog, hr %#lx.\n", hr);
12824 memset(&desc, 0, sizeof(desc));
12825 desc.dwSize = sizeof(desc);
12826 desc.dwCaps = D3DVBCAPS_WRITEONLY;
12827 desc.dwFVF = D3DFVF_XYZ | D3DFVF_DIFFUSE;
12828 desc.dwNumVertices = ARRAY_SIZE(quad_strip);
12829 hr = IDirect3D3_CreateVertexBuffer(d3d, &desc, &vb_strip, 0, NULL);
12830 ok(hr == D3D_OK, "Failed to create vertex buffer, hr %#lx.\n", hr);
12831 hr = IDirect3DVertexBuffer_Lock(vb_strip, 0, &data, NULL);
12832 ok(hr == D3D_OK, "Failed to lock vertex buffer, hr %#lx.\n", hr);
12833 memcpy(data, quad_strip, sizeof(quad_strip));
12834 hr = IDirect3DVertexBuffer_Unlock(vb_strip);
12835 ok(hr == D3D_OK, "Failed to unlock vertex buffer, hr %#lx.\n", hr);
12837 desc.dwNumVertices = ARRAY_SIZE(quad_list);
12838 hr = IDirect3D3_CreateVertexBuffer(d3d, &desc, &vb_list, 0, NULL);
12839 ok(hr == D3D_OK, "Failed to create vertex buffer, hr %#lx.\n", hr);
12840 hr = IDirect3DVertexBuffer_Lock(vb_list, 0, &data, NULL);
12841 ok(hr == D3D_OK, "Failed to lock vertex buffer, hr %#lx.\n", hr);
12842 memcpy(data, quad_list, sizeof(quad_list));
12843 hr = IDirect3DVertexBuffer_Unlock(vb_list);
12844 ok(hr == D3D_OK, "Failed to unlock vertex buffer, hr %#lx.\n", hr);
12846 /* Try it first with a TRIANGLESTRIP. Do it with different geometry because
12847 * the color fixups we have to do for FLAT shading will be dependent on that. */
12849 for (i = 0; i < ARRAY_SIZE(tests); ++i)
12851 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xffffffff, 0.0f, 0);
12852 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#lx.\n", hr);
12854 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_SHADEMODE, tests[i].shademode);
12855 ok(hr == D3D_OK, "Failed to set shade mode, hr %#lx.\n", hr);
12857 hr = IDirect3DDevice3_BeginScene(device);
12858 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#lx.\n", hr);
12859 buffer = tests[i].primtype == D3DPT_TRIANGLESTRIP ? vb_strip : vb_list;
12860 count = tests[i].primtype == D3DPT_TRIANGLESTRIP ? 4 : 6;
12861 hr = IDirect3DDevice3_DrawPrimitiveVB(device, tests[i].primtype, buffer, 0, count, 0);
12862 ok(SUCCEEDED(hr), "Failed to draw, hr %#lx.\n", hr);
12863 hr = IDirect3DDevice3_EndScene(device);
12864 ok(SUCCEEDED(hr), "Failed to end scene, hr %#lx.\n", hr);
12866 color0 = get_surface_color(rt, 100, 100); /* Inside first triangle */
12867 color1 = get_surface_color(rt, 500, 350); /* Inside second triangle */
12869 /* For D3DSHADE_FLAT it should take the color of the first vertex of
12870 * each triangle. This requires EXT_provoking_vertex or similar
12871 * functionality being available. */
12872 /* PHONG should be the same as GOURAUD, since no hardware implements
12873 * this. */
12874 ok(compare_color(color0, tests[i].color0, 1), "Test %u shading has color0 %08x, expected %08x.\n",
12875 i, color0, tests[i].color0);
12876 ok(compare_color(color1, tests[i].color1, 1), "Test %u shading has color1 %08x, expected %08x.\n",
12877 i, color1, tests[i].color1);
12880 IDirect3DVertexBuffer_Release(vb_strip);
12881 IDirect3DVertexBuffer_Release(vb_list);
12882 destroy_viewport(device, viewport);
12883 IDirectDrawSurface4_Release(rt);
12884 IDirect3D3_Release(d3d);
12885 refcount = IDirect3DDevice3_Release(device);
12886 ok(!refcount, "Device has %lu references left.\n", refcount);
12887 DestroyWindow(window);
12890 static void test_lockrect_invalid(void)
12892 unsigned int i, r;
12893 IDirectDraw4 *ddraw;
12894 IDirectDrawSurface4 *surface;
12895 HWND window;
12896 HRESULT hr;
12897 DDSURFACEDESC2 surface_desc;
12898 DDCAPS hal_caps;
12899 DWORD needed_caps = DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY;
12900 static RECT valid[] =
12902 {60, 60, 68, 68},
12903 {60, 60, 60, 68},
12904 {60, 60, 68, 60},
12905 {120, 60, 128, 68},
12906 {60, 120, 68, 128},
12908 static RECT invalid[] =
12910 {68, 60, 60, 68}, /* left > right */
12911 {60, 68, 68, 60}, /* top > bottom */
12912 {-8, 60, 0, 68}, /* left < surface */
12913 {60, -8, 68, 0}, /* top < surface */
12914 {-16, 60, -8, 68}, /* right < surface */
12915 {60, -16, 68, -8}, /* bottom < surface */
12916 {60, 60, 136, 68}, /* right > surface */
12917 {60, 60, 68, 136}, /* bottom > surface */
12918 {136, 60, 144, 68}, /* left > surface */
12919 {60, 136, 68, 144}, /* top > surface */
12921 static const struct
12923 DWORD caps, caps2;
12924 const char *name;
12925 BOOL allowed;
12926 HRESULT hr;
12928 resources[] =
12930 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY, 0, "sysmem offscreenplain", TRUE, DDERR_INVALIDPARAMS},
12931 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0, "vidmem offscreenplain", TRUE, DDERR_INVALIDPARAMS},
12932 {DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, 0, "sysmem texture", TRUE, DDERR_INVALIDPARAMS},
12933 {DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, 0, "vidmem texture", TRUE, DDERR_INVALIDPARAMS},
12934 {DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, "managed texture", TRUE, DDERR_INVALIDPARAMS},
12936 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY | DDSCAPS_WRITEONLY, 0, "sysmem offscreenplain writeonly", FALSE, DDERR_INVALIDPARAMS},
12937 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY | DDSCAPS_WRITEONLY, 0, "vidmem offscreenplain writeonly", FALSE, DDERR_INVALIDPARAMS},
12938 {DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_WRITEONLY, 0, "sysmem texture writeonly", FALSE, DDERR_INVALIDPARAMS},
12939 {DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_WRITEONLY, 0, "vidmem texture writeonly", FALSE, DDERR_INVALIDPARAMS},
12940 {DDSCAPS_TEXTURE | DDSCAPS_WRITEONLY, DDSCAPS2_TEXTUREMANAGE, "managed texture writeonly", TRUE, DDERR_INVALIDPARAMS},
12943 window = create_window();
12944 ddraw = create_ddraw();
12945 ok(!!ddraw, "Failed to create a ddraw object.\n");
12946 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
12947 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
12949 memset(&hal_caps, 0, sizeof(hal_caps));
12950 hal_caps.dwSize = sizeof(hal_caps);
12951 hr = IDirectDraw4_GetCaps(ddraw, &hal_caps, NULL);
12952 ok(SUCCEEDED(hr), "Failed to get caps, hr %#lx.\n", hr);
12953 if ((hal_caps.ddsCaps.dwCaps & needed_caps) != needed_caps
12954 || !(hal_caps.ddsCaps.dwCaps & DDSCAPS2_TEXTUREMANAGE))
12956 skip("Required surface types not supported, skipping test.\n");
12957 goto done;
12960 for (r = 0; r < ARRAY_SIZE(resources); ++r)
12962 memset(&surface_desc, 0, sizeof(surface_desc));
12963 surface_desc.dwSize = sizeof(surface_desc);
12964 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
12965 surface_desc.ddsCaps.dwCaps = resources[r].caps;
12966 surface_desc.ddsCaps.dwCaps2 = resources[r].caps2;
12967 surface_desc.dwWidth = 128;
12968 surface_desc.dwHeight = 128;
12969 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
12970 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB;
12971 surface_desc.ddpfPixelFormat.dwRGBBitCount = 32;
12972 surface_desc.ddpfPixelFormat.dwRBitMask = 0xff0000;
12973 surface_desc.ddpfPixelFormat.dwGBitMask = 0x00ff00;
12974 surface_desc.ddpfPixelFormat.dwBBitMask = 0x0000ff;
12976 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
12977 if (!resources[r].allowed)
12979 ok(hr == DDERR_INVALIDCAPS, "Got unexpected hr %#lx, type %s.\n", hr, resources[r].name);
12980 continue;
12982 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx, type %s.\n", hr, resources[r].name);
12984 hr = IDirectDrawSurface4_Lock(surface, NULL, NULL, DDLOCK_WAIT, NULL);
12985 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx, type %s.\n", hr, resources[r].name);
12987 for (i = 0; i < ARRAY_SIZE(valid); ++i)
12989 RECT *rect = &valid[i];
12991 memset(&surface_desc, 0, sizeof(surface_desc));
12992 surface_desc.dwSize = sizeof(surface_desc);
12994 hr = IDirectDrawSurface4_Lock(surface, rect, &surface_desc, DDLOCK_WAIT, NULL);
12995 ok(SUCCEEDED(hr), "Lock failed (%#lx) for rect %s, type %s.\n",
12996 hr, wine_dbgstr_rect(rect), resources[r].name);
12998 hr = IDirectDrawSurface4_Unlock(surface, NULL);
12999 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx, type %s.\n", hr, resources[r].name);
13002 for (i = 0; i < ARRAY_SIZE(invalid); ++i)
13004 RECT *rect = &invalid[i];
13006 memset(&surface_desc, 1, sizeof(surface_desc));
13007 surface_desc.dwSize = sizeof(surface_desc);
13009 hr = IDirectDrawSurface4_Lock(surface, rect, &surface_desc, DDLOCK_WAIT, NULL);
13010 ok(hr == resources[r].hr, "Lock returned %#lx for rect %s, type %s.\n",
13011 hr, wine_dbgstr_rect(rect), resources[r].name);
13012 if (SUCCEEDED(hr))
13014 hr = IDirectDrawSurface4_Unlock(surface, NULL);
13015 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx, type %s.\n", hr, resources[r].name);
13017 else
13018 ok(!surface_desc.lpSurface, "Got unexpected lpSurface %p.\n", surface_desc.lpSurface);
13021 hr = IDirectDrawSurface4_Lock(surface, NULL, &surface_desc, DDLOCK_WAIT, NULL);
13022 ok(SUCCEEDED(hr), "Lock(rect = NULL) failed, hr %#lx, type %s.\n",
13023 hr, resources[r].name);
13024 hr = IDirectDrawSurface4_Lock(surface, NULL, &surface_desc, DDLOCK_WAIT, NULL);
13025 ok(hr == DDERR_SURFACEBUSY, "Double lock(rect = NULL) returned %#lx, type %s.\n",
13026 hr, resources[r].name);
13027 hr = IDirectDrawSurface4_Unlock(surface, NULL);
13028 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx, type %s.\n", hr, resources[r].name);
13030 hr = IDirectDrawSurface4_Lock(surface, &valid[0], &surface_desc, DDLOCK_WAIT, NULL);
13031 ok(SUCCEEDED(hr), "Lock(rect = %s) failed (%#lx).\n", wine_dbgstr_rect(&valid[0]), hr);
13032 hr = IDirectDrawSurface4_Lock(surface, &valid[0], &surface_desc, DDLOCK_WAIT, NULL);
13033 ok(hr == DDERR_SURFACEBUSY, "Double lock(rect = %s) failed (%#lx).\n",
13034 wine_dbgstr_rect(&valid[0]), hr);
13036 /* Locking a different rectangle returns DD_OK, but it seems to break the surface.
13037 * Afterwards unlocking the surface fails(NULL rectangle or both locked rectangles) */
13039 hr = IDirectDrawSurface4_Unlock(surface, NULL);
13040 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx, type %s.\n", hr, resources[r].name);
13042 IDirectDrawSurface4_Release(surface);
13045 done:
13046 IDirectDraw4_Release(ddraw);
13047 DestroyWindow(window);
13050 static void test_yv12_overlay(void)
13052 IDirectDrawSurface4 *src_surface, *dst_surface;
13053 RECT rect = {13, 17, 14, 18};
13054 unsigned int offset, y;
13055 DDSURFACEDESC2 desc;
13056 unsigned char *base;
13057 IDirectDraw4 *ddraw;
13058 HWND window;
13059 HRESULT hr;
13061 window = create_window();
13062 ddraw = create_ddraw();
13063 ok(!!ddraw, "Failed to create a ddraw object.\n");
13064 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
13065 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
13067 if (!(src_surface = create_overlay(ddraw, 256, 256, MAKEFOURCC('Y','V','1','2'))))
13069 skip("Failed to create a YV12 overlay, skipping test.\n");
13070 goto done;
13073 memset(&desc, 0, sizeof(desc));
13074 desc.dwSize = sizeof(desc);
13075 hr = IDirectDrawSurface4_Lock(src_surface, NULL, &desc, DDLOCK_WAIT, NULL);
13076 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#lx.\n", hr);
13078 ok(desc.dwFlags == (DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_PITCH),
13079 "Got unexpected flags %#lx.\n", desc.dwFlags);
13080 ok(desc.ddsCaps.dwCaps == (DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM | DDSCAPS_HWCODEC)
13081 || desc.ddsCaps.dwCaps == (DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM),
13082 "Got unexpected caps %#lx.\n", desc.ddsCaps.dwCaps);
13083 ok(desc.dwWidth == 256, "Got unexpected width %lu.\n", desc.dwWidth);
13084 ok(desc.dwHeight == 256, "Got unexpected height %lu.\n", desc.dwHeight);
13085 /* The overlay pitch seems to have 256 byte alignment. */
13086 ok(!(desc.lPitch & 0xff), "Got unexpected pitch %lu.\n", desc.lPitch);
13088 /* Fill the surface with some data for the blit test. */
13089 base = desc.lpSurface;
13090 /* Luminance */
13091 for (y = 0; y < desc.dwHeight; ++y)
13093 memset(base + desc.lPitch * y, 0x10, desc.dwWidth);
13095 /* V */
13096 for (; y < desc.dwHeight + desc.dwHeight / 4; ++y)
13098 memset(base + desc.lPitch * y, 0x20, desc.dwWidth);
13100 /* U */
13101 for (; y < desc.dwHeight + desc.dwHeight / 2; ++y)
13103 memset(base + desc.lPitch * y, 0x30, desc.dwWidth);
13106 hr = IDirectDrawSurface4_Unlock(src_surface, NULL);
13107 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx.\n", hr);
13109 /* YV12 uses 2x2 blocks with 6 bytes per block (4*Y, 1*U, 1*V). Unlike
13110 * other block-based formats like DXT the entire Y channel is stored in
13111 * one big chunk of memory, followed by the chroma channels. So partial
13112 * locks do not really make sense. Show that they are allowed nevertheless
13113 * and the offset points into the luminance data. */
13114 hr = IDirectDrawSurface4_Lock(src_surface, &rect, &desc, DDLOCK_WAIT, NULL);
13115 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#lx.\n", hr);
13116 offset = ((const unsigned char *)desc.lpSurface - base);
13117 ok(offset == rect.top * desc.lPitch + rect.left, "Got unexpected offset %u, expected %lu.\n",
13118 offset, rect.top * desc.lPitch + rect.left);
13119 hr = IDirectDrawSurface4_Unlock(src_surface, NULL);
13120 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx.\n", hr);
13122 if (!(dst_surface = create_overlay(ddraw, 256, 256, MAKEFOURCC('Y','V','1','2'))))
13124 /* Windows XP with a Radeon X1600 GPU refuses to create a second
13125 * overlay surface, DDERR_NOOVERLAYHW, making the blit tests moot. */
13126 skip("Failed to create a second YV12 surface, skipping blit test.\n");
13127 IDirectDrawSurface4_Release(src_surface);
13128 goto done;
13131 hr = IDirectDrawSurface4_Blt(dst_surface, NULL, src_surface, NULL, DDBLT_WAIT, NULL);
13132 /* VMware rejects YV12 blits. This behavior has not been seen on real
13133 * hardware yet, so mark it broken. */
13134 ok(SUCCEEDED(hr) || broken(hr == E_NOTIMPL), "Failed to blit, hr %#lx.\n", hr);
13136 if (SUCCEEDED(hr))
13138 memset(&desc, 0, sizeof(desc));
13139 desc.dwSize = sizeof(desc);
13140 hr = IDirectDrawSurface4_Lock(dst_surface, NULL, &desc, DDLOCK_WAIT, NULL);
13141 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#lx.\n", hr);
13143 base = desc.lpSurface;
13144 ok(base[0] == 0x10, "Got unexpected Y data 0x%02x.\n", base[0]);
13145 base += desc.dwHeight * desc.lPitch;
13146 ok(base[0] == 0x20, "Got unexpected V data 0x%02x.\n", base[0]);
13147 base += desc.dwHeight / 4 * desc.lPitch;
13148 ok(base[0] == 0x30, "Got unexpected U data 0x%02x.\n", base[0]);
13150 hr = IDirectDrawSurface4_Unlock(dst_surface, NULL);
13151 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx.\n", hr);
13154 IDirectDrawSurface4_Release(dst_surface);
13155 IDirectDrawSurface4_Release(src_surface);
13156 done:
13157 IDirectDraw4_Release(ddraw);
13158 DestroyWindow(window);
13161 static BOOL dwm_enabled(void)
13163 BOOL ret = FALSE;
13165 if (!strcmp(winetest_platform, "wine"))
13166 return FALSE;
13167 if (!pDwmIsCompositionEnabled)
13168 return FALSE;
13169 if (FAILED(pDwmIsCompositionEnabled(&ret)))
13170 return FALSE;
13171 return ret;
13174 static void test_offscreen_overlay(void)
13176 IDirectDrawSurface4 *overlay, *offscreen, *primary;
13177 DDSURFACEDESC2 surface_desc;
13178 IDirectDraw4 *ddraw;
13179 HWND window;
13180 HRESULT hr;
13181 HDC dc;
13183 window = create_window();
13184 ddraw = create_ddraw();
13185 ok(!!ddraw, "Failed to create a ddraw object.\n");
13186 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
13187 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
13189 if (!(overlay = create_overlay(ddraw, 64, 64, MAKEFOURCC('U','Y','V','Y'))))
13191 skip("Failed to create a UYVY overlay, skipping test.\n");
13192 goto done;
13195 memset(&surface_desc, 0, sizeof(surface_desc));
13196 surface_desc.dwSize = sizeof(surface_desc);
13197 surface_desc.dwFlags = DDSD_CAPS;
13198 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
13199 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &primary, NULL);
13200 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n",hr);
13202 /* On Windows 7, and probably Vista, UpdateOverlay() will return
13203 * DDERR_OUTOFCAPS if the dwm is active. Calling GetDC() on the primary
13204 * surface prevents this by disabling the dwm. */
13205 hr = IDirectDrawSurface4_GetDC(primary, &dc);
13206 ok(SUCCEEDED(hr), "Failed to get DC, hr %#lx.\n", hr);
13207 hr = IDirectDrawSurface4_ReleaseDC(primary, dc);
13208 ok(SUCCEEDED(hr), "Failed to release DC, hr %#lx.\n", hr);
13210 /* Try to overlay a NULL surface. */
13211 hr = IDirectDrawSurface4_UpdateOverlay(overlay, NULL, NULL, NULL, DDOVER_SHOW, NULL);
13212 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
13213 hr = IDirectDrawSurface4_UpdateOverlay(overlay, NULL, NULL, NULL, DDOVER_HIDE, NULL);
13214 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
13216 /* Try to overlay an offscreen surface. */
13217 memset(&surface_desc, 0, sizeof(surface_desc));
13218 surface_desc.dwSize = sizeof(surface_desc);
13219 surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
13220 surface_desc.dwWidth = 64;
13221 surface_desc.dwHeight = 64;
13222 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
13223 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
13224 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB;
13225 surface_desc.ddpfPixelFormat.dwFourCC = 0;
13226 surface_desc.ddpfPixelFormat.dwRGBBitCount = 16;
13227 surface_desc.ddpfPixelFormat.dwRBitMask = 0xf800;
13228 surface_desc.ddpfPixelFormat.dwGBitMask = 0x07e0;
13229 surface_desc.ddpfPixelFormat.dwBBitMask = 0x001f;
13230 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &offscreen, NULL);
13231 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n",hr);
13233 hr = IDirectDrawSurface4_UpdateOverlay(overlay, NULL, offscreen, NULL, DDOVER_SHOW, NULL);
13234 ok(SUCCEEDED(hr) || broken(hr == DDERR_OUTOFCAPS && dwm_enabled())
13235 || broken(hr == E_NOTIMPL && ddraw_is_vmware(ddraw)),
13236 "Failed to update overlay, hr %#lx.\n", hr);
13238 /* Try to overlay the primary with a non-overlay surface. */
13239 hr = IDirectDrawSurface4_UpdateOverlay(offscreen, NULL, primary, NULL, DDOVER_SHOW, NULL);
13240 ok(hr == DDERR_NOTAOVERLAYSURFACE, "Got unexpected hr %#lx.\n", hr);
13241 hr = IDirectDrawSurface4_UpdateOverlay(offscreen, NULL, primary, NULL, DDOVER_HIDE, NULL);
13242 ok(hr == DDERR_NOTAOVERLAYSURFACE, "Got unexpected hr %#lx.\n", hr);
13244 IDirectDrawSurface4_Release(offscreen);
13245 IDirectDrawSurface4_Release(primary);
13246 IDirectDrawSurface4_Release(overlay);
13247 done:
13248 IDirectDraw4_Release(ddraw);
13249 DestroyWindow(window);
13252 static void test_overlay_rect(void)
13254 IDirectDrawSurface4 *overlay, *primary = NULL;
13255 DDSURFACEDESC2 surface_desc;
13256 RECT rect = {0, 0, 64, 64};
13257 IDirectDraw4 *ddraw;
13258 LONG pos_x, pos_y;
13259 HRESULT hr, hr2;
13260 HWND window;
13261 HDC dc;
13263 window = create_window();
13264 ddraw = create_ddraw();
13265 ok(!!ddraw, "Failed to create a ddraw object.\n");
13266 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
13267 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
13269 if (!(overlay = create_overlay(ddraw, 64, 64, MAKEFOURCC('U','Y','V','Y'))))
13271 skip("Failed to create a UYVY overlay, skipping test.\n");
13272 goto done;
13275 memset(&surface_desc, 0, sizeof(surface_desc));
13276 surface_desc.dwSize = sizeof(surface_desc);
13277 surface_desc.dwFlags = DDSD_CAPS;
13278 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
13279 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &primary, NULL);
13280 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n",hr);
13282 /* On Windows 7, and probably Vista, UpdateOverlay() will return
13283 * DDERR_OUTOFCAPS if the dwm is active. Calling GetDC() on the primary
13284 * surface prevents this by disabling the dwm. */
13285 hr = IDirectDrawSurface4_GetDC(primary, &dc);
13286 ok(SUCCEEDED(hr), "Failed to get DC, hr %#lx.\n", hr);
13287 hr = IDirectDrawSurface4_ReleaseDC(primary, dc);
13288 ok(SUCCEEDED(hr), "Failed to release DC, hr %#lx.\n", hr);
13290 /* On Windows 8 and newer DWM can't be turned off, making overlays unusable. */
13291 if (dwm_enabled())
13293 win_skip("Cannot disable DWM, skipping overlay test.\n");
13294 goto done;
13297 /* The dx sdk sort of implies that rect must be set when DDOVER_SHOW is
13298 * used. This is not true in Windows Vista and earlier, but changed in
13299 * Windows 7. */
13300 hr = IDirectDrawSurface4_UpdateOverlay(overlay, NULL, primary, &rect, DDOVER_SHOW, NULL);
13301 ok(SUCCEEDED(hr), "Failed to update overlay, hr %#lx.\n", hr);
13302 hr = IDirectDrawSurface4_UpdateOverlay(overlay, NULL, primary, NULL, DDOVER_HIDE, NULL);
13303 ok(SUCCEEDED(hr), "Failed to update overlay, hr %#lx.\n", hr);
13304 hr = IDirectDrawSurface4_UpdateOverlay(overlay, NULL, primary, NULL, DDOVER_SHOW, NULL);
13305 ok(hr == DD_OK || hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
13307 /* Show that the overlay position is the (top, left) coordinate of the
13308 * destination rectangle. */
13309 OffsetRect(&rect, 32, 16);
13310 hr = IDirectDrawSurface4_UpdateOverlay(overlay, NULL, primary, &rect, DDOVER_SHOW, NULL);
13311 ok(SUCCEEDED(hr), "Failed to update overlay, hr %#lx.\n", hr);
13312 pos_x = -1; pos_y = -1;
13313 hr = IDirectDrawSurface4_GetOverlayPosition(overlay, &pos_x, &pos_y);
13314 ok(SUCCEEDED(hr), "Failed to get overlay position, hr %#lx.\n", hr);
13315 ok(pos_x == rect.left, "Got unexpected pos_x %ld, expected %ld.\n", pos_x, rect.left);
13316 ok(pos_y == rect.top, "Got unexpected pos_y %ld, expected %ld.\n", pos_y, rect.top);
13318 /* Passing a NULL dest rect sets the position to 0/0. Visually it can be
13319 * seen that the overlay overlays the whole primary(==screen). */
13320 hr2 = IDirectDrawSurface4_UpdateOverlay(overlay, NULL, primary, NULL, 0, NULL);
13321 ok(hr2 == DD_OK || hr2 == DDERR_INVALIDPARAMS || hr2 == DDERR_OUTOFCAPS, "Got unexpected hr %#lx.\n", hr2);
13322 hr = IDirectDrawSurface4_GetOverlayPosition(overlay, &pos_x, &pos_y);
13323 ok(SUCCEEDED(hr), "Failed to get overlay position, hr %#lx.\n", hr);
13324 if (SUCCEEDED(hr2))
13326 ok(!pos_x, "Got unexpected pos_x %ld.\n", pos_x);
13327 ok(!pos_y, "Got unexpected pos_y %ld.\n", pos_y);
13329 else
13331 ok(pos_x == 32, "Got unexpected pos_x %ld.\n", pos_x);
13332 ok(pos_y == 16, "Got unexpected pos_y %ld.\n", pos_y);
13335 /* The position cannot be retrieved when the overlay is not shown. */
13336 hr = IDirectDrawSurface4_UpdateOverlay(overlay, NULL, primary, &rect, DDOVER_HIDE, NULL);
13337 ok(SUCCEEDED(hr), "Failed to update overlay, hr %#lx.\n", hr);
13338 pos_x = -1; pos_y = -1;
13339 hr = IDirectDrawSurface4_GetOverlayPosition(overlay, &pos_x, &pos_y);
13340 ok(hr == DDERR_OVERLAYNOTVISIBLE, "Got unexpected hr %#lx.\n", hr);
13341 ok(!pos_x, "Got unexpected pos_x %ld.\n", pos_x);
13342 ok(!pos_y, "Got unexpected pos_y %ld.\n", pos_y);
13344 done:
13345 if (primary)
13346 IDirectDrawSurface4_Release(primary);
13347 if (overlay)
13348 IDirectDrawSurface4_Release(overlay);
13349 IDirectDraw4_Release(ddraw);
13350 DestroyWindow(window);
13353 static void test_blt(void)
13355 IDirectDrawSurface4 *surface, *rt;
13356 DDSURFACEDESC2 surface_desc;
13357 IDirect3DDevice3 *device;
13358 IDirectDraw4 *ddraw;
13359 IDirect3D3 *d3d;
13360 unsigned int i;
13361 ULONG refcount;
13362 HWND window;
13363 HRESULT hr;
13365 static struct
13367 RECT src_rect;
13368 RECT dst_rect;
13369 HRESULT hr;
13371 test_data[] =
13373 {{160, 0, 640, 480}, { 0, 0, 480, 480}, DD_OK}, /* Overlapped blit. */
13374 {{160, 480, 640, 0}, { 0, 0, 480, 480}, DDERR_INVALIDRECT}, /* Overlapped blit, flipped source. */
13375 {{640, 0, 160, 480}, { 0, 0, 480, 480}, DDERR_INVALIDRECT}, /* Overlapped blit, mirrored source. */
13376 {{160, 0, 480, 480}, { 0, 0, 480, 480}, DD_OK}, /* Overlapped blit, stretched x. */
13377 {{160, 160, 640, 480}, { 0, 0, 480, 480}, DD_OK}, /* Overlapped blit, stretched y. */
13378 {{ 0, 0, 640, 480}, { 0, 0, 640, 480}, DD_OK}, /* Full surface blit. */
13379 {{ 0, 0, 640, 480}, { 0, 480, 640, 0}, DDERR_INVALIDRECT}, /* Full surface, flipped destination. */
13380 {{ 0, 0, 640, 480}, {640, 0, 0, 480}, DDERR_INVALIDRECT}, /* Full surface, mirrored destination. */
13381 {{ 0, 480, 640, 0}, { 0, 0, 640, 480}, DDERR_INVALIDRECT}, /* Full surface, flipped source. */
13382 {{640, 0, 0, 480}, { 0, 0, 640, 480}, DDERR_INVALIDRECT}, /* Full surface, mirrored source. */
13385 window = create_window();
13386 if (!(device = create_device(window, DDSCL_NORMAL)))
13388 skip("Failed to create a 3D device, skipping test.\n");
13389 DestroyWindow(window);
13390 return;
13393 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
13394 ok(SUCCEEDED(hr), "Failed to get Direct3D3 interface, hr %#lx.\n", hr);
13395 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
13396 ok(SUCCEEDED(hr), "Failed to get DirectDraw4 interface, hr %#lx.\n", hr);
13397 IDirect3D3_Release(d3d);
13398 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
13399 ok(SUCCEEDED(hr), "Failed to get render target, hr %#lx.\n", hr);
13401 memset(&surface_desc, 0, sizeof(surface_desc));
13402 surface_desc.dwSize = sizeof(surface_desc);
13403 surface_desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
13404 surface_desc.dwWidth = 640;
13405 surface_desc.dwHeight = 480;
13406 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
13407 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
13408 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
13410 hr = IDirectDrawSurface4_Blt(surface, NULL, surface, NULL, 0, NULL);
13411 ok(SUCCEEDED(hr), "Failed to blit, hr %#lx.\n", hr);
13413 hr = IDirectDrawSurface4_Blt(surface, NULL, rt, NULL, 0, NULL);
13414 ok(SUCCEEDED(hr), "Failed to blit, hr %#lx.\n", hr);
13416 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
13418 hr = IDirectDrawSurface4_Blt(surface, &test_data[i].dst_rect,
13419 surface, &test_data[i].src_rect, DDBLT_WAIT, NULL);
13420 ok(hr == test_data[i].hr, "Test %u: Got unexpected hr %#lx, expected %#lx.\n", i, hr, test_data[i].hr);
13422 hr = IDirectDrawSurface4_Blt(surface, &test_data[i].dst_rect,
13423 rt, &test_data[i].src_rect, DDBLT_WAIT, NULL);
13424 ok(hr == test_data[i].hr, "Test %u: Got unexpected hr %#lx, expected %#lx.\n", i, hr, test_data[i].hr);
13426 hr = IDirectDrawSurface4_Blt(surface, &test_data[i].dst_rect,
13427 NULL, &test_data[i].src_rect, DDBLT_WAIT, NULL);
13428 ok(hr == DDERR_INVALIDPARAMS, "Test %u: Got unexpected hr %#lx.\n", i, hr);
13430 hr = IDirectDrawSurface4_Blt(surface, &test_data[i].dst_rect, NULL, NULL, DDBLT_WAIT, NULL);
13431 ok(hr == DDERR_INVALIDPARAMS, "Test %u: Got unexpected hr %#lx.\n", i, hr);
13434 IDirectDrawSurface4_Release(surface);
13435 IDirectDrawSurface4_Release(rt);
13436 IDirectDraw4_Release(ddraw);
13437 refcount = IDirect3DDevice3_Release(device);
13438 ok(!refcount, "Device has %lu references left.\n", refcount);
13439 DestroyWindow(window);
13442 static void test_blt_z_alpha(void)
13444 DWORD blt_flags[] =
13446 /* 0 */
13447 DDBLT_ALPHADEST,
13448 DDBLT_ALPHADESTCONSTOVERRIDE,
13449 DDBLT_ALPHADESTNEG,
13450 DDBLT_ALPHADESTSURFACEOVERRIDE,
13451 DDBLT_ALPHAEDGEBLEND,
13452 /* 5 */
13453 DDBLT_ALPHASRC,
13454 DDBLT_ALPHASRCCONSTOVERRIDE,
13455 DDBLT_ALPHASRCNEG,
13456 DDBLT_ALPHASRCSURFACEOVERRIDE,
13457 DDBLT_ZBUFFER,
13458 /* 10 */
13459 DDBLT_ZBUFFERDESTCONSTOVERRIDE,
13460 DDBLT_ZBUFFERDESTOVERRIDE,
13461 DDBLT_ZBUFFERSRCCONSTOVERRIDE,
13462 DDBLT_ZBUFFERSRCOVERRIDE,
13464 IDirectDrawSurface4 *src_surface, *dst_surface;
13465 DDSURFACEDESC2 surface_desc;
13466 unsigned int color, i;
13467 IDirectDraw4 *ddraw;
13468 DDPIXELFORMAT pf;
13469 ULONG refcount;
13470 HWND window;
13471 HRESULT hr;
13472 DDBLTFX fx;
13474 window = create_window();
13475 ddraw = create_ddraw();
13476 ok(!!ddraw, "Failed to create a ddraw object.\n");
13477 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
13478 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
13480 memset(&pf, 0, sizeof(pf));
13481 pf.dwSize = sizeof(pf);
13482 pf.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
13483 pf.dwRGBBitCount = 32;
13484 pf.dwRBitMask = 0x00ff0000;
13485 pf.dwGBitMask = 0x0000ff00;
13486 pf.dwBBitMask = 0x000000ff;
13487 pf.dwRGBAlphaBitMask = 0xff000000;
13489 memset(&surface_desc, 0, sizeof(surface_desc));
13490 surface_desc.dwSize = sizeof(surface_desc);
13491 surface_desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_PIXELFORMAT;
13492 surface_desc.dwWidth = 64;
13493 surface_desc.dwHeight = 64;
13494 surface_desc.ddpfPixelFormat = pf;
13495 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
13497 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &src_surface, NULL);
13498 ok(SUCCEEDED(hr), "Failed to create source surface, hr %#lx.\n", hr);
13499 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &dst_surface, NULL);
13500 ok(SUCCEEDED(hr), "Failed to create destination surface, hr %#lx.\n", hr);
13502 memset(&fx, 0, sizeof(fx));
13503 fx.dwSize = sizeof(fx);
13504 fx.dwZBufferOpCode = D3DCMP_NEVER;
13505 fx.dwZDestConstBitDepth = 32;
13506 fx.dwZDestConst = 0x11111111;
13507 fx.dwZSrcConstBitDepth = 32;
13508 fx.dwZSrcConst = 0xeeeeeeee;
13509 fx.dwAlphaEdgeBlendBitDepth = 8;
13510 fx.dwAlphaEdgeBlend = 0x7f;
13511 fx.dwAlphaDestConstBitDepth = 8;
13512 fx.dwAlphaDestConst = 0xdd;
13513 fx.dwAlphaSrcConstBitDepth = 8;
13514 fx.dwAlphaSrcConst = 0x22;
13516 for (i = 0; i < ARRAY_SIZE(blt_flags); ++i)
13518 fx.dwFillColor = 0x3300ff00;
13519 hr = IDirectDrawSurface4_Blt(src_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
13520 ok(SUCCEEDED(hr), "Test %u: Got unexpected hr %#lx.\n", i, hr);
13522 fx.dwFillColor = 0xccff0000;
13523 hr = IDirectDrawSurface4_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
13524 ok(SUCCEEDED(hr), "Test %u: Got unexpected hr %#lx.\n", i, hr);
13526 hr = IDirectDrawSurface4_Blt(dst_surface, NULL, src_surface, NULL, blt_flags[i] | DDBLT_WAIT, &fx);
13527 ok(SUCCEEDED(hr), "Test %u: Got unexpected hr %#lx.\n", i, hr);
13529 color = get_surface_color(dst_surface, 32, 32);
13530 ok(compare_color(color, 0x0000ff00, 0), "Test %u: Got unexpected color 0x%08x.\n", i, color);
13533 IDirectDrawSurface4_Release(dst_surface);
13534 IDirectDrawSurface4_Release(src_surface);
13535 refcount = IDirectDraw4_Release(ddraw);
13536 ok(!refcount, "DirectDraw has %lu references left.\n", refcount);
13537 DestroyWindow(window);
13540 static void test_cross_device_blt(void)
13542 IDirectDrawSurface4 *surface, *surface2, *sysmem_surface;
13543 IDirect3DDevice3 *device, *device2;
13544 IDirectDraw4 *ddraw, *ddraw2;
13545 DDSURFACEDESC2 surface_desc;
13546 HWND window, window2;
13547 unsigned int color;
13548 IDirect3D3 *d3d;
13549 ULONG refcount;
13550 DDBLTFX fx;
13551 HRESULT hr;
13553 window = create_window();
13554 if (!(device = create_device(window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN)))
13556 skip("Failed to create a 3D device.\n");
13557 DestroyWindow(window);
13558 return;
13561 window2 = create_window();
13562 if (!(device2 = create_device(window2, DDSCL_NORMAL)))
13564 skip("Failed to create a 3D device.\n");
13565 IDirect3DDevice3_Release(device);
13566 DestroyWindow(window);
13567 DestroyWindow(window2);
13568 return;
13571 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
13572 ok(SUCCEEDED(hr), "Failed to get Direct3D3 interface, hr %#lx.\n", hr);
13573 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
13574 ok(SUCCEEDED(hr), "Failed to get DirectDraw4 interface, hr %#lx.\n", hr);
13575 IDirect3D3_Release(d3d);
13577 hr = IDirect3DDevice3_GetDirect3D(device2, &d3d);
13578 ok(SUCCEEDED(hr), "Failed to get Direct3D3 interface, hr %#lx.\n", hr);
13579 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw2);
13580 ok(SUCCEEDED(hr), "Failed to get DirectDraw4 interface, hr %#lx.\n", hr);
13581 IDirect3D3_Release(d3d);
13583 memset(&surface_desc, 0, sizeof(surface_desc));
13584 surface_desc.dwSize = sizeof(surface_desc);
13585 surface_desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
13586 surface_desc.dwWidth = 640;
13587 surface_desc.dwHeight = 480;
13588 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
13589 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &sysmem_surface, NULL);
13590 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
13592 memset(&surface_desc, 0, sizeof(surface_desc));
13593 surface_desc.dwSize = sizeof(surface_desc);
13594 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
13595 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP | DDSCAPS_VIDEOMEMORY;
13596 surface_desc.dwBackBufferCount = 2;
13597 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
13598 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
13600 memset(&surface_desc, 0, sizeof(surface_desc));
13601 surface_desc.dwSize = sizeof(surface_desc);
13602 surface_desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_PIXELFORMAT;
13603 surface_desc.dwWidth = 640;
13604 surface_desc.dwHeight = 480;
13605 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
13606 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
13607 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB;
13608 surface_desc.ddpfPixelFormat.dwRGBBitCount = 16;
13609 surface_desc.ddpfPixelFormat.dwRBitMask = 0x00007c00;
13610 surface_desc.ddpfPixelFormat.dwGBitMask = 0x000003e0;
13611 surface_desc.ddpfPixelFormat.dwBBitMask = 0x0000001f;
13612 hr = IDirectDraw4_CreateSurface(ddraw2, &surface_desc, &surface2, NULL);
13613 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
13615 memset(&fx, 0, sizeof(fx));
13616 fx.dwSize = sizeof(fx);
13617 fx.dwFillColor = 0xff0000ff;
13618 hr = IDirectDrawSurface4_Blt(surface2, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
13619 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#lx.\n", hr);
13621 hr = IDirectDrawSurface4_Blt(surface, NULL, surface2, NULL, DDBLT_WAIT, NULL);
13622 ok(hr == E_NOTIMPL, "Got unexpected hr %#lx.\n", hr);
13623 hr = IDirectDrawSurface4_Flip(surface, NULL, DDFLIP_WAIT);
13624 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
13625 hr = IDirectDrawSurface4_Blt(surface, NULL, surface2, NULL, DDBLT_WAIT, NULL);
13626 ok(hr == E_NOTIMPL, "Got unexpected hr %#lx.\n", hr);
13627 color = get_surface_color(surface, 320, 240);
13628 ok(color == 0x00000000, "Got unexpected color 0x%08x.\n", color);
13630 hr = IDirectDrawSurface4_Blt(sysmem_surface, NULL, surface2, NULL, DDBLT_WAIT, NULL);
13631 ok(hr == E_NOTIMPL, "Got unexpected hr %#lx.\n", hr);
13632 color = get_surface_color(sysmem_surface, 320, 240);
13633 ok(color == 0x00000000, "Got unexpected color 0x%08x.\n", color);
13635 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
13636 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
13637 hr = IDirectDrawSurface4_IsLost(sysmem_surface);
13638 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
13640 hr = IDirectDrawSurface4_Blt(sysmem_surface, NULL, surface2, NULL, DDBLT_WAIT, NULL);
13641 ok(hr == E_NOTIMPL, "Got unexpected hr %#lx.\n", hr);
13642 color = get_surface_color(sysmem_surface, 320, 240);
13643 ok(color == 0x00000000, "Got unexpected color 0x%08x.\n", color);
13645 IDirectDrawSurface4_Release(surface2);
13646 memset(&surface_desc, 0, sizeof(surface_desc));
13647 surface_desc.dwSize = sizeof(surface_desc);
13648 surface_desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
13649 surface_desc.dwWidth = 640;
13650 surface_desc.dwHeight = 480;
13651 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
13652 hr = IDirectDraw4_CreateSurface(ddraw2, &surface_desc, &surface2, NULL);
13653 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
13654 hr = IDirectDrawSurface4_Blt(surface2, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
13655 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#lx.\n", hr);
13657 hr = IDirectDrawSurface4_Blt(sysmem_surface, NULL, surface2, NULL, DDBLT_WAIT, NULL);
13658 todo_wine ok(hr == D3D_OK, "Failed to blit, hr %#lx.\n", hr);
13659 color = get_surface_color(sysmem_surface, 320, 240);
13660 todo_wine ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
13662 IDirectDrawSurface4_Release(surface);
13663 IDirectDrawSurface4_Release(surface2);
13664 IDirectDrawSurface4_Release(sysmem_surface);
13665 IDirectDraw4_Release(ddraw);
13666 IDirectDraw4_Release(ddraw2);
13667 refcount = IDirect3DDevice3_Release(device);
13668 ok(!refcount, "Device has %lu references left.\n", refcount);
13669 refcount = IDirect3DDevice3_Release(device2);
13670 ok(!refcount, "Device has %lu references left.\n", refcount);
13671 DestroyWindow(window);
13672 DestroyWindow(window2);
13675 static void test_color_clamping(void)
13677 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
13678 static D3DMATRIX mat =
13680 1.0f, 0.0f, 0.0f, 0.0f,
13681 0.0f, 1.0f, 0.0f, 0.0f,
13682 0.0f, 0.0f, 1.0f, 0.0f,
13683 0.0f, 0.0f, 0.0f, 1.0f,
13685 static struct vec3 quad[] =
13687 {-1.0f, -1.0f, 0.1f},
13688 {-1.0f, 1.0f, 0.1f},
13689 { 1.0f, -1.0f, 0.1f},
13690 { 1.0f, 1.0f, 0.1f},
13692 IDirect3DViewport3 *viewport;
13693 IDirect3DDevice3 *device;
13694 IDirectDrawSurface4 *rt;
13695 unsigned int color;
13696 ULONG refcount;
13697 HWND window;
13698 HRESULT hr;
13700 window = create_window();
13701 if (!(device = create_device(window, DDSCL_NORMAL)))
13703 skip("Failed to create a 3D device, skipping test.\n");
13704 DestroyWindow(window);
13705 return;
13708 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
13709 ok(SUCCEEDED(hr), "Failed to get render target, hr %#lx.\n", hr);
13711 viewport = create_viewport(device, 0, 0, 640, 480);
13712 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
13713 ok(SUCCEEDED(hr), "Failed to activate the viewport, hr %#lx.\n", hr);
13715 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &mat);
13716 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#lx.\n", hr);
13717 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_VIEW, &mat);
13718 ok(SUCCEEDED(hr), "Failed to set view transform, hr %#lx.\n", hr);
13719 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &mat);
13720 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#lx.\n", hr);
13721 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ZENABLE, FALSE);
13722 ok(SUCCEEDED(hr), "Failed to disable Z test, hr %#lx.\n", hr);
13723 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, FALSE);
13724 ok(SUCCEEDED(hr), "Failed to disable fog, hr %#lx.\n", hr);
13725 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_STENCILENABLE, FALSE);
13726 ok(SUCCEEDED(hr), "Failed to disable stencil test, hr %#lx.\n", hr);
13727 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_CULLMODE, D3DCULL_NONE);
13728 ok(SUCCEEDED(hr), "Failed to disable culling, hr %#lx.\n", hr);
13730 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_TEXTUREFACTOR, 0xff404040);
13731 ok(SUCCEEDED(hr), "Failed to set texture factor, hr %#lx.\n", hr);
13732 hr = IDirect3DDevice3_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_ADD);
13733 ok(SUCCEEDED(hr), "Failed to set color op, hr %#lx.\n", hr);
13734 hr = IDirect3DDevice3_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);
13735 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#lx.\n", hr);
13736 hr = IDirect3DDevice3_SetTextureStageState(device, 0, D3DTSS_COLORARG2, D3DTA_SPECULAR);
13737 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#lx.\n", hr);
13738 hr = IDirect3DDevice3_SetTextureStageState(device, 1, D3DTSS_COLOROP, D3DTOP_MODULATE);
13739 ok(SUCCEEDED(hr), "Failed to set color op, hr %#lx.\n", hr);
13740 hr = IDirect3DDevice3_SetTextureStageState(device, 1, D3DTSS_COLORARG1, D3DTA_TFACTOR);
13741 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#lx.\n", hr);
13742 hr = IDirect3DDevice3_SetTextureStageState(device, 1, D3DTSS_COLORARG2, D3DTA_CURRENT);
13743 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#lx.\n", hr);
13745 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xff00ff00, 0.0f, 0);
13746 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#lx.\n", hr);
13748 hr = IDirect3DDevice3_BeginScene(device);
13749 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#lx.\n", hr);
13751 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, quad, 4, 0);
13752 ok(SUCCEEDED(hr), "Failed to draw, hr %#lx.\n", hr);
13754 hr = IDirect3DDevice3_EndScene(device);
13755 ok(SUCCEEDED(hr), "Failed to end scene, hr %#lx.\n", hr);
13757 color = get_surface_color(rt, 320, 240);
13758 ok(compare_color(color, 0x00404040, 1), "Got unexpected color 0x%08x.\n", color);
13760 destroy_viewport(device, viewport);
13761 IDirectDrawSurface4_Release(rt);
13762 refcount = IDirect3DDevice3_Release(device);
13763 ok(!refcount, "Device has %lu references left.\n", refcount);
13764 DestroyWindow(window);
13767 static void test_getdc(void)
13769 DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, {0}};
13770 IDirectDrawSurface4 *surface, *surface2, *tmp;
13771 DDSURFACEDESC2 surface_desc, map_desc;
13772 IDirectDraw4 *ddraw;
13773 unsigned int i, screen_bpp;
13774 HWND window;
13775 HDC dc, dc2;
13776 HRESULT hr;
13778 static const struct
13780 const char *name;
13781 DDPIXELFORMAT format;
13782 BOOL getdc_supported;
13783 HRESULT alt_result;
13785 test_data[] =
13787 {"D3DFMT_A8R8G8B8", {sizeof(test_data->format), DDPF_RGB | DDPF_ALPHAPIXELS, 0, {32},
13788 {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}}, TRUE},
13789 {"D3DFMT_X8R8G8B8", {sizeof(test_data->format), DDPF_RGB, 0, {32},
13790 {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0x00000000}}, TRUE},
13791 {"D3DFMT_R5G6B5", {sizeof(test_data->format), DDPF_RGB, 0, {16},
13792 {0x0000f800}, {0x000007e0}, {0x0000001f}, {0x00000000}}, TRUE},
13793 {"D3DFMT_X1R5G5B5", {sizeof(test_data->format), DDPF_RGB, 0, {16},
13794 {0x00007c00}, {0x000003e0}, {0x0000001f}, {0x00000000}}, TRUE},
13795 {"D3DFMT_A1R5G5B5", {sizeof(test_data->format), DDPF_RGB | DDPF_ALPHAPIXELS, 0, {16},
13796 {0x00007c00}, {0x000003e0}, {0x0000001f}, {0x00008000}}, TRUE},
13797 {"D3DFMT_A4R4G4B4", {sizeof(test_data->format), DDPF_RGB | DDPF_ALPHAPIXELS, 0, {16},
13798 {0x00000f00}, {0x000000f0}, {0x0000000f}, {0x0000f000}}, TRUE, DDERR_CANTCREATEDC /* Vista+ */},
13799 {"D3DFMT_X4R4G4B4", {sizeof(test_data->format), DDPF_RGB, 0, {16},
13800 {0x00000f00}, {0x000000f0}, {0x0000000f}, {0x00000000}}, TRUE, DDERR_CANTCREATEDC /* Vista+ */},
13801 {"D3DFMT_A2R10G10B10", {sizeof(test_data->format), DDPF_RGB | DDPF_ALPHAPIXELS, 0, {32},
13802 {0xc0000000}, {0x3ff00000}, {0x000ffc00}, {0x000003ff}}, TRUE},
13803 {"D3DFMT_A8B8G8R8", {sizeof(test_data->format), DDPF_RGB | DDPF_ALPHAPIXELS, 0, {32},
13804 {0x000000ff}, {0x0000ff00}, {0x00ff0000}, {0xff000000}}, TRUE, DDERR_CANTCREATEDC /* Vista+ */},
13805 {"D3DFMT_X8B8G8R8", {sizeof(test_data->format), DDPF_RGB, 0, {32},
13806 {0x000000ff}, {0x0000ff00}, {0x00ff0000}, {0x00000000}}, TRUE, DDERR_CANTCREATEDC /* Vista+ */},
13807 {"D3DFMT_R3G3B2", {sizeof(test_data->format), DDPF_RGB, 0, {8},
13808 {0x000000e0}, {0x0000001c}, {0x00000003}, {0x00000000}}, FALSE},
13809 /* GetDC() on a P8 surface fails unless the display mode is 8 bpp.
13810 * This is not implemented in wine yet, so disable the test for now.
13811 * Succeeding P8 GetDC() calls are tested in the ddraw:visual test.
13812 {"D3DFMT_P8", {sizeof(test_data->format), DDPF_PALETTEINDEXED8 | DDPF_RGB, 0, {8 },
13813 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
13815 {"D3DFMT_L8", {sizeof(test_data->format), DDPF_LUMINANCE, 0, {8},
13816 {0x000000ff}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
13817 {"D3DFMT_A8L8", {sizeof(test_data->format), DDPF_ALPHAPIXELS | DDPF_LUMINANCE, 0, {16},
13818 {0x000000ff}, {0x00000000}, {0x00000000}, {0x0000ff00}}, FALSE},
13819 {"D3DFMT_DXT1", {sizeof(test_data->format), DDPF_FOURCC, MAKEFOURCC('D','X','T','1'), {0},
13820 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
13821 {"D3DFMT_DXT2", {sizeof(test_data->format), DDPF_FOURCC, MAKEFOURCC('D','X','T','2'), {0},
13822 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
13823 {"D3DFMT_DXT3", {sizeof(test_data->format), DDPF_FOURCC, MAKEFOURCC('D','X','T','3'), {0},
13824 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
13825 {"D3DFMT_DXT4", {sizeof(test_data->format), DDPF_FOURCC, MAKEFOURCC('D','X','T','4'), {0},
13826 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
13827 {"D3DFMT_DXT5", {sizeof(test_data->format), DDPF_FOURCC, MAKEFOURCC('D','X','T','5'), {0},
13828 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
13831 window = create_window();
13832 ddraw = create_ddraw();
13833 ok(!!ddraw, "Failed to create a ddraw object.\n");
13834 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
13835 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
13837 surface_desc.dwSize = sizeof(surface_desc);
13838 hr = IDirectDraw4_GetDisplayMode(ddraw, &surface_desc);
13839 ok(SUCCEEDED(hr), "Failed to get display mode, hr %#lx.\n", hr);
13840 screen_bpp = surface_desc.ddpfPixelFormat.dwRGBBitCount;
13842 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
13844 memset(&surface_desc, 0, sizeof(surface_desc));
13845 surface_desc.dwSize = sizeof(surface_desc);
13846 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
13847 surface_desc.dwWidth = 64;
13848 surface_desc.dwHeight = 64;
13849 surface_desc.ddpfPixelFormat = test_data[i].format;
13850 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
13852 if (FAILED(IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL)))
13854 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
13855 surface_desc.ddsCaps.dwCaps2 = DDSCAPS2_TEXTUREMANAGE;
13856 if (FAILED(hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL)))
13858 skip("Failed to create surface for format %s (hr %#lx), skipping tests.\n", test_data[i].name, hr);
13859 continue;
13863 dc = (void *)0x1234;
13864 hr = IDirectDrawSurface4_GetDC(surface, &dc);
13865 if (test_data[i].getdc_supported)
13866 ok(SUCCEEDED(hr) || broken(hr == test_data[i].alt_result),
13867 "Got unexpected hr %#lx for format %s.\n", hr, test_data[i].name);
13868 else
13869 ok(FAILED(hr), "Got unexpected hr %#lx for format %s.\n", hr, test_data[i].name);
13871 if (SUCCEEDED(hr))
13873 unsigned int width_bytes;
13874 DIBSECTION dib;
13875 HBITMAP bitmap;
13876 DWORD type;
13877 int size;
13879 type = GetObjectType(dc);
13880 ok(type == OBJ_MEMDC, "Got unexpected object type %#lx for format %s.\n", type, test_data[i].name);
13881 bitmap = GetCurrentObject(dc, OBJ_BITMAP);
13882 type = GetObjectType(bitmap);
13883 ok(type == OBJ_BITMAP, "Got unexpected object type %#lx for format %s.\n", type, test_data[i].name);
13885 size = GetObjectA(bitmap, sizeof(dib), &dib);
13886 ok(size == sizeof(dib), "Got unexpected size %d for format %s.\n", size, test_data[i].name);
13887 ok(!dib.dsBm.bmType, "Got unexpected type %#x for format %s.\n",
13888 dib.dsBm.bmType, test_data[i].name);
13889 ok(dib.dsBm.bmWidth == surface_desc.dwWidth, "Got unexpected width %d for format %s.\n",
13890 dib.dsBm.bmWidth, test_data[i].name);
13891 ok(dib.dsBm.bmHeight == surface_desc.dwHeight, "Got unexpected height %d for format %s.\n",
13892 dib.dsBm.bmHeight, test_data[i].name);
13893 width_bytes = ((dib.dsBm.bmWidth * test_data[i].format.dwRGBBitCount + 31) >> 3) & ~3;
13894 ok(dib.dsBm.bmWidthBytes == width_bytes, "Got unexpected width bytes %d for format %s.\n",
13895 dib.dsBm.bmWidthBytes, test_data[i].name);
13896 ok(dib.dsBm.bmPlanes == 1, "Got unexpected plane count %d for format %s.\n",
13897 dib.dsBm.bmPlanes, test_data[i].name);
13898 ok(dib.dsBm.bmBitsPixel == test_data[i].format.dwRGBBitCount,
13899 "Got unexpected bit count %d for format %s.\n",
13900 dib.dsBm.bmBitsPixel, test_data[i].name);
13901 /* Windows XP sets bmBits == NULL for formats that match the screen at least on my r200 GPU. I
13902 * suspect this applies to all HW accelerated pre-WDDM drivers because they can handle gdi access
13903 * to ddraw surfaces themselves instead of going through a sysmem DIB section. */
13904 ok(!!dib.dsBm.bmBits || broken(!pDwmIsCompositionEnabled && dib.dsBm.bmBitsPixel == screen_bpp),
13905 "Got unexpected bits %p for format %s.\n", dib.dsBm.bmBits, test_data[i].name);
13907 ok(dib.dsBmih.biSize == sizeof(dib.dsBmih), "Got unexpected size %lu for format %s.\n",
13908 dib.dsBmih.biSize, test_data[i].name);
13909 ok(dib.dsBmih.biWidth == surface_desc.dwWidth, "Got unexpected width %ld for format %s.\n",
13910 dib.dsBmih.biHeight, test_data[i].name);
13911 ok(dib.dsBmih.biHeight == surface_desc.dwHeight, "Got unexpected height %ld for format %s.\n",
13912 dib.dsBmih.biHeight, test_data[i].name);
13913 ok(dib.dsBmih.biPlanes == 1, "Got unexpected plane count %u for format %s.\n",
13914 dib.dsBmih.biPlanes, test_data[i].name);
13915 ok(dib.dsBmih.biBitCount == test_data[i].format.dwRGBBitCount,
13916 "Got unexpected bit count %u for format %s.\n",
13917 dib.dsBmih.biBitCount, test_data[i].name);
13918 ok(dib.dsBmih.biCompression == (test_data[i].format.dwRGBBitCount == 16 ? BI_BITFIELDS : BI_RGB)
13919 || broken(test_data[i].format.dwRGBBitCount == 32 && dib.dsBmih.biCompression == BI_BITFIELDS),
13920 "Got unexpected compression %#lx for format %s.\n",
13921 dib.dsBmih.biCompression, test_data[i].name);
13922 ok(!dib.dsBmih.biSizeImage, "Got unexpected image size %lu for format %s.\n",
13923 dib.dsBmih.biSizeImage, test_data[i].name);
13924 ok(!dib.dsBmih.biXPelsPerMeter, "Got unexpected horizontal resolution %ld for format %s.\n",
13925 dib.dsBmih.biXPelsPerMeter, test_data[i].name);
13926 ok(!dib.dsBmih.biYPelsPerMeter, "Got unexpected vertical resolution %ld for format %s.\n",
13927 dib.dsBmih.biYPelsPerMeter, test_data[i].name);
13928 ok(!dib.dsBmih.biClrUsed, "Got unexpected used colour count %lu for format %s.\n",
13929 dib.dsBmih.biClrUsed, test_data[i].name);
13930 ok(!dib.dsBmih.biClrImportant, "Got unexpected important colour count %lu for format %s.\n",
13931 dib.dsBmih.biClrImportant, test_data[i].name);
13933 if (dib.dsBmih.biCompression == BI_BITFIELDS)
13935 ok((dib.dsBitfields[0] == test_data[i].format.dwRBitMask
13936 && dib.dsBitfields[1] == test_data[i].format.dwGBitMask
13937 && dib.dsBitfields[2] == test_data[i].format.dwBBitMask)
13938 || broken(!dib.dsBitfields[0] && !dib.dsBitfields[1] && !dib.dsBitfields[2]),
13939 "Got unexpected colour masks 0x%08lx 0x%08lx 0x%08lx for format %s.\n",
13940 dib.dsBitfields[0], dib.dsBitfields[1], dib.dsBitfields[2], test_data[i].name);
13942 else
13944 ok(!dib.dsBitfields[0] && !dib.dsBitfields[1] && !dib.dsBitfields[2],
13945 "Got unexpected colour masks 0x%08lx 0x%08lx 0x%08lx for format %s.\n",
13946 dib.dsBitfields[0], dib.dsBitfields[1], dib.dsBitfields[2], test_data[i].name);
13948 ok(!dib.dshSection, "Got unexpected section %p for format %s.\n", dib.dshSection, test_data[i].name);
13949 ok(!dib.dsOffset, "Got unexpected offset %lu for format %s.\n", dib.dsOffset, test_data[i].name);
13951 hr = IDirectDrawSurface4_ReleaseDC(surface, dc);
13952 ok(hr == DD_OK, "Failed to release DC for format %s, hr %#lx.\n", test_data[i].name, hr);
13954 else
13956 ok(!dc, "Got unexpected dc %p for format %s.\n", dc, test_data[i].name);
13959 IDirectDrawSurface4_Release(surface);
13961 if (FAILED(hr))
13962 continue;
13964 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
13965 surface_desc.ddsCaps.dwCaps2 = DDSCAPS2_TEXTUREMANAGE;
13966 if (FAILED(hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL)))
13968 skip("Failed to create mip-mapped texture for format %s (hr %#lx), skipping tests.\n",
13969 test_data[i].name, hr);
13970 continue;
13973 hr = IDirectDrawSurface4_GetAttachedSurface(surface, &caps, &tmp);
13974 ok(SUCCEEDED(hr), "Failed to get attached surface for format %s, hr %#lx.\n", test_data[i].name, hr);
13975 hr = IDirectDrawSurface4_GetAttachedSurface(tmp, &caps, &surface2);
13976 ok(SUCCEEDED(hr), "Failed to get attached surface for format %s, hr %#lx.\n", test_data[i].name, hr);
13977 IDirectDrawSurface4_Release(tmp);
13979 hr = IDirectDrawSurface4_GetDC(surface, &dc);
13980 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#lx.\n", test_data[i].name, hr);
13981 hr = IDirectDrawSurface4_ReleaseDC(surface, dc);
13982 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#lx.\n", test_data[i].name, hr);
13983 hr = IDirectDrawSurface4_GetDC(surface2, &dc);
13984 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#lx.\n", test_data[i].name, hr);
13985 hr = IDirectDrawSurface4_ReleaseDC(surface2, dc);
13986 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#lx.\n", test_data[i].name, hr);
13988 hr = IDirectDrawSurface4_GetDC(surface, &dc);
13989 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#lx.\n", test_data[i].name, hr);
13990 dc2 = (void *)0x1234;
13991 hr = IDirectDrawSurface4_GetDC(surface, &dc2);
13992 ok(hr == DDERR_DCALREADYCREATED, "Got unexpected hr %#lx for format %s.\n", hr, test_data[i].name);
13993 ok(dc2 == (void *)0x1234, "Got unexpected dc %p for format %s.\n", dc, test_data[i].name);
13994 hr = IDirectDrawSurface4_ReleaseDC(surface, dc);
13995 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#lx.\n", test_data[i].name, hr);
13996 hr = IDirectDrawSurface4_ReleaseDC(surface, dc);
13997 ok(hr == DDERR_NODC, "Got unexpected hr %#lx for format %s.\n", hr, test_data[i].name);
13999 map_desc.dwSize = sizeof(map_desc);
14000 hr = IDirectDrawSurface4_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
14001 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#lx.\n", test_data[i].name, hr);
14002 hr = IDirectDrawSurface4_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
14003 ok(hr == DDERR_SURFACEBUSY, "Got unexpected hr %#lx for format %s.\n", hr, test_data[i].name);
14004 hr = IDirectDrawSurface4_Unlock(surface, NULL);
14005 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#lx.\n", test_data[i].name, hr);
14006 hr = IDirectDrawSurface4_Unlock(surface, NULL);
14007 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#lx for format %s.\n", hr, test_data[i].name);
14009 hr = IDirectDrawSurface4_GetDC(surface, &dc);
14010 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#lx.\n", test_data[i].name, hr);
14011 hr = IDirectDrawSurface4_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
14012 ok(hr == DDERR_SURFACEBUSY, "Got unexpected hr %#lx for format %s.\n", hr, test_data[i].name);
14013 hr = IDirectDrawSurface4_ReleaseDC(surface, dc);
14014 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#lx.\n", test_data[i].name, hr);
14016 hr = IDirectDrawSurface4_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
14017 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#lx.\n", test_data[i].name, hr);
14018 hr = IDirectDrawSurface4_GetDC(surface, &dc);
14019 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#lx.\n", test_data[i].name, hr);
14020 hr = IDirectDrawSurface4_ReleaseDC(surface, dc);
14021 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#lx.\n", test_data[i].name, hr);
14022 hr = IDirectDrawSurface4_Unlock(surface, NULL);
14023 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#lx.\n", test_data[i].name, hr);
14025 hr = IDirectDrawSurface4_GetDC(surface, &dc);
14026 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#lx.\n", test_data[i].name, hr);
14027 hr = IDirectDrawSurface4_GetDC(surface2, &dc2);
14028 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#lx.\n", test_data[i].name, hr);
14029 hr = IDirectDrawSurface4_ReleaseDC(surface2, dc2);
14030 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#lx.\n", test_data[i].name, hr);
14031 hr = IDirectDrawSurface4_ReleaseDC(surface, dc);
14032 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#lx.\n", test_data[i].name, hr);
14034 hr = IDirectDrawSurface4_GetDC(surface2, &dc);
14035 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#lx.\n", test_data[i].name, hr);
14036 hr = IDirectDrawSurface4_GetDC(surface, &dc2);
14037 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#lx.\n", test_data[i].name, hr);
14038 hr = IDirectDrawSurface4_ReleaseDC(surface, dc2);
14039 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#lx.\n", test_data[i].name, hr);
14040 hr = IDirectDrawSurface4_ReleaseDC(surface2, dc);
14041 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#lx.\n", test_data[i].name, hr);
14043 hr = IDirectDrawSurface4_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
14044 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#lx.\n", test_data[i].name, hr);
14045 hr = IDirectDrawSurface4_Lock(surface2, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
14046 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#lx.\n", test_data[i].name, hr);
14047 hr = IDirectDrawSurface4_Unlock(surface2, NULL);
14048 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#lx.\n", test_data[i].name, hr);
14049 hr = IDirectDrawSurface4_Unlock(surface, NULL);
14050 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#lx.\n", test_data[i].name, hr);
14052 hr = IDirectDrawSurface4_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
14053 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#lx.\n", test_data[i].name, hr);
14054 hr = IDirectDrawSurface4_GetDC(surface, &dc);
14055 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#lx.\n", test_data[i].name, hr);
14056 hr = IDirectDrawSurface4_ReleaseDC(surface, dc);
14057 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#lx.\n", test_data[i].name, hr);
14058 hr = IDirectDrawSurface4_Unlock(surface, NULL);
14059 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#lx.\n", test_data[i].name, hr);
14061 hr = IDirectDrawSurface4_Lock(surface2, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
14062 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#lx.\n", test_data[i].name, hr);
14063 hr = IDirectDrawSurface4_GetDC(surface, &dc);
14064 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#lx.\n", test_data[i].name, hr);
14065 hr = IDirectDrawSurface4_ReleaseDC(surface, dc);
14066 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#lx.\n", test_data[i].name, hr);
14067 hr = IDirectDrawSurface4_Unlock(surface2, NULL);
14068 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#lx.\n", test_data[i].name, hr);
14070 hr = IDirectDrawSurface4_GetDC(surface, &dc);
14071 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#lx.\n", test_data[i].name, hr);
14072 hr = IDirectDrawSurface4_Lock(surface2, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
14073 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#lx.\n", test_data[i].name, hr);
14074 hr = IDirectDrawSurface4_Unlock(surface2, NULL);
14075 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#lx.\n", test_data[i].name, hr);
14076 hr = IDirectDrawSurface4_ReleaseDC(surface, dc);
14077 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#lx.\n", test_data[i].name, hr);
14079 hr = IDirectDrawSurface4_GetDC(surface2, &dc);
14080 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#lx.\n", test_data[i].name, hr);
14081 hr = IDirectDrawSurface4_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
14082 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#lx.\n", test_data[i].name, hr);
14083 hr = IDirectDrawSurface4_Unlock(surface, NULL);
14084 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#lx.\n", test_data[i].name, hr);
14085 hr = IDirectDrawSurface4_ReleaseDC(surface2, dc);
14086 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#lx.\n", test_data[i].name, hr);
14088 hr = IDirectDrawSurface4_Unlock(surface, NULL);
14089 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#lx for format %s.\n", hr, test_data[i].name);
14090 hr = IDirectDrawSurface4_GetDC(surface2, &dc);
14091 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#lx.\n", test_data[i].name, hr);
14092 hr = IDirectDrawSurface4_Unlock(surface, NULL);
14093 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#lx for format %s.\n", hr, test_data[i].name);
14094 hr = IDirectDrawSurface4_ReleaseDC(surface2, dc);
14095 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#lx.\n", test_data[i].name, hr);
14096 hr = IDirectDrawSurface4_Unlock(surface, NULL);
14097 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#lx for format %s.\n", hr, test_data[i].name);
14099 hr = IDirectDrawSurface4_Unlock(surface2, NULL);
14100 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#lx for format %s.\n", hr, test_data[i].name);
14101 hr = IDirectDrawSurface4_GetDC(surface, &dc);
14102 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#lx.\n", test_data[i].name, hr);
14103 hr = IDirectDrawSurface4_Unlock(surface2, NULL);
14104 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#lx for format %s.\n", hr, test_data[i].name);
14105 hr = IDirectDrawSurface4_ReleaseDC(surface, dc);
14106 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#lx.\n", test_data[i].name, hr);
14107 hr = IDirectDrawSurface4_Unlock(surface2, NULL);
14108 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#lx for format %s.\n", hr, test_data[i].name);
14110 IDirectDrawSurface4_Release(surface2);
14111 IDirectDrawSurface4_Release(surface);
14114 IDirectDraw4_Release(ddraw);
14115 DestroyWindow(window);
14118 static void test_draw_primitive(void)
14120 static WORD indices[] = {0, 1, 2, 3};
14121 static struct vec3 quad[] =
14123 {-1.0f, -1.0f, 0.0f},
14124 {-1.0f, 1.0f, 0.0f},
14125 { 1.0f, -1.0f, 0.0f},
14126 { 1.0f, 1.0f, 0.0f},
14128 D3DDRAWPRIMITIVESTRIDEDDATA strided;
14129 IDirect3DViewport3 *viewport;
14130 D3DVERTEXBUFFERDESC vb_desc;
14131 IDirect3DVertexBuffer *vb;
14132 IDirect3DDevice3 *device;
14133 IDirect3D3 *d3d;
14134 ULONG refcount;
14135 HWND window;
14136 HRESULT hr;
14137 void *data;
14139 window = create_window();
14140 if (!(device = create_device(window, DDSCL_NORMAL)))
14142 skip("Failed to create a 3D device, skipping test.\n");
14143 DestroyWindow(window);
14144 return;
14147 viewport = create_viewport(device, 0, 0, 640, 480);
14148 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
14149 ok(SUCCEEDED(hr), "Failed to activate the viewport, hr %#lx.\n", hr);
14151 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
14152 ok(SUCCEEDED(hr), "Failed to get D3D interface, hr %#lx.\n", hr);
14154 memset(&vb_desc, 0, sizeof(vb_desc));
14155 vb_desc.dwSize = sizeof(vb_desc);
14156 vb_desc.dwFVF = D3DFVF_XYZ;
14157 vb_desc.dwNumVertices = 4;
14158 hr = IDirect3D3_CreateVertexBuffer(d3d, &vb_desc, &vb, 0, NULL);
14159 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#lx.\n", hr);
14161 IDirect3D3_Release(d3d);
14163 memset(&strided, 0, sizeof(strided));
14165 hr = IDirect3DDevice3_DrawIndexedPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, NULL, 0, NULL, 0, 0);
14166 ok(SUCCEEDED(hr), "Failed to draw, hr %#lx.\n", hr);
14167 hr = IDirect3DDevice3_DrawIndexedPrimitiveStrided(device,
14168 D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, &strided, 0, NULL, 0, 0);
14169 ok(SUCCEEDED(hr), "Failed to draw, hr %#lx.\n", hr);
14170 hr = IDirect3DDevice3_DrawIndexedPrimitiveVB(device, D3DPT_TRIANGLESTRIP, vb, NULL, 0, 0);
14171 ok(SUCCEEDED(hr), "Failed to draw, hr %#lx.\n", hr);
14172 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, NULL, 0, 0);
14173 ok(SUCCEEDED(hr), "Failed to draw, hr %#lx.\n", hr);
14174 hr = IDirect3DDevice3_DrawPrimitiveStrided(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, &strided, 0, 0);
14175 ok(SUCCEEDED(hr), "Failed to draw, hr %#lx.\n", hr);
14176 hr = IDirect3DDevice3_DrawPrimitiveVB(device, D3DPT_TRIANGLESTRIP, vb, 0, 0, 0);
14177 ok(SUCCEEDED(hr), "Failed to draw, hr %#lx.\n", hr);
14179 hr = IDirect3DDevice3_DrawIndexedPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, NULL, 0, indices, 4, 0);
14180 ok(SUCCEEDED(hr), "Failed to draw, hr %#lx.\n", hr);
14181 hr = IDirect3DDevice3_DrawIndexedPrimitiveStrided(device,
14182 D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, &strided, 0, indices, 4, 0);
14183 ok(SUCCEEDED(hr), "Failed to draw, hr %#lx.\n", hr);
14184 hr = IDirect3DDevice3_DrawIndexedPrimitiveVB(device, D3DPT_TRIANGLESTRIP, vb, indices, 4, 0);
14185 ok(SUCCEEDED(hr), "Failed to draw, hr %#lx.\n", hr);
14187 strided.position.lpvData = quad;
14188 strided.position.dwStride = sizeof(*quad);
14189 hr = IDirect3DVertexBuffer_Lock(vb, 0, &data, NULL);
14190 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#lx.\n", hr);
14191 memcpy(data, quad, sizeof(quad));
14192 hr = IDirect3DVertexBuffer_Unlock(vb);
14193 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#lx.\n", hr);
14195 hr = IDirect3DDevice3_DrawIndexedPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, quad, 4, NULL, 0, 0);
14196 ok(SUCCEEDED(hr), "Failed to draw, hr %#lx.\n", hr);
14197 hr = IDirect3DDevice3_DrawIndexedPrimitiveStrided(device,
14198 D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, &strided, 4, NULL, 0, 0);
14199 ok(SUCCEEDED(hr), "Failed to draw, hr %#lx.\n", hr);
14200 hr = IDirect3DDevice3_DrawIndexedPrimitiveVB(device, D3DPT_TRIANGLESTRIP, vb, NULL, 0, 0);
14201 ok(SUCCEEDED(hr), "Failed to draw, hr %#lx.\n", hr);
14202 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, quad, 4, 0);
14203 ok(SUCCEEDED(hr), "Failed to draw, hr %#lx.\n", hr);
14204 hr = IDirect3DDevice3_DrawPrimitiveStrided(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, &strided, 4, 0);
14205 ok(SUCCEEDED(hr), "Failed to draw, hr %#lx.\n", hr);
14206 hr = IDirect3DDevice3_DrawPrimitiveVB(device, D3DPT_TRIANGLESTRIP, vb, 0, 4, 0);
14207 ok(SUCCEEDED(hr), "Failed to draw, hr %#lx.\n", hr);
14208 hr = IDirect3DDevice3_DrawIndexedPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, quad, 4, indices, 4, 0);
14209 ok(SUCCEEDED(hr), "Failed to draw, hr %#lx.\n", hr);
14210 hr = IDirect3DDevice3_DrawIndexedPrimitiveStrided(device,
14211 D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, &strided, 4, indices, 4, 0);
14212 ok(SUCCEEDED(hr), "Failed to draw, hr %#lx.\n", hr);
14213 hr = IDirect3DDevice3_DrawIndexedPrimitiveVB(device, D3DPT_TRIANGLESTRIP, vb, indices, 4, 0);
14214 ok(SUCCEEDED(hr), "Failed to draw, hr %#lx.\n", hr);
14216 IDirect3DVertexBuffer_Release(vb);
14217 destroy_viewport(device, viewport);
14218 refcount = IDirect3DDevice3_Release(device);
14219 ok(!refcount, "Device has %lu references left.\n", refcount);
14220 DestroyWindow(window);
14223 static void test_edge_antialiasing_blending(void)
14225 D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
14226 IDirectDrawSurface4 *offscreen, *ds;
14227 D3DDEVICEDESC hal_desc, hel_desc;
14228 IDirect3DViewport3 *viewport;
14229 DDSURFACEDESC2 surface_desc;
14230 IDirect3DDevice3 *device;
14231 IDirectDraw4 *ddraw;
14232 unsigned int color;
14233 IDirect3D3 *d3d;
14234 ULONG refcount;
14235 HWND window;
14236 HRESULT hr;
14238 static D3DMATRIX mat =
14240 1.0f, 0.0f, 0.0f, 0.0f,
14241 0.0f, 1.0f, 0.0f, 0.0f,
14242 0.0f, 0.0f, 1.0f, 0.0f,
14243 0.0f, 0.0f, 0.0f, 1.0f,
14245 static struct
14247 struct vec3 position;
14248 DWORD diffuse;
14250 green_quad[] =
14252 {{-1.0f, -1.0f, 0.1f}, 0x7f00ff00},
14253 {{-1.0f, 1.0f, 0.1f}, 0x7f00ff00},
14254 {{ 1.0f, -1.0f, 0.1f}, 0x7f00ff00},
14255 {{ 1.0f, 1.0f, 0.1f}, 0x7f00ff00},
14257 static struct
14259 struct vec3 position;
14260 DWORD diffuse;
14262 red_quad[] =
14264 {{-1.0f, -1.0f, 0.1f}, 0xccff0000},
14265 {{-1.0f, 1.0f, 0.1f}, 0xccff0000},
14266 {{ 1.0f, -1.0f, 0.1f}, 0xccff0000},
14267 {{ 1.0f, 1.0f, 0.1f}, 0xccff0000},
14270 window = create_window();
14271 if (!(device = create_device(window, DDSCL_NORMAL)))
14273 skip("Failed to create a 3D device.\n");
14274 DestroyWindow(window);
14275 return;
14278 memset(&hal_desc, 0, sizeof(hal_desc));
14279 hal_desc.dwSize = sizeof(hal_desc);
14280 memset(&hel_desc, 0, sizeof(hel_desc));
14281 hel_desc.dwSize = sizeof(hel_desc);
14282 hr = IDirect3DDevice3_GetCaps(device, &hal_desc, &hel_desc);
14283 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#lx.\n", hr);
14284 trace("HAL line edge antialiasing support: %#lx.\n",
14285 hal_desc.dpcLineCaps.dwRasterCaps & D3DPRASTERCAPS_ANTIALIASEDGES);
14286 trace("HAL triangle edge antialiasing support: %#lx.\n",
14287 hal_desc.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_ANTIALIASEDGES);
14288 trace("HEL line edge antialiasing support: %#lx.\n",
14289 hel_desc.dpcLineCaps.dwRasterCaps & D3DPRASTERCAPS_ANTIALIASEDGES);
14290 trace("HEL triangle edge antialiasing support: %#lx.\n",
14291 hel_desc.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_ANTIALIASEDGES);
14293 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
14294 ok(SUCCEEDED(hr), "Failed to get D3D interface, hr %#lx.\n", hr);
14295 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
14296 ok(SUCCEEDED(hr), "Failed to get DirectDraw4 interface, hr %#lx.\n", hr);
14297 IDirect3D3_Release(d3d);
14299 memset(&surface_desc, 0, sizeof(surface_desc));
14300 surface_desc.dwSize = sizeof(surface_desc);
14301 surface_desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_PIXELFORMAT;
14302 surface_desc.dwWidth = 640;
14303 surface_desc.dwHeight = 480;
14304 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_3DDEVICE;
14305 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
14306 surface_desc.ddpfPixelFormat.dwRGBBitCount = 32;
14307 surface_desc.ddpfPixelFormat.dwRBitMask = 0x00ff0000;
14308 surface_desc.ddpfPixelFormat.dwGBitMask = 0x0000ff00;
14309 surface_desc.ddpfPixelFormat.dwBBitMask = 0x000000ff;
14310 surface_desc.ddpfPixelFormat.dwRGBAlphaBitMask = 0xff000000;
14311 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &offscreen, NULL);
14312 ok(hr == D3D_OK, "Creating the offscreen render target failed, hr %#lx.\n", hr);
14314 ds = get_depth_stencil(device);
14315 hr = IDirectDrawSurface4_AddAttachedSurface(offscreen, ds);
14316 todo_wine ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#lx.\n", hr);
14317 IDirectDrawSurface4_Release(ds);
14319 hr = IDirect3DDevice3_SetRenderTarget(device, offscreen, 0);
14320 ok(SUCCEEDED(hr), "Failed to set render target, hr %#lx.\n", hr);
14322 viewport = create_viewport(device, 0, 0, 640, 480);
14323 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
14324 ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#lx.\n", hr);
14326 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &mat);
14327 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#lx.\n", hr);
14328 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_VIEW, &mat);
14329 ok(SUCCEEDED(hr), "Failed to set view transform, hr %#lx.\n", hr);
14330 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &mat);
14331 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#lx.\n", hr);
14332 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ZENABLE, FALSE);
14333 ok(SUCCEEDED(hr), "Failed to disable Z test, hr %#lx.\n", hr);
14334 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, FALSE);
14335 ok(SUCCEEDED(hr), "Failed to disable fog, hr %#lx.\n", hr);
14336 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_STENCILENABLE, FALSE);
14337 ok(SUCCEEDED(hr), "Failed to disable stencil test, hr %#lx.\n", hr);
14338 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_CULLMODE, D3DCULL_NONE);
14339 ok(SUCCEEDED(hr), "Failed to disable culling, hr %#lx.\n", hr);
14341 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);
14342 ok(SUCCEEDED(hr), "Failed to enable blending, hr %#lx.\n", hr);
14343 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);
14344 ok(SUCCEEDED(hr), "Failed to set src blend, hr %#lx.\n", hr);
14345 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_DESTBLEND, D3DBLEND_DESTALPHA);
14346 ok(SUCCEEDED(hr), "Failed to set dest blend, hr %#lx.\n", hr);
14348 hr = IDirect3DDevice3_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
14349 ok(SUCCEEDED(hr), "Failed to set color op, hr %#lx.\n", hr);
14350 hr = IDirect3DDevice3_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);
14351 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#lx.\n", hr);
14352 hr = IDirect3DDevice3_SetTextureStageState(device, 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
14353 ok(SUCCEEDED(hr), "Failed to set alpha op, hr %#lx.\n", hr);
14354 hr = IDirect3DDevice3_SetTextureStageState(device, 0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);
14355 ok(SUCCEEDED(hr), "Failed to set alpha arg, hr %#lx.\n", hr);
14357 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xccff0000, 0.0f, 0);
14358 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#lx.\n", hr);
14359 hr = IDirect3DDevice3_BeginScene(device);
14360 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#lx.\n", hr);
14361 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE,
14362 green_quad, 4, 0);
14363 ok(SUCCEEDED(hr), "Failed to draw, hr %#lx.\n", hr);
14364 hr = IDirect3DDevice3_EndScene(device);
14365 ok(SUCCEEDED(hr), "Failed to end scene, hr %#lx.\n", hr);
14366 color = get_surface_color(offscreen, 320, 240);
14367 ok(compare_color(color, 0x00cc7f00, 1), "Got unexpected color 0x%08x.\n", color);
14369 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0x7f00ff00, 0.0f, 0);
14370 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#lx.\n", hr);
14371 hr = IDirect3DDevice3_BeginScene(device);
14372 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#lx.\n", hr);
14373 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE,
14374 red_quad, 4, 0);
14375 ok(SUCCEEDED(hr), "Failed to draw, hr %#lx.\n", hr);
14376 hr = IDirect3DDevice3_EndScene(device);
14377 ok(SUCCEEDED(hr), "Failed to end scene, hr %#lx.\n", hr);
14378 color = get_surface_color(offscreen, 320, 240);
14379 ok(compare_color(color, 0x00cc7f00, 1), "Got unexpected color 0x%08x.\n", color);
14381 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, FALSE);
14382 ok(SUCCEEDED(hr), "Failed to disable blending, hr %#lx.\n", hr);
14384 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xccff0000, 0.0f, 0);
14385 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#lx.\n", hr);
14386 hr = IDirect3DDevice3_BeginScene(device);
14387 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#lx.\n", hr);
14388 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE,
14389 green_quad, 4, 0);
14390 ok(SUCCEEDED(hr), "Failed to draw, hr %#lx.\n", hr);
14391 hr = IDirect3DDevice3_EndScene(device);
14392 ok(SUCCEEDED(hr), "Failed to end scene, hr %#lx.\n", hr);
14393 color = get_surface_color(offscreen, 320, 240);
14394 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
14396 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0x7f00ff00, 0.0f, 0);
14397 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#lx.\n", hr);
14398 hr = IDirect3DDevice3_BeginScene(device);
14399 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#lx.\n", hr);
14400 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE,
14401 red_quad, 4, 0);
14402 ok(SUCCEEDED(hr), "Failed to draw, hr %#lx.\n", hr);
14403 hr = IDirect3DDevice3_EndScene(device);
14404 ok(SUCCEEDED(hr), "Failed to end scene, hr %#lx.\n", hr);
14405 color = get_surface_color(offscreen, 320, 240);
14406 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
14408 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_EDGEANTIALIAS, TRUE);
14409 ok(SUCCEEDED(hr), "Failed to enable edge antialiasing, hr %#lx.\n", hr);
14411 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xccff0000, 0.0f, 0);
14412 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#lx.\n", hr);
14413 hr = IDirect3DDevice3_BeginScene(device);
14414 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#lx.\n", hr);
14415 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE,
14416 green_quad, 4, 0);
14417 ok(SUCCEEDED(hr), "Failed to draw, hr %#lx.\n", hr);
14418 hr = IDirect3DDevice3_EndScene(device);
14419 ok(SUCCEEDED(hr), "Failed to end scene, hr %#lx.\n", hr);
14420 color = get_surface_color(offscreen, 320, 240);
14421 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
14423 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0x7f00ff00, 0.0f, 0);
14424 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#lx.\n", hr);
14425 hr = IDirect3DDevice3_BeginScene(device);
14426 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#lx.\n", hr);
14427 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE,
14428 red_quad, 4, 0);
14429 ok(SUCCEEDED(hr), "Failed to draw, hr %#lx.\n", hr);
14430 hr = IDirect3DDevice3_EndScene(device);
14431 ok(SUCCEEDED(hr), "Failed to end scene, hr %#lx.\n", hr);
14432 color = get_surface_color(offscreen, 320, 240);
14433 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
14435 IDirectDrawSurface4_Release(offscreen);
14436 IDirectDraw4_Release(ddraw);
14437 destroy_viewport(device, viewport);
14438 refcount = IDirect3DDevice3_Release(device);
14439 ok(!refcount, "Device has %lu references left.\n", refcount);
14440 DestroyWindow(window);
14443 /* TransformVertices always writes 32 bytes regardless of the input / output stride.
14444 * The stride is honored for navigating to the next vertex. 3 floats input position
14445 * are read, and 16 bytes extra vertex data are copied around. */
14446 struct transform_input
14448 float x, y, z, unused1; /* Position data, transformed. */
14449 DWORD v1, v2, v3, v4; /* Extra data, e.g. color and texture coords, copied. */
14450 DWORD unused2;
14453 struct transform_output
14455 float x, y, z, w;
14456 unsigned int v1, v2, v3, v4;
14457 unsigned int unused3, unused4;
14460 static void test_transform_vertices(void)
14462 IDirect3DDevice3 *device;
14463 IDirectDrawSurface4 *rt;
14464 unsigned int color;
14465 ULONG refcount;
14466 HWND window;
14467 HRESULT hr;
14468 IDirect3DViewport3 *viewport;
14469 static struct transform_input position_tests[] =
14471 { 0.0f, 0.0f, 0.0f, 0.0f, 1, 2, 3, 4, 5},
14472 { 1.0f, 1.0f, 1.0f, 8.0f, 6, 7, 8, 9, 10},
14473 {-1.0f, -1.0f, -1.0f, 4.0f, 11, 12, 13, 14, 15},
14474 { 0.5f, 0.5f, 0.5f, 2.0f, 16, 17, 18, 19, 20},
14475 {-0.5f, -0.5f, -0.5f, 1.0f, ~1U, ~2U, ~3U, ~4U, ~5U},
14476 {-0.5f, -0.5f, 0.0f, 0.0f, ~6U, ~7U, ~8U, ~9U, ~0U},
14478 static struct transform_input cliptest[] =
14480 { 25.59f, 25.59f, 1.0f, 0.0f, 1, 2, 3, 4, 5},
14481 { 25.61f, 25.61f, 1.01f, 0.0f, 1, 2, 3, 4, 5},
14482 {-25.59f, -25.59f, 0.0f, 0.0f, 1, 2, 3, 4, 5},
14483 {-25.61f, -25.61f, -0.01f, 0.0f, 1, 2, 3, 4, 5},
14485 static struct transform_input offscreentest[] =
14487 {128.1f, 0.0f, 0.0f, 0.0f, 1, 2, 3, 4, 5},
14489 struct transform_output out[ARRAY_SIZE(position_tests)];
14490 D3DHVERTEX out_h[ARRAY_SIZE(position_tests)];
14491 D3DTRANSFORMDATA transformdata;
14492 static const D3DVIEWPORT vp_template =
14494 sizeof(vp_template), 0, 0, 256, 256, 5.0f, 5.0f, 256.0f, 256.0f, -25.0f, 60.0f
14496 D3DVIEWPORT vp_data =
14498 sizeof(vp_data), 0, 0, 256, 256, 1.0f, 1.0f, 256.0f, 256.0f, 0.0f, 1.0f
14500 D3DVIEWPORT2 vp2_data;
14501 unsigned int i;
14502 DWORD offscreen;
14503 static D3DMATRIX mat_scale =
14505 2.0f, 0.0f, 0.0f, 0.0f,
14506 0.0f, 2.0f, 0.0f, 0.0f,
14507 0.0f, 0.0f, 2.0f, 0.0f,
14508 0.0f, 0.0f, 0.0f, 1.0f,
14510 mat_translate1 =
14512 1.0f, 0.0f, 0.0f, 0.0f,
14513 0.0f, 1.0f, 0.0f, 0.0f,
14514 0.0f, 0.0f, 1.0f, 0.0f,
14515 1.0f, 0.0f, 0.0f, 1.0f,
14517 mat_translate2 =
14519 1.0f, 0.0f, 0.0f, 0.0f,
14520 0.0f, 1.0f, 0.0f, 0.0f,
14521 0.0f, 0.0f, 1.0f, 0.0f,
14522 0.0f, 1.0f, 0.0f, 1.0f,
14524 mat_transform3 =
14526 1.0f, 0.0f, 0.0f, 0.0f,
14527 0.0f, 1.0f, 0.0f, 0.0f,
14528 0.0f, 0.0f, 1.0f, 0.0f,
14529 0.0f, 19.2f, 0.0f, 2.0f,
14531 mat_identity =
14533 1.0f, 0.0f, 0.0f, 0.0f,
14534 0.0f, 1.0f, 0.0f, 0.0f,
14535 0.0f, 0.0f, 1.0f, 0.0f,
14536 0.0f, 0.0f, 0.0f, 1.0f,
14538 static struct
14540 struct vec3 position;
14541 DWORD color;
14543 quad[] =
14545 {{-0.75f, -0.5f , 0.0f}, 0xffff0000},
14546 {{-0.75f, 0.25f, 0.0f}, 0xffff0000},
14547 {{ 0.5f, -0.5f , 0.0f}, 0xffff0000},
14548 {{ 0.5f, 0.25f, 0.0f}, 0xffff0000},
14550 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
14552 for (i = 0; i < ARRAY_SIZE(out); ++i)
14554 out[i].unused3 = 0xdeadbeef;
14555 out[i].unused4 = 0xcafecafe;
14558 window = create_window();
14559 if (!(device = create_device(window, DDSCL_NORMAL)))
14561 skip("Failed to create a 3D device.\n");
14562 DestroyWindow(window);
14563 return;
14565 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
14566 ok(SUCCEEDED(hr), "Failed to get render target, hr %#lx.\n", hr);
14568 viewport = create_viewport(device, 0, 0, 256, 256);
14569 hr = IDirect3DViewport2_SetViewport(viewport, &vp_data);
14570 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#lx.\n", hr);
14572 memset(&transformdata, 0, sizeof(transformdata));
14573 transformdata.dwSize = sizeof(transformdata);
14574 transformdata.lpIn = position_tests;
14575 transformdata.dwInSize = sizeof(position_tests[0]);
14576 transformdata.lpOut = out;
14577 transformdata.dwOutSize = sizeof(out[0]);
14578 transformdata.lpHOut = NULL;
14580 hr = IDirect3DViewport2_TransformVertices(viewport, ARRAY_SIZE(position_tests),
14581 &transformdata, D3DTRANSFORM_UNCLIPPED, &offscreen);
14582 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#lx.\n", hr);
14583 ok(!offscreen, "Offscreen is %#lx.\n", offscreen);
14585 for (i = 0; i < ARRAY_SIZE(position_tests); ++i)
14587 static const struct vec4 cmp[] =
14589 {128.0f, 128.0f, 0.0f, 1.0f}, {129.0f, 127.0f, 1.0f, 1.0f}, {127.0f, 129.0f, -1.0f, 1.0f},
14590 {128.5f, 127.5f, 0.5f, 1.0f}, {127.5f, 128.5f, -0.5f, 1.0f}, {127.5f, 128.5f, 0.0f, 1.0f}
14593 ok(compare_vec4(&cmp[i], out[i].x, out[i].y, out[i].z, out[i].w, 4096),
14594 "Vertex %u differs. Got %.8e %.8e %.8e %.8e.\n", i,
14595 out[i].x, out[i].y, out[i].z, out[i].w);
14596 ok(out[i].v1 == position_tests[i].v1 && out[i].v2 == position_tests[i].v2
14597 && out[i].v3 == position_tests[i].v3 && out[i].v4 == position_tests[i].v4,
14598 "Vertex %u payload is %u %u %u %u.\n", i, out[i].v1, out[i].v2, out[i].v3, out[i].v4);
14599 ok(out[i].unused3 == 0xdeadbeef && out[i].unused4 == 0xcafecafe,
14600 "Vertex %u unused data is %#x, %#x.\n", i, out[i].unused3, out[i].unused4);
14603 vp_data = vp_template;
14604 hr = IDirect3DViewport2_SetViewport(viewport, &vp_data);
14605 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#lx.\n", hr);
14606 offscreen = 0xdeadbeef;
14607 hr = IDirect3DViewport2_TransformVertices(viewport, ARRAY_SIZE(position_tests),
14608 &transformdata, D3DTRANSFORM_UNCLIPPED, &offscreen);
14609 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#lx.\n", hr);
14610 ok(!offscreen, "Offscreen is %#lx.\n", offscreen);
14612 for (i = 0; i < ARRAY_SIZE(position_tests); ++i)
14614 static const struct vec4 cmp[] =
14616 {128.0f, 128.0f, 0.0f, 1.0f}, {133.0f, 123.0f, 1.0f, 1.0f}, {123.0f, 133.0f, -1.0f, 1.0f},
14617 {130.5f, 125.5f, 0.5f, 1.0f}, {125.5f, 130.5f, -0.5f, 1.0f}, {125.5f, 130.5f, 0.0f, 1.0f}
14619 ok(compare_vec4(&cmp[i], out[i].x, out[i].y, out[i].z, out[i].w, 4096),
14620 "Vertex %u differs. Got %.8e %.8e %.8e %.8e.\n", i,
14621 out[i].x, out[i].y, out[i].z, out[i].w);
14624 vp_data.dwX = 10;
14625 vp_data.dwY = 20;
14626 hr = IDirect3DViewport2_SetViewport(viewport, &vp_data);
14627 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#lx.\n", hr);
14628 offscreen = 0xdeadbeef;
14629 hr = IDirect3DViewport2_TransformVertices(viewport, ARRAY_SIZE(position_tests),
14630 &transformdata, D3DTRANSFORM_UNCLIPPED, &offscreen);
14631 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#lx.\n", hr);
14632 ok(!offscreen, "Offscreen is %#lx.\n", offscreen);
14633 for (i = 0; i < ARRAY_SIZE(position_tests); ++i)
14635 static const struct vec4 cmp[] =
14637 {138.0f, 148.0f, 0.0f, 1.0f}, {143.0f, 143.0f, 1.0f, 1.0f}, {133.0f, 153.0f, -1.0f, 1.0f},
14638 {140.5f, 145.5f, 0.5f, 1.0f}, {135.5f, 150.5f, -0.5f, 1.0f}, {135.5f, 150.5f, 0.0f, 1.0f}
14640 ok(compare_vec4(&cmp[i], out[i].x, out[i].y, out[i].z, out[i].w, 4096),
14641 "Vertex %u differs. Got %.8e %.8e %.8e %.8e.\n", i,
14642 out[i].x, out[i].y, out[i].z, out[i].w);
14645 transformdata.lpHOut = out_h;
14646 offscreen = 0xdeadbeef;
14647 hr = IDirect3DViewport2_TransformVertices(viewport, ARRAY_SIZE(position_tests),
14648 &transformdata, D3DTRANSFORM_CLIPPED, &offscreen);
14649 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#lx.\n", hr);
14650 ok(!offscreen, "Offscreen is %#lx.\n", offscreen);
14651 for (i = 0; i < ARRAY_SIZE(position_tests); ++i)
14653 static const D3DHVERTEX cmp_h[] =
14655 {0, { 0.0f}, { 0.0f}, { 0.0f}}, {0, { 1.0f}, { 1.0f}, {1.0f}},
14656 {D3DCLIP_FRONT, {-1.0f}, {-1.0f}, {-1.0f}}, {0, { 0.5f}, { 0.5f}, {0.5f}},
14657 {D3DCLIP_FRONT, {-0.5f}, {-0.5f}, {-0.5f}}, {0, {-0.5f}, {-0.5f}, {0.0f}}
14659 ok(compare_float(cmp_h[i].hx, out_h[i].hx, 4096)
14660 && compare_float(cmp_h[i].hy, out_h[i].hy, 4096)
14661 && compare_float(cmp_h[i].hz, out_h[i].hz, 4096)
14662 && cmp_h[i].dwFlags == out_h[i].dwFlags,
14663 "HVertex %u differs. Got %#lx %.8e %.8e %.8e.\n", i,
14664 out_h[i].dwFlags, out_h[i].hx, out_h[i].hy, out_h[i].hz);
14666 /* No scheme has been found behind those return values. It seems to be
14667 * whatever data windows has when throwing the vertex away. Modify the
14668 * input test vertices to test this more. Depending on the input data
14669 * it can happen that the z coord gets written into y, or similar things. */
14670 if (0)
14672 static const struct vec4 cmp[] =
14674 {138.0f, 148.0f, 0.0f, 1.0f}, {143.0f, 143.0f, 1.0f, 1.0f}, { -1.0f, -1.0f, 0.5f, 1.0f},
14675 {140.5f, 145.5f, 0.5f, 1.0f}, { -0.5f, -0.5f, -0.5f, 1.0f}, {135.5f, 150.5f, 0.0f, 1.0f}
14677 ok(compare_vec4(&cmp[i], out[i].x, out[i].y, out[i].z, out[i].w, 4096),
14678 "Vertex %u differs. Got %.8e %.8e %.8e %.8e.\n", i,
14679 out[i].x, out[i].y, out[i].z, out[i].w);
14683 transformdata.lpIn = cliptest;
14684 transformdata.dwInSize = sizeof(cliptest[0]);
14685 offscreen = 0xdeadbeef;
14686 hr = IDirect3DViewport2_TransformVertices(viewport, ARRAY_SIZE(cliptest),
14687 &transformdata, D3DTRANSFORM_CLIPPED, &offscreen);
14688 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#lx.\n", hr);
14689 ok(!offscreen, "Offscreen is %#lx.\n", offscreen);
14690 for (i = 0; i < ARRAY_SIZE(cliptest); ++i)
14692 static const DWORD flags[] =
14695 D3DCLIP_RIGHT | D3DCLIP_BACK | D3DCLIP_TOP,
14697 D3DCLIP_LEFT | D3DCLIP_BOTTOM | D3DCLIP_FRONT,
14699 ok(flags[i] == out_h[i].dwFlags, "Cliptest %u returned %#lx.\n", i, out_h[i].dwFlags);
14702 vp_data = vp_template;
14703 vp_data.dwWidth = 10;
14704 vp_data.dwHeight = 480;
14705 hr = IDirect3DViewport2_SetViewport(viewport, &vp_data);
14706 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#lx.\n", hr);
14707 offscreen = 0xdeadbeef;
14708 hr = IDirect3DViewport2_TransformVertices(viewport, ARRAY_SIZE(cliptest),
14709 &transformdata, D3DTRANSFORM_CLIPPED, &offscreen);
14710 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#lx.\n", hr);
14711 ok(!offscreen, "Offscreen is %#lx.\n", offscreen);
14712 for (i = 0; i < ARRAY_SIZE(cliptest); ++i)
14714 static const DWORD flags[] =
14716 D3DCLIP_RIGHT,
14717 D3DCLIP_RIGHT | D3DCLIP_BACK,
14718 D3DCLIP_LEFT,
14719 D3DCLIP_LEFT | D3DCLIP_FRONT,
14721 ok(flags[i] == out_h[i].dwFlags, "Cliptest %u returned %#lx.\n", i, out_h[i].dwFlags);
14724 vp_data = vp_template;
14725 vp_data.dwWidth = 256;
14726 vp_data.dwHeight = 256;
14727 vp_data.dvScaleX = 1;
14728 vp_data.dvScaleY = 1;
14729 hr = IDirect3DViewport2_SetViewport(viewport, &vp_data);
14730 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#lx.\n", hr);
14731 hr = IDirect3DViewport2_TransformVertices(viewport, ARRAY_SIZE(cliptest),
14732 &transformdata, D3DTRANSFORM_CLIPPED, &offscreen);
14733 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#lx.\n", hr);
14734 ok(!offscreen, "Offscreen is %#lx.\n", offscreen);
14735 for (i = 0; i < ARRAY_SIZE(cliptest); ++i)
14737 static const DWORD flags[] =
14740 D3DCLIP_BACK,
14742 D3DCLIP_FRONT,
14744 ok(flags[i] == out_h[i].dwFlags, "Cliptest %u returned %#lx.\n", i, out_h[i].dwFlags);
14747 /* Finally try to figure out how the DWORD dwOffscreen works.
14748 * It is a logical AND of the vertices' dwFlags members. */
14749 vp_data = vp_template;
14750 vp_data.dwWidth = 5;
14751 vp_data.dwHeight = 5;
14752 vp_data.dvScaleX = 10000.0f;
14753 vp_data.dvScaleY = 10000.0f;
14754 hr = IDirect3DViewport2_SetViewport(viewport, &vp_data);
14755 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#lx.\n", hr);
14756 transformdata.lpIn = cliptest;
14757 offscreen = 0xdeadbeef;
14758 hr = IDirect3DViewport2_TransformVertices(viewport, 1,
14759 &transformdata, D3DTRANSFORM_UNCLIPPED, &offscreen);
14760 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#lx.\n", hr);
14761 ok(!offscreen, "Offscreen is %#lx.\n", offscreen);
14763 offscreen = 0xdeadbeef;
14764 hr = IDirect3DViewport2_TransformVertices(viewport, 1,
14765 &transformdata, D3DTRANSFORM_CLIPPED, &offscreen);
14766 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#lx.\n", hr);
14767 ok(offscreen == (D3DCLIP_RIGHT | D3DCLIP_TOP), "Offscreen is %#lx.\n", offscreen);
14768 offscreen = 0xdeadbeef;
14769 hr = IDirect3DViewport2_TransformVertices(viewport, 2,
14770 &transformdata, D3DTRANSFORM_CLIPPED, &offscreen);
14771 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#lx.\n", hr);
14772 ok(offscreen == (D3DCLIP_RIGHT | D3DCLIP_TOP), "Offscreen is %#lx.\n", offscreen);
14773 hr = IDirect3DViewport2_TransformVertices(viewport, 3,
14774 &transformdata, D3DTRANSFORM_CLIPPED, &offscreen);
14775 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#lx.\n", hr);
14776 ok(!offscreen, "Offscreen is %#lx.\n", offscreen);
14778 transformdata.lpIn = cliptest + 1;
14779 hr = IDirect3DViewport2_TransformVertices(viewport, 1,
14780 &transformdata, D3DTRANSFORM_CLIPPED, &offscreen);
14781 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#lx.\n", hr);
14782 ok(offscreen == (D3DCLIP_BACK | D3DCLIP_RIGHT | D3DCLIP_TOP), "Offscreen is %#lx.\n", offscreen);
14784 transformdata.lpIn = cliptest + 2;
14785 hr = IDirect3DViewport2_TransformVertices(viewport, 1,
14786 &transformdata, D3DTRANSFORM_CLIPPED, &offscreen);
14787 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#lx.\n", hr);
14788 ok(offscreen == (D3DCLIP_BOTTOM | D3DCLIP_LEFT), "Offscreen is %#lx.\n", offscreen);
14789 offscreen = 0xdeadbeef;
14790 hr = IDirect3DViewport2_TransformVertices(viewport, 2,
14791 &transformdata, D3DTRANSFORM_CLIPPED, &offscreen);
14792 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#lx.\n", hr);
14793 ok(offscreen == (D3DCLIP_BOTTOM | D3DCLIP_LEFT), "Offscreen is %#lx.\n", offscreen);
14795 transformdata.lpIn = cliptest + 3;
14796 hr = IDirect3DViewport2_TransformVertices(viewport, 1,
14797 &transformdata, D3DTRANSFORM_CLIPPED, &offscreen);
14798 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#lx.\n", hr);
14799 ok(offscreen == (D3DCLIP_FRONT | D3DCLIP_BOTTOM | D3DCLIP_LEFT), "Offscreen is %#lx.\n", offscreen);
14801 transformdata.lpIn = offscreentest;
14802 transformdata.dwInSize = sizeof(offscreentest[0]);
14803 vp_data = vp_template;
14804 vp_data.dwWidth = 257;
14805 vp_data.dwHeight = 257;
14806 vp_data.dvScaleX = 1.0f;
14807 vp_data.dvScaleY = 1.0f;
14808 hr = IDirect3DViewport2_SetViewport(viewport, &vp_data);
14809 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#lx.\n", hr);
14810 offscreen = 0xdeadbeef;
14811 hr = IDirect3DViewport2_TransformVertices(viewport, 1,
14812 &transformdata, D3DTRANSFORM_CLIPPED, &offscreen);
14813 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#lx.\n", hr);
14814 ok(!offscreen, "Offscreen is %#lx.\n", offscreen);
14816 vp_data.dwWidth = 256;
14817 vp_data.dwHeight = 256;
14818 hr = IDirect3DViewport2_SetViewport(viewport, &vp_data);
14819 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#lx.\n", hr);
14820 hr = IDirect3DViewport2_TransformVertices(viewport, 1,
14821 &transformdata, D3DTRANSFORM_CLIPPED, &offscreen);
14822 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#lx.\n", hr);
14823 ok(offscreen == D3DCLIP_RIGHT, "Offscreen is %#lx.\n", offscreen);
14825 /* Test the effect of Matrices.
14827 * Basically the x coordinate ends up as ((x + 1) * 2 + 0) * 5 and
14828 * y as ((y + 0) * 2 + 1) * 5. The 5 comes from dvScaleX/Y, 2 from
14829 * the view matrix and the +1's from the world and projection matrix. */
14830 vp_data.dwX = 0;
14831 vp_data.dwY = 0;
14832 vp_data.dwWidth = 256;
14833 vp_data.dwHeight = 256;
14834 vp_data.dvScaleX = 5.0f;
14835 vp_data.dvScaleY = 5.0f;
14836 vp_data.dvMinZ = 0.0f;
14837 vp_data.dvMaxZ = 1.0f;
14838 hr = IDirect3DViewport2_SetViewport(viewport, &vp_data);
14839 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#lx.\n", hr);
14841 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &mat_translate1);
14842 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#lx.\n", hr);
14843 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_VIEW, &mat_scale);
14844 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#lx.\n", hr);
14845 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &mat_translate2);
14846 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#lx.\n", hr);
14848 transformdata.lpIn = position_tests;
14849 transformdata.dwInSize = sizeof(position_tests[0]);
14850 hr = IDirect3DViewport2_TransformVertices(viewport, ARRAY_SIZE(position_tests),
14851 &transformdata, D3DTRANSFORM_UNCLIPPED, &offscreen);
14852 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#lx.\n", hr);
14854 for (i = 0; i < ARRAY_SIZE(position_tests); ++i)
14856 static const struct vec4 cmp[] =
14858 {138.0f, 123.0f, 0.0f, 1.0f}, {148.0f, 113.0f, 2.0f, 1.0f}, {128.0f, 133.0f, -2.0f, 1.0f},
14859 {143.0f, 118.0f, 1.0f, 1.0f}, {133.0f, 128.0f, -1.0f, 1.0f}, {133.0f, 128.0f, 0.0f, 1.0f}
14862 ok(compare_vec4(&cmp[i], out[i].x, out[i].y, out[i].z, out[i].w, 4096),
14863 "Vertex %u differs. Got %.8e %.8e %.8e %.8e.\n", i,
14864 out[i].x, out[i].y, out[i].z, out[i].w);
14867 /* Invalid flags. */
14868 offscreen = 0xdeadbeef;
14869 hr = IDirect3DViewport2_TransformVertices(viewport, ARRAY_SIZE(position_tests),
14870 &transformdata, 0, &offscreen);
14871 ok(hr == DDERR_INVALIDPARAMS, "Got hr %#lx.\n", hr);
14872 ok(offscreen == 0xdeadbeef, "Offscreen is %#lx.\n", offscreen);
14874 /* NULL transform data. */
14875 hr = IDirect3DViewport2_TransformVertices(viewport, 1,
14876 NULL, D3DTRANSFORM_UNCLIPPED, &offscreen);
14877 ok(hr == DDERR_INVALIDPARAMS, "Got hr %#lx.\n", hr);
14878 ok(offscreen == 0xdeadbeef, "Offscreen is %#lx.\n", offscreen);
14879 hr = IDirect3DViewport2_TransformVertices(viewport, 0,
14880 NULL, D3DTRANSFORM_UNCLIPPED, &offscreen);
14881 ok(hr == DDERR_INVALIDPARAMS, "Got hr %#lx.\n", hr);
14882 ok(offscreen == 0xdeadbeef, "Offscreen is %#lx.\n", offscreen);
14884 /* NULL transform data and NULL dwOffscreen.
14886 * Valid transform data + NULL dwOffscreen -> crash. */
14887 hr = IDirect3DViewport2_TransformVertices(viewport, 1,
14888 NULL, D3DTRANSFORM_UNCLIPPED, NULL);
14889 ok(hr == DDERR_INVALIDPARAMS, "Got hr %#lx.\n", hr);
14891 /* No vertices. */
14892 hr = IDirect3DViewport2_TransformVertices(viewport, 0,
14893 &transformdata, D3DTRANSFORM_UNCLIPPED, &offscreen);
14894 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#lx.\n", hr);
14895 ok(!offscreen, "Offscreen is %#lx.\n", offscreen);
14896 hr = IDirect3DViewport2_TransformVertices(viewport, 0,
14897 &transformdata, D3DTRANSFORM_CLIPPED, &offscreen);
14898 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#lx.\n", hr);
14899 ok(offscreen == ~0u, "Offscreen is %#lx.\n", offscreen);
14901 /* Invalid sizes. */
14902 offscreen = 0xdeadbeef;
14903 transformdata.dwSize = sizeof(transformdata) - 1;
14904 hr = IDirect3DViewport2_TransformVertices(viewport, 1,
14905 &transformdata, D3DTRANSFORM_UNCLIPPED, &offscreen);
14906 ok(hr == DDERR_INVALIDPARAMS, "Got hr %#lx.\n", hr);
14907 ok(offscreen == 0xdeadbeef, "Offscreen is %#lx.\n", offscreen);
14908 transformdata.dwSize = sizeof(transformdata) + 1;
14909 hr = IDirect3DViewport2_TransformVertices(viewport, 1,
14910 &transformdata, D3DTRANSFORM_UNCLIPPED, &offscreen);
14911 ok(hr == DDERR_INVALIDPARAMS, "Got hr %#lx.\n", hr);
14912 ok(offscreen == 0xdeadbeef, "Offscreen is %#lx.\n", offscreen);
14914 /* NULL lpIn or lpOut -> crash, except when transforming 0 vertices. */
14915 transformdata.dwSize = sizeof(transformdata);
14916 transformdata.lpIn = NULL;
14917 transformdata.lpOut = NULL;
14918 offscreen = 0xdeadbeef;
14919 hr = IDirect3DViewport2_TransformVertices(viewport, 0,
14920 &transformdata, D3DTRANSFORM_CLIPPED, &offscreen);
14921 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#lx.\n", hr);
14922 ok(offscreen == ~0u, "Offscreen is %#lx.\n", offscreen);
14924 /* Test how vertices are transformed during draws. */
14925 vp_data.dwX = 20;
14926 vp_data.dwY = 20;
14927 vp_data.dwWidth = 200;
14928 vp_data.dwHeight = 400;
14929 vp_data.dvScaleX = 20.0f;
14930 vp_data.dvScaleY = 50.0f;
14931 vp_data.dvMinZ = 0.0f;
14932 vp_data.dvMaxZ = 1.0f;
14933 hr = IDirect3DViewport3_SetViewport(viewport, &vp_data);
14934 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#lx.\n", hr);
14935 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
14936 ok(SUCCEEDED(hr), "Failed to activate the viewport, hr %#lx.\n", hr);
14938 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0x000000ff, 0.0f, 0);
14939 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#lx.\n", hr);
14941 hr = IDirect3DDevice3_BeginScene(device);
14942 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#lx.\n", hr);
14943 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE,
14944 quad, 4, 0);
14945 ok(SUCCEEDED(hr), "Failed to draw, hr %#lx.\n", hr);
14946 hr = IDirect3DDevice3_EndScene(device);
14947 ok(SUCCEEDED(hr), "Failed to end scene, hr %#lx.\n", hr);
14949 color = get_surface_color(rt, 128, 143);
14950 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
14951 color = get_surface_color(rt, 132, 143);
14952 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
14953 color = get_surface_color(rt, 128, 147);
14954 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
14955 color = get_surface_color(rt, 132, 147);
14956 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
14958 color = get_surface_color(rt, 177, 217);
14959 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
14960 color = get_surface_color(rt, 181, 217);
14961 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
14962 color = get_surface_color(rt, 177, 221);
14963 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
14964 color = get_surface_color(rt, 181, 221);
14965 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
14967 /* Test D3DVIEWPORT2 behavior. */
14968 vp2_data.dwSize = sizeof(vp2_data);
14969 vp2_data.dwX = 20;
14970 vp2_data.dwY = 20;
14971 vp2_data.dwWidth = 200;
14972 vp2_data.dwHeight = 400;
14973 vp2_data.dvClipX = -0.5f;
14974 vp2_data.dvClipY = 4.0f;
14975 vp2_data.dvClipWidth = 5.0f;
14976 vp2_data.dvClipHeight = 10.0f;
14977 vp2_data.dvMinZ = 0.0f;
14978 vp2_data.dvMaxZ = 2.0f;
14979 hr = IDirect3DViewport3_SetViewport2(viewport, &vp2_data);
14980 ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#lx.\n", hr);
14981 transformdata.lpIn = position_tests;
14982 transformdata.lpOut = out;
14983 hr = IDirect3DViewport3_TransformVertices(viewport, ARRAY_SIZE(position_tests),
14984 &transformdata, D3DTRANSFORM_UNCLIPPED, &offscreen);
14985 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#lx.\n", hr);
14986 for (i = 0; i < ARRAY_SIZE(position_tests); ++i)
14988 static const struct vec4 cmp[] =
14990 {120.0f, 140.0f, 0.0f, 1.0f}, {200.0f, 60.0f, 1.0f, 1.0f}, {40.0f, 220.0f, -1.0f, 1.0f},
14991 {160.0f, 100.0f, 0.5f, 1.0f}, { 80.0f, 180.0f, -0.5f, 1.0f}, {80.0f, 180.0f, 0.0f, 1.0f}
14994 ok(compare_vec4(&cmp[i], out[i].x, out[i].y, out[i].z, out[i].w, 4096),
14995 "Vertex %u differs. Got %.8e %.8e %.8e %.8e.\n", i,
14996 out[i].x, out[i].y, out[i].z, out[i].w);
14999 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0x0000ff00, 0.0f, 0);
15000 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#lx.\n", hr);
15002 hr = IDirect3DDevice3_BeginScene(device);
15003 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#lx.\n", hr);
15004 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE,
15005 quad, 4, 0);
15006 ok(SUCCEEDED(hr), "Failed to draw, hr %#lx.\n", hr);
15007 hr = IDirect3DDevice3_EndScene(device);
15008 ok(SUCCEEDED(hr), "Failed to end scene, hr %#lx.\n", hr);
15010 color = get_surface_color(rt, 58, 118);
15011 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
15012 color = get_surface_color(rt, 62, 118);
15013 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
15014 color = get_surface_color(rt, 58, 122);
15015 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
15016 color = get_surface_color(rt, 62, 122);
15017 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
15019 color = get_surface_color(rt, 157, 177);
15020 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
15021 color = get_surface_color(rt, 161, 177);
15022 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
15023 color = get_surface_color(rt, 157, 181);
15024 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
15025 color = get_surface_color(rt, 161, 181);
15026 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
15028 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &mat_identity);
15029 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#lx.\n", hr);
15030 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_VIEW, &mat_identity);
15031 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#lx.\n", hr);
15032 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &mat_transform3);
15033 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#lx.\n", hr);
15035 vp2_data.dwX = 0.0;
15036 vp2_data.dwY = 0.0;
15037 vp2_data.dwWidth = 1;
15038 vp2_data.dwHeight = 1;
15039 vp2_data.dvClipX = -12.8f;
15040 vp2_data.dvClipY = 12.8f + mat_transform3._42 / mat_transform3._44;
15041 vp2_data.dvClipWidth = 25.6f;
15042 vp2_data.dvClipHeight = 25.6f;
15043 vp2_data.dvMinZ = 0.0f;
15044 vp2_data.dvMaxZ = 0.5f;
15045 hr = IDirect3DViewport3_SetViewport2(viewport, &vp2_data);
15046 ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#lx.\n", hr);
15047 transformdata.lpIn = cliptest;
15048 transformdata.dwInSize = sizeof(cliptest[0]);
15049 offscreen = 0xdeadbeef;
15050 hr = IDirect3DViewport3_TransformVertices(viewport, ARRAY_SIZE(cliptest),
15051 &transformdata, D3DTRANSFORM_CLIPPED, &offscreen);
15052 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#lx.\n", hr);
15053 ok(!offscreen, "Offscreen is %#lx.\n", offscreen);
15054 for (i = 0; i < ARRAY_SIZE(cliptest); ++i)
15056 static const D3DHVERTEX cmp_h[] =
15058 {0, { 25.59f}, { 44.79f}, { 1.0f }},
15059 {D3DCLIP_RIGHT | D3DCLIP_TOP | D3DCLIP_BACK, { 25.61f}, { 44.81f}, { 1.01f}},
15060 {0, {-25.59f}, {-6.39f }, { 0.0f }},
15061 {D3DCLIP_LEFT | D3DCLIP_BOTTOM | D3DCLIP_FRONT,{-25.61f}, {-6.41f }, {-0.01f}},
15063 ok(compare_float(cmp_h[i].hx, out_h[i].hx, 4096)
15064 && compare_float(cmp_h[i].hy, out_h[i].hy, 4096)
15065 && compare_float(cmp_h[i].hz, out_h[i].hz, 4096)
15066 && cmp_h[i].dwFlags == out_h[i].dwFlags,
15067 "HVertex %u differs. Got %#lx %.8e %.8e %.8e.\n", i,
15068 out_h[i].dwFlags, out_h[i].hx, out_h[i].hy, out_h[i].hz);
15071 destroy_viewport(device, viewport);
15072 IDirectDrawSurface4_Release(rt);
15073 refcount = IDirect3DDevice3_Release(device);
15074 ok(!refcount, "Device has %lu references left.\n", refcount);
15075 DestroyWindow(window);
15078 static void test_display_mode_surface_pixel_format(void)
15080 unsigned int width, height, bpp;
15081 IDirectDrawSurface4 *surface;
15082 DDSURFACEDESC2 surface_desc;
15083 IDirectDraw4 *ddraw;
15084 ULONG refcount;
15085 HWND window;
15086 HRESULT hr;
15088 if (!(ddraw = create_ddraw()))
15090 skip("Failed to create ddraw.\n");
15091 return;
15094 surface_desc.dwSize = sizeof(surface_desc);
15095 hr = IDirectDraw4_GetDisplayMode(ddraw, &surface_desc);
15096 ok(SUCCEEDED(hr), "Failed to get display mode, hr %#lx.\n", hr);
15097 width = surface_desc.dwWidth;
15098 height = surface_desc.dwHeight;
15100 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
15101 0, 0, width, height, NULL, NULL, NULL, NULL);
15102 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
15103 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
15105 bpp = 0;
15106 if (SUCCEEDED(IDirectDraw4_SetDisplayMode(ddraw, width, height, 16, 0, 0)))
15107 bpp = 16;
15108 if (SUCCEEDED(IDirectDraw4_SetDisplayMode(ddraw, width, height, 24, 0, 0)))
15109 bpp = 24;
15110 if (SUCCEEDED(IDirectDraw4_SetDisplayMode(ddraw, width, height, 32, 0, 0)))
15111 bpp = 32;
15112 ok(bpp, "Set display mode failed.\n");
15114 surface_desc.dwSize = sizeof(surface_desc);
15115 hr = IDirectDraw4_GetDisplayMode(ddraw, &surface_desc);
15116 ok(SUCCEEDED(hr), "Failed to get display mode, hr %#lx.\n", hr);
15117 ok(surface_desc.dwWidth == width, "Got width %lu, expected %u.\n", surface_desc.dwWidth, width);
15118 ok(surface_desc.dwHeight == height, "Got height %lu, expected %u.\n", surface_desc.dwHeight, height);
15119 ok(surface_desc.ddpfPixelFormat.dwRGBBitCount == bpp, "Got bpp %lu, expected %u.\n",
15120 surface_desc.ddpfPixelFormat.dwRGBBitCount, bpp);
15122 memset(&surface_desc, 0, sizeof(surface_desc));
15123 surface_desc.dwSize = sizeof(surface_desc);
15124 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
15125 surface_desc.dwBackBufferCount = 1;
15126 surface_desc.ddsCaps.dwCaps = DDSCAPS_COMPLEX | DDSCAPS_FLIP | DDSCAPS_PRIMARYSURFACE;
15127 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
15128 ok(hr == D3D_OK, "Failed to create surface, hr %#lx.\n", hr);
15129 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &surface_desc);
15130 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#lx.\n", hr);
15131 ok(surface_desc.dwWidth == width, "Got width %lu, expected %u.\n", surface_desc.dwWidth, width);
15132 ok(surface_desc.dwHeight == height, "Got height %lu, expected %u.\n", surface_desc.dwHeight, height);
15133 ok(surface_desc.ddpfPixelFormat.dwFlags == DDPF_RGB, "Got unexpected pixel format flags %#lx.\n",
15134 surface_desc.ddpfPixelFormat.dwFlags);
15135 ok(surface_desc.ddpfPixelFormat.dwRGBBitCount == bpp, "Got bpp %lu, expected %u.\n",
15136 surface_desc.ddpfPixelFormat.dwRGBBitCount, bpp);
15137 IDirectDrawSurface4_Release(surface);
15139 memset(&surface_desc, 0, sizeof(surface_desc));
15140 surface_desc.dwSize = sizeof(surface_desc);
15141 surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
15142 surface_desc.dwWidth = width;
15143 surface_desc.dwHeight = height;
15144 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
15145 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
15146 ok(hr == D3D_OK, "Failed to create surface, hr %#lx.\n", hr);
15147 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &surface_desc);
15148 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#lx.\n", hr);
15149 ok(surface_desc.ddpfPixelFormat.dwFlags == DDPF_RGB, "Got unexpected pixel format flags %#lx.\n",
15150 surface_desc.ddpfPixelFormat.dwFlags);
15151 ok(surface_desc.ddpfPixelFormat.dwRGBBitCount == bpp, "Got bpp %lu, expected %u.\n",
15152 surface_desc.ddpfPixelFormat.dwRGBBitCount, bpp);
15153 IDirectDrawSurface4_Release(surface);
15155 refcount = IDirectDraw4_Release(ddraw);
15156 ok(!refcount, "DirectDraw has %lu references left.\n", refcount);
15157 DestroyWindow(window);
15160 static void test_surface_desc_size(void)
15162 union
15164 DWORD dwSize;
15165 DDSURFACEDESC desc1;
15166 DDSURFACEDESC2 desc2;
15167 BYTE blob[1024];
15168 } desc;
15169 IDirectDrawSurface4 *surface4;
15170 IDirectDrawSurface3 *surface3;
15171 IDirectDrawSurface *surface;
15172 DDSURFACEDESC2 surface_desc;
15173 HRESULT expected_hr, hr;
15174 IDirectDraw4 *ddraw;
15175 unsigned int i, j;
15176 ULONG refcount;
15178 static const struct
15180 unsigned int caps;
15181 const char *name;
15183 surface_caps[] =
15185 {DDSCAPS_OFFSCREENPLAIN, "offscreenplain"},
15186 {DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, "systemmemory texture"},
15187 {DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, "videomemory texture"},
15189 static const unsigned int desc_sizes[] =
15191 sizeof(DDSURFACEDESC),
15192 sizeof(DDSURFACEDESC2),
15193 sizeof(DDSURFACEDESC) + 1,
15194 sizeof(DDSURFACEDESC2) + 1,
15195 2 * sizeof(DDSURFACEDESC),
15196 2 * sizeof(DDSURFACEDESC2),
15197 sizeof(DDSURFACEDESC) - 1,
15198 sizeof(DDSURFACEDESC2) - 1,
15199 sizeof(DDSURFACEDESC) / 2,
15200 sizeof(DDSURFACEDESC2) / 2,
15204 sizeof(desc) / 2,
15205 sizeof(desc) - 100,
15208 if (!(ddraw = create_ddraw()))
15210 skip("Failed to create ddraw.\n");
15211 return;
15213 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
15214 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
15216 for (i = 0; i < ARRAY_SIZE(surface_caps); ++i)
15218 memset(&surface_desc, 0, sizeof(surface_desc));
15219 surface_desc.dwSize = sizeof(surface_desc);
15220 surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
15221 surface_desc.ddsCaps.dwCaps = surface_caps[i].caps;
15222 surface_desc.dwHeight = 128;
15223 surface_desc.dwWidth = 128;
15224 if (FAILED(IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface4, NULL)))
15226 skip("Failed to create surface, type %s.\n", surface_caps[i].name);
15227 continue;
15229 hr = IDirectDrawSurface_QueryInterface(surface4, &IID_IDirectDrawSurface, (void **)&surface);
15230 ok(hr == DD_OK, "Failed to query IDirectDrawSurface, hr %#lx, type %s.\n", hr, surface_caps[i].name);
15231 hr = IDirectDrawSurface_QueryInterface(surface4, &IID_IDirectDrawSurface3, (void **)&surface3);
15232 ok(hr == DD_OK, "Failed to query IDirectDrawSurface3, hr %#lx, type %s.\n", hr, surface_caps[i].name);
15234 /* GetSurfaceDesc() */
15235 for (j = 0; j < ARRAY_SIZE(desc_sizes); ++j)
15237 memset(&desc, 0, sizeof(desc));
15238 desc.dwSize = desc_sizes[j];
15239 expected_hr = desc.dwSize == sizeof(DDSURFACEDESC) ? DD_OK : DDERR_INVALIDPARAMS;
15240 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &desc.desc1);
15241 ok(hr == expected_hr, "Got hr %#lx, expected %#lx, size %u, type %s.\n",
15242 hr, expected_hr, desc_sizes[j], surface_caps[i].name);
15244 memset(&desc, 0, sizeof(desc));
15245 desc.dwSize = desc_sizes[j];
15246 expected_hr = desc.dwSize == sizeof(DDSURFACEDESC) ? DD_OK : DDERR_INVALIDPARAMS;
15247 hr = IDirectDrawSurface3_GetSurfaceDesc(surface3, &desc.desc1);
15248 ok(hr == expected_hr, "Got hr %#lx, expected %#lx, size %u, type %s.\n",
15249 hr, expected_hr, desc_sizes[j], surface_caps[i].name);
15251 memset(&desc, 0, sizeof(desc));
15252 desc.dwSize = desc_sizes[j];
15253 expected_hr = desc.dwSize == sizeof(DDSURFACEDESC2) ? DD_OK : DDERR_INVALIDPARAMS;
15254 hr = IDirectDrawSurface4_GetSurfaceDesc(surface4, &desc.desc2);
15255 ok(hr == expected_hr, "Got hr %#lx, expected %#lx, size %u, type %s.\n",
15256 hr, expected_hr, desc_sizes[j], surface_caps[i].name);
15259 /* Lock() */
15260 for (j = 0; j < ARRAY_SIZE(desc_sizes); ++j)
15262 const BOOL valid_size = desc_sizes[j] == sizeof(DDSURFACEDESC)
15263 || desc_sizes[j] == sizeof(DDSURFACEDESC2);
15264 DWORD expected_texture_stage;
15266 memset(&desc, 0, sizeof(desc));
15267 desc.dwSize = desc_sizes[j];
15268 desc.desc2.dwTextureStage = 0xdeadbeef;
15269 desc.blob[sizeof(DDSURFACEDESC2)] = 0xef;
15270 hr = IDirectDrawSurface_Lock(surface, NULL, &desc.desc1, 0, 0);
15271 expected_hr = valid_size ? DD_OK : DDERR_INVALIDPARAMS;
15272 ok(hr == expected_hr, "Got hr %#lx, expected %#lx, size %u, type %s.\n",
15273 hr, expected_hr, desc_sizes[j], surface_caps[i].name);
15274 ok(desc.dwSize == desc_sizes[j], "dwSize was changed from %u to %lu, type %s.\n",
15275 desc_sizes[j], desc.dwSize, surface_caps[i].name);
15276 ok(desc.blob[sizeof(DDSURFACEDESC2)] == 0xef, "Got unexpected byte %02x, size %u, type %s.\n",
15277 desc.blob[sizeof(DDSURFACEDESC2)], desc_sizes[j], surface_caps[i].name);
15278 if (SUCCEEDED(hr))
15280 ok(desc.desc1.dwWidth == 128, "Got unexpected width %lu, size %u, type %s.\n",
15281 desc.desc1.dwWidth, desc_sizes[j], surface_caps[i].name);
15282 ok(desc.desc1.dwHeight == 128, "Got unexpected height %lu, size %u, type %s.\n",
15283 desc.desc1.dwHeight, desc_sizes[j], surface_caps[i].name);
15284 expected_texture_stage = desc_sizes[j] >= sizeof(DDSURFACEDESC2) ? 0 : 0xdeadbeef;
15285 todo_wine_if(!expected_texture_stage)
15286 ok(desc.desc2.dwTextureStage == expected_texture_stage,
15287 "Got unexpected texture stage %#lx, size %u, type %s.\n",
15288 desc.desc2.dwTextureStage, desc_sizes[j], surface_caps[i].name);
15289 IDirectDrawSurface_Unlock(surface, NULL);
15292 memset(&desc, 0, sizeof(desc));
15293 desc.dwSize = desc_sizes[j];
15294 desc.desc2.dwTextureStage = 0xdeadbeef;
15295 desc.blob[sizeof(DDSURFACEDESC2)] = 0xef;
15296 hr = IDirectDrawSurface3_Lock(surface3, NULL, &desc.desc1, 0, 0);
15297 expected_hr = valid_size ? DD_OK : DDERR_INVALIDPARAMS;
15298 ok(hr == expected_hr, "Got hr %#lx, expected %#lx, size %u, type %s.\n",
15299 hr, expected_hr, desc_sizes[j], surface_caps[i].name);
15300 ok(desc.dwSize == desc_sizes[j], "dwSize was changed from %u to %lu, type %s.\n",
15301 desc_sizes[j], desc.dwSize, surface_caps[i].name);
15302 ok(desc.blob[sizeof(DDSURFACEDESC2)] == 0xef, "Got unexpected byte %02x, size %u, type %s.\n",
15303 desc.blob[sizeof(DDSURFACEDESC2)], desc_sizes[j], surface_caps[i].name);
15304 if (SUCCEEDED(hr))
15306 ok(desc.desc1.dwWidth == 128, "Got unexpected width %lu, size %u, type %s.\n",
15307 desc.desc1.dwWidth, desc_sizes[j], surface_caps[i].name);
15308 ok(desc.desc1.dwHeight == 128, "Got unexpected height %lu, size %u, type %s.\n",
15309 desc.desc1.dwHeight, desc_sizes[j], surface_caps[i].name);
15310 expected_texture_stage = desc_sizes[j] >= sizeof(DDSURFACEDESC2) ? 0 : 0xdeadbeef;
15311 todo_wine_if(!expected_texture_stage)
15312 ok(desc.desc2.dwTextureStage == expected_texture_stage,
15313 "Got unexpected texture stage %#lx, size %u, type %s.\n",
15314 desc.desc2.dwTextureStage, desc_sizes[j], surface_caps[i].name);
15315 IDirectDrawSurface3_Unlock(surface3, NULL);
15318 memset(&desc, 0, sizeof(desc));
15319 desc.dwSize = desc_sizes[j];
15320 desc.desc2.dwTextureStage = 0xdeadbeef;
15321 desc.blob[sizeof(DDSURFACEDESC2)] = 0xef;
15322 hr = IDirectDrawSurface4_Lock(surface4, NULL, &desc.desc2, 0, 0);
15323 expected_hr = valid_size ? DD_OK : DDERR_INVALIDPARAMS;
15324 ok(hr == expected_hr, "Got hr %#lx, expected %#lx, size %u, type %s.\n",
15325 hr, expected_hr, desc_sizes[j], surface_caps[i].name);
15326 ok(desc.dwSize == desc_sizes[j], "dwSize was changed from %u to %lu, type %s.\n",
15327 desc_sizes[j], desc.dwSize, surface_caps[i].name);
15328 ok(desc.blob[sizeof(DDSURFACEDESC2)] == 0xef, "Got unexpected byte %02x, size %u, type %s.\n",
15329 desc.blob[sizeof(DDSURFACEDESC2)], desc_sizes[j], surface_caps[i].name);
15330 if (SUCCEEDED(hr))
15332 ok(desc.desc2.dwWidth == 128, "Got unexpected width %lu, size %u, type %s.\n",
15333 desc.desc2.dwWidth, desc_sizes[j], surface_caps[i].name);
15334 ok(desc.desc2.dwHeight == 128, "Got unexpected height %lu, size %u, type %s.\n",
15335 desc.desc2.dwHeight, desc_sizes[j], surface_caps[i].name);
15336 expected_texture_stage = desc_sizes[j] >= sizeof(DDSURFACEDESC2) ? 0 : 0xdeadbeef;
15337 ok(desc.desc2.dwTextureStage == expected_texture_stage,
15338 "Got unexpected texture stage %#lx, size %u, type %s.\n",
15339 desc.desc2.dwTextureStage, desc_sizes[j], surface_caps[i].name);
15340 IDirectDrawSurface4_Unlock(surface4, NULL);
15344 IDirectDrawSurface4_Release(surface4);
15345 IDirectDrawSurface3_Release(surface3);
15346 IDirectDrawSurface_Release(surface);
15349 /* GetDisplayMode() */
15350 for (j = 0; j < ARRAY_SIZE(desc_sizes); ++j)
15352 memset(&desc, 0xcc, sizeof(desc));
15353 desc.dwSize = desc_sizes[j];
15354 expected_hr = (desc.dwSize == sizeof(DDSURFACEDESC) || desc.dwSize == sizeof(DDSURFACEDESC2))
15355 ? DD_OK : DDERR_INVALIDPARAMS;
15356 hr = IDirectDraw4_GetDisplayMode(ddraw, &desc.desc2);
15357 ok(hr == expected_hr, "Got hr %#lx, expected %#lx, size %u.\n", hr, expected_hr, desc_sizes[j]);
15358 if (SUCCEEDED(hr))
15360 ok(desc.dwSize == sizeof(DDSURFACEDESC2), "Wrong size %lu for %u.\n", desc.dwSize, desc_sizes[j]);
15361 ok(desc.blob[desc_sizes[j]] == 0xcc, "Overflow for size %u.\n", desc_sizes[j]);
15362 ok(desc.blob[desc_sizes[j] - 1] != 0xcc, "Struct not cleared for size %u.\n", desc_sizes[j]);
15366 refcount = IDirectDraw4_Release(ddraw);
15367 ok(!refcount, "DirectDraw has %lu references left.\n", refcount);
15370 static void test_get_surface_from_dc(void)
15372 IDirectDrawSurface *surface1, *tmp;
15373 IDirectDrawSurface4 *surface;
15374 DDSURFACEDESC2 surface_desc;
15375 IDirectDraw4 *ddraw;
15376 HDC dc, device_dc;
15377 ULONG refcount;
15378 HWND window;
15379 HRESULT hr;
15380 DWORD ret;
15382 window = create_window();
15383 ddraw = create_ddraw();
15384 ok(!!ddraw, "Failed to create a ddraw object.\n");
15385 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
15386 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
15388 memset(&surface_desc, 0, sizeof(surface_desc));
15389 surface_desc.dwSize = sizeof(surface_desc);
15390 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
15391 surface_desc.dwWidth = 64;
15392 surface_desc.dwHeight = 64;
15393 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
15395 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
15396 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
15397 hr = IDirectDrawSurface4_QueryInterface(surface, &IID_IDirectDrawSurface, (void **)&surface1);
15398 ok(SUCCEEDED(hr), "Failed to query IDirectDrawSurface interface, hr %#lx.\n", hr);
15400 refcount = get_refcount((IUnknown *)surface1);
15401 ok(refcount == 1, "Got unexpected refcount %lu.\n", refcount);
15402 refcount = get_refcount((IUnknown *)surface);
15403 ok(refcount == 1, "Got unexpected refcount %lu.\n", refcount);
15405 hr = IDirectDrawSurface4_GetDC(surface, &dc);
15406 ok(SUCCEEDED(hr), "Failed to get DC, hr %#lx.\n", hr);
15408 tmp = (void *)0xdeadbeef;
15409 device_dc = (void *)0xdeadbeef;
15410 hr = GetSurfaceFromDC(NULL, &tmp, &device_dc);
15411 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#lx.\n", hr);
15412 ok(!tmp, "Got unexpected surface %p.\n", tmp);
15413 ok(!device_dc, "Got unexpected device_dc %p.\n", device_dc);
15415 device_dc = (void *)0xdeadbeef;
15416 hr = GetSurfaceFromDC(dc, NULL, &device_dc);
15417 ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr);
15418 ok(device_dc == (void *)0xdeadbeef, "Got unexpected device_dc %p.\n", device_dc);
15420 tmp = (void *)0xdeadbeef;
15421 hr = GetSurfaceFromDC(dc, &tmp, NULL);
15422 ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr);
15423 ok(!tmp, "Got unexpected surface %p.\n", tmp);
15425 hr = GetSurfaceFromDC(dc, &tmp, &device_dc);
15426 ok(SUCCEEDED(hr), "GetSurfaceFromDC failed, hr %#lx.\n", hr);
15427 ok(tmp == surface1, "Got unexpected surface %p, expected %p.\n", tmp, surface1);
15428 IDirectDrawSurface_Release(tmp);
15430 ret = GetObjectType(device_dc);
15431 todo_wine ok(ret == OBJ_DC, "Got unexpected object type %#lx.\n", ret);
15432 ret = GetDeviceCaps(device_dc, TECHNOLOGY);
15433 todo_wine ok(ret == DT_RASDISPLAY, "Got unexpected technology %#lx.\n", ret);
15435 hr = IDirectDraw4_GetSurfaceFromDC(ddraw, dc, NULL);
15436 ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr);
15438 hr = IDirectDraw4_GetSurfaceFromDC(ddraw, dc, (IDirectDrawSurface4 **)&tmp);
15439 ok(SUCCEEDED(hr), "GetSurfaceFromDC failed, hr %#lx.\n", hr);
15440 ok(tmp == surface1, "Got unexpected surface %p, expected %p.\n", tmp, surface1);
15442 refcount = get_refcount((IUnknown *)surface1);
15443 ok(refcount == 2, "Got unexpected refcount %lu.\n", refcount);
15444 refcount = get_refcount((IUnknown *)surface);
15445 ok(refcount == 1, "Got unexpected refcount %lu.\n", refcount);
15447 hr = IDirectDrawSurface4_ReleaseDC(surface, dc);
15448 ok(SUCCEEDED(hr), "ReleaseDC failed, hr %#lx.\n", hr);
15450 IDirectDrawSurface_Release(tmp);
15452 dc = CreateCompatibleDC(NULL);
15453 ok(!!dc, "CreateCompatibleDC failed.\n");
15455 tmp = (void *)0xdeadbeef;
15456 device_dc = (void *)0xdeadbeef;
15457 hr = GetSurfaceFromDC(dc, &tmp, &device_dc);
15458 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#lx.\n", hr);
15459 ok(!tmp, "Got unexpected surface %p.\n", tmp);
15460 ok(!device_dc, "Got unexpected device_dc %p.\n", device_dc);
15462 tmp = (void *)0xdeadbeef;
15463 hr = IDirectDraw4_GetSurfaceFromDC(ddraw, dc, (IDirectDrawSurface4 **)&tmp);
15464 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#lx.\n", hr);
15465 ok(!tmp, "Got unexpected surface %p.\n", tmp);
15467 ok(DeleteDC(dc), "DeleteDC failed.\n");
15469 tmp = (void *)0xdeadbeef;
15470 hr = IDirectDraw4_GetSurfaceFromDC(ddraw, NULL, (IDirectDrawSurface4 **)&tmp);
15471 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#lx.\n", hr);
15472 ok(!tmp, "Got unexpected surface %p.\n", tmp);
15474 IDirectDrawSurface4_Release(surface);
15475 IDirectDrawSurface_Release(surface1);
15476 IDirectDraw4_Release(ddraw);
15477 DestroyWindow(window);
15480 static void test_ck_operation(void)
15482 IDirectDrawSurface4 *src, *dst;
15483 IDirectDrawSurface *src1, *dst1;
15484 DDSURFACEDESC2 surface_desc;
15485 unsigned int i, *color;
15486 IDirectDraw4 *ddraw;
15487 ULONG refcount;
15488 HWND window;
15489 HRESULT hr;
15490 DDCOLORKEY ckey;
15491 DDBLTFX fx;
15493 window = create_window();
15494 ddraw = create_ddraw();
15495 ok(!!ddraw, "Failed to create a ddraw object.\n");
15496 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
15497 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
15499 memset(&surface_desc, 0, sizeof(surface_desc));
15500 surface_desc.dwSize = sizeof(surface_desc);
15501 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
15502 surface_desc.dwWidth = 4;
15503 surface_desc.dwHeight = 1;
15504 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
15505 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB;
15506 surface_desc.ddpfPixelFormat.dwRGBBitCount = 32;
15507 surface_desc.ddpfPixelFormat.dwRBitMask = 0x00ff0000;
15508 surface_desc.ddpfPixelFormat.dwGBitMask = 0x0000ff00;
15509 surface_desc.ddpfPixelFormat.dwBBitMask = 0x000000ff;
15510 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &dst, NULL);
15511 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
15513 surface_desc.dwFlags |= DDSD_CKSRCBLT;
15514 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00ff00ff;
15515 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00ff00ff;
15516 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &src, NULL);
15517 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
15519 hr = IDirectDrawSurface4_Lock(src, NULL, &surface_desc, DDLOCK_WAIT, NULL);
15520 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#lx.\n", hr);
15521 ok(!(surface_desc.dwFlags & DDSD_LPSURFACE), "Surface desc has LPSURFACE Flags set.\n");
15522 color = surface_desc.lpSurface;
15523 color[0] = 0x77010203;
15524 color[1] = 0x00010203;
15525 color[2] = 0x77ff00ff;
15526 color[3] = 0x00ff00ff;
15527 hr = IDirectDrawSurface4_Unlock(src, NULL);
15528 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx.\n", hr);
15530 for (i = 0; i < 2; ++i)
15532 hr = IDirectDrawSurface4_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
15533 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#lx.\n", hr);
15534 color = surface_desc.lpSurface;
15535 color[0] = 0xcccccccc;
15536 color[1] = 0xcccccccc;
15537 color[2] = 0xcccccccc;
15538 color[3] = 0xcccccccc;
15539 hr = IDirectDrawSurface4_Unlock(dst, NULL);
15540 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx.\n", hr);
15542 if (i)
15544 hr = IDirectDrawSurface4_BltFast(dst, 0, 0, src, NULL, DDBLTFAST_SRCCOLORKEY);
15545 ok(SUCCEEDED(hr), "Failed to blit, hr %#lx.\n", hr);
15547 else
15549 hr = IDirectDrawSurface4_Blt(dst, NULL, src, NULL, DDBLT_KEYSRC, NULL);
15550 ok(SUCCEEDED(hr), "Failed to blit, hr %#lx.\n", hr);
15553 hr = IDirectDrawSurface4_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT | DDLOCK_READONLY, NULL);
15554 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#lx.\n", hr);
15555 ok(!(surface_desc.dwFlags & DDSD_LPSURFACE), "Surface desc has LPSURFACE Flags set.\n");
15556 color = surface_desc.lpSurface;
15557 /* Different behavior on some drivers / windows versions. Some versions ignore the X channel when
15558 * color keying, but copy it to the destination surface. Others (sysmem surfaces) apply it for
15559 * color keying, but do not copy it into the destination surface. Nvidia neither uses it for
15560 * color keying nor copies it. */
15561 ok((color[0] == 0x77010203 && color[1] == 0x00010203
15562 && color[2] == 0xcccccccc && color[3] == 0xcccccccc) /* AMD, Wine */
15563 || broken(color[0] == 0x00010203 && color[1] == 0x00010203
15564 && color[2] == 0x00ff00ff && color[3] == 0xcccccccc) /* Sysmem surfaces? */
15565 || broken(color[0] == 0x00010203 && color[1] == 0x00010203
15566 && color[2] == 0xcccccccc && color[3] == 0xcccccccc) /* Nvidia */
15567 || broken(color[0] == 0xff010203 && color[1] == 0xff010203
15568 && color[2] == 0xcccccccc && color[3] == 0xcccccccc) /* Testbot */,
15569 "Destination data after blitting is %08x %08x %08x %08x, i=%u.\n",
15570 color[0], color[1], color[2], color[3], i);
15571 hr = IDirectDrawSurface4_Unlock(dst, NULL);
15572 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx.\n", hr);
15575 hr = IDirectDrawSurface4_GetColorKey(src, DDCKEY_SRCBLT, &ckey);
15576 ok(SUCCEEDED(hr), "Failed to get color key, hr %#lx.\n", hr);
15577 ok(ckey.dwColorSpaceLowValue == 0x00ff00ff && ckey.dwColorSpaceHighValue == 0x00ff00ff,
15578 "Got unexpected color key low=%08lx high=%08lx.\n", ckey.dwColorSpaceLowValue, ckey.dwColorSpaceHighValue);
15580 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0x0000ff00;
15581 hr = IDirectDrawSurface4_SetColorKey(src, DDCKEY_SRCBLT, &ckey);
15582 ok(SUCCEEDED(hr), "Failed to set color key, hr %#lx.\n", hr);
15584 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0;
15585 hr = IDirectDrawSurface4_GetColorKey(src, DDCKEY_SRCBLT, &ckey);
15586 ok(SUCCEEDED(hr), "Failed to get color key, hr %#lx.\n", hr);
15587 ok(ckey.dwColorSpaceLowValue == 0x0000ff00 && ckey.dwColorSpaceHighValue == 0x0000ff00,
15588 "Got unexpected color key low=%08lx high=%08lx.\n", ckey.dwColorSpaceLowValue, ckey.dwColorSpaceHighValue);
15590 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0;
15591 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0;
15592 hr = IDirectDrawSurface4_GetSurfaceDesc(src, &surface_desc);
15593 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#lx.\n", hr);
15594 ok(surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue == 0x0000ff00
15595 && surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue == 0x0000ff00,
15596 "Got unexpected color key low=%08lx high=%08lx.\n", surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue,
15597 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue);
15599 /* Test SetColorKey with dwColorSpaceHighValue < dwColorSpaceLowValue */
15600 ckey.dwColorSpaceLowValue = 0x000000ff;
15601 ckey.dwColorSpaceHighValue = 0x00000000;
15602 hr = IDirectDrawSurface4_SetColorKey(src, DDCKEY_SRCBLT, &ckey);
15603 ok(SUCCEEDED(hr), "Failed to set color key, hr %#lx.\n", hr);
15605 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0;
15606 hr = IDirectDrawSurface4_GetColorKey(src, DDCKEY_SRCBLT, &ckey);
15607 ok(SUCCEEDED(hr), "Failed to get color key, hr %#lx.\n", hr);
15608 ok(ckey.dwColorSpaceLowValue == 0x000000ff && ckey.dwColorSpaceHighValue == 0x000000ff,
15609 "Got unexpected color key low=%08lx high=%08lx.\n", ckey.dwColorSpaceLowValue, ckey.dwColorSpaceHighValue);
15611 ckey.dwColorSpaceLowValue = 0x000000ff;
15612 ckey.dwColorSpaceHighValue = 0x00000001;
15613 hr = IDirectDrawSurface4_SetColorKey(src, DDCKEY_SRCBLT, &ckey);
15614 ok(SUCCEEDED(hr), "Failed to set color key, hr %#lx.\n", hr);
15616 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0;
15617 hr = IDirectDrawSurface4_GetColorKey(src, DDCKEY_SRCBLT, &ckey);
15618 ok(SUCCEEDED(hr), "Failed to get color key, hr %#lx.\n", hr);
15619 ok(ckey.dwColorSpaceLowValue == 0x000000ff && ckey.dwColorSpaceHighValue == 0x000000ff,
15620 "Got unexpected color key low=%08lx high=%08lx.\n", ckey.dwColorSpaceLowValue, ckey.dwColorSpaceHighValue);
15622 ckey.dwColorSpaceLowValue = 0x000000fe;
15623 ckey.dwColorSpaceHighValue = 0x000000fd;
15624 hr = IDirectDrawSurface4_SetColorKey(src, DDCKEY_SRCBLT, &ckey);
15625 ok(SUCCEEDED(hr), "Failed to set color key, hr %#lx.\n", hr);
15627 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0;
15628 hr = IDirectDrawSurface4_GetColorKey(src, DDCKEY_SRCBLT, &ckey);
15629 ok(SUCCEEDED(hr), "Failed to get color key, hr %#lx.\n", hr);
15630 ok(ckey.dwColorSpaceLowValue == 0x000000fe && ckey.dwColorSpaceHighValue == 0x000000fe,
15631 "Got unexpected color key low=%08lx high=%08lx.\n", ckey.dwColorSpaceLowValue, ckey.dwColorSpaceHighValue);
15633 IDirectDrawSurface4_Release(src);
15634 IDirectDrawSurface4_Release(dst);
15636 /* Test source and destination keys and where they are read from. Use a surface with alpha
15637 * to avoid driver-dependent content in the X channel. */
15638 memset(&surface_desc, 0, sizeof(surface_desc));
15639 surface_desc.dwSize = sizeof(surface_desc);
15640 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
15641 surface_desc.dwWidth = 6;
15642 surface_desc.dwHeight = 1;
15643 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
15644 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
15645 surface_desc.ddpfPixelFormat.dwRGBBitCount = 32;
15646 surface_desc.ddpfPixelFormat.dwRBitMask = 0x00ff0000;
15647 surface_desc.ddpfPixelFormat.dwGBitMask = 0x0000ff00;
15648 surface_desc.ddpfPixelFormat.dwBBitMask = 0x000000ff;
15649 surface_desc.ddpfPixelFormat.dwRGBAlphaBitMask = 0xff000000;
15650 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &dst, NULL);
15651 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
15652 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &src, NULL);
15653 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
15655 ckey.dwColorSpaceLowValue = 0x0000ff00;
15656 ckey.dwColorSpaceHighValue = 0x0000ff00;
15657 hr = IDirectDrawSurface4_SetColorKey(dst, DDCKEY_SRCBLT, &ckey);
15658 ok(SUCCEEDED(hr), "Failed to set color key, hr %#lx.\n", hr);
15659 ckey.dwColorSpaceLowValue = 0x00ff0000;
15660 ckey.dwColorSpaceHighValue = 0x00ff0000;
15661 hr = IDirectDrawSurface4_SetColorKey(dst, DDCKEY_DESTBLT, &ckey);
15662 ok(SUCCEEDED(hr) || hr == DDERR_NOCOLORKEYHW, "Failed to set color key, hr %#lx.\n", hr);
15663 if (FAILED(hr))
15665 /* Nvidia reject dest keys, AMD allows them. This applies to vidmem and sysmem surfaces. */
15666 skip("Failed to set destination color key, skipping related tests.\n");
15667 goto done;
15670 ckey.dwColorSpaceLowValue = 0x000000ff;
15671 ckey.dwColorSpaceHighValue = 0x000000ff;
15672 hr = IDirectDrawSurface4_SetColorKey(src, DDCKEY_SRCBLT, &ckey);
15673 ok(SUCCEEDED(hr), "Failed to set color key, hr %#lx.\n", hr);
15674 ckey.dwColorSpaceLowValue = 0x000000aa;
15675 ckey.dwColorSpaceHighValue = 0x000000aa;
15676 hr = IDirectDrawSurface4_SetColorKey(src, DDCKEY_DESTBLT, &ckey);
15677 ok(SUCCEEDED(hr), "Failed to set color key, hr %#lx.\n", hr);
15679 memset(&fx, 0, sizeof(fx));
15680 fx.dwSize = sizeof(fx);
15681 fx.ddckSrcColorkey.dwColorSpaceHighValue = 0x00110000;
15682 fx.ddckSrcColorkey.dwColorSpaceLowValue = 0x00110000;
15683 fx.ddckDestColorkey.dwColorSpaceHighValue = 0x00001100;
15684 fx.ddckDestColorkey.dwColorSpaceLowValue = 0x00001100;
15686 hr = IDirectDrawSurface4_Lock(src, NULL, &surface_desc, DDLOCK_WAIT, NULL);
15687 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#lx.\n", hr);
15688 color = surface_desc.lpSurface;
15689 color[0] = 0x000000ff; /* Applies to src blt key in src surface. */
15690 color[1] = 0x000000aa; /* Applies to dst blt key in src surface. */
15691 color[2] = 0x00ff0000; /* Dst color key in dst surface. */
15692 color[3] = 0x0000ff00; /* Src color key in dst surface. */
15693 color[4] = 0x00001100; /* Src color key in ddbltfx. */
15694 color[5] = 0x00110000; /* Dst color key in ddbltfx. */
15695 hr = IDirectDrawSurface4_Unlock(src, NULL);
15696 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx.\n", hr);
15698 hr = IDirectDrawSurface4_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
15699 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#lx.\n", hr);
15700 color = surface_desc.lpSurface;
15701 color[0] = color[1] = color[2] = color[3] = color[4] = color[5] = 0x55555555;
15702 hr = IDirectDrawSurface4_Unlock(dst, NULL);
15703 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx.\n", hr);
15705 /* Test a blit without keying. */
15706 hr = IDirectDrawSurface4_Blt(dst, NULL, src, NULL, 0, &fx);
15707 ok(SUCCEEDED(hr), "Failed to blit, hr %#lx.\n", hr);
15709 hr = IDirectDrawSurface4_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
15710 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#lx.\n", hr);
15711 color = surface_desc.lpSurface;
15712 /* Should have copied src data unmodified to dst. */
15713 ok(color[0] == 0x000000ff && color[1] == 0x000000aa && color[2] == 0x00ff0000 &&
15714 color[3] == 0x0000ff00 && color[4] == 0x00001100 && color[5] == 0x00110000,
15715 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
15716 color[0], color[1], color[2], color[3], color[4], color[5]);
15718 color[0] = color[1] = color[2] = color[3] = color[4] = color[5] = 0x55555555;
15719 hr = IDirectDrawSurface4_Unlock(dst, NULL);
15720 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx.\n", hr);
15722 /* Src key. */
15723 hr = IDirectDrawSurface4_Blt(dst, NULL, src, NULL, DDBLT_KEYSRC, &fx);
15724 ok(SUCCEEDED(hr), "Failed to blit, hr %#lx.\n", hr);
15726 hr = IDirectDrawSurface4_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
15727 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#lx.\n", hr);
15728 color = surface_desc.lpSurface;
15729 /* Src key applied to color[0]. It is unmodified, the others are copied. */
15730 ok(color[0] == 0x55555555 && color[1] == 0x000000aa && color[2] == 0x00ff0000 &&
15731 color[3] == 0x0000ff00 && color[4] == 0x00001100 && color[5] == 0x00110000,
15732 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
15733 color[0], color[1], color[2], color[3], color[4], color[5]);
15735 color[0] = color[1] = color[2] = color[3] = color[4] = color[5] = 0x55555555;
15736 hr = IDirectDrawSurface4_Unlock(dst, NULL);
15737 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx.\n", hr);
15739 /* Src override. */
15740 hr = IDirectDrawSurface4_Blt(dst, NULL, src, NULL, DDBLT_KEYSRCOVERRIDE, &fx);
15741 ok(SUCCEEDED(hr), "Failed to blit, hr %#lx.\n", hr);
15743 hr = IDirectDrawSurface4_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
15744 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#lx.\n", hr);
15745 color = surface_desc.lpSurface;
15746 /* Override key applied to color[5]. It is unmodified, the others are copied. */
15747 ok(color[0] == 0x000000ff && color[1] == 0x000000aa && color[2] == 0x00ff0000 &&
15748 color[3] == 0x0000ff00 && color[4] == 0x00001100 && color[5] == 0x55555555,
15749 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
15750 color[0], color[1], color[2], color[3], color[4], color[5]);
15752 color[0] = color[1] = color[2] = color[3] = color[4] = color[5] = 0x55555555;
15753 hr = IDirectDrawSurface4_Unlock(dst, NULL);
15754 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx.\n", hr);
15756 /* Src override AND src key. That is not supposed to work. */
15757 hr = IDirectDrawSurface4_Blt(dst, NULL, src, NULL, DDBLT_KEYSRC | DDBLT_KEYSRCOVERRIDE, &fx);
15758 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
15760 hr = IDirectDrawSurface4_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
15761 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#lx.\n", hr);
15762 color = surface_desc.lpSurface;
15763 /* Ensure the destination was not changed. */
15764 ok(color[0] == 0x55555555 && color[1] == 0x55555555 && color[2] == 0x55555555 &&
15765 color[3] == 0x55555555 && color[4] == 0x55555555 && color[5] == 0x55555555,
15766 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
15767 color[0], color[1], color[2], color[3], color[4], color[5]);
15769 /* Use different dst colors for the dst key test. */
15770 color[0] = 0x00ff0000; /* Dest key in dst surface. */
15771 color[1] = 0x00ff0000; /* Dest key in dst surface. */
15772 color[2] = 0x00001100; /* Dest key in override. */
15773 color[3] = 0x00001100; /* Dest key in override. */
15774 color[4] = 0x000000aa; /* Dest key in src surface. */
15775 color[5] = 0x000000aa; /* Dest key in src surface. */
15776 hr = IDirectDrawSurface4_Unlock(dst, NULL);
15777 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx.\n", hr);
15779 /* Dest key blit. The key is taken from the DESTINATION surface in v4! */
15780 hr = IDirectDrawSurface4_Blt(dst, NULL, src, NULL, DDBLT_KEYDEST, &fx);
15781 ok(SUCCEEDED(hr), "Failed to blit, hr %#lx.\n", hr);
15783 hr = IDirectDrawSurface4_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
15784 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#lx.\n", hr);
15785 color = surface_desc.lpSurface;
15786 /* Dst key applied to color[0,1], they are the only changed pixels. */
15787 todo_wine ok(color[0] == 0x000000ff && color[1] == 0x000000aa && color[2] == 0x00001100 &&
15788 color[3] == 0x00001100 && color[4] == 0x000000aa && color[5] == 0x000000aa,
15789 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
15790 color[0], color[1], color[2], color[3], color[4], color[5]);
15792 color[0] = 0x00ff0000; /* Dest key in dst surface. */
15793 color[1] = 0x00ff0000; /* Dest key in dst surface. */
15794 color[2] = 0x00001100; /* Dest key in override. */
15795 color[3] = 0x00001100; /* Dest key in override. */
15796 color[4] = 0x000000aa; /* Dest key in src surface. */
15797 color[5] = 0x000000aa; /* Dest key in src surface. */
15798 hr = IDirectDrawSurface4_Unlock(dst, NULL);
15799 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx.\n", hr);
15801 /* What happens with a QI'd older version of the interface? It takes the key
15802 * from the source surface. */
15803 hr = IDirectDrawSurface4_QueryInterface(src, &IID_IDirectDrawSurface, (void **)&src1);
15804 ok(SUCCEEDED(hr), "Failed to query IDirectDrawSurface interface, hr %#lx.\n", hr);
15805 hr = IDirectDrawSurface4_QueryInterface(dst, &IID_IDirectDrawSurface, (void **)&dst1);
15806 ok(SUCCEEDED(hr), "Failed to query IDirectDrawSurface interface, hr %#lx.\n", hr);
15808 hr = IDirectDrawSurface_Blt(dst1, NULL, src1, NULL, DDBLT_KEYDEST, &fx);
15809 ok(SUCCEEDED(hr), "Failed to blit, hr %#lx.\n", hr);
15811 IDirectDrawSurface_Release(dst1);
15812 IDirectDrawSurface_Release(src1);
15814 hr = IDirectDrawSurface7_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
15815 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#lx.\n", hr);
15816 color = surface_desc.lpSurface;
15817 /* Dst key applied to color[4,5], they are the only changed pixels. */
15818 ok(color[0] == 0x00ff0000 && color[1] == 0x00ff0000 && color[2] == 0x00001100 &&
15819 color[3] == 0x00001100 && color[4] == 0x00001100 && color[5] == 0x00110000,
15820 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
15821 color[0], color[1], color[2], color[3], color[4], color[5]);
15823 color[0] = 0x00ff0000; /* Dest key in dst surface. */
15824 color[1] = 0x00ff0000; /* Dest key in dst surface. */
15825 color[2] = 0x00001100; /* Dest key in override. */
15826 color[3] = 0x00001100; /* Dest key in override. */
15827 color[4] = 0x000000aa; /* Dest key in src surface. */
15828 color[5] = 0x000000aa; /* Dest key in src surface. */
15829 hr = IDirectDrawSurface7_Unlock(dst, NULL);
15830 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx.\n", hr);
15832 /* Dest override key blit. */
15833 hr = IDirectDrawSurface4_Blt(dst, NULL, src, NULL, DDBLT_KEYDESTOVERRIDE, &fx);
15834 ok(SUCCEEDED(hr), "Failed to blit, hr %#lx.\n", hr);
15836 hr = IDirectDrawSurface4_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
15837 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#lx.\n", hr);
15838 color = surface_desc.lpSurface;
15839 /* Dst key applied to color[2,3], they are the only changed pixels. */
15840 ok(color[0] == 0x00ff0000 && color[1] == 0x00ff0000 && color[2] == 0x00ff0000 &&
15841 color[3] == 0x0000ff00 && color[4] == 0x000000aa && color[5] == 0x000000aa,
15842 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
15843 color[0], color[1], color[2], color[3], color[4], color[5]);
15845 color[0] = 0x00ff0000; /* Dest key in dst surface. */
15846 color[1] = 0x00ff0000; /* Dest key in dst surface. */
15847 color[2] = 0x00001100; /* Dest key in override. */
15848 color[3] = 0x00001100; /* Dest key in override. */
15849 color[4] = 0x000000aa; /* Dest key in src surface. */
15850 color[5] = 0x000000aa; /* Dest key in src surface. */
15851 hr = IDirectDrawSurface4_Unlock(dst, NULL);
15852 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx.\n", hr);
15854 /* Dest override together with surface key. Supposed to fail. */
15855 hr = IDirectDrawSurface4_Blt(dst, NULL, src, NULL, DDBLT_KEYDEST | DDBLT_KEYDESTOVERRIDE, &fx);
15856 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
15858 hr = IDirectDrawSurface4_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
15859 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#lx.\n", hr);
15860 color = surface_desc.lpSurface;
15861 /* Destination is unchanged. */
15862 ok(color[0] == 0x00ff0000 && color[1] == 0x00ff0000 && color[2] == 0x00001100 &&
15863 color[3] == 0x00001100 && color[4] == 0x000000aa && color[5] == 0x000000aa,
15864 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
15865 color[0], color[1], color[2], color[3], color[4], color[5]);
15866 hr = IDirectDrawSurface4_Unlock(dst, NULL);
15867 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx.\n", hr);
15869 /* Source and destination key. This is driver dependent. New HW treats it like
15870 * DDBLT_KEYSRC. Older HW and some software renderers apply both keys. */
15871 if (0)
15873 hr = IDirectDrawSurface4_Blt(dst, NULL, src, NULL, DDBLT_KEYDEST | DDBLT_KEYSRC, &fx);
15874 ok(SUCCEEDED(hr), "Failed to blit, hr %#lx.\n", hr);
15876 hr = IDirectDrawSurface4_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
15877 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#lx.\n", hr);
15878 color = surface_desc.lpSurface;
15879 /* Color[0] is filtered by the src key, 2-5 are filtered by the dst key, if
15880 * the driver applies it. */
15881 ok(color[0] == 0x00ff0000 && color[1] == 0x000000aa && color[2] == 0x00ff0000 &&
15882 color[3] == 0x0000ff00 && color[4] == 0x00001100 && color[5] == 0x00110000,
15883 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
15884 color[0], color[1], color[2], color[3], color[4], color[5]);
15886 color[0] = 0x00ff0000; /* Dest key in dst surface. */
15887 color[1] = 0x00ff0000; /* Dest key in dst surface. */
15888 color[2] = 0x00001100; /* Dest key in override. */
15889 color[3] = 0x00001100; /* Dest key in override. */
15890 color[4] = 0x000000aa; /* Dest key in src surface. */
15891 color[5] = 0x000000aa; /* Dest key in src surface. */
15892 hr = IDirectDrawSurface4_Unlock(dst, NULL);
15893 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx.\n", hr);
15896 /* Override keys without ddbltfx parameter fail */
15897 hr = IDirectDrawSurface4_Blt(dst, NULL, src, NULL, DDBLT_KEYDESTOVERRIDE, NULL);
15898 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
15899 hr = IDirectDrawSurface4_Blt(dst, NULL, src, NULL, DDBLT_KEYSRCOVERRIDE, NULL);
15900 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
15902 /* Try blitting without keys in the source surface. */
15903 hr = IDirectDrawSurface4_SetColorKey(src, DDCKEY_SRCBLT, NULL);
15904 ok(SUCCEEDED(hr), "Failed to set color key, hr %#lx.\n", hr);
15905 hr = IDirectDrawSurface4_SetColorKey(src, DDCKEY_DESTBLT, NULL);
15906 ok(SUCCEEDED(hr), "Failed to set color key, hr %#lx.\n", hr);
15908 /* That fails now. Do not bother to check that the data is unmodified. */
15909 hr = IDirectDrawSurface4_Blt(dst, NULL, src, NULL, DDBLT_KEYSRC, &fx);
15910 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
15912 /* Dest key blit still works, the destination surface key is used in v4. */
15913 hr = IDirectDrawSurface4_Blt(dst, NULL, src, NULL, DDBLT_KEYDEST, &fx);
15914 ok(SUCCEEDED(hr), "Failed to blit, hr %#lx.\n", hr);
15916 hr = IDirectDrawSurface4_Lock(dst, NULL, &surface_desc, DDLOCK_WAIT, NULL);
15917 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#lx.\n", hr);
15918 color = surface_desc.lpSurface;
15919 /* Dst key applied to color[0,1], they are the only changed pixels. */
15920 todo_wine ok(color[0] == 0x000000ff && color[1] == 0x000000aa && color[2] == 0x00001100 &&
15921 color[3] == 0x00001100 && color[4] == 0x000000aa && color[5] == 0x000000aa,
15922 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
15923 color[0], color[1], color[2], color[3], color[4], color[5]);
15924 hr = IDirectDrawSurface4_Unlock(dst, NULL);
15925 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx.\n", hr);
15927 /* Try blitting without keys in the destination surface. */
15928 hr = IDirectDrawSurface4_SetColorKey(dst, DDCKEY_SRCBLT, NULL);
15929 ok(SUCCEEDED(hr), "Failed to set color key, hr %#lx.\n", hr);
15930 hr = IDirectDrawSurface4_SetColorKey(dst, DDCKEY_DESTBLT, NULL);
15931 ok(SUCCEEDED(hr), "Failed to set color key, hr %#lx.\n", hr);
15933 /* This fails, as sanity would dictate. */
15934 hr = IDirectDrawSurface4_Blt(dst, NULL, src, NULL, DDBLT_KEYDEST, &fx);
15935 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
15937 done:
15938 IDirectDrawSurface4_Release(src);
15939 IDirectDrawSurface4_Release(dst);
15940 refcount = IDirectDraw4_Release(ddraw);
15941 ok(!refcount, "DirectDraw has %lu references left.\n", refcount);
15942 DestroyWindow(window);
15945 static void test_vb_refcount(void)
15947 ULONG prev_d3d_refcount, prev_device_refcount;
15948 ULONG cur_d3d_refcount, cur_device_refcount;
15949 IDirect3DVertexBuffer *vb, *vb1;
15950 IDirect3DVertexBuffer7 *vb7;
15951 D3DVERTEXBUFFERDESC vb_desc;
15952 IDirect3DDevice3 *device;
15953 IDirect3D3 *d3d;
15954 ULONG refcount;
15955 IUnknown *unk;
15956 HWND window;
15957 HRESULT hr;
15959 window = create_window();
15960 if (!(device = create_device(window, DDSCL_NORMAL)))
15962 skip("Failed to create a 3D device, skipping test.\n");
15963 DestroyWindow(window);
15964 return;
15967 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
15968 ok(SUCCEEDED(hr), "Failed to get Direct3D3 interface, hr %#lx.\n", hr);
15970 prev_d3d_refcount = get_refcount((IUnknown *)d3d);
15971 prev_device_refcount = get_refcount((IUnknown *)device);
15973 memset(&vb_desc, 0, sizeof(vb_desc));
15974 vb_desc.dwSize = sizeof(vb_desc);
15975 vb_desc.dwFVF = D3DFVF_XYZ;
15976 vb_desc.dwNumVertices = 4;
15977 hr = IDirect3D3_CreateVertexBuffer(d3d, &vb_desc, &vb, 0, NULL);
15978 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#lx.\n", hr);
15980 cur_d3d_refcount = get_refcount((IUnknown *)d3d);
15981 cur_device_refcount = get_refcount((IUnknown *)device);
15982 ok(cur_d3d_refcount == prev_d3d_refcount, "D3D object refcount changed from %lu to %lu.\n",
15983 prev_d3d_refcount, cur_d3d_refcount);
15984 ok(cur_device_refcount == prev_device_refcount, "Device refcount changed from %lu to %lu.\n",
15985 prev_device_refcount, cur_device_refcount);
15987 hr = IDirect3DVertexBuffer_QueryInterface(vb, &IID_IDirect3DVertexBuffer, (void **)&vb1);
15988 ok(hr == DD_OK, "Failed to query IDirect3DVertexBuffer, hr %#lx.\n", hr);
15989 IDirect3DVertexBuffer_Release(vb1);
15991 hr = IDirect3DVertexBuffer_QueryInterface(vb, &IID_IDirect3DVertexBuffer7, (void **)&vb7);
15992 ok(hr == E_NOINTERFACE, "Querying IDirect3DVertexBuffer7 returned unexpected hr %#lx.\n", hr);
15994 hr = IDirect3DVertexBuffer_QueryInterface(vb, &IID_IUnknown, (void **)&unk);
15995 ok(hr == DD_OK, "Failed to query IUnknown, hr %#lx.\n", hr);
15996 ok((IUnknown *)vb == unk,
15997 "IDirect3DVertexBuffer and IUnknown interface pointers don't match, %p != %p.\n", vb, unk);
15998 IUnknown_Release(unk);
16000 refcount = IDirect3DVertexBuffer_Release(vb);
16001 ok(!refcount, "Vertex buffer has %lu references left.\n", refcount);
16002 IDirect3D3_Release(d3d);
16003 refcount = IDirect3DDevice3_Release(device);
16004 ok(!refcount, "Device has %lu references left.\n", refcount);
16005 DestroyWindow(window);
16008 static void test_compute_sphere_visibility(void)
16010 static D3DMATRIX proj_1 =
16012 1.810660f, 0.000000f, 0.000000f, 0.000000f,
16013 0.000000f, 2.414213f, 0.000000f, 0.000000f,
16014 0.000000f, 0.000000f, 1.020408f, 1.000000f,
16015 0.000000f, 0.000000f, -0.102041f, 0.000000f,
16017 static D3DMATRIX proj_2 =
16019 10.0f, 0.0f, 0.0f, 0.0f,
16020 0.0f, 10.0f, 0.0f, 0.0f,
16021 0.0f, 0.0f, 10.0f, 0.0f,
16022 0.0f, 0.0f, 0.0f, 1.0f,
16024 static D3DMATRIX view_1 =
16026 1.000000f, 0.000000f, 0.000000f, 0.000000f,
16027 0.000000f, 0.768221f, -0.640185f, 0.000000f,
16028 -0.000000f, 0.640185f, 0.768221f, 0.000000f,
16029 -14.852037f, 9.857489f, 11.600972f, 1.000000f,
16031 static D3DMATRIX identity =
16033 1.0f, 0.0f, 0.0f, 0.0f,
16034 0.0f, 1.0f, 0.0f, 0.0f,
16035 0.0f, 0.0f, 1.0f, 0.0f,
16036 0.0f, 0.0f, 0.0f, 1.0f,
16038 static struct
16040 D3DMATRIX *view, *proj;
16041 unsigned int sphere_count;
16042 D3DVECTOR center[3];
16043 D3DVALUE radius[3];
16044 const DWORD expected[3];
16045 BOOL todo;
16047 tests[] =
16049 {&view_1, &proj_1, 1, {{{11.461533f}, {-4.761727f}, {-1.171646f}}}, {38.252632f}, {0x1555}},
16050 {&view_1, &proj_1, 3, {{{-3.515620f}, {-1.560661f}, {-12.464638f}},
16051 {{14.290396f}, {-2.981143f}, {-24.311312f}},
16052 {{1.461626f}, {-6.093709f}, {-13.901010f}}},
16053 {4.354097f, 12.500704f, 17.251318f}, {0x154a, 0x1555, 0x1555}},
16054 {&identity, &proj_2, 1, {{{0.0f}, {0.0f}, {0.05f}}}, {0.04f}, {0x1555}, TRUE},
16055 {&identity, &identity, 1, {{{0.0f}, {0.0f}, {0.5f}}}, {0.5f}, {0x1401}},
16056 {&identity, &identity, 1, {{{0.0f}, {0.0f}, {0.0f}}}, {0.0f}, {0x401}},
16057 {&identity, &identity, 1, {{{-1.0f}, {-1.0f}, {0.5f}}}, {0.25f}, {0x1505}, TRUE}, /* 5 */
16058 {&identity, &identity, 1, {{{-20.0f}, {0.0f}, {0.5f}}}, {3.0f}, {0x154a}},
16059 {&identity, &identity, 1, {{{20.0f}, {0.0f}, {0.5f}}}, {3.0f}, {0x1562}},
16060 {&identity, &identity, 1, {{{0.0f}, {-20.0f}, {0.5f}}}, {3.0f}, {0x1616}},
16061 {&identity, &identity, 1, {{{0.0f}, {20.0f}, {0.5f}}}, {3.0f}, {0x1496}},
16062 {&identity, &identity, 1, {{{0.0f}, {0.0f}, {-20.0f}}}, {3.0f}, {0x956}}, /* 10 */
16063 {&identity, &identity, 1, {{{0.0f}, {0.0f}, {20.0f}}}, {3.0f}, {0x2156}},
16065 IDirect3DViewport3 *viewport;
16066 IDirect3DDevice3 *device;
16067 unsigned int i, j;
16068 DWORD result[3];
16069 ULONG refcount;
16070 HWND window;
16071 HRESULT hr;
16073 window = create_window();
16074 if (!(device = create_device(window, DDSCL_NORMAL)))
16076 skip("Failed to create a 3D device, skipping test.\n");
16077 DestroyWindow(window);
16078 return;
16081 viewport = create_viewport(device, 0, 0, 640, 480);
16082 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
16083 ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#lx.\n", hr);
16085 IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &identity);
16087 for (i = 0; i < ARRAY_SIZE(tests); ++i)
16089 IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_VIEW, tests[i].view);
16090 IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, tests[i].proj);
16092 hr = IDirect3DDevice3_ComputeSphereVisibility(device, tests[i].center, tests[i].radius,
16093 tests[i].sphere_count, 0, result);
16094 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
16096 for (j = 0; j < tests[i].sphere_count; ++j)
16097 todo_wine_if(tests[i].todo)
16098 ok(result[j] == tests[i].expected[j], "Test %u sphere %u: expected %#lx, got %#lx.\n",
16099 i, j, tests[i].expected[j], result[j]);
16102 destroy_viewport(device, viewport);
16103 refcount = IDirect3DDevice3_Release(device);
16104 ok(!refcount, "Device has %lu references left.\n", refcount);
16105 DestroyWindow(window);
16108 static void test_texture_stages_limits(void)
16110 IDirectDrawSurface4 *surface;
16111 DDSURFACEDESC2 surface_desc;
16112 IDirect3DTexture2 *texture;
16113 IDirect3DDevice3 *device;
16114 IDirectDraw4 *ddraw;
16115 IDirect3D3 *d3d;
16116 unsigned int i;
16117 ULONG refcount;
16118 HWND window;
16119 HRESULT hr;
16121 window = create_window();
16122 if (!(device = create_device(window, DDSCL_NORMAL)))
16124 skip("Failed to create 3D device.\n");
16125 DestroyWindow(window);
16126 return;
16128 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
16129 ok(SUCCEEDED(hr), "Failed to get Direct3D interface, hr %#lx.\n", hr);
16130 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
16131 ok(SUCCEEDED(hr), "Failed to get DirectDraw interface, hr %#lx.\n", hr);
16132 IDirect3D3_Release(d3d);
16134 memset(&surface_desc, 0, sizeof(surface_desc));
16135 surface_desc.dwSize = sizeof(surface_desc);
16136 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
16137 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
16138 surface_desc.dwWidth = 16;
16139 surface_desc.dwHeight = 16;
16140 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
16141 ok(hr == DD_OK, "Failed to create surface, hr %#lx.\n", hr);
16142 hr = IDirectDrawSurface4_QueryInterface(surface, &IID_IDirect3DTexture2, (void **)&texture);
16143 ok(SUCCEEDED(hr), "Failed to get texture interface, hr %#lx.\n", hr);
16144 IDirectDrawSurface4_Release(surface);
16146 for (i = 0; i < 8; ++i)
16148 hr = IDirect3DDevice3_SetTexture(device, i, texture);
16149 ok(hr == D3D_OK, "Failed to set texture %u, hr %#lx.\n", i, hr);
16150 hr = IDirect3DDevice3_SetTexture(device, i, NULL);
16151 ok(hr == D3D_OK, "Failed to set texture %u, hr %#lx.\n", i, hr);
16152 hr = IDirect3DDevice3_SetTextureStageState(device, i, D3DTSS_COLOROP, D3DTOP_ADD);
16153 ok(hr == D3D_OK, "Failed to set texture stage state %u, hr %#lx.\n", i, hr);
16156 IDirectDraw4_Release(ddraw);
16157 IDirect3DTexture2_Release(texture);
16158 refcount = IDirect3DDevice3_Release(device);
16159 ok(!refcount, "Device has %lu references left.\n", refcount);
16160 DestroyWindow(window);
16163 static void test_set_render_state(void)
16165 IDirect3DDevice3 *device;
16166 ULONG refcount;
16167 HWND window;
16168 DWORD state;
16169 HRESULT hr;
16171 window = create_window();
16172 if (!(device = create_device(window, DDSCL_NORMAL)))
16174 skip("Failed to create 3D device.\n");
16175 DestroyWindow(window);
16176 return;
16179 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ZVISIBLE, TRUE);
16180 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
16181 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ZVISIBLE, FALSE);
16182 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
16184 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_TEXTUREHANDLE, 0);
16185 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
16186 state = 0xdeadbeef;
16187 hr = IDirect3DDevice3_GetRenderState(device, D3DRENDERSTATE_TEXTUREHANDLE, &state);
16188 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
16189 ok(!state, "Got unexpected render state %#lx.\n", state);
16190 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_TEXTUREMAPBLEND, D3DTBLEND_MODULATE);
16191 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
16192 hr = IDirect3DDevice3_GetRenderState(device, D3DRENDERSTATE_TEXTUREMAPBLEND, &state);
16193 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
16194 ok(state == D3DTBLEND_MODULATE, "Got unexpected render state %#lx.\n", state);
16196 refcount = IDirect3DDevice3_Release(device);
16197 ok(!refcount, "Device has %lu references left.\n", refcount);
16198 DestroyWindow(window);
16201 static void test_map_synchronisation(void)
16203 LARGE_INTEGER frequency, diff, ts[3];
16204 unsigned int i, j, tri_count, colour;
16205 IDirect3DVertexBuffer *buffer;
16206 IDirect3DViewport3 *viewport;
16207 D3DVERTEXBUFFERDESC vb_desc;
16208 IDirect3DDevice3 *device;
16209 BOOL unsynchronised, ret;
16210 IDirectDrawSurface4 *rt;
16211 IDirect3D3 *d3d;
16212 ULONG refcount;
16213 HWND window;
16214 HRESULT hr;
16216 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
16218 /* DDLOCK_DISCARDCONTENTS and DDLOCK_NOOVERWRITE were introduced with
16219 * ddraw7 and are ignored in earlier versions. */
16220 static const struct
16222 unsigned int flags;
16223 BOOL unsynchronised;
16225 tests[] =
16227 {0, FALSE},
16228 {DDLOCK_NOOVERWRITE, FALSE},
16229 {DDLOCK_DISCARDCONTENTS, FALSE},
16230 {DDLOCK_NOOVERWRITE | DDLOCK_DISCARDCONTENTS, FALSE},
16233 static const struct quad
16235 struct
16237 struct vec3 position;
16238 DWORD diffuse;
16239 } strip[4];
16241 quad1 =
16244 {{-1.0f, -1.0f, 0.0f}, 0xffff0000},
16245 {{-1.0f, 1.0f, 0.0f}, 0xff00ff00},
16246 {{ 1.0f, -1.0f, 0.0f}, 0xff0000ff},
16247 {{ 1.0f, 1.0f, 0.0f}, 0xffffffff},
16250 quad2 =
16253 {{-1.0f, -1.0f, 0.0f}, 0xffffff00},
16254 {{-1.0f, 1.0f, 0.0f}, 0xffffff00},
16255 {{ 1.0f, -1.0f, 0.0f}, 0xffffff00},
16256 {{ 1.0f, 1.0f, 0.0f}, 0xffffff00},
16259 struct quad *quads;
16261 window = create_window();
16262 ok(!!window, "Failed to create a window.\n");
16264 if (!(device = create_device(window, DDSCL_NORMAL)))
16266 skip("Failed to create a D3D device, skipping tests.\n");
16267 DestroyWindow(window);
16268 return;
16271 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
16272 ok(SUCCEEDED(hr), "Failed to get Direct3D3 interface, hr %#lx.\n", hr);
16274 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
16275 ok(SUCCEEDED(hr), "Failed to get render target, hr %#lx.\n", hr);
16276 viewport = create_viewport(device, 0, 0, 640, 480);
16277 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
16278 ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#lx.\n", hr);
16280 tri_count = 0x1000;
16282 ret = QueryPerformanceFrequency(&frequency);
16283 ok(ret, "Failed to get performance counter frequency.\n");
16285 vb_desc.dwSize = sizeof(vb_desc);
16286 vb_desc.dwCaps = D3DVBCAPS_WRITEONLY;
16287 vb_desc.dwFVF = D3DFVF_XYZ | D3DFVF_DIFFUSE;
16288 vb_desc.dwNumVertices = tri_count + 2;
16289 hr = IDirect3D3_CreateVertexBuffer(d3d, &vb_desc, &buffer, 0, NULL);
16290 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#lx.\n", hr);
16291 hr = IDirect3DVertexBuffer_Lock(buffer, DDLOCK_DISCARDCONTENTS, (void **)&quads, NULL);
16292 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#lx.\n", hr);
16293 for (j = 0; j < vb_desc.dwNumVertices / 4; ++j)
16295 quads[j] = quad1;
16297 hr = IDirect3DVertexBuffer_Unlock(buffer);
16298 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#lx.\n", hr);
16300 /* Initial draw to initialise states, compile shaders, etc. */
16301 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xff0000ff, 0.0f, 0);
16302 ok(SUCCEEDED(hr), "Failed to clear, hr %#lx.\n", hr);
16303 hr = IDirect3DDevice3_BeginScene(device);
16304 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#lx.\n", hr);
16305 hr = IDirect3DDevice3_DrawPrimitiveVB(device, D3DPT_TRIANGLESTRIP, buffer, 0, vb_desc.dwNumVertices, 0);
16306 ok(SUCCEEDED(hr), "Failed to draw, hr %#lx.\n", hr);
16307 hr = IDirect3DDevice3_EndScene(device);
16308 ok(SUCCEEDED(hr), "Failed to end scene, hr %#lx.\n", hr);
16309 /* Read the result to ensure the GPU has finished drawing. */
16310 colour = get_surface_color(rt, 320, 240);
16312 /* Time drawing tri_count triangles. */
16313 ret = QueryPerformanceCounter(&ts[0]);
16314 ok(ret, "Failed to read performance counter.\n");
16315 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xff0000ff, 0.0f, 0);
16316 ok(SUCCEEDED(hr), "Failed to clear, hr %#lx.\n", hr);
16317 hr = IDirect3DDevice3_BeginScene(device);
16318 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#lx.\n", hr);
16319 hr = IDirect3DDevice3_DrawPrimitiveVB(device, D3DPT_TRIANGLESTRIP, buffer, 0, vb_desc.dwNumVertices, 0);
16320 ok(SUCCEEDED(hr), "Failed to draw, hr %#lx.\n", hr);
16321 hr = IDirect3DDevice3_EndScene(device);
16322 ok(SUCCEEDED(hr), "Failed to end scene, hr %#lx.\n", hr);
16323 colour = get_surface_color(rt, 320, 240);
16324 /* Time drawing a single triangle. */
16325 ret = QueryPerformanceCounter(&ts[1]);
16326 ok(ret, "Failed to read performance counter.\n");
16327 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xff0000ff, 0.0f, 0);
16328 ok(SUCCEEDED(hr), "Failed to clear, hr %#lx.\n", hr);
16329 hr = IDirect3DDevice3_BeginScene(device);
16330 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#lx.\n", hr);
16331 hr = IDirect3DDevice3_DrawPrimitiveVB(device, D3DPT_TRIANGLESTRIP, buffer, 0, 3, 0);
16332 ok(SUCCEEDED(hr), "Failed to draw, hr %#lx.\n", hr);
16333 hr = IDirect3DDevice3_EndScene(device);
16334 ok(SUCCEEDED(hr), "Failed to end scene, hr %#lx.\n", hr);
16335 colour = get_surface_color(rt, 320, 240);
16336 ret = QueryPerformanceCounter(&ts[2]);
16337 ok(ret, "Failed to read performance counter.\n");
16339 IDirect3DVertexBuffer_Release(buffer);
16341 /* Estimate the number of triangles we can draw in 100ms. */
16342 diff.QuadPart = ts[1].QuadPart - ts[0].QuadPart + ts[1].QuadPart - ts[2].QuadPart;
16343 tri_count = (tri_count * frequency.QuadPart) / (diff.QuadPart * 10);
16344 tri_count = ((tri_count + 2 + 3) & ~3) - 2;
16345 vb_desc.dwNumVertices = tri_count + 2;
16347 for (i = 0; i < ARRAY_SIZE(tests); ++i)
16349 hr = IDirect3D3_CreateVertexBuffer(d3d, &vb_desc, &buffer, 0, NULL);
16350 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#lx.\n", hr);
16351 hr = IDirect3DVertexBuffer_Lock(buffer, DDLOCK_DISCARDCONTENTS, (void **)&quads, NULL);
16352 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#lx.\n", hr);
16353 for (j = 0; j < vb_desc.dwNumVertices / 4; ++j)
16355 quads[j] = quad1;
16357 hr = IDirect3DVertexBuffer_Unlock(buffer);
16358 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#lx.\n", hr);
16360 /* Start a draw operation. */
16361 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xff0000ff, 0.0f, 0);
16362 ok(SUCCEEDED(hr), "Failed to clear, hr %#lx.\n", hr);
16363 hr = IDirect3DDevice3_BeginScene(device);
16364 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#lx.\n", hr);
16365 hr = IDirect3DDevice3_DrawPrimitiveVB(device, D3DPT_TRIANGLESTRIP, buffer, 0, vb_desc.dwNumVertices, 0);
16366 ok(SUCCEEDED(hr), "Failed to draw, hr %#lx.\n", hr);
16367 hr = IDirect3DDevice3_EndScene(device);
16368 ok(SUCCEEDED(hr), "Failed to end scene, hr %#lx.\n", hr);
16370 /* Map the last quad while the draw is in progress. */
16371 hr = IDirect3DVertexBuffer_Lock(buffer, DDLOCK_WAIT | tests[i].flags, (void **)&quads, NULL);
16372 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#lx.\n", hr);
16373 quads[(vb_desc.dwNumVertices / 4) - 1] = quad2;
16374 hr = IDirect3DVertexBuffer_Unlock(buffer);
16375 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#lx.\n", hr);
16377 colour = get_surface_color(rt, 320, 240);
16378 unsynchronised = compare_color(colour, 0x00ffff00, 1);
16379 ok(tests[i].unsynchronised == unsynchronised, "Expected %s map for flags %#x.\n",
16380 tests[i].unsynchronised ? "unsynchronised" : "synchronised", tests[i].flags);
16382 IDirect3DVertexBuffer_Release(buffer);
16385 destroy_viewport(device, viewport);
16386 IDirectDrawSurface4_Release(rt);
16387 IDirect3D3_Release(d3d);
16388 refcount = IDirect3DDevice3_Release(device);
16389 ok(!refcount, "Device has %lu references left.\n", refcount);
16390 DestroyWindow(window);
16393 static void test_depth_readback(void)
16395 unsigned int depth, expected_depth, i, x, y, max_diff, passed_fmts = 0;
16396 IDirectDrawSurface4 *rt, *ds;
16397 IDirect3DViewport3 *viewport;
16398 DDSURFACEDESC2 surface_desc;
16399 IDirect3DDevice3 *device;
16400 IDirectDraw4 *ddraw;
16401 IDirect3D3 *d3d;
16402 ULONG refcount;
16403 HWND window;
16404 HRESULT hr;
16405 RECT r;
16406 BOOL all_pass;
16408 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
16409 static struct
16411 struct vec3 position;
16412 DWORD diffuse;
16414 quad[] =
16416 {{-1.0f, -1.0f, 0.1f}, 0xff00ff00},
16417 {{-1.0f, 1.0f, 0.0f}, 0xff00ff00},
16418 {{ 1.0f, -1.0f, 1.0f}, 0xff00ff00},
16419 {{ 1.0f, 1.0f, 0.9f}, 0xff00ff00},
16422 static const struct
16424 unsigned int z_depth, s_depth, z_mask, s_mask;
16425 BOOL todo;
16427 tests[] =
16429 {16, 0, 0x0000ffff, 0x00000000},
16430 {24, 0, 0x00ffffff, 0x00000000},
16431 {32, 0, 0x00ffffff, 0x00000000},
16432 {32, 8, 0x00ffffff, 0xff000000, TRUE},
16433 {32, 0, 0xffffffff, 0x00000000},
16436 window = create_window();
16437 ok(!!window, "Failed to create a window.\n");
16439 if (!(device = create_device(window, DDSCL_NORMAL)))
16441 skip("Failed to create a D3D device, skipping tests.\n");
16442 DestroyWindow(window);
16443 return;
16446 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
16447 ok(SUCCEEDED(hr), "Failed to get Direct3D3 interface, hr %#lx.\n", hr);
16448 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
16449 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#lx.\n", hr);
16451 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
16452 ok(SUCCEEDED(hr), "Failed to get render target, hr %#lx.\n", hr);
16453 viewport = create_viewport(device, 0, 0, 640, 480);
16454 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
16455 ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#lx.\n", hr);
16457 ds = get_depth_stencil(device);
16458 hr = IDirectDrawSurface4_DeleteAttachedSurface(rt, 0, ds);
16459 ok(SUCCEEDED(hr), "Failed to detach depth buffer, hr %#lx.\n", hr);
16460 IDirectDrawSurface4_Release(ds);
16462 for (i = 0; i < ARRAY_SIZE(tests); ++i)
16464 memset(&surface_desc, 0, sizeof(surface_desc));
16465 surface_desc.dwSize = sizeof(surface_desc);
16466 surface_desc.dwFlags = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT;
16467 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | DDSCAPS_VIDEOMEMORY;
16468 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
16469 surface_desc.ddpfPixelFormat.dwFlags = DDPF_ZBUFFER;
16470 if (tests[i].s_depth)
16471 surface_desc.ddpfPixelFormat.dwFlags |= DDPF_STENCILBUFFER;
16472 surface_desc.ddpfPixelFormat.dwZBufferBitDepth = tests[i].z_depth;
16473 surface_desc.ddpfPixelFormat.dwStencilBitDepth = tests[i].s_depth;
16474 surface_desc.ddpfPixelFormat.dwZBitMask = tests[i].z_mask;
16475 surface_desc.ddpfPixelFormat.dwStencilBitMask = tests[i].s_mask;
16476 surface_desc.dwWidth = 640;
16477 surface_desc.dwHeight = 480;
16478 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &ds, NULL);
16479 if (FAILED(hr))
16481 skip("Format %u not supported, skipping test.\n", i);
16482 continue;
16485 hr = IDirectDrawSurface_AddAttachedSurface(rt, ds);
16486 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#lx.\n", hr);
16487 hr = IDirect3DDevice3_SetRenderTarget(device, rt, 0);
16488 ok(SUCCEEDED(hr), "Failed to set render target, hr %#lx.\n", hr);
16490 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect,
16491 D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff0000ff, 1.0f, 0);
16492 ok(SUCCEEDED(hr), "Failed to clear, hr %#lx.\n", hr);
16493 hr = IDirect3DDevice3_BeginScene(device);
16494 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#lx.\n", hr);
16495 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE, quad, 4, 0);
16496 ok(SUCCEEDED(hr), "Failed to draw, hr %#lx.\n", hr);
16497 hr = IDirect3DDevice3_EndScene(device);
16498 ok(SUCCEEDED(hr), "Failed to end scene, hr %#lx.\n", hr);
16500 all_pass = TRUE;
16501 for (y = 60; y < 480; y += 120)
16503 for (x = 80; x < 640; x += 160)
16505 SetRect(&r, x, y, x + 1, y + 1);
16506 memset(&surface_desc, 0, sizeof(surface_desc));
16507 surface_desc.dwSize = sizeof(surface_desc);
16508 hr = IDirectDrawSurface4_Lock(ds, &r, &surface_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
16509 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#lx.\n", hr);
16511 depth = *((DWORD *)surface_desc.lpSurface) & tests[i].z_mask;
16512 expected_depth = (x * (0.9 / 640.0) + y * (0.1 / 480.0)) * tests[i].z_mask;
16513 max_diff = ((0.5f * 0.9f) / 640.0f) * tests[i].z_mask;
16514 /* The ddraw4 version of this test behaves similarly to the ddraw7 version on Nvidia GPUs,
16515 * except that Geforce 7 also returns garbage data in D24S8, whereas the ddraw7 version
16516 * returns 0 for that format. Give up on pre-filtering formats, accept Nvidia as generally
16517 * broken here, but still expect at least one format (D16 or D24X8 in practise) to pass.
16519 * Some of the tested places pass on some GPUs on Wine by accident. */
16520 todo_wine_if(tests[i].todo && !compare_uint(expected_depth, depth, max_diff))
16521 ok(compare_uint(expected_depth, depth, max_diff) || ddraw_is_nvidia(ddraw)
16522 || (ddraw_is_amd(ddraw) && !tests[i].s_depth && tests[i].z_mask == 0x00ffffff),
16523 "Test %u: Got depth 0x%08x (diff %d), expected 0x%08x+/-%u, at %u, %u.\n",
16524 i, depth, expected_depth - depth, expected_depth, max_diff, x, y);
16525 if (!compare_uint(expected_depth, depth, max_diff))
16526 all_pass = FALSE;
16528 hr = IDirectDrawSurface4_Unlock(ds, &r);
16529 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx.\n", hr);
16533 if (all_pass)
16534 passed_fmts++;
16536 hr = IDirectDrawSurface4_DeleteAttachedSurface(rt, 0, ds);
16537 ok(SUCCEEDED(hr), "Failed to detach depth buffer, hr %#lx.\n", hr);
16538 IDirectDrawSurface4_Release(ds);
16541 ok(passed_fmts, "Not a single format passed the tests, this is bad even by Nvidia's standards.\n");
16543 destroy_viewport(device, viewport);
16544 IDirectDrawSurface4_Release(rt);
16545 IDirectDraw4_Release(ddraw);
16546 IDirect3D3_Release(d3d);
16547 refcount = IDirect3DDevice3_Release(device);
16548 ok(!refcount, "Device has %lu references left.\n", refcount);
16549 DestroyWindow(window);
16552 static void test_clear(void)
16554 D3DRECT rect_negneg, rect_full = {{0}, {0}, {640}, {480}};
16555 IDirect3DViewport3 *viewport, *viewport2, *viewport3;
16556 IDirect3DDevice3 *device;
16557 IDirectDrawSurface4 *rt;
16558 IDirectDraw4 *ddraw;
16559 unsigned int color;
16560 IDirect3D3 *d3d;
16561 D3DRECT rect[2];
16562 ULONG refcount;
16563 HWND window;
16564 HRESULT hr;
16566 window = create_window();
16567 if (!(device = create_device(window, DDSCL_NORMAL)))
16569 skip("Failed to create 3D device.\n");
16570 DestroyWindow(window);
16571 return;
16574 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
16575 ok(SUCCEEDED(hr), "Failed to get Direct3D3 interface, hr %#lx.\n", hr);
16576 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
16577 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#lx.\n", hr);
16579 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
16580 ok(SUCCEEDED(hr), "Failed to get render target, hr %#lx.\n", hr);
16582 viewport = create_viewport(device, 0, 0, 640, 480);
16583 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
16584 ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#lx.\n", hr);
16586 hr = IDirect3DViewport3_Clear2(viewport, 1, &rect_full, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
16587 ok(SUCCEEDED(hr), "Failed to clear, hr %#lx.\n", hr);
16589 /* Positive x, negative y. */
16590 rect[0].x1 = 0;
16591 rect[0].y1 = 480;
16592 rect[0].x2 = 320;
16593 rect[0].y2 = 240;
16595 /* Positive x, positive y. */
16596 rect[1].x1 = 0;
16597 rect[1].y1 = 0;
16598 rect[1].x2 = 320;
16599 rect[1].y2 = 240;
16601 /* Clear 2 rectangles with one call. Unlike d3d8/9, the refrast does not
16602 * refuse negative rectangles, but it will not clear them either. */
16603 hr = IDirect3DViewport3_Clear2(viewport, 2, rect, D3DCLEAR_TARGET, 0xffff0000, 0.0f, 0);
16604 ok(SUCCEEDED(hr), "Failed to clear, hr %#lx.\n", hr);
16606 color = get_surface_color(rt, 160, 360);
16607 ok(compare_color(color, 0x00ffffff, 0), "Clear rectangle 3 (pos, neg) has color 0x%08x.\n", color);
16608 color = get_surface_color(rt, 160, 120);
16609 ok(compare_color(color, 0x00ff0000, 0), "Clear rectangle 1 (pos, pos) has color 0x%08x.\n", color);
16610 color = get_surface_color(rt, 480, 360);
16611 ok(compare_color(color, 0x00ffffff, 0), "Clear rectangle 4 (NULL) has color 0x%08x.\n", color);
16612 color = get_surface_color(rt, 480, 120);
16613 ok(compare_color(color, 0x00ffffff, 0), "Clear rectangle 4 (neg, neg) has color 0x%08x.\n", color);
16615 hr = IDirect3DViewport3_Clear2(viewport, 1, &rect_full, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
16616 ok(SUCCEEDED(hr), "Failed to clear, hr %#lx.\n", hr);
16617 /* negative x, negative y.
16618 * Also ignored, except on WARP, which clears the entire screen. */
16619 rect_negneg.x1 = 640;
16620 rect_negneg.y1 = 240;
16621 rect_negneg.x2 = 320;
16622 rect_negneg.y2 = 0;
16623 hr = IDirect3DViewport3_Clear2(viewport, 1, &rect_negneg, D3DCLEAR_TARGET, 0xff00ff00, 0.0f, 0);
16624 ok(SUCCEEDED(hr), "Failed to clear, hr %#lx.\n", hr);
16626 color = get_surface_color(rt, 160, 360);
16627 ok(compare_color(color, 0x00ffffff, 0)
16628 || broken(ddraw_is_warp(ddraw) && compare_color(color, 0x0000ff00, 0)),
16629 "Got unexpected color 0x%08x.\n", color);
16630 color = get_surface_color(rt, 160, 120);
16631 ok(compare_color(color, 0x00ffffff, 0)
16632 || broken(ddraw_is_warp(ddraw) && compare_color(color, 0x0000ff00, 0)),
16633 "Got unexpected color 0x%08x.\n", color);
16634 color = get_surface_color(rt, 480, 360);
16635 ok(compare_color(color, 0x00ffffff, 0)
16636 || broken(ddraw_is_warp(ddraw) && compare_color(color, 0x0000ff00, 0)),
16637 "Got unexpected color 0x%08x.\n", color);
16638 color = get_surface_color(rt, 480, 120);
16639 ok(compare_color(color, 0x00ffffff, 0)
16640 || broken(ddraw_is_warp(ddraw) && compare_color(color, 0x0000ff00, 0)),
16641 "Got unexpected color 0x%08x.\n", color);
16643 /* Test how the viewport affects clears. */
16644 hr = IDirect3DViewport3_Clear2(viewport, 1, &rect_full, D3DCLEAR_TARGET, 0xffffffff, 0.0f, 0);
16645 ok(SUCCEEDED(hr), "Failed to clear, hr %#lx.\n", hr);
16647 viewport2 = create_viewport(device, 160, 120, 160, 120);
16648 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport2);
16649 ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#lx.\n", hr);
16651 hr = IDirect3DViewport3_Clear2(viewport2, 1, &rect_full, D3DCLEAR_TARGET, 0xff0000ff, 0.0f, 0);
16652 ok(SUCCEEDED(hr), "Failed to clear, hr %#lx.\n", hr);
16654 viewport3 = create_viewport(device, 320, 240, 320, 240);
16655 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport3);
16656 ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#lx.\n", hr);
16658 rect[0].x1 = 160;
16659 rect[0].y1 = 120;
16660 rect[0].x2 = 480;
16661 rect[0].y2 = 360;
16662 hr = IDirect3DViewport3_Clear2(viewport3, 1, &rect[0], D3DCLEAR_TARGET, 0xff00ff00, 0.0f, 0);
16663 ok(SUCCEEDED(hr), "Failed to clear, hr %#lx.\n", hr);
16665 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
16666 ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#lx.\n", hr);
16668 color = get_surface_color(rt, 158, 118);
16669 ok(compare_color(color, 0x00ffffff, 0), "(158, 118) has color 0x%08x.\n", color);
16670 color = get_surface_color(rt, 162, 118);
16671 ok(compare_color(color, 0x00ffffff, 0), "(162, 118) has color 0x%08x.\n", color);
16672 color = get_surface_color(rt, 158, 122);
16673 ok(compare_color(color, 0x00ffffff, 0), "(158, 122) has color 0x%08x.\n", color);
16674 color = get_surface_color(rt, 162, 122);
16675 ok(compare_color(color, 0x000000ff, 0), "(162, 122) has color 0x%08x.\n", color);
16677 color = get_surface_color(rt, 318, 238);
16678 ok(compare_color(color, 0x000000ff, 0), "(318, 238) has color 0x%08x.\n", color);
16679 color = get_surface_color(rt, 322, 238);
16680 ok(compare_color(color, 0x00ffffff, 0), "(322, 328) has color 0x%08x.\n", color);
16681 color = get_surface_color(rt, 318, 242);
16682 ok(compare_color(color, 0x00ffffff, 0), "(318, 242) has color 0x%08x.\n", color);
16683 color = get_surface_color(rt, 322, 242);
16684 ok(compare_color(color, 0x0000ff00, 0), "(322, 242) has color 0x%08x.\n", color);
16686 color = get_surface_color(rt, 478, 358);
16687 ok(compare_color(color, 0x0000ff00, 0), "(478, 358) has color 0x%08x.\n", color);
16688 color = get_surface_color(rt, 482, 358);
16689 ok(compare_color(color, 0x00ffffff, 0), "(482, 358) has color 0x%08x.\n", color);
16690 color = get_surface_color(rt, 478, 362);
16691 ok(compare_color(color, 0x00ffffff, 0), "(478, 362) has color 0x%08x.\n", color);
16692 color = get_surface_color(rt, 482, 362);
16693 ok(compare_color(color, 0x00ffffff, 0), "(482, 362) has color 0x%08x.\n", color);
16695 /* The clear rectangle is rendertarget absolute, not relative to the
16696 * viewport. */
16697 hr = IDirect3DViewport3_Clear2(viewport, 1, &rect_full, D3DCLEAR_TARGET, 0xffffffff, 0.0f, 0);
16698 ok(SUCCEEDED(hr), "Failed to clear, hr %#lx.\n", hr);
16699 rect[0].x1 = 330;
16700 rect[0].y1 = 250;
16701 rect[0].x2 = 340;
16702 rect[0].y2 = 260;
16703 hr = IDirect3DViewport3_Clear2(viewport3, 1, &rect[0], D3DCLEAR_TARGET, 0xff00ff00, 0.0f, 0);
16704 ok(SUCCEEDED(hr), "Failed to clear, hr %#lx.\n", hr);
16706 color = get_surface_color(rt, 328, 248);
16707 ok(compare_color(color, 0x00ffffff, 0), "(328, 248) has color 0x%08x.\n", color);
16708 color = get_surface_color(rt, 332, 248);
16709 ok(compare_color(color, 0x00ffffff, 0), "(332, 248) has color 0x%08x.\n", color);
16710 color = get_surface_color(rt, 328, 252);
16711 ok(compare_color(color, 0x00ffffff, 0), "(328, 252) has color 0x%08x.\n", color);
16712 color = get_surface_color(rt, 332, 252);
16713 ok(compare_color(color, 0x0000ff00, 0), "(332, 252) has color 0x%08x.\n", color);
16715 color = get_surface_color(rt, 338, 248);
16716 ok(compare_color(color, 0x00ffffff, 0), "(338, 248) has color 0x%08x.\n", color);
16717 color = get_surface_color(rt, 342, 248);
16718 ok(compare_color(color, 0x00ffffff, 0), "(342, 248) has color 0x%08x.\n", color);
16719 color = get_surface_color(rt, 338, 252);
16720 ok(compare_color(color, 0x0000ff00, 0), "(338, 252) has color 0x%08x.\n", color);
16721 color = get_surface_color(rt, 342, 252);
16722 ok(compare_color(color, 0x00ffffff, 0), "(342, 252) has color 0x%08x.\n", color);
16724 color = get_surface_color(rt, 328, 258);
16725 ok(compare_color(color, 0x00ffffff, 0), "(328, 258) has color 0x%08x.\n", color);
16726 color = get_surface_color(rt, 332, 258);
16727 ok(compare_color(color, 0x0000ff00, 0), "(332, 258) has color 0x%08x.\n", color);
16728 color = get_surface_color(rt, 328, 262);
16729 ok(compare_color(color, 0x00ffffff, 0), "(328, 262) has color 0x%08x.\n", color);
16730 color = get_surface_color(rt, 332, 262);
16731 ok(compare_color(color, 0x00ffffff, 0), "(332, 262) has color 0x%08x.\n", color);
16733 color = get_surface_color(rt, 338, 258);
16734 ok(compare_color(color, 0x0000ff00, 0), "(338, 258) has color 0x%08x.\n", color);
16735 color = get_surface_color(rt, 342, 258);
16736 ok(compare_color(color, 0x00ffffff, 0), "(342, 258) has color 0x%08x.\n", color);
16737 color = get_surface_color(rt, 338, 262);
16738 ok(compare_color(color, 0x00ffffff, 0), "(338, 262) has color 0x%08x.\n", color);
16739 color = get_surface_color(rt, 342, 262);
16740 ok(compare_color(color, 0x00ffffff, 0), "(342, 262) has color 0x%08x.\n", color);
16742 /* COLORWRITEENABLE, SRGBWRITEENABLE and scissor rectangles do not exist
16743 * in d3d3. */
16745 IDirect3DViewport3_Release(viewport3);
16746 IDirect3DViewport3_Release(viewport2);
16747 IDirect3DViewport3_Release(viewport);
16748 IDirectDrawSurface4_Release(rt);
16749 IDirectDraw4_Release(ddraw);
16750 IDirect3D3_Release(d3d);
16751 refcount = IDirect3DDevice3_Release(device);
16752 ok(!refcount, "Device has %lu references left.\n", refcount);
16753 DestroyWindow(window);
16756 struct enum_surfaces_param
16758 IDirectDraw4 *ddraw;
16759 DDSURFACEDESC2 modes[20];
16760 unsigned int mode_count;
16762 IDirectDrawSurface4 *surfaces[8];
16763 unsigned int count;
16766 static HRESULT CALLBACK build_mode_list_cb(DDSURFACEDESC2 *desc, void *context)
16768 struct enum_surfaces_param *param = context;
16769 IDirectDrawSurface4 *surface;
16771 if (SUCCEEDED(IDirectDraw4_CreateSurface(param->ddraw, desc, &surface, NULL)))
16773 if (param->mode_count < ARRAY_SIZE(param->modes))
16774 param->modes[param->mode_count] = *desc;
16775 ++param->mode_count;
16776 IDirectDrawSurface4_Release(surface);
16779 return DDENUMRET_OK;
16782 static HRESULT WINAPI enum_surfaces_cb(IDirectDrawSurface4 *surface, DDSURFACEDESC2 *desc, void *context)
16784 struct enum_surfaces_param *param = context;
16785 BOOL found = FALSE;
16786 unsigned int i;
16788 for (i = 0; i < ARRAY_SIZE(param->surfaces); ++i)
16790 if (param->surfaces[i] == surface)
16792 found = TRUE;
16793 break;
16797 ok(found, "Unexpected surface %p enumerated.\n", surface);
16798 IDirectDrawSurface4_Release(surface);
16799 ++param->count;
16801 return DDENUMRET_OK;
16804 static HRESULT WINAPI enum_surfaces_create_cb(IDirectDrawSurface4 *surface, DDSURFACEDESC2 *desc, void *context)
16806 static const DWORD expect_flags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH | DDSD_PIXELFORMAT;
16807 struct enum_surfaces_param *param = context;
16809 ok(!surface, "Unexpected surface %p.\n", surface);
16810 ok((desc->dwFlags & expect_flags) == expect_flags, "Got unexpected flags %#lx.\n", desc->dwFlags);
16811 if (param->count < ARRAY_SIZE(param->modes))
16813 const DDSURFACEDESC2 *expect = &param->modes[param->count];
16814 ok(desc->dwWidth == expect->dwWidth, "Expected width %lu, got %lu.\n", expect->dwWidth, desc->dwWidth);
16815 ok(desc->dwHeight == expect->dwHeight, "Expected height %lu, got %lu.\n", expect->dwHeight, desc->dwHeight);
16816 ok(!memcmp(&desc->ddpfPixelFormat, &expect->ddpfPixelFormat, sizeof(desc->ddpfPixelFormat)),
16817 "Pixel formats didn't match.\n");
16820 ++param->count;
16822 return DDENUMRET_OK;
16825 static void test_enum_surfaces(void)
16827 struct enum_surfaces_param param = {0};
16828 DDPIXELFORMAT current_format;
16829 DDSURFACEDESC2 desc;
16830 IDirectDraw4 *ddraw;
16831 HRESULT hr;
16833 ddraw = create_ddraw();
16834 ok(!!ddraw, "Failed to create a ddraw object.\n");
16835 param.ddraw = ddraw;
16837 memset(&desc, 0, sizeof(desc));
16838 desc.dwSize = sizeof(desc);
16839 hr = IDirectDraw4_GetDisplayMode(ddraw, &desc);
16840 ok(hr == DD_OK, "Failed to get display mode, hr %#lx.\n", hr);
16841 current_format = desc.ddpfPixelFormat;
16843 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
16844 ok(hr == DD_OK, "Failed to set cooperative level, hr %#lx.\n", hr);
16846 hr = IDirectDraw4_EnumSurfaces(ddraw, DDENUMSURFACES_ALL, NULL, NULL, enum_surfaces_cb);
16847 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
16849 hr = IDirectDraw4_EnumSurfaces(ddraw, DDENUMSURFACES_CANBECREATED | DDENUMSURFACES_ALL,
16850 NULL, NULL, enum_surfaces_cb);
16851 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
16853 memset(&desc, 0, sizeof(desc));
16854 desc.dwSize = sizeof(desc);
16855 desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_MIPMAPCOUNT;
16856 desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
16857 desc.dwMipMapCount = 3;
16858 desc.dwWidth = 32;
16859 desc.dwHeight = 32;
16860 hr = IDirectDraw4_CreateSurface(ddraw, &desc, &param.surfaces[0], NULL);
16861 ok(hr == DD_OK, "Failed to create a surface, hr %#lx.\n", hr);
16863 hr = IDirectDrawSurface4_GetAttachedSurface(param.surfaces[0], &desc.ddsCaps, &param.surfaces[1]);
16864 ok(hr == DD_OK, "Failed to get attached surface, hr %#lx.\n", hr);
16865 hr = IDirectDrawSurface4_GetAttachedSurface(param.surfaces[1], &desc.ddsCaps, &param.surfaces[2]);
16866 ok(hr == DD_OK, "Failed to get attached surface, hr %#lx.\n", hr);
16867 hr = IDirectDrawSurface4_GetAttachedSurface(param.surfaces[2], &desc.ddsCaps, &param.surfaces[3]);
16868 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#lx.\n", hr);
16869 ok(!param.surfaces[3], "Got unexpected pointer %p.\n", param.surfaces[3]);
16871 param.count = 0;
16872 hr = IDirectDraw4_EnumSurfaces(ddraw, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_ALL,
16873 &desc, &param, enum_surfaces_cb);
16874 ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#lx.\n", hr);
16875 ok(param.count == 3, "Got unexpected number of enumerated surfaces %u.\n", param.count);
16877 param.count = 0;
16878 hr = IDirectDraw4_EnumSurfaces(ddraw, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_ALL,
16879 NULL, &param, enum_surfaces_cb);
16880 ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#lx.\n", hr);
16881 ok(param.count == 3, "Got unexpected number of enumerated surfaces %u.\n", param.count);
16883 desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
16884 param.count = 0;
16885 hr = IDirectDraw4_EnumSurfaces(ddraw, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_MATCH,
16886 &desc, &param, enum_surfaces_cb);
16887 ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#lx.\n", hr);
16888 ok(param.count == 1, "Got unexpected number of enumerated surfaces %u.\n", param.count);
16890 param.count = 0;
16891 hr = IDirectDraw4_EnumSurfaces(ddraw, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_NOMATCH,
16892 &desc, &param, enum_surfaces_cb);
16893 ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#lx.\n", hr);
16894 ok(param.count == 2, "Got unexpected number of enumerated surfaces %u.\n", param.count);
16896 desc.dwFlags = 0;
16897 param.count = 0;
16898 hr = IDirectDraw4_EnumSurfaces(ddraw, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_MATCH,
16899 &desc, &param, enum_surfaces_cb);
16900 ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#lx.\n", hr);
16901 ok(param.count == 3, "Got unexpected number of enumerated surfaces %u.\n", param.count);
16903 desc.dwFlags = 0;
16904 param.count = 0;
16905 hr = IDirectDraw4_EnumSurfaces(ddraw, DDENUMSURFACES_DOESEXIST, &desc, &param, enum_surfaces_cb);
16906 ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#lx.\n", hr);
16907 ok(param.count == 3, "Got unexpected number of enumerated surfaces %u.\n", param.count);
16909 IDirectDrawSurface4_Release(param.surfaces[2]);
16910 IDirectDrawSurface4_Release(param.surfaces[1]);
16911 IDirectDrawSurface4_Release(param.surfaces[0]);
16913 param.count = 0;
16914 hr = IDirectDraw4_EnumSurfaces(ddraw, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_ALL,
16915 NULL, &param, enum_surfaces_cb);
16916 ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#lx.\n", hr);
16917 ok(!param.count, "Got unexpected number of enumerated surfaces %u.\n", param.count);
16919 memset(&desc, 0, sizeof(desc));
16920 desc.dwSize = sizeof(desc);
16921 desc.dwFlags = DDSD_CAPS;
16922 desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
16924 hr = IDirectDraw4_EnumSurfaces(ddraw, DDENUMSURFACES_CANBECREATED | DDENUMSURFACES_ALL,
16925 &desc, &param, enum_surfaces_create_cb);
16926 ok(hr == DDERR_INVALIDPARAMS, "Failed to enumerate surfaces, hr %#lx.\n", hr);
16928 hr = IDirectDraw4_EnumSurfaces(ddraw, DDENUMSURFACES_CANBECREATED | DDENUMSURFACES_NOMATCH,
16929 &desc, &param, enum_surfaces_create_cb);
16930 ok(hr == DDERR_INVALIDPARAMS, "Failed to enumerate surfaces, hr %#lx.\n", hr);
16932 hr = IDirectDraw4_EnumSurfaces(ddraw, DDENUMSURFACES_CANBECREATED,
16933 &desc, &param, enum_surfaces_create_cb);
16934 ok(hr == DDERR_INVALIDPARAMS, "Failed to enumerate surfaces, hr %#lx.\n", hr);
16936 /* When not passed width and height, the callback is called with every
16937 * available display resolution. */
16939 param.mode_count = 0;
16940 desc.dwFlags |= DDSD_PIXELFORMAT;
16941 desc.ddpfPixelFormat = current_format;
16942 hr = IDirectDraw4_EnumDisplayModes(ddraw, 0, &desc, &param, build_mode_list_cb);
16943 ok(hr == DD_OK, "Failed to build mode list, hr %#lx.\n", hr);
16945 param.count = 0;
16946 desc.dwFlags &= ~DDSD_PIXELFORMAT;
16947 hr = IDirectDraw4_EnumSurfaces(ddraw, DDENUMSURFACES_CANBECREATED | DDENUMSURFACES_MATCH,
16948 &desc, &param, enum_surfaces_create_cb);
16949 ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#lx.\n", hr);
16950 ok(param.count == param.mode_count, "Expected %u surfaces, got %u.\n", param.mode_count, param.count);
16952 desc.dwFlags |= DDSD_WIDTH | DDSD_HEIGHT;
16953 desc.dwWidth = desc.dwHeight = 32;
16955 param.modes[0].dwWidth = param.modes[0].dwHeight = 32;
16957 param.count = 0;
16958 hr = IDirectDraw4_EnumSurfaces(ddraw, DDENUMSURFACES_CANBECREATED | DDENUMSURFACES_MATCH,
16959 &desc, &param, enum_surfaces_create_cb);
16960 ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#lx.\n", hr);
16961 ok(param.count == 1, "Got unexpected number of enumerated surfaces %u.\n", param.count);
16963 hr = IDirectDraw4_CreateSurface(ddraw, &desc, &param.surfaces[0], NULL);
16964 ok(hr == DD_OK, "Failed to create surface, hr %#lx.\n", hr);
16965 param.count = 0;
16966 hr = IDirectDraw4_EnumSurfaces(ddraw, DDENUMSURFACES_CANBECREATED | DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_MATCH,
16967 &desc, &param, enum_surfaces_create_cb);
16968 ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#lx.\n", hr);
16969 ok(param.count == 1, "Got unexpected number of enumerated surfaces %u.\n", param.count);
16970 IDirectDrawSurface4_Release(param.surfaces[0]);
16972 desc.dwFlags |= DDSD_PIXELFORMAT;
16973 desc.ddpfPixelFormat.dwSize = sizeof(desc.ddpfPixelFormat);
16974 desc.ddpfPixelFormat.dwFlags = DDPF_FOURCC;
16975 desc.ddpfPixelFormat.dwFourCC = 0xdeadbeef;
16977 param.count = 0;
16978 hr = IDirectDraw4_EnumSurfaces(ddraw, DDENUMSURFACES_CANBECREATED | DDENUMSURFACES_MATCH,
16979 &desc, &param, enum_surfaces_create_cb);
16980 ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#lx.\n", hr);
16981 ok(!param.count, "Got unexpected number of enumerated surfaces %u.\n", param.count);
16983 IDirectDraw4_Release(ddraw);
16986 static void test_viewport(void)
16988 static struct
16990 D3DVIEWPORT7 vp;
16991 RECT expected_rect;
16992 const char *message;
16994 tests[] =
16996 {{ 0, 0, 640, 480}, { 0, 120, 479, 359}, "Viewport (0, 0) - (640, 480)"},
16997 {{ 0, 0, 320, 240}, { 0, 60, 239, 179}, "Viewport (0, 0) - (320, 240)"},
16998 {{ 0, 0, 1280, 960}, { 0, 240, 639, 479}, "Viewport (0, 0) - (1280, 960)"},
16999 {{ 0, 0, 2000, 1600}, { 0, 400, 639, 479}, "Viewport (0, 0) - (2000, 1600)"},
17000 {{100, 100, 640, 480}, {100, 220, 579, 459}, "Viewport (100, 100) - (640, 480)"},
17001 {{ 0, 0, 8192, 8192}, {-10, -10, -10, -10}, "Viewport (0, 0) - (8192, 8192)"},
17003 static const struct
17005 unsigned int x, y;
17007 rt_sizes[] =
17009 {640, 480}, {1280, 960}, {320, 240}, {800, 600},
17011 static D3DMATRIX mat =
17013 1.0f, 0.0f, 0.0f, 0.0f,
17014 0.0f, 1.0f, 0.0f, 0.0f,
17015 0.0f, 0.0f, 1.0f, 0.0f,
17016 0.0f, 0.0f, 0.0f, 1.0f,
17018 static struct vec3 quad[] =
17020 {-1.5f, -0.5f, 0.1f},
17021 {-1.5f, 0.5f, 0.1f},
17022 { 0.5f, -0.5f, 0.1f},
17023 { 0.5f, 0.5f, 0.1f},
17025 IDirect3DViewport3 *viewport, *full_viewport;
17026 IDirectDrawSurface4 *rt, *ds;
17027 DDSURFACEDESC2 surface_desc;
17028 IDirect3DDevice3 *device;
17029 BOOL expected_failure;
17030 IDirectDraw4 *ddraw;
17031 DDPIXELFORMAT z_fmt;
17032 D3DRECT clear_rect;
17033 unsigned int i, j;
17034 IDirect3D3 *d3d;
17035 D3DVIEWPORT2 vp;
17036 ULONG refcount;
17037 HWND window;
17038 HRESULT hr;
17040 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
17041 0, 0, 640, 480, 0, 0, 0, 0);
17042 if (!(device = create_device(window, DDSCL_NORMAL)))
17044 skip("Failed to create a 3D device, skipping test.\n");
17045 DestroyWindow(window);
17046 return;
17049 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
17050 ok(SUCCEEDED(hr), "Failed to get Direct3D3 interface, hr %#lx.\n", hr);
17051 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
17052 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#lx.\n", hr);
17054 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
17055 ok(SUCCEEDED(hr), "Failed to disable depth test, hr %#lx.\n", hr);
17056 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_CULLMODE, D3DCULL_NONE);
17057 ok(SUCCEEDED(hr), "Failed to disable culling, hr %#lx.\n", hr);
17059 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &mat);
17060 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#lx.\n", hr);
17061 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_VIEW, &mat);
17062 ok(SUCCEEDED(hr), "Failed to set view transform, hr %#lx.\n", hr);
17063 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &mat);
17064 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#lx.\n", hr);
17066 ds = get_depth_stencil(device);
17067 memset(&surface_desc, 0, sizeof(surface_desc));
17068 surface_desc.dwSize = sizeof(surface_desc);
17069 hr = IDirectDrawSurface4_GetSurfaceDesc(ds, &surface_desc);
17070 z_fmt = surface_desc.ddpfPixelFormat;
17072 for (i = 0; i < ARRAY_SIZE(rt_sizes); ++i)
17074 winetest_push_context("Size %ux%u", rt_sizes[i].x, rt_sizes[i].y);
17076 if (i)
17078 memset(&surface_desc, 0, sizeof(surface_desc));
17079 surface_desc.dwSize = sizeof(surface_desc);
17080 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
17081 surface_desc.dwWidth = rt_sizes[i].x;
17082 surface_desc.dwHeight = rt_sizes[i].y;
17083 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
17084 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &rt, NULL);
17085 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17087 surface_desc.dwFlags = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT;
17088 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
17089 surface_desc.ddpfPixelFormat = z_fmt;
17090 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &ds, NULL);
17091 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17092 hr = IDirectDrawSurface4_AddAttachedSurface(rt, ds);
17093 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17095 hr = IDirect3DDevice3_SetRenderTarget(device, rt, 0);
17096 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17098 else
17100 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
17101 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17104 full_viewport = create_viewport(device, 0, 0, rt_sizes[i].x, rt_sizes[i].y);
17106 clear_rect.x1 = clear_rect.y1 = 0;
17107 clear_rect.x2 = rt_sizes[i].x;
17108 clear_rect.y2 = rt_sizes[i].y;
17110 for (j = 0; j < ARRAY_SIZE(tests); ++j)
17112 winetest_push_context(tests[j].message);
17114 expected_failure = tests[j].vp.dwX + tests[j].vp.dwWidth > rt_sizes[i].x
17115 || tests[j].vp.dwY + tests[j].vp.dwHeight > rt_sizes[i].y;
17117 hr = IDirect3DViewport3_Clear2(full_viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xff000000, 0.0f, 0);
17118 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17120 hr = IDirect3D3_CreateViewport(d3d, &viewport, NULL);
17121 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17122 hr = IDirect3DViewport3_SetViewport2(viewport, NULL);
17123 ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr);
17124 memset(&vp, 0, sizeof(vp));
17125 vp.dwSize = sizeof(vp);
17126 vp.dwX = tests[j].vp.dwX;
17127 vp.dwY = tests[j].vp.dwY;
17128 vp.dwWidth = tests[j].vp.dwWidth;
17129 vp.dwHeight = tests[j].vp.dwHeight;
17130 vp.dvClipX = -1.0f;
17131 vp.dvClipY = 1.0f;
17132 vp.dvClipWidth = 2.0f;
17133 vp.dvClipHeight = 2.0f;
17134 vp.dvMinZ = 0.0f;
17135 vp.dvMaxZ = 1.0f;
17136 hr = IDirect3DViewport3_SetViewport2(viewport, &vp);
17137 ok(hr == D3DERR_VIEWPORTHASNODEVICE, "Got unexpected hr %#lx.\n", hr);
17138 hr = IDirect3DDevice3_AddViewport(device, viewport);
17139 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17140 hr = IDirect3DViewport3_SetViewport2(viewport, &vp);
17141 ok(hr == (expected_failure ? E_INVALIDARG : DD_OK), "Got unexpected hr %#lx.\n", hr);
17143 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
17144 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17145 if (expected_failure)
17147 destroy_viewport(device, viewport);
17148 winetest_pop_context();
17149 continue;
17152 hr = IDirect3DDevice3_BeginScene(device);
17153 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17154 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, quad, 4, 0);
17155 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17156 hr = IDirect3DDevice3_EndScene(device);
17157 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17159 check_rect(rt, tests[j].expected_rect);
17161 destroy_viewport(device, viewport);
17162 winetest_pop_context();
17165 destroy_viewport(device, full_viewport);
17167 hr = IDirectDrawSurface4_DeleteAttachedSurface(rt, 0, ds);
17168 ok(SUCCEEDED(hr), "Failed to detach surface, hr %#lx (i %u).\n", hr, i);
17169 IDirectDrawSurface4_Release(ds);
17171 IDirectDrawSurface4_Release(rt);
17173 winetest_pop_context();
17176 refcount = IDirect3DDevice3_Release(device);
17177 ok(!refcount, "Device has %lu references left.\n", refcount);
17178 IDirect3D3_Release(d3d);
17179 IDirectDraw4_Release(ddraw);
17180 DestroyWindow(window);
17183 static void test_find_device(void)
17185 D3DFINDDEVICESEARCH search = {0};
17186 D3DFINDDEVICERESULT result = {0};
17187 IDirect3DDevice3 *device;
17188 IDirectDraw4 *ddraw;
17189 IDirect3D3 *d3d;
17190 unsigned int i;
17191 HWND window;
17192 HRESULT hr;
17194 struct
17196 DWORD size;
17197 GUID guid;
17198 D3DDEVICEDESC_V1 hw_desc;
17199 D3DDEVICEDESC_V1 sw_desc;
17200 } result_v1;
17202 struct
17204 DWORD size;
17205 GUID guid;
17206 D3DDEVICEDESC_V2 hw_desc;
17207 D3DDEVICEDESC_V2 sw_desc;
17208 } result_v2;
17210 static const struct
17212 const GUID *guid;
17213 HRESULT hr;
17215 tests[] =
17217 {&IID_IDirect3D, DDERR_NOTFOUND},
17218 {&IID_IDirect3DRampDevice, DDERR_NOTFOUND},
17219 {&IID_IDirect3DRGBDevice, D3D_OK},
17220 {&IID_IDirect3DMMXDevice, DDERR_NOTFOUND},
17221 {&IID_IDirect3DRefDevice, DDERR_NOTFOUND},
17222 {&IID_IDirect3DTnLHalDevice, DDERR_NOTFOUND},
17223 {&IID_IDirect3DNullDevice, DDERR_NOTFOUND},
17226 ddraw = create_ddraw();
17227 ok(!!ddraw, "Failed to create a ddraw object.\n");
17229 if (FAILED(IDirectDraw4_QueryInterface(ddraw, &IID_IDirect3D3, (void **)&d3d)))
17231 skip("D3D interface is not available, skipping test.\n");
17232 IDirectDraw4_Release(ddraw);
17233 return;
17236 result.dwSize = sizeof(result);
17237 search.dwSize = sizeof(search);
17238 hr = IDirect3D3_FindDevice(d3d, NULL, NULL);
17239 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
17240 hr = IDirect3D3_FindDevice(d3d, NULL, &result);
17241 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
17242 hr = IDirect3D3_FindDevice(d3d, &search, NULL);
17243 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
17244 hr = IDirect3D3_FindDevice(d3d, &search, &result);
17245 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
17246 ok(result.dwSize == sizeof(result), "Got unexpected result size %lu.\n", result.dwSize);
17247 ok(result.ddHwDesc.dwSize == sizeof(result.ddHwDesc),
17248 "Got unexpected HW desc size %lu.\n", result.ddHwDesc.dwSize);
17249 ok(result.ddSwDesc.dwSize == sizeof(result.ddSwDesc),
17250 "Got unexpected SW desc size %lu.\n", result.ddSwDesc.dwSize);
17252 memset(&search, 0, sizeof(search));
17253 memset(&result, 0, sizeof(result));
17254 hr = IDirect3D3_FindDevice(d3d, &search, &result);
17255 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
17257 search.dwSize = sizeof(search) + 1;
17258 result.dwSize = sizeof(result) + 1;
17259 hr = IDirect3D3_FindDevice(d3d, &search, &result);
17260 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
17262 search.dwSize = sizeof(search);
17264 memset(&result_v1, 0, sizeof(result_v1));
17265 result_v1.size = sizeof(result_v1);
17266 hr = IDirect3D3_FindDevice(d3d, &search, (D3DFINDDEVICERESULT *)&result_v1);
17267 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
17268 ok(result_v1.hw_desc.dwSize == sizeof(result.ddHwDesc),
17269 "Got unexpected HW desc size %lu.\n", result_v1.hw_desc.dwSize);
17270 ok(result_v1.sw_desc.dwSize == sizeof(result.ddSwDesc),
17271 "Got unexpected SW desc size %lu.\n", result_v1.sw_desc.dwSize);
17273 memset(&result_v2, 0, sizeof(result_v2));
17274 result_v2.size = sizeof(result_v2);
17275 hr = IDirect3D3_FindDevice(d3d, &search, (D3DFINDDEVICERESULT *)&result_v2);
17276 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
17277 ok(result_v2.hw_desc.dwSize == sizeof(result.ddHwDesc),
17278 "Got unexpected HW desc size %lu.\n", result_v2.hw_desc.dwSize);
17279 ok(result_v2.sw_desc.dwSize == sizeof(result.ddSwDesc),
17280 "Got unexpected SW desc size %lu.\n", result_v2.sw_desc.dwSize);
17282 for (i = 0; i < ARRAY_SIZE(tests); ++i)
17284 memset(&search, 0, sizeof(search));
17285 search.dwSize = sizeof(search);
17286 search.dwFlags = D3DFDS_GUID;
17287 search.guid = *tests[i].guid;
17289 memset(&result, 0, sizeof(result));
17290 result.dwSize = sizeof(result);
17292 hr = IDirect3D3_FindDevice(d3d, &search, &result);
17293 ok(hr == tests[i].hr, "Test %u: Got unexpected hr %#lx.\n", i, hr);
17294 ok(result.dwSize == sizeof(result), "Test %u: Got unexpected result size %lu.\n", i, result.dwSize);
17295 if (SUCCEEDED(hr))
17297 ok(result.ddHwDesc.dwSize == sizeof(result.ddHwDesc),
17298 "Test %u: Got unexpected HW desc size %lu.\n", i, result.ddHwDesc.dwSize);
17299 ok(result.ddSwDesc.dwSize == sizeof(result.ddSwDesc),
17300 "Test %u: Got unexpected SW desc size %lu.\n", i, result.ddSwDesc.dwSize);
17302 else
17304 ok(!result.ddHwDesc.dwSize,
17305 "Test %u: Got unexpected HW desc size %lu.\n", i, result.ddHwDesc.dwSize);
17306 ok(!result.ddSwDesc.dwSize,
17307 "Test %u: Got unexpected SW desc size %lu.\n", i, result.ddSwDesc.dwSize);
17311 /* The HAL device can only be enumerated if hardware acceleration is present. */
17312 search.dwSize = sizeof(search);
17313 search.dwFlags = D3DFDS_GUID;
17314 search.guid = IID_IDirect3DHALDevice;
17315 result.dwSize = sizeof(result);
17316 hr = IDirect3D3_FindDevice(d3d, &search, &result);
17318 window = create_window();
17319 device = create_device(window, DDSCL_NORMAL);
17320 if (hr == D3D_OK)
17321 ok(!!device, "Failed to create a 3D device.\n");
17322 else
17323 ok(!device, "Succeeded to create a 3D device.\n");
17324 if (device)
17325 IDirect3DDevice3_Release(device);
17326 DestroyWindow(window);
17328 /* Curiously the colour model criteria seem to be ignored. */
17329 search.dwSize = sizeof(search);
17330 search.dwFlags = D3DFDS_COLORMODEL;
17331 search.dcmColorModel = 0xdeadbeef;
17332 result.dwSize = sizeof(result);
17333 hr = IDirect3D3_FindDevice(d3d, &search, &result);
17334 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
17336 IDirect3D3_Release(d3d);
17337 IDirectDraw4_Release(ddraw);
17340 static IDirectDraw4 *killfocus_ddraw;
17341 static IDirectDrawSurface4 *killfocus_surface;
17343 static LRESULT CALLBACK killfocus_proc(HWND window, UINT message, WPARAM wparam, LPARAM lparam)
17345 ULONG ref;
17347 if (message == WM_KILLFOCUS)
17349 ref = IDirectDrawSurface4_Release(killfocus_surface);
17350 ok(!ref, "Unexpected surface refcount %lu.\n", ref);
17351 ref = IDirectDraw4_Release(killfocus_ddraw);
17352 ok(!ref, "Unexpected ddraw refcount %lu.\n", ref);
17353 killfocus_ddraw = NULL;
17356 return DefWindowProcA(window, message, wparam, lparam);
17359 static void test_killfocus(void)
17361 DDSURFACEDESC2 surface_desc;
17362 HRESULT hr;
17363 HWND window;
17364 WNDCLASSA wc = {0};
17366 wc.lpfnWndProc = killfocus_proc;
17367 wc.lpszClassName = "ddraw_killfocus_wndproc_wc";
17368 ok(RegisterClassA(&wc), "Failed to register window class.\n");
17370 window = CreateWindowA("ddraw_killfocus_wndproc_wc", "d3d7_test", WS_OVERLAPPEDWINDOW,
17371 0, 0, 640, 480, 0, 0, 0, 0);
17373 killfocus_ddraw = create_ddraw();
17374 ok(!!killfocus_ddraw, "Failed to create a ddraw object.\n");
17376 hr = IDirectDraw4_SetCooperativeLevel(killfocus_ddraw, window, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
17377 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#lx.\n", hr);
17379 memset(&surface_desc, 0, sizeof(surface_desc));
17380 surface_desc.dwSize = sizeof(surface_desc);
17381 surface_desc.dwFlags = DDSD_CAPS;
17382 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
17383 hr = IDirectDraw4_CreateSurface(killfocus_ddraw, &surface_desc, &killfocus_surface, NULL);
17384 ok(SUCCEEDED(hr), "Failed to create surface, hr %#lx.\n", hr);
17386 SetForegroundWindow(GetDesktopWindow());
17387 ok(!killfocus_ddraw, "WM_KILLFOCUS was not received.\n");
17389 DestroyWindow(window);
17390 UnregisterClassA("ddraw_killfocus_wndproc_wc", GetModuleHandleA(NULL));
17393 static void test_sysmem_draw(void)
17395 D3DRECT rect_full = {{0}, {0}, {640}, {480}};
17396 IDirectDrawSurface4 *rt, *surface;
17397 IDirect3DViewport3 *viewport;
17398 DDSURFACEDESC2 surface_desc;
17399 D3DVERTEXBUFFERDESC vb_desc;
17400 IDirect3DTexture2 *texture;
17401 IDirect3DVertexBuffer *vb;
17402 IDirect3DDevice3 *device;
17403 IDirectDraw4 *ddraw;
17404 unsigned int color;
17405 IDirect3D3 *d3d;
17406 ULONG refcount;
17407 HWND window;
17408 HRESULT hr;
17409 BYTE *data;
17411 static const struct
17413 struct vec3 position;
17414 DWORD diffuse;
17416 quad[] =
17418 {{ 0.0f, 0.0f, 0.0f}, 0x00000000},
17419 {{ 0.0f, 0.0f, 0.0f}, 0x00000000},
17420 {{ 0.0f, 0.0f, 0.0f}, 0x00000000},
17421 {{ 0.0f, 0.0f, 0.0f}, 0x00000000},
17422 {{-1.0f, -1.0f, 0.0f}, 0xffff0000},
17423 {{-1.0f, 1.0f, 0.0f}, 0xff00ff00},
17424 {{ 1.0f, -1.0f, 0.0f}, 0xff0000ff},
17425 {{ 1.0f, 1.0f, 0.0f}, 0xffffffff},
17427 static WORD indices[] = {4, 5, 6, 7};
17429 window = create_window();
17430 ok(!!window, "Failed to create a window.\n");
17432 if (!(device = create_device(window, DDSCL_NORMAL)))
17434 skip("Failed to create a 3D device, skipping test.\n");
17435 DestroyWindow(window);
17436 return;
17439 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
17440 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17441 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
17442 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17443 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
17444 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17446 viewport = create_viewport(device, 0, 0, 640, 480);
17447 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
17448 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17450 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
17451 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17453 vb_desc.dwSize = sizeof(vb_desc);
17454 vb_desc.dwCaps = D3DVBCAPS_SYSTEMMEMORY;
17455 vb_desc.dwFVF = D3DFVF_XYZ | D3DFVF_DIFFUSE;
17456 vb_desc.dwNumVertices = ARRAY_SIZE(quad);
17457 hr = IDirect3D3_CreateVertexBuffer(d3d, &vb_desc, &vb, 0, NULL);
17458 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17460 hr = IDirect3DVertexBuffer_Lock(vb, 0, (void **)&data, NULL);
17461 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17462 memcpy(data, quad, sizeof(quad));
17463 hr = IDirect3DVertexBuffer_Unlock(vb);
17464 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17466 hr = IDirect3DViewport3_Clear2(viewport, 1, &rect_full, D3DCLEAR_TARGET, 0xffffffff, 0.0f, 0);
17467 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17469 hr = IDirect3DDevice3_BeginScene(device);
17470 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17471 hr = IDirect3DDevice3_DrawPrimitiveVB(device, D3DPT_TRIANGLESTRIP, vb, 4, 4, 0);
17472 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17473 hr = IDirect3DDevice3_EndScene(device);
17474 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17476 color = get_surface_color(rt, 320, 240);
17477 ok(compare_color(color, 0x00007f7f, 1), "Got unexpected color 0x%08x.\n", color);
17479 hr = IDirect3DViewport3_Clear2(viewport, 1, &rect_full, D3DCLEAR_TARGET, 0xffffffff, 0.0f, 0);
17480 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17482 hr = IDirect3DDevice3_BeginScene(device);
17483 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17484 hr = IDirect3DDevice3_DrawIndexedPrimitiveVB(device, D3DPT_TRIANGLESTRIP, vb, indices, 4, 0);
17485 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17486 hr = IDirect3DDevice3_EndScene(device);
17487 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17489 color = get_surface_color(rt, 320, 240);
17490 ok(compare_color(color, 0x00007f7f, 1), "Got unexpected color 0x%08x.\n", color);
17492 memset(&surface_desc, 0, sizeof(surface_desc));
17493 surface_desc.dwSize = sizeof(surface_desc);
17494 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
17495 surface_desc.dwHeight = 2;
17496 surface_desc.dwWidth = 2;
17497 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY;
17498 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
17499 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
17500 surface_desc.ddpfPixelFormat.dwRGBBitCount = 32;
17501 surface_desc.ddpfPixelFormat.dwRBitMask = 0x00ff0000;
17502 surface_desc.ddpfPixelFormat.dwGBitMask = 0x0000ff00;
17503 surface_desc.ddpfPixelFormat.dwBBitMask = 0x000000ff;
17504 surface_desc.ddpfPixelFormat.dwRGBAlphaBitMask = 0xff000000;
17505 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
17506 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17507 hr = IDirectDrawSurface4_QueryInterface(surface, &IID_IDirect3DTexture2, (void **)&texture);
17508 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17509 IDirectDrawSurface4_Release(surface);
17510 hr = IDirect3DDevice3_SetTexture(device, 0, texture);
17511 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
17513 hr = IDirect3DViewport3_Clear2(viewport, 1, &rect_full, D3DCLEAR_TARGET, 0xffffffff, 0.0f, 0);
17514 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
17516 hr = IDirect3DDevice3_BeginScene(device);
17517 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
17518 hr = IDirect3DDevice3_DrawPrimitiveVB(device, D3DPT_TRIANGLESTRIP, vb, 0, 4, 0);
17519 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
17520 hr = IDirect3DDevice3_EndScene(device);
17521 ok(hr == D3D_OK || hr == D3DERR_SCENE_END_FAILED, "Got unexpected hr %#lx.\n", hr);
17523 IDirect3DTexture2_Release(texture);
17524 IDirect3DVertexBuffer_Release(vb);
17525 IDirect3DViewport3_Release(viewport);
17526 IDirectDrawSurface4_Release(rt);
17527 IDirectDraw4_Release(ddraw);
17528 IDirect3D3_Release(d3d);
17529 refcount = IDirect3DDevice3_Release(device);
17530 ok(!refcount, "Device has %lu references left.\n", refcount);
17531 DestroyWindow(window);
17534 static void test_gdi_surface(void)
17536 IDirectDrawSurface4 *primary, *backbuffer, *gdi_surface;
17537 DDSCAPS2 caps = {DDSCAPS_BACKBUFFER, 0, 0, {0}};
17538 DDSURFACEDESC2 surface_desc;
17539 IDirectDraw4 *ddraw;
17540 ULONG refcount;
17541 HWND window;
17542 HRESULT hr;
17544 window = create_window();
17545 ddraw = create_ddraw();
17546 ok(!!ddraw, "Failed to create a ddraw object.\n");
17547 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
17548 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17550 /* Retrieving the GDI surface requires a primary surface to exist. */
17551 gdi_surface = (void *)0xc0dec0de;
17552 hr = IDirectDraw4_GetGDISurface(ddraw, &gdi_surface);
17553 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#lx.\n", hr);
17554 ok(!gdi_surface, "Got unexpected surface %p.\n", gdi_surface);
17556 hr = IDirectDraw4_FlipToGDISurface(ddraw);
17557 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#lx.\n", hr);
17559 memset(&surface_desc, 0, sizeof(surface_desc));
17560 surface_desc.dwSize = sizeof(surface_desc);
17561 surface_desc.dwFlags = DDSD_CAPS;
17562 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
17563 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &primary, NULL);
17564 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17566 hr = IDirectDraw4_GetGDISurface(ddraw, &gdi_surface);
17567 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17568 ok(gdi_surface == primary, "Got unexpected surface %p, expected %p.\n", gdi_surface, primary);
17569 IDirectDrawSurface4_Release(gdi_surface);
17571 /* Flipping to the GDI surface requires the primary surface to be
17572 * flippable. */
17573 hr = IDirectDraw4_FlipToGDISurface(ddraw);
17574 ok(hr == DDERR_NOTFLIPPABLE, "Got unexpected hr %#lx.\n", hr);
17576 IDirectDrawSurface4_Release(primary);
17578 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
17579 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17581 memset(&surface_desc, 0, sizeof(surface_desc));
17582 surface_desc.dwSize = sizeof(surface_desc);
17583 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
17584 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
17585 surface_desc.dwBackBufferCount = 1;
17586 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &primary, NULL);
17587 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17588 hr = IDirectDrawSurface4_GetAttachedSurface(primary, &caps, &backbuffer);
17589 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17590 ok(backbuffer != primary, "Got unexpected backbuffer %p.\n", backbuffer);
17592 hr = IDirectDraw4_GetGDISurface(ddraw, &gdi_surface);
17593 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17594 ok(gdi_surface == primary, "Got unexpected surface %p, expected %p.\n", gdi_surface, primary);
17595 IDirectDrawSurface4_Release(gdi_surface);
17597 hr = IDirectDrawSurface4_Flip(primary, NULL, DDFLIP_WAIT);
17598 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17599 hr = IDirectDraw4_GetGDISurface(ddraw, &gdi_surface);
17600 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17601 ok(gdi_surface == backbuffer || broken(gdi_surface == primary),
17602 "Got unexpected surface %p, expected %p.\n", gdi_surface, backbuffer);
17603 IDirectDrawSurface4_Release(gdi_surface);
17605 hr = IDirectDraw4_FlipToGDISurface(ddraw);
17606 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17608 hr = IDirectDraw4_GetGDISurface(ddraw, &gdi_surface);
17609 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17610 ok(gdi_surface == primary, "Got unexpected surface %p, expected %p.\n", gdi_surface, primary);
17611 IDirectDrawSurface4_Release(gdi_surface);
17613 hr = IDirectDraw4_FlipToGDISurface(ddraw);
17614 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17616 IDirectDrawSurface4_Release(backbuffer);
17617 IDirectDrawSurface4_Release(primary);
17619 refcount = IDirectDraw4_Release(ddraw);
17620 ok(!refcount, "%lu references left.\n", refcount);
17621 DestroyWindow(window);
17624 static void test_alphatest(void)
17626 #define ALPHATEST_PASSED 0x0000ff00
17627 #define ALPHATEST_FAILED 0x00ff0000
17628 D3DRECT rect_full = {{0}, {0}, {640}, {480}};
17629 IDirect3DViewport3 *viewport;
17630 IDirect3DDevice3 *device;
17631 IDirectDrawSurface4 *rt;
17632 unsigned int color, i;
17633 ULONG refcount;
17634 HWND window;
17635 DWORD value;
17636 HRESULT hr;
17638 static const struct
17640 D3DCMPFUNC func;
17641 unsigned int color_less, color_equal, color_greater;
17643 test_data[] =
17645 {D3DCMP_NEVER, ALPHATEST_FAILED, ALPHATEST_FAILED, ALPHATEST_FAILED},
17646 {D3DCMP_LESS, ALPHATEST_PASSED, ALPHATEST_FAILED, ALPHATEST_FAILED},
17647 {D3DCMP_EQUAL, ALPHATEST_FAILED, ALPHATEST_PASSED, ALPHATEST_FAILED},
17648 {D3DCMP_LESSEQUAL, ALPHATEST_PASSED, ALPHATEST_PASSED, ALPHATEST_FAILED},
17649 {D3DCMP_GREATER, ALPHATEST_FAILED, ALPHATEST_FAILED, ALPHATEST_PASSED},
17650 {D3DCMP_NOTEQUAL, ALPHATEST_PASSED, ALPHATEST_FAILED, ALPHATEST_PASSED},
17651 {D3DCMP_GREATEREQUAL, ALPHATEST_FAILED, ALPHATEST_PASSED, ALPHATEST_PASSED},
17652 {D3DCMP_ALWAYS, ALPHATEST_PASSED, ALPHATEST_PASSED, ALPHATEST_PASSED},
17654 static struct
17656 struct vec3 position;
17657 DWORD diffuse;
17659 quad[] =
17661 {{-1.0f, -1.0f, 0.1f}, ALPHATEST_PASSED | 0x80000000},
17662 {{-1.0f, 1.0f, 0.1f}, ALPHATEST_PASSED | 0x80000000},
17663 {{ 1.0f, -1.0f, 0.1f}, ALPHATEST_PASSED | 0x80000000},
17664 {{ 1.0f, 1.0f, 0.1f}, ALPHATEST_PASSED | 0x80000000},
17667 window = create_window();
17668 if (!(device = create_device(window, DDSCL_NORMAL)))
17670 skip("Failed to create a 3D device.\n");
17671 DestroyWindow(window);
17672 return;
17674 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
17675 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
17677 viewport = create_viewport(device, 0, 0, 640, 480);
17678 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
17679 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
17681 hr = IDirect3DViewport3_Clear2(viewport, 1, &rect_full, D3DCLEAR_TARGET, 0xff0000ff, 0.0f, 0);
17682 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
17683 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
17684 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
17685 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ZENABLE, FALSE);
17686 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
17687 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ALPHATESTENABLE, TRUE);
17688 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
17690 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
17692 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ALPHAFUNC, test_data[i].func);
17693 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
17695 hr = IDirect3DViewport3_Clear2(viewport, 1, &rect_full, D3DCLEAR_TARGET, ALPHATEST_FAILED, 0.0f, 0);
17696 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
17697 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ALPHAREF, 0x70);
17698 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
17699 hr = IDirect3DDevice3_BeginScene(device);
17700 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
17701 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
17702 D3DFVF_XYZ | D3DFVF_DIFFUSE, quad, ARRAY_SIZE(quad), 0);
17703 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
17704 hr = IDirect3DDevice3_EndScene(device);
17705 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
17706 color = get_surface_color(rt, 320, 240);
17707 ok(compare_color(color, test_data[i].color_greater, 0),
17708 "Alphatest failed, color 0x%08x, expected 0x%08x, alpha > ref, func %u.\n",
17709 color, test_data[i].color_greater, test_data[i].func);
17711 hr = IDirect3DViewport3_Clear2(viewport, 1, &rect_full, D3DCLEAR_TARGET, ALPHATEST_FAILED, 0.0f, 0);
17712 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
17713 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ALPHAREF, 0xff70);
17714 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
17715 hr = IDirect3DDevice3_GetRenderState(device, D3DRENDERSTATE_ALPHAREF, &value);
17716 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
17717 ok(value == 0xff70, "Got unexpected value %#lx.\n", value);
17718 hr = IDirect3DDevice3_BeginScene(device);
17719 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
17720 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
17721 D3DFVF_XYZ | D3DFVF_DIFFUSE, quad, ARRAY_SIZE(quad), 0);
17722 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
17723 hr = IDirect3DDevice3_EndScene(device);
17724 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
17725 color = get_surface_color(rt, 320, 240);
17726 ok(compare_color(color, test_data[i].color_greater, 0),
17727 "Alphatest failed, color 0x%08x, expected 0x%08x, alpha > ref, func %u.\n",
17728 color, test_data[i].color_greater, test_data[i].func);
17731 destroy_viewport(device, viewport);
17732 IDirectDrawSurface4_Release(rt);
17733 refcount = IDirect3DDevice3_Release(device);
17734 ok(!refcount, "Device has %lu references left.\n", refcount);
17735 DestroyWindow(window);
17738 static void test_clipper_refcount(void)
17740 IDirectDrawSurface4 *surface;
17741 IDirectDrawClipper *clipper, *clipper2;
17742 DDSURFACEDESC2 surface_desc;
17743 IDirectDraw4 *ddraw;
17744 IDirectDraw *ddraw1;
17745 ULONG refcount;
17746 HWND window;
17747 HRESULT hr;
17748 BOOL changed;
17749 const IDirectDrawClipperVtbl *orig_vtbl;
17751 window = create_window();
17752 ddraw = create_ddraw();
17753 ok(!!ddraw, "Failed to create a ddraw object.\n");
17754 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
17755 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17757 memset(&surface_desc, 0, sizeof(surface_desc));
17758 surface_desc.dwSize = sizeof(surface_desc);
17759 surface_desc.dwFlags = DDSD_CAPS;
17760 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
17761 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
17762 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17764 hr = IDirectDraw4_CreateClipper(ddraw, 0, &clipper, NULL);
17765 ok(SUCCEEDED(hr), "Failed to create clipper, hr %#lx.\n", hr);
17766 refcount = get_refcount((IUnknown *)clipper);
17767 ok(refcount == 1, "Got unexpected refcount %lu.\n", refcount);
17769 /* Show that clipper validation doesn't somehow happen through per-clipper vtable
17770 * pointers. */
17771 hr = IDirectDraw4_CreateClipper(ddraw, 0, &clipper2, NULL);
17772 ok(SUCCEEDED(hr), "Failed to create clipper, hr %#lx.\n", hr);
17773 ok(clipper->lpVtbl == clipper2->lpVtbl, "Got different clipper vtables %p and %p.\n",
17774 clipper->lpVtbl, clipper2->lpVtbl);
17775 orig_vtbl = clipper->lpVtbl;
17776 IDirectDrawClipper_Release(clipper2);
17778 /* Surfaces hold a reference to clippers. No surprises there. */
17779 hr = IDirectDrawSurface4_SetClipper(surface, clipper);
17780 ok(SUCCEEDED(hr), "Failed to set clipper, hr %#lx.\n", hr);
17781 refcount = get_refcount((IUnknown *)clipper);
17782 ok(refcount == 2, "Got unexpected refcount %lu.\n", refcount);
17784 hr = IDirectDrawSurface4_GetClipper(surface, &clipper2);
17785 ok(SUCCEEDED(hr), "Failed to get clipper, hr %#lx.\n", hr);
17786 ok(clipper == clipper2, "Got clipper %p, expected %p.\n", clipper2, clipper);
17787 refcount = IDirectDrawClipper_Release(clipper2);
17788 ok(refcount == 2, "Got unexpected refcount %lu.\n", refcount);
17790 hr = IDirectDrawSurface4_SetClipper(surface, NULL);
17791 ok(SUCCEEDED(hr), "Failed to set clipper, hr %#lx.\n", hr);
17792 refcount = get_refcount((IUnknown *)clipper);
17793 ok(refcount == 1, "Got unexpected refcount %lu.\n", refcount);
17795 hr = IDirectDrawSurface4_SetClipper(surface, clipper);
17796 ok(SUCCEEDED(hr), "Failed to set clipper, hr %#lx.\n", hr);
17797 refcount = get_refcount((IUnknown *)clipper);
17798 ok(refcount == 2, "Got unexpected refcount %lu.\n", refcount);
17800 refcount = IDirectDrawSurface4_Release(surface);
17801 ok(!refcount, "%lu references left.\n", refcount);
17802 refcount = get_refcount((IUnknown *)clipper);
17803 ok(refcount == 1, "Got unexpected refcount %lu.\n", refcount);
17805 /* SetClipper with an invalid pointer crashes. */
17807 /* Clipper methods work with a broken vtable, with the exception of Release. */
17808 clipper->lpVtbl = (void *)0xdeadbeef;
17809 refcount = orig_vtbl->AddRef(clipper);
17810 todo_wine ok(refcount == 2, "Got unexpected refcount %lu.\n", refcount);
17811 refcount = orig_vtbl->Release(clipper);
17812 ok(!refcount, "Got unexpected refcount %lu.\n", refcount);
17814 clipper->lpVtbl = orig_vtbl;
17815 refcount = orig_vtbl->Release(clipper);
17816 todo_wine ok(refcount == 1, "Got unexpected refcount %lu.\n", refcount);
17818 /* Fix the refcount difference because Wine did not increase the ref in the
17819 * AddRef call above. */
17820 if (refcount)
17822 refcount = IDirectDrawClipper_Release(clipper);
17823 ok(!refcount, "Got unexpected refcount %lu.\n", refcount);
17826 /* Steal the reference and see what happens - releasing the surface works fine.
17827 * The clipper is destroyed and not kept alive by a hidden refcount - trying to
17828 * release it after the GetClipper call is likely to crash, and certain to crash
17829 * if we allocate and zero as much heap memory as we can get. */
17830 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
17831 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17832 hr = IDirectDraw4_CreateClipper(ddraw, 0, &clipper, NULL);
17833 ok(SUCCEEDED(hr), "Failed to create clipper, hr %#lx.\n", hr);
17834 hr = IDirectDrawSurface4_SetClipper(surface, clipper);
17835 ok(SUCCEEDED(hr), "Failed to set clipper, hr %#lx.\n", hr);
17837 IDirectDrawClipper_Release(clipper);
17838 IDirectDrawClipper_Release(clipper);
17840 if (0)
17842 /* Disabled because it causes heap corruption (HeapValidate fails and random
17843 * hangs in a later HeapFree) on Windows on one of my Machines: MacbookPro 10,1
17844 * running Windows 10 18363.535 and Nvidia driver 425.31. Driver version 441.66
17845 * is affected too. Some testbot machines have crashes directly in GetClipper
17846 * or proceed with a corrupted heap too.
17848 * The same Windows and driver versions run the test without heap corruption on
17849 * a Geforce 1060 GTX card. I have not seen the problem on AMD GPUs either. */
17850 hr = IDirectDrawSurface4_GetClipper(surface, &clipper2);
17851 ok(SUCCEEDED(hr), "Failed to get clipper, hr %#lx.\n", hr);
17852 ok(clipper == clipper2, "Got clipper %p, expected %p.\n", clipper2, clipper);
17855 /* Show that invoking the Release method does not crash, but don't get the
17856 * vtable through the clipper pointer because it is no longer pointing to
17857 * valid memory. */
17858 refcount = orig_vtbl->Release(clipper);
17859 ok(!refcount, "%lu references left.\n", refcount);
17861 refcount = IDirectDrawSurface4_Release(surface);
17862 ok(!refcount, "%lu references left.\n", refcount);
17864 /* It looks like the protection against invalid thispointers is part of
17865 * the IDirectDrawClipper method implementation, not IDirectDrawSurface. */
17866 clipper = calloc(1, 0x1000);
17867 ok(!!clipper, "failed to allocate memory\n");
17869 /* Assigning the vtable to our fake clipper does NOT make a difference on
17870 * native - there is a different member of the clipper implementation struct
17871 * that is used to determine if a clipper is valid. */
17872 clipper->lpVtbl = orig_vtbl;
17874 refcount = orig_vtbl->AddRef(clipper);
17875 todo_wine ok(!refcount, "Got refcount %lu.\n", refcount);
17876 refcount = orig_vtbl->AddRef((IDirectDrawClipper *)(ULONG_PTR)0xdeadbeef);
17877 ok(!refcount, "Got refcount %lu.\n", refcount);
17879 changed = 0x1234;
17880 hr = orig_vtbl->IsClipListChanged(clipper, &changed);
17881 todo_wine ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
17882 todo_wine ok(changed == 0x1234, "'changed' changed: %x.\n", changed);
17884 changed = 0x1234;
17885 hr = orig_vtbl->IsClipListChanged((IDirectDrawClipper *)(ULONG_PTR)0xdeadbeef, &changed);
17886 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
17887 ok(changed == 0x1234, "'changed' changed: %x.\n", changed);
17889 /* Nope, we can't initialize our fake clipper. */
17890 hr = IDirectDraw4_QueryInterface(ddraw, &IID_IDirectDraw, (void **)&ddraw1);
17891 ok(SUCCEEDED(hr), "Failed to get ddraw1 interface, hr %#lx.\n", hr);
17893 hr = orig_vtbl->Initialize(clipper, ddraw1, 0);
17894 todo_wine ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#lx.\n", hr);
17896 IDirectDraw_Release(ddraw1);
17898 free(clipper);
17900 refcount = IDirectDraw4_Release(ddraw);
17901 ok(!refcount, "%lu references left.\n", refcount);
17902 DestroyWindow(window);
17905 static void test_caps(void)
17907 DWORD caps_never, caps_always, caps_hal;
17908 DDCAPS hal_caps, hel_caps;
17909 IDirectDraw4 *ddraw;
17910 IDirectDraw *ddraw1;
17911 HRESULT hr;
17912 BOOL no3d;
17914 caps_never = DDSCAPS_RESERVED1
17915 | DDSCAPS_ALPHA
17916 | DDSCAPS_PRIMARYSURFACELEFT
17917 | DDSCAPS_SYSTEMMEMORY
17918 | DDSCAPS_VISIBLE
17919 | DDSCAPS_WRITEONLY
17920 | DDSCAPS_LIVEVIDEO
17921 | DDSCAPS_HWCODEC
17922 | DDSCAPS_MODEX
17923 | DDSCAPS_RESERVED2
17924 | 0x01000000u
17925 | 0x02000000u
17926 | DDSCAPS_ALLOCONLOAD
17927 | DDSCAPS_VIDEOPORT
17928 | DDSCAPS_STANDARDVGAMODE
17929 | DDSCAPS_OPTIMIZED;
17931 caps_always = DDSCAPS_FLIP
17932 | DDSCAPS_OFFSCREENPLAIN
17933 | DDSCAPS_PRIMARYSURFACE
17934 | DDSCAPS_TEXTURE
17935 | DDSCAPS_ZBUFFER
17936 | DDSCAPS_MIPMAP;
17938 caps_hal = DDSCAPS_BACKBUFFER
17939 | DDSCAPS_COMPLEX
17940 | DDSCAPS_FRONTBUFFER
17941 | DDSCAPS_3DDEVICE
17942 | DDSCAPS_VIDEOMEMORY
17943 | DDSCAPS_LOCALVIDMEM
17944 | DDSCAPS_NONLOCALVIDMEM;
17946 ddraw = create_ddraw();
17947 ok(!!ddraw, "Failed to create a ddraw object.\n");
17949 memset(&hal_caps, 0, sizeof(hal_caps));
17950 memset(&hel_caps, 0, sizeof(hel_caps));
17951 hal_caps.dwSize = sizeof(hal_caps);
17952 hel_caps.dwSize = sizeof(hel_caps);
17953 hr = IDirectDraw4_GetCaps(ddraw, &hal_caps, &hel_caps);
17954 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17955 ok(hal_caps.ddsOldCaps.dwCaps == hal_caps.ddsCaps.dwCaps,
17956 "Got unexpected caps %#lx, expected %#lx.\n",
17957 hal_caps.ddsOldCaps.dwCaps, hal_caps.ddsCaps.dwCaps);
17958 ok(hel_caps.ddsOldCaps.dwCaps == hel_caps.ddsCaps.dwCaps,
17959 "Got unexpected caps %#lx, expected %#lx.\n",
17960 hel_caps.ddsOldCaps.dwCaps, hel_caps.ddsCaps.dwCaps);
17962 no3d = !(hal_caps.ddsCaps.dwCaps & DDSCAPS_3DDEVICE);
17963 if (hal_caps.ddsCaps.dwCaps)
17965 ok(!(hal_caps.ddsCaps.dwCaps & caps_never), "Got unexpected caps %#lx.\n", hal_caps.ddsCaps.dwCaps);
17966 ok(!(~hal_caps.ddsCaps.dwCaps & caps_always), "Got unexpected caps %#lx.\n", hal_caps.ddsCaps.dwCaps);
17967 todo_wine_if(no3d) ok(!(~hal_caps.ddsCaps.dwCaps & caps_hal),
17968 "Got unexpected caps %#lx.\n", hal_caps.ddsCaps.dwCaps);
17970 ok(!(hel_caps.ddsCaps.dwCaps & caps_never), "Got unexpected caps %#lx.\n", hel_caps.ddsCaps.dwCaps);
17971 ok(!(~hel_caps.ddsCaps.dwCaps & caps_always), "Got unexpected caps %#lx.\n", hel_caps.ddsCaps.dwCaps);
17972 todo_wine_if(!no3d) ok(!(hel_caps.ddsCaps.dwCaps & caps_hal),
17973 "Got unexpected caps %#lx.\n", hel_caps.ddsCaps.dwCaps);
17975 IDirectDraw4_Release(ddraw);
17977 if (hal_caps.ddsCaps.dwCaps)
17979 hr = DirectDrawCreate((GUID *)DDCREATE_HARDWAREONLY, &ddraw1, NULL);
17980 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17981 hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirectDraw4, (void **)&ddraw);
17982 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17983 IDirectDraw_Release(ddraw1);
17985 memset(&hal_caps, 0, sizeof(hal_caps));
17986 memset(&hel_caps, 0, sizeof(hel_caps));
17987 hal_caps.dwSize = sizeof(hal_caps);
17988 hel_caps.dwSize = sizeof(hel_caps);
17989 hr = IDirectDraw4_GetCaps(ddraw, &hal_caps, &hel_caps);
17990 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
17991 ok(hal_caps.ddsOldCaps.dwCaps == hal_caps.ddsCaps.dwCaps,
17992 "Got unexpected caps %#lx, expected %#lx.\n",
17993 hal_caps.ddsOldCaps.dwCaps, hal_caps.ddsCaps.dwCaps);
17994 ok(hel_caps.ddsOldCaps.dwCaps == hel_caps.ddsCaps.dwCaps,
17995 "Got unexpected caps %#lx, expected %#lx.\n",
17996 hel_caps.ddsOldCaps.dwCaps, hel_caps.ddsCaps.dwCaps);
17998 ok(!(hal_caps.ddsCaps.dwCaps & caps_never), "Got unexpected caps %#lx.\n", hal_caps.ddsCaps.dwCaps);
17999 ok(!(~hal_caps.ddsCaps.dwCaps & caps_always), "Got unexpected caps %#lx.\n", hal_caps.ddsCaps.dwCaps);
18000 todo_wine_if(no3d) ok(!(~hal_caps.ddsCaps.dwCaps & caps_hal),
18001 "Got unexpected caps %#lx.\n", hal_caps.ddsCaps.dwCaps);
18002 todo_wine ok(!hel_caps.ddsCaps.dwCaps, "Got unexpected caps %#lx.\n", hel_caps.ddsCaps.dwCaps);
18004 IDirectDraw4_Release(ddraw);
18007 hr = DirectDrawCreate((GUID *)DDCREATE_EMULATIONONLY, &ddraw1, NULL);
18008 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
18009 hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirectDraw4, (void **)&ddraw);
18010 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
18011 IDirectDraw_Release(ddraw1);
18013 memset(&hal_caps, 0, sizeof(hal_caps));
18014 memset(&hel_caps, 0, sizeof(hel_caps));
18015 hal_caps.dwSize = sizeof(hal_caps);
18016 hel_caps.dwSize = sizeof(hel_caps);
18017 hr = IDirectDraw4_GetCaps(ddraw, &hal_caps, &hel_caps);
18018 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
18019 ok(hal_caps.ddsOldCaps.dwCaps == hal_caps.ddsCaps.dwCaps,
18020 "Got unexpected caps %#lx, expected %#lx.\n",
18021 hal_caps.ddsOldCaps.dwCaps, hal_caps.ddsCaps.dwCaps);
18022 ok(hel_caps.ddsOldCaps.dwCaps == hel_caps.ddsCaps.dwCaps,
18023 "Got unexpected caps %#lx, expected %#lx.\n",
18024 hel_caps.ddsOldCaps.dwCaps, hel_caps.ddsCaps.dwCaps);
18026 todo_wine ok(!hal_caps.ddsCaps.dwCaps, "Got unexpected caps %#lx.\n", hal_caps.ddsCaps.dwCaps);
18027 ok(!(hel_caps.ddsCaps.dwCaps & caps_never), "Got unexpected caps %#lx.\n", hel_caps.ddsCaps.dwCaps);
18028 ok(!(~hel_caps.ddsCaps.dwCaps & caps_always), "Got unexpected caps %#lx.\n", hel_caps.ddsCaps.dwCaps);
18029 todo_wine_if(!no3d) ok(!(hel_caps.ddsCaps.dwCaps & caps_hal),
18030 "Got unexpected caps %#lx.\n", hel_caps.ddsCaps.dwCaps);
18032 IDirectDraw4_Release(ddraw);
18035 static void test_d32_support(void)
18037 IDirectDrawSurface4 *surface;
18038 DDSURFACEDESC2 surface_desc;
18039 IDirectDraw4 *ddraw;
18040 ULONG refcount;
18041 HWND window;
18042 HRESULT hr;
18044 window = create_window();
18045 ddraw = create_ddraw();
18046 ok(!!ddraw, "Failed to create a ddraw object.\n");
18047 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
18048 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
18050 memset(&surface_desc, 0, sizeof(surface_desc));
18051 surface_desc.dwSize = sizeof(surface_desc);
18052 surface_desc.dwFlags = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT;
18053 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
18054 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
18055 surface_desc.ddpfPixelFormat.dwFlags = DDPF_ZBUFFER;
18056 surface_desc.ddpfPixelFormat.dwZBufferBitDepth = 32;
18057 surface_desc.ddpfPixelFormat.dwZBitMask = 0xffffffff;
18058 surface_desc.dwWidth = 64;
18059 surface_desc.dwHeight = 64;
18060 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
18061 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
18063 memset(&surface_desc, 0, sizeof(surface_desc));
18064 surface_desc.dwSize = sizeof(surface_desc);
18065 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &surface_desc);
18066 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
18067 ok((surface_desc.dwFlags & DDSD_PIXELFORMAT), "Got unexpected flags %#lx.\n", surface_desc.dwFlags);
18068 ok(surface_desc.ddpfPixelFormat.dwFlags & DDPF_ZBUFFER,
18069 "Got unexpected format flags %#lx.\n", surface_desc.ddpfPixelFormat.dwFlags);
18070 ok(surface_desc.ddpfPixelFormat.dwZBufferBitDepth == 32,
18071 "Got unexpected dwZBufferBitDepth %lu.\n", surface_desc.ddpfPixelFormat.dwZBufferBitDepth);
18072 ok(surface_desc.ddpfPixelFormat.dwZBitMask == 0xffffffff,
18073 "Got unexpected Z mask 0x%08lx.\n", surface_desc.ddpfPixelFormat.dwZBitMask);
18074 ok(!(surface_desc.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY),
18075 "Got unexpected surface caps %#lx.\n", surface_desc.ddsCaps.dwCaps);
18076 IDirectDrawSurface4_Release(surface);
18078 refcount = IDirectDraw4_Release(ddraw);
18079 ok(!refcount, "%lu references left.\n", refcount);
18080 DestroyWindow(window);
18083 static void test_surface_format_conversion_alpha(void)
18085 static const unsigned int rgba_data[4 * 4] =
18087 0xff00ff00, 0xff0000ff, 0xff0000ff, 0xff0000ff,
18088 0xff0000ff, 0xff00ff00, 0xff0000ff, 0xff0000ff,
18089 0xff00ff00, 0xff0000ff, 0xff00ff00, 0xff0000ff,
18090 0xff00ff00, 0xff0000ff, 0xff0000ff, 0xff00ff00,
18092 static const unsigned int rgbx_data[4 * 4] =
18094 0x0000ff00, 0x000000ff, 0x000000ff, 0x000000ff,
18095 0x000000ff, 0x0000ff00, 0x000000ff, 0x000000ff,
18096 0x0000ff00, 0x000000ff, 0x0000ff00, 0x000000ff,
18097 0x0000ff00, 0x000000ff, 0x000000ff, 0x0000ff00,
18099 static const unsigned short int r5g6b5_data[4 * 4] =
18101 0x07e0, 0x001f, 0x001f, 0x001f,
18102 0x001f, 0x07e0, 0x001f, 0x001f,
18103 0x07e0, 0x001f, 0x07e0, 0x001f,
18104 0x07e0, 0x001f, 0x001f, 0x07e0,
18106 static const unsigned short int r5g5b5x1_data[4 * 4] =
18108 0x03e0, 0x001f, 0x001f, 0x001f,
18109 0x001f, 0x03e0, 0x001f, 0x001f,
18110 0x03e0, 0x001f, 0x03e0, 0x001f,
18111 0x03e0, 0x001f, 0x001f, 0x03e0,
18113 static const unsigned short int r5g5b5a1_data[4 * 4] =
18115 0x83e0, 0x801f, 0x801f, 0x801f,
18116 0x801f, 0x83e0, 0x801f, 0x801f,
18117 0x83e0, 0x801f, 0x83e0, 0x801f,
18118 0x83e0, 0x801f, 0x801f, 0x83e0,
18120 static const unsigned int dxt1_data[8] =
18122 0x001f07e0, 0x14445154,
18124 static const unsigned int dxt2_data[16] =
18126 0xffffffff, 0xffffffff, 0x001f07e0, 0x14445154,
18129 enum test_format_id
18131 FMT_RGBA,
18132 FMT_RGBX,
18133 FMT_R5G6B5,
18134 FMT_R5G5B5X1,
18135 FMT_R5G5B5A1,
18136 FMT_DXT1,
18137 FMT_DXT2,
18138 FMT_DXT3,
18141 static const struct test_format
18143 DDPIXELFORMAT fmt;
18144 const char *name;
18145 unsigned int block_size, x_blocks, y_blocks;
18146 DWORD support_flag;
18147 BOOL broken_software_blit, broken_hardware_blit;
18149 formats[] =
18153 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
18154 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
18156 "RGBA", 4, 4, 4,
18160 sizeof(DDPIXELFORMAT), DDPF_RGB, 0,
18161 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0x00000000}
18163 "RGBX", 4, 4, 4,
18167 sizeof(DDPIXELFORMAT), DDPF_RGB, 0,
18168 {16}, {0x0000f800}, {0x000007e0}, {0x0000001f}, {0x00000000}
18170 "R5G6B5", 2, 4, 4, 0, TRUE,
18171 /* Looks broken for sysmem texture conversions on Windows (at
18172 * least with hardware device), the result is either error from
18173 * _Blt() or a copy of the source data without any conversion. */
18177 sizeof(DDPIXELFORMAT), DDPF_RGB, 0,
18178 {16}, {0x00007c00}, {0x000003e0}, {0x0000001f}, {0x00000000}
18180 "R5G5B5X1", 2, 4, 4,
18184 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
18185 {16}, {0x00007c00}, {0x000003e0}, {0x0000001f}, {0x00008000}
18187 "R5G5B5A1", 2, 4, 4, 0, FALSE, TRUE,
18191 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('D', 'X', 'T', '1'),
18192 {0}, {0}, {0}, {0}, {0}
18194 "DXT1", 8, 1, 1, SUPPORT_DXT1,
18198 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('D', 'X', 'T', '2'),
18199 {0}, {0}, {0}, {0}, {0}
18201 "DXT2", 16, 1, 1, SUPPORT_DXT2,
18205 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('D', 'X', 'T', '3'),
18206 {0}, {0}, {0}, {0}, {0}
18208 "DXT3", 16, 1, 1, SUPPORT_DXT3,
18212 static const struct
18214 DWORD src_caps, dst_caps;
18216 test_caps[] =
18218 {DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY},
18219 {DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY},
18220 {DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY},
18221 {DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY},
18224 static const struct
18226 enum test_format_id src_format;
18227 const void *src_data;
18228 enum test_format_id dst_format;
18229 const void *expected_data;
18230 BOOL todo;
18232 tests[] =
18234 #if 0
18235 /* The following 3 tests give different results on AMD and NVIDIA on Windows, disabling. */
18236 {FMT_RGBX, rgbx_data, FMT_RGBA, rgba_data},
18237 {FMT_RGBA, rgba_data, FMT_RGBX, rgbx_data},
18238 {FMT_R5G5B5X1, r5g5b5x1_data, FMT_RGBA, rgba_data},
18239 #endif
18240 {FMT_R5G6B5, r5g6b5_data, FMT_RGBA, rgba_data},
18241 {FMT_R5G6B5, r5g6b5_data, FMT_R5G5B5A1, r5g5b5a1_data},
18242 {FMT_R5G5B5X1, r5g5b5x1_data, FMT_R5G5B5A1, r5g5b5x1_data, TRUE},
18243 {FMT_R5G5B5A1, r5g5b5a1_data, FMT_R5G6B5, r5g6b5_data},
18244 {FMT_RGBA, rgba_data, FMT_DXT1, dxt1_data},
18245 {FMT_RGBX, rgbx_data, FMT_DXT1, dxt1_data},
18246 {FMT_RGBA, rgba_data, FMT_DXT2, dxt2_data},
18247 {FMT_RGBX, rgbx_data, FMT_DXT2, dxt2_data},
18248 {FMT_RGBA, rgba_data, FMT_DXT3, dxt2_data},
18249 {FMT_RGBX, rgbx_data, FMT_DXT3, dxt2_data},
18250 {FMT_DXT1, dxt1_data, FMT_DXT2, dxt2_data},
18251 {FMT_DXT1, dxt1_data, FMT_RGBA, rgba_data},
18252 {FMT_DXT1, dxt1_data, FMT_RGBX, rgba_data},
18253 {FMT_DXT3, dxt2_data, FMT_RGBA, rgba_data},
18254 {FMT_DXT3, dxt2_data, FMT_RGBX, rgba_data},
18257 const struct test_format *src_format, *dst_format;
18258 IDirectDrawSurface4 *src_surf, *dst_surf;
18259 DDSURFACEDESC2 surface_desc, lock;
18260 unsigned int i, j, x, y, pitch;
18261 IDirect3DDevice3 *device;
18262 DWORD supported_fmts;
18263 IDirectDraw4 *ddraw;
18264 ULONG refcount;
18265 BOOL is_wine;
18266 HWND window;
18267 BOOL passed;
18268 HRESULT hr;
18270 window = create_window();
18271 if (!(device = create_device(window, DDSCL_NORMAL)))
18273 skip("Failed to create a 3D device, skipping test.\n");
18274 DestroyWindow(window);
18275 return;
18278 ddraw = create_ddraw();
18279 ok(!!ddraw, "Failed to create a ddraw object.\n");
18280 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
18281 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
18283 hr = IDirect3DDevice3_EnumTextureFormats(device, test_block_formats_creation_cb,
18284 &supported_fmts);
18285 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
18287 is_wine = !strcmp(winetest_platform, "wine");
18289 memset(&surface_desc, 0, sizeof(surface_desc));
18290 surface_desc.dwSize = sizeof(surface_desc);
18291 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
18292 surface_desc.dwWidth = 4;
18293 surface_desc.dwHeight = 4;
18295 for (i = 0; i < ARRAY_SIZE(tests); ++i)
18297 src_format = &formats[tests[i].src_format];
18298 dst_format = &formats[tests[i].dst_format];
18300 if (~supported_fmts & dst_format->support_flag)
18302 skip("%s format is not supported, skipping test %u.\n", dst_format->name, i);
18303 continue;
18305 if (~supported_fmts & src_format->support_flag)
18307 skip("%s format is not supported, skipping test %u.\n", src_format->name, i);
18308 continue;
18311 for (j = 0; j < ARRAY_SIZE(test_caps); ++j)
18313 if (!is_wine && ((test_caps[j].src_caps | test_caps[j].dst_caps) & DDSCAPS_SYSTEMMEMORY)
18314 && (src_format->broken_software_blit || dst_format->broken_software_blit))
18315 continue;
18316 if (!is_wine && (test_caps[j].dst_caps & DDSCAPS_VIDEOMEMORY)
18317 && dst_format->broken_hardware_blit)
18318 continue;
18320 surface_desc.ddpfPixelFormat = src_format->fmt;
18321 surface_desc.ddsCaps.dwCaps = test_caps[j].src_caps;
18322 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &src_surf, NULL);
18323 ok(hr == DD_OK, "Test (%u, %u), got unexpected hr %#lx.\n", j, i, hr);
18325 surface_desc.ddpfPixelFormat = dst_format->fmt;
18326 surface_desc.ddsCaps.dwCaps = test_caps[j].dst_caps;
18327 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &dst_surf, NULL);
18328 ok(hr == DD_OK, "Test (%u, %u), got unexpected hr %#lx.\n", j, i, hr);
18330 memset(&lock, 0, sizeof(lock));
18331 lock.dwSize = sizeof(lock);
18332 hr = IDirectDrawSurface4_Lock(src_surf, NULL, &lock, 0, NULL);
18333 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
18334 pitch = lock.lPitch;
18335 for (y = 0; y < src_format->y_blocks; ++y)
18337 memcpy((BYTE *)lock.lpSurface + y * pitch,
18338 (BYTE *)tests[i].src_data + y * src_format->x_blocks * src_format->block_size,
18339 src_format->block_size * src_format->x_blocks);
18341 hr = IDirectDrawSurface4_Unlock(src_surf, NULL);
18342 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
18344 hr = IDirectDrawSurface4_Blt(dst_surf, NULL, src_surf, NULL, DDBLT_WAIT, NULL);
18345 if (!is_wine && FAILED(hr))
18347 /* Some software blits are rejected on Windows. */
18348 IDirectDrawSurface4_Release(dst_surf);
18349 IDirectDrawSurface4_Release(src_surf);
18350 skip("Skipping test (%u, %u), cannot blit %s -> %s, hr %#lx.\n", j, i,
18351 src_format->name, dst_format->name, hr);
18352 continue;
18354 ok(hr == DD_OK, "Test (%u, %s -> %s), got unexpected hr %#lx.\n", j,
18355 src_format->name, dst_format->name, hr);
18357 memset(&lock, 0, sizeof(lock));
18358 lock.dwSize = sizeof(lock);
18359 hr = IDirectDrawSurface4_Lock(dst_surf, NULL, &lock, 0, NULL);
18360 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
18361 pitch = lock.lPitch;
18363 for (y = 0; y < dst_format->y_blocks; ++y)
18365 const void *expected_data = tests[i].expected_data;
18367 passed = !memcmp((BYTE*)lock.lpSurface + y * pitch,
18368 (BYTE *)expected_data + y * dst_format->x_blocks * dst_format->block_size,
18369 dst_format->block_size * dst_format->x_blocks);
18370 todo_wine_if(tests[i].todo)
18371 ok(passed, "Test (%u, %s -> %s), row %u, unexpected surface data.\n", j,
18372 src_format->name, dst_format->name, y);
18374 if (!passed && !(is_wine && tests[i].todo))
18376 for (x = 0; x < dst_format->x_blocks * dst_format->block_size / 4; ++x)
18378 trace("Test (%u, %u), x %u, y %u, got 0x%08x, expected 0x%08x.\n", j, i, x, y,
18379 *(unsigned int *)((BYTE *)lock.lpSurface + y * pitch + x * 4),
18380 *(unsigned int *)((BYTE *)expected_data + y * dst_format->x_blocks
18381 * dst_format->block_size + x * 4));
18384 if (!passed)
18385 break;
18387 hr = IDirectDrawSurface4_Unlock(dst_surf, NULL);
18388 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
18390 IDirectDrawSurface4_Release(dst_surf);
18391 IDirectDrawSurface4_Release(src_surf);
18395 IDirect3DDevice3_Release(device);
18396 refcount = IDirectDraw4_Release(ddraw);
18397 ok(!refcount, "%lu references left.\n", refcount);
18398 DestroyWindow(window);
18401 struct find_different_mode_param
18403 unsigned int old_width;
18404 unsigned int old_height;
18405 unsigned int old_frequency;
18406 unsigned int new_width;
18407 unsigned int new_height;
18408 unsigned int new_frequency;
18409 unsigned int new_bpp;
18412 static HRESULT CALLBACK find_different_mode_callback(DDSURFACEDESC2 *surface_desc, void *context)
18414 struct find_different_mode_param *param = context;
18416 if (surface_desc->ddpfPixelFormat.dwRGBBitCount != registry_mode.dmBitsPerPel)
18417 return DDENUMRET_OK;
18419 /* See comment in ddraw7 about the frequency. */
18420 if (surface_desc->dwWidth != param->old_width && surface_desc->dwHeight != param->old_height &&
18421 (!compare_uint(surface_desc->dwRefreshRate, param->old_frequency, 1) || !param->old_frequency))
18423 /* See test_coop_level_mode_set_enum_cb() for why enumeration might accidentally continue. */
18424 if (!param->new_width || (param->new_width < registry_mode.dmPelsWidth
18425 && param->new_height < registry_mode.dmPelsHeight))
18427 param->new_width = surface_desc->dwWidth;
18428 param->new_height = surface_desc->dwHeight;
18429 param->new_frequency = surface_desc->dwRefreshRate;
18430 param->new_bpp = surface_desc->ddpfPixelFormat.dwRGBBitCount;
18432 return DDENUMRET_CANCEL;
18435 return DDENUMRET_OK;
18438 static void test_cursor_clipping(void)
18440 struct find_different_mode_param param;
18441 DDSURFACEDESC2 surface_desc;
18442 RECT rect, clip_rect;
18443 IDirectDraw4 *ddraw;
18444 HWND window;
18445 HRESULT hr;
18446 BOOL ret;
18448 window = create_window();
18449 ok(!!window, "Failed to create a window.\n");
18450 ddraw = create_ddraw();
18451 ok(!!ddraw, "Failed to create a ddraw object.\n");
18453 memset(&surface_desc, 0, sizeof(surface_desc));
18454 surface_desc.dwSize = sizeof(surface_desc);
18455 hr = IDirectDraw4_GetDisplayMode(ddraw, &surface_desc);
18456 ok(hr == DD_OK, "GetDisplayMode failed, hr %#lx.\n", hr);
18458 memset(&param, 0, sizeof(param));
18459 param.old_width = surface_desc.dwWidth;
18460 param.old_height = surface_desc.dwHeight;
18461 hr = IDirectDraw4_EnumDisplayModes(ddraw, 0, NULL, &param, find_different_mode_callback);
18462 ok(hr == DD_OK, "EnumDisplayModes failed, hr %#lx.\n", hr);
18463 if (!(param.new_width && param.new_height))
18465 skip("Failed to find a different mode than %ux%u.\n", param.old_width, param.old_height);
18466 goto done;
18469 ret = ClipCursor(NULL);
18470 ok(ret, "ClipCursor failed, error %lu.\n", GetLastError());
18471 get_virtual_rect(&rect);
18472 ret = GetClipCursor(&clip_rect);
18473 ok(ret, "GetClipCursor failed, error %lu.\n", GetLastError());
18474 ok(EqualRect(&clip_rect, &rect), "Expect clip rect %s, got %s.\n", wine_dbgstr_rect(&rect),
18475 wine_dbgstr_rect(&clip_rect));
18477 /* Set cooperative level to normal */
18478 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
18479 ok(hr == DD_OK, "SetCooperativeLevel failed, hr %#lx.\n", hr);
18480 flush_events();
18481 get_virtual_rect(&rect);
18482 ret = GetClipCursor(&clip_rect);
18483 ok(ret, "GetClipCursor failed, error %lu.\n", GetLastError());
18484 ok(EqualRect(&clip_rect, &rect), "Expect clip rect %s, got %s.\n", wine_dbgstr_rect(&rect),
18485 wine_dbgstr_rect(&clip_rect));
18487 hr = set_display_mode(ddraw, param.new_width, param.new_height);
18488 ok(hr == DD_OK || hr == DDERR_UNSUPPORTED, "SetDisplayMode failed, hr %#lx.\n", hr);
18489 if (FAILED(hr))
18491 win_skip("SetDisplayMode failed, hr %#lx.\n", hr);
18492 goto done;
18494 flush_events();
18495 get_virtual_rect(&rect);
18496 ret = GetClipCursor(&clip_rect);
18497 ok(ret, "GetClipCursor failed, error %lu.\n", GetLastError());
18498 ok(EqualRect(&clip_rect, &rect), "Expect clip rect %s, got %s.\n", wine_dbgstr_rect(&rect),
18499 wine_dbgstr_rect(&clip_rect));
18501 hr = IDirectDraw4_RestoreDisplayMode(ddraw);
18502 ok(hr == DD_OK, "RestoreDisplayMode failed, hr %#lx.\n", hr);
18503 flush_events();
18504 get_virtual_rect(&rect);
18505 ret = GetClipCursor(&clip_rect);
18506 ok(ret, "GetClipCursor failed, error %lu.\n", GetLastError());
18507 ok(EqualRect(&clip_rect, &rect), "Expect clip rect %s, got %s.\n", wine_dbgstr_rect(&rect),
18508 wine_dbgstr_rect(&clip_rect));
18510 /* Switch to full screen cooperative level */
18511 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
18512 ok(hr == DD_OK, "SetCooperativeLevel failed, hr %#lx.\n", hr);
18513 flush_events();
18514 SetRect(&rect, 0, 0, param.old_width, param.old_height);
18515 ret = GetClipCursor(&clip_rect);
18516 ok(ret, "GetClipCursor failed, error %lu.\n", GetLastError());
18517 ok(EqualRect(&clip_rect, &rect), "Expect clip rect %s, got %s.\n", wine_dbgstr_rect(&rect),
18518 wine_dbgstr_rect(&clip_rect));
18520 hr = set_display_mode(ddraw, param.new_width, param.new_height);
18521 ok(hr == DD_OK || hr == DDERR_UNSUPPORTED, "SetDisplayMode failed, hr %#lx.\n", hr);
18522 if (FAILED(hr))
18524 win_skip("SetDisplayMode failed, hr %#lx.\n", hr);
18525 goto done;
18527 flush_events();
18528 SetRect(&rect, 0, 0, param.new_width, param.new_height);
18529 ret = GetClipCursor(&clip_rect);
18530 ok(ret, "GetClipCursor failed, error %lu.\n", GetLastError());
18531 ok(EqualRect(&clip_rect, &rect), "Expect clip rect %s, got %s.\n", wine_dbgstr_rect(&rect),
18532 wine_dbgstr_rect(&clip_rect));
18534 /* Restore display mode */
18535 hr = IDirectDraw4_RestoreDisplayMode(ddraw);
18536 ok(hr == DD_OK, "RestoreDisplayMode failed, hr %#lx.\n", hr);
18537 flush_events();
18538 SetRect(&rect, 0, 0, param.old_width, param.old_height);
18539 ret = GetClipCursor(&clip_rect);
18540 ok(ret, "GetClipCursor failed, error %lu.\n", GetLastError());
18541 ok(EqualRect(&clip_rect, &rect), "Expect clip rect %s, got %s.\n", wine_dbgstr_rect(&rect),
18542 wine_dbgstr_rect(&clip_rect));
18544 /* Switch to normal cooperative level */
18545 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
18546 ok(hr == DD_OK, "SetCooperativeLevel failed, hr %#lx.\n", hr);
18547 flush_events();
18548 get_virtual_rect(&rect);
18549 ret = GetClipCursor(&clip_rect);
18550 ok(ret, "GetClipCursor failed, error %lu.\n", GetLastError());
18551 ok(EqualRect(&clip_rect, &rect), "Expect clip rect %s, got %s.\n", wine_dbgstr_rect(&rect),
18552 wine_dbgstr_rect(&clip_rect));
18554 done:
18555 IDirectDraw4_Release(ddraw);
18556 DestroyWindow(window);
18559 static BOOL CALLBACK test_window_position_cb(HMONITOR monitor, HDC hdc, RECT *monitor_rect,
18560 LPARAM lparam)
18562 RECT primary_rect, window_rect, new_rect;
18563 IDirectDraw4 *ddraw;
18564 HWND window;
18565 HRESULT hr;
18566 BOOL ret;
18568 ddraw = create_ddraw();
18569 ok(!!ddraw, "Failed to create a ddraw object.\n");
18570 window = CreateWindowA("static", "ddraw_test", WS_POPUP | WS_VISIBLE, monitor_rect->left,
18571 monitor_rect->top, 100, 100, NULL, NULL, NULL, NULL);
18572 ok(!!window, "Failed to create a window.\n");
18573 flush_events();
18575 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
18576 ok(hr == DD_OK, "SetCooperativeLevel failed, hr %#lx.\n", hr);
18577 flush_events();
18578 ret = GetWindowRect(window, &window_rect);
18579 ok(ret, "GetWindowRect failed, error %lu.\n", GetLastError());
18580 SetRect(&primary_rect, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
18581 ok(EqualRect(&window_rect, &primary_rect), "Expect window rect %s, got %s.\n",
18582 wine_dbgstr_rect(&primary_rect), wine_dbgstr_rect(&window_rect));
18584 new_rect = window_rect;
18585 --new_rect.right;
18586 --new_rect.bottom;
18588 ret = MoveWindow(window, new_rect.left, new_rect.top, new_rect.right - new_rect.left,
18589 new_rect.bottom - new_rect.top, TRUE);
18590 ok(ret, "Got unexpected ret %#x, error %lu.\n", ret, GetLastError());
18591 ret = GetWindowRect(window, &window_rect);
18592 ok(ret, "Got unexpected ret %#x, error %lu.\n", ret, GetLastError());
18593 ok(EqualRect(&window_rect, &new_rect),
18594 "Expected window rect %s, got %s.\n",
18595 wine_dbgstr_rect(monitor_rect), wine_dbgstr_rect(&window_rect));
18596 /* After processing window events window rectangle gets restored. But only once, the size set
18597 * on the second resize remains. */
18598 flush_events();
18599 ret = GetWindowRect(window, &window_rect);
18600 ok(ret, "Got unexpected ret %#x, error %lu.\n", ret, GetLastError());
18601 /* Both Windows and Wine change the size of the window. On Windows it is exactly the new size but in Wine
18602 * it may get adjusted depending on window manager. */
18603 ok(window_rect.right != monitor_rect->right && window_rect.bottom != monitor_rect->bottom,
18604 "Expected window rect %s, got %s.\n",
18605 wine_dbgstr_rect(monitor_rect), wine_dbgstr_rect(&window_rect));
18607 ret = MoveWindow(window, new_rect.left, new_rect.top, new_rect.right - new_rect.left,
18608 new_rect.bottom - new_rect.top, TRUE);
18609 ok(ret, "Got unexpected ret %#x, error %lu.\n", ret, GetLastError());
18610 ret = GetWindowRect(window, &window_rect);
18611 ok(ret, "Got unexpected ret %#x, error %lu.\n", ret, GetLastError());
18612 ok(EqualRect(&window_rect, &new_rect),
18613 "Expected window rect %s, got %s.\n",
18614 wine_dbgstr_rect(monitor_rect), wine_dbgstr_rect(&window_rect));
18615 flush_events();
18616 ret = GetWindowRect(window, &window_rect);
18617 ok(ret, "Got unexpected ret %#x, error %lu.\n", ret, GetLastError());
18618 ok(window_rect.right != monitor_rect->right && window_rect.bottom != monitor_rect->bottom,
18619 "Expected window rect %s, got %s.\n",
18620 wine_dbgstr_rect(monitor_rect), wine_dbgstr_rect(&window_rect));
18622 /* Window activation should restore the window to fit the whole primary monitor */
18623 ret = SetWindowPos(window, 0, monitor_rect->left, monitor_rect->top, 0, 0,
18624 SWP_NOZORDER | SWP_NOSIZE);
18625 ok(ret, "SetWindowPos failed, error %lu.\n", GetLastError());
18626 ret = SetForegroundWindow(GetDesktopWindow());
18627 ok(ret, "Failed to set foreground window.\n");
18628 flush_events();
18629 ret = ShowWindow(window, SW_RESTORE);
18630 ok(ret, "Failed to restore window, error %lu.\n", GetLastError());
18631 flush_events();
18632 ret = SetForegroundWindow(window);
18633 ok(ret, "SetForegroundWindow failed, error %lu.\n", GetLastError());
18634 flush_events();
18635 ret = GetWindowRect(window, &window_rect);
18636 ok(ret, "GetWindowRect failed, error %lu.\n", GetLastError());
18637 ok(EqualRect(&window_rect, &primary_rect), "Expect window rect %s, got %s.\n",
18638 wine_dbgstr_rect(&primary_rect), wine_dbgstr_rect(&window_rect));
18640 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
18641 ok(hr == DD_OK, "SetCooperativeLevel failed, hr %#lx.\n", hr);
18642 ret = GetWindowRect(window, &window_rect);
18643 ok(ret, "GetWindowRect failed, error %lu.\n", GetLastError());
18644 ok(EqualRect(&window_rect, &primary_rect), "Expect window rect %s, got %s.\n",
18645 wine_dbgstr_rect(&primary_rect), wine_dbgstr_rect(&window_rect));
18647 DestroyWindow(window);
18648 IDirectDraw4_Release(ddraw);
18649 return TRUE;
18652 static void test_window_position(void)
18654 EnumDisplayMonitors(NULL, NULL, test_window_position_cb, 0);
18657 static BOOL CALLBACK test_get_display_mode_cb(HMONITOR monitor, HDC hdc, RECT *monitor_rect,
18658 LPARAM lparam)
18660 DDSURFACEDESC2 surface_desc;
18661 IDirectDraw4 *ddraw;
18662 HWND window;
18663 HRESULT hr;
18664 BOOL ret;
18666 ddraw = create_ddraw();
18667 ok(!!ddraw, "Failed to create a ddraw object.\n");
18668 window = create_window();
18669 ok(!!window, "Failed to create a window.\n");
18671 /* Test that DirectDraw doesn't use the device window to determine which monitor to use */
18672 ret = SetWindowPos(window, 0, monitor_rect->left, monitor_rect->top, 0, 0,
18673 SWP_NOZORDER | SWP_NOSIZE);
18674 ok(ret, "SetWindowPos failed, error %lu.\n", GetLastError());
18676 surface_desc.dwSize = sizeof(surface_desc);
18677 hr = IDirectDraw4_GetDisplayMode(ddraw, &surface_desc);
18678 ok(hr == DD_OK, "GetDisplayMode failed, hr %#lx.\n", hr);
18679 ok(surface_desc.dwWidth == GetSystemMetrics(SM_CXSCREEN), "Expect width %d, got %lu.\n",
18680 GetSystemMetrics(SM_CXSCREEN), surface_desc.dwWidth);
18681 ok(surface_desc.dwHeight == GetSystemMetrics(SM_CYSCREEN), "Expect height %d, got %lu.\n",
18682 GetSystemMetrics(SM_CYSCREEN), surface_desc.dwHeight);
18684 DestroyWindow(window);
18685 IDirectDraw4_Release(ddraw);
18686 return TRUE;
18689 static void test_get_display_mode(void)
18691 static const DWORD flags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_REFRESHRATE | DDSD_PIXELFORMAT | DDSD_PITCH;
18692 struct find_different_mode_param param;
18693 DDSURFACEDESC2 surface_desc;
18694 IDirectDraw4 *ddraw;
18695 DEVMODEW devmode;
18696 HWND window;
18697 HRESULT hr;
18698 BOOL ret;
18700 EnumDisplayMonitors(NULL, NULL, test_get_display_mode_cb, 0);
18702 ddraw = create_ddraw();
18703 ok(!!ddraw, "Failed to create a ddraw object.\n");
18704 window = create_window();
18705 ok(!!window, "Failed to create a window.\n");
18707 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
18708 ok(hr == DD_OK, "SetCooperativeLevel failed, hr %#lx.\n", hr);
18710 memset(&devmode, 0, sizeof(devmode));
18711 devmode.dmSize = sizeof(devmode);
18712 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
18713 ok(ret, "EnumDisplaySettingsW failed, error %lu.\n", GetLastError());
18715 surface_desc.dwSize = sizeof(surface_desc);
18716 hr = IDirectDraw4_GetDisplayMode(ddraw, &surface_desc);
18717 ok(hr == DD_OK, "GetDisplayMode failed, hr %#lx.\n", hr);
18718 ok(surface_desc.dwSize == sizeof(surface_desc), "Got dwSize %lu.\n", surface_desc.dwSize);
18719 ok(surface_desc.dwFlags == flags, "Expected dwFlags %#lx, got %#lx.\n", flags,
18720 surface_desc.dwFlags);
18721 ok(surface_desc.dwWidth == devmode.dmPelsWidth, "Expected width %lu, got %lu.\n",
18722 devmode.dmPelsWidth, surface_desc.dwWidth);
18723 ok(surface_desc.dwHeight == devmode.dmPelsHeight, "Expected height %lu, got %lu.\n",
18724 devmode.dmPelsHeight, surface_desc.dwHeight);
18725 ok(surface_desc.dwRefreshRate == devmode.dmDisplayFrequency, "Expected frequency %lu, got %lu.\n",
18726 devmode.dmDisplayFrequency, surface_desc.dwRefreshRate);
18727 ok(surface_desc.ddpfPixelFormat.dwSize == sizeof(surface_desc.ddpfPixelFormat),
18728 "Got ddpfPixelFormat.dwSize %lu.\n", surface_desc.ddpfPixelFormat.dwSize);
18729 ok(surface_desc.ddpfPixelFormat.dwRGBBitCount == devmode.dmBitsPerPel,
18730 "Expected ddpfPixelFormat.dwRGBBitCount %lu, got %lu.\n", devmode.dmBitsPerPel,
18731 surface_desc.ddpfPixelFormat.dwRGBBitCount);
18732 ok(surface_desc.lPitch == devmode.dmPelsWidth * devmode.dmBitsPerPel / 8,
18733 "Expected pitch %lu, got %lu.\n", devmode.dmPelsWidth * devmode.dmBitsPerPel / 8,
18734 surface_desc.lPitch);
18736 memset(&param, 0, sizeof(param));
18737 param.old_frequency = surface_desc.dwRefreshRate;
18738 hr = IDirectDraw4_EnumDisplayModes(ddraw, DDEDM_REFRESHRATES, NULL, &param,
18739 find_different_mode_callback);
18740 ok(hr == DD_OK, "EnumDisplayModes failed, hr %#lx.\n", hr);
18741 if (!param.new_frequency)
18743 skip("Failed to find a display mode with a different frequency.\n");
18744 goto done;
18747 hr = IDirectDraw4_SetDisplayMode(ddraw, param.new_width, param.new_height, param.new_bpp,
18748 param.new_frequency, 0);
18749 ok(hr == DD_OK, "SetDisplayMode failed, hr %#lx.\n", hr);
18750 hr = IDirectDraw4_GetDisplayMode(ddraw, &surface_desc);
18751 ok(hr == DD_OK, "GetDisplayMode failed, hr %#lx.\n", hr);
18752 ok(surface_desc.dwWidth == param.new_width, "Expected width %u, got %lu.\n", param.new_width,
18753 surface_desc.dwWidth);
18754 ok(surface_desc.dwHeight == param.new_height, "Expected height %u, got %lu.\n", param.new_height,
18755 surface_desc.dwHeight);
18756 ok(surface_desc.dwRefreshRate == param.new_frequency, "Expected frequency %u, got %lu.\n",
18757 param.new_frequency, surface_desc.dwRefreshRate);
18758 ok(surface_desc.ddpfPixelFormat.dwRGBBitCount == param.new_bpp,
18759 "Expected ddpfPixelFormat.dwRGBBitCount %lu, got %lu.\n", devmode.dmBitsPerPel,
18760 surface_desc.ddpfPixelFormat.dwRGBBitCount);
18762 done:
18763 DestroyWindow(window);
18764 IDirectDraw4_Release(ddraw);
18767 static void run_for_each_device_type(void (*test_func)(const GUID *))
18769 test_func(&IID_IDirect3DHALDevice);
18770 test_func(&IID_IDirect3DRGBDevice);
18773 static void test_texture_wrong_caps(const GUID *device_guid)
18775 static struct
18777 struct vec3 position;
18778 unsigned int diffuse;
18779 struct vec2 texcoord;
18781 quad[] =
18783 {{-1.0f, -1.0f, 0.0f}, 0x00ff0000, {0.0f, 1.0f}},
18784 {{-1.0f, 1.0f, 0.0f}, 0x00ff0000, {0.0f, 0.0f}},
18785 {{ 1.0f, -1.0f, 0.0f}, 0x00ff0000, {1.0f, 1.0f}},
18786 {{ 1.0f, 1.0f, 0.0f}, 0x00ff0000, {1.0f, 0.0f}},
18788 static DDPIXELFORMAT fmt =
18790 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
18791 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
18793 D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
18794 IDirect3DTexture2 *texture, *ret_texture;
18795 unsigned int color, expected_color;
18796 IDirectDrawSurface4 *surface, *rt;
18797 IDirect3DViewport3 *viewport;
18798 IDirect3DDevice3 *device;
18799 IDirectDraw4 *ddraw;
18800 DDSURFACEDESC2 ddsd;
18801 IDirect3D3 *d3d;
18802 ULONG refcount;
18803 HWND window;
18804 HRESULT hr;
18806 window = create_window();
18807 if (!(device = create_device_ex(window, DDSCL_NORMAL, device_guid, NULL)))
18809 skip("Failed to create a 3D device, skipping test.\n");
18810 DestroyWindow(window);
18811 return;
18813 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
18814 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
18815 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
18816 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
18817 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
18818 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
18820 viewport = create_viewport(device, 0, 0, 640, 480);
18821 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
18822 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
18824 memset(&ddsd, 0, sizeof(ddsd));
18825 ddsd.dwSize = sizeof(ddsd);
18826 ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
18827 ddsd.dwHeight = 16;
18828 ddsd.dwWidth = 16;
18829 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
18830 ddsd.ddpfPixelFormat = fmt;
18831 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
18832 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
18833 hr = IDirectDrawSurface4_QueryInterface(surface, &IID_IDirect3DTexture2, (void **)&texture);
18834 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
18836 fill_surface(surface, 0xff00ff00);
18838 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
18839 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
18840 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
18841 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
18843 hr = IDirect3DDevice3_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
18844 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
18845 hr = IDirect3DDevice3_SetTextureStageState(device, 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
18846 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
18847 hr = IDirect3DDevice3_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
18848 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
18849 hr = IDirect3DDevice3_SetTextureStageState(device, 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
18850 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
18852 hr = IDirect3DDevice3_SetTexture(device, 0, texture);
18853 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
18854 hr = IDirect3DDevice3_GetTexture(device, 0, &ret_texture);
18855 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
18856 todo_wine_if (!is_software_device_type(device_guid))
18857 ok(ret_texture == texture, "Got texture %p.\n", ret_texture);
18859 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0x000000ff, 0.0f, 0);
18860 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
18861 hr = IDirect3DDevice3_BeginScene(device);
18862 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
18863 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
18864 D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1, quad, 4, 0);
18865 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
18866 hr = IDirect3DDevice3_EndScene(device);
18867 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
18869 expected_color = is_software_device_type(device_guid) ? 0x0000ff00 : 0x00ff0000;
18870 color = get_surface_color(rt, 320, 240);
18871 ok(color == expected_color, "Got color 0x%08x, expected 0x%08x.\n", color, expected_color);
18873 IDirect3DTexture2_Release(texture);
18874 IDirectDrawSurface4_Release(surface);
18875 IDirectDrawSurface4_Release(rt);
18876 destroy_viewport(device, viewport);
18877 IDirectDraw4_Release(ddraw);
18878 IDirect3D3_Release(d3d);
18879 refcount = IDirect3DDevice3_Release(device);
18880 ok(!refcount, "Device has %lu references left.\n", refcount);
18881 DestroyWindow(window);
18884 static void test_filling_convention(void)
18886 IDirectDrawSurface4 *rt, *backbuffer, *cur, *ds;
18887 static const DWORD colour_bottom = 0x00ffff00;
18888 static const DWORD colour_clear = 0x000000ff;
18889 static const DWORD colour_right = 0x00000000;
18890 static const DWORD colour_left = 0x00ff0000;
18891 static const DWORD colour_top = 0x0000ff00;
18892 unsigned int colour, expected, i, j, x, y;
18893 IDirect3DViewport3 *viewport;
18894 IDirect3DDevice3 *device;
18895 IDirectDraw4 *ddraw;
18896 DDSURFACEDESC2 desc;
18897 IDirect3D3 *d3d;
18898 ULONG refcount;
18899 HWND window;
18900 HRESULT hr;
18901 BOOL todo;
18903 static const unsigned int vp_size = 8;
18904 D3DRECT clear_rect = {{0}, {0}, {vp_size}, {vp_size}};
18906 /* This test data follows the examples in MSDN's
18907 * "Rasterization Rules (Direct3D 9)" article.
18909 * See the d3d9 test for a comment about the eps value. */
18910 static const float eps = 1.0f / 64.0f;
18911 struct
18913 struct vec3 position;
18914 DWORD diffuse;
18916 center_tris[] =
18918 /* left */
18919 {{-2.5f / 4.0f, -1.5f / 4.0f, 0.0f}, colour_left},
18920 {{-2.5f / 4.0f, 2.5f / 4.0f, 0.0f}, colour_left},
18921 {{-1.5f / 4.0f, 0.5f / 4.0f, 0.0f}, colour_left},
18923 /* top */
18924 {{-1.5f / 4.0f, 0.5f / 4.0f, 0.0f}, colour_top},
18925 {{-2.5f / 4.0f, 2.5f / 4.0f, 0.0f}, colour_top},
18926 {{-0.5f / 4.0f, 2.5f / 4.0f, 0.0f}, colour_top},
18928 /* right */
18929 {{-0.5f / 4.0f, -1.5f / 4.0f, 0.0f}, colour_right},
18930 {{-1.5f / 4.0f, 0.5f / 4.0f, 0.0f}, colour_right},
18931 {{-0.5f / 4.0f, 2.5f / 4.0f, 0.0f}, colour_right},
18933 /* bottom */
18934 {{-2.5f / 4.0f, -1.5f / 4.0f, 0.0f}, colour_bottom},
18935 {{-1.5f / 4.0f, 0.5f / 4.0f, 0.0f}, colour_bottom},
18936 {{-0.5f / 4.0f, -1.5f / 4.0f, 0.0f}, colour_bottom},
18939 edge_tris[] =
18941 /* left */
18942 {{-2.0f / 4.0f, -1.0f / 4.0f, 0.0f}, colour_left},
18943 {{-2.0f / 4.0f, 3.0f / 4.0f, 0.0f}, colour_left},
18944 {{-1.0f / 4.0f, 1.0f / 4.0f, 0.0f}, colour_left},
18946 /* top */
18947 {{-1.0f / 4.0f, 1.0f / 4.0f, 0.0f}, colour_top},
18948 {{-2.0f / 4.0f, 3.0f / 4.0f, 0.0f}, colour_top},
18949 {{ 0.0f / 4.0f, 3.0f / 4.0f, 0.0f}, colour_top},
18951 /* right */
18952 {{ 0.0f / 4.0f, -1.0f / 4.0f, 0.0f}, colour_right},
18953 {{-1.0f / 4.0f, 1.0f / 4.0f, 0.0f}, colour_right},
18954 {{ 0.0f / 4.0f, 3.0f / 4.0f, 0.0f}, colour_right},
18956 /* bottom */
18957 {{-2.0f / 4.0f, -1.0f / 4.0f, 0.0f}, colour_bottom},
18958 {{-1.0f / 4.0f, 1.0f / 4.0f, 0.0f}, colour_bottom},
18959 {{ 0.0f / 4.0f, -1.0f / 4.0f, 0.0f}, colour_bottom},
18961 nudge_right_tris[] =
18963 /* left */
18964 {{eps - 2.0f / 4.0f, -1.0f / 4.0f, 0.0f}, colour_left},
18965 {{eps - 2.0f / 4.0f, 3.0f / 4.0f, 0.0f}, colour_left},
18966 {{eps - 1.0f / 4.0f, 1.0f / 4.0f, 0.0f}, colour_left},
18968 /* top */
18969 {{eps - 1.0f / 4.0f, 1.0f / 4.0f, 0.0f}, colour_top},
18970 {{eps - 2.0f / 4.0f, 3.0f / 4.0f, 0.0f}, colour_top},
18971 {{eps - 0.0f / 4.0f, 3.0f / 4.0f, 0.0f}, colour_top},
18973 /* right */
18974 {{eps - 0.0f / 4.0f, -1.0f / 4.0f, 0.0f}, colour_right},
18975 {{eps - 1.0f / 4.0f, 1.0f / 4.0f, 0.0f}, colour_right},
18976 {{eps - 0.0f / 4.0f, 3.0f / 4.0f, 0.0f}, colour_right},
18978 /* bottom */
18979 {{eps - 2.0f / 4.0f, -1.0f / 4.0f, 0.0f}, colour_bottom},
18980 {{eps - 1.0f / 4.0f, 1.0f / 4.0f, 0.0f}, colour_bottom},
18981 {{eps - 0.0f / 4.0f, -1.0f / 4.0f, 0.0f}, colour_bottom},
18983 nudge_left_tris[] =
18985 {{-eps - 2.0f / 4.0f, -1.0f / 4.0f, 0.0f}, colour_left},
18986 {{-eps - 2.0f / 4.0f, 3.0f / 4.0f, 0.0f}, colour_left},
18987 {{-eps - 1.0f / 4.0f, 1.0f / 4.0f, 0.0f}, colour_left},
18989 /* top */
18990 {{-eps - 1.0f / 4.0f, 1.0f / 4.0f, 0.0f}, colour_top},
18991 {{-eps - 2.0f / 4.0f, 3.0f / 4.0f, 0.0f}, colour_top},
18992 {{-eps - 0.0f / 4.0f, 3.0f / 4.0f, 0.0f}, colour_top},
18994 /* right */
18995 {{-eps - 0.0f / 4.0f, -1.0f / 4.0f, 0.0f}, colour_right},
18996 {{-eps - 1.0f / 4.0f, 1.0f / 4.0f, 0.0f}, colour_right},
18997 {{-eps - 0.0f / 4.0f, 3.0f / 4.0f, 0.0f}, colour_right},
18999 /* bottom */
19000 {{-eps - 2.0f / 4.0f, -1.0f / 4.0f, 0.0f}, colour_bottom},
19001 {{-eps - 1.0f / 4.0f, 1.0f / 4.0f, 0.0f}, colour_bottom},
19002 {{-eps - 0.0f / 4.0f, -1.0f / 4.0f, 0.0f}, colour_bottom},
19004 nudge_top_tris[] =
19006 /* left */
19007 {{-2.0f / 4.0f, eps - 1.0f / 4.0f, 0.0f}, colour_left},
19008 {{-2.0f / 4.0f, eps + 3.0f / 4.0f, 0.0f}, colour_left},
19009 {{-1.0f / 4.0f, eps + 1.0f / 4.0f, 0.0f}, colour_left},
19011 /* top */
19012 {{-1.0f / 4.0f, eps + 1.0f / 4.0f, 0.0f}, colour_top},
19013 {{-2.0f / 4.0f, eps + 3.0f / 4.0f, 0.0f}, colour_top},
19014 {{ 0.0f / 4.0f, eps + 3.0f / 4.0f, 0.0f}, colour_top},
19016 /* right */
19017 {{ 0.0f / 4.0f, eps - 1.0f / 4.0f, 0.0f}, colour_right},
19018 {{-1.0f / 4.0f, eps + 1.0f / 4.0f, 0.0f}, colour_right},
19019 {{ 0.0f / 4.0f, eps + 3.0f / 4.0f, 0.0f}, colour_right},
19021 /* bottom */
19022 {{-2.0f / 4.0f, eps - 1.0f / 4.0f, 0.0f}, colour_bottom},
19023 {{-1.0f / 4.0f, eps + 1.0f / 4.0f, 0.0f}, colour_bottom},
19024 {{ 0.0f / 4.0f, eps - 1.0f / 4.0f, 0.0f}, colour_bottom},
19026 nudge_bottom_tris[] =
19028 /* left */
19029 {{-2.0f / 4.0f, -eps - 1.0f / 4.0f, 0.0f}, colour_left},
19030 {{-2.0f / 4.0f, -eps + 3.0f / 4.0f, 0.0f}, colour_left},
19031 {{-1.0f / 4.0f, -eps + 1.0f / 4.0f, 0.0f}, colour_left},
19033 /* top */
19034 {{-1.0f / 4.0f, -eps + 1.0f / 4.0f, 0.0f}, colour_top},
19035 {{-2.0f / 4.0f, -eps + 3.0f / 4.0f, 0.0f}, colour_top},
19036 {{ 0.0f / 4.0f, -eps + 3.0f / 4.0f, 0.0f}, colour_top},
19038 /* right */
19039 {{ 0.0f / 4.0f, -eps - 1.0f / 4.0f, 0.0f}, colour_right},
19040 {{-1.0f / 4.0f, -eps + 1.0f / 4.0f, 0.0f}, colour_right},
19041 {{ 0.0f / 4.0f, -eps + 3.0f / 4.0f, 0.0f}, colour_right},
19043 /* bottom */
19044 {{-2.0f / 4.0f, -eps - 1.0f / 4.0f, 0.0f}, colour_bottom},
19045 {{-1.0f / 4.0f, -eps + 1.0f / 4.0f, 0.0f}, colour_bottom},
19046 {{ 0.0f / 4.0f, -eps - 1.0f / 4.0f, 0.0f}, colour_bottom},
19049 struct
19051 struct vec4 position;
19052 DWORD diffuse;
19054 center_tris_t[] =
19056 /* left */
19057 {{ 1.5f, 1.5f, 0.0f, 1.0f}, colour_left},
19058 {{ 2.5f, 3.5f, 0.0f, 1.0f}, colour_left},
19059 {{ 1.5f, 5.5f, 0.0f, 1.0f}, colour_left},
19061 /* top */
19062 {{ 1.5f, 1.5f, 0.0f, 1.0f}, colour_top},
19063 {{ 3.5f, 1.5f, 0.0f, 1.0f}, colour_top},
19064 {{ 2.5f, 3.5f, 0.0f, 1.0f}, colour_top},
19066 /* right */
19067 {{ 3.5f, 1.5f, 0.0f, 1.0f}, colour_right},
19068 {{ 3.5f, 5.5f, 0.0f, 1.0f}, colour_right},
19069 {{ 2.5f, 3.5f, 0.0f, 1.0f}, colour_right},
19071 /* bottom */
19072 {{ 2.5f, 3.5f, 0.0f, 1.0f}, colour_bottom},
19073 {{ 3.5f, 5.5f, 0.0f, 1.0f}, colour_bottom},
19074 {{ 1.5f, 5.5f, 0.0f, 1.0f}, colour_bottom},
19076 edge_tris_t[] =
19078 /* left */
19079 {{ 2.0f, 1.0f, 0.0f, 1.0f}, colour_left},
19080 {{ 3.0f, 3.0f, 0.0f, 1.0f}, colour_left},
19081 {{ 2.0f, 5.0f, 0.0f, 1.0f}, colour_left},
19083 /* top */
19084 {{ 2.0f, 1.0f, 0.0f, 1.0f}, colour_top},
19085 {{ 4.0f, 1.0f, 0.0f, 1.0f}, colour_top},
19086 {{ 3.0f, 3.0f, 0.0f, 1.0f}, colour_top},
19088 /* right */
19089 {{ 4.0f, 1.0f, 0.0f, 1.0f}, colour_right},
19090 {{ 4.0f, 5.0f, 0.0f, 1.0f}, colour_right},
19091 {{ 3.0f, 3.0f, 0.0f, 1.0f}, colour_right},
19093 /* bottom */
19094 {{ 3.0f, 3.0f, 0.0f, 1.0f}, colour_bottom},
19095 {{ 4.0f, 5.0f, 0.0f, 1.0f}, colour_bottom},
19096 {{ 2.0f, 5.0f, 0.0f, 1.0f}, colour_bottom},
19099 const struct
19101 void *geometry;
19102 DWORD fvf;
19103 const char *expected[8];
19105 tests[] =
19108 center_tris,
19109 D3DFVF_XYZ | D3DFVF_DIFFUSE,
19111 " ",
19112 " ",
19113 " TT ",
19114 " LR ",
19115 " LR ",
19116 " BB ",
19117 " ",
19122 edge_tris,
19123 D3DFVF_XYZ | D3DFVF_DIFFUSE,
19125 " ",
19126 " TT ",
19127 " LT ",
19128 " LR ",
19129 " LB ",
19130 " ",
19131 " ",
19136 nudge_right_tris,
19137 D3DFVF_XYZ | D3DFVF_DIFFUSE,
19139 " ",
19140 " TT ",
19141 " TR ",
19142 " LR ",
19143 " BR ",
19144 " ",
19145 " ",
19150 nudge_left_tris,
19151 D3DFVF_XYZ | D3DFVF_DIFFUSE,
19153 " ",
19154 " TT ",
19155 " LT ",
19156 " LR ",
19157 " LB ",
19158 " ",
19159 " ",
19164 nudge_top_tris,
19165 D3DFVF_XYZ | D3DFVF_DIFFUSE,
19167 " ",
19168 " LT ",
19169 " LT ",
19170 " LB ",
19171 " LB ",
19172 " ",
19173 " ",
19178 nudge_bottom_tris,
19179 D3DFVF_XYZ | D3DFVF_DIFFUSE,
19181 " ",
19182 " ",
19183 " LT ",
19184 " Lt ",
19185 " LB ",
19186 " lB ",
19187 " ",
19192 center_tris_t,
19193 D3DFVF_XYZRHW | D3DFVF_DIFFUSE,
19195 " ",
19196 " ",
19197 " TT ",
19198 " LR ",
19199 " LR ",
19200 " BB ",
19201 " ",
19206 edge_tris_t,
19207 D3DFVF_XYZRHW | D3DFVF_DIFFUSE,
19209 " ",
19210 " TT ",
19211 " LT ",
19212 " LR ",
19213 " LB ",
19214 " ",
19215 " ",
19221 window = create_window();
19222 if (!(device = create_device(window, DDSCL_NORMAL)))
19224 skip("Failed to create 3D device.\n");
19225 DestroyWindow(window);
19226 return;
19229 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
19230 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
19231 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
19232 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
19233 hr = IDirect3DDevice3_GetRenderTarget(device, &backbuffer);
19234 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
19235 viewport = create_viewport(device, 0, 0, vp_size, vp_size);
19236 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
19237 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
19239 memset(&desc, 0, sizeof(desc));
19240 desc.dwSize = sizeof(desc);
19241 desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
19242 desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
19243 desc.dwWidth = vp_size;
19244 desc.dwHeight = vp_size;
19245 desc.ddpfPixelFormat.dwSize = sizeof(desc.ddpfPixelFormat);
19246 desc.ddpfPixelFormat.dwFlags = DDPF_RGB;
19247 desc.ddpfPixelFormat.dwRGBBitCount = 32;
19248 desc.ddpfPixelFormat.dwRBitMask = 0x00ff0000;
19249 desc.ddpfPixelFormat.dwGBitMask = 0x0000ff00;
19250 desc.ddpfPixelFormat.dwBBitMask = 0x000000ff;
19251 hr = IDirectDraw4_CreateSurface(ddraw, &desc, &rt, NULL);
19252 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
19254 /* Nvidia on Windows 10 refuses to set the offscreen RT
19255 * if it does not have an attached depth stencil. */
19256 ds = get_depth_stencil(device);
19257 memset(&desc, 0, sizeof(desc));
19258 desc.dwSize = sizeof(desc);
19259 desc.ddpfPixelFormat.dwSize = sizeof(desc.ddpfPixelFormat);
19260 hr = IDirectDrawSurface4_GetPixelFormat(ds, &desc.ddpfPixelFormat);
19261 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
19262 IDirectDrawSurface4_Release(ds);
19264 desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
19265 desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
19266 desc.dwWidth = vp_size;
19267 desc.dwHeight = vp_size;
19268 hr = IDirectDraw4_CreateSurface(ddraw, &desc, &ds, NULL);
19269 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
19270 hr = IDirectDrawSurface4_AddAttachedSurface(rt, ds);
19271 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#lx.\n", hr);
19273 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
19274 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
19275 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
19276 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
19278 for (i = 0; i < ARRAY_SIZE(tests); ++i)
19280 for (j = 0; j < 2; ++j)
19282 cur = j ? rt : backbuffer;
19284 hr = IDirect3DDevice3_SetRenderTarget(device, cur, 0);
19285 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
19286 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, colour_clear, 0.0f, 0);
19287 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
19289 hr = IDirect3DDevice3_BeginScene(device);
19290 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
19291 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLELIST,
19292 tests[i].fvf, tests[i].geometry, 12, 0);
19293 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
19294 hr = IDirect3DDevice3_EndScene(device);
19295 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
19297 for (y = 0; y < 8; y++)
19299 for (x = 0; x < 8; x++)
19301 todo = FALSE;
19302 switch (tests[i].expected[y][x])
19304 case 'l': todo = TRUE;
19305 case 'L':
19306 expected = colour_left;
19307 break;
19308 case 't': todo = TRUE;
19309 case 'T':
19310 expected = colour_top;
19311 break;
19312 case 'r': todo = TRUE;
19313 case 'R':
19314 expected = colour_right;
19315 break;
19316 case 'b': todo = TRUE;
19317 case 'B':
19318 expected = colour_bottom;
19319 break;
19320 case ' ':
19321 expected = colour_clear;
19322 break;
19323 default:
19324 ok(0, "Unexpected entry in expected test char\n");
19325 expected = 0xdeadbeef;
19327 colour = get_surface_color(cur, x, y);
19328 /* The nudge-to-bottom test fails on cards that give us a bottom-left
19329 * filling convention. The cause isn't the bottom part of the filling
19330 * convention, but because wined3d will nudge geometry to the left to
19331 * keep diagonals (the 'R' in test case 'edge_tris') intact. */
19332 todo_wine_if(todo && !compare_color(colour, expected, 1))
19333 ok(compare_color(colour, expected, 1), "Got unexpected colour %08x, %ux%u, case %u, j %u.\n",
19334 colour, x, y, i, j);
19340 destroy_viewport(device, viewport);
19341 IDirectDrawSurface4_Release(backbuffer);
19342 IDirectDrawSurface4_Release(rt);
19343 IDirectDrawSurface4_Release(ds);
19344 IDirectDraw4_Release(ddraw);
19345 IDirect3D3_Release(d3d);
19346 refcount = IDirect3DDevice3_Release(device);
19347 ok(!refcount, "Device has %lu references left.\n", refcount);
19348 DestroyWindow(window);
19351 static HRESULT WINAPI test_enum_devices_caps_callback(GUID *guid, char *device_desc,
19352 char *device_name, D3DDEVICEDESC *hal, D3DDEVICEDESC *hel, void *ctx)
19354 if(IsEqualGUID(&IID_IDirect3DRGBDevice, guid))
19356 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
19357 "RGB Device hal line caps has D3DPTEXTURECAPS_POW2 flag set\n");
19358 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
19359 "RGB Device hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n");
19360 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
19361 "RGB Device hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n");
19362 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
19363 "RGB Device hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n");
19365 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
19366 "RGB Device hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n");
19367 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
19368 "RGB Device hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n");
19369 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
19370 "RGB Device hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n");
19371 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
19372 "RGB Device hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n");
19374 ok(hal->dcmColorModel == 0, "RGB Device hal caps has colormodel %lu\n", hal->dcmColorModel);
19375 ok(hel->dcmColorModel == D3DCOLOR_RGB, "RGB Device hel caps has colormodel %lu\n", hel->dcmColorModel);
19377 ok(hal->dwFlags == 0, "RGB Device hal caps has hardware flags %#lx\n", hal->dwFlags);
19378 ok(hel->dwFlags != 0, "RGB Device hel caps has hardware flags %#lx\n", hel->dwFlags);
19380 ok((hal->dwDevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) == 0,
19381 "RGB Device hal device caps has D3DDEVCAPS_HWTRANSFORMANDLIGHT set\n");
19382 ok((hel->dwDevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) == 0,
19383 "RGB Device hel device caps has D3DDEVCAPS_HWTRANSFORMANDLIGHT set\n");
19384 ok((hal->dwDevCaps & D3DDEVCAPS_DRAWPRIMITIVES2EX) == 0,
19385 "RGB Device hal device caps has D3DDEVCAPS_DRAWPRIMITIVES2EX set\n");
19386 ok((hel->dwDevCaps & D3DDEVCAPS_DRAWPRIMITIVES2EX) == 0,
19387 "RGB Device hel device caps has D3DDEVCAPS_DRAWPRIMITIVES2EX set\n");
19388 ok((hal->dwDevCaps & D3DDEVCAPS_HWRASTERIZATION) == 0,
19389 "RGB Device hal device caps has D3DDEVCAPS_HWRASTERIZATION set\n");
19390 ok((hel->dwDevCaps & D3DDEVCAPS_HWRASTERIZATION) == 0,
19391 "RGB Device hel device caps has D3DDEVCAPS_HWRASTERIZATION set\n");
19393 else if(IsEqualGUID(&IID_IDirect3DHALDevice, guid))
19395 ok(hal->dcmColorModel == D3DCOLOR_RGB, "HAL Device hal caps has colormodel %lu\n", hel->dcmColorModel);
19396 ok(hel->dcmColorModel == 0, "HAL Device hel caps has colormodel %lu\n", hel->dcmColorModel);
19398 ok(hal->dwFlags != 0, "HAL Device hal caps has hardware flags %#lx\n", hal->dwFlags);
19399 ok(hel->dwFlags != 0, "HAL Device hel caps has hardware flags %#lx\n", hel->dwFlags);
19401 ok(hal->dwDevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT,
19402 "HAL Device hal device caps does not have D3DDEVCAPS_HWTRANSFORMANDLIGHT set\n");
19403 ok((hel->dwDevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) == 0,
19404 "RGB Device hel device caps has D3DDEVCAPS_HWTRANSFORMANDLIGHT set\n");
19405 ok(hal->dwDevCaps & D3DDEVCAPS_DRAWPRIMITIVES2EX,
19406 "HAL Device hal device caps does not have D3DDEVCAPS_DRAWPRIMITIVES2EX set\n");
19407 ok((hel->dwDevCaps & D3DDEVCAPS_DRAWPRIMITIVES2EX) == 0,
19408 "RGB Device hel device caps has D3DDEVCAPS_DRAWPRIMITIVES2EX set\n");
19410 else if(IsEqualGUID(&IID_IDirect3DRefDevice, guid))
19412 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
19413 "REF Device hal line caps has D3DPTEXTURECAPS_POW2 flag set\n");
19414 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
19415 "REF Device hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n");
19416 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
19417 "REF Device hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n");
19418 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
19419 "REF Device hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n");
19421 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
19422 "REF Device hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n");
19423 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
19424 "REF Device hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n");
19425 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
19426 "REF Device hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n");
19427 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
19428 "REF Device hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n");
19430 ok((hal->dwDevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) == 0,
19431 "REF Device hal device caps has D3DDEVCAPS_HWTRANSFORMANDLIGHT set\n");
19432 ok((hel->dwDevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) == 0,
19433 "REF Device hel device caps has D3DDEVCAPS_HWTRANSFORMANDLIGHT set\n");
19434 ok((hal->dwDevCaps & D3DDEVCAPS_DRAWPRIMITIVES2EX) == 0,
19435 "REF Device hal device caps has D3DDEVCAPS_DRAWPRIMITIVES2EX set\n");
19436 ok((hel->dwDevCaps & D3DDEVCAPS_DRAWPRIMITIVES2EX) == 0,
19437 "REF Device hel device caps has D3DDEVCAPS_DRAWPRIMITIVES2EX set\n");
19439 else if(IsEqualGUID(&IID_IDirect3DRampDevice, guid))
19441 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
19442 "Ramp Device hal line caps has D3DPTEXTURECAPS_POW2 flag set\n");
19443 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
19444 "Ramp Device hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n");
19445 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
19446 "Ramp Device hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n");
19447 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
19448 "Ramp Device hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n");
19450 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
19451 "Ramp Device hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n");
19452 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
19453 "Ramp Device hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n");
19454 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
19455 "Ramp Device hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n");
19456 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
19457 "Ramp Device hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n");
19459 ok(hal->dcmColorModel == 0, "Ramp Device hal caps has colormodel %lu\n", hal->dcmColorModel);
19460 ok(hel->dcmColorModel == D3DCOLOR_MONO, "Ramp Device hel caps has colormodel %lu\n",
19461 hel->dcmColorModel);
19463 ok(hal->dwFlags == 0, "Ramp Device hal caps has hardware flags %#lx\n", hal->dwFlags);
19464 ok(hel->dwFlags != 0, "Ramp Device hel caps has hardware flags %#lx\n", hel->dwFlags);
19466 ok((hal->dwDevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) == 0,
19467 "Ramp Device hal device caps has D3DDEVCAPS_HWTRANSFORMANDLIGHT set\n");
19468 ok((hel->dwDevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) == 0,
19469 "Ramp Device hel device caps has D3DDEVCAPS_HWTRANSFORMANDLIGHT set\n");
19470 ok((hal->dwDevCaps & D3DDEVCAPS_DRAWPRIMITIVES2EX) == 0,
19471 "Ramp Device hal device caps has D3DDEVCAPS_DRAWPRIMITIVES2EX set\n");
19472 ok((hel->dwDevCaps & D3DDEVCAPS_DRAWPRIMITIVES2EX) == 0,
19473 "Ramp Device hel device caps has D3DDEVCAPS_DRAWPRIMITIVES2EX set\n");
19475 else if(IsEqualGUID(&IID_IDirect3DMMXDevice, guid))
19477 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
19478 "MMX Device hal line caps has D3DPTEXTURECAPS_POW2 flag set\n");
19479 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
19480 "MMX Device hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n");
19481 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
19482 "MMX Device hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n");
19483 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
19484 "MMX Device hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n");
19486 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
19487 "MMX Device hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n");
19488 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
19489 "MMX Device hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n");
19490 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
19491 "MMX Device hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n");
19492 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
19493 "MMX Device hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n");
19495 ok(hal->dcmColorModel == 0, "MMX Device hal caps has colormodel %lu\n", hal->dcmColorModel);
19496 ok(hel->dcmColorModel == D3DCOLOR_RGB, "MMX Device hel caps has colormodel %lu\n", hel->dcmColorModel);
19498 ok(hal->dwFlags == 0, "MMX Device hal caps has hardware flags %#lx\n", hal->dwFlags);
19499 ok(hel->dwFlags != 0, "MMX Device hel caps has hardware flags %#lx\n", hel->dwFlags);
19501 ok((hal->dwDevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) == 0,
19502 "MMX Device hal device caps has D3DDEVCAPS_HWTRANSFORMANDLIGHT set\n");
19503 ok((hel->dwDevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) == 0,
19504 "MMX Device hel device caps has D3DDEVCAPS_HWTRANSFORMANDLIGHT set\n");
19505 ok((hal->dwDevCaps & D3DDEVCAPS_DRAWPRIMITIVES2EX) == 0,
19506 "MMX Device hal device caps has D3DDEVCAPS_DRAWPRIMITIVES2EX set\n");
19507 ok((hel->dwDevCaps & D3DDEVCAPS_DRAWPRIMITIVES2EX) == 0,
19508 "MMX Device hel device caps has D3DDEVCAPS_DRAWPRIMITIVES2EX set\n");
19510 else
19512 ok(FALSE, "Unexpected device enumerated: \"%s\" \"%s\"\n", device_desc, device_name);
19513 if (hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2)
19514 trace("hal line has pow2 set\n");
19515 else
19516 trace("hal line does NOT have pow2 set\n");
19517 if (hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2)
19518 trace("hal tri has pow2 set\n");
19519 else
19520 trace("hal tri does NOT have pow2 set\n");
19521 if (hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2)
19522 trace("hel line has pow2 set\n");
19523 else
19524 trace("hel line does NOT have pow2 set\n");
19525 if (hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2)
19526 trace("hel tri has pow2 set\n");
19527 else
19528 trace("hel tri does NOT have pow2 set\n");
19531 return DDENUMRET_OK;
19534 static void test_enum_devices(void)
19536 IDirectDraw4 *ddraw;
19537 IDirect3D3 *d3d;
19538 ULONG refcount;
19539 HRESULT hr;
19541 ddraw = create_ddraw();
19542 ok(!!ddraw, "Failed to create a ddraw object.\n");
19544 hr = IDirectDraw4_QueryInterface(ddraw, &IID_IDirect3D3, (void **)&d3d);
19545 if (FAILED(hr))
19547 skip("D3D interface is not available, skipping test.\n");
19548 IDirectDraw4_Release(ddraw);
19549 return;
19552 hr = IDirect3D3_EnumDevices(d3d, NULL, NULL);
19553 ok(hr == DDERR_INVALIDPARAMS, "Got hr %#lx.\n", hr);
19555 hr = IDirect3D3_EnumDevices(d3d, test_enum_devices_caps_callback, NULL);
19556 ok(hr == D3D_OK, "Got hr %#lx.\n", hr);
19558 IDirect3D3_Release(d3d);
19559 refcount = IDirectDraw4_Release(ddraw);
19560 ok(!refcount, "Device has %lu references left.\n", refcount);
19563 static void test_multiple_devices(void)
19565 IDirect3DDevice3 *device, *device2, *device3;
19566 D3DMATERIALHANDLE mat_handle, mat_handle2;
19567 IDirect3DViewport3 *viewport, *viewport2;
19568 IDirect3DMaterial3 *material;
19569 IDirectDrawSurface4 *surface;
19570 IDirectDraw4 *ddraw;
19571 IDirect3D3 *d3d;
19572 ULONG refcount;
19573 DWORD value;
19574 HWND window;
19575 HRESULT hr;
19577 window = create_window();
19578 if (!(device = create_device_ex(window, DDSCL_NORMAL, &IID_IDirect3DHALDevice, &surface)))
19580 skip("Failed to create a 3D device, skipping test.\n");
19581 DestroyWindow(window);
19582 return;
19585 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
19586 ok(hr == D3D_OK, "got %#lx.\n", hr);
19587 hr = IDirect3DDevice3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
19588 ok(hr == D3D_OK, "got %#lx.\n", hr);
19589 hr = IDirect3D3_CreateDevice(d3d, &IID_IDirect3DHALDevice, surface, &device2, NULL);
19590 ok(hr == D3D_OK, "got %#lx.\n", hr);
19592 device3 = create_device(window, DDSCL_NORMAL);
19593 ok(!!device3, "got NULL.\n");
19595 viewport = create_viewport(device, 0, 0, 640, 480);
19596 viewport2 = create_viewport(device2, 0, 0, 640, 480);
19597 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
19598 ok(hr == D3D_OK, "got %#lx.\n", hr);
19599 hr = IDirect3DDevice3_SetCurrentViewport(device2, viewport);
19600 ok(hr == DDERR_INVALIDPARAMS, "got %#lx.\n", hr);
19601 hr = IDirect3DDevice3_SetCurrentViewport(device2, viewport2);
19602 ok(hr == D3D_OK, "got %#lx.\n", hr);
19604 material = create_diffuse_material(device, 1.0f, 0.0f, 0.0f, 1.0f);
19605 hr = IDirect3DMaterial3_GetHandle(material, device, &mat_handle);
19606 ok(hr == D3D_OK, "got %#lx.\n", hr);
19607 hr = IDirect3DMaterial3_GetHandle(material, device, &mat_handle2);
19608 ok(hr == D3D_OK, "got %#lx.\n", hr);
19609 ok(mat_handle == mat_handle2, "got different handles.\n");
19611 hr = IDirect3DMaterial3_GetHandle(material, device2, &mat_handle2);
19612 ok(hr == D3D_OK, "got %#lx.\n", hr);
19613 todo_wine ok(mat_handle != mat_handle2, "got same handles.\n");
19615 hr = IDirect3DDevice3_SetLightState(device, D3DLIGHTSTATE_MATERIAL, mat_handle);
19616 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
19617 hr = IDirect3DDevice3_SetLightState(device2, D3DLIGHTSTATE_MATERIAL, mat_handle);
19618 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
19619 hr = IDirect3DDevice3_SetLightState(device3, D3DLIGHTSTATE_MATERIAL, mat_handle);
19620 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
19621 hr = IDirect3DDevice3_SetLightState(device, D3DLIGHTSTATE_MATERIAL, mat_handle2);
19622 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
19624 hr = IDirect3DViewport3_SetBackground(viewport, mat_handle);
19625 ok(hr == D3D_OK, "got %#lx.\n", hr);
19626 hr = IDirect3DViewport3_SetBackground(viewport2, mat_handle);
19627 ok(hr == D3D_OK, "got %#lx.\n", hr);
19629 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, FALSE);
19630 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
19631 hr = IDirect3DDevice3_SetRenderState(device2, D3DRENDERSTATE_ALPHABLENDENABLE, FALSE);
19632 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
19633 hr = IDirect3DDevice3_SetRenderState(device3, D3DRENDERSTATE_ALPHABLENDENABLE, FALSE);
19634 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
19636 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);
19637 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
19638 value = 0xdeadbeef;
19639 hr = IDirect3DDevice3_GetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, &value);
19640 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
19641 ok(value == TRUE, "got %#lx.\n", value);
19642 hr = IDirect3DDevice3_GetRenderState(device2, D3DRENDERSTATE_ALPHABLENDENABLE, &value);
19643 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
19644 ok(!value, "got %#lx.\n", value);
19645 hr = IDirect3DDevice3_GetRenderState(device3, D3DRENDERSTATE_ALPHABLENDENABLE, &value);
19646 ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr);
19647 ok(!value, "got %#lx.\n", value);
19649 IDirect3DMaterial3_Release(material);
19650 IDirect3DViewport3_Release(viewport);
19651 IDirect3DViewport3_Release(viewport2);
19653 refcount = IDirect3DDevice3_Release(device);
19654 ok(!refcount, "Device has %lu references left.\n", refcount);
19655 refcount = IDirect3DDevice3_Release(device2);
19656 ok(!refcount, "Device has %lu references left.\n", refcount);
19657 refcount = IDirect3DDevice3_Release(device3);
19658 ok(!refcount, "Device has %lu references left.\n", refcount);
19659 refcount = IDirectDrawSurface4_Release(surface);
19660 ok(!refcount, "Surface has %lu references left.\n", refcount);
19661 IDirectDraw4_Release(ddraw);
19662 IDirect3D3_Release(d3d);
19663 DestroyWindow(window);
19666 static void test_vb_desc(void)
19668 IDirect3DVertexBuffer *vb;
19669 D3DVERTEXBUFFERDESC desc;
19670 IDirectDraw4 *ddraw;
19671 IDirect3D3 *d3d;
19672 ULONG refcount;
19673 HWND window;
19674 HRESULT hr;
19676 static const DWORD caps_tests[] =
19679 D3DVBCAPS_WRITEONLY,
19680 D3DVBCAPS_SYSTEMMEMORY,
19681 D3DVBCAPS_SYSTEMMEMORY | D3DVBCAPS_WRITEONLY
19684 static const DWORD fvf_tests[] = {D3DFVF_XYZ, D3DFVF_XYZRHW};
19686 ddraw = create_ddraw();
19687 ok(!!ddraw, "Failed to create a ddraw object.\n");
19688 window = create_window();
19689 ok(!!window, "Failed to create a window.\n");
19690 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
19691 ok(hr == DD_OK, "SetCooperativeLevel failed, hr %#lx.\n", hr);
19693 hr = IDirectDraw4_QueryInterface(ddraw, &IID_IDirect3D3, (void **)&d3d);
19694 if (FAILED(hr))
19696 skip("D3D interface is not available, skipping test.\n");
19697 IDirectDraw4_Release(ddraw);
19698 return;
19701 for (unsigned int i = 0; i < ARRAY_SIZE(caps_tests); ++i)
19703 for (unsigned int j = 0; j < ARRAY_SIZE(fvf_tests); ++j)
19705 winetest_push_context("caps %#lx, fvf %#lx", caps_tests[i], fvf_tests[j]);
19707 desc.dwSize = sizeof(desc);
19708 desc.dwCaps = caps_tests[i];
19709 desc.dwFVF = fvf_tests[j];
19710 desc.dwNumVertices = 256;
19712 hr = IDirect3D3_CreateVertexBuffer(d3d, &desc, &vb, 0, NULL);
19713 ok(hr == S_OK, "Got hr %#lx.\n", hr);
19715 memset(&desc, 0, sizeof(desc));
19716 hr = IDirect3DVertexBuffer_GetVertexBufferDesc(vb, &desc);
19717 ok(hr == S_OK, "Got hr %#lx.\n", hr);
19719 ok(!desc.dwSize, "Got size %lu.\n", desc.dwSize);
19720 ok(desc.dwCaps == caps_tests[i], "Got caps %#lx.\n", desc.dwCaps);
19721 ok(desc.dwFVF == fvf_tests[j], "Got FVF %#lx.\n", desc.dwFVF);
19722 ok(desc.dwNumVertices == 256, "Got %lu vertices.\n", desc.dwNumVertices);
19724 IDirect3DVertexBuffer_Release(vb);
19726 winetest_pop_context();
19730 IDirect3D3_Release(d3d);
19731 DestroyWindow(window);
19732 refcount = IDirectDraw4_Release(ddraw);
19733 ok(!refcount, "Device has %lu references left.\n", refcount);
19736 START_TEST(ddraw4)
19738 DDDEVICEIDENTIFIER identifier;
19739 DEVMODEW current_mode;
19740 IDirectDraw4 *ddraw;
19741 HMODULE dwmapi;
19743 if (!(ddraw = create_ddraw()))
19745 skip("Failed to create a ddraw object, skipping tests.\n");
19746 return;
19749 if (ddraw_get_identifier(ddraw, &identifier))
19751 trace("Driver string: \"%s\"\n", identifier.szDriver);
19752 trace("Description string: \"%s\"\n", identifier.szDescription);
19753 trace("Driver version %d.%d.%d.%d\n",
19754 HIWORD(identifier.liDriverVersion.HighPart), LOWORD(identifier.liDriverVersion.HighPart),
19755 HIWORD(identifier.liDriverVersion.LowPart), LOWORD(identifier.liDriverVersion.LowPart));
19757 IDirectDraw4_Release(ddraw);
19759 memset(&current_mode, 0, sizeof(current_mode));
19760 current_mode.dmSize = sizeof(current_mode);
19761 ok(EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &current_mode), "Failed to get display mode.\n");
19762 registry_mode.dmSize = sizeof(registry_mode);
19763 ok(EnumDisplaySettingsW(NULL, ENUM_REGISTRY_SETTINGS, &registry_mode), "Failed to get display mode.\n");
19764 if (registry_mode.dmPelsWidth != current_mode.dmPelsWidth
19765 || registry_mode.dmPelsHeight != current_mode.dmPelsHeight)
19767 skip("Current mode does not match registry mode, skipping test.\n");
19768 return;
19771 if ((dwmapi = LoadLibraryA("dwmapi.dll")))
19772 pDwmIsCompositionEnabled = (void *)GetProcAddress(dwmapi, "DwmIsCompositionEnabled");
19774 test_process_vertices();
19775 test_coop_level_create_device_window();
19776 test_clipper_blt();
19777 test_coop_level_d3d_state();
19778 test_surface_interface_mismatch();
19779 test_coop_level_threaded();
19780 run_for_each_device_type(test_depth_blit);
19781 test_texture_load_ckey();
19782 test_viewport_object();
19783 run_for_each_device_type(test_zenable);
19784 run_for_each_device_type(test_ck_rgba);
19785 test_ck_default();
19786 test_ck_complex();
19787 test_surface_qi();
19788 test_device_qi();
19789 test_wndproc();
19790 test_window_style();
19791 test_redundant_mode_set();
19792 test_coop_level_mode_set();
19793 test_coop_level_mode_set_multi();
19794 test_initialize();
19795 test_coop_level_surf_create();
19796 test_vb_discard();
19797 test_coop_level_multi_window();
19798 test_draw_strided();
19799 test_lighting();
19800 test_specular_lighting();
19801 test_clear_rect_count();
19802 test_coop_level_versions();
19803 test_lighting_interface_versions();
19804 test_coop_level_activateapp();
19805 test_texturemanage();
19806 test_block_formats_creation();
19807 test_unsupported_formats();
19808 run_for_each_device_type(test_rt_caps);
19809 test_primary_caps();
19810 test_surface_lock();
19811 test_surface_discard();
19812 test_flip();
19813 test_set_surface_desc();
19814 test_user_memory_getdc();
19815 test_sysmem_overlay();
19816 test_primary_palette();
19817 test_surface_attachment();
19818 test_private_data();
19819 test_pixel_format();
19820 test_create_surface_pitch();
19821 test_mipmap();
19822 test_palette_complex();
19823 test_p8_blit();
19824 test_material();
19825 test_palette_gdi();
19826 test_palette_alpha();
19827 test_vb_writeonly();
19828 test_lost_device();
19829 test_surface_desc_lock();
19830 test_texturemapblend();
19831 test_signed_formats();
19832 test_color_fill();
19833 test_texcoordindex();
19834 test_colorkey_precision();
19835 test_range_colorkey();
19836 test_shademode();
19837 test_lockrect_invalid();
19838 test_yv12_overlay();
19839 test_offscreen_overlay();
19840 test_overlay_rect();
19841 test_blt();
19842 test_blt_z_alpha();
19843 test_cross_device_blt();
19844 test_color_clamping();
19845 test_getdc();
19846 test_draw_primitive();
19847 test_edge_antialiasing_blending();
19848 test_transform_vertices();
19849 test_display_mode_surface_pixel_format();
19850 test_surface_desc_size();
19851 test_get_surface_from_dc();
19852 test_ck_operation();
19853 test_vb_refcount();
19854 test_compute_sphere_visibility();
19855 test_texture_stages_limits();
19856 test_set_render_state();
19857 test_map_synchronisation();
19858 test_depth_readback();
19859 test_clear();
19860 test_enum_surfaces();
19861 test_viewport();
19862 test_find_device();
19863 test_killfocus();
19864 test_sysmem_draw();
19865 test_gdi_surface();
19866 test_alphatest();
19867 test_clipper_refcount();
19868 test_caps();
19869 test_d32_support();
19870 test_surface_format_conversion_alpha();
19871 test_cursor_clipping();
19872 test_window_position();
19873 test_get_display_mode();
19874 run_for_each_device_type(test_texture_wrong_caps);
19875 test_filling_convention();
19876 test_enum_devices();
19877 test_multiple_devices();
19878 test_vb_desc();