ddraw/tests: Fix double assigment to the same lvalue (coccinellery).
[wine.git] / dlls / ddraw / tests / ddraw4.c
blobbda2ebfa5444085fd53e6867ee71e3b2ab5e2ecc
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
20 #define COBJMACROS
22 #include "wine/test.h"
23 #include <limits.h>
24 #include <math.h>
25 #include "d3d.h"
27 HRESULT WINAPI GetSurfaceFromDC(HDC dc, struct IDirectDrawSurface **surface, HDC *device_dc);
29 static BOOL is_ddraw64 = sizeof(DWORD) != sizeof(DWORD *);
30 static DEVMODEW registry_mode;
32 static HRESULT (WINAPI *pDwmIsCompositionEnabled)(BOOL *);
34 #ifndef ARRAY_SIZE
35 #define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
36 #endif
38 struct vec2
40 float x, y;
43 struct vec3
45 float x, y, z;
48 struct vec4
50 float x, y, z, w;
53 struct create_window_thread_param
55 HWND window;
56 HANDLE window_created;
57 HANDLE destroy_window;
58 HANDLE thread;
61 static BOOL compare_float(float f, float g, unsigned int ulps)
63 int x = *(int *)&f;
64 int y = *(int *)&g;
66 if (x < 0)
67 x = INT_MIN - x;
68 if (y < 0)
69 y = INT_MIN - y;
71 if (abs(x - y) > ulps)
72 return FALSE;
74 return TRUE;
77 static BOOL compare_vec4(const struct vec4 *vec, float x, float y, float z, float w, unsigned int ulps)
79 return compare_float(vec->x, x, ulps)
80 && compare_float(vec->y, y, ulps)
81 && compare_float(vec->z, z, ulps)
82 && compare_float(vec->w, w, ulps);
85 static BOOL compare_color(D3DCOLOR c1, D3DCOLOR c2, BYTE max_diff)
87 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
88 c1 >>= 8; c2 >>= 8;
89 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
90 c1 >>= 8; c2 >>= 8;
91 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
92 c1 >>= 8; c2 >>= 8;
93 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
94 return TRUE;
97 static BOOL ddraw_is_warp(IDirectDraw4 *ddraw)
99 DDDEVICEIDENTIFIER identifier;
100 HRESULT hr;
102 if (!strcmp(winetest_platform, "wine"))
103 return FALSE;
105 hr = IDirectDraw4_GetDeviceIdentifier(ddraw, &identifier, 0);
106 ok(SUCCEEDED(hr), "Failed to get device identifier, hr %#x.\n", hr);
108 return !!strstr(identifier.szDriver, "warp");
111 static BOOL ddraw_is_nvidia(IDirectDraw4 *ddraw)
113 DDDEVICEIDENTIFIER identifier;
114 HRESULT hr;
116 if (!strcmp(winetest_platform, "wine"))
117 return FALSE;
119 hr = IDirectDraw4_GetDeviceIdentifier(ddraw, &identifier, 0);
120 ok(SUCCEEDED(hr), "Failed to get device identifier, hr %#x.\n", hr);
122 return identifier.dwVendorId == 0x10de;
125 static BOOL ddraw_is_intel(IDirectDraw4 *ddraw)
127 DDDEVICEIDENTIFIER identifier;
128 HRESULT hr;
130 if (!strcmp(winetest_platform, "wine"))
131 return FALSE;
133 hr = IDirectDraw4_GetDeviceIdentifier(ddraw, &identifier, 0);
134 ok(SUCCEEDED(hr), "Failed to get device identifier, hr %#x.\n", hr);
136 return identifier.dwVendorId == 0x8086;
139 static IDirectDrawSurface4 *create_overlay(IDirectDraw4 *ddraw,
140 unsigned int width, unsigned int height, DWORD format)
142 IDirectDrawSurface4 *surface;
143 DDSURFACEDESC2 desc;
145 memset(&desc, 0, sizeof(desc));
146 desc.dwSize = sizeof(desc);
147 desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
148 desc.dwWidth = width;
149 desc.dwHeight = height;
150 desc.ddsCaps.dwCaps = DDSCAPS_OVERLAY;
151 U4(desc).ddpfPixelFormat.dwSize = sizeof(U4(desc).ddpfPixelFormat);
152 U4(desc).ddpfPixelFormat.dwFlags = DDPF_FOURCC;
153 U4(desc).ddpfPixelFormat.dwFourCC = format;
155 if (FAILED(IDirectDraw4_CreateSurface(ddraw, &desc, &surface, NULL)))
156 return NULL;
157 return surface;
160 static DWORD WINAPI create_window_thread_proc(void *param)
162 struct create_window_thread_param *p = param;
163 DWORD res;
164 BOOL ret;
166 p->window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
167 0, 0, 640, 480, 0, 0, 0, 0);
168 ret = SetEvent(p->window_created);
169 ok(ret, "SetEvent failed, last error %#x.\n", GetLastError());
171 for (;;)
173 MSG msg;
175 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
176 DispatchMessageA(&msg);
177 res = WaitForSingleObject(p->destroy_window, 100);
178 if (res == WAIT_OBJECT_0)
179 break;
180 if (res != WAIT_TIMEOUT)
182 ok(0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
183 break;
187 DestroyWindow(p->window);
189 return 0;
192 static void create_window_thread(struct create_window_thread_param *p)
194 DWORD res, tid;
196 p->window_created = CreateEventA(NULL, FALSE, FALSE, NULL);
197 ok(!!p->window_created, "CreateEvent failed, last error %#x.\n", GetLastError());
198 p->destroy_window = CreateEventA(NULL, FALSE, FALSE, NULL);
199 ok(!!p->destroy_window, "CreateEvent failed, last error %#x.\n", GetLastError());
200 p->thread = CreateThread(NULL, 0, create_window_thread_proc, p, 0, &tid);
201 ok(!!p->thread, "Failed to create thread, last error %#x.\n", GetLastError());
202 res = WaitForSingleObject(p->window_created, INFINITE);
203 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
206 static void destroy_window_thread(struct create_window_thread_param *p)
208 SetEvent(p->destroy_window);
209 WaitForSingleObject(p->thread, INFINITE);
210 CloseHandle(p->destroy_window);
211 CloseHandle(p->window_created);
212 CloseHandle(p->thread);
215 static IDirectDrawSurface4 *get_depth_stencil(IDirect3DDevice3 *device)
217 IDirectDrawSurface4 *rt, *ret;
218 DDSCAPS2 caps = {DDSCAPS_ZBUFFER, 0, 0, {0}};
219 HRESULT hr;
221 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
222 ok(SUCCEEDED(hr), "Failed to get the render target, hr %#x.\n", hr);
223 hr = IDirectDrawSurface4_GetAttachedSurface(rt, &caps, &ret);
224 ok(SUCCEEDED(hr) || hr == DDERR_NOTFOUND, "Failed to get the z buffer, hr %#x.\n", hr);
225 IDirectDrawSurface4_Release(rt);
226 return ret;
229 static HRESULT set_display_mode(IDirectDraw4 *ddraw, DWORD width, DWORD height)
231 if (SUCCEEDED(IDirectDraw4_SetDisplayMode(ddraw, width, height, 32, 0, 0)))
232 return DD_OK;
233 return IDirectDraw4_SetDisplayMode(ddraw, width, height, 24, 0, 0);
236 static D3DCOLOR get_surface_color(IDirectDrawSurface4 *surface, UINT x, UINT y)
238 RECT rect = {x, y, x + 1, y + 1};
239 DDSURFACEDESC2 surface_desc;
240 D3DCOLOR color;
241 HRESULT hr;
243 memset(&surface_desc, 0, sizeof(surface_desc));
244 surface_desc.dwSize = sizeof(surface_desc);
246 hr = IDirectDrawSurface4_Lock(surface, &rect, &surface_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
247 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
248 if (FAILED(hr))
249 return 0xdeadbeef;
251 color = *((DWORD *)surface_desc.lpSurface) & 0x00ffffff;
253 hr = IDirectDrawSurface4_Unlock(surface, &rect);
254 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
256 return color;
259 static HRESULT CALLBACK enum_z_fmt(DDPIXELFORMAT *format, void *ctx)
261 DDPIXELFORMAT *z_fmt = ctx;
263 if (U1(*format).dwZBufferBitDepth > U1(*z_fmt).dwZBufferBitDepth)
264 *z_fmt = *format;
266 return DDENUMRET_OK;
269 static IDirectDraw4 *create_ddraw(void)
271 IDirectDraw4 *ddraw4;
272 IDirectDraw *ddraw1;
273 HRESULT hr;
275 if (FAILED(DirectDrawCreate(NULL, &ddraw1, NULL)))
276 return NULL;
278 hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirectDraw4, (void **)&ddraw4);
279 IDirectDraw_Release(ddraw1);
280 if (FAILED(hr))
281 return NULL;
283 return ddraw4;
286 static IDirect3DDevice3 *create_device(HWND window, DWORD coop_level)
288 IDirectDrawSurface4 *surface, *ds;
289 IDirect3DDevice3 *device = NULL;
290 DDSURFACEDESC2 surface_desc;
291 IDirectDraw4 *ddraw4;
292 DDPIXELFORMAT z_fmt;
293 IDirect3D3 *d3d3;
294 HRESULT hr;
296 if (!(ddraw4 = create_ddraw()))
297 return NULL;
299 hr = IDirectDraw4_SetCooperativeLevel(ddraw4, window, coop_level);
300 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
302 memset(&surface_desc, 0, sizeof(surface_desc));
303 surface_desc.dwSize = sizeof(surface_desc);
304 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
305 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
306 surface_desc.dwWidth = 640;
307 surface_desc.dwHeight = 480;
309 hr = IDirectDraw4_CreateSurface(ddraw4, &surface_desc, &surface, NULL);
310 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
312 if (coop_level & DDSCL_NORMAL)
314 IDirectDrawClipper *clipper;
316 hr = IDirectDraw4_CreateClipper(ddraw4, 0, &clipper, NULL);
317 ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr);
318 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
319 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
320 hr = IDirectDrawSurface4_SetClipper(surface, clipper);
321 ok(SUCCEEDED(hr), "Failed to set surface clipper, hr %#x.\n", hr);
322 IDirectDrawClipper_Release(clipper);
325 hr = IDirectDraw4_QueryInterface(ddraw4, &IID_IDirect3D3, (void **)&d3d3);
326 IDirectDraw4_Release(ddraw4);
327 if (FAILED(hr))
329 IDirectDrawSurface4_Release(surface);
330 return NULL;
333 memset(&z_fmt, 0, sizeof(z_fmt));
334 hr = IDirect3D3_EnumZBufferFormats(d3d3, &IID_IDirect3DHALDevice, enum_z_fmt, &z_fmt);
335 if (FAILED(hr) || !z_fmt.dwSize)
337 IDirect3D3_Release(d3d3);
338 IDirectDrawSurface4_Release(surface);
339 return NULL;
342 memset(&surface_desc, 0, sizeof(surface_desc));
343 surface_desc.dwSize = sizeof(surface_desc);
344 surface_desc.dwFlags = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT;
345 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
346 U4(surface_desc).ddpfPixelFormat = z_fmt;
347 surface_desc.dwWidth = 640;
348 surface_desc.dwHeight = 480;
349 hr = IDirectDraw4_CreateSurface(ddraw4, &surface_desc, &ds, NULL);
350 ok(SUCCEEDED(hr), "Failed to create depth buffer, hr %#x.\n", hr);
351 if (FAILED(hr))
353 IDirect3D3_Release(d3d3);
354 IDirectDrawSurface4_Release(surface);
355 return NULL;
358 hr = IDirectDrawSurface_AddAttachedSurface(surface, ds);
359 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
360 IDirectDrawSurface4_Release(ds);
361 if (FAILED(hr))
363 IDirect3D3_Release(d3d3);
364 IDirectDrawSurface4_Release(surface);
365 return NULL;
368 hr = IDirect3D3_CreateDevice(d3d3, &IID_IDirect3DHALDevice, surface, &device, NULL);
369 IDirect3D3_Release(d3d3);
370 IDirectDrawSurface4_Release(surface);
371 if (FAILED(hr))
372 return NULL;
374 return device;
377 static IDirect3DViewport3 *create_viewport(IDirect3DDevice3 *device, UINT x, UINT y, UINT w, UINT h)
379 IDirect3DViewport3 *viewport;
380 D3DVIEWPORT2 vp;
381 IDirect3D3 *d3d;
382 HRESULT hr;
384 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
385 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
386 hr = IDirect3D3_CreateViewport(d3d, &viewport, NULL);
387 ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
388 hr = IDirect3DDevice3_AddViewport(device, viewport);
389 ok(SUCCEEDED(hr), "Failed to add viewport, hr %#x.\n", hr);
390 memset(&vp, 0, sizeof(vp));
391 vp.dwSize = sizeof(vp);
392 vp.dwX = x;
393 vp.dwY = y;
394 vp.dwWidth = w;
395 vp.dwHeight = h;
396 vp.dvClipX = -1.0f;
397 vp.dvClipY = 1.0f;
398 vp.dvClipWidth = 2.0f;
399 vp.dvClipHeight = 2.0f;
400 vp.dvMinZ = 0.0f;
401 vp.dvMaxZ = 1.0f;
402 hr = IDirect3DViewport3_SetViewport2(viewport, &vp);
403 ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
404 IDirect3D3_Release(d3d);
406 return viewport;
409 static void destroy_viewport(IDirect3DDevice3 *device, IDirect3DViewport3 *viewport)
411 HRESULT hr;
413 hr = IDirect3DDevice3_DeleteViewport(device, viewport);
414 ok(SUCCEEDED(hr), "Failed to delete viewport, hr %#x.\n", hr);
415 IDirect3DViewport3_Release(viewport);
418 static IDirect3DMaterial3 *create_material(IDirect3DDevice3 *device, D3DMATERIAL *mat)
420 IDirect3DMaterial3 *material;
421 IDirect3D3 *d3d;
422 HRESULT hr;
424 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
425 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
426 hr = IDirect3D3_CreateMaterial(d3d, &material, NULL);
427 ok(SUCCEEDED(hr), "Failed to create material, hr %#x.\n", hr);
428 hr = IDirect3DMaterial3_SetMaterial(material, mat);
429 ok(SUCCEEDED(hr), "Failed to set material data, hr %#x.\n", hr);
430 IDirect3D3_Release(d3d);
432 return material;
435 static IDirect3DMaterial3 *create_diffuse_material(IDirect3DDevice3 *device, float r, float g, float b, float a)
437 D3DMATERIAL mat;
439 memset(&mat, 0, sizeof(mat));
440 mat.dwSize = sizeof(mat);
441 U1(U(mat).diffuse).r = r;
442 U2(U(mat).diffuse).g = g;
443 U3(U(mat).diffuse).b = b;
444 U4(U(mat).diffuse).a = a;
446 return create_material(device, &mat);
449 static IDirect3DMaterial3 *create_specular_material(IDirect3DDevice3 *device,
450 float r, float g, float b, float a, float power)
452 D3DMATERIAL mat;
454 memset(&mat, 0, sizeof(mat));
455 mat.dwSize = sizeof(mat);
456 U1(U2(mat).specular).r = r;
457 U2(U2(mat).specular).g = g;
458 U3(U2(mat).specular).b = b;
459 U4(U2(mat).specular).a = a;
460 U4(mat).power = power;
462 return create_material(device, &mat);
465 static IDirect3DMaterial3 *create_emissive_material(IDirect3DDevice3 *device, float r, float g, float b, float a)
467 D3DMATERIAL mat;
469 memset(&mat, 0, sizeof(mat));
470 mat.dwSize = sizeof(mat);
471 U1(U3(mat).emissive).r = r;
472 U2(U3(mat).emissive).g = g;
473 U3(U3(mat).emissive).b = b;
474 U4(U3(mat).emissive).a = a;
476 return create_material(device, &mat);
479 static void destroy_material(IDirect3DMaterial3 *material)
481 IDirect3DMaterial3_Release(material);
484 struct message
486 UINT message;
487 BOOL check_wparam;
488 WPARAM expect_wparam;
491 static const struct message *expect_messages;
493 static LRESULT CALLBACK test_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
495 if (expect_messages && message == expect_messages->message)
497 if (expect_messages->check_wparam)
498 ok (wparam == expect_messages->expect_wparam,
499 "Got unexpected wparam %lx for message %x, expected %lx.\n",
500 wparam, message, expect_messages->expect_wparam);
502 ++expect_messages;
505 return DefWindowProcA(hwnd, message, wparam, lparam);
508 /* Set the wndproc back to what ddraw expects it to be, and release the ddraw
509 * interface. This prevents subsequent SetCooperativeLevel() calls on a
510 * different window from failing with DDERR_HWNDALREADYSET. */
511 static void fix_wndproc(HWND window, LONG_PTR proc)
513 IDirectDraw4 *ddraw;
514 HRESULT hr;
516 if (!(ddraw = create_ddraw()))
517 return;
519 SetWindowLongPtrA(window, GWLP_WNDPROC, proc);
520 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
521 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
522 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
523 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
525 IDirectDraw4_Release(ddraw);
528 static void test_process_vertices(void)
530 IDirect3DVertexBuffer *src_vb, *dst_vb;
531 IDirect3DViewport3 *viewport;
532 D3DVERTEXBUFFERDESC vb_desc;
533 IDirect3DDevice3 *device;
534 struct vec3 *src_data;
535 struct vec4 *dst_data;
536 IDirect3D3 *d3d3;
537 D3DVIEWPORT2 vp2;
538 D3DVIEWPORT vp1;
539 HWND window;
540 HRESULT hr;
542 static D3DMATRIX identity =
544 1.0f, 0.0f, 0.0f, 0.0f,
545 0.0f, 1.0f, 0.0f, 0.0f,
546 0.0f, 0.0f, 1.0f, 0.0f,
547 0.0f, 0.0f, 0.0f, 1.0f,
549 static D3DMATRIX projection =
551 1.0f, 0.0f, 0.0f, 0.0f,
552 0.0f, 1.0f, 0.0f, 0.0f,
553 0.0f, 0.0f, 1.0f, 0.0f,
554 6.0f, 7.0f, 8.0f, 1.0f,
557 window = CreateWindowA("static", "d3d7_test", WS_OVERLAPPEDWINDOW,
558 0, 0, 640, 480, 0, 0, 0, 0);
559 if (!(device = create_device(window, DDSCL_NORMAL)))
561 skip("Failed to create a 3D device, skipping test.\n");
562 DestroyWindow(window);
563 return;
566 hr = IDirect3DDevice3_GetDirect3D(device, &d3d3);
567 ok(SUCCEEDED(hr), "Failed to get Direct3D3 interface, hr %#x.\n", hr);
569 memset(&vb_desc, 0, sizeof(vb_desc));
570 vb_desc.dwSize = sizeof(vb_desc);
571 vb_desc.dwFVF = D3DFVF_XYZ;
572 vb_desc.dwNumVertices = 3;
573 hr = IDirect3D3_CreateVertexBuffer(d3d3, &vb_desc, &src_vb, 0, NULL);
574 ok(SUCCEEDED(hr), "Failed to create source vertex buffer, hr %#x.\n", hr);
576 hr = IDirect3DVertexBuffer_Lock(src_vb, DDLOCK_WRITEONLY, (void **)&src_data, NULL);
577 ok(SUCCEEDED(hr), "Failed to lock source vertex buffer, hr %#x.\n", hr);
578 src_data[0].x = -1.0f;
579 src_data[0].y = -1.0f;
580 src_data[0].z = -1.0f;
581 src_data[1].x = 0.0f;
582 src_data[1].y = 0.0f;
583 src_data[1].z = 0.0f;
584 src_data[2].x = 1.0f;
585 src_data[2].y = 1.0f;
586 src_data[2].z = 1.0f;
587 hr = IDirect3DVertexBuffer_Unlock(src_vb);
588 ok(SUCCEEDED(hr), "Failed to unlock source vertex buffer, hr %#x.\n", hr);
590 memset(&vb_desc, 0, sizeof(vb_desc));
591 vb_desc.dwSize = sizeof(vb_desc);
592 vb_desc.dwFVF = D3DFVF_XYZRHW;
593 vb_desc.dwNumVertices = 3;
594 hr = IDirect3D3_CreateVertexBuffer(d3d3, &vb_desc, &dst_vb, 0, NULL);
595 ok(SUCCEEDED(hr), "Failed to create destination vertex buffer, hr %#x.\n", hr);
597 hr = IDirect3D3_CreateViewport(d3d3, &viewport, NULL);
598 ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
599 hr = IDirect3DDevice3_AddViewport(device, viewport);
600 ok(SUCCEEDED(hr), "Failed to add viewport, hr %#x.\n", hr);
601 vp2.dwSize = sizeof(vp2);
602 vp2.dwX = 10;
603 vp2.dwY = 20;
604 vp2.dwWidth = 100;
605 vp2.dwHeight = 200;
606 vp2.dvClipX = 2.0f;
607 vp2.dvClipY = 3.0f;
608 vp2.dvClipWidth = 4.0f;
609 vp2.dvClipHeight = 5.0f;
610 vp2.dvMinZ = -2.0f;
611 vp2.dvMaxZ = 3.0f;
612 hr = IDirect3DViewport3_SetViewport2(viewport, &vp2);
613 ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
614 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
615 ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr);
617 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &identity);
618 ok(SUCCEEDED(hr), "Failed to set world transformation, hr %#x.\n", hr);
619 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_VIEW, &identity);
620 ok(SUCCEEDED(hr), "Failed to set view transformation, hr %#x.\n", hr);
621 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &identity);
622 ok(SUCCEEDED(hr), "Failed to set projection transformation, hr %#x.\n", hr);
624 hr = IDirect3DVertexBuffer_ProcessVertices(dst_vb, D3DVOP_TRANSFORM, 0, 3, src_vb, 0, device, 0);
625 ok(SUCCEEDED(hr), "Failed to process vertices, hr %#x.\n", hr);
627 hr = IDirect3DVertexBuffer_Lock(dst_vb, DDLOCK_READONLY, (void **)&dst_data, NULL);
628 ok(SUCCEEDED(hr), "Failed to lock destination vertex buffer, hr %#x.\n", hr);
629 ok(compare_vec4(&dst_data[0], -6.500e+1f, +1.800e+2f, +2.000e-1f, +1.000e+0f, 4096),
630 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
631 dst_data[0].x, dst_data[0].y, dst_data[0].z, dst_data[0].w);
632 ok(compare_vec4(&dst_data[1], -4.000e+1f, +1.400e+2f, +4.000e-1f, +1.000e+0f, 4096),
633 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
634 dst_data[1].x, dst_data[1].y, dst_data[1].z, dst_data[1].w);
635 ok(compare_vec4(&dst_data[2], -1.500e+1f, +1.000e+2f, +6.000e-1f, +1.000e+0f, 4096),
636 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
637 dst_data[2].x, dst_data[2].y, dst_data[2].z, dst_data[2].w);
638 hr = IDirect3DVertexBuffer_Unlock(dst_vb);
639 ok(SUCCEEDED(hr), "Failed to unlock destination vertex buffer, hr %#x.\n", hr);
641 hr = IDirect3DDevice3_MultiplyTransform(device, D3DTRANSFORMSTATE_PROJECTION, &projection);
642 ok(SUCCEEDED(hr), "Failed to set projection transformation, hr %#x.\n", hr);
644 hr = IDirect3DVertexBuffer_ProcessVertices(dst_vb, D3DVOP_TRANSFORM, 0, 3, src_vb, 0, device, 0);
645 ok(SUCCEEDED(hr), "Failed to process vertices, hr %#x.\n", hr);
647 hr = IDirect3DVertexBuffer_Lock(dst_vb, DDLOCK_READONLY, (void **)&dst_data, NULL);
648 ok(SUCCEEDED(hr), "Failed to lock destination vertex buffer, hr %#x.\n", hr);
649 ok(compare_vec4(&dst_data[0], +8.500e+1f, -1.000e+2f, +1.800e+0f, +1.000e+0f, 4096),
650 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
651 dst_data[0].x, dst_data[0].y, dst_data[0].z, dst_data[0].w);
652 ok(compare_vec4(&dst_data[1], +1.100e+2f, -1.400e+2f, +2.000e+0f, +1.000e+0f, 4096),
653 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
654 dst_data[1].x, dst_data[1].y, dst_data[1].z, dst_data[1].w);
655 ok(compare_vec4(&dst_data[2], +1.350e+2f, -1.800e+2f, +2.200e+0f, +1.000e+0f, 4096),
656 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
657 dst_data[2].x, dst_data[2].y, dst_data[2].z, dst_data[2].w);
658 hr = IDirect3DVertexBuffer_Unlock(dst_vb);
659 ok(SUCCEEDED(hr), "Failed to unlock destination vertex buffer, hr %#x.\n", hr);
661 vp2.dwSize = sizeof(vp2);
662 vp2.dwX = 30;
663 vp2.dwY = 40;
664 vp2.dwWidth = 90;
665 vp2.dwHeight = 80;
666 vp2.dvClipX = 4.0f;
667 vp2.dvClipY = 6.0f;
668 vp2.dvClipWidth = 2.0f;
669 vp2.dvClipHeight = 4.0f;
670 vp2.dvMinZ = 3.0f;
671 vp2.dvMaxZ = -2.0f;
672 hr = IDirect3DViewport3_SetViewport2(viewport, &vp2);
673 ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
675 hr = IDirect3DVertexBuffer_ProcessVertices(dst_vb, D3DVOP_TRANSFORM, 0, 3, src_vb, 0, device, 0);
676 ok(SUCCEEDED(hr), "Failed to process vertices, hr %#x.\n", hr);
678 hr = IDirect3DVertexBuffer_Lock(dst_vb, DDLOCK_READONLY, (void **)&dst_data, NULL);
679 ok(SUCCEEDED(hr), "Failed to lock destination vertex buffer, hr %#x.\n", hr);
680 ok(compare_vec4(&dst_data[0], +7.500e+1f, +4.000e+1f, -8.000e-1f, +1.000e+0f, 4096),
681 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
682 dst_data[0].x, dst_data[0].y, dst_data[0].z, dst_data[0].w);
683 ok(compare_vec4(&dst_data[1], +1.200e+2f, +2.000e+1f, -1.000e+0f, +1.000e+0f, 4096),
684 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
685 dst_data[1].x, dst_data[1].y, dst_data[1].z, dst_data[1].w);
686 ok(compare_vec4(&dst_data[2], +1.650e+2f, +0.000e+0f, -1.200e+0f, +1.000e+0f, 4096),
687 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
688 dst_data[2].x, dst_data[2].y, dst_data[2].z, dst_data[2].w);
689 hr = IDirect3DVertexBuffer_Unlock(dst_vb);
690 ok(SUCCEEDED(hr), "Failed to unlock destination vertex buffer, hr %#x.\n", hr);
692 vp1.dwSize = sizeof(vp1);
693 vp1.dwX = 30;
694 vp1.dwY = 40;
695 vp1.dwWidth = 90;
696 vp1.dwHeight = 80;
697 vp1.dvScaleX = 7.0f;
698 vp1.dvScaleY = 2.0f;
699 vp1.dvMaxX = 6.0f;
700 vp1.dvMaxY = 10.0f;
701 vp1.dvMinZ = -2.0f;
702 vp1.dvMaxZ = 3.0f;
703 hr = IDirect3DViewport3_SetViewport(viewport, &vp1);
704 ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
706 hr = IDirect3DVertexBuffer_ProcessVertices(dst_vb, D3DVOP_TRANSFORM, 0, 3, src_vb, 0, device, 0);
707 ok(SUCCEEDED(hr), "Failed to process vertices, hr %#x.\n", hr);
709 hr = IDirect3DVertexBuffer_Lock(dst_vb, DDLOCK_READONLY, (void **)&dst_data, NULL);
710 ok(SUCCEEDED(hr), "Failed to lock destination vertex buffer, hr %#x.\n", hr);
711 ok(compare_vec4(&dst_data[0], +1.100e+2f, +6.800e+1f, +7.000e+0f, +1.000e+0f, 4096),
712 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
713 dst_data[0].x, dst_data[0].y, dst_data[0].z, dst_data[0].w);
714 ok(compare_vec4(&dst_data[1], +1.170e+2f, +6.600e+1f, +8.000e+0f, +1.000e+0f, 4096),
715 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
716 dst_data[1].x, dst_data[1].y, dst_data[1].z, dst_data[1].w);
717 ok(compare_vec4(&dst_data[2], +1.240e+2f, +6.400e+1f, +9.000e+0f, +1.000e+0f, 4096),
718 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
719 dst_data[2].x, dst_data[2].y, dst_data[2].z, dst_data[2].w);
720 hr = IDirect3DVertexBuffer_Unlock(dst_vb);
721 ok(SUCCEEDED(hr), "Failed to unlock destination vertex buffer, hr %#x.\n", hr);
723 hr = IDirect3DDevice3_DeleteViewport(device, viewport);
724 ok(SUCCEEDED(hr), "Failed to delete viewport, hr %#x.\n", hr);
726 IDirect3DVertexBuffer_Release(dst_vb);
727 IDirect3DVertexBuffer_Release(src_vb);
728 IDirect3DViewport3_Release(viewport);
729 IDirect3D3_Release(d3d3);
730 IDirect3DDevice3_Release(device);
731 DestroyWindow(window);
734 static void test_coop_level_create_device_window(void)
736 HWND focus_window, device_window;
737 IDirectDraw4 *ddraw;
738 HRESULT hr;
740 focus_window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
741 0, 0, 640, 480, 0, 0, 0, 0);
742 ddraw = create_ddraw();
743 ok(!!ddraw, "Failed to create a ddraw object.\n");
745 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
746 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
747 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
748 ok(!device_window, "Unexpected device window found.\n");
749 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW);
750 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
751 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
752 ok(!device_window, "Unexpected device window found.\n");
753 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_NORMAL);
754 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
755 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
756 ok(!device_window, "Unexpected device window found.\n");
757 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_NORMAL | DDSCL_FULLSCREEN);
758 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
759 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
760 ok(!device_window, "Unexpected device window found.\n");
761 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
762 ok(hr == DDERR_NOFOCUSWINDOW || broken(hr == DDERR_INVALIDPARAMS), "Got unexpected hr %#x.\n", hr);
763 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
764 ok(!device_window, "Unexpected device window found.\n");
766 /* Windows versions before 98 / NT5 don't support DDSCL_CREATEDEVICEWINDOW. */
767 if (broken(hr == DDERR_INVALIDPARAMS))
769 win_skip("DDSCL_CREATEDEVICEWINDOW not supported, skipping test.\n");
770 IDirectDraw4_Release(ddraw);
771 DestroyWindow(focus_window);
772 return;
775 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
776 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
777 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
778 ok(!device_window, "Unexpected device window found.\n");
779 hr = IDirectDraw4_SetCooperativeLevel(ddraw, focus_window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
780 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
781 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
782 ok(!device_window, "Unexpected device window found.\n");
784 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
785 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
786 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
787 ok(!device_window, "Unexpected device window found.\n");
788 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_SETFOCUSWINDOW
789 | DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
790 ok(hr == DDERR_NOHWND, "Got unexpected hr %#x.\n", hr);
791 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
792 ok(!!device_window, "Device window not found.\n");
794 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
795 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
796 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
797 ok(!device_window, "Unexpected device window found.\n");
798 hr = IDirectDraw4_SetCooperativeLevel(ddraw, focus_window, DDSCL_SETFOCUSWINDOW
799 | DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
800 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
801 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
802 ok(!!device_window, "Device window not found.\n");
804 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
805 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
806 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
807 ok(!device_window, "Unexpected device window found.\n");
808 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
809 ok(hr == DDERR_NOFOCUSWINDOW, "Got unexpected hr %#x.\n", hr);
810 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
811 ok(!device_window, "Unexpected device window found.\n");
812 hr = IDirectDraw4_SetCooperativeLevel(ddraw, focus_window, DDSCL_SETFOCUSWINDOW);
813 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
814 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
815 ok(!device_window, "Unexpected device window found.\n");
816 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
817 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
818 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
819 ok(!!device_window, "Device window not found.\n");
821 IDirectDraw4_Release(ddraw);
822 DestroyWindow(focus_window);
825 static void test_clipper_blt(void)
827 IDirectDrawSurface4 *src_surface, *dst_surface;
828 RECT client_rect, src_rect;
829 IDirectDrawClipper *clipper;
830 DDSURFACEDESC2 surface_desc;
831 unsigned int i, j, x, y;
832 IDirectDraw4 *ddraw;
833 RGNDATA *rgn_data;
834 D3DCOLOR color;
835 ULONG refcount;
836 HRGN r1, r2;
837 HWND window;
838 DDBLTFX fx;
839 HRESULT hr;
840 DWORD *ptr;
841 DWORD ret;
843 static const DWORD src_data[] =
845 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
846 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
847 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
849 static const D3DCOLOR expected1[] =
851 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
852 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
853 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
854 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
856 /* Nvidia on Windows seems to have an off-by-one error
857 * when processing source rectangles. Our left = 1 and
858 * right = 5 input reads from x = {1, 2, 3}. x = 4 is
859 * read as well, but only for the edge pixels on the
860 * output image. The bug happens on the y axis as well,
861 * but we only read one row there, and all source rows
862 * contain the same data. This bug is not dependent on
863 * the presence of a clipper. */
864 static const D3DCOLOR expected1_broken[] =
866 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
867 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
868 0x00000000, 0x00000000, 0x00ff0000, 0x00ff0000,
869 0x00000000, 0x00000000, 0x0000ff00, 0x00ff0000,
871 static const D3DCOLOR expected2[] =
873 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
874 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
875 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
876 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
879 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
880 10, 10, 640, 480, 0, 0, 0, 0);
881 ShowWindow(window, SW_SHOW);
882 ddraw = create_ddraw();
883 ok(!!ddraw, "Failed to create a ddraw object.\n");
885 ret = GetClientRect(window, &client_rect);
886 ok(ret, "Failed to get client rect.\n");
887 ret = MapWindowPoints(window, NULL, (POINT *)&client_rect, 2);
888 ok(ret, "Failed to map client rect.\n");
890 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
891 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
893 hr = IDirectDraw4_CreateClipper(ddraw, 0, &clipper, NULL);
894 ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr);
895 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
896 ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr);
897 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
898 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
899 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
900 ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr);
901 rgn_data = HeapAlloc(GetProcessHeap(), 0, ret);
902 hr = IDirectDrawClipper_GetClipList(clipper, NULL, rgn_data, &ret);
903 ok(SUCCEEDED(hr), "Failed to get clip list, hr %#x.\n", hr);
904 ok(rgn_data->rdh.dwSize == sizeof(rgn_data->rdh), "Got unexpected structure size %#x.\n", rgn_data->rdh.dwSize);
905 ok(rgn_data->rdh.iType == RDH_RECTANGLES, "Got unexpected type %#x.\n", rgn_data->rdh.iType);
906 ok(rgn_data->rdh.nCount >= 1, "Got unexpected count %u.\n", rgn_data->rdh.nCount);
907 ok(EqualRect(&rgn_data->rdh.rcBound, &client_rect),
908 "Got unexpected bounding rect %s, expected %s.\n",
909 wine_dbgstr_rect(&rgn_data->rdh.rcBound), wine_dbgstr_rect(&client_rect));
910 HeapFree(GetProcessHeap(), 0, rgn_data);
912 r1 = CreateRectRgn(0, 0, 320, 240);
913 ok(!!r1, "Failed to create region.\n");
914 r2 = CreateRectRgn(320, 240, 640, 480);
915 ok(!!r2, "Failed to create region.\n");
916 CombineRgn(r1, r1, r2, RGN_OR);
917 ret = GetRegionData(r1, 0, NULL);
918 rgn_data = HeapAlloc(GetProcessHeap(), 0, ret);
919 ret = GetRegionData(r1, ret, rgn_data);
920 ok(!!ret, "Failed to get region data.\n");
922 DeleteObject(r2);
923 DeleteObject(r1);
925 hr = IDirectDrawClipper_SetClipList(clipper, rgn_data, 0);
926 ok(hr == DDERR_CLIPPERISUSINGHWND, "Got unexpected hr %#x.\n", hr);
927 hr = IDirectDrawClipper_SetHWnd(clipper, 0, NULL);
928 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
929 hr = IDirectDrawClipper_SetClipList(clipper, rgn_data, 0);
930 ok(SUCCEEDED(hr), "Failed to set clip list, hr %#x.\n", hr);
932 HeapFree(GetProcessHeap(), 0, rgn_data);
934 memset(&surface_desc, 0, sizeof(surface_desc));
935 surface_desc.dwSize = sizeof(surface_desc);
936 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
937 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
938 surface_desc.dwWidth = 640;
939 surface_desc.dwHeight = 480;
940 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
941 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
942 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
943 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
944 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
945 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
947 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &src_surface, NULL);
948 ok(SUCCEEDED(hr), "Failed to create source surface, hr %#x.\n", hr);
949 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &dst_surface, NULL);
950 ok(SUCCEEDED(hr), "Failed to create destination surface, hr %#x.\n", hr);
952 memset(&fx, 0, sizeof(fx));
953 fx.dwSize = sizeof(fx);
954 hr = IDirectDrawSurface4_Blt(src_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
955 ok(SUCCEEDED(hr), "Failed to clear source surface, hr %#x.\n", hr);
956 hr = IDirectDrawSurface4_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
957 ok(SUCCEEDED(hr), "Failed to clear destination surface, hr %#x.\n", hr);
959 hr = IDirectDrawSurface4_Lock(src_surface, NULL, &surface_desc, DDLOCK_WAIT, NULL);
960 ok(SUCCEEDED(hr), "Failed to lock source surface, hr %#x.\n", hr);
961 ok(U1(surface_desc).lPitch == 2560, "Got unexpected surface pitch %u.\n", U1(surface_desc).lPitch);
962 ptr = surface_desc.lpSurface;
963 memcpy(&ptr[ 0], &src_data[ 0], 6 * sizeof(DWORD));
964 memcpy(&ptr[ 640], &src_data[ 6], 6 * sizeof(DWORD));
965 memcpy(&ptr[1280], &src_data[12], 6 * sizeof(DWORD));
966 hr = IDirectDrawSurface4_Unlock(src_surface, NULL);
967 ok(SUCCEEDED(hr), "Failed to unlock source surface, hr %#x.\n", hr);
969 hr = IDirectDrawSurface4_SetClipper(dst_surface, clipper);
970 ok(SUCCEEDED(hr), "Failed to set clipper, hr %#x.\n", hr);
972 SetRect(&src_rect, 1, 1, 5, 2);
973 hr = IDirectDrawSurface4_Blt(dst_surface, NULL, src_surface, &src_rect, DDBLT_WAIT, NULL);
974 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
975 for (i = 0; i < 4; ++i)
977 for (j = 0; j < 4; ++j)
979 x = 80 * ((2 * j) + 1);
980 y = 60 * ((2 * i) + 1);
981 color = get_surface_color(dst_surface, x, y);
982 ok(compare_color(color, expected1[i * 4 + j], 1)
983 || broken(compare_color(color, expected1_broken[i * 4 + j], 1)),
984 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected1[i * 4 + j], x, y, color);
988 U5(fx).dwFillColor = 0xff0000ff;
989 hr = IDirectDrawSurface4_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
990 ok(SUCCEEDED(hr), "Failed to clear destination surface, hr %#x.\n", hr);
991 for (i = 0; i < 4; ++i)
993 for (j = 0; j < 4; ++j)
995 x = 80 * ((2 * j) + 1);
996 y = 60 * ((2 * i) + 1);
997 color = get_surface_color(dst_surface, x, y);
998 ok(compare_color(color, expected2[i * 4 + j], 1),
999 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected2[i * 4 + j], x, y, color);
1003 hr = IDirectDrawSurface4_BltFast(dst_surface, 0, 0, src_surface, NULL, DDBLTFAST_WAIT);
1004 ok(hr == DDERR_BLTFASTCANTCLIP, "Got unexpected hr %#x.\n", hr);
1006 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
1007 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
1008 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
1009 ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr);
1010 DestroyWindow(window);
1011 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
1012 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
1013 hr = IDirectDrawClipper_SetHWnd(clipper, 0, NULL);
1014 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
1015 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
1016 ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr);
1017 hr = IDirectDrawClipper_SetClipList(clipper, NULL, 0);
1018 ok(SUCCEEDED(hr), "Failed to set clip list, hr %#x.\n", hr);
1019 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
1020 ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr);
1021 hr = IDirectDrawSurface4_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
1022 ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr);
1024 IDirectDrawSurface4_Release(dst_surface);
1025 IDirectDrawSurface4_Release(src_surface);
1026 refcount = IDirectDrawClipper_Release(clipper);
1027 ok(!refcount, "Clipper has %u references left.\n", refcount);
1028 IDirectDraw4_Release(ddraw);
1031 static void test_coop_level_d3d_state(void)
1033 D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
1034 IDirectDrawSurface4 *rt, *surface;
1035 IDirect3DViewport3 *viewport;
1036 IDirect3DDevice3 *device;
1037 IDirectDraw4 *ddraw;
1038 IDirect3D3 *d3d;
1039 D3DCOLOR color;
1040 DWORD value;
1041 HWND window;
1042 HRESULT hr;
1044 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1045 0, 0, 640, 480, 0, 0, 0, 0);
1046 if (!(device = create_device(window, DDSCL_NORMAL)))
1048 skip("Failed to create a 3D device, skipping test.\n");
1049 DestroyWindow(window);
1050 return;
1053 viewport = create_viewport(device, 0, 0, 640, 480);
1055 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
1056 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1057 hr = IDirect3DDevice3_GetRenderState(device, D3DRENDERSTATE_ZENABLE, &value);
1058 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
1059 ok(!!value, "Got unexpected z-enable state %#x.\n", value);
1060 hr = IDirect3DDevice3_GetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, &value);
1061 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
1062 ok(!value, "Got unexpected alpha blend enable state %#x.\n", value);
1063 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);
1064 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
1065 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xffff0000, 0.0f, 0);
1066 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
1067 color = get_surface_color(rt, 320, 240);
1068 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
1070 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
1071 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
1072 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
1073 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
1074 IDirect3D3_Release(d3d);
1075 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
1076 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
1077 hr = IDirectDrawSurface4_IsLost(rt);
1078 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
1079 hr = IDirectDraw4_RestoreAllSurfaces(ddraw);
1080 ok(SUCCEEDED(hr), "Failed to restore surfaces, hr %#x.\n", hr);
1081 IDirectDraw4_Release(ddraw);
1083 hr = IDirect3DDevice3_GetRenderTarget(device, &surface);
1084 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1085 ok(surface == rt, "Got unexpected surface %p.\n", surface);
1086 hr = IDirect3DDevice3_GetRenderState(device, D3DRENDERSTATE_ZENABLE, &value);
1087 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
1088 ok(!!value, "Got unexpected z-enable state %#x.\n", value);
1089 hr = IDirect3DDevice3_GetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, &value);
1090 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
1091 ok(!!value, "Got unexpected alpha blend enable state %#x.\n", value);
1092 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xff00ff00, 0.0f, 0);
1093 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
1094 color = get_surface_color(rt, 320, 240);
1095 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
1097 destroy_viewport(device, viewport);
1098 IDirectDrawSurface4_Release(surface);
1099 IDirectDrawSurface4_Release(rt);
1100 IDirect3DDevice3_Release(device);
1101 DestroyWindow(window);
1104 static void test_surface_interface_mismatch(void)
1106 IDirectDraw4 *ddraw = NULL;
1107 IDirect3D3 *d3d = NULL;
1108 IDirectDrawSurface4 *surface = NULL, *ds;
1109 IDirectDrawSurface3 *surface3 = NULL;
1110 IDirect3DDevice3 *device = NULL;
1111 IDirect3DViewport3 *viewport = NULL;
1112 DDSURFACEDESC2 surface_desc;
1113 DDPIXELFORMAT z_fmt;
1114 ULONG refcount;
1115 HRESULT hr;
1116 D3DCOLOR color;
1117 HWND window;
1118 D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
1120 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1121 0, 0, 640, 480, 0, 0, 0, 0);
1122 ddraw = create_ddraw();
1123 ok(!!ddraw, "Failed to create a ddraw object.\n");
1124 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
1125 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
1127 memset(&surface_desc, 0, sizeof(surface_desc));
1128 surface_desc.dwSize = sizeof(surface_desc);
1129 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1130 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
1131 surface_desc.dwWidth = 640;
1132 surface_desc.dwHeight = 480;
1134 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1135 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1137 hr = IDirectDrawSurface4_QueryInterface(surface, &IID_IDirectDrawSurface3, (void **)&surface3);
1138 ok(SUCCEEDED(hr), "Failed to QI IDirectDrawSurface3, hr %#x.\n", hr);
1140 if (FAILED(IDirectDraw4_QueryInterface(ddraw, &IID_IDirect3D3, (void **)&d3d)))
1142 skip("D3D interface is not available, skipping test.\n");
1143 goto cleanup;
1146 memset(&z_fmt, 0, sizeof(z_fmt));
1147 hr = IDirect3D3_EnumZBufferFormats(d3d, &IID_IDirect3DHALDevice, enum_z_fmt, &z_fmt);
1148 if (FAILED(hr) || !z_fmt.dwSize)
1150 skip("No depth buffer formats available, skipping test.\n");
1151 goto cleanup;
1154 memset(&surface_desc, 0, sizeof(surface_desc));
1155 surface_desc.dwSize = sizeof(surface_desc);
1156 surface_desc.dwFlags = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT;
1157 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
1158 U4(surface_desc).ddpfPixelFormat = z_fmt;
1159 surface_desc.dwWidth = 640;
1160 surface_desc.dwHeight = 480;
1161 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &ds, NULL);
1162 ok(SUCCEEDED(hr), "Failed to create depth buffer, hr %#x.\n", hr);
1163 if (FAILED(hr))
1164 goto cleanup;
1166 /* Using a different surface interface version still works */
1167 hr = IDirectDrawSurface3_AddAttachedSurface(surface3, (IDirectDrawSurface3 *)ds);
1168 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
1169 refcount = IDirectDrawSurface4_Release(ds);
1170 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
1171 if (FAILED(hr))
1172 goto cleanup;
1174 /* Here too */
1175 hr = IDirect3D3_CreateDevice(d3d, &IID_IDirect3DHALDevice, (IDirectDrawSurface4 *)surface3, &device, NULL);
1176 ok(SUCCEEDED(hr), "Failed to create d3d device.\n");
1177 if (FAILED(hr))
1178 goto cleanup;
1180 viewport = create_viewport(device, 0, 0, 640, 480);
1182 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xffff0000, 0.0f, 0);
1183 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
1184 color = get_surface_color(surface, 320, 240);
1185 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
1187 cleanup:
1188 if (viewport)
1189 destroy_viewport(device, viewport);
1190 if (surface3) IDirectDrawSurface3_Release(surface3);
1191 if (surface) IDirectDrawSurface4_Release(surface);
1192 if (device) IDirect3DDevice3_Release(device);
1193 if (d3d) IDirect3D3_Release(d3d);
1194 if (ddraw) IDirectDraw4_Release(ddraw);
1195 DestroyWindow(window);
1198 static void test_coop_level_threaded(void)
1200 struct create_window_thread_param p;
1201 IDirectDraw4 *ddraw;
1202 HRESULT hr;
1204 ddraw = create_ddraw();
1205 ok(!!ddraw, "Failed to create a ddraw object.\n");
1206 create_window_thread(&p);
1208 hr = IDirectDraw4_SetCooperativeLevel(ddraw, p.window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
1209 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
1211 IDirectDraw4_Release(ddraw);
1212 destroy_window_thread(&p);
1215 static void test_depth_blit(void)
1217 static struct
1219 float x, y, z;
1220 DWORD color;
1222 quad1[] =
1224 { -1.0, 1.0, 0.50f, 0xff00ff00},
1225 { 1.0, 1.0, 0.50f, 0xff00ff00},
1226 { -1.0, -1.0, 0.50f, 0xff00ff00},
1227 { 1.0, -1.0, 0.50f, 0xff00ff00},
1229 static const D3DCOLOR expected_colors[4][4] =
1231 {0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00},
1232 {0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00},
1233 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1234 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1236 DDSURFACEDESC2 ddsd_new, ddsd_existing;
1238 IDirect3DDevice3 *device;
1239 IDirectDrawSurface4 *ds1, *ds2, *ds3, *rt;
1240 IDirect3DViewport3 *viewport;
1241 RECT src_rect, dst_rect;
1242 unsigned int i, j;
1243 D3DCOLOR color;
1244 HRESULT hr;
1245 IDirect3D3 *d3d;
1246 IDirectDraw4 *ddraw;
1247 DDBLTFX fx;
1248 HWND window;
1249 D3DRECT d3drect;
1251 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1252 0, 0, 640, 480, 0, 0, 0, 0);
1253 if (!(device = create_device(window, DDSCL_NORMAL)))
1255 skip("Failed to create a 3D device, skipping test.\n");
1256 DestroyWindow(window);
1257 return;
1260 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
1261 ok(SUCCEEDED(hr), "Failed to get Direct3D3 interface, hr %#x.\n", hr);
1262 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
1263 ok(SUCCEEDED(hr), "Failed to get DirectDraw4 interface, hr %#x.\n", hr);
1264 IDirect3D3_Release(d3d);
1266 ds1 = get_depth_stencil(device);
1268 memset(&ddsd_new, 0, sizeof(ddsd_new));
1269 ddsd_new.dwSize = sizeof(ddsd_new);
1270 memset(&ddsd_existing, 0, sizeof(ddsd_existing));
1271 ddsd_existing.dwSize = sizeof(ddsd_existing);
1272 hr = IDirectDrawSurface4_GetSurfaceDesc(ds1, &ddsd_existing);
1273 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
1274 ddsd_new.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
1275 ddsd_new.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
1276 ddsd_new.dwWidth = ddsd_existing.dwWidth;
1277 ddsd_new.dwHeight = ddsd_existing.dwHeight;
1278 U4(ddsd_new).ddpfPixelFormat = U4(ddsd_existing).ddpfPixelFormat;
1279 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd_new, &ds2, NULL);
1280 ok(SUCCEEDED(hr), "Failed to create a surface, hr %#x.\n", hr);
1281 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd_new, &ds3, NULL);
1282 ok(SUCCEEDED(hr), "Failed to create a surface, hr %#x.\n", hr);
1283 IDirectDraw4_Release(ddraw);
1285 viewport = create_viewport(device, 0, 0, ddsd_existing.dwWidth, ddsd_existing.dwHeight);
1286 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
1287 ok(SUCCEEDED(hr), "Failed to activate the viewport, hr %#x.\n", hr);
1289 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_TRUE);
1290 ok(SUCCEEDED(hr), "Failed to enable z testing, hr %#x.\n", hr);
1291 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ZFUNC, D3DCMP_LESSEQUAL);
1292 ok(SUCCEEDED(hr), "Failed to set the z function, hr %#x.\n", hr);
1294 U1(d3drect).x1 = U2(d3drect).y1 = 0;
1295 U3(d3drect).x2 = ddsd_existing.dwWidth; U4(d3drect).y2 = ddsd_existing.dwHeight;
1296 hr = IDirect3DViewport3_Clear2(viewport, 1, &d3drect, D3DCLEAR_ZBUFFER, 0, 0.0f, 0);
1297 ok(SUCCEEDED(hr), "Failed to clear the z buffer, hr %#x.\n", hr);
1299 /* Partial blit. */
1300 SetRect(&src_rect, 0, 0, 320, 240);
1301 SetRect(&dst_rect, 0, 0, 320, 240);
1302 hr = IDirectDrawSurface4_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1303 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1304 /* Different locations. */
1305 SetRect(&src_rect, 0, 0, 320, 240);
1306 SetRect(&dst_rect, 320, 240, 640, 480);
1307 hr = IDirectDrawSurface4_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1308 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1309 /* Stretched. */
1310 SetRect(&src_rect, 0, 0, 320, 240);
1311 SetRect(&dst_rect, 0, 0, 640, 480);
1312 hr = IDirectDrawSurface4_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1313 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1314 /* Flipped. */
1315 SetRect(&src_rect, 0, 480, 640, 0);
1316 SetRect(&dst_rect, 0, 0, 640, 480);
1317 hr = IDirectDrawSurface4_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1318 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
1319 SetRect(&src_rect, 0, 0, 640, 480);
1320 SetRect(&dst_rect, 0, 480, 640, 0);
1321 hr = IDirectDrawSurface4_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1322 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
1323 /* Full, explicit. */
1324 SetRect(&src_rect, 0, 0, 640, 480);
1325 SetRect(&dst_rect, 0, 0, 640, 480);
1326 hr = IDirectDrawSurface4_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1327 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1328 /* Depth -> color blit: Succeeds on Win7 + Radeon HD 5700, fails on WinXP + Radeon X1600 */
1330 /* Depth blit inside a BeginScene / EndScene pair */
1331 hr = IDirect3DDevice3_BeginScene(device);
1332 ok(SUCCEEDED(hr), "Failed to start a scene, hr %#x.\n", hr);
1333 /* From the current depth stencil */
1334 hr = IDirectDrawSurface4_Blt(ds2, NULL, ds1, NULL, DDBLT_WAIT, NULL);
1335 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1336 /* To the current depth stencil */
1337 hr = IDirectDrawSurface4_Blt(ds1, NULL, ds2, NULL, DDBLT_WAIT, NULL);
1338 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1339 /* Between unbound surfaces */
1340 hr = IDirectDrawSurface4_Blt(ds3, NULL, ds2, NULL, DDBLT_WAIT, NULL);
1341 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1342 hr = IDirect3DDevice3_EndScene(device);
1343 ok(SUCCEEDED(hr), "Failed to end a scene, hr %#x.\n", hr);
1345 /* Avoid changing the depth stencil, it doesn't work properly on Windows.
1346 * Instead use DDBLT_DEPTHFILL to clear the depth stencil. Unfortunately
1347 * drivers disagree on the meaning of dwFillDepth. Only 0 seems to produce
1348 * a reliable result(z = 0.0) */
1349 memset(&fx, 0, sizeof(fx));
1350 fx.dwSize = sizeof(fx);
1351 hr = IDirectDrawSurface4_Blt(ds2, NULL, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
1352 ok(SUCCEEDED(hr), "Failed to clear the source z buffer, hr %#x.\n", hr);
1354 hr = IDirect3DViewport3_Clear2(viewport, 1, &d3drect, D3DCLEAR_ZBUFFER | D3DCLEAR_TARGET, 0xffff0000, 1.0f, 0);
1355 ok(SUCCEEDED(hr), "Failed to clear the color and z buffers, hr %#x.\n", hr);
1356 SetRect(&dst_rect, 0, 0, 320, 240);
1357 hr = IDirectDrawSurface4_Blt(ds1, &dst_rect, ds2, NULL, DDBLT_WAIT, NULL);
1358 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1359 IDirectDrawSurface4_Release(ds3);
1360 IDirectDrawSurface4_Release(ds2);
1361 IDirectDrawSurface4_Release(ds1);
1363 hr = IDirect3DDevice3_BeginScene(device);
1364 ok(SUCCEEDED(hr), "Failed to start a scene, hr %#x.\n", hr);
1365 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE,
1366 quad1, 4, 0);
1367 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1368 hr = IDirect3DDevice3_EndScene(device);
1369 ok(SUCCEEDED(hr), "Failed to end a scene, hr %#x.\n", hr);
1371 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
1372 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1373 for (i = 0; i < 4; ++i)
1375 for (j = 0; j < 4; ++j)
1377 unsigned int x = 80 * ((2 * j) + 1);
1378 unsigned int y = 60 * ((2 * i) + 1);
1379 color = get_surface_color(rt, x, y);
1380 ok(compare_color(color, expected_colors[i][j], 1),
1381 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected_colors[i][j], x, y, color);
1384 IDirectDrawSurface4_Release(rt);
1386 destroy_viewport(device, viewport);
1387 IDirect3DDevice3_Release(device);
1388 DestroyWindow(window);
1391 static void test_texture_load_ckey(void)
1393 IDirectDraw4 *ddraw;
1394 IDirectDrawSurface4 *src;
1395 IDirectDrawSurface4 *dst;
1396 IDirect3DTexture2 *src_tex;
1397 IDirect3DTexture2 *dst_tex;
1398 DDSURFACEDESC2 ddsd;
1399 HRESULT hr;
1400 DDCOLORKEY ckey;
1402 ddraw = create_ddraw();
1403 ok(!!ddraw, "Failed to create a ddraw object.\n");
1404 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
1405 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
1407 memset(&ddsd, 0, sizeof(ddsd));
1408 ddsd.dwSize = sizeof(ddsd);
1409 ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
1410 ddsd.dwHeight = 128;
1411 ddsd.dwWidth = 128;
1412 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY;
1413 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &src, NULL);
1414 ok(SUCCEEDED(hr), "Failed to create source texture, hr %#x.\n", hr);
1415 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1416 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &dst, NULL);
1417 ok(SUCCEEDED(hr), "Failed to create destination texture, hr %#x.\n", hr);
1419 hr = IDirectDrawSurface4_QueryInterface(src, &IID_IDirect3DTexture2, (void **)&src_tex);
1420 ok(SUCCEEDED(hr) || hr == E_NOINTERFACE, "Failed to get Direct3DTexture2 interface, hr %#x.\n", hr);
1421 if (FAILED(hr))
1423 /* 64 bit ddraw does not support d3d */
1424 skip("Could not get Direct3DTexture2 interface, skipping texture::Load color keying tests.\n");
1425 IDirectDrawSurface4_Release(dst);
1426 IDirectDrawSurface4_Release(src);
1427 IDirectDraw4_Release(ddraw);
1428 return;
1430 hr = IDirectDrawSurface4_QueryInterface(dst, &IID_IDirect3DTexture2, (void **)&dst_tex);
1431 ok(SUCCEEDED(hr), "Failed to get Direct3DTexture2 interface, hr %#x.\n", hr);
1433 /* No surface has a color key */
1434 hr = IDirect3DTexture2_Load(dst_tex, src_tex);
1435 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1436 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0xdeadbeef;
1437 hr = IDirectDrawSurface4_GetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1438 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1439 ok(ckey.dwColorSpaceLowValue == 0xdeadbeef, "dwColorSpaceLowValue is %#x.\n", ckey.dwColorSpaceLowValue);
1440 ok(ckey.dwColorSpaceHighValue == 0xdeadbeef, "dwColorSpaceHighValue is %#x.\n", ckey.dwColorSpaceHighValue);
1442 /* Source surface has a color key */
1443 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0x0000ff00;
1444 hr = IDirectDrawSurface4_SetColorKey(src, DDCKEY_SRCBLT, &ckey);
1445 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1446 hr = IDirect3DTexture2_Load(dst_tex, src_tex);
1447 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1448 hr = IDirectDrawSurface4_GetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1449 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1450 ok(ckey.dwColorSpaceLowValue == 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey.dwColorSpaceLowValue);
1451 ok(ckey.dwColorSpaceHighValue == 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey.dwColorSpaceHighValue);
1453 /* Both surfaces have a color key: Dest ckey is overwritten */
1454 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0x000000ff;
1455 hr = IDirectDrawSurface4_SetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1456 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1457 hr = IDirect3DTexture2_Load(dst_tex, src_tex);
1458 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1459 hr = IDirectDrawSurface4_GetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1460 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1461 ok(ckey.dwColorSpaceLowValue == 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey.dwColorSpaceLowValue);
1462 ok(ckey.dwColorSpaceHighValue == 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey.dwColorSpaceHighValue);
1464 /* Only the destination has a color key: It is not deleted */
1465 hr = IDirectDrawSurface4_SetColorKey(src, DDCKEY_SRCBLT, NULL);
1466 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1467 hr = IDirectDrawSurface4_GetColorKey(src, DDCKEY_SRCBLT, &ckey);
1468 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1469 hr = IDirect3DTexture2_Load(dst_tex, src_tex);
1470 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1471 hr = IDirectDrawSurface4_GetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1472 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1473 ok(ckey.dwColorSpaceLowValue == 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey.dwColorSpaceLowValue);
1474 ok(ckey.dwColorSpaceHighValue == 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey.dwColorSpaceHighValue);
1476 IDirect3DTexture2_Release(dst_tex);
1477 IDirect3DTexture2_Release(src_tex);
1478 IDirectDrawSurface4_Release(dst);
1479 IDirectDrawSurface4_Release(src);
1480 IDirectDraw4_Release(ddraw);
1483 static ULONG get_refcount(IUnknown *test_iface)
1485 IUnknown_AddRef(test_iface);
1486 return IUnknown_Release(test_iface);
1489 static void test_viewport(void)
1491 IDirectDraw4 *ddraw;
1492 IDirect3D3 *d3d;
1493 HRESULT hr, old_d3d_ref;
1494 ULONG ref;
1495 IDirect3DViewport *viewport;
1496 IDirect3DViewport2 *viewport2;
1497 IDirect3DViewport3 *viewport3, *another_vp, *test_vp;
1498 IDirectDrawGammaControl *gamma;
1499 IUnknown *unknown;
1500 HWND window;
1501 IDirect3DDevice3 *device;
1503 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1504 0, 0, 640, 480, 0, 0, 0, 0);
1505 if (!(device = create_device(window, DDSCL_NORMAL)))
1507 skip("Failed to create a 3D device, skipping test.\n");
1508 DestroyWindow(window);
1509 return;
1511 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
1512 ok(SUCCEEDED(hr), "Failed to get Direct3D3 interface, hr %#x.\n", hr);
1513 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
1514 ok(SUCCEEDED(hr), "Failed to get DirectDraw4 interface, hr %#x.\n", hr);
1515 old_d3d_ref = get_refcount((IUnknown *) d3d);
1517 hr = IDirect3D3_CreateViewport(d3d, &viewport3, NULL);
1518 ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
1519 ref = get_refcount((IUnknown *)viewport3);
1520 ok(ref == 1, "Initial IDirect3DViewport3 refcount is %u\n", ref);
1521 ref = get_refcount((IUnknown *)d3d);
1522 ok(ref == old_d3d_ref, "IDirect3D3 refcount is %u\n", ref);
1524 gamma = (IDirectDrawGammaControl *)0xdeadbeef;
1525 hr = IDirect3DViewport2_QueryInterface(viewport3, &IID_IDirectDrawGammaControl, (void **)&gamma);
1526 ok(hr == E_NOINTERFACE, "Got unexpected hr %#x.\n", hr);
1527 ok(gamma == NULL, "Interface not set to NULL by failed QI call: %p\n", gamma);
1528 if (SUCCEEDED(hr)) IDirectDrawGammaControl_Release(gamma);
1529 /* NULL iid: Segfaults */
1531 hr = IDirect3DViewport3_QueryInterface(viewport3, &IID_IDirect3DViewport, (void **)&viewport);
1532 ok(SUCCEEDED(hr), "Failed to QI IDirect3DViewport, hr %#x.\n", hr);
1533 if (viewport)
1535 ref = get_refcount((IUnknown *)viewport);
1536 ok(ref == 2, "IDirect3DViewport refcount is %u\n", ref);
1537 ref = get_refcount((IUnknown *)viewport3);
1538 ok(ref == 2, "IDirect3DViewport3 refcount is %u\n", ref);
1539 IDirect3DViewport_Release(viewport);
1540 viewport = NULL;
1543 hr = IDirect3DViewport3_QueryInterface(viewport3, &IID_IDirect3DViewport3, (void **)&viewport2);
1544 ok(SUCCEEDED(hr), "Failed to QI IDirect3DViewport3, hr %#x.\n", hr);
1545 if (viewport2)
1547 ref = get_refcount((IUnknown *)viewport2);
1548 ok(ref == 2, "IDirect3DViewport2 refcount is %u\n", ref);
1549 ref = get_refcount((IUnknown *)viewport3);
1550 ok(ref == 2, "IDirect3DViewport3 refcount is %u\n", ref);
1551 IDirect3DViewport3_Release(viewport2);
1554 hr = IDirect3DViewport3_QueryInterface(viewport3, &IID_IUnknown, (void **)&unknown);
1555 ok(SUCCEEDED(hr), "Failed to QI IUnknown, hr %#x.\n", hr);
1556 if (unknown)
1558 ref = get_refcount((IUnknown *)viewport3);
1559 ok(ref == 2, "IDirect3DViewport3 refcount is %u\n", ref);
1560 ref = get_refcount(unknown);
1561 ok(ref == 2, "IUnknown refcount is %u\n", ref);
1562 IUnknown_Release(unknown);
1565 /* AddViewport(NULL): Segfault */
1566 hr = IDirect3DDevice3_DeleteViewport(device, NULL);
1567 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
1568 hr = IDirect3DDevice3_GetCurrentViewport(device, NULL);
1569 ok(hr == D3DERR_NOCURRENTVIEWPORT, "Got unexpected hr %#x.\n", hr);
1571 hr = IDirect3D3_CreateViewport(d3d, &another_vp, NULL);
1572 ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
1574 /* Setting a viewport not in the viewport list fails */
1575 hr = IDirect3DDevice3_SetCurrentViewport(device, another_vp);
1576 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
1578 hr = IDirect3DDevice3_AddViewport(device, viewport3);
1579 ok(SUCCEEDED(hr), "Failed to add viewport to device, hr %#x.\n", hr);
1580 ref = get_refcount((IUnknown *) viewport3);
1581 ok(ref == 2, "viewport3 refcount is %d\n", ref);
1582 hr = IDirect3DDevice3_AddViewport(device, another_vp);
1583 ok(SUCCEEDED(hr), "Failed to add viewport to device, hr %#x.\n", hr);
1584 ref = get_refcount((IUnknown *) another_vp);
1585 ok(ref == 2, "another_vp refcount is %d\n", ref);
1587 test_vp = (IDirect3DViewport3 *) 0xbaadc0de;
1588 hr = IDirect3DDevice3_GetCurrentViewport(device, &test_vp);
1589 ok(hr == D3DERR_NOCURRENTVIEWPORT, "Got unexpected hr %#x.\n", hr);
1590 ok(test_vp == (IDirect3DViewport3 *) 0xbaadc0de, "Got unexpected pointer %p\n", test_vp);
1592 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport3);
1593 ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr);
1594 ref = get_refcount((IUnknown *) viewport3);
1595 ok(ref == 3, "viewport3 refcount is %d\n", ref);
1596 ref = get_refcount((IUnknown *) device);
1597 ok(ref == 1, "device refcount is %d\n", ref);
1599 test_vp = NULL;
1600 hr = IDirect3DDevice3_GetCurrentViewport(device, &test_vp);
1601 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
1602 ok(test_vp == viewport3, "Got unexpected viewport %p\n", test_vp);
1603 ref = get_refcount((IUnknown *) viewport3);
1604 ok(ref == 4, "viewport3 refcount is %d\n", ref);
1605 if(test_vp) IDirect3DViewport3_Release(test_vp);
1607 /* GetCurrentViewport with a viewport set and NULL input param: Segfault */
1609 /* Cannot set the viewport to NULL */
1610 hr = IDirect3DDevice3_SetCurrentViewport(device, NULL);
1611 ok(hr == DDERR_INVALIDPARAMS, "Failed to set viewport to NULL, hr %#x.\n", hr);
1612 test_vp = NULL;
1613 hr = IDirect3DDevice3_GetCurrentViewport(device, &test_vp);
1614 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
1615 ok(test_vp == viewport3, "Got unexpected viewport %p\n", test_vp);
1616 if(test_vp) IDirect3DViewport3_Release(test_vp);
1618 /* SetCurrentViewport properly releases the old viewport's reference */
1619 hr = IDirect3DDevice3_SetCurrentViewport(device, another_vp);
1620 ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr);
1621 ref = get_refcount((IUnknown *) viewport3);
1622 ok(ref == 2, "viewport3 refcount is %d\n", ref);
1623 ref = get_refcount((IUnknown *) another_vp);
1624 ok(ref == 3, "another_vp refcount is %d\n", ref);
1626 /* Unlike device2::DeleteViewport, device3::DeleteViewport releases the
1627 * reference held by SetCurrentViewport */
1628 hr = IDirect3DDevice3_DeleteViewport(device, another_vp);
1629 ok(SUCCEEDED(hr), "Failed to delete viewport from device, hr %#x.\n", hr);
1630 ref = get_refcount((IUnknown *) another_vp);
1631 ok(ref == 1, "another_vp refcount is %d\n", ref);
1633 /* GetCurrentViewport still fails */
1634 test_vp = NULL;
1635 hr = IDirect3DDevice3_GetCurrentViewport(device, &test_vp);
1636 ok(hr == D3DERR_NOCURRENTVIEWPORT, "Got unexpected hr %#x.\n", hr);
1637 ok(test_vp == NULL, "Got unexpected viewport %p\n", test_vp);
1638 if(test_vp) IDirect3DViewport3_Release(test_vp);
1640 /* Setting a different viewport doesn't have any surprises now */
1641 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport3);
1642 ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr);
1643 ref = get_refcount((IUnknown *) viewport3);
1644 ok(ref == 3, "viewport3 refcount is %d\n", ref);
1645 ref = get_refcount((IUnknown *) another_vp);
1646 ok(ref == 1, "another_vp refcount is %d\n", ref);
1648 /* Destroying the device removes the viewport and releases the reference */
1649 IDirect3DDevice3_Release(device);
1650 ref = get_refcount((IUnknown *) viewport3);
1651 ok(ref == 1, "viewport3 refcount is %d\n", ref);
1653 ref = IDirect3DViewport3_Release(another_vp);
1654 ok(ref == 0, "Got unexpected ref %d\n", ref);
1655 ref = IDirect3DViewport3_Release(viewport3);
1656 ok(ref == 0, "Got unexpected ref %d\n", ref);
1657 IDirect3D3_Release(d3d);
1658 DestroyWindow(window);
1659 IDirectDraw4_Release(ddraw);
1662 static void test_zenable(void)
1664 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
1665 static struct
1667 struct vec4 position;
1668 D3DCOLOR diffuse;
1670 tquad[] =
1672 {{ 0.0f, 480.0f, -0.5f, 1.0f}, 0xff00ff00},
1673 {{ 0.0f, 0.0f, -0.5f, 1.0f}, 0xff00ff00},
1674 {{640.0f, 480.0f, 1.5f, 1.0f}, 0xff00ff00},
1675 {{640.0f, 0.0f, 1.5f, 1.0f}, 0xff00ff00},
1677 IDirect3DViewport3 *viewport;
1678 IDirect3DDevice3 *device;
1679 IDirectDrawSurface4 *rt;
1680 D3DCOLOR color;
1681 HWND window;
1682 HRESULT hr;
1683 UINT x, y;
1684 UINT i, j;
1686 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1687 0, 0, 640, 480, 0, 0, 0, 0);
1688 if (!(device = create_device(window, DDSCL_NORMAL)))
1690 skip("Failed to create a 3D device, skipping test.\n");
1691 DestroyWindow(window);
1692 return;
1695 viewport = create_viewport(device, 0, 0, 640, 480);
1696 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
1697 ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr);
1699 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
1700 ok(SUCCEEDED(hr), "Failed to disable z-buffering, hr %#x.\n", hr);
1702 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffff0000, 0.0f, 0);
1703 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
1704 hr = IDirect3DDevice3_BeginScene(device);
1705 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1706 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_DIFFUSE, tquad, 4, 0);
1707 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1708 hr = IDirect3DDevice3_EndScene(device);
1709 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1711 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
1712 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1713 for (i = 0; i < 4; ++i)
1715 for (j = 0; j < 4; ++j)
1717 x = 80 * ((2 * j) + 1);
1718 y = 60 * ((2 * i) + 1);
1719 color = get_surface_color(rt, x, y);
1720 ok(compare_color(color, 0x0000ff00, 1),
1721 "Expected color 0x0000ff00 at %u, %u, got 0x%08x.\n", x, y, color);
1724 IDirectDrawSurface4_Release(rt);
1726 destroy_viewport(device, viewport);
1727 IDirect3DDevice3_Release(device);
1728 DestroyWindow(window);
1731 static void test_ck_rgba(void)
1733 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
1734 static struct
1736 struct vec4 position;
1737 struct vec2 texcoord;
1739 tquad[] =
1741 {{ 0.0f, 480.0f, 0.25f, 1.0f}, {0.0f, 0.0f}},
1742 {{ 0.0f, 0.0f, 0.25f, 1.0f}, {0.0f, 1.0f}},
1743 {{640.0f, 480.0f, 0.25f, 1.0f}, {1.0f, 0.0f}},
1744 {{640.0f, 0.0f, 0.25f, 1.0f}, {1.0f, 1.0f}},
1745 {{ 0.0f, 480.0f, 0.75f, 1.0f}, {0.0f, 0.0f}},
1746 {{ 0.0f, 0.0f, 0.75f, 1.0f}, {0.0f, 1.0f}},
1747 {{640.0f, 480.0f, 0.75f, 1.0f}, {1.0f, 0.0f}},
1748 {{640.0f, 0.0f, 0.75f, 1.0f}, {1.0f, 1.0f}},
1750 static const struct
1752 D3DCOLOR fill_color;
1753 BOOL color_key;
1754 BOOL blend;
1755 D3DCOLOR result1, result1_broken;
1756 D3DCOLOR result2, result2_broken;
1758 tests[] =
1760 /* r200 on Windows doesn't check the alpha component when applying the color
1761 * key, so the key matches on every texel. */
1762 {0xff00ff00, TRUE, TRUE, 0x00ff0000, 0x00ff0000, 0x000000ff, 0x000000ff},
1763 {0xff00ff00, TRUE, FALSE, 0x00ff0000, 0x00ff0000, 0x000000ff, 0x000000ff},
1764 {0xff00ff00, FALSE, TRUE, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1765 {0xff00ff00, FALSE, FALSE, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1766 {0x7f00ff00, TRUE, TRUE, 0x00807f00, 0x00ff0000, 0x00807f00, 0x000000ff},
1767 {0x7f00ff00, TRUE, FALSE, 0x0000ff00, 0x00ff0000, 0x0000ff00, 0x000000ff},
1768 {0x7f00ff00, FALSE, TRUE, 0x00807f00, 0x00807f00, 0x00807f00, 0x00807f00},
1769 {0x7f00ff00, FALSE, FALSE, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1772 IDirectDrawSurface4 *surface;
1773 IDirect3DViewport3 *viewport;
1774 DDSURFACEDESC2 surface_desc;
1775 IDirect3DTexture2 *texture;
1776 IDirect3DDevice3 *device;
1777 IDirectDrawSurface4 *rt;
1778 IDirectDraw4 *ddraw;
1779 IDirect3D3 *d3d;
1780 D3DCOLOR color;
1781 HWND window;
1782 DDBLTFX fx;
1783 HRESULT hr;
1784 UINT i;
1786 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1787 0, 0, 640, 480, 0, 0, 0, 0);
1788 if (!(device = create_device(window, DDSCL_NORMAL)))
1790 skip("Failed to create a 3D device, skipping test.\n");
1791 DestroyWindow(window);
1792 return;
1795 viewport = create_viewport(device, 0, 0, 640, 480);
1796 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
1797 ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr);
1799 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
1800 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
1801 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
1802 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
1803 IDirect3D3_Release(d3d);
1805 memset(&surface_desc, 0, sizeof(surface_desc));
1806 surface_desc.dwSize = sizeof(surface_desc);
1807 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CKSRCBLT;
1808 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1809 surface_desc.dwWidth = 256;
1810 surface_desc.dwHeight = 256;
1811 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
1812 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
1813 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
1814 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
1815 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
1816 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
1817 U5(U4(surface_desc).ddpfPixelFormat).dwRGBAlphaBitMask = 0xff000000;
1818 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0xff00ff00;
1819 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0xff00ff00;
1820 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1821 ok(SUCCEEDED(hr), "Failed to create destination surface, hr %#x.\n", hr);
1822 hr = IDirectDrawSurface4_QueryInterface(surface, &IID_IDirect3DTexture2, (void **)&texture);
1823 ok(SUCCEEDED(hr), "Failed to get texture interface, hr %#x.\n", hr);
1825 hr = IDirect3DDevice3_SetTexture(device, 0, texture);
1826 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
1827 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);
1828 ok(SUCCEEDED(hr), "Failed to enable alpha blending, hr %#x.\n", hr);
1829 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA);
1830 ok(SUCCEEDED(hr), "Failed to enable alpha blending, hr %#x.\n", hr);
1832 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
1833 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1835 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
1837 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, tests[i].color_key);
1838 ok(SUCCEEDED(hr), "Failed to enable color keying, hr %#x.\n", hr);
1839 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, tests[i].blend);
1840 ok(SUCCEEDED(hr), "Failed to enable alpha blending, hr %#x.\n", hr);
1842 memset(&fx, 0, sizeof(fx));
1843 fx.dwSize = sizeof(fx);
1844 U5(fx).dwFillColor = tests[i].fill_color;
1845 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
1846 ok(SUCCEEDED(hr), "Failed to fill texture, hr %#x.\n", hr);
1848 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect,
1849 D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffff0000, 1.0f, 0);
1850 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
1851 hr = IDirect3DDevice3_BeginScene(device);
1852 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1853 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_TEX1, &tquad[0], 4, 0);
1854 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1855 hr = IDirect3DDevice3_EndScene(device);
1856 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1858 color = get_surface_color(rt, 320, 240);
1859 ok(compare_color(color, tests[i].result1, 1) || compare_color(color, tests[i].result1_broken, 1),
1860 "Expected color 0x%08x for test %u, got 0x%08x.\n",
1861 tests[i].result1, i, color);
1863 U5(fx).dwFillColor = 0xff0000ff;
1864 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
1865 ok(SUCCEEDED(hr), "Failed to fill texture, hr %#x.\n", hr);
1867 hr = IDirect3DDevice3_BeginScene(device);
1868 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1869 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_TEX1, &tquad[4], 4, 0);
1870 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1871 hr = IDirect3DDevice3_EndScene(device);
1872 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1874 /* This tests that fragments that are masked out by the color key are
1875 * discarded, instead of just fully transparent. */
1876 color = get_surface_color(rt, 320, 240);
1877 ok(compare_color(color, tests[i].result2, 1) || compare_color(color, tests[i].result2_broken, 1),
1878 "Expected color 0x%08x for test %u, got 0x%08x.\n",
1879 tests[i].result2, i, color);
1882 IDirectDrawSurface4_Release(rt);
1883 IDirect3DTexture2_Release(texture);
1884 IDirectDrawSurface4_Release(surface);
1885 destroy_viewport(device, viewport);
1886 IDirectDraw4_Release(ddraw);
1887 IDirect3DDevice3_Release(device);
1888 DestroyWindow(window);
1891 static void test_ck_default(void)
1893 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
1894 static struct
1896 struct vec4 position;
1897 struct vec2 texcoord;
1899 tquad[] =
1901 {{ 0.0f, 480.0f, 0.0f, 1.0f}, {0.0f, 0.0f}},
1902 {{ 0.0f, 0.0f, 0.0f, 1.0f}, {0.0f, 1.0f}},
1903 {{640.0f, 480.0f, 0.0f, 1.0f}, {1.0f, 0.0f}},
1904 {{640.0f, 0.0f, 0.0f, 1.0f}, {1.0f, 1.0f}},
1906 IDirectDrawSurface4 *surface, *rt;
1907 IDirect3DViewport3 *viewport;
1908 DDSURFACEDESC2 surface_desc;
1909 IDirect3DTexture2 *texture;
1910 IDirect3DDevice3 *device;
1911 IDirectDraw4 *ddraw;
1912 IDirect3D3 *d3d;
1913 D3DCOLOR color;
1914 DWORD value;
1915 HWND window;
1916 DDBLTFX fx;
1917 HRESULT hr;
1919 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1920 0, 0, 640, 480, 0, 0, 0, 0);
1922 if (!(device = create_device(window, DDSCL_NORMAL)))
1924 skip("Failed to create a 3D device, skipping test.\n");
1925 DestroyWindow(window);
1926 return;
1929 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
1930 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
1931 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
1932 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
1933 IDirect3D3_Release(d3d);
1935 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
1936 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1938 viewport = create_viewport(device, 0, 0, 640, 480);
1939 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
1940 ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr);
1942 memset(&surface_desc, 0, sizeof(surface_desc));
1943 surface_desc.dwSize = sizeof(surface_desc);
1944 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CKSRCBLT;
1945 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1946 surface_desc.dwWidth = 256;
1947 surface_desc.dwHeight = 256;
1948 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
1949 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
1950 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
1951 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
1952 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
1953 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
1954 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x000000ff;
1955 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x000000ff;
1956 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1957 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1958 hr = IDirectDrawSurface4_QueryInterface(surface, &IID_IDirect3DTexture2, (void **)&texture);
1959 ok(SUCCEEDED(hr), "Failed to get texture interface, hr %#x.\n", hr);
1960 hr = IDirect3DDevice3_SetTexture(device, 0, texture);
1961 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
1963 memset(&fx, 0, sizeof(fx));
1964 fx.dwSize = sizeof(fx);
1965 U5(fx).dwFillColor = 0x000000ff;
1966 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
1967 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
1969 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xff00ff00, 1.0f, 0);
1970 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
1971 hr = IDirect3DDevice3_BeginScene(device);
1972 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1973 hr = IDirect3DDevice3_GetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, &value);
1974 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
1975 ok(!value, "Got unexpected color keying state %#x.\n", value);
1976 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_TEX1, &tquad[0], 4, 0);
1977 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1978 hr = IDirect3DDevice3_EndScene(device);
1979 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1980 color = get_surface_color(rt, 320, 240);
1981 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
1983 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xff00ff00, 1.0f, 0);
1984 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
1985 hr = IDirect3DDevice3_BeginScene(device);
1986 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1987 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, TRUE);
1988 ok(SUCCEEDED(hr), "Failed to enable color keying, hr %#x.\n", hr);
1989 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_TEX1, &tquad[0], 4, 0);
1990 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1991 hr = IDirect3DDevice3_GetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, &value);
1992 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
1993 ok(!!value, "Got unexpected color keying state %#x.\n", value);
1994 hr = IDirect3DDevice3_EndScene(device);
1995 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1996 color = get_surface_color(rt, 320, 240);
1997 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
1999 IDirect3DTexture_Release(texture);
2000 IDirectDrawSurface4_Release(surface);
2001 destroy_viewport(device, viewport);
2002 IDirectDrawSurface4_Release(rt);
2003 IDirect3DDevice3_Release(device);
2004 IDirectDraw4_Release(ddraw);
2005 DestroyWindow(window);
2008 static void test_ck_complex(void)
2010 IDirectDrawSurface4 *surface, *mipmap, *tmp;
2011 DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, {0}};
2012 DDSURFACEDESC2 surface_desc;
2013 IDirect3DDevice3 *device;
2014 DDCOLORKEY color_key;
2015 IDirectDraw4 *ddraw;
2016 IDirect3D3 *d3d;
2017 unsigned int i;
2018 ULONG refcount;
2019 HWND window;
2020 HRESULT hr;
2022 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
2023 0, 0, 640, 480, 0, 0, 0, 0);
2024 if (!(device = create_device(window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN)))
2026 skip("Failed to create a 3D device, skipping test.\n");
2027 DestroyWindow(window);
2028 return;
2030 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
2031 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
2032 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
2033 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
2034 IDirect3D3_Release(d3d);
2036 memset(&surface_desc, 0, sizeof(surface_desc));
2037 surface_desc.dwSize = sizeof(surface_desc);
2038 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
2039 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
2040 surface_desc.dwWidth = 128;
2041 surface_desc.dwHeight = 128;
2042 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
2043 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
2045 hr = IDirectDrawSurface4_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
2046 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
2047 color_key.dwColorSpaceLowValue = 0x0000ff00;
2048 color_key.dwColorSpaceHighValue = 0x0000ff00;
2049 hr = IDirectDrawSurface4_SetColorKey(surface, DDCKEY_SRCBLT, &color_key);
2050 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
2051 memset(&color_key, 0, sizeof(color_key));
2052 hr = IDirectDrawSurface4_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
2053 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
2054 ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
2055 color_key.dwColorSpaceLowValue);
2056 ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
2057 color_key.dwColorSpaceHighValue);
2059 mipmap = surface;
2060 IDirectDrawSurface_AddRef(mipmap);
2061 for (i = 0; i < 7; ++i)
2063 hr = IDirectDrawSurface4_GetAttachedSurface(mipmap, &caps, &tmp);
2064 ok(SUCCEEDED(hr), "Failed to get attached surface, i %u, hr %#x.\n", i, hr);
2066 hr = IDirectDrawSurface4_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
2067 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x, i %u.\n", hr, i);
2068 color_key.dwColorSpaceLowValue = 0x000000ff;
2069 color_key.dwColorSpaceHighValue = 0x000000ff;
2070 hr = IDirectDrawSurface4_SetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
2071 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x, i %u.\n", hr, i);
2072 memset(&color_key, 0, sizeof(color_key));
2073 hr = IDirectDrawSurface4_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
2074 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x, i %u.\n", hr, i);
2075 ok(color_key.dwColorSpaceLowValue == 0x000000ff, "Got unexpected value 0x%08x, i %u.\n",
2076 color_key.dwColorSpaceLowValue, i);
2077 ok(color_key.dwColorSpaceHighValue == 0x000000ff, "Got unexpected value 0x%08x, i %u.\n",
2078 color_key.dwColorSpaceHighValue, i);
2080 IDirectDrawSurface_Release(mipmap);
2081 mipmap = tmp;
2084 memset(&color_key, 0, sizeof(color_key));
2085 hr = IDirectDrawSurface4_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
2086 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
2087 ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
2088 color_key.dwColorSpaceLowValue);
2089 ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
2090 color_key.dwColorSpaceHighValue);
2092 hr = IDirectDrawSurface4_GetAttachedSurface(mipmap, &caps, &tmp);
2093 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
2094 IDirectDrawSurface_Release(mipmap);
2095 refcount = IDirectDrawSurface4_Release(surface);
2096 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
2098 memset(&surface_desc, 0, sizeof(surface_desc));
2099 surface_desc.dwSize = sizeof(surface_desc);
2100 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
2101 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
2102 U5(surface_desc).dwBackBufferCount = 1;
2103 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
2104 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
2106 hr = IDirectDrawSurface4_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
2107 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
2108 color_key.dwColorSpaceLowValue = 0x0000ff00;
2109 color_key.dwColorSpaceHighValue = 0x0000ff00;
2110 hr = IDirectDrawSurface4_SetColorKey(surface, DDCKEY_SRCBLT, &color_key);
2111 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
2112 memset(&color_key, 0, sizeof(color_key));
2113 hr = IDirectDrawSurface4_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
2114 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
2115 ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
2116 color_key.dwColorSpaceLowValue);
2117 ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
2118 color_key.dwColorSpaceHighValue);
2120 hr = IDirectDrawSurface4_GetAttachedSurface(surface, &caps, &tmp);
2121 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
2123 hr = IDirectDrawSurface4_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
2124 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x, i %u.\n", hr, i);
2125 color_key.dwColorSpaceLowValue = 0x0000ff00;
2126 color_key.dwColorSpaceHighValue = 0x0000ff00;
2127 hr = IDirectDrawSurface4_SetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
2128 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
2129 memset(&color_key, 0, sizeof(color_key));
2130 hr = IDirectDrawSurface4_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
2131 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
2132 ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
2133 color_key.dwColorSpaceLowValue);
2134 ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
2135 color_key.dwColorSpaceHighValue);
2137 IDirectDrawSurface_Release(tmp);
2139 refcount = IDirectDrawSurface4_Release(surface);
2140 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
2141 IDirectDraw4_Release(ddraw);
2142 refcount = IDirect3DDevice3_Release(device);
2143 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
2144 DestroyWindow(window);
2147 struct qi_test
2149 REFIID iid;
2150 REFIID refcount_iid;
2151 HRESULT hr;
2154 static void test_qi(const char *test_name, IUnknown *base_iface,
2155 REFIID refcount_iid, const struct qi_test *tests, UINT entry_count)
2157 ULONG refcount, expected_refcount;
2158 IUnknown *iface1, *iface2;
2159 HRESULT hr;
2160 UINT i, j;
2162 for (i = 0; i < entry_count; ++i)
2164 hr = IUnknown_QueryInterface(base_iface, tests[i].iid, (void **)&iface1);
2165 ok(hr == tests[i].hr, "Got hr %#x for test \"%s\" %u.\n", hr, test_name, i);
2166 if (SUCCEEDED(hr))
2168 for (j = 0; j < entry_count; ++j)
2170 hr = IUnknown_QueryInterface(iface1, tests[j].iid, (void **)&iface2);
2171 ok(hr == tests[j].hr, "Got hr %#x for test \"%s\" %u, %u.\n", hr, test_name, i, j);
2172 if (SUCCEEDED(hr))
2174 expected_refcount = 0;
2175 if (IsEqualGUID(refcount_iid, tests[j].refcount_iid))
2176 ++expected_refcount;
2177 if (IsEqualGUID(tests[i].refcount_iid, tests[j].refcount_iid))
2178 ++expected_refcount;
2179 refcount = IUnknown_Release(iface2);
2180 ok(refcount == expected_refcount, "Got refcount %u for test \"%s\" %u, %u, expected %u.\n",
2181 refcount, test_name, i, j, expected_refcount);
2185 expected_refcount = 0;
2186 if (IsEqualGUID(refcount_iid, tests[i].refcount_iid))
2187 ++expected_refcount;
2188 refcount = IUnknown_Release(iface1);
2189 ok(refcount == expected_refcount, "Got refcount %u for test \"%s\" %u, expected %u.\n",
2190 refcount, test_name, i, expected_refcount);
2195 static void test_surface_qi(void)
2197 static const struct qi_test tests[] =
2199 {&IID_IDirect3DTexture2, &IID_IDirectDrawSurface4, S_OK },
2200 {&IID_IDirect3DTexture, &IID_IDirectDrawSurface4, S_OK },
2201 {&IID_IDirectDrawGammaControl, &IID_IDirectDrawGammaControl, S_OK },
2202 {&IID_IDirectDrawColorControl, NULL, E_NOINTERFACE},
2203 {&IID_IDirectDrawSurface7, &IID_IDirectDrawSurface7, S_OK },
2204 {&IID_IDirectDrawSurface4, &IID_IDirectDrawSurface4, S_OK },
2205 {&IID_IDirectDrawSurface3, &IID_IDirectDrawSurface3, S_OK },
2206 {&IID_IDirectDrawSurface2, &IID_IDirectDrawSurface2, S_OK },
2207 {&IID_IDirectDrawSurface, &IID_IDirectDrawSurface, S_OK },
2208 {&IID_IDirect3DDevice7, NULL, E_INVALIDARG },
2209 {&IID_IDirect3DDevice3, NULL, E_INVALIDARG },
2210 {&IID_IDirect3DDevice2, NULL, E_INVALIDARG },
2211 {&IID_IDirect3DDevice, NULL, E_INVALIDARG },
2212 {&IID_IDirect3D7, NULL, E_INVALIDARG },
2213 {&IID_IDirect3D3, NULL, E_INVALIDARG },
2214 {&IID_IDirect3D2, NULL, E_INVALIDARG },
2215 {&IID_IDirect3D, NULL, E_INVALIDARG },
2216 {&IID_IDirectDraw7, NULL, E_INVALIDARG },
2217 {&IID_IDirectDraw4, NULL, E_INVALIDARG },
2218 {&IID_IDirectDraw3, NULL, E_INVALIDARG },
2219 {&IID_IDirectDraw2, NULL, E_INVALIDARG },
2220 {&IID_IDirectDraw, NULL, E_INVALIDARG },
2221 {&IID_IDirect3DLight, NULL, E_INVALIDARG },
2222 {&IID_IDirect3DMaterial, NULL, E_INVALIDARG },
2223 {&IID_IDirect3DMaterial2, NULL, E_INVALIDARG },
2224 {&IID_IDirect3DMaterial3, NULL, E_INVALIDARG },
2225 {&IID_IDirect3DExecuteBuffer, NULL, E_INVALIDARG },
2226 {&IID_IDirect3DViewport, NULL, E_INVALIDARG },
2227 {&IID_IDirect3DViewport2, NULL, E_INVALIDARG },
2228 {&IID_IDirect3DViewport3, NULL, E_INVALIDARG },
2229 {&IID_IDirect3DVertexBuffer, NULL, E_INVALIDARG },
2230 {&IID_IDirect3DVertexBuffer7, NULL, E_INVALIDARG },
2231 {&IID_IDirectDrawPalette, NULL, E_INVALIDARG },
2232 {&IID_IDirectDrawClipper, NULL, E_INVALIDARG },
2233 {&IID_IUnknown, &IID_IDirectDrawSurface, S_OK },
2236 IDirectDrawSurface4 *surface;
2237 DDSURFACEDESC2 surface_desc;
2238 IDirect3DDevice3 *device;
2239 IDirectDraw4 *ddraw;
2240 HWND window;
2241 HRESULT hr;
2243 if (!GetProcAddress(GetModuleHandleA("ddraw.dll"), "DirectDrawCreateEx"))
2245 win_skip("DirectDrawCreateEx not available, skipping test.\n");
2246 return;
2249 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
2250 0, 0, 640, 480, 0, 0, 0, 0);
2251 /* Try to create a D3D device to see if the ddraw implementation supports
2252 * D3D. 64-bit ddraw in particular doesn't seem to support D3D, and
2253 * doesn't support e.g. the IDirect3DTexture interfaces. */
2254 if (!(device = create_device(window, DDSCL_NORMAL)))
2256 skip("Failed to create a 3D device, skipping test.\n");
2257 DestroyWindow(window);
2258 return;
2260 IDirect3DDevice_Release(device);
2261 ddraw = create_ddraw();
2262 ok(!!ddraw, "Failed to create a ddraw object.\n");
2263 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2264 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
2266 memset(&surface_desc, 0, sizeof(surface_desc));
2267 surface_desc.dwSize = sizeof(surface_desc);
2268 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
2269 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
2270 surface_desc.dwWidth = 512;
2271 surface_desc.dwHeight = 512;
2272 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, (IDirectDrawSurface4 **)0xdeadbeef, NULL);
2273 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2274 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
2275 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
2277 test_qi("surface_qi", (IUnknown *)surface, &IID_IDirectDrawSurface4, tests, sizeof(tests) / sizeof(*tests));
2279 IDirectDrawSurface4_Release(surface);
2280 IDirectDraw4_Release(ddraw);
2281 DestroyWindow(window);
2284 static void test_device_qi(void)
2286 static const struct qi_test tests[] =
2288 {&IID_IDirect3DTexture2, NULL, E_NOINTERFACE},
2289 {&IID_IDirect3DTexture, NULL, E_NOINTERFACE},
2290 {&IID_IDirectDrawGammaControl, NULL, E_NOINTERFACE},
2291 {&IID_IDirectDrawColorControl, NULL, E_NOINTERFACE},
2292 {&IID_IDirectDrawSurface7, NULL, E_NOINTERFACE},
2293 {&IID_IDirectDrawSurface4, NULL, E_NOINTERFACE},
2294 {&IID_IDirectDrawSurface3, NULL, E_NOINTERFACE},
2295 {&IID_IDirectDrawSurface2, NULL, E_NOINTERFACE},
2296 {&IID_IDirectDrawSurface, NULL, E_NOINTERFACE},
2297 {&IID_IDirect3DDevice7, NULL, E_NOINTERFACE},
2298 {&IID_IDirect3DDevice3, &IID_IDirect3DDevice3, S_OK },
2299 {&IID_IDirect3DDevice2, &IID_IDirect3DDevice3, S_OK },
2300 {&IID_IDirect3DDevice, &IID_IDirect3DDevice3, S_OK },
2301 {&IID_IDirect3DRampDevice, NULL, E_NOINTERFACE},
2302 {&IID_IDirect3DRGBDevice, NULL, E_NOINTERFACE},
2303 {&IID_IDirect3DHALDevice, NULL, E_NOINTERFACE},
2304 {&IID_IDirect3DMMXDevice, NULL, E_NOINTERFACE},
2305 {&IID_IDirect3DRefDevice, NULL, E_NOINTERFACE},
2306 {&IID_IDirect3DTnLHalDevice, NULL, E_NOINTERFACE},
2307 {&IID_IDirect3DNullDevice, NULL, E_NOINTERFACE},
2308 {&IID_IDirect3D7, NULL, E_NOINTERFACE},
2309 {&IID_IDirect3D3, NULL, E_NOINTERFACE},
2310 {&IID_IDirect3D2, NULL, E_NOINTERFACE},
2311 {&IID_IDirect3D, NULL, E_NOINTERFACE},
2312 {&IID_IDirectDraw7, NULL, E_NOINTERFACE},
2313 {&IID_IDirectDraw4, NULL, E_NOINTERFACE},
2314 {&IID_IDirectDraw3, NULL, E_NOINTERFACE},
2315 {&IID_IDirectDraw2, NULL, E_NOINTERFACE},
2316 {&IID_IDirectDraw, NULL, E_NOINTERFACE},
2317 {&IID_IDirect3DLight, NULL, E_NOINTERFACE},
2318 {&IID_IDirect3DMaterial, NULL, E_NOINTERFACE},
2319 {&IID_IDirect3DMaterial2, NULL, E_NOINTERFACE},
2320 {&IID_IDirect3DMaterial3, NULL, E_NOINTERFACE},
2321 {&IID_IDirect3DExecuteBuffer, NULL, E_NOINTERFACE},
2322 {&IID_IDirect3DViewport, NULL, E_NOINTERFACE},
2323 {&IID_IDirect3DViewport2, NULL, E_NOINTERFACE},
2324 {&IID_IDirect3DViewport3, NULL, E_NOINTERFACE},
2325 {&IID_IDirect3DVertexBuffer, NULL, E_NOINTERFACE},
2326 {&IID_IDirect3DVertexBuffer7, NULL, E_NOINTERFACE},
2327 {&IID_IDirectDrawPalette, NULL, E_NOINTERFACE},
2328 {&IID_IDirectDrawClipper, NULL, E_NOINTERFACE},
2329 {&IID_IUnknown, &IID_IDirect3DDevice3, S_OK },
2332 IDirect3DDevice3 *device;
2333 HWND window;
2335 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
2336 0, 0, 640, 480, 0, 0, 0, 0);
2337 if (!(device = create_device(window, DDSCL_NORMAL)))
2339 skip("Failed to create a 3D device, skipping test.\n");
2340 DestroyWindow(window);
2341 return;
2344 test_qi("device_qi", (IUnknown *)device, &IID_IDirect3DDevice3, tests, sizeof(tests) / sizeof(*tests));
2346 IDirect3DDevice3_Release(device);
2347 DestroyWindow(window);
2350 static void test_wndproc(void)
2352 LONG_PTR proc, ddraw_proc;
2353 IDirectDraw4 *ddraw;
2354 WNDCLASSA wc = {0};
2355 HWND window;
2356 HRESULT hr;
2357 ULONG ref;
2359 static struct message messages[] =
2361 {WM_WINDOWPOSCHANGING, FALSE, 0},
2362 {WM_MOVE, FALSE, 0},
2363 {WM_SIZE, FALSE, 0},
2364 {WM_WINDOWPOSCHANGING, FALSE, 0},
2365 {WM_ACTIVATE, FALSE, 0},
2366 {WM_SETFOCUS, FALSE, 0},
2367 {0, FALSE, 0},
2370 /* DDSCL_EXCLUSIVE replaces the window's window proc. */
2371 ddraw = create_ddraw();
2372 ok(!!ddraw, "Failed to create a ddraw object.\n");
2374 wc.lpfnWndProc = test_proc;
2375 wc.lpszClassName = "ddraw_test_wndproc_wc";
2376 ok(RegisterClassA(&wc), "Failed to register window class.\n");
2378 window = CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
2379 WS_MAXIMIZE | WS_CAPTION , 0, 0, 640, 480, 0, 0, 0, 0);
2381 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2382 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2383 (LONG_PTR)test_proc, proc);
2384 expect_messages = messages;
2385 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2386 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2387 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2388 expect_messages = NULL;
2389 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2390 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
2391 (LONG_PTR)test_proc, proc);
2392 ref = IDirectDraw4_Release(ddraw);
2393 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2394 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2395 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2396 (LONG_PTR)test_proc, proc);
2398 /* DDSCL_NORMAL doesn't. */
2399 ddraw = create_ddraw();
2400 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2401 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2402 (LONG_PTR)test_proc, proc);
2403 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL | DDSCL_FULLSCREEN);
2404 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2405 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2406 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2407 (LONG_PTR)test_proc, proc);
2408 ref = IDirectDraw4_Release(ddraw);
2409 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2410 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2411 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2412 (LONG_PTR)test_proc, proc);
2414 /* The original window proc is only restored by ddraw if the current
2415 * window proc matches the one ddraw set. This also affects switching
2416 * from DDSCL_NORMAL to DDSCL_EXCLUSIVE. */
2417 ddraw = create_ddraw();
2418 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2419 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2420 (LONG_PTR)test_proc, proc);
2421 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2422 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2423 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2424 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
2425 (LONG_PTR)test_proc, proc);
2426 ddraw_proc = proc;
2427 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2428 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2429 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2430 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2431 (LONG_PTR)test_proc, proc);
2432 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2433 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2434 proc = SetWindowLongPtrA(window, GWLP_WNDPROC, (LONG_PTR)DefWindowProcA);
2435 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
2436 (LONG_PTR)test_proc, proc);
2437 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2438 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2439 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2440 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#lx, got %#lx.\n",
2441 (LONG_PTR)DefWindowProcA, proc);
2442 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2443 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2444 proc = SetWindowLongPtrA(window, GWLP_WNDPROC, (LONG_PTR)ddraw_proc);
2445 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#lx, got %#lx.\n",
2446 (LONG_PTR)DefWindowProcA, proc);
2447 ref = IDirectDraw4_Release(ddraw);
2448 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2449 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2450 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2451 (LONG_PTR)test_proc, proc);
2453 ddraw = create_ddraw();
2454 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2455 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2456 (LONG_PTR)test_proc, proc);
2457 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2458 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2459 proc = SetWindowLongPtrA(window, GWLP_WNDPROC, (LONG_PTR)DefWindowProcA);
2460 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
2461 (LONG_PTR)test_proc, proc);
2462 ref = IDirectDraw4_Release(ddraw);
2463 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2464 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2465 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#lx, got %#lx.\n",
2466 (LONG_PTR)DefWindowProcA, proc);
2468 fix_wndproc(window, (LONG_PTR)test_proc);
2469 expect_messages = NULL;
2470 DestroyWindow(window);
2471 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL));
2474 static void test_window_style(void)
2476 LONG style, exstyle, tmp, expected_style;
2477 RECT fullscreen_rect, r;
2478 IDirectDraw4 *ddraw;
2479 HWND window;
2480 HRESULT hr;
2481 ULONG ref;
2482 BOOL ret;
2484 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
2485 0, 0, 100, 100, 0, 0, 0, 0);
2486 ddraw = create_ddraw();
2487 ok(!!ddraw, "Failed to create a ddraw object.\n");
2489 style = GetWindowLongA(window, GWL_STYLE);
2490 exstyle = GetWindowLongA(window, GWL_EXSTYLE);
2491 SetRect(&fullscreen_rect, 0, 0, registry_mode.dmPelsWidth, registry_mode.dmPelsHeight);
2493 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2494 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2496 tmp = GetWindowLongA(window, GWL_STYLE);
2497 todo_wine ok(tmp == style, "Expected window style %#x, got %#x.\n", style, tmp);
2498 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2499 todo_wine ok(tmp == exstyle, "Expected window extended style %#x, got %#x.\n", exstyle, tmp);
2501 GetWindowRect(window, &r);
2502 ok(EqualRect(&r, &fullscreen_rect), "Expected %s, got %s.\n",
2503 wine_dbgstr_rect(&fullscreen_rect), wine_dbgstr_rect(&r));
2504 GetClientRect(window, &r);
2505 todo_wine ok(!EqualRect(&r, &fullscreen_rect), "Client rect and window rect are equal.\n");
2507 ret = SetForegroundWindow(GetDesktopWindow());
2508 ok(ret, "Failed to set foreground window.\n");
2510 tmp = GetWindowLongA(window, GWL_STYLE);
2511 todo_wine ok(tmp == style, "Expected window style %#x, got %#x.\n", style, tmp);
2512 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2513 todo_wine ok(tmp == exstyle, "Expected window extended style %#x, got %#x.\n", exstyle, tmp);
2515 ret = SetForegroundWindow(window);
2516 ok(ret, "Failed to set foreground window.\n");
2517 /* Windows 7 (but not Vista and XP) shows the window when it receives focus. Hide it again,
2518 * the next tests expect this. */
2519 ShowWindow(window, SW_HIDE);
2521 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2522 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2524 tmp = GetWindowLongA(window, GWL_STYLE);
2525 todo_wine ok(tmp == style, "Expected window style %#x, got %#x.\n", style, tmp);
2526 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2527 todo_wine ok(tmp == exstyle, "Expected window extended style %#x, got %#x.\n", exstyle, tmp);
2529 ShowWindow(window, SW_SHOW);
2530 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2531 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2533 tmp = GetWindowLongA(window, GWL_STYLE);
2534 expected_style = style | WS_VISIBLE;
2535 todo_wine ok(tmp == expected_style, "Expected window style %#x, got %#x.\n", expected_style, tmp);
2536 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2537 expected_style = exstyle | WS_EX_TOPMOST;
2538 todo_wine ok(tmp == expected_style, "Expected window extended style %#x, got %#x.\n", expected_style, tmp);
2540 ret = SetForegroundWindow(GetDesktopWindow());
2541 ok(ret, "Failed to set foreground window.\n");
2542 tmp = GetWindowLongA(window, GWL_STYLE);
2543 expected_style = style | WS_VISIBLE | WS_MINIMIZE;
2544 todo_wine ok(tmp == expected_style, "Expected window style %#x, got %#x.\n", expected_style, tmp);
2545 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2546 expected_style = exstyle | WS_EX_TOPMOST;
2547 todo_wine ok(tmp == expected_style, "Expected window extended style %#x, got %#x.\n", expected_style, tmp);
2549 ref = IDirectDraw4_Release(ddraw);
2550 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2552 DestroyWindow(window);
2555 static void test_redundant_mode_set(void)
2557 DDSURFACEDESC2 surface_desc = {0};
2558 IDirectDraw4 *ddraw;
2559 HWND window;
2560 HRESULT hr;
2561 RECT r, s;
2562 ULONG ref;
2564 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
2565 0, 0, 100, 100, 0, 0, 0, 0);
2566 ddraw = create_ddraw();
2567 ok(!!ddraw, "Failed to create a ddraw object.\n");
2569 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2570 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2572 surface_desc.dwSize = sizeof(surface_desc);
2573 hr = IDirectDraw4_GetDisplayMode(ddraw, &surface_desc);
2574 ok(SUCCEEDED(hr), "GetDisplayMode failed, hr %#x.\n", hr);
2576 hr = IDirectDraw4_SetDisplayMode(ddraw, surface_desc.dwWidth, surface_desc.dwHeight,
2577 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount, 0, 0);
2578 ok(SUCCEEDED(hr), "SetDisplayMode failed, hr %#x.\n", hr);
2580 GetWindowRect(window, &r);
2581 r.right /= 2;
2582 r.bottom /= 2;
2583 SetWindowPos(window, HWND_TOP, r.left, r.top, r.right, r.bottom, 0);
2584 GetWindowRect(window, &s);
2585 ok(EqualRect(&r, &s), "Expected %s, got %s.\n", wine_dbgstr_rect(&r), wine_dbgstr_rect(&s));
2587 hr = IDirectDraw4_SetDisplayMode(ddraw, surface_desc.dwWidth, surface_desc.dwHeight,
2588 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount, 0, 0);
2589 ok(SUCCEEDED(hr), "SetDisplayMode failed, hr %#x.\n", hr);
2591 GetWindowRect(window, &s);
2592 ok(EqualRect(&r, &s), "Expected %s, got %s.\n", wine_dbgstr_rect(&r), wine_dbgstr_rect(&s));
2594 ref = IDirectDraw4_Release(ddraw);
2595 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2597 DestroyWindow(window);
2600 static SIZE screen_size, screen_size2;
2602 static LRESULT CALLBACK mode_set_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
2604 if (message == WM_SIZE)
2606 screen_size.cx = GetSystemMetrics(SM_CXSCREEN);
2607 screen_size.cy = GetSystemMetrics(SM_CYSCREEN);
2610 return test_proc(hwnd, message, wparam, lparam);
2613 static LRESULT CALLBACK mode_set_proc2(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
2615 if (message == WM_SIZE)
2617 screen_size2.cx = GetSystemMetrics(SM_CXSCREEN);
2618 screen_size2.cy = GetSystemMetrics(SM_CYSCREEN);
2621 return test_proc(hwnd, message, wparam, lparam);
2624 struct test_coop_level_mode_set_enum_param
2626 DWORD ddraw_width, ddraw_height, user32_width, user32_height;
2629 static HRESULT CALLBACK test_coop_level_mode_set_enum_cb(DDSURFACEDESC2 *surface_desc, void *context)
2631 struct test_coop_level_mode_set_enum_param *param = context;
2633 if (U1(U4(*surface_desc).ddpfPixelFormat).dwRGBBitCount != registry_mode.dmBitsPerPel)
2634 return DDENUMRET_OK;
2635 if (surface_desc->dwWidth == registry_mode.dmPelsWidth
2636 && surface_desc->dwHeight == registry_mode.dmPelsHeight)
2637 return DDENUMRET_OK;
2639 if (!param->ddraw_width)
2641 param->ddraw_width = surface_desc->dwWidth;
2642 param->ddraw_height = surface_desc->dwHeight;
2643 return DDENUMRET_OK;
2645 if (surface_desc->dwWidth == param->ddraw_width && surface_desc->dwHeight == param->ddraw_height)
2646 return DDENUMRET_OK;
2648 param->user32_width = surface_desc->dwWidth;
2649 param->user32_height = surface_desc->dwHeight;
2650 return DDENUMRET_CANCEL;
2653 static void test_coop_level_mode_set(void)
2655 IDirectDrawSurface4 *primary;
2656 RECT registry_rect, ddraw_rect, user32_rect, r;
2657 IDirectDraw4 *ddraw;
2658 DDSURFACEDESC2 ddsd;
2659 WNDCLASSA wc = {0};
2660 HWND window, window2;
2661 HRESULT hr;
2662 ULONG ref;
2663 MSG msg;
2664 struct test_coop_level_mode_set_enum_param param;
2665 DEVMODEW devmode;
2666 BOOL ret;
2667 LONG change_ret;
2669 static const struct message exclusive_messages[] =
2671 {WM_WINDOWPOSCHANGING, FALSE, 0},
2672 {WM_WINDOWPOSCHANGED, FALSE, 0},
2673 {WM_SIZE, FALSE, 0},
2674 {WM_DISPLAYCHANGE, FALSE, 0},
2675 {0, FALSE, 0},
2677 static const struct message exclusive_focus_loss_messages[] =
2679 {WM_ACTIVATE, TRUE, WA_INACTIVE},
2680 {WM_DISPLAYCHANGE, FALSE, 0},
2681 {WM_WINDOWPOSCHANGING, FALSE, 0},
2682 /* Like d3d8 and d3d9 ddraw seems to use SW_SHOWMINIMIZED instead of
2683 * SW_MINIMIZED, causing a recursive window activation that does not
2684 * produce the same result in Wine yet. Ignore the difference for now.
2685 * {WM_ACTIVATE, TRUE, 0x200000 | WA_ACTIVE}, */
2686 {WM_WINDOWPOSCHANGED, FALSE, 0},
2687 {WM_MOVE, FALSE, 0},
2688 {WM_SIZE, TRUE, SIZE_MINIMIZED},
2689 {WM_ACTIVATEAPP, TRUE, FALSE},
2690 {0, FALSE, 0},
2692 static const struct message exclusive_focus_restore_messages[] =
2694 {WM_WINDOWPOSCHANGING, FALSE, 0}, /* From the ShowWindow(SW_RESTORE). */
2695 {WM_WINDOWPOSCHANGING, FALSE, 0}, /* Generated by ddraw, matches d3d9 behavior. */
2696 {WM_WINDOWPOSCHANGED, FALSE, 0}, /* Matching previous message. */
2697 {WM_SIZE, FALSE, 0}, /* DefWindowProc. */
2698 {WM_DISPLAYCHANGE, FALSE, 0}, /* Ddraw restores mode. */
2699 /* Native redundantly sets the window size here. */
2700 {WM_ACTIVATEAPP, TRUE, TRUE}, /* End of ddraw's hooks. */
2701 {WM_WINDOWPOSCHANGED, FALSE, 0}, /* Matching the one from ShowWindow. */
2702 {WM_MOVE, FALSE, 0}, /* DefWindowProc. */
2703 {WM_SIZE, TRUE, SIZE_RESTORED}, /* DefWindowProc. */
2704 {0, FALSE, 0},
2706 static const struct message sc_restore_messages[] =
2708 {WM_SYSCOMMAND, TRUE, SC_RESTORE},
2709 {WM_WINDOWPOSCHANGING, FALSE, 0},
2710 {WM_WINDOWPOSCHANGED, FALSE, 0},
2711 {WM_SIZE, TRUE, SIZE_RESTORED},
2712 {0, FALSE, 0},
2714 static const struct message sc_minimize_messages[] =
2716 {WM_SYSCOMMAND, TRUE, SC_MINIMIZE},
2717 {WM_WINDOWPOSCHANGING, FALSE, 0},
2718 {WM_WINDOWPOSCHANGED, FALSE, 0},
2719 {WM_SIZE, TRUE, SIZE_MINIMIZED},
2720 {0, FALSE, 0},
2722 static const struct message sc_maximize_messages[] =
2724 {WM_SYSCOMMAND, TRUE, SC_MAXIMIZE},
2725 {WM_WINDOWPOSCHANGING, FALSE, 0},
2726 {WM_WINDOWPOSCHANGED, FALSE, 0},
2727 {WM_SIZE, TRUE, SIZE_MAXIMIZED},
2728 {0, FALSE, 0},
2731 static const struct message normal_messages[] =
2733 {WM_DISPLAYCHANGE, FALSE, 0},
2734 {0, FALSE, 0},
2737 ddraw = create_ddraw();
2738 ok(!!ddraw, "Failed to create a ddraw object.\n");
2740 memset(&param, 0, sizeof(param));
2741 hr = IDirectDraw4_EnumDisplayModes(ddraw, 0, NULL, &param, test_coop_level_mode_set_enum_cb);
2742 ok(SUCCEEDED(hr), "Failed to enumerate display mode, hr %#x.\n", hr);
2743 ref = IDirectDraw4_Release(ddraw);
2744 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2746 if (!param.user32_height)
2748 skip("Fewer than 3 different modes supported, skipping mode restore test.\n");
2749 return;
2752 SetRect(&registry_rect, 0, 0, registry_mode.dmPelsWidth, registry_mode.dmPelsHeight);
2753 SetRect(&ddraw_rect, 0, 0, param.ddraw_width, param.ddraw_height);
2754 SetRect(&user32_rect, 0, 0, param.user32_width, param.user32_height);
2756 memset(&devmode, 0, sizeof(devmode));
2757 devmode.dmSize = sizeof(devmode);
2758 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
2759 devmode.dmPelsWidth = param.user32_width;
2760 devmode.dmPelsHeight = param.user32_height;
2761 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
2762 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2764 ddraw = create_ddraw();
2765 ok(!!ddraw, "Failed to create a ddraw object.\n");
2767 wc.lpfnWndProc = mode_set_proc;
2768 wc.lpszClassName = "ddraw_test_wndproc_wc";
2769 ok(RegisterClassA(&wc), "Failed to register window class.\n");
2770 wc.lpfnWndProc = mode_set_proc2;
2771 wc.lpszClassName = "ddraw_test_wndproc_wc2";
2772 ok(RegisterClassA(&wc), "Failed to register window class.\n");
2774 window = CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test", WS_OVERLAPPEDWINDOW,
2775 0, 0, 100, 100, 0, 0, 0, 0);
2776 window2 = CreateWindowA("ddraw_test_wndproc_wc2", "ddraw_test", WS_OVERLAPPEDWINDOW,
2777 0, 0, 100, 100, 0, 0, 0, 0);
2779 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2780 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2782 GetWindowRect(window, &r);
2783 ok(EqualRect(&r, &user32_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&user32_rect),
2784 wine_dbgstr_rect(&r));
2786 memset(&ddsd, 0, sizeof(ddsd));
2787 ddsd.dwSize = sizeof(ddsd);
2788 ddsd.dwFlags = DDSD_CAPS;
2789 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2791 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
2792 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2793 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
2794 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2795 ok(ddsd.dwWidth == param.user32_width, "Expected surface width %u, got %u.\n",
2796 param.user32_width, ddsd.dwWidth);
2797 ok(ddsd.dwHeight == param.user32_height, "Expected surface height %u, got %u.\n",
2798 param.user32_height, ddsd.dwHeight);
2800 GetWindowRect(window, &r);
2801 ok(EqualRect(&r, &user32_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&user32_rect),
2802 wine_dbgstr_rect(&r));
2804 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2805 expect_messages = exclusive_messages;
2806 screen_size.cx = 0;
2807 screen_size.cy = 0;
2809 hr = IDirectDrawSurface4_IsLost(primary);
2810 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
2811 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
2812 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2813 hr = IDirectDrawSurface4_IsLost(primary);
2814 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2816 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2817 expect_messages = NULL;
2818 ok(screen_size.cx == param.ddraw_width && screen_size.cy == param.ddraw_height,
2819 "Expected screen size %ux%u, got %ux%u.\n",
2820 param.ddraw_width, param.ddraw_height, screen_size.cx, screen_size.cy);
2822 GetWindowRect(window, &r);
2823 ok(EqualRect(&r, &ddraw_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect),
2824 wine_dbgstr_rect(&r));
2826 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
2827 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2828 ok(ddsd.dwWidth == param.user32_width, "Expected surface width %u, got %u.\n",
2829 param.user32_width, ddsd.dwWidth);
2830 ok(ddsd.dwHeight == param.user32_height, "Expected surface height %u, got %u.\n",
2831 param.user32_height, ddsd.dwHeight);
2832 IDirectDrawSurface4_Release(primary);
2834 memset(&ddsd, 0, sizeof(ddsd));
2835 ddsd.dwSize = sizeof(ddsd);
2836 ddsd.dwFlags = DDSD_CAPS;
2837 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2839 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
2840 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2841 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
2842 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2843 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2844 param.ddraw_width, ddsd.dwWidth);
2845 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2846 param.ddraw_height, ddsd.dwHeight);
2848 GetWindowRect(window, &r);
2849 ok(EqualRect(&r, &ddraw_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect),
2850 wine_dbgstr_rect(&r));
2852 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2853 expect_messages = exclusive_messages;
2854 screen_size.cx = 0;
2855 screen_size.cy = 0;
2857 hr = IDirectDrawSurface4_IsLost(primary);
2858 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
2859 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
2860 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2861 hr = IDirectDrawSurface4_IsLost(primary);
2862 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2864 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2865 expect_messages = NULL;
2866 ok(screen_size.cx == param.user32_width && screen_size.cy == param.user32_height,
2867 "Expected screen size %ux%u, got %ux%u.\n",
2868 param.user32_width, param.user32_height, screen_size.cx, screen_size.cy);
2870 GetWindowRect(window, &r);
2871 ok(EqualRect(&r, &user32_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&user32_rect),
2872 wine_dbgstr_rect(&r));
2874 expect_messages = exclusive_focus_loss_messages;
2875 ret = SetForegroundWindow(GetDesktopWindow());
2876 ok(ret, "Failed to set foreground window.\n");
2877 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2878 memset(&devmode, 0, sizeof(devmode));
2879 devmode.dmSize = sizeof(devmode);
2880 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
2881 ok(ret, "Failed to get display mode.\n");
2882 ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth
2883 && devmode.dmPelsHeight == registry_mode.dmPelsHeight, "Got unexpect screen size %ux%u.\n",
2884 devmode.dmPelsWidth, devmode.dmPelsHeight);
2886 expect_messages = exclusive_focus_restore_messages;
2887 ShowWindow(window, SW_RESTORE);
2888 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2890 GetWindowRect(window, &r);
2891 ok(EqualRect(&r, &ddraw_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect),
2892 wine_dbgstr_rect(&r));
2893 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
2894 ok(ret, "Failed to get display mode.\n");
2895 ok(devmode.dmPelsWidth == param.ddraw_width
2896 && devmode.dmPelsHeight == param.ddraw_height, "Got unexpect screen size %ux%u.\n",
2897 devmode.dmPelsWidth, devmode.dmPelsHeight);
2899 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2900 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2901 /* Normally the primary should be restored here. Unfortunately this causes the
2902 * GetSurfaceDesc call after the next display mode change to crash on the Windows 8
2903 * testbot. Another Restore call would presumably avoid the crash, but it also moots
2904 * the point of the GetSurfaceDesc call. */
2906 expect_messages = sc_minimize_messages;
2907 SendMessageA(window, WM_SYSCOMMAND, SC_MINIMIZE, 0);
2908 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2909 expect_messages = NULL;
2911 expect_messages = sc_restore_messages;
2912 SendMessageA(window, WM_SYSCOMMAND, SC_RESTORE, 0);
2913 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2914 expect_messages = NULL;
2916 expect_messages = sc_maximize_messages;
2917 SendMessageA(window, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
2918 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2919 expect_messages = NULL;
2921 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2922 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2924 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2925 expect_messages = exclusive_messages;
2926 screen_size.cx = 0;
2927 screen_size.cy = 0;
2929 hr = IDirectDrawSurface4_IsLost(primary);
2930 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2931 hr = IDirectDraw4_RestoreDisplayMode(ddraw);
2932 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
2933 hr = IDirectDrawSurface4_IsLost(primary);
2934 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
2936 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2937 expect_messages = NULL;
2938 ok(screen_size.cx == registry_mode.dmPelsWidth
2939 && screen_size.cy == registry_mode.dmPelsHeight,
2940 "Expected screen size %ux%u, got %ux%u.\n",
2941 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight, screen_size.cx, screen_size.cy);
2943 GetWindowRect(window, &r);
2944 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2945 wine_dbgstr_rect(&r));
2947 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
2948 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2949 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2950 param.ddraw_width, ddsd.dwWidth);
2951 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2952 param.ddraw_height, ddsd.dwHeight);
2953 IDirectDrawSurface4_Release(primary);
2955 /* For Wine. */
2956 change_ret = ChangeDisplaySettingsW(NULL, CDS_FULLSCREEN);
2957 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2959 memset(&ddsd, 0, sizeof(ddsd));
2960 ddsd.dwSize = sizeof(ddsd);
2961 ddsd.dwFlags = DDSD_CAPS;
2962 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2964 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
2965 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2966 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
2967 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2968 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2969 registry_mode.dmPelsWidth, ddsd.dwWidth);
2970 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2971 registry_mode.dmPelsHeight, ddsd.dwHeight);
2973 GetWindowRect(window, &r);
2974 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2975 wine_dbgstr_rect(&r));
2977 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2978 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2980 GetWindowRect(window, &r);
2981 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
2982 wine_dbgstr_rect(&r));
2984 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
2985 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2986 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2987 registry_mode.dmPelsWidth, ddsd.dwWidth);
2988 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2989 registry_mode.dmPelsHeight, ddsd.dwHeight);
2990 IDirectDrawSurface4_Release(primary);
2992 memset(&ddsd, 0, sizeof(ddsd));
2993 ddsd.dwSize = sizeof(ddsd);
2994 ddsd.dwFlags = DDSD_CAPS;
2995 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2997 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
2998 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2999 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
3000 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
3001 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
3002 registry_mode.dmPelsWidth, ddsd.dwWidth);
3003 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
3004 registry_mode.dmPelsHeight, ddsd.dwHeight);
3006 GetWindowRect(window, &r);
3007 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
3008 wine_dbgstr_rect(&r));
3010 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
3011 expect_messages = normal_messages;
3012 screen_size.cx = 0;
3013 screen_size.cy = 0;
3015 hr = IDirectDrawSurface4_IsLost(primary);
3016 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
3017 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
3018 devmode.dmPelsWidth = param.user32_width;
3019 devmode.dmPelsHeight = param.user32_height;
3020 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
3021 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
3022 hr = IDirectDrawSurface4_IsLost(primary);
3023 todo_wine ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
3025 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
3026 expect_messages = NULL;
3027 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
3029 GetWindowRect(window, &r);
3030 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
3031 wine_dbgstr_rect(&r));
3033 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
3034 expect_messages = normal_messages;
3035 screen_size.cx = 0;
3036 screen_size.cy = 0;
3038 hr = IDirectDrawSurface4_Restore(primary);
3039 ok(hr == DDERR_WRONGMODE, "Got unexpected hr %#x.\n", hr);
3040 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
3041 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3042 hr = IDirectDrawSurface4_Restore(primary);
3043 ok(hr == DDERR_WRONGMODE, "Got unexpected hr %#x.\n", hr);
3044 hr = IDirectDrawSurface4_IsLost(primary);
3045 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
3047 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
3048 expect_messages = NULL;
3049 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
3051 GetWindowRect(window, &r);
3052 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
3053 wine_dbgstr_rect(&r));
3055 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
3056 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
3057 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
3058 registry_mode.dmPelsWidth, ddsd.dwWidth);
3059 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
3060 registry_mode.dmPelsHeight, ddsd.dwHeight);
3061 IDirectDrawSurface4_Release(primary);
3063 memset(&ddsd, 0, sizeof(ddsd));
3064 ddsd.dwSize = sizeof(ddsd);
3065 ddsd.dwFlags = DDSD_CAPS;
3066 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3068 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
3069 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
3070 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
3071 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
3072 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
3073 param.ddraw_width, ddsd.dwWidth);
3074 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
3075 param.ddraw_height, ddsd.dwHeight);
3077 GetWindowRect(window, &r);
3078 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
3079 wine_dbgstr_rect(&r));
3081 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
3082 expect_messages = normal_messages;
3083 screen_size.cx = 0;
3084 screen_size.cy = 0;
3086 hr = IDirectDrawSurface4_IsLost(primary);
3087 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
3088 hr = IDirectDraw4_RestoreDisplayMode(ddraw);
3089 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
3090 hr = IDirectDrawSurface4_IsLost(primary);
3091 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
3093 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
3094 expect_messages = NULL;
3095 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
3097 GetWindowRect(window, &r);
3098 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
3099 wine_dbgstr_rect(&r));
3101 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
3102 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
3103 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
3104 param.ddraw_width, ddsd.dwWidth);
3105 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
3106 param.ddraw_height, ddsd.dwHeight);
3107 IDirectDrawSurface4_Release(primary);
3109 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
3110 ok(ret, "Failed to get display mode.\n");
3111 ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth
3112 && devmode.dmPelsHeight == registry_mode.dmPelsHeight,
3113 "Expected resolution %ux%u, got %ux%u.\n",
3114 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight,
3115 devmode.dmPelsWidth, devmode.dmPelsHeight);
3116 change_ret = ChangeDisplaySettingsW(NULL, CDS_FULLSCREEN);
3117 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
3119 memset(&ddsd, 0, sizeof(ddsd));
3120 ddsd.dwSize = sizeof(ddsd);
3121 ddsd.dwFlags = DDSD_CAPS;
3122 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3124 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
3125 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
3126 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
3127 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
3128 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
3129 registry_mode.dmPelsWidth, ddsd.dwWidth);
3130 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
3131 registry_mode.dmPelsHeight, ddsd.dwHeight);
3133 GetWindowRect(window, &r);
3134 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
3135 wine_dbgstr_rect(&r));
3137 /* DDSCL_NORMAL | DDSCL_FULLSCREEN behaves the same as just DDSCL_NORMAL.
3138 * Resizing the window on mode changes is a property of DDSCL_EXCLUSIVE,
3139 * not DDSCL_FULLSCREEN. */
3140 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL | DDSCL_FULLSCREEN);
3141 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3143 GetWindowRect(window, &r);
3144 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
3145 wine_dbgstr_rect(&r));
3147 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
3148 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
3149 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
3150 registry_mode.dmPelsWidth, ddsd.dwWidth);
3151 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
3152 registry_mode.dmPelsHeight, ddsd.dwHeight);
3153 IDirectDrawSurface4_Release(primary);
3155 memset(&ddsd, 0, sizeof(ddsd));
3156 ddsd.dwSize = sizeof(ddsd);
3157 ddsd.dwFlags = DDSD_CAPS;
3158 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3160 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
3161 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
3162 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
3163 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
3164 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
3165 registry_mode.dmPelsWidth, ddsd.dwWidth);
3166 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
3167 registry_mode.dmPelsHeight, ddsd.dwHeight);
3169 GetWindowRect(window, &r);
3170 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
3171 wine_dbgstr_rect(&r));
3173 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
3174 expect_messages = normal_messages;
3175 screen_size.cx = 0;
3176 screen_size.cy = 0;
3178 hr = IDirectDrawSurface4_IsLost(primary);
3179 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
3180 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
3181 devmode.dmPelsWidth = param.user32_width;
3182 devmode.dmPelsHeight = param.user32_height;
3183 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
3184 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
3185 hr = IDirectDrawSurface4_IsLost(primary);
3186 todo_wine ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
3188 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
3189 expect_messages = NULL;
3190 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
3192 GetWindowRect(window, &r);
3193 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
3194 wine_dbgstr_rect(&r));
3196 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
3197 expect_messages = normal_messages;
3198 screen_size.cx = 0;
3199 screen_size.cy = 0;
3201 hr = IDirectDrawSurface4_Restore(primary);
3202 ok(hr == DDERR_WRONGMODE, "Got unexpected hr %#x.\n", hr);
3203 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
3204 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3205 hr = IDirectDrawSurface4_Restore(primary);
3206 ok(hr == DDERR_WRONGMODE, "Got unexpected hr %#x.\n", hr);
3207 hr = IDirectDrawSurface4_IsLost(primary);
3208 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
3210 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
3211 expect_messages = NULL;
3212 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
3214 GetWindowRect(window, &r);
3215 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
3216 wine_dbgstr_rect(&r));
3218 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
3219 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
3220 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
3221 registry_mode.dmPelsWidth, ddsd.dwWidth);
3222 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
3223 registry_mode.dmPelsHeight, ddsd.dwHeight);
3224 IDirectDrawSurface4_Release(primary);
3226 memset(&ddsd, 0, sizeof(ddsd));
3227 ddsd.dwSize = sizeof(ddsd);
3228 ddsd.dwFlags = DDSD_CAPS;
3229 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3231 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
3232 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
3233 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
3234 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
3235 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
3236 param.ddraw_width, ddsd.dwWidth);
3237 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
3238 param.ddraw_height, ddsd.dwHeight);
3240 GetWindowRect(window, &r);
3241 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
3242 wine_dbgstr_rect(&r));
3244 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
3245 expect_messages = normal_messages;
3246 screen_size.cx = 0;
3247 screen_size.cy = 0;
3249 hr = IDirectDrawSurface4_IsLost(primary);
3250 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
3251 hr = IDirectDraw4_RestoreDisplayMode(ddraw);
3252 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
3253 hr = IDirectDrawSurface4_IsLost(primary);
3254 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
3256 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
3257 expect_messages = NULL;
3258 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
3260 GetWindowRect(window, &r);
3261 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
3262 wine_dbgstr_rect(&r));
3264 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
3265 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
3266 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
3267 param.ddraw_width, ddsd.dwWidth);
3268 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
3269 param.ddraw_height, ddsd.dwHeight);
3270 IDirectDrawSurface4_Release(primary);
3272 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
3273 ok(ret, "Failed to get display mode.\n");
3274 ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth
3275 && devmode.dmPelsHeight == registry_mode.dmPelsHeight,
3276 "Expected resolution %ux%u, got %ux%u.\n",
3277 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight,
3278 devmode.dmPelsWidth, devmode.dmPelsHeight);
3279 change_ret = ChangeDisplaySettingsW(NULL, CDS_FULLSCREEN);
3280 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
3282 memset(&ddsd, 0, sizeof(ddsd));
3283 ddsd.dwSize = sizeof(ddsd);
3284 ddsd.dwFlags = DDSD_CAPS;
3285 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3287 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
3288 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
3289 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
3290 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
3291 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
3292 registry_mode.dmPelsWidth, ddsd.dwWidth);
3293 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
3294 registry_mode.dmPelsHeight, ddsd.dwHeight);
3295 IDirectDrawSurface4_Release(primary);
3297 GetWindowRect(window, &r);
3298 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
3299 wine_dbgstr_rect(&r));
3301 /* Changing the coop level from EXCLUSIVE to NORMAL restores the screen resolution */
3302 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3303 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3304 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
3305 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3307 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
3308 expect_messages = exclusive_messages;
3309 screen_size.cx = 0;
3310 screen_size.cy = 0;
3312 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
3313 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3315 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
3316 expect_messages = NULL;
3317 ok(screen_size.cx == registry_mode.dmPelsWidth
3318 && screen_size.cy == registry_mode.dmPelsHeight,
3319 "Expected screen size %ux%u, got %ux%u.\n",
3320 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight,
3321 screen_size.cx, screen_size.cy);
3323 GetWindowRect(window, &r);
3324 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
3325 wine_dbgstr_rect(&r));
3327 memset(&ddsd, 0, sizeof(ddsd));
3328 ddsd.dwSize = sizeof(ddsd);
3329 ddsd.dwFlags = DDSD_CAPS;
3330 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3332 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
3333 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
3334 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
3335 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
3336 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
3337 registry_mode.dmPelsWidth, ddsd.dwWidth);
3338 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
3339 registry_mode.dmPelsHeight, ddsd.dwHeight);
3340 IDirectDrawSurface4_Release(primary);
3342 /* The screen restore is a property of DDSCL_EXCLUSIVE */
3343 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL | DDSCL_FULLSCREEN);
3344 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3345 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
3346 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3348 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
3349 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3351 memset(&ddsd, 0, sizeof(ddsd));
3352 ddsd.dwSize = sizeof(ddsd);
3353 ddsd.dwFlags = DDSD_CAPS;
3354 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3356 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
3357 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
3358 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
3359 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
3360 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
3361 param.ddraw_width, ddsd.dwWidth);
3362 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
3363 param.ddraw_height, ddsd.dwHeight);
3364 IDirectDrawSurface4_Release(primary);
3366 hr = IDirectDraw4_RestoreDisplayMode(ddraw);
3367 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
3369 /* If the window is changed at the same time, messages are sent to the new window. */
3370 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3371 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3372 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
3373 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3375 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
3376 expect_messages = exclusive_messages;
3377 screen_size.cx = 0;
3378 screen_size.cy = 0;
3379 screen_size2.cx = 0;
3380 screen_size2.cy = 0;
3382 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window2, DDSCL_NORMAL);
3383 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3385 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
3386 expect_messages = NULL;
3387 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n",
3388 screen_size.cx, screen_size.cy);
3389 ok(screen_size2.cx == registry_mode.dmPelsWidth && screen_size2.cy == registry_mode.dmPelsHeight,
3390 "Expected screen size 2 %ux%u, got %ux%u.\n",
3391 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight, screen_size2.cx, screen_size2.cy);
3393 GetWindowRect(window, &r);
3394 ok(EqualRect(&r, &ddraw_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect),
3395 wine_dbgstr_rect(&r));
3396 GetWindowRect(window2, &r);
3397 ok(EqualRect(&r, &registry_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&registry_rect),
3398 wine_dbgstr_rect(&r));
3400 memset(&ddsd, 0, sizeof(ddsd));
3401 ddsd.dwSize = sizeof(ddsd);
3402 ddsd.dwFlags = DDSD_CAPS;
3403 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3405 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
3406 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
3407 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
3408 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
3409 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
3410 registry_mode.dmPelsWidth, ddsd.dwWidth);
3411 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
3412 registry_mode.dmPelsHeight, ddsd.dwHeight);
3413 IDirectDrawSurface4_Release(primary);
3415 ref = IDirectDraw4_Release(ddraw);
3416 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3418 GetWindowRect(window, &r);
3419 ok(EqualRect(&r, &ddraw_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect),
3420 wine_dbgstr_rect(&r));
3422 expect_messages = NULL;
3423 DestroyWindow(window);
3424 DestroyWindow(window2);
3425 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL));
3426 UnregisterClassA("ddraw_test_wndproc_wc2", GetModuleHandleA(NULL));
3429 static void test_coop_level_mode_set_multi(void)
3431 IDirectDraw4 *ddraw1, *ddraw2;
3432 UINT w, h;
3433 HWND window;
3434 HRESULT hr;
3435 ULONG ref;
3437 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
3438 0, 0, 100, 100, 0, 0, 0, 0);
3439 ddraw1 = create_ddraw();
3440 ok(!!ddraw1, "Failed to create a ddraw object.\n");
3442 /* With just a single ddraw object, the display mode is restored on
3443 * release. */
3444 hr = set_display_mode(ddraw1, 800, 600);
3445 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3446 w = GetSystemMetrics(SM_CXSCREEN);
3447 ok(w == 800, "Got unexpected screen width %u.\n", w);
3448 h = GetSystemMetrics(SM_CYSCREEN);
3449 ok(h == 600, "Got unexpected screen height %u.\n", h);
3451 ref = IDirectDraw4_Release(ddraw1);
3452 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3453 w = GetSystemMetrics(SM_CXSCREEN);
3454 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3455 h = GetSystemMetrics(SM_CYSCREEN);
3456 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3458 /* When there are multiple ddraw objects, the display mode is restored to
3459 * the initial mode, before the first SetDisplayMode() call. */
3460 ddraw1 = create_ddraw();
3461 hr = set_display_mode(ddraw1, 800, 600);
3462 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3463 w = GetSystemMetrics(SM_CXSCREEN);
3464 ok(w == 800, "Got unexpected screen width %u.\n", w);
3465 h = GetSystemMetrics(SM_CYSCREEN);
3466 ok(h == 600, "Got unexpected screen height %u.\n", h);
3468 ddraw2 = create_ddraw();
3469 hr = set_display_mode(ddraw2, 640, 480);
3470 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3471 w = GetSystemMetrics(SM_CXSCREEN);
3472 ok(w == 640, "Got unexpected screen width %u.\n", w);
3473 h = GetSystemMetrics(SM_CYSCREEN);
3474 ok(h == 480, "Got unexpected screen height %u.\n", h);
3476 ref = IDirectDraw4_Release(ddraw2);
3477 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3478 w = GetSystemMetrics(SM_CXSCREEN);
3479 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3480 h = GetSystemMetrics(SM_CYSCREEN);
3481 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3483 ref = IDirectDraw4_Release(ddraw1);
3484 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3485 w = GetSystemMetrics(SM_CXSCREEN);
3486 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3487 h = GetSystemMetrics(SM_CYSCREEN);
3488 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3490 /* Regardless of release ordering. */
3491 ddraw1 = create_ddraw();
3492 hr = set_display_mode(ddraw1, 800, 600);
3493 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3494 w = GetSystemMetrics(SM_CXSCREEN);
3495 ok(w == 800, "Got unexpected screen width %u.\n", w);
3496 h = GetSystemMetrics(SM_CYSCREEN);
3497 ok(h == 600, "Got unexpected screen height %u.\n", h);
3499 ddraw2 = create_ddraw();
3500 hr = set_display_mode(ddraw2, 640, 480);
3501 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3502 w = GetSystemMetrics(SM_CXSCREEN);
3503 ok(w == 640, "Got unexpected screen width %u.\n", w);
3504 h = GetSystemMetrics(SM_CYSCREEN);
3505 ok(h == 480, "Got unexpected screen height %u.\n", h);
3507 ref = IDirectDraw4_Release(ddraw1);
3508 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3509 w = GetSystemMetrics(SM_CXSCREEN);
3510 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3511 h = GetSystemMetrics(SM_CYSCREEN);
3512 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3514 ref = IDirectDraw4_Release(ddraw2);
3515 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3516 w = GetSystemMetrics(SM_CXSCREEN);
3517 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3518 h = GetSystemMetrics(SM_CYSCREEN);
3519 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3521 /* But only for ddraw objects that called SetDisplayMode(). */
3522 ddraw1 = create_ddraw();
3523 ddraw2 = create_ddraw();
3524 hr = set_display_mode(ddraw2, 640, 480);
3525 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3526 w = GetSystemMetrics(SM_CXSCREEN);
3527 ok(w == 640, "Got unexpected screen width %u.\n", w);
3528 h = GetSystemMetrics(SM_CYSCREEN);
3529 ok(h == 480, "Got unexpected screen height %u.\n", h);
3531 ref = IDirectDraw4_Release(ddraw1);
3532 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3533 w = GetSystemMetrics(SM_CXSCREEN);
3534 ok(w == 640, "Got unexpected screen width %u.\n", w);
3535 h = GetSystemMetrics(SM_CYSCREEN);
3536 ok(h == 480, "Got unexpected screen height %u.\n", h);
3538 ref = IDirectDraw4_Release(ddraw2);
3539 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3540 w = GetSystemMetrics(SM_CXSCREEN);
3541 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3542 h = GetSystemMetrics(SM_CYSCREEN);
3543 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3545 /* If there's a ddraw object that's currently in exclusive mode, it blocks
3546 * restoring the display mode. */
3547 ddraw1 = create_ddraw();
3548 hr = set_display_mode(ddraw1, 800, 600);
3549 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3550 w = GetSystemMetrics(SM_CXSCREEN);
3551 ok(w == 800, "Got unexpected screen width %u.\n", w);
3552 h = GetSystemMetrics(SM_CYSCREEN);
3553 ok(h == 600, "Got unexpected screen height %u.\n", h);
3555 ddraw2 = create_ddraw();
3556 hr = set_display_mode(ddraw2, 640, 480);
3557 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3558 w = GetSystemMetrics(SM_CXSCREEN);
3559 ok(w == 640, "Got unexpected screen width %u.\n", w);
3560 h = GetSystemMetrics(SM_CYSCREEN);
3561 ok(h == 480, "Got unexpected screen height %u.\n", h);
3563 hr = IDirectDraw4_SetCooperativeLevel(ddraw2, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3564 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3566 ref = IDirectDraw4_Release(ddraw1);
3567 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3568 w = GetSystemMetrics(SM_CXSCREEN);
3569 ok(w == 640, "Got unexpected screen width %u.\n", w);
3570 h = GetSystemMetrics(SM_CYSCREEN);
3571 ok(h == 480, "Got unexpected screen height %u.\n", h);
3573 ref = IDirectDraw4_Release(ddraw2);
3574 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3575 w = GetSystemMetrics(SM_CXSCREEN);
3576 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3577 h = GetSystemMetrics(SM_CYSCREEN);
3578 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3580 /* Exclusive mode blocks mode setting on other ddraw objects in general. */
3581 ddraw1 = create_ddraw();
3582 hr = set_display_mode(ddraw1, 800, 600);
3583 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3584 w = GetSystemMetrics(SM_CXSCREEN);
3585 ok(w == 800, "Got unexpected screen width %u.\n", w);
3586 h = GetSystemMetrics(SM_CYSCREEN);
3587 ok(h == 600, "Got unexpected screen height %u.\n", h);
3589 hr = IDirectDraw4_SetCooperativeLevel(ddraw1, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3590 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3592 ddraw2 = create_ddraw();
3593 hr = set_display_mode(ddraw2, 640, 480);
3594 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
3596 ref = IDirectDraw4_Release(ddraw1);
3597 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3598 w = GetSystemMetrics(SM_CXSCREEN);
3599 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3600 h = GetSystemMetrics(SM_CYSCREEN);
3601 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3603 ref = IDirectDraw4_Release(ddraw2);
3604 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3605 w = GetSystemMetrics(SM_CXSCREEN);
3606 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3607 h = GetSystemMetrics(SM_CYSCREEN);
3608 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3610 DestroyWindow(window);
3613 static void test_initialize(void)
3615 IDirectDraw4 *ddraw;
3616 HRESULT hr;
3618 ddraw = create_ddraw();
3619 ok(!!ddraw, "Failed to create a ddraw object.\n");
3621 hr = IDirectDraw4_Initialize(ddraw, NULL);
3622 ok(hr == DDERR_ALREADYINITIALIZED, "Initialize returned hr %#x.\n", hr);
3623 IDirectDraw4_Release(ddraw);
3625 CoInitialize(NULL);
3626 hr = CoCreateInstance(&CLSID_DirectDraw, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectDraw4, (void **)&ddraw);
3627 ok(SUCCEEDED(hr), "Failed to create IDirectDraw4 instance, hr %#x.\n", hr);
3628 hr = IDirectDraw4_Initialize(ddraw, NULL);
3629 ok(hr == DD_OK, "Initialize returned hr %#x, expected DD_OK.\n", hr);
3630 hr = IDirectDraw4_Initialize(ddraw, NULL);
3631 ok(hr == DDERR_ALREADYINITIALIZED, "Initialize returned hr %#x, expected DDERR_ALREADYINITIALIZED.\n", hr);
3632 IDirectDraw4_Release(ddraw);
3633 CoUninitialize();
3636 static void test_coop_level_surf_create(void)
3638 IDirectDrawSurface4 *surface;
3639 IDirectDraw4 *ddraw;
3640 DDSURFACEDESC2 ddsd;
3641 HRESULT hr;
3643 ddraw = create_ddraw();
3644 ok(!!ddraw, "Failed to create a ddraw object.\n");
3646 memset(&ddsd, 0, sizeof(ddsd));
3647 ddsd.dwSize = sizeof(ddsd);
3648 ddsd.dwFlags = DDSD_CAPS;
3649 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3650 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
3651 ok(hr == DDERR_NOCOOPERATIVELEVELSET, "Surface creation returned hr %#x.\n", hr);
3653 IDirectDraw4_Release(ddraw);
3656 static void test_vb_discard(void)
3658 static const struct vec4 quad[] =
3660 { 0.0f, 480.0f, 0.0f, 1.0f},
3661 { 0.0f, 0.0f, 0.0f, 1.0f},
3662 {640.0f, 480.0f, 0.0f, 1.0f},
3663 {640.0f, 0.0f, 0.0f, 1.0f},
3666 IDirect3DDevice3 *device;
3667 IDirect3D3 *d3d;
3668 IDirect3DVertexBuffer *buffer;
3669 HWND window;
3670 HRESULT hr;
3671 D3DVERTEXBUFFERDESC desc;
3672 BYTE *data;
3673 static const unsigned int vbsize = 16;
3674 unsigned int i;
3676 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
3677 0, 0, 640, 480, 0, 0, 0, 0);
3679 if (!(device = create_device(window, DDSCL_NORMAL)))
3681 skip("Failed to create a 3D device, skipping test.\n");
3682 DestroyWindow(window);
3683 return;
3686 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
3687 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
3689 memset(&desc, 0, sizeof(desc));
3690 desc.dwSize = sizeof(desc);
3691 desc.dwCaps = D3DVBCAPS_WRITEONLY;
3692 desc.dwFVF = D3DFVF_XYZRHW;
3693 desc.dwNumVertices = vbsize;
3694 hr = IDirect3D3_CreateVertexBuffer(d3d, &desc, &buffer, 0, NULL);
3695 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
3697 hr = IDirect3DVertexBuffer_Lock(buffer, DDLOCK_DISCARDCONTENTS, (void **)&data, NULL);
3698 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
3699 memcpy(data, quad, sizeof(quad));
3700 hr = IDirect3DVertexBuffer_Unlock(buffer);
3701 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
3703 hr = IDirect3DDevice3_BeginScene(device);
3704 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
3705 hr = IDirect3DDevice3_DrawPrimitiveVB(device, D3DPT_TRIANGLESTRIP, buffer, 0, 4, 0);
3706 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3707 hr = IDirect3DDevice3_EndScene(device);
3708 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
3710 hr = IDirect3DVertexBuffer_Lock(buffer, DDLOCK_DISCARDCONTENTS, (void **)&data, NULL);
3711 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
3712 memset(data, 0xaa, sizeof(struct vec4) * vbsize);
3713 hr = IDirect3DVertexBuffer_Unlock(buffer);
3714 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
3716 hr = IDirect3DVertexBuffer_Lock(buffer, DDLOCK_DISCARDCONTENTS, (void **)&data, NULL);
3717 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
3718 for (i = 0; i < sizeof(struct vec4) * vbsize; i++)
3720 if (data[i] != 0xaa)
3722 ok(FALSE, "Vertex buffer data byte %u is 0x%02x, expected 0xaa\n", i, data[i]);
3723 break;
3726 hr = IDirect3DVertexBuffer_Unlock(buffer);
3727 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
3729 IDirect3DVertexBuffer_Release(buffer);
3730 IDirect3D3_Release(d3d);
3731 IDirect3DDevice3_Release(device);
3732 DestroyWindow(window);
3735 static void test_coop_level_multi_window(void)
3737 HWND window1, window2;
3738 IDirectDraw4 *ddraw;
3739 HRESULT hr;
3741 window1 = CreateWindowA("static", "ddraw_test1", WS_OVERLAPPEDWINDOW,
3742 0, 0, 640, 480, 0, 0, 0, 0);
3743 window2 = CreateWindowA("static", "ddraw_test2", WS_OVERLAPPEDWINDOW,
3744 0, 0, 640, 480, 0, 0, 0, 0);
3745 ddraw = create_ddraw();
3746 ok(!!ddraw, "Failed to create a ddraw object.\n");
3748 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window1, DDSCL_NORMAL);
3749 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3750 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window2, DDSCL_NORMAL);
3751 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3752 ok(IsWindow(window1), "Window 1 was destroyed.\n");
3753 ok(IsWindow(window2), "Window 2 was destroyed.\n");
3755 IDirectDraw4_Release(ddraw);
3756 DestroyWindow(window2);
3757 DestroyWindow(window1);
3760 static void test_draw_strided(void)
3762 static struct vec3 position[] =
3764 {-1.0, -1.0, 0.0},
3765 {-1.0, 1.0, 0.0},
3766 { 1.0, 1.0, 0.0},
3767 { 1.0, -1.0, 0.0},
3769 static DWORD diffuse[] =
3771 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00,
3773 static WORD indices[] =
3775 0, 1, 2, 2, 3, 0
3778 IDirectDrawSurface4 *rt;
3779 IDirect3DDevice3 *device;
3780 D3DCOLOR color;
3781 HWND window;
3782 HRESULT hr;
3783 D3DDRAWPRIMITIVESTRIDEDDATA strided;
3784 IDirect3DViewport3 *viewport;
3785 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
3787 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
3788 0, 0, 640, 480, 0, 0, 0, 0);
3790 if (!(device = create_device(window, DDSCL_NORMAL)))
3792 skip("Failed to create a 3D device, skipping test.\n");
3793 DestroyWindow(window);
3794 return;
3797 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
3798 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
3799 viewport = create_viewport(device, 0, 0, 640, 480);
3800 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
3801 ok(SUCCEEDED(hr), "Failed to activate the viewport, hr %#x.\n", hr);
3802 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0x00000000, 0.0f, 0);
3803 ok(SUCCEEDED(hr), "Failed to clear the viewport, hr %#x.\n", hr);
3805 hr = IDirect3DDevice3_BeginScene(device);
3806 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
3808 memset(&strided, 0x55, sizeof(strided));
3809 strided.position.lpvData = position;
3810 strided.position.dwStride = sizeof(*position);
3811 strided.diffuse.lpvData = diffuse;
3812 strided.diffuse.dwStride = sizeof(*diffuse);
3813 hr = IDirect3DDevice3_DrawIndexedPrimitiveStrided(device, D3DPT_TRIANGLELIST, D3DFVF_XYZ | D3DFVF_DIFFUSE,
3814 &strided, 4, indices, 6, 0);
3815 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3817 hr = IDirect3DDevice3_EndScene(device);
3818 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
3820 color = get_surface_color(rt, 320, 240);
3821 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
3823 IDirect3DViewport3_Release(viewport);
3824 IDirectDrawSurface4_Release(rt);
3825 IDirect3DDevice3_Release(device);
3826 DestroyWindow(window);
3829 static void test_lighting(void)
3831 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
3832 static D3DMATRIX mat =
3834 1.0f, 0.0f, 0.0f, 0.0f,
3835 0.0f, 1.0f, 0.0f, 0.0f,
3836 0.0f, 0.0f, 1.0f, 0.0f,
3837 0.0f, 0.0f, 0.0f, 1.0f,
3839 mat_singular =
3841 1.0f, 0.0f, 1.0f, 0.0f,
3842 0.0f, 1.0f, 0.0f, 0.0f,
3843 1.0f, 0.0f, 1.0f, 0.0f,
3844 0.0f, 0.0f, 0.5f, 1.0f,
3846 mat_transf =
3848 0.0f, 0.0f, 1.0f, 0.0f,
3849 0.0f, 1.0f, 0.0f, 0.0f,
3850 -1.0f, 0.0f, 0.0f, 0.0f,
3851 10.f, 10.0f, 10.0f, 1.0f,
3853 mat_nonaffine =
3855 1.0f, 0.0f, 0.0f, 0.0f,
3856 0.0f, 1.0f, 0.0f, 0.0f,
3857 0.0f, 0.0f, 1.0f, -1.0f,
3858 10.f, 10.0f, 10.0f, 0.0f,
3860 static struct
3862 struct vec3 position;
3863 DWORD diffuse;
3865 unlitquad[] =
3867 {{-1.0f, -1.0f, 0.1f}, 0xffff0000},
3868 {{-1.0f, 0.0f, 0.1f}, 0xffff0000},
3869 {{ 0.0f, 0.0f, 0.1f}, 0xffff0000},
3870 {{ 0.0f, -1.0f, 0.1f}, 0xffff0000},
3872 litquad[] =
3874 {{-1.0f, 0.0f, 0.1f}, 0xff00ff00},
3875 {{-1.0f, 1.0f, 0.1f}, 0xff00ff00},
3876 {{ 0.0f, 1.0f, 0.1f}, 0xff00ff00},
3877 {{ 0.0f, 0.0f, 0.1f}, 0xff00ff00},
3879 static struct
3881 struct vec3 position;
3882 struct vec3 normal;
3883 DWORD diffuse;
3885 unlitnquad[] =
3887 {{0.0f, -1.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xff0000ff},
3888 {{0.0f, 0.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xff0000ff},
3889 {{1.0f, 0.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xff0000ff},
3890 {{1.0f, -1.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xff0000ff},
3892 litnquad[] =
3894 {{0.0f, 0.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xffffff00},
3895 {{0.0f, 1.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xffffff00},
3896 {{1.0f, 1.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xffffff00},
3897 {{1.0f, 0.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xffffff00},
3899 nquad[] =
3901 {{-1.0f, -1.0f, 0.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
3902 {{-1.0f, 1.0f, 0.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
3903 {{ 1.0f, 1.0f, 0.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
3904 {{ 1.0f, -1.0f, 0.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
3906 rotatedquad[] =
3908 {{-10.0f, -11.0f, 11.0f}, {-1.0f, 0.0f, 0.0f}, 0xff0000ff},
3909 {{-10.0f, -9.0f, 11.0f}, {-1.0f, 0.0f, 0.0f}, 0xff0000ff},
3910 {{-10.0f, -9.0f, 9.0f}, {-1.0f, 0.0f, 0.0f}, 0xff0000ff},
3911 {{-10.0f, -11.0f, 9.0f}, {-1.0f, 0.0f, 0.0f}, 0xff0000ff},
3913 translatedquad[] =
3915 {{-11.0f, -11.0f, -10.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
3916 {{-11.0f, -9.0f, -10.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
3917 {{ -9.0f, -9.0f, -10.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
3918 {{ -9.0f, -11.0f, -10.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
3920 static WORD indices[] = {0, 1, 2, 2, 3, 0};
3921 static const struct
3923 D3DMATRIX *world_matrix;
3924 void *quad;
3925 DWORD expected;
3926 const char *message;
3928 tests[] =
3930 {&mat, nquad, 0x000000ff, "Lit quad with light"},
3931 {&mat_singular, nquad, 0x000000b4, "Lit quad with singular world matrix"},
3932 {&mat_transf, rotatedquad, 0x000000ff, "Lit quad with transformation matrix"},
3933 {&mat_nonaffine, translatedquad, 0x000000ff, "Lit quad with non-affine matrix"},
3936 HWND window;
3937 IDirect3D3 *d3d;
3938 IDirect3DDevice3 *device;
3939 IDirectDrawSurface4 *rt;
3940 IDirect3DViewport3 *viewport;
3941 IDirect3DMaterial3 *material;
3942 IDirect3DLight *light;
3943 D3DMATERIALHANDLE mat_handle;
3944 D3DLIGHT2 light_desc;
3945 HRESULT hr;
3946 DWORD fvf = D3DFVF_XYZ | D3DFVF_DIFFUSE;
3947 DWORD nfvf = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_NORMAL;
3948 D3DCOLOR color;
3949 ULONG refcount;
3950 unsigned int i;
3952 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
3953 0, 0, 640, 480, 0, 0, 0, 0);
3954 if (!(device = create_device(window, DDSCL_NORMAL)))
3956 skip("Failed to create a 3D device, skipping test.\n");
3957 DestroyWindow(window);
3958 return;
3961 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
3962 ok(SUCCEEDED(hr), "Failed to get D3D interface, hr %#x.\n", hr);
3964 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
3965 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
3967 viewport = create_viewport(device, 0, 0, 640, 480);
3968 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
3969 ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr);
3971 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xffffffff, 0.0f, 0);
3972 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
3974 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &mat);
3975 ok(SUCCEEDED(hr), "Failed to set world transformation, hr %#x.\n", hr);
3976 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_VIEW, &mat);
3977 ok(SUCCEEDED(hr), "Failed to set view transformation, hr %#x.\n", hr);
3978 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &mat);
3979 ok(SUCCEEDED(hr), "Failed to set projection transformation, hr %#x.\n", hr);
3980 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_CLIPPING, FALSE);
3981 ok(SUCCEEDED(hr), "Failed to disable clipping, hr %#x.\n", hr);
3982 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ZENABLE, FALSE);
3983 ok(SUCCEEDED(hr), "Failed to disable zbuffer, hr %#x.\n", hr);
3984 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, FALSE);
3985 ok(SUCCEEDED(hr), "Failed to disable fog, hr %#x.\n", hr);
3986 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_STENCILENABLE, FALSE);
3987 ok(SUCCEEDED(hr), "Failed to disable stencil buffer, hr %#x.\n", hr);
3988 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_CULLMODE, D3DCULL_NONE);
3989 ok(SUCCEEDED(hr), "Failed to disable culling, hr %#x.\n", hr);
3991 hr = IDirect3DDevice3_BeginScene(device);
3992 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
3994 /* There is no D3DRENDERSTATE_LIGHTING on ddraw < 7. */
3995 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
3996 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
3997 hr = IDirect3DDevice3_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, fvf, unlitquad, 4,
3998 indices, 6, 0);
3999 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
4001 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_LIGHTING, TRUE);
4002 ok(SUCCEEDED(hr), "Failed to enable lighting, hr %#x.\n", hr);
4003 hr = IDirect3DDevice3_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, fvf, litquad, 4,
4004 indices, 6, 0);
4005 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
4007 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
4008 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
4009 hr = IDirect3DDevice3_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, nfvf, unlitnquad, 4,
4010 indices, 6, 0);
4011 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
4013 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_LIGHTING, TRUE);
4014 ok(SUCCEEDED(hr), "Failed to enable lighting, hr %#x.\n", hr);
4015 hr = IDirect3DDevice3_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, nfvf, litnquad, 4,
4016 indices, 6, 0);
4017 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
4019 hr = IDirect3DDevice3_EndScene(device);
4020 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
4022 color = get_surface_color(rt, 160, 360);
4023 ok(color == 0x00ff0000, "Unlit quad without normals has color 0x%08x.\n", color);
4024 color = get_surface_color(rt, 160, 120);
4025 ok(color == 0x0000ff00, "Lit quad without normals has color 0x%08x.\n", color);
4026 color = get_surface_color(rt, 480, 360);
4027 ok(color == 0x000000ff, "Unlit quad with normals has color 0x%08x.\n", color);
4028 color = get_surface_color(rt, 480, 120);
4029 ok(color == 0x00ffff00, "Lit quad with normals has color 0x%08x.\n", color);
4031 material = create_diffuse_material(device, 0.0f, 1.0f, 0.0f, 0.0f);
4032 hr = IDirect3DMaterial3_GetHandle(material, device, &mat_handle);
4033 ok(SUCCEEDED(hr), "Failed to set material state, hr %#x.\n", hr);
4034 hr = IDirect3DDevice3_SetLightState(device, D3DLIGHTSTATE_MATERIAL, mat_handle);
4035 ok(SUCCEEDED(hr), "Failed to set material state, hr %#x.\n", hr);
4037 hr = IDirect3D3_CreateLight(d3d, &light, NULL);
4038 ok(SUCCEEDED(hr), "Failed to create a light object, hr %#x.\n", hr);
4039 memset(&light_desc, 0, sizeof(light_desc));
4040 light_desc.dwSize = sizeof(light_desc);
4041 light_desc.dltType = D3DLIGHT_DIRECTIONAL;
4042 U1(light_desc.dcvColor).r = 1.0f;
4043 U2(light_desc.dcvColor).g = 1.0f;
4044 U3(light_desc.dcvColor).b = 1.0f;
4045 U4(light_desc.dcvColor).a = 1.0f;
4046 U3(light_desc.dvDirection).z = 1.0f;
4047 hr = IDirect3DLight_SetLight(light, (D3DLIGHT *)&light_desc);
4048 ok(SUCCEEDED(hr), "Failed to set light, hr %#x.\n", hr);
4049 hr = IDirect3DViewport3_AddLight(viewport, light);
4050 ok(SUCCEEDED(hr), "Failed to add a light to the viewport, hr %#x.\n", hr);
4052 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xffffffff, 0.0f, 0);
4053 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
4055 hr = IDirect3DDevice3_BeginScene(device);
4056 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
4058 hr = IDirect3DDevice3_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, nfvf, nquad,
4059 4, indices, 6, 0);
4060 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
4062 hr = IDirect3DDevice3_EndScene(device);
4063 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
4065 color = get_surface_color(rt, 320, 240);
4066 ok(color == 0x00000000, "Lit quad with no light has color 0x%08x.\n", color);
4068 light_desc.dwFlags = D3DLIGHT_ACTIVE;
4069 hr = IDirect3DLight_SetLight(light, (D3DLIGHT *)&light_desc);
4070 ok(SUCCEEDED(hr), "Failed to set light, hr %#x.\n", hr);
4072 for (i = 0; i < sizeof(tests) / sizeof(tests[0]); ++i)
4074 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_WORLD, tests[i].world_matrix);
4075 ok(SUCCEEDED(hr), "Failed to set world transformation, hr %#x.\n", hr);
4077 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xffffffff, 0.0f, 0);
4078 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
4080 hr = IDirect3DDevice3_BeginScene(device);
4081 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
4083 hr = IDirect3DDevice3_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, nfvf, tests[i].quad,
4084 4, indices, 6, 0);
4085 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
4087 hr = IDirect3DDevice3_EndScene(device);
4088 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
4090 color = get_surface_color(rt, 320, 240);
4091 ok(color == tests[i].expected, "%s has color 0x%08x.\n", tests[i].message, color);
4094 hr = IDirect3DViewport3_DeleteLight(viewport, light);
4095 ok(SUCCEEDED(hr), "Failed to remove a light from the viewport, hr %#x.\n", hr);
4096 IDirect3DLight_Release(light);
4097 destroy_material(material);
4098 IDirect3DViewport3_Release(viewport);
4099 IDirectDrawSurface4_Release(rt);
4100 refcount = IDirect3DDevice3_Release(device);
4101 ok(!refcount, "Device has %u references left.\n", refcount);
4102 IDirect3D3_Release(d3d);
4103 DestroyWindow(window);
4106 static void test_specular_lighting(void)
4108 static const unsigned int vertices_side = 5;
4109 const unsigned int indices_count = (vertices_side - 1) * (vertices_side - 1) * 2 * 3;
4110 static const DWORD fvf = D3DFVF_XYZ | D3DFVF_NORMAL;
4111 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
4112 static D3DMATRIX mat =
4114 1.0f, 0.0f, 0.0f, 0.0f,
4115 0.0f, 1.0f, 0.0f, 0.0f,
4116 0.0f, 0.0f, 1.0f, 0.0f,
4117 0.0f, 0.0f, 0.0f, 1.0f,
4119 static D3DLIGHT2 directional =
4121 sizeof(D3DLIGHT2),
4122 D3DLIGHT_DIRECTIONAL,
4123 {{1.0f}, {1.0f}, {1.0f}, {0.0f}},
4124 {{0.0f}, {0.0f}, {0.0f}},
4125 {{0.0f}, {0.0f}, {1.0f}},
4127 point =
4129 sizeof(D3DLIGHT2),
4130 D3DLIGHT_POINT,
4131 {{1.0f}, {1.0f}, {1.0f}, {0.0f}},
4132 {{0.0f}, {0.0f}, {0.0f}},
4133 {{0.0f}, {0.0f}, {0.0f}},
4134 100.0f,
4135 0.0f,
4136 0.0f, 0.0f, 1.0f,
4138 spot =
4140 sizeof(D3DLIGHT2),
4141 D3DLIGHT_SPOT,
4142 {{1.0f}, {1.0f}, {1.0f}, {0.0f}},
4143 {{0.0f}, {0.0f}, {0.0f}},
4144 {{0.0f}, {0.0f}, {1.0f}},
4145 100.0f,
4146 1.0f,
4147 0.0f, 0.0f, 1.0f,
4148 M_PI / 12.0f, M_PI / 3.0f
4150 parallelpoint =
4152 sizeof(D3DLIGHT2),
4153 D3DLIGHT_PARALLELPOINT,
4154 {{1.0f}, {1.0f}, {1.0f}, {0.0f}},
4155 {{0.5f}, {0.0f}, {-1.0f}},
4156 {{0.0f}, {0.0f}, {0.0f}},
4158 static const struct expected_color
4160 unsigned int x, y;
4161 D3DCOLOR color;
4163 expected_directional[] =
4165 {160, 120, 0x003c3c3c},
4166 {320, 120, 0x00717171},
4167 {480, 120, 0x003c3c3c},
4168 {160, 240, 0x00717171},
4169 {320, 240, 0x00ffffff},
4170 {480, 240, 0x00717171},
4171 {160, 360, 0x003c3c3c},
4172 {320, 360, 0x00717171},
4173 {480, 360, 0x003c3c3c},
4175 expected_point[] =
4177 {160, 120, 0x00000000},
4178 {320, 120, 0x00090909},
4179 {480, 120, 0x00000000},
4180 {160, 240, 0x00090909},
4181 {320, 240, 0x00fafafa},
4182 {480, 240, 0x00090909},
4183 {160, 360, 0x00000000},
4184 {320, 360, 0x00090909},
4185 {480, 360, 0x00000000},
4187 expected_spot[] =
4189 {160, 120, 0x00000000},
4190 {320, 120, 0x00020202},
4191 {480, 120, 0x00000000},
4192 {160, 240, 0x00020202},
4193 {320, 240, 0x00fafafa},
4194 {480, 240, 0x00020202},
4195 {160, 360, 0x00000000},
4196 {320, 360, 0x00020202},
4197 {480, 360, 0x00000000},
4199 expected_parallelpoint[] =
4201 {160, 120, 0x00050505},
4202 {320, 120, 0x002c2c2c},
4203 {480, 120, 0x006e6e6e},
4204 {160, 240, 0x00090909},
4205 {320, 240, 0x00717171},
4206 {480, 240, 0x00ffffff},
4207 {160, 360, 0x00050505},
4208 {320, 360, 0x002c2c2c},
4209 {480, 360, 0x006e6e6e},
4211 static const struct
4213 D3DLIGHT2 *light;
4214 BOOL local_viewer;
4215 const struct expected_color *expected;
4216 unsigned int expected_count;
4218 tests[] =
4220 /* D3DRENDERSTATE_LOCALVIEWER does not exist in D3D < 7 (the behavior is
4221 * the one you get on newer D3D versions with it set as TRUE). */
4222 {&directional, FALSE, expected_directional,
4223 sizeof(expected_directional) / sizeof(expected_directional[0])},
4224 {&directional, TRUE, expected_directional,
4225 sizeof(expected_directional) / sizeof(expected_directional[0])},
4226 {&point, TRUE, expected_point,
4227 sizeof(expected_point) / sizeof(expected_point[0])},
4228 {&spot, TRUE, expected_spot,
4229 sizeof(expected_spot) / sizeof(expected_spot[0])},
4230 {&parallelpoint, TRUE, expected_parallelpoint,
4231 sizeof(expected_parallelpoint) / sizeof(expected_parallelpoint[0])},
4233 IDirect3D3 *d3d;
4234 IDirect3DDevice3 *device;
4235 IDirectDrawSurface4 *rt;
4236 IDirect3DViewport3 *viewport;
4237 IDirect3DMaterial3 *material;
4238 IDirect3DLight *light;
4239 D3DMATERIALHANDLE mat_handle;
4240 D3DCOLOR color;
4241 ULONG refcount;
4242 HWND window;
4243 HRESULT hr;
4244 unsigned int i, j, x, y;
4245 struct
4247 struct vec3 position;
4248 struct vec3 normal;
4249 } *quad;
4250 WORD *indices;
4252 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
4253 0, 0, 640, 480, 0, 0, 0, 0);
4254 if (!(device = create_device(window, DDSCL_NORMAL)))
4256 skip("Failed to create a 3D device, skipping test.\n");
4257 DestroyWindow(window);
4258 return;
4261 quad = HeapAlloc(GetProcessHeap(), 0, vertices_side * vertices_side * sizeof(*quad));
4262 indices = HeapAlloc(GetProcessHeap(), 0, indices_count * sizeof(*indices));
4263 for (i = 0, y = 0; y < vertices_side; ++y)
4265 for (x = 0; x < vertices_side; ++x)
4267 quad[i].position.x = x * 2.0f / (vertices_side - 1) - 1.0f;
4268 quad[i].position.y = y * 2.0f / (vertices_side - 1) - 1.0f;
4269 quad[i].position.z = 1.0f;
4270 quad[i].normal.x = 0.0f;
4271 quad[i].normal.y = 0.0f;
4272 quad[i++].normal.z = -1.0f;
4275 for (i = 0, y = 0; y < (vertices_side - 1); ++y)
4277 for (x = 0; x < (vertices_side - 1); ++x)
4279 indices[i++] = y * vertices_side + x + 1;
4280 indices[i++] = y * vertices_side + x;
4281 indices[i++] = (y + 1) * vertices_side + x;
4282 indices[i++] = y * vertices_side + x + 1;
4283 indices[i++] = (y + 1) * vertices_side + x;
4284 indices[i++] = (y + 1) * vertices_side + x + 1;
4288 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
4289 ok(SUCCEEDED(hr), "Failed to get D3D interface, hr %#x.\n", hr);
4291 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
4292 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
4294 viewport = create_viewport(device, 0, 0, 640, 480);
4295 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
4296 ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr);
4298 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &mat);
4299 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#x.\n", hr);
4300 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_VIEW, &mat);
4301 ok(SUCCEEDED(hr), "Failed to set view transform, hr %#x.\n", hr);
4302 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &mat);
4303 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
4304 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_CLIPPING, FALSE);
4305 ok(SUCCEEDED(hr), "Failed to disable clipping, hr %#x.\n", hr);
4306 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ZENABLE, FALSE);
4307 ok(SUCCEEDED(hr), "Failed to disable z-buffering, hr %#x.\n", hr);
4308 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, FALSE);
4309 ok(SUCCEEDED(hr), "Failed to disable fog, hr %#x.\n", hr);
4311 material = create_specular_material(device, 1.0f, 1.0f, 1.0f, 1.0f, 30.0f);
4312 hr = IDirect3DMaterial3_GetHandle(material, device, &mat_handle);
4313 ok(SUCCEEDED(hr), "Failed to get material handle, hr %#x.\n", hr);
4314 hr = IDirect3DDevice3_SetLightState(device, D3DLIGHTSTATE_MATERIAL, mat_handle);
4315 ok(SUCCEEDED(hr), "Failed to set material state, hr %#x.\n", hr);
4317 hr = IDirect3D3_CreateLight(d3d, &light, NULL);
4318 ok(SUCCEEDED(hr), "Failed to create a light object, hr %#x.\n", hr);
4319 hr = IDirect3DViewport3_AddLight(viewport, light);
4320 ok(SUCCEEDED(hr), "Failed to add a light to the viewport, hr %#x.\n", hr);
4322 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_SPECULARENABLE, TRUE);
4323 ok(SUCCEEDED(hr), "Failed to enable specular lighting, hr %#x.\n", hr);
4325 for (i = 0; i < sizeof(tests) / sizeof(tests[0]); ++i)
4327 tests[i].light->dwFlags = D3DLIGHT_ACTIVE;
4328 hr = IDirect3DLight_SetLight(light, (D3DLIGHT *)tests[i].light);
4329 ok(SUCCEEDED(hr), "Failed to set light, hr %#x.\n", hr);
4331 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_LOCALVIEWER, tests[i].local_viewer);
4332 ok(SUCCEEDED(hr), "Failed to set local viewer state, hr %#x.\n", hr);
4334 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xffffffff, 0.0f, 0);
4335 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
4337 hr = IDirect3DDevice3_BeginScene(device);
4338 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
4340 hr = IDirect3DDevice3_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, fvf, quad,
4341 vertices_side * vertices_side, indices, indices_count, 0);
4342 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
4344 hr = IDirect3DDevice3_EndScene(device);
4345 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
4347 for (j = 0; j < tests[i].expected_count; ++j)
4349 color = get_surface_color(rt, tests[i].expected[j].x, tests[i].expected[j].y);
4350 ok(compare_color(color, tests[i].expected[j].color, 1),
4351 "Expected color 0x%08x at location (%u, %u), got 0x%08x, case %u.\n",
4352 tests[i].expected[j].color, tests[i].expected[j].x,
4353 tests[i].expected[j].y, color, i);
4357 hr = IDirect3DViewport3_DeleteLight(viewport, light);
4358 ok(SUCCEEDED(hr), "Failed to remove a light from the viewport, hr %#x.\n", hr);
4359 IDirect3DLight_Release(light);
4360 destroy_material(material);
4361 IDirect3DViewport3_Release(viewport);
4362 IDirectDrawSurface4_Release(rt);
4363 refcount = IDirect3DDevice3_Release(device);
4364 ok(!refcount, "Device has %u references left.\n", refcount);
4365 IDirect3D3_Release(d3d);
4366 DestroyWindow(window);
4367 HeapFree(GetProcessHeap(), 0, indices);
4368 HeapFree(GetProcessHeap(), 0, quad);
4371 static void test_clear_rect_count(void)
4373 IDirectDrawSurface4 *rt;
4374 IDirect3DDevice3 *device;
4375 D3DCOLOR color;
4376 HWND window;
4377 HRESULT hr;
4378 IDirect3DViewport3 *viewport;
4379 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
4381 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
4382 0, 0, 640, 480, 0, 0, 0, 0);
4383 if (!(device = create_device(window, DDSCL_NORMAL)))
4385 skip("Failed to create a 3D device, skipping test.\n");
4386 DestroyWindow(window);
4387 return;
4390 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
4391 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
4393 viewport = create_viewport(device, 0, 0, 640, 480);
4394 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
4395 ok(SUCCEEDED(hr), "Failed to activate the viewport, hr %#x.\n", hr);
4396 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0x00ffffff, 0.0f, 0);
4397 ok(SUCCEEDED(hr), "Failed to clear the viewport, hr %#x.\n", hr);
4398 hr = IDirect3DViewport3_Clear2(viewport, 0, &clear_rect, D3DCLEAR_TARGET, 0x00ff0000, 0.0f, 0);
4399 ok(SUCCEEDED(hr), "Failed to clear the viewport, hr %#x.\n", hr);
4400 hr = IDirect3DViewport3_Clear2(viewport, 0, NULL, D3DCLEAR_TARGET, 0x0000ff00, 0.0f, 0);
4401 ok(SUCCEEDED(hr), "Failed to clear the viewport, hr %#x.\n", hr);
4402 hr = IDirect3DViewport3_Clear2(viewport, 1, NULL, D3DCLEAR_TARGET, 0x000000ff, 0.0f, 0);
4403 ok(SUCCEEDED(hr), "Failed to clear the viewport, hr %#x.\n", hr);
4405 color = get_surface_color(rt, 320, 240);
4406 ok(compare_color(color, 0x00ffffff, 1) || broken(compare_color(color, 0x000000ff, 1)),
4407 "Got unexpected color 0x%08x.\n", color);
4409 IDirect3DViewport3_Release(viewport);
4410 IDirectDrawSurface4_Release(rt);
4411 IDirect3DDevice3_Release(device);
4412 DestroyWindow(window);
4415 static BOOL test_mode_restored(IDirectDraw4 *ddraw, HWND window)
4417 DDSURFACEDESC2 ddsd1, ddsd2;
4418 HRESULT hr;
4420 memset(&ddsd1, 0, sizeof(ddsd1));
4421 ddsd1.dwSize = sizeof(ddsd1);
4422 hr = IDirectDraw4_GetDisplayMode(ddraw, &ddsd1);
4423 ok(SUCCEEDED(hr), "GetDisplayMode failed, hr %#x.\n", hr);
4425 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
4426 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
4427 hr = set_display_mode(ddraw, 640, 480);
4428 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
4429 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
4430 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
4432 memset(&ddsd2, 0, sizeof(ddsd2));
4433 ddsd2.dwSize = sizeof(ddsd2);
4434 hr = IDirectDraw4_GetDisplayMode(ddraw, &ddsd2);
4435 ok(SUCCEEDED(hr), "GetDisplayMode failed, hr %#x.\n", hr);
4436 hr = IDirectDraw4_RestoreDisplayMode(ddraw);
4437 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
4439 return ddsd1.dwWidth == ddsd2.dwWidth && ddsd1.dwHeight == ddsd2.dwHeight;
4442 static void test_coop_level_versions(void)
4444 HWND window;
4445 IDirectDraw *ddraw;
4446 HRESULT hr;
4447 BOOL restored;
4448 IDirectDrawSurface *surface;
4449 IDirectDraw4 *ddraw4;
4450 DDSURFACEDESC ddsd;
4452 window = CreateWindowA("static", "ddraw_test1", WS_OVERLAPPEDWINDOW,
4453 0, 0, 640, 480, 0, 0, 0, 0);
4455 ddraw4 = create_ddraw();
4456 ok(!!ddraw4, "Failed to create a ddraw object.\n");
4457 /* Newly created ddraw objects restore the mode on ddraw2+::SetCooperativeLevel(NORMAL) */
4458 restored = test_mode_restored(ddraw4, window);
4459 ok(restored, "Display mode not restored in new ddraw object\n");
4461 /* A failing ddraw1::SetCooperativeLevel call does not have an effect */
4462 hr = IDirectDraw4_QueryInterface(ddraw4, &IID_IDirectDraw, (void **)&ddraw);
4463 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#x.\n", hr);
4465 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
4466 ok(FAILED(hr), "SetCooperativeLevel returned %#x, expected failure.\n", hr);
4467 restored = test_mode_restored(ddraw4, window);
4468 ok(restored, "Display mode not restored after bad ddraw1::SetCooperativeLevel call\n");
4470 /* A successful one does */
4471 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
4472 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
4473 restored = test_mode_restored(ddraw4, window);
4474 ok(!restored, "Display mode restored after good ddraw1::SetCooperativeLevel call\n");
4476 IDirectDraw_Release(ddraw);
4477 IDirectDraw4_Release(ddraw4);
4479 ddraw4 = create_ddraw();
4480 ok(!!ddraw4, "Failed to create a ddraw object.\n");
4481 hr = IDirectDraw4_QueryInterface(ddraw4, &IID_IDirectDraw, (void **)&ddraw);
4482 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#x.\n", hr);
4484 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_SETFOCUSWINDOW);
4485 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
4486 restored = test_mode_restored(ddraw4, window);
4487 ok(!restored, "Display mode restored after ddraw1::SetCooperativeLevel(SETFOCUSWINDOW) call\n");
4489 IDirectDraw_Release(ddraw);
4490 IDirectDraw4_Release(ddraw4);
4492 /* A failing call does not restore the ddraw2+ behavior */
4493 ddraw4 = create_ddraw();
4494 ok(!!ddraw4, "Failed to create a ddraw object.\n");
4495 hr = IDirectDraw4_QueryInterface(ddraw4, &IID_IDirectDraw, (void **)&ddraw);
4496 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#x.\n", hr);
4498 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
4499 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
4500 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
4501 ok(FAILED(hr), "SetCooperativeLevel returned %#x, expected failure.\n", hr);
4502 restored = test_mode_restored(ddraw4, window);
4503 ok(!restored, "Display mode restored after good-bad ddraw1::SetCooperativeLevel() call sequence\n");
4505 IDirectDraw_Release(ddraw);
4506 IDirectDraw4_Release(ddraw4);
4508 /* Neither does a sequence of successful calls with the new interface */
4509 ddraw4 = create_ddraw();
4510 ok(!!ddraw4, "Failed to create a ddraw object.\n");
4511 hr = IDirectDraw4_QueryInterface(ddraw4, &IID_IDirectDraw, (void **)&ddraw);
4512 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#x.\n", hr);
4514 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
4515 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
4516 hr = IDirectDraw4_SetCooperativeLevel(ddraw4, window, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
4517 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
4518 hr = IDirectDraw4_SetCooperativeLevel(ddraw4, window, DDSCL_NORMAL);
4519 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
4521 restored = test_mode_restored(ddraw4, window);
4522 ok(!restored, "Display mode restored after ddraw1-ddraw4 SetCooperativeLevel() call sequence\n");
4523 IDirectDraw_Release(ddraw);
4524 IDirectDraw4_Release(ddraw4);
4526 /* ddraw1::CreateSurface does not triger the ddraw1 behavior */
4527 ddraw4 = create_ddraw();
4528 ok(!!ddraw4, "Failed to create a ddraw object.\n");
4529 hr = IDirectDraw4_QueryInterface(ddraw4, &IID_IDirectDraw, (void **)&ddraw);
4530 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#x.\n", hr);
4532 hr = IDirectDraw4_SetCooperativeLevel(ddraw4, window, DDSCL_NORMAL);
4533 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
4535 memset(&ddsd, 0, sizeof(ddsd));
4536 ddsd.dwSize = sizeof(ddsd);
4537 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
4538 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
4539 ddsd.dwWidth = ddsd.dwHeight = 8;
4540 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &surface, NULL);
4541 ok(SUCCEEDED(hr), "CreateSurface failed, hr %#x.\n", hr);
4542 IDirectDrawSurface_Release(surface);
4543 restored = test_mode_restored(ddraw4, window);
4544 ok(restored, "Display mode not restored after ddraw1::CreateSurface() call\n");
4546 IDirectDraw_Release(ddraw);
4547 IDirectDraw4_Release(ddraw4);
4548 DestroyWindow(window);
4551 static void test_lighting_interface_versions(void)
4553 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
4554 IDirect3DMaterial3 *emissive;
4555 IDirect3DViewport3 *viewport;
4556 IDirect3DDevice3 *device;
4557 IDirectDrawSurface4 *rt;
4558 D3DCOLOR color;
4559 HWND window;
4560 HRESULT hr;
4561 D3DMATERIALHANDLE mat_handle;
4562 DWORD rs;
4563 unsigned int i;
4564 ULONG ref;
4565 static D3DVERTEX quad[] =
4567 {{-1.0f}, { 1.0f}, {0.0f}, {1.0f}, {0.0f}, {0.0f}},
4568 {{ 1.0f}, { 1.0f}, {0.0f}, {1.0f}, {0.0f}, {0.0f}},
4569 {{-1.0f}, {-1.0f}, {0.0f}, {1.0f}, {0.0f}, {0.0f}},
4570 {{ 1.0f}, {-1.0f}, {0.0f}, {1.0f}, {0.0f}, {0.0f}},
4573 #define FVF_COLORVERTEX (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE | D3DFVF_SPECULAR)
4574 static struct
4576 struct vec3 position;
4577 struct vec3 normal;
4578 DWORD diffuse, specular;
4580 quad2[] =
4582 {{-1.0f, 1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000, 0xff808080},
4583 {{ 1.0f, 1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000, 0xff808080},
4584 {{-1.0f, -1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000, 0xff808080},
4585 {{ 1.0f, -1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000, 0xff808080},
4588 static D3DLVERTEX lquad[] =
4590 {{-1.0f}, { 1.0f}, {0.0f}, 0, {0xffff0000}, {0xff808080}},
4591 {{ 1.0f}, { 1.0f}, {0.0f}, 0, {0xffff0000}, {0xff808080}},
4592 {{-1.0f}, {-1.0f}, {0.0f}, 0, {0xffff0000}, {0xff808080}},
4593 {{ 1.0f}, {-1.0f}, {0.0f}, 0, {0xffff0000}, {0xff808080}},
4596 #define FVF_LVERTEX2 (D3DFVF_LVERTEX & ~D3DFVF_RESERVED1)
4597 static struct
4599 struct vec3 position;
4600 DWORD diffuse, specular;
4601 struct vec2 texcoord;
4603 lquad2[] =
4605 {{-1.0f, 1.0f, 0.0f}, 0xffff0000, 0xff808080},
4606 {{ 1.0f, 1.0f, 0.0f}, 0xffff0000, 0xff808080},
4607 {{-1.0f, -1.0f, 0.0f}, 0xffff0000, 0xff808080},
4608 {{ 1.0f, -1.0f, 0.0f}, 0xffff0000, 0xff808080},
4611 static D3DTLVERTEX tlquad[] =
4613 {{ 0.0f}, { 480.0f}, {0.0f}, {1.0f}, {0xff0000ff}, {0xff808080}},
4614 {{ 0.0f}, { 0.0f}, {0.0f}, {1.0f}, {0xff0000ff}, {0xff808080}},
4615 {{ 640.0f}, { 480.0f}, {0.0f}, {1.0f}, {0xff0000ff}, {0xff808080}},
4616 {{ 640.0f}, { 0.0f}, {0.0f}, {1.0f}, {0xff0000ff}, {0xff808080}},
4619 static const struct
4621 DWORD vertextype;
4622 void *data;
4623 DWORD d3drs_lighting, d3drs_specular;
4624 DWORD draw_flags;
4625 D3DCOLOR color;
4627 tests[] =
4629 /* Lighting is enabled when all of these conditions are met:
4630 * 1) No pretransformed position(D3DFVF_XYZRHW)
4631 * 2) Normals are available (D3DFVF_NORMAL)
4632 * 3) D3DDP_DONOTLIGHT is not set.
4634 * D3DRENDERSTATE_LIGHTING is ignored, it is not defined
4635 * in this d3d version */
4637 /* 0 */
4638 { D3DFVF_VERTEX, quad, FALSE, FALSE, 0, 0x0000ff00},
4639 { D3DFVF_VERTEX, quad, TRUE, FALSE, 0, 0x0000ff00},
4640 { D3DFVF_VERTEX, quad, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x00ffffff},
4641 { D3DFVF_VERTEX, quad, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x00ffffff},
4642 { D3DFVF_VERTEX, quad, FALSE, TRUE, 0, 0x0000ff00},
4643 { D3DFVF_VERTEX, quad, TRUE, TRUE, 0, 0x0000ff00},
4644 { D3DFVF_VERTEX, quad, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x00ffffff},
4645 { D3DFVF_VERTEX, quad, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x00ffffff},
4647 /* 8 */
4648 { FVF_COLORVERTEX, quad2, FALSE, FALSE, 0, 0x0000ff00},
4649 { FVF_COLORVERTEX, quad2, TRUE, FALSE, 0, 0x0000ff00},
4650 { FVF_COLORVERTEX, quad2, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x00ff0000},
4651 { FVF_COLORVERTEX, quad2, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x00ff0000},
4652 /* The specular color in the vertex is ignored because
4653 * D3DRENDERSTATE_COLORVERTEX is not enabled */
4654 { FVF_COLORVERTEX, quad2, FALSE, TRUE, 0, 0x0000ff00},
4655 { FVF_COLORVERTEX, quad2, TRUE, TRUE, 0, 0x0000ff00},
4656 { FVF_COLORVERTEX, quad2, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x00ff8080},
4657 { FVF_COLORVERTEX, quad2, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x00ff8080},
4659 /* 16 */
4660 { D3DFVF_LVERTEX, lquad, FALSE, FALSE, 0, 0x00ff0000},
4661 { D3DFVF_LVERTEX, lquad, TRUE, FALSE, 0, 0x00ff0000},
4662 { D3DFVF_LVERTEX, lquad, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x00ff0000},
4663 { D3DFVF_LVERTEX, lquad, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x00ff0000},
4664 { D3DFVF_LVERTEX, lquad, FALSE, TRUE, 0, 0x00ff8080},
4665 { D3DFVF_LVERTEX, lquad, TRUE, TRUE, 0, 0x00ff8080},
4666 { D3DFVF_LVERTEX, lquad, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x00ff8080},
4667 { D3DFVF_LVERTEX, lquad, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x00ff8080},
4669 /* 24 */
4670 { FVF_LVERTEX2, lquad2, FALSE, FALSE, 0, 0x00ff0000},
4671 { FVF_LVERTEX2, lquad2, TRUE, FALSE, 0, 0x00ff0000},
4672 { FVF_LVERTEX2, lquad2, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x00ff0000},
4673 { FVF_LVERTEX2, lquad2, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x00ff0000},
4674 { FVF_LVERTEX2, lquad2, FALSE, TRUE, 0, 0x00ff8080},
4675 { FVF_LVERTEX2, lquad2, TRUE, TRUE, 0, 0x00ff8080},
4676 { FVF_LVERTEX2, lquad2, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x00ff8080},
4677 { FVF_LVERTEX2, lquad2, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x00ff8080},
4679 /* 32 */
4680 { D3DFVF_TLVERTEX, tlquad, FALSE, FALSE, 0, 0x000000ff},
4681 { D3DFVF_TLVERTEX, tlquad, TRUE, FALSE, 0, 0x000000ff},
4682 { D3DFVF_TLVERTEX, tlquad, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x000000ff},
4683 { D3DFVF_TLVERTEX, tlquad, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x000000ff},
4684 { D3DFVF_TLVERTEX, tlquad, FALSE, TRUE, 0, 0x008080ff},
4685 { D3DFVF_TLVERTEX, tlquad, TRUE, TRUE, 0, 0x008080ff},
4686 { D3DFVF_TLVERTEX, tlquad, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x008080ff},
4687 { D3DFVF_TLVERTEX, tlquad, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x008080ff},
4690 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
4691 0, 0, 640, 480, 0, 0, 0, 0);
4693 if (!(device = create_device(window, DDSCL_NORMAL)))
4695 skip("Failed to create a 3D device, skipping test.\n");
4696 DestroyWindow(window);
4697 return;
4700 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
4701 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
4703 viewport = create_viewport(device, 0, 0, 640, 480);
4704 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
4705 ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr);
4707 emissive = create_emissive_material(device, 0.0f, 1.0f, 0.0f, 0.0f);
4708 hr = IDirect3DMaterial3_GetHandle(emissive, device, &mat_handle);
4709 ok(SUCCEEDED(hr), "Failed to get material handle, hr %#x.\n", hr);
4710 hr = IDirect3DDevice3_SetLightState(device, D3DLIGHTSTATE_MATERIAL, mat_handle);
4711 ok(SUCCEEDED(hr), "Failed to set material state, hr %#x.\n", hr);
4712 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
4713 ok(SUCCEEDED(hr), "Failed to disable z test, hr %#x.\n", hr);
4715 hr = IDirect3DDevice3_GetRenderState(device, D3DRENDERSTATE_SPECULARENABLE, &rs);
4716 ok(SUCCEEDED(hr), "Failed to get specularenable render state, hr %#x.\n", hr);
4717 ok(rs == FALSE, "Initial D3DRENDERSTATE_SPECULARENABLE is %#x, expected FALSE.\n", rs);
4719 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
4721 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xff202020, 0.0f, 0);
4722 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
4724 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_LIGHTING, tests[i].d3drs_lighting);
4725 ok(SUCCEEDED(hr), "Failed to set lighting render state, hr %#x.\n", hr);
4726 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_SPECULARENABLE,
4727 tests[i].d3drs_specular);
4728 ok(SUCCEEDED(hr), "Failed to set specularenable render state, hr %#x.\n", hr);
4730 hr = IDirect3DDevice3_BeginScene(device);
4731 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
4732 hr = IDirect3DDevice2_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
4733 tests[i].vertextype, tests[i].data, 4, tests[i].draw_flags | D3DDP_WAIT);
4734 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
4735 hr = IDirect3DDevice3_EndScene(device);
4736 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
4738 color = get_surface_color(rt, 320, 240);
4739 ok(compare_color(color, tests[i].color, 1),
4740 "Got unexpected color 0x%08x, expected 0x%08x, test %u.\n",
4741 color, tests[i].color, i);
4744 destroy_material(emissive);
4745 IDirectDrawSurface4_Release(rt);
4746 ref = IDirect3DDevice3_Release(device);
4747 ok(ref == 0, "Device not properly released, refcount %u.\n", ref);
4748 DestroyWindow(window);
4751 static struct
4753 BOOL received;
4754 IDirectDraw4 *ddraw;
4755 HWND window;
4756 DWORD coop_level;
4757 } activateapp_testdata;
4759 static LRESULT CALLBACK activateapp_test_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
4761 if (message == WM_ACTIVATEAPP)
4763 if (activateapp_testdata.ddraw)
4765 HRESULT hr;
4766 activateapp_testdata.received = FALSE;
4767 hr = IDirectDraw4_SetCooperativeLevel(activateapp_testdata.ddraw,
4768 activateapp_testdata.window, activateapp_testdata.coop_level);
4769 ok(SUCCEEDED(hr), "Recursive SetCooperativeLevel call failed, hr %#x.\n", hr);
4770 ok(!activateapp_testdata.received, "Received WM_ACTIVATEAPP during recursive SetCooperativeLevel call.\n");
4772 activateapp_testdata.received = TRUE;
4775 return DefWindowProcA(hwnd, message, wparam, lparam);
4778 static void test_coop_level_activateapp(void)
4780 IDirectDraw4 *ddraw;
4781 HRESULT hr;
4782 HWND window;
4783 WNDCLASSA wc = {0};
4784 DDSURFACEDESC2 ddsd;
4785 IDirectDrawSurface4 *surface;
4787 ddraw = create_ddraw();
4788 ok(!!ddraw, "Failed to create a ddraw object.\n");
4790 wc.lpfnWndProc = activateapp_test_proc;
4791 wc.lpszClassName = "ddraw_test_wndproc_wc";
4792 ok(RegisterClassA(&wc), "Failed to register window class.\n");
4794 window = CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
4795 WS_MAXIMIZE | WS_CAPTION , 0, 0, 640, 480, 0, 0, 0, 0);
4797 /* Exclusive with window already active. */
4798 SetForegroundWindow(window);
4799 activateapp_testdata.received = FALSE;
4800 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
4801 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4802 ok(!activateapp_testdata.received, "Received WM_ACTIVATEAPP although window was already active.\n");
4803 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
4804 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4806 /* Exclusive with window not active. */
4807 SetForegroundWindow(GetDesktopWindow());
4808 activateapp_testdata.received = FALSE;
4809 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
4810 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4811 ok(activateapp_testdata.received, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
4812 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
4813 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4815 /* Normal with window not active, then exclusive with the same window. */
4816 SetForegroundWindow(GetDesktopWindow());
4817 activateapp_testdata.received = FALSE;
4818 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
4819 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4820 ok(!activateapp_testdata.received, "Received WM_ACTIVATEAPP when setting DDSCL_NORMAL.\n");
4821 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
4822 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4823 ok(activateapp_testdata.received, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
4824 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
4825 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4827 /* Recursive set of DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN. */
4828 SetForegroundWindow(GetDesktopWindow());
4829 activateapp_testdata.received = FALSE;
4830 activateapp_testdata.ddraw = ddraw;
4831 activateapp_testdata.window = window;
4832 activateapp_testdata.coop_level = DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN;
4833 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
4834 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4835 ok(activateapp_testdata.received, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
4836 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
4837 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4839 /* The recursive call seems to have some bad effect on native ddraw, despite (apparently)
4840 * succeeding. Another switch to exclusive and back to normal is needed to release the
4841 * window properly. Without doing this, SetCooperativeLevel(EXCLUSIVE) will not send
4842 * WM_ACTIVATEAPP messages. */
4843 activateapp_testdata.ddraw = NULL;
4844 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
4845 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4846 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
4847 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4849 /* Setting DDSCL_NORMAL with recursive invocation. */
4850 SetForegroundWindow(GetDesktopWindow());
4851 activateapp_testdata.received = FALSE;
4852 activateapp_testdata.ddraw = ddraw;
4853 activateapp_testdata.window = window;
4854 activateapp_testdata.coop_level = DDSCL_NORMAL;
4855 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
4856 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4857 ok(activateapp_testdata.received, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
4859 /* DDraw is in exclusive mode now. */
4860 memset(&ddsd, 0, sizeof(ddsd));
4861 ddsd.dwSize = sizeof(ddsd);
4862 ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
4863 U5(ddsd).dwBackBufferCount = 1;
4864 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
4865 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
4866 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4867 IDirectDrawSurface4_Release(surface);
4869 /* Recover again, just to be sure. */
4870 activateapp_testdata.ddraw = NULL;
4871 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
4872 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4873 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
4874 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4876 DestroyWindow(window);
4877 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL));
4878 IDirectDraw4_Release(ddraw);
4881 static void test_texturemanage(void)
4883 IDirectDraw4 *ddraw;
4884 HRESULT hr;
4885 DDSURFACEDESC2 ddsd;
4886 IDirectDrawSurface4 *surface;
4887 unsigned int i;
4888 DDCAPS hal_caps, hel_caps;
4889 DWORD needed_caps = DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY;
4890 static const struct
4892 DWORD caps_in, caps2_in;
4893 HRESULT hr;
4894 DWORD caps_out, caps2_out;
4896 tests[] =
4898 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
4899 ~0U, ~0U},
4900 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, DDERR_INVALIDCAPS,
4901 ~0U, ~0U},
4902 {DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
4903 ~0U, ~0U},
4904 {DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, DDERR_INVALIDCAPS,
4905 ~0U, ~0U},
4906 {DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, DD_OK,
4907 DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE},
4908 {DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, DD_OK,
4909 DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE},
4910 {DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE, 0, DD_OK,
4911 DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE | DDSCAPS_LOCALVIDMEM, 0},
4912 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, 0, DD_OK,
4913 DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, 0},
4915 {0, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
4916 ~0U, ~0U},
4917 {0, DDSCAPS2_D3DTEXTUREMANAGE, DDERR_INVALIDCAPS,
4918 ~0U, ~0U},
4919 {DDSCAPS_SYSTEMMEMORY, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
4920 ~0U, ~0U},
4921 {DDSCAPS_SYSTEMMEMORY, DDSCAPS2_D3DTEXTUREMANAGE, DDERR_INVALIDCAPS,
4922 ~0U, ~0U},
4923 {DDSCAPS_VIDEOMEMORY, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
4924 ~0U, ~0U},
4925 {DDSCAPS_VIDEOMEMORY, DDSCAPS2_D3DTEXTUREMANAGE, DDERR_INVALIDCAPS,
4926 ~0U, ~0U},
4927 {DDSCAPS_VIDEOMEMORY, 0, DD_OK,
4928 DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY, 0},
4929 {DDSCAPS_SYSTEMMEMORY, 0, DD_OK,
4930 DDSCAPS_SYSTEMMEMORY, 0},
4933 ddraw = create_ddraw();
4934 ok(!!ddraw, "Failed to create a ddraw object.\n");
4935 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
4936 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4938 memset(&hal_caps, 0, sizeof(hal_caps));
4939 hal_caps.dwSize = sizeof(hal_caps);
4940 memset(&hel_caps, 0, sizeof(hel_caps));
4941 hel_caps.dwSize = sizeof(hel_caps);
4942 hr = IDirectDraw4_GetCaps(ddraw, &hal_caps, &hel_caps);
4943 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
4944 if ((hal_caps.ddsCaps.dwCaps & needed_caps) != needed_caps)
4946 skip("Managed textures not supported, skipping managed texture test.\n");
4947 IDirectDraw4_Release(ddraw);
4948 return;
4951 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
4953 memset(&ddsd, 0, sizeof(ddsd));
4954 ddsd.dwSize = sizeof(ddsd);
4955 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
4956 ddsd.ddsCaps.dwCaps = tests[i].caps_in;
4957 ddsd.ddsCaps.dwCaps2 = tests[i].caps2_in;
4958 ddsd.dwWidth = 4;
4959 ddsd.dwHeight = 4;
4961 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
4962 ok(hr == tests[i].hr, "Got unexpected, hr %#x, case %u.\n", hr, i);
4963 if (FAILED(hr))
4964 continue;
4966 memset(&ddsd, 0, sizeof(ddsd));
4967 ddsd.dwSize = sizeof(ddsd);
4968 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &ddsd);
4969 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
4971 ok(ddsd.ddsCaps.dwCaps == tests[i].caps_out,
4972 "Input caps %#x, %#x, expected output caps %#x, got %#x, case %u.\n",
4973 tests[i].caps_in, tests[i].caps2_in, tests[i].caps_out, ddsd.ddsCaps.dwCaps, i);
4974 ok(ddsd.ddsCaps.dwCaps2 == tests[i].caps2_out,
4975 "Input caps %#x, %#x, expected output caps %#x, got %#x, case %u.\n",
4976 tests[i].caps_in, tests[i].caps2_in, tests[i].caps2_out, ddsd.ddsCaps.dwCaps2, i);
4978 IDirectDrawSurface4_Release(surface);
4981 IDirectDraw4_Release(ddraw);
4984 #define SUPPORT_DXT1 0x01
4985 #define SUPPORT_DXT2 0x02
4986 #define SUPPORT_DXT3 0x04
4987 #define SUPPORT_DXT4 0x08
4988 #define SUPPORT_DXT5 0x10
4989 #define SUPPORT_YUY2 0x20
4990 #define SUPPORT_UYVY 0x40
4992 static HRESULT WINAPI test_block_formats_creation_cb(DDPIXELFORMAT *fmt, void *ctx)
4994 DWORD *supported_fmts = ctx;
4996 if (!(fmt->dwFlags & DDPF_FOURCC))
4997 return DDENUMRET_OK;
4999 switch (fmt->dwFourCC)
5001 case MAKEFOURCC('D','X','T','1'):
5002 *supported_fmts |= SUPPORT_DXT1;
5003 break;
5004 case MAKEFOURCC('D','X','T','2'):
5005 *supported_fmts |= SUPPORT_DXT2;
5006 break;
5007 case MAKEFOURCC('D','X','T','3'):
5008 *supported_fmts |= SUPPORT_DXT3;
5009 break;
5010 case MAKEFOURCC('D','X','T','4'):
5011 *supported_fmts |= SUPPORT_DXT4;
5012 break;
5013 case MAKEFOURCC('D','X','T','5'):
5014 *supported_fmts |= SUPPORT_DXT5;
5015 break;
5016 case MAKEFOURCC('Y','U','Y','2'):
5017 *supported_fmts |= SUPPORT_YUY2;
5018 break;
5019 case MAKEFOURCC('U','Y','V','Y'):
5020 *supported_fmts |= SUPPORT_UYVY;
5021 break;
5022 default:
5023 break;
5026 return DDENUMRET_OK;
5029 static void test_block_formats_creation(void)
5031 HRESULT hr, expect_hr;
5032 unsigned int i, j, w, h;
5033 HWND window;
5034 IDirectDraw4 *ddraw;
5035 IDirect3D3 *d3d;
5036 IDirect3DDevice3 *device;
5037 IDirectDrawSurface4 *surface;
5038 DWORD supported_fmts = 0, supported_overlay_fmts = 0;
5039 DWORD num_fourcc_codes = 0, *fourcc_codes;
5040 DDSURFACEDESC2 ddsd;
5041 DDCAPS hal_caps;
5042 void *mem;
5044 static const struct
5046 DWORD fourcc;
5047 const char *name;
5048 DWORD support_flag;
5049 unsigned int block_width;
5050 unsigned int block_height;
5051 unsigned int block_size;
5052 BOOL create_size_checked, overlay;
5054 formats[] =
5056 {MAKEFOURCC('D','X','T','1'), "D3DFMT_DXT1", SUPPORT_DXT1, 4, 4, 8, TRUE, FALSE},
5057 {MAKEFOURCC('D','X','T','2'), "D3DFMT_DXT2", SUPPORT_DXT2, 4, 4, 16, TRUE, FALSE},
5058 {MAKEFOURCC('D','X','T','3'), "D3DFMT_DXT3", SUPPORT_DXT3, 4, 4, 16, TRUE, FALSE},
5059 {MAKEFOURCC('D','X','T','4'), "D3DFMT_DXT4", SUPPORT_DXT4, 4, 4, 16, TRUE, FALSE},
5060 {MAKEFOURCC('D','X','T','5'), "D3DFMT_DXT5", SUPPORT_DXT5, 4, 4, 16, TRUE, FALSE},
5061 {MAKEFOURCC('Y','U','Y','2'), "D3DFMT_YUY2", SUPPORT_YUY2, 2, 1, 4, FALSE, TRUE },
5062 {MAKEFOURCC('U','Y','V','Y'), "D3DFMT_UYVY", SUPPORT_UYVY, 2, 1, 4, FALSE, TRUE },
5064 static const struct
5066 DWORD caps, caps2;
5067 const char *name;
5068 BOOL overlay;
5070 types[] =
5072 /* DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY fails to create any fourcc
5073 * surface with DDERR_INVALIDPIXELFORMAT. Don't care about it for now.
5075 * Nvidia returns E_FAIL on DXTN DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY.
5076 * Other hw / drivers successfully create those surfaces. Ignore them, this
5077 * suggests that no game uses this, otherwise Nvidia would support it. */
5079 DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE, 0,
5080 "videomemory texture", FALSE
5083 DDSCAPS_VIDEOMEMORY | DDSCAPS_OVERLAY, 0,
5084 "videomemory overlay", TRUE
5087 DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, 0,
5088 "systemmemory texture", FALSE
5091 DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE,
5092 "managed texture", FALSE
5095 enum size_type
5097 SIZE_TYPE_ZERO,
5098 SIZE_TYPE_PITCH,
5099 SIZE_TYPE_SIZE,
5101 static const struct
5103 DWORD flags;
5104 enum size_type size_type;
5105 int rel_size;
5106 HRESULT hr;
5108 user_mem_tests[] =
5110 {DDSD_LINEARSIZE, SIZE_TYPE_ZERO, 0, DD_OK},
5111 {DDSD_LINEARSIZE, SIZE_TYPE_SIZE, 0, DD_OK},
5112 {DDSD_PITCH, SIZE_TYPE_ZERO, 0, DD_OK},
5113 {DDSD_PITCH, SIZE_TYPE_PITCH, 0, DD_OK},
5114 {DDSD_LPSURFACE, SIZE_TYPE_ZERO, 0, DDERR_INVALIDPARAMS},
5115 {DDSD_LPSURFACE | DDSD_LINEARSIZE, SIZE_TYPE_ZERO, 0, DDERR_INVALIDPARAMS},
5116 {DDSD_LPSURFACE | DDSD_LINEARSIZE, SIZE_TYPE_PITCH, 0, DDERR_INVALIDPARAMS},
5117 {DDSD_LPSURFACE | DDSD_LINEARSIZE, SIZE_TYPE_SIZE, 0, DD_OK},
5118 {DDSD_LPSURFACE | DDSD_LINEARSIZE, SIZE_TYPE_SIZE, 1, DD_OK},
5119 {DDSD_LPSURFACE | DDSD_LINEARSIZE, SIZE_TYPE_SIZE, -1, DDERR_INVALIDPARAMS},
5120 {DDSD_LPSURFACE | DDSD_PITCH, SIZE_TYPE_ZERO, 0, DD_OK},
5121 {DDSD_LPSURFACE | DDSD_PITCH, SIZE_TYPE_PITCH, 0, DD_OK},
5122 {DDSD_LPSURFACE | DDSD_PITCH, SIZE_TYPE_SIZE, 0, DD_OK},
5123 {DDSD_LPSURFACE | DDSD_PITCH | DDSD_LINEARSIZE, SIZE_TYPE_SIZE, 0, DD_OK},
5126 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5127 0, 0, 640, 480, 0, 0, 0, 0);
5129 if (!(device = create_device(window, DDSCL_NORMAL)))
5131 skip("Failed to create a 3D device, skipping test.\n");
5132 DestroyWindow(window);
5133 return;
5136 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
5137 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
5138 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **) &ddraw);
5139 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
5140 IDirect3D3_Release(d3d);
5142 hr = IDirect3DDevice3_EnumTextureFormats(device, test_block_formats_creation_cb,
5143 &supported_fmts);
5144 ok(SUCCEEDED(hr), "Failed to enumerate texture formats %#x.\n", hr);
5146 hr = IDirectDraw4_GetFourCCCodes(ddraw, &num_fourcc_codes, NULL);
5147 ok(SUCCEEDED(hr), "Failed to get fourcc codes %#x.\n", hr);
5148 fourcc_codes = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
5149 num_fourcc_codes * sizeof(*fourcc_codes));
5150 if (!fourcc_codes)
5151 goto cleanup;
5152 hr = IDirectDraw4_GetFourCCCodes(ddraw, &num_fourcc_codes, fourcc_codes);
5153 ok(SUCCEEDED(hr), "Failed to get fourcc codes %#x.\n", hr);
5154 for (i = 0; i < num_fourcc_codes; i++)
5156 for (j = 0; j < sizeof(formats) / sizeof(*formats); j++)
5158 if (fourcc_codes[i] == formats[j].fourcc)
5159 supported_overlay_fmts |= formats[j].support_flag;
5162 HeapFree(GetProcessHeap(), 0, fourcc_codes);
5164 memset(&hal_caps, 0, sizeof(hal_caps));
5165 hal_caps.dwSize = sizeof(hal_caps);
5166 hr = IDirectDraw4_GetCaps(ddraw, &hal_caps, NULL);
5167 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
5169 mem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 2 * 2 * 16 + 1);
5171 for (i = 0; i < sizeof(formats) / sizeof(*formats); i++)
5173 for (j = 0; j < sizeof(types) / sizeof(*types); j++)
5175 BOOL support;
5177 if (formats[i].overlay != types[j].overlay
5178 || (types[j].overlay && !(hal_caps.dwCaps & DDCAPS_OVERLAY)))
5179 continue;
5181 if (formats[i].overlay)
5182 support = supported_overlay_fmts & formats[i].support_flag;
5183 else
5184 support = supported_fmts & formats[i].support_flag;
5186 for (w = 1; w <= 8; w++)
5188 for (h = 1; h <= 8; h++)
5190 BOOL block_aligned = TRUE;
5191 BOOL todo = FALSE;
5193 if (w & (formats[i].block_width - 1) || h & (formats[i].block_height - 1))
5194 block_aligned = FALSE;
5196 memset(&ddsd, 0, sizeof(ddsd));
5197 ddsd.dwSize = sizeof(ddsd);
5198 ddsd.dwFlags = DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
5199 ddsd.ddsCaps.dwCaps = types[j].caps;
5200 ddsd.ddsCaps.dwCaps2 = types[j].caps2;
5201 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
5202 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_FOURCC;
5203 U4(ddsd).ddpfPixelFormat.dwFourCC = formats[i].fourcc;
5204 ddsd.dwWidth = w;
5205 ddsd.dwHeight = h;
5207 /* TODO: Handle power of two limitations. I cannot test the pow2
5208 * behavior on windows because I have no hardware that doesn't at
5209 * least support np2_conditional. There's probably no HW that
5210 * supports DXTN textures but no conditional np2 textures. */
5211 if (!support && !(types[j].caps & DDSCAPS_SYSTEMMEMORY))
5212 expect_hr = DDERR_INVALIDPARAMS;
5213 else if (formats[i].create_size_checked && !block_aligned)
5215 expect_hr = DDERR_INVALIDPARAMS;
5216 if (!(types[j].caps & DDSCAPS_TEXTURE))
5217 todo = TRUE;
5219 else
5220 expect_hr = D3D_OK;
5222 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
5223 todo_wine_if (todo)
5224 ok(hr == expect_hr,
5225 "Got unexpected hr %#x for format %s, resource type %s, size %ux%u, expected %#x.\n",
5226 hr, formats[i].name, types[j].name, w, h, expect_hr);
5228 if (SUCCEEDED(hr))
5229 IDirectDrawSurface4_Release(surface);
5234 if (formats[i].overlay)
5235 continue;
5237 for (j = 0; j < sizeof(user_mem_tests) / sizeof(*user_mem_tests); ++j)
5239 memset(&ddsd, 0, sizeof(ddsd));
5240 ddsd.dwSize = sizeof(ddsd);
5241 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | user_mem_tests[j].flags;
5242 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE;
5244 switch (user_mem_tests[j].size_type)
5246 case SIZE_TYPE_ZERO:
5247 U1(ddsd).dwLinearSize = 0;
5248 break;
5250 case SIZE_TYPE_PITCH:
5251 U1(ddsd).dwLinearSize = 2 * formats[i].block_size;
5252 break;
5254 case SIZE_TYPE_SIZE:
5255 U1(ddsd).dwLinearSize = 2 * 2 * formats[i].block_size;
5256 break;
5258 U1(ddsd).dwLinearSize += user_mem_tests[j].rel_size;
5260 ddsd.lpSurface = mem;
5261 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
5262 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_FOURCC;
5263 U4(ddsd).ddpfPixelFormat.dwFourCC = formats[i].fourcc;
5264 ddsd.dwWidth = 8;
5265 ddsd.dwHeight = 8;
5267 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
5268 ok(hr == user_mem_tests[j].hr, "Test %u: Got unexpected hr %#x, format %s.\n", j, hr, formats[i].name);
5270 if (FAILED(hr))
5271 continue;
5273 memset(&ddsd, 0, sizeof(ddsd));
5274 ddsd.dwSize = sizeof(ddsd);
5275 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &ddsd);
5276 ok(SUCCEEDED(hr), "Test %u: Failed to get surface desc, hr %#x.\n", j, hr);
5277 ok(ddsd.dwFlags == (DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_LINEARSIZE),
5278 "Test %u: Got unexpected flags %#x.\n", j, ddsd.dwFlags);
5279 if (user_mem_tests[j].flags & DDSD_LPSURFACE)
5280 ok(U1(ddsd).dwLinearSize == ~0u, "Test %u: Got unexpected linear size %#x.\n",
5281 j, U1(ddsd).dwLinearSize);
5282 else
5283 ok(U1(ddsd).dwLinearSize == 2 * 2 * formats[i].block_size,
5284 "Test %u: Got unexpected linear size %#x, expected %#x.\n",
5285 j, U1(ddsd).dwLinearSize, 2 * 2 * formats[i].block_size);
5286 IDirectDrawSurface4_Release(surface);
5290 HeapFree(GetProcessHeap(), 0, mem);
5291 cleanup:
5292 IDirectDraw4_Release(ddraw);
5293 IDirect3DDevice3_Release(device);
5294 DestroyWindow(window);
5297 struct format_support_check
5299 const DDPIXELFORMAT *format;
5300 BOOL supported;
5303 static HRESULT WINAPI test_unsupported_formats_cb(DDPIXELFORMAT *fmt, void *ctx)
5305 struct format_support_check *format = ctx;
5307 if (!memcmp(format->format, fmt, sizeof(*fmt)))
5309 format->supported = TRUE;
5310 return DDENUMRET_CANCEL;
5313 return DDENUMRET_OK;
5316 static void test_unsupported_formats(void)
5318 HRESULT hr;
5319 BOOL expect_success;
5320 HWND window;
5321 IDirectDraw4 *ddraw;
5322 IDirect3D3 *d3d;
5323 IDirect3DDevice3 *device;
5324 IDirectDrawSurface4 *surface;
5325 DDSURFACEDESC2 ddsd;
5326 unsigned int i, j;
5327 DWORD expected_caps;
5328 static const struct
5330 const char *name;
5331 DDPIXELFORMAT fmt;
5333 formats[] =
5336 "D3DFMT_A8R8G8B8",
5338 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
5339 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
5343 "D3DFMT_P8",
5345 sizeof(DDPIXELFORMAT), DDPF_PALETTEINDEXED8 | DDPF_RGB, 0,
5346 {8 }, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}
5350 static const DWORD caps[] = {0, DDSCAPS_SYSTEMMEMORY, DDSCAPS_VIDEOMEMORY};
5352 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5353 0, 0, 640, 480, 0, 0, 0, 0);
5355 if (!(device = create_device(window, DDSCL_NORMAL)))
5357 skip("Failed to create a 3D device, skipping test.\n");
5358 DestroyWindow(window);
5359 return;
5362 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
5363 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
5364 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **) &ddraw);
5365 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
5366 IDirect3D3_Release(d3d);
5368 for (i = 0; i < sizeof(formats) / sizeof(*formats); i++)
5370 struct format_support_check check = {&formats[i].fmt, FALSE};
5371 hr = IDirect3DDevice3_EnumTextureFormats(device, test_unsupported_formats_cb, &check);
5372 ok(SUCCEEDED(hr), "Failed to enumerate texture formats %#x.\n", hr);
5374 for (j = 0; j < sizeof(caps) / sizeof(*caps); j++)
5376 memset(&ddsd, 0, sizeof(ddsd));
5377 ddsd.dwSize = sizeof(ddsd);
5378 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
5379 U4(ddsd).ddpfPixelFormat = formats[i].fmt;
5380 ddsd.dwWidth = 4;
5381 ddsd.dwHeight = 4;
5382 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | caps[j];
5384 if (caps[j] & DDSCAPS_VIDEOMEMORY && !check.supported)
5385 expect_success = FALSE;
5386 else
5387 expect_success = TRUE;
5389 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
5390 ok(SUCCEEDED(hr) == expect_success,
5391 "Got unexpected hr %#x for format %s, caps %#x, expected %s.\n",
5392 hr, formats[i].name, caps[j], expect_success ? "success" : "failure");
5393 if (FAILED(hr))
5394 continue;
5396 memset(&ddsd, 0, sizeof(ddsd));
5397 ddsd.dwSize = sizeof(ddsd);
5398 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &ddsd);
5399 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
5401 if (caps[j] & DDSCAPS_VIDEOMEMORY)
5402 expected_caps = DDSCAPS_VIDEOMEMORY;
5403 else if (caps[j] & DDSCAPS_SYSTEMMEMORY)
5404 expected_caps = DDSCAPS_SYSTEMMEMORY;
5405 else if (check.supported)
5406 expected_caps = DDSCAPS_VIDEOMEMORY;
5407 else
5408 expected_caps = DDSCAPS_SYSTEMMEMORY;
5410 ok(ddsd.ddsCaps.dwCaps & expected_caps,
5411 "Expected capability %#x, format %s, input cap %#x.\n",
5412 expected_caps, formats[i].name, caps[j]);
5414 IDirectDrawSurface4_Release(surface);
5418 IDirectDraw4_Release(ddraw);
5419 IDirect3DDevice3_Release(device);
5420 DestroyWindow(window);
5423 static void test_rt_caps(void)
5425 PALETTEENTRY palette_entries[256];
5426 IDirectDrawPalette *palette;
5427 IDirectDraw4 *ddraw;
5428 DDPIXELFORMAT z_fmt;
5429 IDirect3D3 *d3d;
5430 unsigned int i;
5431 ULONG refcount;
5432 HWND window;
5433 HRESULT hr;
5435 static const DDPIXELFORMAT p8_fmt =
5437 sizeof(DDPIXELFORMAT), DDPF_PALETTEINDEXED8 | DDPF_RGB, 0,
5438 {8}, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000},
5441 const struct
5443 const DDPIXELFORMAT *pf;
5444 DWORD caps_in;
5445 DWORD caps_out;
5446 HRESULT create_device_hr;
5447 HRESULT set_rt_hr, alternative_set_rt_hr;
5449 test_data[] =
5452 NULL,
5453 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY,
5454 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
5455 D3D_OK,
5456 D3D_OK,
5457 D3D_OK,
5460 NULL,
5461 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE,
5462 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
5463 D3D_OK,
5464 D3D_OK,
5465 D3D_OK,
5468 NULL,
5469 DDSCAPS_OFFSCREENPLAIN,
5470 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
5471 DDERR_INVALIDCAPS,
5472 DDERR_INVALIDCAPS,
5473 DDERR_INVALIDCAPS,
5476 NULL,
5477 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
5478 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
5479 D3DERR_SURFACENOTINVIDMEM,
5480 D3D_OK,
5481 D3D_OK,
5484 NULL,
5485 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
5486 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
5487 DDERR_INVALIDCAPS,
5488 DDERR_INVALIDCAPS,
5489 DDERR_INVALIDCAPS,
5492 NULL,
5493 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY,
5494 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
5495 D3D_OK,
5496 D3D_OK,
5497 D3D_OK,
5500 NULL,
5501 DDSCAPS_3DDEVICE,
5502 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
5503 D3D_OK,
5504 D3D_OK,
5505 D3D_OK,
5508 NULL,
5510 DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
5511 DDERR_INVALIDCAPS,
5512 DDERR_INVALIDCAPS,
5513 DDERR_INVALIDCAPS,
5516 NULL,
5517 DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
5518 DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
5519 D3DERR_SURFACENOTINVIDMEM,
5520 D3D_OK,
5521 D3D_OK,
5524 NULL,
5525 DDSCAPS_SYSTEMMEMORY,
5526 DDSCAPS_SYSTEMMEMORY,
5527 DDERR_INVALIDCAPS,
5528 DDERR_INVALIDCAPS,
5529 DDERR_INVALIDCAPS,
5532 &p8_fmt,
5534 DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
5535 DDERR_INVALIDCAPS,
5536 DDERR_INVALIDCAPS,
5537 DDERR_INVALIDCAPS,
5540 &p8_fmt,
5541 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE,
5542 ~0U /* AMD r200 */,
5543 DDERR_NOPALETTEATTACHED,
5544 DDERR_INVALIDCAPS,
5545 DDERR_INVALIDCAPS,
5548 &p8_fmt,
5549 DDSCAPS_OFFSCREENPLAIN,
5550 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
5551 DDERR_INVALIDCAPS,
5552 DDERR_INVALIDCAPS,
5553 DDERR_INVALIDCAPS,
5556 &p8_fmt,
5557 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
5558 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
5559 DDERR_NOPALETTEATTACHED,
5560 DDERR_INVALIDCAPS,
5561 DDERR_INVALIDCAPS,
5564 &p8_fmt,
5565 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
5566 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
5567 DDERR_INVALIDCAPS,
5568 DDERR_INVALIDCAPS,
5569 DDERR_INVALIDCAPS,
5572 &z_fmt,
5573 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_ZBUFFER,
5574 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_ZBUFFER | DDSCAPS_LOCALVIDMEM,
5575 DDERR_INVALIDCAPS,
5576 DDERR_INVALIDPIXELFORMAT,
5577 D3D_OK /* r200 */,
5580 &z_fmt,
5581 DDSCAPS_3DDEVICE | DDSCAPS_ZBUFFER,
5582 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_ZBUFFER | DDSCAPS_LOCALVIDMEM,
5583 DDERR_INVALIDCAPS,
5584 DDERR_INVALIDPIXELFORMAT,
5585 D3D_OK /* r200 */,
5588 &z_fmt,
5589 DDSCAPS_ZBUFFER,
5590 DDSCAPS_VIDEOMEMORY | DDSCAPS_ZBUFFER | DDSCAPS_LOCALVIDMEM,
5591 DDERR_INVALIDCAPS,
5592 DDERR_INVALIDCAPS,
5593 DDERR_INVALIDCAPS,
5596 &z_fmt,
5597 DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE | DDSCAPS_ZBUFFER,
5598 DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE | DDSCAPS_ZBUFFER,
5599 DDERR_INVALIDCAPS,
5600 DDERR_INVALIDPIXELFORMAT,
5601 D3D_OK /* r200 */,
5604 &z_fmt,
5605 DDSCAPS_SYSTEMMEMORY | DDSCAPS_ZBUFFER,
5606 DDSCAPS_SYSTEMMEMORY | DDSCAPS_ZBUFFER,
5607 DDERR_INVALIDCAPS,
5608 DDERR_INVALIDCAPS,
5609 DDERR_INVALIDCAPS,
5613 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5614 0, 0, 640, 480, 0, 0, 0, 0);
5615 ddraw = create_ddraw();
5616 ok(!!ddraw, "Failed to create a ddraw object.\n");
5617 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
5618 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5620 if (FAILED(IDirectDraw4_QueryInterface(ddraw, &IID_IDirect3D3, (void **)&d3d)))
5622 skip("D3D interface is not available, skipping test.\n");
5623 goto done;
5626 memset(&z_fmt, 0, sizeof(z_fmt));
5627 hr = IDirect3D3_EnumZBufferFormats(d3d, &IID_IDirect3DHALDevice, enum_z_fmt, &z_fmt);
5628 if (FAILED(hr) || !z_fmt.dwSize)
5630 skip("No depth buffer formats available, skipping test.\n");
5631 IDirect3D3_Release(d3d);
5632 goto done;
5635 memset(palette_entries, 0, sizeof(palette_entries));
5636 hr = IDirectDraw4_CreatePalette(ddraw, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, palette_entries, &palette, NULL);
5637 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
5639 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
5641 IDirectDrawSurface4 *surface, *rt, *expected_rt, *tmp;
5642 DDSURFACEDESC2 surface_desc;
5643 IDirect3DDevice3 *device;
5645 memset(&surface_desc, 0, sizeof(surface_desc));
5646 surface_desc.dwSize = sizeof(surface_desc);
5647 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
5648 surface_desc.ddsCaps.dwCaps = test_data[i].caps_in;
5649 if (test_data[i].pf)
5651 surface_desc.dwFlags |= DDSD_PIXELFORMAT;
5652 U4(surface_desc).ddpfPixelFormat = *test_data[i].pf;
5654 surface_desc.dwWidth = 640;
5655 surface_desc.dwHeight = 480;
5656 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
5657 ok(SUCCEEDED(hr), "Test %u: Failed to create surface with caps %#x, hr %#x.\n",
5658 i, test_data[i].caps_in, hr);
5660 memset(&surface_desc, 0, sizeof(surface_desc));
5661 surface_desc.dwSize = sizeof(surface_desc);
5662 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &surface_desc);
5663 ok(SUCCEEDED(hr), "Test %u: Failed to get surface desc, hr %#x.\n", i, hr);
5664 ok(test_data[i].caps_out == ~0U || surface_desc.ddsCaps.dwCaps == test_data[i].caps_out,
5665 "Test %u: Got unexpected caps %#x, expected %#x.\n",
5666 i, surface_desc.ddsCaps.dwCaps, test_data[i].caps_out);
5668 hr = IDirect3D3_CreateDevice(d3d, &IID_IDirect3DHALDevice, surface, &device, NULL);
5669 ok(hr == test_data[i].create_device_hr, "Test %u: Got unexpected hr %#x, expected %#x.\n",
5670 i, hr, test_data[i].create_device_hr);
5671 if (FAILED(hr))
5673 if (hr == DDERR_NOPALETTEATTACHED)
5675 hr = IDirectDrawSurface4_SetPalette(surface, palette);
5676 ok(SUCCEEDED(hr), "Test %u: Failed to set palette, hr %#x.\n", i, hr);
5677 hr = IDirect3D3_CreateDevice(d3d, &IID_IDirect3DHALDevice, surface, &device, NULL);
5678 if (surface_desc.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY)
5679 ok(hr == DDERR_INVALIDPIXELFORMAT, "Test %u: Got unexpected hr %#x.\n", i, hr);
5680 else
5681 ok(hr == D3DERR_SURFACENOTINVIDMEM, "Test %u: Got unexpected hr %#x.\n", i, hr);
5683 IDirectDrawSurface4_Release(surface);
5685 memset(&surface_desc, 0, sizeof(surface_desc));
5686 surface_desc.dwSize = sizeof(surface_desc);
5687 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
5688 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
5689 surface_desc.dwWidth = 640;
5690 surface_desc.dwHeight = 480;
5691 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
5692 ok(SUCCEEDED(hr), "Test %u: Failed to create surface, hr %#x.\n", i, hr);
5694 hr = IDirect3D3_CreateDevice(d3d, &IID_IDirect3DHALDevice, surface, &device, NULL);
5695 ok(SUCCEEDED(hr), "Test %u: Failed to create device, hr %#x.\n", i, hr);
5698 memset(&surface_desc, 0, sizeof(surface_desc));
5699 surface_desc.dwSize = sizeof(surface_desc);
5700 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
5701 surface_desc.ddsCaps.dwCaps = test_data[i].caps_in;
5702 if (test_data[i].pf)
5704 surface_desc.dwFlags |= DDSD_PIXELFORMAT;
5705 U4(surface_desc).ddpfPixelFormat = *test_data[i].pf;
5707 surface_desc.dwWidth = 640;
5708 surface_desc.dwHeight = 480;
5709 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &rt, NULL);
5710 ok(SUCCEEDED(hr), "Test %u: Failed to create surface with caps %#x, hr %#x.\n",
5711 i, test_data[i].caps_in, hr);
5713 hr = IDirect3DDevice3_SetRenderTarget(device, rt, 0);
5714 ok(hr == test_data[i].set_rt_hr || broken(hr == test_data[i].alternative_set_rt_hr),
5715 "Test %u: Got unexpected hr %#x, expected %#x.\n",
5716 i, hr, test_data[i].set_rt_hr);
5717 if (SUCCEEDED(hr) || hr == DDERR_INVALIDPIXELFORMAT)
5718 expected_rt = rt;
5719 else
5720 expected_rt = surface;
5722 hr = IDirect3DDevice3_GetRenderTarget(device, &tmp);
5723 ok(SUCCEEDED(hr), "Test %u: Failed to get render target, hr %#x.\n", i, hr);
5724 ok(tmp == expected_rt, "Test %u: Got unexpected rt %p.\n", i, tmp);
5726 IDirectDrawSurface4_Release(tmp);
5727 IDirectDrawSurface4_Release(rt);
5728 refcount = IDirect3DDevice3_Release(device);
5729 ok(refcount == 0, "Test %u: The device was not properly freed, refcount %u.\n", i, refcount);
5730 refcount = IDirectDrawSurface4_Release(surface);
5731 ok(refcount == 0, "Test %u: The surface was not properly freed, refcount %u.\n", i, refcount);
5734 IDirectDrawPalette_Release(palette);
5735 IDirect3D3_Release(d3d);
5737 done:
5738 refcount = IDirectDraw4_Release(ddraw);
5739 ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount);
5740 DestroyWindow(window);
5743 static void test_primary_caps(void)
5745 const DWORD placement = DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY | DDSCAPS_SYSTEMMEMORY;
5746 IDirectDrawSurface4 *surface;
5747 DDSURFACEDESC2 surface_desc;
5748 IDirectDraw4 *ddraw;
5749 unsigned int i;
5750 ULONG refcount;
5751 HWND window;
5752 HRESULT hr;
5754 static const struct
5756 DWORD coop_level;
5757 DWORD caps_in;
5758 DWORD back_buffer_count;
5759 HRESULT hr;
5760 DWORD caps_out;
5762 test_data[] =
5765 DDSCL_NORMAL,
5766 DDSCAPS_PRIMARYSURFACE,
5767 ~0u,
5768 DD_OK,
5769 DDSCAPS_VISIBLE | DDSCAPS_PRIMARYSURFACE,
5772 DDSCL_NORMAL,
5773 DDSCAPS_PRIMARYSURFACE | DDSCAPS_TEXTURE,
5774 ~0u,
5775 DDERR_INVALIDCAPS,
5776 ~0u,
5779 DDSCL_NORMAL,
5780 DDSCAPS_PRIMARYSURFACE | DDSCAPS_FRONTBUFFER,
5781 ~0u,
5782 DDERR_INVALIDCAPS,
5783 ~0u,
5786 DDSCL_NORMAL,
5787 DDSCAPS_PRIMARYSURFACE | DDSCAPS_BACKBUFFER,
5788 ~0u,
5789 DDERR_INVALIDCAPS,
5790 ~0u,
5793 DDSCL_NORMAL,
5794 DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP,
5795 ~0u,
5796 DDERR_INVALIDCAPS,
5797 ~0u,
5800 DDSCL_NORMAL,
5801 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX,
5802 ~0u,
5803 DDERR_INVALIDCAPS,
5804 ~0u,
5807 DDSCL_NORMAL,
5808 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
5809 ~0u,
5810 DDERR_INVALIDCAPS,
5811 ~0u,
5814 DDSCL_NORMAL,
5815 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
5817 DDERR_INVALIDCAPS,
5818 ~0u,
5821 DDSCL_NORMAL,
5822 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
5824 DDERR_NOEXCLUSIVEMODE,
5825 ~0u,
5828 DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN,
5829 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
5831 DDERR_INVALIDCAPS,
5832 ~0u,
5835 DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN,
5836 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
5838 DD_OK,
5839 DDSCAPS_VISIBLE | DDSCAPS_PRIMARYSURFACE | DDSCAPS_FRONTBUFFER | DDSCAPS_FLIP | DDSCAPS_COMPLEX,
5842 DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN,
5843 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP | DDSCAPS_FRONTBUFFER,
5845 DDERR_INVALIDCAPS,
5846 ~0u,
5849 DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN,
5850 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP | DDSCAPS_BACKBUFFER,
5852 DDERR_INVALIDCAPS,
5853 ~0u,
5857 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5858 0, 0, 640, 480, 0, 0, 0, 0);
5859 ddraw = create_ddraw();
5860 ok(!!ddraw, "Failed to create a ddraw object.\n");
5862 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
5864 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, test_data[i].coop_level);
5865 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5867 memset(&surface_desc, 0, sizeof(surface_desc));
5868 surface_desc.dwSize = sizeof(surface_desc);
5869 surface_desc.dwFlags = DDSD_CAPS;
5870 if (test_data[i].back_buffer_count != ~0u)
5871 surface_desc.dwFlags |= DDSD_BACKBUFFERCOUNT;
5872 surface_desc.ddsCaps.dwCaps = test_data[i].caps_in;
5873 U5(surface_desc).dwBackBufferCount = test_data[i].back_buffer_count;
5874 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
5875 ok(hr == test_data[i].hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, test_data[i].hr);
5876 if (FAILED(hr))
5877 continue;
5879 memset(&surface_desc, 0, sizeof(surface_desc));
5880 surface_desc.dwSize = sizeof(surface_desc);
5881 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &surface_desc);
5882 ok(SUCCEEDED(hr), "Test %u: Failed to get surface desc, hr %#x.\n", i, hr);
5883 ok((surface_desc.ddsCaps.dwCaps & ~placement) == test_data[i].caps_out,
5884 "Test %u: Got unexpected caps %#x, expected %#x.\n",
5885 i, surface_desc.ddsCaps.dwCaps, test_data[i].caps_out);
5887 IDirectDrawSurface4_Release(surface);
5890 refcount = IDirectDraw4_Release(ddraw);
5891 ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount);
5892 DestroyWindow(window);
5895 static void test_surface_lock(void)
5897 IDirectDraw4 *ddraw;
5898 IDirect3D3 *d3d = NULL;
5899 IDirectDrawSurface4 *surface;
5900 HRESULT hr;
5901 HWND window;
5902 unsigned int i;
5903 DDSURFACEDESC2 ddsd;
5904 ULONG refcount;
5905 DDPIXELFORMAT z_fmt;
5906 static const struct
5908 DWORD caps;
5909 DWORD caps2;
5910 const char *name;
5912 tests[] =
5915 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY,
5917 "videomemory offscreenplain"
5920 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
5922 "systemmemory offscreenplain"
5925 DDSCAPS_PRIMARYSURFACE,
5927 "primary"
5930 DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY,
5932 "videomemory texture"
5935 DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY,
5936 DDSCAPS2_OPAQUE,
5937 "opaque videomemory texture"
5940 DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY,
5942 "systemmemory texture"
5945 DDSCAPS_TEXTURE,
5946 DDSCAPS2_TEXTUREMANAGE,
5947 "managed texture"
5950 DDSCAPS_TEXTURE,
5951 DDSCAPS2_D3DTEXTUREMANAGE,
5952 "managed texture"
5955 DDSCAPS_TEXTURE,
5956 DDSCAPS2_TEXTUREMANAGE | DDSCAPS2_OPAQUE,
5957 "opaque managed texture"
5960 DDSCAPS_TEXTURE,
5961 DDSCAPS2_D3DTEXTUREMANAGE | DDSCAPS2_OPAQUE,
5962 "opaque managed texture"
5965 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE,
5967 "render target"
5970 DDSCAPS_ZBUFFER,
5972 "Z buffer"
5976 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5977 0, 0, 640, 480, 0, 0, 0, 0);
5978 ddraw = create_ddraw();
5979 ok(!!ddraw, "Failed to create a ddraw object.\n");
5980 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
5981 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5983 if (FAILED(IDirectDraw4_QueryInterface(ddraw, &IID_IDirect3D3, (void **)&d3d)))
5985 skip("D3D interface is not available, skipping test.\n");
5986 goto done;
5989 memset(&z_fmt, 0, sizeof(z_fmt));
5990 hr = IDirect3D3_EnumZBufferFormats(d3d, &IID_IDirect3DHALDevice, enum_z_fmt, &z_fmt);
5991 if (FAILED(hr) || !z_fmt.dwSize)
5993 skip("No depth buffer formats available, skipping test.\n");
5994 goto done;
5997 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
5999 memset(&ddsd, 0, sizeof(ddsd));
6000 ddsd.dwSize = sizeof(ddsd);
6001 ddsd.dwFlags = DDSD_CAPS;
6002 if (!(tests[i].caps & DDSCAPS_PRIMARYSURFACE))
6004 ddsd.dwFlags |= DDSD_WIDTH | DDSD_HEIGHT;
6005 ddsd.dwWidth = 64;
6006 ddsd.dwHeight = 64;
6008 if (tests[i].caps & DDSCAPS_ZBUFFER)
6010 ddsd.dwFlags |= DDSD_PIXELFORMAT;
6011 U4(ddsd).ddpfPixelFormat = z_fmt;
6013 ddsd.ddsCaps.dwCaps = tests[i].caps;
6014 ddsd.ddsCaps.dwCaps2 = tests[i].caps2;
6016 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
6017 ok(SUCCEEDED(hr), "Failed to create surface, type %s, hr %#x.\n", tests[i].name, hr);
6019 memset(&ddsd, 0, sizeof(ddsd));
6020 ddsd.dwSize = sizeof(ddsd);
6021 hr = IDirectDrawSurface4_Lock(surface, NULL, &ddsd, DDLOCK_WAIT, NULL);
6022 ok(SUCCEEDED(hr), "Failed to lock surface, type %s, hr %#x.\n", tests[i].name, hr);
6023 if (SUCCEEDED(hr))
6025 hr = IDirectDrawSurface4_Unlock(surface, NULL);
6026 ok(SUCCEEDED(hr), "Failed to unlock surface, type %s, hr %#x.\n", tests[i].name, hr);
6029 memset(&ddsd, 0, sizeof(ddsd));
6030 hr = IDirectDrawSurface4_Lock(surface, NULL, &ddsd, DDLOCK_WAIT, NULL);
6031 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x, type %s.\n", hr, tests[i].name);
6033 IDirectDrawSurface4_Release(surface);
6036 done:
6037 if (d3d)
6038 IDirect3D3_Release(d3d);
6039 refcount = IDirectDraw4_Release(ddraw);
6040 ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount);
6041 DestroyWindow(window);
6044 static void test_surface_discard(void)
6046 IDirect3DDevice3 *device;
6047 IDirect3D3 *d3d;
6048 IDirectDraw4 *ddraw;
6049 HRESULT hr;
6050 HWND window;
6051 DDSURFACEDESC2 ddsd;
6052 IDirectDrawSurface4 *surface, *target;
6053 void *addr;
6054 static const struct
6056 DWORD caps, caps2;
6057 BOOL discard;
6059 tests[] =
6061 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0, TRUE},
6062 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY, 0, FALSE},
6063 {DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, 0, TRUE},
6064 {DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, 0, FALSE},
6065 {DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, FALSE},
6066 {DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE | DDSCAPS2_HINTDYNAMIC, FALSE},
6067 {DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, FALSE},
6068 {DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE | DDSCAPS2_HINTDYNAMIC, FALSE},
6070 unsigned int i;
6072 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
6073 0, 0, 640, 480, 0, 0, 0, 0);
6075 if (!(device = create_device(window, DDSCL_NORMAL)))
6077 skip("Failed to create a 3D device, skipping test.\n");
6078 DestroyWindow(window);
6079 return;
6081 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
6082 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
6083 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
6084 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
6085 hr = IDirect3DDevice3_GetRenderTarget(device, &target);
6086 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
6088 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
6090 BOOL discarded;
6092 memset(&ddsd, 0, sizeof(ddsd));
6093 ddsd.dwSize = sizeof(ddsd);
6094 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
6095 ddsd.ddsCaps.dwCaps = tests[i].caps;
6096 ddsd.ddsCaps.dwCaps2 = tests[i].caps2;
6097 ddsd.dwWidth = 64;
6098 ddsd.dwHeight = 64;
6099 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
6100 ok(SUCCEEDED(hr), "Failed to create offscreen surface, hr %#x, case %u.\n", hr, i);
6102 memset(&ddsd, 0, sizeof(ddsd));
6103 ddsd.dwSize = sizeof(ddsd);
6104 hr = IDirectDrawSurface4_Lock(surface, NULL, &ddsd, 0, NULL);
6105 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
6106 addr = ddsd.lpSurface;
6107 hr = IDirectDrawSurface4_Unlock(surface, NULL);
6108 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
6110 memset(&ddsd, 0, sizeof(ddsd));
6111 ddsd.dwSize = sizeof(ddsd);
6112 hr = IDirectDrawSurface4_Lock(surface, NULL, &ddsd, DDLOCK_DISCARDCONTENTS, NULL);
6113 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
6114 discarded = ddsd.lpSurface != addr;
6115 hr = IDirectDrawSurface4_Unlock(surface, NULL);
6116 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
6118 hr = IDirectDrawSurface4_Blt(target, NULL, surface, NULL, DDBLT_WAIT, NULL);
6119 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
6121 memset(&ddsd, 0, sizeof(ddsd));
6122 ddsd.dwSize = sizeof(ddsd);
6123 hr = IDirectDrawSurface4_Lock(surface, NULL, &ddsd, DDLOCK_DISCARDCONTENTS, NULL);
6124 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
6125 discarded |= ddsd.lpSurface != addr;
6126 hr = IDirectDrawSurface4_Unlock(surface, NULL);
6127 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
6129 IDirectDrawSurface4_Release(surface);
6131 /* Windows 7 reliably changes the address of surfaces that are discardable (Nvidia Kepler,
6132 * AMD r500, evergreen). Windows XP, at least on AMD r200, does not. */
6133 ok(!discarded || tests[i].discard, "Expected surface not to be discarded, case %u\n", i);
6136 IDirectDrawSurface4_Release(target);
6137 IDirectDraw4_Release(ddraw);
6138 IDirect3D3_Release(d3d);
6139 IDirect3DDevice3_Release(device);
6140 DestroyWindow(window);
6143 static void test_flip(void)
6145 const DWORD placement = DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY | DDSCAPS_SYSTEMMEMORY;
6146 IDirectDrawSurface4 *frontbuffer, *backbuffer1, *backbuffer2, *backbuffer3, *surface;
6147 DDSCAPS2 caps = {DDSCAPS_FLIP, 0, 0, {0}};
6148 DDSURFACEDESC2 surface_desc;
6149 BOOL sysmem_primary;
6150 IDirectDraw4 *ddraw;
6151 DWORD expected_caps;
6152 unsigned int i;
6153 D3DCOLOR color;
6154 ULONG refcount;
6155 HWND window;
6156 DDBLTFX fx;
6157 HRESULT hr;
6159 static const struct
6161 const char *name;
6162 DWORD caps;
6164 test_data[] =
6166 {"PRIMARYSURFACE", DDSCAPS_PRIMARYSURFACE},
6167 {"OFFSCREENPLAIN", DDSCAPS_OFFSCREENPLAIN},
6168 {"TEXTURE", DDSCAPS_TEXTURE},
6171 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
6172 0, 0, 640, 480, 0, 0, 0, 0);
6173 ddraw = create_ddraw();
6174 ok(!!ddraw, "Failed to create a ddraw object.\n");
6176 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
6177 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6179 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
6181 /* Creating a flippable texture induces a BSoD on some versions of the
6182 * Intel graphics driver. At least Intel GMA 950 with driver version
6183 * 6.14.10.4926 on Windows XP SP3 is affected. */
6184 if ((test_data[i].caps & DDSCAPS_TEXTURE) && ddraw_is_intel(ddraw))
6186 win_skip("Skipping flippable texture test.\n");
6187 continue;
6190 memset(&surface_desc, 0, sizeof(surface_desc));
6191 surface_desc.dwSize = sizeof(surface_desc);
6192 surface_desc.dwFlags = DDSD_CAPS;
6193 if (!(test_data[i].caps & DDSCAPS_PRIMARYSURFACE))
6194 surface_desc.dwFlags |= DDSD_WIDTH | DDSD_HEIGHT;
6195 surface_desc.ddsCaps.dwCaps = DDSCAPS_COMPLEX | DDSCAPS_FLIP | test_data[i].caps;
6196 surface_desc.dwWidth = 512;
6197 surface_desc.dwHeight = 512;
6198 U5(surface_desc).dwBackBufferCount = 3;
6199 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &frontbuffer, NULL);
6200 ok(hr == DDERR_INVALIDCAPS, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
6202 surface_desc.ddsCaps.dwCaps &= ~DDSCAPS_FLIP;
6203 surface_desc.dwFlags |= DDSD_BACKBUFFERCOUNT;
6204 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &frontbuffer, NULL);
6205 ok(hr == DDERR_INVALIDCAPS, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
6207 surface_desc.ddsCaps.dwCaps &= ~DDSCAPS_COMPLEX;
6208 surface_desc.ddsCaps.dwCaps |= DDSCAPS_FLIP;
6209 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &frontbuffer, NULL);
6210 ok(hr == DDERR_INVALIDCAPS, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
6212 surface_desc.ddsCaps.dwCaps |= DDSCAPS_COMPLEX;
6213 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &frontbuffer, NULL);
6214 todo_wine_if(test_data[i].caps & DDSCAPS_TEXTURE)
6215 ok(SUCCEEDED(hr), "%s: Failed to create surface, hr %#x.\n", test_data[i].name, hr);
6216 if (FAILED(hr))
6217 continue;
6219 memset(&surface_desc, 0, sizeof(surface_desc));
6220 surface_desc.dwSize = sizeof(surface_desc);
6221 hr = IDirectDrawSurface4_GetSurfaceDesc(frontbuffer, &surface_desc);
6222 ok(SUCCEEDED(hr), "%s: Failed to get surface desc, hr %#x.\n", test_data[i].name, hr);
6223 expected_caps = DDSCAPS_FRONTBUFFER | DDSCAPS_COMPLEX | DDSCAPS_FLIP | test_data[i].caps;
6224 if (test_data[i].caps & DDSCAPS_PRIMARYSURFACE)
6225 expected_caps |= DDSCAPS_VISIBLE;
6226 ok((surface_desc.ddsCaps.dwCaps & ~placement) == expected_caps,
6227 "%s: Got unexpected caps %#x.\n", test_data[i].name, surface_desc.ddsCaps.dwCaps);
6228 sysmem_primary = surface_desc.ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY;
6230 hr = IDirectDrawSurface4_GetAttachedSurface(frontbuffer, &caps, &backbuffer1);
6231 ok(SUCCEEDED(hr), "%s: Failed to get attached surface, hr %#x.\n", test_data[i].name, hr);
6232 memset(&surface_desc, 0, sizeof(surface_desc));
6233 surface_desc.dwSize = sizeof(surface_desc);
6234 hr = IDirectDrawSurface4_GetSurfaceDesc(backbuffer1, &surface_desc);
6235 ok(SUCCEEDED(hr), "%s: Failed to get surface desc, hr %#x.\n", test_data[i].name, hr);
6236 ok(!U5(surface_desc).dwBackBufferCount, "%s: Got unexpected back buffer count %u.\n",
6237 test_data[i].name, U5(surface_desc).dwBackBufferCount);
6238 expected_caps &= ~(DDSCAPS_VISIBLE | DDSCAPS_PRIMARYSURFACE | DDSCAPS_FRONTBUFFER);
6239 expected_caps |= DDSCAPS_BACKBUFFER;
6240 ok((surface_desc.ddsCaps.dwCaps & ~placement) == expected_caps,
6241 "%s: Got unexpected caps %#x.\n", test_data[i].name, surface_desc.ddsCaps.dwCaps);
6243 hr = IDirectDrawSurface4_GetAttachedSurface(backbuffer1, &caps, &backbuffer2);
6244 ok(SUCCEEDED(hr), "%s: Failed to get attached surface, hr %#x.\n", test_data[i].name, hr);
6245 memset(&surface_desc, 0, sizeof(surface_desc));
6246 surface_desc.dwSize = sizeof(surface_desc);
6247 hr = IDirectDrawSurface4_GetSurfaceDesc(backbuffer2, &surface_desc);
6248 ok(SUCCEEDED(hr), "%s: Failed to get surface desc, hr %#x.\n", test_data[i].name, hr);
6249 ok(!U5(surface_desc).dwBackBufferCount, "%s: Got unexpected back buffer count %u.\n",
6250 test_data[i].name, U5(surface_desc).dwBackBufferCount);
6251 expected_caps &= ~DDSCAPS_BACKBUFFER;
6252 ok((surface_desc.ddsCaps.dwCaps & ~placement) == expected_caps,
6253 "%s: Got unexpected caps %#x.\n", test_data[i].name, surface_desc.ddsCaps.dwCaps);
6255 hr = IDirectDrawSurface4_GetAttachedSurface(backbuffer2, &caps, &backbuffer3);
6256 ok(SUCCEEDED(hr), "%s: Failed to get attached surface, hr %#x.\n", test_data[i].name, hr);
6257 memset(&surface_desc, 0, sizeof(surface_desc));
6258 surface_desc.dwSize = sizeof(surface_desc);
6259 hr = IDirectDrawSurface4_GetSurfaceDesc(backbuffer3, &surface_desc);
6260 ok(SUCCEEDED(hr), "%s: Failed to get surface desc, hr %#x.\n", test_data[i].name, hr);
6261 ok(!U5(surface_desc).dwBackBufferCount, "%s: Got unexpected back buffer count %u.\n",
6262 test_data[i].name, U5(surface_desc).dwBackBufferCount);
6263 ok((surface_desc.ddsCaps.dwCaps & ~placement) == expected_caps,
6264 "%s: Got unexpected caps %#x.\n", test_data[i].name, surface_desc.ddsCaps.dwCaps);
6266 hr = IDirectDrawSurface4_GetAttachedSurface(backbuffer3, &caps, &surface);
6267 ok(SUCCEEDED(hr), "%s: Failed to get attached surface, hr %#x.\n", test_data[i].name, hr);
6268 ok(surface == frontbuffer, "%s: Got unexpected surface %p, expected %p.\n",
6269 test_data[i].name, surface, frontbuffer);
6270 IDirectDrawSurface4_Release(surface);
6272 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL | DDSCL_FULLSCREEN);
6273 ok(SUCCEEDED(hr), "%s: Failed to set cooperative level, hr %#x.\n", test_data[i].name, hr);
6274 hr = IDirectDrawSurface4_IsLost(frontbuffer);
6275 ok(hr == DD_OK, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
6276 hr = IDirectDrawSurface4_Flip(frontbuffer, NULL, DDFLIP_WAIT);
6277 if (test_data[i].caps & DDSCAPS_PRIMARYSURFACE)
6278 ok(hr == DDERR_NOEXCLUSIVEMODE, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
6279 else
6280 ok(SUCCEEDED(hr), "%s: Failed to flip, hr %#x.\n", test_data[i].name, hr);
6281 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
6282 ok(SUCCEEDED(hr), "%s: Failed to set cooperative level, hr %#x.\n", test_data[i].name, hr);
6283 hr = IDirectDrawSurface4_IsLost(frontbuffer);
6284 todo_wine ok(hr == DDERR_SURFACELOST, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
6285 hr = IDirectDraw4_RestoreAllSurfaces(ddraw);
6286 ok(SUCCEEDED(hr), "%s: Failed to restore surfaces, hr %#x.\n", test_data[i].name, hr);
6288 memset(&surface_desc, 0, sizeof(surface_desc));
6289 surface_desc.dwSize = sizeof(surface_desc);
6290 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
6291 surface_desc.ddsCaps.dwCaps = 0;
6292 surface_desc.dwWidth = 640;
6293 surface_desc.dwHeight = 480;
6294 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
6295 ok(SUCCEEDED(hr), "%s: Failed to create surface, hr %#x.\n", test_data[i].name, hr);
6296 hr = IDirectDrawSurface4_Flip(frontbuffer, surface, DDFLIP_WAIT);
6297 ok(hr == DDERR_NOTFLIPPABLE, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
6298 IDirectDrawSurface4_Release(surface);
6300 hr = IDirectDrawSurface4_Flip(frontbuffer, frontbuffer, DDFLIP_WAIT);
6301 ok(hr == DDERR_NOTFLIPPABLE, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
6302 hr = IDirectDrawSurface4_Flip(backbuffer1, NULL, DDFLIP_WAIT);
6303 ok(hr == DDERR_NOTFLIPPABLE, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
6304 hr = IDirectDrawSurface4_Flip(backbuffer2, NULL, DDFLIP_WAIT);
6305 ok(hr == DDERR_NOTFLIPPABLE, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
6306 hr = IDirectDrawSurface4_Flip(backbuffer3, NULL, DDFLIP_WAIT);
6307 ok(hr == DDERR_NOTFLIPPABLE, "%s: Got unexpected hr %#x.\n", test_data[i].name, hr);
6309 memset(&fx, 0, sizeof(fx));
6310 fx.dwSize = sizeof(fx);
6311 U5(fx).dwFillColor = 0xffff0000;
6312 hr = IDirectDrawSurface4_Blt(backbuffer1, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
6313 ok(SUCCEEDED(hr), "%s: Failed to fill surface, hr %#x.\n", test_data[i].name, hr);
6314 U5(fx).dwFillColor = 0xff00ff00;
6315 hr = IDirectDrawSurface4_Blt(backbuffer2, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
6316 ok(SUCCEEDED(hr), "%s: Failed to fill surface, hr %#x.\n", test_data[i].name, hr);
6317 U5(fx).dwFillColor = 0xff0000ff;
6318 hr = IDirectDrawSurface4_Blt(backbuffer3, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
6319 ok(SUCCEEDED(hr), "%s: Failed to fill surface, hr %#x.\n", test_data[i].name, hr);
6321 hr = IDirectDrawSurface4_Flip(frontbuffer, NULL, DDFLIP_WAIT);
6322 ok(SUCCEEDED(hr), "%s: Failed to flip, hr %#x.\n", test_data[i].name, hr);
6323 color = get_surface_color(backbuffer1, 320, 240);
6324 /* The testbot seems to just copy the contents of one surface to all the
6325 * others, instead of properly flipping. */
6326 ok(compare_color(color, 0x0000ff00, 1) || broken(sysmem_primary && compare_color(color, 0x000000ff, 1)),
6327 "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
6328 color = get_surface_color(backbuffer2, 320, 240);
6329 ok(compare_color(color, 0x000000ff, 1), "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
6330 U5(fx).dwFillColor = 0xffff0000;
6331 hr = IDirectDrawSurface4_Blt(backbuffer3, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
6332 ok(SUCCEEDED(hr), "%s: Failed to fill surface, hr %#x.\n", test_data[i].name, hr);
6334 hr = IDirectDrawSurface4_Flip(frontbuffer, NULL, DDFLIP_WAIT);
6335 ok(SUCCEEDED(hr), "%s: Failed to flip, hr %#x.\n", test_data[i].name, hr);
6336 color = get_surface_color(backbuffer1, 320, 240);
6337 ok(compare_color(color, 0x000000ff, 1) || broken(sysmem_primary && compare_color(color, 0x00ff0000, 1)),
6338 "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
6339 color = get_surface_color(backbuffer2, 320, 240);
6340 ok(compare_color(color, 0x00ff0000, 1), "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
6341 U5(fx).dwFillColor = 0xff00ff00;
6342 hr = IDirectDrawSurface4_Blt(backbuffer3, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
6343 ok(SUCCEEDED(hr), "%s: Failed to fill surface, hr %#x.\n", test_data[i].name, hr);
6345 hr = IDirectDrawSurface4_Flip(frontbuffer, NULL, DDFLIP_WAIT);
6346 ok(SUCCEEDED(hr), "%s: Failed to flip, hr %#x.\n", test_data[i].name, hr);
6347 color = get_surface_color(backbuffer1, 320, 240);
6348 ok(compare_color(color, 0x00ff0000, 1) || broken(sysmem_primary && compare_color(color, 0x0000ff00, 1)),
6349 "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
6350 color = get_surface_color(backbuffer2, 320, 240);
6351 ok(compare_color(color, 0x0000ff00, 1), "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
6352 U5(fx).dwFillColor = 0xff0000ff;
6353 hr = IDirectDrawSurface4_Blt(backbuffer3, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
6354 ok(SUCCEEDED(hr), "%s: Failed to fill surface, hr %#x.\n", test_data[i].name, hr);
6356 hr = IDirectDrawSurface4_Flip(frontbuffer, backbuffer1, DDFLIP_WAIT);
6357 ok(SUCCEEDED(hr), "%s: Failed to flip, hr %#x.\n", test_data[i].name, hr);
6358 color = get_surface_color(backbuffer2, 320, 240);
6359 ok(compare_color(color, 0x0000ff00, 1) || broken(sysmem_primary && compare_color(color, 0x000000ff, 1)),
6360 "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
6361 color = get_surface_color(backbuffer3, 320, 240);
6362 ok(compare_color(color, 0x000000ff, 1), "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
6363 U5(fx).dwFillColor = 0xffff0000;
6364 hr = IDirectDrawSurface4_Blt(backbuffer1, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
6365 ok(SUCCEEDED(hr), "%s: Failed to fill surface, hr %#x.\n", test_data[i].name, hr);
6367 hr = IDirectDrawSurface4_Flip(frontbuffer, backbuffer2, DDFLIP_WAIT);
6368 ok(SUCCEEDED(hr), "%s: Failed to flip, hr %#x.\n", test_data[i].name, hr);
6369 color = get_surface_color(backbuffer1, 320, 240);
6370 ok(compare_color(color, 0x00ff0000, 1), "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
6371 color = get_surface_color(backbuffer3, 320, 240);
6372 ok(compare_color(color, 0x000000ff, 1) || broken(sysmem_primary && compare_color(color, 0x00ff0000, 1)),
6373 "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
6374 U5(fx).dwFillColor = 0xff00ff00;
6375 hr = IDirectDrawSurface4_Blt(backbuffer2, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
6376 ok(SUCCEEDED(hr), "%s: Failed to fill surface, hr %#x.\n", test_data[i].name, hr);
6378 hr = IDirectDrawSurface4_Flip(frontbuffer, backbuffer3, DDFLIP_WAIT);
6379 ok(SUCCEEDED(hr), "%s: Failed to flip, hr %#x.\n", test_data[i].name, hr);
6380 color = get_surface_color(backbuffer1, 320, 240);
6381 ok(compare_color(color, 0x00ff0000, 1) || broken(sysmem_primary && compare_color(color, 0x0000ff00, 1)),
6382 "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
6383 color = get_surface_color(backbuffer2, 320, 240);
6384 ok(compare_color(color, 0x0000ff00, 1), "%s: Got unexpected color 0x%08x.\n", test_data[i].name, color);
6386 IDirectDrawSurface4_Release(backbuffer3);
6387 IDirectDrawSurface4_Release(backbuffer2);
6388 IDirectDrawSurface4_Release(backbuffer1);
6389 IDirectDrawSurface4_Release(frontbuffer);
6392 refcount = IDirectDraw4_Release(ddraw);
6393 ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount);
6394 DestroyWindow(window);
6397 static void reset_ddsd(DDSURFACEDESC2 *ddsd)
6399 memset(ddsd, 0, sizeof(*ddsd));
6400 ddsd->dwSize = sizeof(*ddsd);
6403 static void test_set_surface_desc(void)
6405 IDirectDraw4 *ddraw;
6406 HWND window;
6407 HRESULT hr;
6408 DDSURFACEDESC2 ddsd;
6409 IDirectDrawSurface4 *surface;
6410 BYTE data[16*16*4];
6411 ULONG ref;
6412 unsigned int i;
6413 static const struct
6415 DWORD caps, caps2;
6416 BOOL supported;
6417 const char *name;
6419 invalid_caps_tests[] =
6421 {DDSCAPS_VIDEOMEMORY, 0, FALSE, "videomemory plain"},
6422 {DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, 0, TRUE, "systemmemory texture"},
6423 {DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, FALSE, "managed texture"},
6424 {DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, FALSE, "managed texture"},
6425 {DDSCAPS_PRIMARYSURFACE | DDSCAPS_SYSTEMMEMORY, 0, FALSE, "systemmemory primary"},
6428 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
6429 0, 0, 640, 480, 0, 0, 0, 0);
6430 ddraw = create_ddraw();
6431 ok(!!ddraw, "Failed to create a ddraw object.\n");
6432 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6433 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6435 reset_ddsd(&ddsd);
6436 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_PIXELFORMAT;
6437 ddsd.dwWidth = 8;
6438 ddsd.dwHeight = 8;
6439 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
6440 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
6441 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
6442 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
6443 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
6444 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000ff;
6445 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
6447 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
6448 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6450 reset_ddsd(&ddsd);
6451 ddsd.dwFlags = DDSD_LPSURFACE;
6452 ddsd.lpSurface = data;
6453 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
6454 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
6456 /* Redundantly setting the same lpSurface is not an error. */
6457 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
6458 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
6459 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &ddsd);
6460 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
6461 ok(!(ddsd.dwFlags & DDSD_LPSURFACE), "DDSD_LPSURFACE is set.\n");
6462 ok(ddsd.lpSurface == NULL, "lpSurface is %p, expected NULL.\n", ddsd.lpSurface);
6464 hr = IDirectDrawSurface4_Lock(surface, NULL, &ddsd, 0, NULL);
6465 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
6466 ok(!(ddsd.dwFlags & DDSD_LPSURFACE), "DDSD_LPSURFACE is set.\n");
6467 ok(ddsd.lpSurface == data, "lpSurface is %p, expected %p.\n", data, data);
6468 hr = IDirectDrawSurface4_Unlock(surface, NULL);
6469 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
6471 reset_ddsd(&ddsd);
6472 ddsd.dwFlags = DDSD_LPSURFACE;
6473 ddsd.lpSurface = data;
6474 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 1);
6475 ok(hr == DDERR_INVALIDPARAMS, "SetSurfaceDesc with flags=1 returned %#x.\n", hr);
6477 ddsd.lpSurface = NULL;
6478 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
6479 ok(hr == DDERR_INVALIDPARAMS, "Setting lpSurface=NULL returned %#x.\n", hr);
6481 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, NULL, 0);
6482 ok(hr == DDERR_INVALIDPARAMS, "SetSurfaceDesc with NULL desc returned %#x.\n", hr);
6484 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &ddsd);
6485 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
6486 ok(ddsd.ddsCaps.dwCaps == (DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN),
6487 "Got unexpected caps %#x.\n", ddsd.ddsCaps.dwCaps);
6488 ok(ddsd.ddsCaps.dwCaps2 == 0, "Got unexpected caps2 %#x.\n", 0);
6490 /* Setting the caps is an error. This also means the original description cannot be reapplied. */
6491 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
6492 ok(hr == DDERR_INVALIDPARAMS, "Setting the original desc returned %#x.\n", hr);
6494 ddsd.dwFlags = DDSD_CAPS;
6495 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
6496 ok(hr == DDERR_INVALIDPARAMS, "Setting DDSD_CAPS returned %#x.\n", hr);
6498 /* dwCaps = 0 is allowed, but ignored. Caps2 can be anything and is ignored too. */
6499 ddsd.dwFlags = DDSD_CAPS | DDSD_LPSURFACE;
6500 ddsd.lpSurface = data;
6501 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
6502 ok(hr == DDERR_INVALIDCAPS, "Setting DDSD_CAPS returned %#x.\n", hr);
6503 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
6504 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
6505 ok(hr == DDERR_INVALIDCAPS, "Setting DDSD_CAPS returned %#x.\n", hr);
6506 ddsd.ddsCaps.dwCaps = 0;
6507 ddsd.ddsCaps.dwCaps2 = 0xdeadbeef;
6508 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
6509 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
6511 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &ddsd);
6512 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
6513 ok(ddsd.ddsCaps.dwCaps == (DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN),
6514 "Got unexpected caps %#x.\n", ddsd.ddsCaps.dwCaps);
6515 ok(ddsd.ddsCaps.dwCaps2 == 0, "Got unexpected caps2 %#x.\n", 0);
6517 /* Setting the height is allowed, but it cannot be set to 0, and only if LPSURFACE is set too. */
6518 reset_ddsd(&ddsd);
6519 ddsd.dwFlags = DDSD_HEIGHT;
6520 ddsd.dwHeight = 16;
6521 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
6522 ok(hr == DDERR_INVALIDPARAMS, "Setting height without lpSurface returned %#x.\n", hr);
6524 ddsd.lpSurface = data;
6525 ddsd.dwFlags = DDSD_HEIGHT | DDSD_LPSURFACE;
6526 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
6527 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
6529 ddsd.dwHeight = 0;
6530 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
6531 ok(hr == DDERR_INVALIDPARAMS, "Setting height=0 returned %#x.\n", hr);
6533 reset_ddsd(&ddsd);
6534 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &ddsd);
6535 ok(SUCCEEDED(hr), "GetSurfaceDesc failed, hr %#x.\n", hr);
6536 ok(ddsd.dwWidth == 8, "SetSurfaceDesc: Expected width 8, got %u.\n", ddsd.dwWidth);
6537 ok(ddsd.dwHeight == 16, "SetSurfaceDesc: Expected height 16, got %u.\n", ddsd.dwHeight);
6539 /* Pitch and width can be set, but only together, and only with LPSURFACE. They must not be 0 */
6540 reset_ddsd(&ddsd);
6541 ddsd.dwFlags = DDSD_PITCH;
6542 U1(ddsd).lPitch = 8 * 4;
6543 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
6544 ok(hr == DDERR_INVALIDPARAMS, "Setting pitch without lpSurface or width returned %#x.\n", hr);
6546 ddsd.dwFlags = DDSD_WIDTH;
6547 ddsd.dwWidth = 16;
6548 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
6549 ok(hr == DDERR_INVALIDPARAMS, "Setting width without lpSurface or pitch returned %#x.\n", hr);
6551 ddsd.dwFlags = DDSD_PITCH | DDSD_LPSURFACE;
6552 ddsd.lpSurface = data;
6553 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
6554 ok(hr == DDERR_INVALIDPARAMS, "Setting pitch and lpSurface without width returned %#x.\n", hr);
6556 ddsd.dwFlags = DDSD_WIDTH | DDSD_LPSURFACE;
6557 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
6558 ok(hr == DDERR_INVALIDPARAMS, "Setting width and lpSurface without pitch returned %#x.\n", hr);
6560 ddsd.dwFlags = DDSD_WIDTH | DDSD_PITCH | DDSD_LPSURFACE;
6561 U1(ddsd).lPitch = 16 * 4;
6562 ddsd.dwWidth = 16;
6563 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
6564 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
6566 reset_ddsd(&ddsd);
6567 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &ddsd);
6568 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
6569 ok(ddsd.dwWidth == 16, "SetSurfaceDesc: Expected width 8, got %u.\n", ddsd.dwWidth);
6570 ok(ddsd.dwHeight == 16, "SetSurfaceDesc: Expected height 16, got %u.\n", ddsd.dwHeight);
6571 ok(U1(ddsd).lPitch == 16 * 4, "SetSurfaceDesc: Expected pitch 64, got %u.\n", U1(ddsd).lPitch);
6573 /* The pitch must be 32 bit aligned and > 0, but is not verified for sanity otherwise.
6575 * VMware rejects those calls, but all real drivers accept it. Mark the VMware behavior broken. */
6576 ddsd.dwFlags = DDSD_WIDTH | DDSD_PITCH | DDSD_LPSURFACE;
6577 U1(ddsd).lPitch = 4 * 4;
6578 ddsd.lpSurface = data;
6579 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
6580 ok(SUCCEEDED(hr) || broken(hr == DDERR_INVALIDPARAMS), "Failed to set surface desc, hr %#x.\n", hr);
6582 U1(ddsd).lPitch = 4;
6583 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
6584 ok(SUCCEEDED(hr) || broken(hr == DDERR_INVALIDPARAMS), "Failed to set surface desc, hr %#x.\n", hr);
6586 U1(ddsd).lPitch = 16 * 4 + 1;
6587 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
6588 ok(hr == DDERR_INVALIDPARAMS, "Setting misaligned pitch returned %#x.\n", hr);
6590 U1(ddsd).lPitch = 16 * 4 + 3;
6591 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
6592 ok(hr == DDERR_INVALIDPARAMS, "Setting misaligned pitch returned %#x.\n", hr);
6594 U1(ddsd).lPitch = -4;
6595 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
6596 ok(hr == DDERR_INVALIDPARAMS, "Setting negative pitch returned %#x.\n", hr);
6598 U1(ddsd).lPitch = 16 * 4;
6599 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
6600 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
6602 reset_ddsd(&ddsd);
6603 ddsd.dwFlags = DDSD_WIDTH | DDSD_PITCH | DDSD_LPSURFACE;
6604 U1(ddsd).lPitch = 0;
6605 ddsd.dwWidth = 16;
6606 ddsd.lpSurface = data;
6607 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
6608 ok(hr == DDERR_INVALIDPARAMS, "Setting zero pitch returned %#x.\n", hr);
6610 ddsd.dwFlags = DDSD_WIDTH | DDSD_PITCH | DDSD_LPSURFACE;
6611 U1(ddsd).lPitch = 16 * 4;
6612 ddsd.dwWidth = 0;
6613 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
6614 ok(hr == DDERR_INVALIDPARAMS, "Setting zero width returned %#x.\n", hr);
6616 /* Setting the pixelformat without LPSURFACE is an error, but with LPSURFACE it works. */
6617 ddsd.dwFlags = DDSD_PIXELFORMAT;
6618 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
6619 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
6620 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
6621 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
6622 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
6623 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000ff;
6624 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
6625 ok(hr == DDERR_INVALIDPARAMS, "Setting the pixel format returned %#x.\n", hr);
6627 ddsd.dwFlags = DDSD_PIXELFORMAT | DDSD_LPSURFACE;
6628 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
6629 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
6631 /* Can't set color keys. */
6632 reset_ddsd(&ddsd);
6633 ddsd.dwFlags = DDSD_CKSRCBLT;
6634 ddsd.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00ff0000;
6635 ddsd.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00ff0000;
6636 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
6637 ok(hr == DDERR_INVALIDPARAMS, "Setting ddckCKSrcBlt returned %#x.\n", hr);
6639 ddsd.dwFlags = DDSD_CKSRCBLT | DDSD_LPSURFACE;
6640 ddsd.lpSurface = data;
6641 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
6642 ok(hr == DDERR_INVALIDPARAMS, "Setting ddckCKSrcBlt returned %#x.\n", hr);
6644 IDirectDrawSurface4_Release(surface);
6646 /* SetSurfaceDesc needs systemmemory surfaces.
6648 * As a sidenote, fourcc surfaces aren't allowed in sysmem, thus testing DDSD_LINEARSIZE is moot. */
6649 for (i = 0; i < sizeof(invalid_caps_tests) / sizeof(*invalid_caps_tests); i++)
6651 reset_ddsd(&ddsd);
6652 ddsd.dwFlags = DDSD_CAPS;
6653 ddsd.ddsCaps.dwCaps = invalid_caps_tests[i].caps;
6654 ddsd.ddsCaps.dwCaps2 = invalid_caps_tests[i].caps2;
6655 if (!(invalid_caps_tests[i].caps & DDSCAPS_PRIMARYSURFACE))
6657 ddsd.dwFlags |= DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
6658 ddsd.dwWidth = 8;
6659 ddsd.dwHeight = 8;
6660 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
6661 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
6662 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
6663 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
6664 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
6665 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000ff;
6668 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
6669 ok(SUCCEEDED(hr) || hr == DDERR_NODIRECTDRAWHW, "Failed to create surface, hr %#x.\n", hr);
6670 if (FAILED(hr))
6672 skip("Cannot create a %s surface, skipping vidmem SetSurfaceDesc test.\n",
6673 invalid_caps_tests[i].name);
6674 goto done;
6677 reset_ddsd(&ddsd);
6678 ddsd.dwFlags = DDSD_LPSURFACE;
6679 ddsd.lpSurface = data;
6680 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
6681 if (invalid_caps_tests[i].supported)
6683 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
6685 else
6687 ok(hr == DDERR_INVALIDSURFACETYPE, "SetSurfaceDesc on a %s surface returned %#x.\n",
6688 invalid_caps_tests[i].name, hr);
6690 /* Check priority of error conditions. */
6691 ddsd.dwFlags = DDSD_WIDTH;
6692 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
6693 ok(hr == DDERR_INVALIDSURFACETYPE, "SetSurfaceDesc on a %s surface returned %#x.\n",
6694 invalid_caps_tests[i].name, hr);
6697 IDirectDrawSurface4_Release(surface);
6700 done:
6701 ref = IDirectDraw4_Release(ddraw);
6702 ok(ref == 0, "Ddraw object not properly released, refcount %u.\n", ref);
6703 DestroyWindow(window);
6706 static void test_user_memory_getdc(void)
6708 IDirectDraw4 *ddraw;
6709 HWND window;
6710 HRESULT hr;
6711 DDSURFACEDESC2 ddsd;
6712 IDirectDrawSurface4 *surface;
6713 DWORD data[16][16];
6714 HBITMAP bitmap;
6715 DIBSECTION dib;
6716 ULONG ref;
6717 int size;
6718 HDC dc;
6719 unsigned int x, y;
6721 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
6722 0, 0, 640, 480, 0, 0, 0, 0);
6723 ddraw = create_ddraw();
6724 ok(!!ddraw, "Failed to create a ddraw object.\n");
6726 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6727 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6729 reset_ddsd(&ddsd);
6730 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_PIXELFORMAT;
6731 ddsd.dwWidth = 16;
6732 ddsd.dwHeight = 16;
6733 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
6734 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
6735 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
6736 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
6737 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
6738 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000ff;
6739 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
6740 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
6741 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6743 memset(data, 0xaa, sizeof(data));
6744 reset_ddsd(&ddsd);
6745 ddsd.dwFlags = DDSD_LPSURFACE;
6746 ddsd.lpSurface = data;
6747 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
6748 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
6750 hr = IDirectDrawSurface4_GetDC(surface, &dc);
6751 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
6752 bitmap = GetCurrentObject(dc, OBJ_BITMAP);
6753 ok(!!bitmap, "Failed to get bitmap.\n");
6754 size = GetObjectA(bitmap, sizeof(dib), &dib);
6755 ok(size == sizeof(dib), "Got unexpected size %d.\n", size);
6756 ok(dib.dsBm.bmBits == data, "Got unexpected bits %p, expected %p.\n", dib.dsBm.bmBits, data);
6757 BitBlt(dc, 0, 0, 16, 8, NULL, 0, 0, WHITENESS);
6758 BitBlt(dc, 0, 8, 16, 8, NULL, 0, 0, BLACKNESS);
6759 hr = IDirectDrawSurface4_ReleaseDC(surface, dc);
6760 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
6762 ok(data[0][0] == 0xffffffff, "Expected color 0xffffffff, got %#x.\n", data[0][0]);
6763 ok(data[15][15] == 0x00000000, "Expected color 0x00000000, got %#x.\n", data[15][15]);
6765 ddsd.dwFlags = DDSD_LPSURFACE | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PITCH;
6766 ddsd.lpSurface = data;
6767 ddsd.dwWidth = 4;
6768 ddsd.dwHeight = 8;
6769 U1(ddsd).lPitch = sizeof(*data);
6770 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
6771 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
6773 memset(data, 0xaa, sizeof(data));
6774 hr = IDirectDrawSurface4_GetDC(surface, &dc);
6775 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
6776 BitBlt(dc, 0, 0, 4, 8, NULL, 0, 0, BLACKNESS);
6777 BitBlt(dc, 1, 1, 2, 2, NULL, 0, 0, WHITENESS);
6778 hr = IDirectDrawSurface4_ReleaseDC(surface, dc);
6779 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
6781 for (y = 0; y < 4; y++)
6783 for (x = 0; x < 4; x++)
6785 if ((x == 1 || x == 2) && (y == 1 || y == 2))
6786 ok(data[y][x] == 0xffffffff, "Expected color 0xffffffff on position %ux%u, got %#x.\n",
6787 x, y, data[y][x]);
6788 else
6789 ok(data[y][x] == 0x00000000, "Expected color 0x00000000 on position %ux%u, got %#x.\n",
6790 x, y, data[y][x]);
6793 ok(data[0][5] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 5x0, got %#x.\n",
6794 data[0][5]);
6795 ok(data[7][3] == 0x00000000, "Expected color 0x00000000 on position 3x7, got %#x.\n",
6796 data[7][3]);
6797 ok(data[7][4] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 4x7, got %#x.\n",
6798 data[7][4]);
6799 ok(data[8][0] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 0x8, got %#x.\n",
6800 data[8][0]);
6802 IDirectDrawSurface4_Release(surface);
6803 ref = IDirectDraw4_Release(ddraw);
6804 ok(ref == 0, "Ddraw object not properly released, refcount %u.\n", ref);
6805 DestroyWindow(window);
6808 static void test_sysmem_overlay(void)
6810 IDirectDraw4 *ddraw;
6811 HWND window;
6812 HRESULT hr;
6813 DDSURFACEDESC2 ddsd;
6814 IDirectDrawSurface4 *surface;
6815 ULONG ref;
6817 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
6818 0, 0, 640, 480, 0, 0, 0, 0);
6819 ddraw = create_ddraw();
6820 ok(!!ddraw, "Failed to create a ddraw object.\n");
6822 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6823 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6825 reset_ddsd(&ddsd);
6826 ddsd.dwFlags = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT;
6827 ddsd.dwWidth = 16;
6828 ddsd.dwHeight = 16;
6829 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OVERLAY;
6830 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
6831 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
6832 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
6833 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
6834 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
6835 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000ff;
6836 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
6837 ok(hr == DDERR_NOOVERLAYHW, "Got unexpected hr %#x.\n", hr);
6839 ref = IDirectDraw4_Release(ddraw);
6840 ok(ref == 0, "Ddraw object not properly released, refcount %u.\n", ref);
6841 DestroyWindow(window);
6844 static void test_primary_palette(void)
6846 DDSCAPS2 surface_caps = {DDSCAPS_FLIP, 0, 0, {0}};
6847 IDirectDrawSurface4 *primary, *backbuffer;
6848 PALETTEENTRY palette_entries[256];
6849 IDirectDrawPalette *palette, *tmp;
6850 DDSURFACEDESC2 surface_desc;
6851 IDirectDraw4 *ddraw;
6852 DWORD palette_caps;
6853 ULONG refcount;
6854 HWND window;
6855 HRESULT hr;
6857 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
6858 0, 0, 640, 480, 0, 0, 0, 0);
6859 ddraw = create_ddraw();
6860 ok(!!ddraw, "Failed to create a ddraw object.\n");
6861 if (FAILED(IDirectDraw4_SetDisplayMode(ddraw, 640, 480, 8, 0, 0)))
6863 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
6864 IDirectDraw4_Release(ddraw);
6865 DestroyWindow(window);
6866 return;
6868 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
6869 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6871 memset(&surface_desc, 0, sizeof(surface_desc));
6872 surface_desc.dwSize = sizeof(surface_desc);
6873 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
6874 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
6875 U5(surface_desc).dwBackBufferCount = 1;
6876 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &primary, NULL);
6877 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6878 hr = IDirectDrawSurface4_GetAttachedSurface(primary, &surface_caps, &backbuffer);
6879 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
6881 memset(palette_entries, 0, sizeof(palette_entries));
6882 hr = IDirectDraw4_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256, palette_entries, &palette, NULL);
6883 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
6884 refcount = get_refcount((IUnknown *)palette);
6885 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
6887 hr = IDirectDrawPalette_GetCaps(palette, &palette_caps);
6888 ok(SUCCEEDED(hr), "Failed to get palette caps, hr %#x.\n", hr);
6889 ok(palette_caps == (DDPCAPS_8BIT | DDPCAPS_ALLOW256), "Got unexpected palette caps %#x.\n", palette_caps);
6891 hr = IDirectDrawSurface4_SetPalette(primary, palette);
6892 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
6894 /* The Windows 8 testbot attaches the palette to the backbuffer as well,
6895 * and is generally somewhat broken with respect to 8 bpp / palette
6896 * handling. */
6897 if (SUCCEEDED(IDirectDrawSurface4_GetPalette(backbuffer, &tmp)))
6899 win_skip("Broken palette handling detected, skipping tests.\n");
6900 IDirectDrawPalette_Release(tmp);
6901 IDirectDrawPalette_Release(palette);
6902 /* The Windows 8 testbot keeps extra references to the primary and
6903 * backbuffer while in 8 bpp mode. */
6904 hr = IDirectDraw4_RestoreDisplayMode(ddraw);
6905 ok(SUCCEEDED(hr), "Failed to restore display mode, hr %#x.\n", hr);
6906 goto done;
6909 refcount = get_refcount((IUnknown *)palette);
6910 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
6912 hr = IDirectDrawPalette_GetCaps(palette, &palette_caps);
6913 ok(SUCCEEDED(hr), "Failed to get palette caps, hr %#x.\n", hr);
6914 ok(palette_caps == (DDPCAPS_8BIT | DDPCAPS_PRIMARYSURFACE | DDPCAPS_ALLOW256),
6915 "Got unexpected palette caps %#x.\n", palette_caps);
6917 hr = IDirectDrawSurface4_SetPalette(primary, NULL);
6918 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
6919 refcount = get_refcount((IUnknown *)palette);
6920 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
6922 hr = IDirectDrawPalette_GetCaps(palette, &palette_caps);
6923 ok(SUCCEEDED(hr), "Failed to get palette caps, hr %#x.\n", hr);
6924 ok(palette_caps == (DDPCAPS_8BIT | DDPCAPS_ALLOW256), "Got unexpected palette caps %#x.\n", palette_caps);
6926 hr = IDirectDrawSurface4_SetPalette(primary, palette);
6927 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
6928 refcount = get_refcount((IUnknown *)palette);
6929 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
6931 hr = IDirectDrawSurface4_GetPalette(primary, &tmp);
6932 ok(SUCCEEDED(hr), "Failed to get palette, hr %#x.\n", hr);
6933 ok(tmp == palette, "Got unexpected palette %p, expected %p.\n", tmp, palette);
6934 IDirectDrawPalette_Release(tmp);
6935 hr = IDirectDrawSurface4_GetPalette(backbuffer, &tmp);
6936 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x.\n", hr);
6938 refcount = IDirectDrawPalette_Release(palette);
6939 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
6940 refcount = IDirectDrawPalette_Release(palette);
6941 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6943 /* Note that this only seems to work when the palette is attached to the
6944 * primary surface. When attached to a regular surface, attempting to get
6945 * the palette here will cause an access violation. */
6946 hr = IDirectDrawSurface4_GetPalette(primary, &tmp);
6947 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x.\n", hr);
6949 hr = IDirectDrawSurface4_IsLost(primary);
6950 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
6952 memset(&surface_desc, 0, sizeof(surface_desc));
6953 surface_desc.dwSize = sizeof(surface_desc);
6954 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &surface_desc);
6955 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
6956 ok(surface_desc.dwWidth == 640, "Got unexpected surface width %u.\n", surface_desc.dwWidth);
6957 ok(surface_desc.dwHeight == 480, "Got unexpected surface height %u.\n", surface_desc.dwHeight);
6958 ok(U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount == 8, "Got unexpected bit count %u.\n",
6959 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount);
6961 hr = set_display_mode(ddraw, 640, 480);
6962 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
6964 memset(&surface_desc, 0, sizeof(surface_desc));
6965 surface_desc.dwSize = sizeof(surface_desc);
6966 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &surface_desc);
6967 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
6968 ok(surface_desc.dwWidth == 640, "Got unexpected surface width %u.\n", surface_desc.dwWidth);
6969 ok(surface_desc.dwHeight == 480, "Got unexpected surface height %u.\n", surface_desc.dwHeight);
6970 ok(U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount == 32
6971 || U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount == 24,
6972 "Got unexpected bit count %u.\n", U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount);
6974 hr = IDirectDrawSurface4_IsLost(primary);
6975 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
6976 hr = IDirectDrawSurface4_Restore(primary);
6977 ok(hr == DDERR_WRONGMODE, "Got unexpected hr %#x.\n", hr);
6978 hr = IDirectDrawSurface4_IsLost(primary);
6979 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
6981 memset(&surface_desc, 0, sizeof(surface_desc));
6982 surface_desc.dwSize = sizeof(surface_desc);
6983 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &surface_desc);
6984 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
6985 ok(surface_desc.dwWidth == 640, "Got unexpected surface width %u.\n", surface_desc.dwWidth);
6986 ok(surface_desc.dwHeight == 480, "Got unexpected surface height %u.\n", surface_desc.dwHeight);
6987 ok(U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount == 32
6988 || U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount == 24,
6989 "Got unexpected bit count %u.\n", U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount);
6991 done:
6992 refcount = IDirectDrawSurface4_Release(backbuffer);
6993 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
6994 refcount = IDirectDrawSurface4_Release(primary);
6995 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6996 refcount = IDirectDraw4_Release(ddraw);
6997 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6998 DestroyWindow(window);
7001 static HRESULT WINAPI surface_counter(IDirectDrawSurface4 *surface, DDSURFACEDESC2 *desc, void *context)
7003 UINT *surface_count = context;
7005 ++(*surface_count);
7006 IDirectDrawSurface_Release(surface);
7008 return DDENUMRET_OK;
7011 static void test_surface_attachment(void)
7013 IDirectDrawSurface4 *surface1, *surface2, *surface3, *surface4;
7014 IDirectDrawSurface *surface1v1, *surface2v1;
7015 DDSCAPS2 caps = {DDSCAPS_TEXTURE, 0, 0, {0}};
7016 DDSURFACEDESC2 surface_desc;
7017 IDirectDraw4 *ddraw;
7018 UINT surface_count;
7019 ULONG refcount;
7020 HWND window;
7021 HRESULT hr;
7023 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
7024 0, 0, 640, 480, 0, 0, 0, 0);
7025 ddraw = create_ddraw();
7026 ok(!!ddraw, "Failed to create a ddraw object.\n");
7027 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
7028 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
7030 memset(&surface_desc, 0, sizeof(surface_desc));
7031 surface_desc.dwSize = sizeof(surface_desc);
7032 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_MIPMAPCOUNT;
7033 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
7034 U2(surface_desc).dwMipMapCount = 3;
7035 surface_desc.dwWidth = 128;
7036 surface_desc.dwHeight = 128;
7037 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface1, NULL);
7038 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7040 hr = IDirectDrawSurface4_GetAttachedSurface(surface1, &caps, &surface2);
7041 ok(SUCCEEDED(hr), "Failed to get mip level, hr %#x.\n", hr);
7042 hr = IDirectDrawSurface4_GetAttachedSurface(surface2, &caps, &surface3);
7043 ok(SUCCEEDED(hr), "Failed to get mip level, hr %#x.\n", hr);
7044 hr = IDirectDrawSurface4_GetAttachedSurface(surface3, &caps, &surface4);
7045 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
7047 surface_count = 0;
7048 IDirectDrawSurface4_EnumAttachedSurfaces(surface1, &surface_count, surface_counter);
7049 ok(surface_count == 1, "Got unexpected surface_count %u.\n", surface_count);
7050 surface_count = 0;
7051 IDirectDrawSurface4_EnumAttachedSurfaces(surface2, &surface_count, surface_counter);
7052 ok(surface_count == 1, "Got unexpected surface_count %u.\n", surface_count);
7053 surface_count = 0;
7054 IDirectDrawSurface4_EnumAttachedSurfaces(surface3, &surface_count, surface_counter);
7055 ok(!surface_count, "Got unexpected surface_count %u.\n", surface_count);
7057 memset(&surface_desc, 0, sizeof(surface_desc));
7058 surface_desc.dwSize = sizeof(surface_desc);
7059 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
7060 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
7061 surface_desc.dwWidth = 16;
7062 surface_desc.dwHeight = 16;
7063 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface4, NULL);
7064 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7066 hr = IDirectDrawSurface4_AddAttachedSurface(surface1, surface4);
7067 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7068 hr = IDirectDrawSurface4_AddAttachedSurface(surface4, surface1);
7069 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7070 hr = IDirectDrawSurface4_AddAttachedSurface(surface3, surface4);
7071 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7072 hr = IDirectDrawSurface4_AddAttachedSurface(surface4, surface3);
7073 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7074 hr = IDirectDrawSurface4_AddAttachedSurface(surface2, surface4);
7075 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7076 hr = IDirectDrawSurface4_AddAttachedSurface(surface4, surface2);
7077 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7079 IDirectDrawSurface4_Release(surface4);
7081 memset(&surface_desc, 0, sizeof(surface_desc));
7082 surface_desc.dwSize = sizeof(surface_desc);
7083 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
7084 surface_desc.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
7085 surface_desc.dwWidth = 16;
7086 surface_desc.dwHeight = 16;
7087 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface4, NULL);
7088 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7090 if (SUCCEEDED(hr = IDirectDrawSurface4_AddAttachedSurface(surface1, surface4)))
7092 skip("Running on refrast, skipping some tests.\n");
7093 hr = IDirectDrawSurface4_DeleteAttachedSurface(surface1, 0, surface4);
7094 ok(SUCCEEDED(hr), "Failed to detach surface, hr %#x.\n", hr);
7096 else
7098 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7099 hr = IDirectDrawSurface4_AddAttachedSurface(surface4, surface1);
7100 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7101 hr = IDirectDrawSurface4_AddAttachedSurface(surface3, surface4);
7102 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7103 hr = IDirectDrawSurface4_AddAttachedSurface(surface4, surface3);
7104 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7105 hr = IDirectDrawSurface4_AddAttachedSurface(surface2, surface4);
7106 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7107 hr = IDirectDrawSurface4_AddAttachedSurface(surface4, surface2);
7108 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7111 IDirectDrawSurface4_Release(surface4);
7112 IDirectDrawSurface4_Release(surface3);
7113 IDirectDrawSurface4_Release(surface2);
7114 IDirectDrawSurface4_Release(surface1);
7116 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
7117 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
7119 /* Try a single primary and two offscreen plain surfaces. */
7120 memset(&surface_desc, 0, sizeof(surface_desc));
7121 surface_desc.dwSize = sizeof(surface_desc);
7122 surface_desc.dwFlags = DDSD_CAPS;
7123 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
7124 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface1, NULL);
7125 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7127 memset(&surface_desc, 0, sizeof(surface_desc));
7128 surface_desc.dwSize = sizeof(surface_desc);
7129 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
7130 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
7131 surface_desc.dwWidth = registry_mode.dmPelsWidth;
7132 surface_desc.dwHeight = registry_mode.dmPelsHeight;
7133 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface2, NULL);
7134 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7136 memset(&surface_desc, 0, sizeof(surface_desc));
7137 surface_desc.dwSize = sizeof(surface_desc);
7138 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
7139 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
7140 surface_desc.dwWidth = registry_mode.dmPelsWidth;
7141 surface_desc.dwHeight = registry_mode.dmPelsHeight;
7142 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface3, NULL);
7143 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7145 /* This one has a different size. */
7146 memset(&surface_desc, 0, sizeof(surface_desc));
7147 surface_desc.dwSize = sizeof(surface_desc);
7148 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
7149 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
7150 surface_desc.dwWidth = 128;
7151 surface_desc.dwHeight = 128;
7152 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface4, NULL);
7153 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7155 hr = IDirectDrawSurface4_AddAttachedSurface(surface1, surface2);
7156 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
7157 /* Try the reverse without detaching first. */
7158 hr = IDirectDrawSurface4_AddAttachedSurface(surface2, surface1);
7159 ok(hr == DDERR_SURFACEALREADYATTACHED, "Got unexpected hr %#x.\n", hr);
7160 hr = IDirectDrawSurface4_DeleteAttachedSurface(surface1, 0, surface2);
7161 ok(SUCCEEDED(hr), "Failed to detach surface, hr %#x.\n", hr);
7163 hr = IDirectDrawSurface4_AddAttachedSurface(surface2, surface1);
7164 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
7165 /* Try to detach reversed. */
7166 hr = IDirectDrawSurface4_DeleteAttachedSurface(surface1, 0, surface2);
7167 ok(hr == DDERR_CANNOTDETACHSURFACE, "Got unexpected hr %#x.\n", hr);
7168 hr = IDirectDrawSurface4_DeleteAttachedSurface(surface2, 0, surface1);
7169 ok(SUCCEEDED(hr), "Failed to detach surface, hr %#x.\n", hr);
7171 hr = IDirectDrawSurface4_AddAttachedSurface(surface2, surface3);
7172 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
7173 hr = IDirectDrawSurface4_DeleteAttachedSurface(surface2, 0, surface3);
7174 ok(SUCCEEDED(hr), "Failed to detach surface, hr %#x.\n", hr);
7176 hr = IDirectDrawSurface4_AddAttachedSurface(surface1, surface4);
7177 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7178 hr = IDirectDrawSurface4_AddAttachedSurface(surface4, surface1);
7179 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7181 IDirectDrawSurface4_Release(surface4);
7182 IDirectDrawSurface4_Release(surface3);
7183 IDirectDrawSurface4_Release(surface2);
7184 IDirectDrawSurface4_Release(surface1);
7186 /* Test DeleteAttachedSurface() and automatic detachment of attached surfaces on release. */
7187 memset(&surface_desc, 0, sizeof(surface_desc));
7188 surface_desc.dwSize = sizeof(surface_desc);
7189 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
7190 surface_desc.dwWidth = 64;
7191 surface_desc.dwHeight = 64;
7192 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
7193 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
7194 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB; /* D3DFMT_R5G6B5 */
7195 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 16;
7196 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0xf800;
7197 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x07e0;
7198 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x001f;
7199 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface1, NULL);
7200 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7201 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface3, NULL);
7202 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7204 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
7205 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_ZBUFFER;
7206 U1(U4(surface_desc).ddpfPixelFormat).dwZBufferBitDepth = 16;
7207 U3(U4(surface_desc).ddpfPixelFormat).dwZBitMask = 0x0000ffff;
7208 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface2, NULL);
7209 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7211 hr = IDirectDrawSurface4_QueryInterface(surface1, &IID_IDirectDrawSurface, (void **)&surface1v1);
7212 ok(SUCCEEDED(hr), "Failed to get interface, hr %#x.\n", hr);
7213 hr = IDirectDrawSurface4_QueryInterface(surface2, &IID_IDirectDrawSurface, (void **)&surface2v1);
7214 ok(SUCCEEDED(hr), "Failed to get interface, hr %#x.\n", hr);
7216 hr = IDirectDrawSurface4_AddAttachedSurface(surface1, surface2);
7217 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
7218 refcount = get_refcount((IUnknown *)surface2);
7219 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
7220 refcount = get_refcount((IUnknown *)surface2v1);
7221 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
7222 hr = IDirectDrawSurface4_AddAttachedSurface(surface1, surface2);
7223 ok(hr == DDERR_SURFACEALREADYATTACHED, "Got unexpected hr %#x.\n", hr);
7224 hr = IDirectDrawSurface_AddAttachedSurface(surface1v1, surface2v1);
7225 todo_wine ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
7226 hr = IDirectDrawSurface_DeleteAttachedSurface(surface1v1, 0, surface2v1);
7227 ok(hr == DDERR_SURFACENOTATTACHED, "Got unexpected hr %#x.\n", hr);
7229 /* Attaching while already attached to other surface. */
7230 hr = IDirectDrawSurface4_AddAttachedSurface(surface3, surface2);
7231 todo_wine ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
7232 hr = IDirectDrawSurface4_DeleteAttachedSurface(surface3, 0, surface2);
7233 todo_wine ok(SUCCEEDED(hr), "Failed to detach surface, hr %#x.\n", hr);
7234 IDirectDrawSurface4_Release(surface3);
7236 hr = IDirectDrawSurface4_DeleteAttachedSurface(surface1, 0, surface2);
7237 ok(SUCCEEDED(hr), "Failed to detach surface, hr %#x.\n", hr);
7238 refcount = get_refcount((IUnknown *)surface2);
7239 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
7240 refcount = get_refcount((IUnknown *)surface2v1);
7241 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
7243 /* DeleteAttachedSurface() when attaching via IDirectDrawSurface. */
7244 hr = IDirectDrawSurface_AddAttachedSurface(surface1v1, surface2v1);
7245 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
7246 hr = IDirectDrawSurface4_DeleteAttachedSurface(surface1, 0, surface2);
7247 ok(hr == DDERR_SURFACENOTATTACHED, "Got unexpected hr %#x.\n", hr);
7248 hr = IDirectDrawSurface_DeleteAttachedSurface(surface1v1, 0, surface2v1);
7249 ok(SUCCEEDED(hr), "Failed to detach surface, hr %#x.\n", hr);
7250 refcount = IDirectDrawSurface4_Release(surface2);
7251 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7252 refcount = IDirectDrawSurface4_Release(surface1);
7253 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7255 /* Automatic detachment on release. */
7256 hr = IDirectDrawSurface_AddAttachedSurface(surface1v1, surface2v1);
7257 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
7258 refcount = get_refcount((IUnknown *)surface2v1);
7259 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
7260 refcount = IDirectDrawSurface_Release(surface1v1);
7261 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7262 refcount = IDirectDrawSurface_Release(surface2v1);
7263 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7264 refcount = IDirectDraw4_Release(ddraw);
7265 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7266 DestroyWindow(window);
7269 static void test_private_data(void)
7271 IDirectDraw4 *ddraw;
7272 IDirectDrawSurface4 *surface, *surface2;
7273 DDSURFACEDESC2 surface_desc;
7274 ULONG refcount, refcount2, refcount3;
7275 IUnknown *ptr;
7276 DWORD size = sizeof(ptr);
7277 HRESULT hr;
7278 HWND window;
7279 DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, {0}};
7280 DWORD data[] = {1, 2, 3, 4};
7281 DDCAPS hal_caps;
7282 static const GUID ddraw_private_data_test_guid =
7284 0xfdb37466,
7285 0x428f,
7286 0x4edf,
7287 {0xa3,0x7f,0x9b,0x1d,0xf4,0x88,0xc5,0xfc}
7289 static const GUID ddraw_private_data_test_guid2 =
7291 0x2e5afac2,
7292 0x87b5,
7293 0x4c10,
7294 {0x9b,0x4b,0x89,0xd7,0xd1,0x12,0xe7,0x2b}
7297 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
7298 0, 0, 640, 480, 0, 0, 0, 0);
7299 ddraw = create_ddraw();
7300 ok(!!ddraw, "Failed to create a ddraw object.\n");
7301 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
7302 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
7304 reset_ddsd(&surface_desc);
7305 surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
7306 surface_desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
7307 surface_desc.dwHeight = 4;
7308 surface_desc.dwWidth = 4;
7309 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7310 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7312 /* NULL pointers are not valid, but don't cause a crash. */
7313 hr = IDirectDrawSurface4_SetPrivateData(surface, &ddraw_private_data_test_guid, NULL,
7314 sizeof(IUnknown *), DDSPD_IUNKNOWNPOINTER);
7315 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7316 hr = IDirectDrawSurface4_SetPrivateData(surface, &ddraw_private_data_test_guid, NULL, 0, 0);
7317 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7318 hr = IDirectDrawSurface4_SetPrivateData(surface, &ddraw_private_data_test_guid, NULL, 1, 0);
7319 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7321 /* DDSPD_IUNKNOWNPOINTER needs sizeof(IUnknown *) bytes of data. */
7322 hr = IDirectDrawSurface4_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
7323 0, DDSPD_IUNKNOWNPOINTER);
7324 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7325 hr = IDirectDrawSurface4_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
7326 5, DDSPD_IUNKNOWNPOINTER);
7327 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7328 hr = IDirectDrawSurface4_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
7329 sizeof(ddraw) * 2, DDSPD_IUNKNOWNPOINTER);
7330 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7332 /* Note that with a size != 0 and size != sizeof(IUnknown *) and
7333 * DDSPD_IUNKNOWNPOINTER set SetPrivateData in ddraw4 and ddraw7
7334 * erases the old content and returns an error. This behavior has
7335 * been fixed in d3d8 and d3d9. Unless an application is found
7336 * that depends on this we don't care about this behavior. */
7337 hr = IDirectDrawSurface4_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
7338 sizeof(ddraw), DDSPD_IUNKNOWNPOINTER);
7339 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
7340 hr = IDirectDrawSurface4_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
7341 0, DDSPD_IUNKNOWNPOINTER);
7342 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7343 size = sizeof(ptr);
7344 hr = IDirectDrawSurface4_GetPrivateData(surface, &ddraw_private_data_test_guid, &ptr, &size);
7345 ok(SUCCEEDED(hr), "Failed to get private data, hr %#x.\n", hr);
7346 hr = IDirectDrawSurface4_FreePrivateData(surface, &ddraw_private_data_test_guid);
7347 ok(SUCCEEDED(hr), "Failed to free private data, hr %#x.\n", hr);
7349 refcount = get_refcount((IUnknown *)ddraw);
7350 hr = IDirectDrawSurface4_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
7351 sizeof(ddraw), DDSPD_IUNKNOWNPOINTER);
7352 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
7353 refcount2 = get_refcount((IUnknown *)ddraw);
7354 ok(refcount2 == refcount + 1, "Got unexpected refcount %u.\n", refcount2);
7356 hr = IDirectDrawSurface4_FreePrivateData(surface, &ddraw_private_data_test_guid);
7357 ok(SUCCEEDED(hr), "Failed to free private data, hr %#x.\n", hr);
7358 refcount2 = get_refcount((IUnknown *)ddraw);
7359 ok(refcount2 == refcount, "Got unexpected refcount %u.\n", refcount2);
7361 hr = IDirectDrawSurface4_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
7362 sizeof(ddraw), DDSPD_IUNKNOWNPOINTER);
7363 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
7364 hr = IDirectDrawSurface4_SetPrivateData(surface, &ddraw_private_data_test_guid, surface,
7365 sizeof(surface), DDSPD_IUNKNOWNPOINTER);
7366 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
7367 refcount2 = get_refcount((IUnknown *)ddraw);
7368 ok(refcount2 == refcount, "Got unexpected refcount %u.\n", refcount2);
7370 hr = IDirectDrawSurface4_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
7371 sizeof(ddraw), DDSPD_IUNKNOWNPOINTER);
7372 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
7373 size = 2 * sizeof(ptr);
7374 hr = IDirectDrawSurface4_GetPrivateData(surface, &ddraw_private_data_test_guid, &ptr, &size);
7375 ok(SUCCEEDED(hr), "Failed to get private data, hr %#x.\n", hr);
7376 ok(size == sizeof(ddraw), "Got unexpected size %u.\n", size);
7377 refcount2 = get_refcount(ptr);
7378 /* Object is NOT addref'ed by the getter. */
7379 ok(ptr == (IUnknown *)ddraw, "Returned interface pointer is %p, expected %p.\n", ptr, ddraw);
7380 ok(refcount2 == refcount + 1, "Got unexpected refcount %u.\n", refcount2);
7382 ptr = (IUnknown *)0xdeadbeef;
7383 size = 1;
7384 hr = IDirectDrawSurface4_GetPrivateData(surface, &ddraw_private_data_test_guid, NULL, &size);
7385 ok(hr == DDERR_MOREDATA, "Got unexpected hr %#x.\n", hr);
7386 ok(size == sizeof(ddraw), "Got unexpected size %u.\n", size);
7387 size = 2 * sizeof(ptr);
7388 hr = IDirectDrawSurface4_GetPrivateData(surface, &ddraw_private_data_test_guid, NULL, &size);
7389 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7390 ok(size == 2 * sizeof(ptr), "Got unexpected size %u.\n", size);
7391 size = 1;
7392 hr = IDirectDrawSurface4_GetPrivateData(surface, &ddraw_private_data_test_guid, &ptr, &size);
7393 ok(hr == DDERR_MOREDATA, "Got unexpected hr %#x.\n", hr);
7394 ok(size == sizeof(ddraw), "Got unexpected size %u.\n", size);
7395 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
7396 hr = IDirectDrawSurface4_GetPrivateData(surface, &ddraw_private_data_test_guid2, NULL, NULL);
7397 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
7398 size = 0xdeadbabe;
7399 hr = IDirectDrawSurface4_GetPrivateData(surface, &ddraw_private_data_test_guid2, &ptr, &size);
7400 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
7401 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
7402 ok(size == 0xdeadbabe, "Got unexpected size %u.\n", size);
7403 hr = IDirectDrawSurface4_GetPrivateData(surface, &ddraw_private_data_test_guid, NULL, NULL);
7404 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7406 refcount3 = IDirectDrawSurface4_Release(surface);
7407 ok(!refcount3, "Got unexpected refcount %u.\n", refcount3);
7409 /* Destroying the surface frees the reference held on the private data. It also frees
7410 * the reference the surface is holding on its creating object. */
7411 refcount2 = get_refcount((IUnknown *)ddraw);
7412 ok(refcount2 == refcount - 1, "Got unexpected refcount %u.\n", refcount2);
7414 memset(&hal_caps, 0, sizeof(hal_caps));
7415 hal_caps.dwSize = sizeof(hal_caps);
7416 hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, NULL);
7417 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
7418 if ((hal_caps.ddsCaps.dwCaps & (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP)) == (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP))
7420 reset_ddsd(&surface_desc);
7421 surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_MIPMAPCOUNT;
7422 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
7423 surface_desc.dwHeight = 4;
7424 surface_desc.dwWidth = 4;
7425 U2(surface_desc).dwMipMapCount = 2;
7426 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7427 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7428 hr = IDirectDrawSurface4_GetAttachedSurface(surface, &caps, &surface2);
7429 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
7431 hr = IDirectDrawSurface4_SetPrivateData(surface, &ddraw_private_data_test_guid, data, sizeof(data), 0);
7432 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
7433 hr = IDirectDrawSurface4_GetPrivateData(surface2, &ddraw_private_data_test_guid, NULL, NULL);
7434 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
7436 IDirectDrawSurface4_Release(surface2);
7437 IDirectDrawSurface4_Release(surface);
7439 else
7440 skip("Mipmapped textures not supported, skipping mipmap private data test.\n");
7442 refcount = IDirectDraw4_Release(ddraw);
7443 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7444 DestroyWindow(window);
7447 static void test_pixel_format(void)
7449 HWND window, window2 = NULL;
7450 HDC hdc, hdc2 = NULL;
7451 HMODULE gl = NULL;
7452 int format, test_format;
7453 PIXELFORMATDESCRIPTOR pfd;
7454 IDirectDraw4 *ddraw = NULL;
7455 IDirectDrawClipper *clipper = NULL;
7456 DDSURFACEDESC2 ddsd;
7457 IDirectDrawSurface4 *primary = NULL;
7458 DDBLTFX fx;
7459 HRESULT hr;
7461 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
7462 100, 100, 160, 160, NULL, NULL, NULL, NULL);
7463 if (!window)
7465 skip("Failed to create window\n");
7466 return;
7469 window2 = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
7470 100, 100, 160, 160, NULL, NULL, NULL, NULL);
7472 hdc = GetDC(window);
7473 if (!hdc)
7475 skip("Failed to get DC\n");
7476 goto cleanup;
7479 if (window2)
7480 hdc2 = GetDC(window2);
7482 gl = LoadLibraryA("opengl32.dll");
7483 ok(!!gl, "failed to load opengl32.dll; SetPixelFormat()/GetPixelFormat() may not work right\n");
7485 format = GetPixelFormat(hdc);
7486 ok(format == 0, "new window has pixel format %d\n", format);
7488 ZeroMemory(&pfd, sizeof(pfd));
7489 pfd.nSize = sizeof(pfd);
7490 pfd.nVersion = 1;
7491 pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
7492 pfd.iPixelType = PFD_TYPE_RGBA;
7493 pfd.iLayerType = PFD_MAIN_PLANE;
7494 format = ChoosePixelFormat(hdc, &pfd);
7495 if (format <= 0)
7497 skip("no pixel format available\n");
7498 goto cleanup;
7501 if (!SetPixelFormat(hdc, format, &pfd) || GetPixelFormat(hdc) != format)
7503 skip("failed to set pixel format\n");
7504 goto cleanup;
7507 if (!hdc2 || !SetPixelFormat(hdc2, format, &pfd) || GetPixelFormat(hdc2) != format)
7509 skip("failed to set pixel format on second window\n");
7510 if (hdc2)
7512 ReleaseDC(window2, hdc2);
7513 hdc2 = NULL;
7517 ddraw = create_ddraw();
7518 ok(!!ddraw, "Failed to create a ddraw object.\n");
7520 test_format = GetPixelFormat(hdc);
7521 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
7523 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
7524 if (FAILED(hr))
7526 skip("Failed to set cooperative level, hr %#x.\n", hr);
7527 goto cleanup;
7530 test_format = GetPixelFormat(hdc);
7531 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
7533 if (hdc2)
7535 hr = IDirectDraw4_CreateClipper(ddraw, 0, &clipper, NULL);
7536 ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr);
7537 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window2);
7538 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
7540 test_format = GetPixelFormat(hdc);
7541 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
7543 test_format = GetPixelFormat(hdc2);
7544 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
7547 memset(&ddsd, 0, sizeof(ddsd));
7548 ddsd.dwSize = sizeof(ddsd);
7549 ddsd.dwFlags = DDSD_CAPS;
7550 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
7552 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
7553 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
7555 test_format = GetPixelFormat(hdc);
7556 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
7558 if (hdc2)
7560 test_format = GetPixelFormat(hdc2);
7561 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
7564 if (clipper)
7566 hr = IDirectDrawSurface4_SetClipper(primary, clipper);
7567 ok(SUCCEEDED(hr), "Failed to set clipper, hr %#x.\n", hr);
7569 test_format = GetPixelFormat(hdc);
7570 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
7572 test_format = GetPixelFormat(hdc2);
7573 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
7576 memset(&fx, 0, sizeof(fx));
7577 fx.dwSize = sizeof(fx);
7578 hr = IDirectDrawSurface4_Blt(primary, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
7579 ok(SUCCEEDED(hr), "Failed to clear source surface, hr %#x.\n", hr);
7581 test_format = GetPixelFormat(hdc);
7582 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
7584 if (hdc2)
7586 test_format = GetPixelFormat(hdc2);
7587 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
7590 cleanup:
7591 if (primary) IDirectDrawSurface4_Release(primary);
7592 if (clipper) IDirectDrawClipper_Release(clipper);
7593 if (ddraw) IDirectDraw4_Release(ddraw);
7594 if (gl) FreeLibrary(gl);
7595 if (hdc) ReleaseDC(window, hdc);
7596 if (hdc2) ReleaseDC(window2, hdc2);
7597 if (window) DestroyWindow(window);
7598 if (window2) DestroyWindow(window2);
7601 static void test_create_surface_pitch(void)
7603 IDirectDrawSurface4 *surface;
7604 DDSURFACEDESC2 surface_desc;
7605 IDirectDraw4 *ddraw;
7606 unsigned int i;
7607 ULONG refcount;
7608 HWND window;
7609 HRESULT hr;
7610 void *mem;
7612 static const struct
7614 DWORD caps;
7615 DWORD flags_in;
7616 DWORD pitch_in;
7617 HRESULT hr;
7618 DWORD flags_out;
7619 DWORD pitch_out32;
7620 DWORD pitch_out64;
7622 test_data[] =
7624 /* 0 */
7625 {DDSCAPS_VIDEOMEMORY | DDSCAPS_OFFSCREENPLAIN,
7626 0, 0, DD_OK,
7627 DDSD_PITCH, 0x100, 0x100},
7628 {DDSCAPS_VIDEOMEMORY | DDSCAPS_OFFSCREENPLAIN,
7629 DDSD_PITCH, 0x104, DD_OK,
7630 DDSD_PITCH, 0x100, 0x100},
7631 {DDSCAPS_VIDEOMEMORY | DDSCAPS_OFFSCREENPLAIN,
7632 DDSD_PITCH, 0x0f8, DD_OK,
7633 DDSD_PITCH, 0x100, 0x100},
7634 {DDSCAPS_VIDEOMEMORY | DDSCAPS_OFFSCREENPLAIN,
7635 DDSD_LPSURFACE | DDSD_PITCH, 0x100, DDERR_INVALIDCAPS,
7636 0, 0, 0 },
7637 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
7638 0, 0, DD_OK,
7639 DDSD_PITCH, 0x100, 0x0fc},
7640 /* 5 */
7641 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
7642 DDSD_PITCH, 0x104, DD_OK,
7643 DDSD_PITCH, 0x100, 0x0fc},
7644 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
7645 DDSD_PITCH, 0x0f8, DD_OK,
7646 DDSD_PITCH, 0x100, 0x0fc},
7647 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
7648 DDSD_PITCH | DDSD_LINEARSIZE, 0, DD_OK,
7649 DDSD_PITCH, 0x100, 0x0fc},
7650 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
7651 DDSD_LPSURFACE, 0, DDERR_INVALIDPARAMS,
7652 0, 0, 0 },
7653 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
7654 DDSD_LPSURFACE | DDSD_PITCH, 0x100, DD_OK,
7655 DDSD_PITCH, 0x100, 0x100},
7656 /* 10 */
7657 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
7658 DDSD_LPSURFACE | DDSD_PITCH, 0x0fe, DDERR_INVALIDPARAMS,
7659 0, 0, 0 },
7660 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
7661 DDSD_LPSURFACE | DDSD_PITCH, 0x0fc, DD_OK,
7662 DDSD_PITCH, 0x0fc, 0x0fc},
7663 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
7664 DDSD_LPSURFACE | DDSD_PITCH, 0x0f8, DDERR_INVALIDPARAMS,
7665 0, 0, 0 },
7666 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
7667 DDSD_LPSURFACE | DDSD_LINEARSIZE, 0x100, DDERR_INVALIDPARAMS,
7668 0, 0, 0 },
7669 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
7670 DDSD_LPSURFACE | DDSD_LINEARSIZE, 0x3f00, DDERR_INVALIDPARAMS,
7671 0, 0, 0 },
7672 /* 15 */
7673 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN,
7674 DDSD_LPSURFACE | DDSD_PITCH | DDSD_LINEARSIZE, 0x100, DD_OK,
7675 DDSD_PITCH, 0x100, 0x100},
7676 {DDSCAPS_VIDEOMEMORY | DDSCAPS_OFFSCREENPLAIN | DDSCAPS_ALLOCONLOAD,
7677 0, 0, DDERR_INVALIDCAPS,
7678 0, 0, 0 },
7679 {DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD,
7680 0, 0, DD_OK,
7681 DDSD_PITCH, 0x100, 0 },
7682 {DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD,
7683 DDSD_LPSURFACE | DDSD_PITCH, 0x100, DDERR_INVALIDCAPS,
7684 0, 0, 0 },
7685 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN | DDSCAPS_ALLOCONLOAD,
7686 0, 0, DDERR_INVALIDCAPS,
7687 0, 0, 0 },
7688 /* 20 */
7689 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD,
7690 0, 0, DD_OK,
7691 DDSD_PITCH, 0x100, 0 },
7692 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD,
7693 DDSD_LPSURFACE | DDSD_PITCH, 0x100, DD_OK,
7694 DDSD_PITCH, 0x100, 0 },
7696 DWORD flags_mask = DDSD_PITCH | DDSD_LPSURFACE | DDSD_LINEARSIZE;
7698 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
7699 0, 0, 640, 480, 0, 0, 0, 0);
7700 ddraw = create_ddraw();
7701 ok(!!ddraw, "Failed to create a ddraw object.\n");
7702 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
7703 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
7705 mem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ((63 * 4) + 8) * 63);
7707 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
7709 memset(&surface_desc, 0, sizeof(surface_desc));
7710 surface_desc.dwSize = sizeof(surface_desc);
7711 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | test_data[i].flags_in;
7712 surface_desc.ddsCaps.dwCaps = test_data[i].caps;
7713 surface_desc.dwWidth = 63;
7714 surface_desc.dwHeight = 63;
7715 U1(surface_desc).lPitch = test_data[i].pitch_in;
7716 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
7717 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
7718 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
7719 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
7720 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
7721 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
7722 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7723 if (test_data[i].flags_in & DDSD_LPSURFACE)
7725 HRESULT expected_hr = SUCCEEDED(test_data[i].hr) ? DDERR_INVALIDPARAMS : test_data[i].hr;
7726 ok(hr == expected_hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, expected_hr);
7727 surface_desc.lpSurface = mem;
7728 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7730 if ((test_data[i].caps & DDSCAPS_VIDEOMEMORY) && hr == DDERR_NODIRECTDRAWHW)
7731 continue;
7732 ok(hr == test_data[i].hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, test_data[i].hr);
7733 if (FAILED(hr))
7734 continue;
7736 memset(&surface_desc, 0, sizeof(surface_desc));
7737 surface_desc.dwSize = sizeof(surface_desc);
7738 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &surface_desc);
7739 ok(SUCCEEDED(hr), "Test %u: Failed to get surface desc, hr %#x.\n", i, hr);
7740 ok((surface_desc.dwFlags & flags_mask) == test_data[i].flags_out,
7741 "Test %u: Got unexpected flags %#x, expected %#x.\n",
7742 i, surface_desc.dwFlags & flags_mask, test_data[i].flags_out);
7743 /* The pitch for textures seems to be implementation specific. */
7744 if (!(test_data[i].caps & DDSCAPS_TEXTURE))
7746 if (is_ddraw64 && test_data[i].pitch_out32 != test_data[i].pitch_out64)
7747 todo_wine ok(U1(surface_desc).lPitch == test_data[i].pitch_out64,
7748 "Test %u: Got unexpected pitch %u, expected %u.\n",
7749 i, U1(surface_desc).lPitch, test_data[i].pitch_out64);
7750 else
7751 ok(U1(surface_desc).lPitch == test_data[i].pitch_out32,
7752 "Test %u: Got unexpected pitch %u, expected %u.\n",
7753 i, U1(surface_desc).lPitch, test_data[i].pitch_out32);
7755 ok(!surface_desc.lpSurface, "Test %u: Got unexpected lpSurface %p.\n", i, surface_desc.lpSurface);
7757 IDirectDrawSurface4_Release(surface);
7760 HeapFree(GetProcessHeap(), 0, mem);
7761 refcount = IDirectDraw4_Release(ddraw);
7762 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7763 DestroyWindow(window);
7766 static void test_mipmap(void)
7768 IDirectDrawSurface4 *surface, *surface2;
7769 DDSURFACEDESC2 surface_desc;
7770 IDirectDraw4 *ddraw;
7771 unsigned int i;
7772 ULONG refcount;
7773 HWND window;
7774 HRESULT hr;
7775 DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, {0}};
7776 DDCAPS hal_caps;
7778 static const struct
7780 DWORD flags;
7781 DWORD caps;
7782 DWORD width;
7783 DWORD height;
7784 DWORD mipmap_count_in;
7785 HRESULT hr;
7786 DWORD mipmap_count_out;
7788 tests[] =
7790 {DDSD_MIPMAPCOUNT, DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP, 128, 32, 3, DD_OK, 3},
7791 {DDSD_MIPMAPCOUNT, DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP, 128, 32, 0, DDERR_INVALIDPARAMS, 0},
7792 {0, DDSCAPS_TEXTURE | DDSCAPS_MIPMAP, 128, 32, 0, DD_OK, 1},
7793 {0, DDSCAPS_MIPMAP, 128, 32, 0, DDERR_INVALIDCAPS, 0},
7794 {0, DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP, 128, 32, 0, DD_OK, 6},
7795 {0, DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP, 32, 64, 0, DD_OK, 6},
7798 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
7799 0, 0, 640, 480, 0, 0, 0, 0);
7800 ddraw = create_ddraw();
7801 ok(!!ddraw, "Failed to create a ddraw object.\n");
7802 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
7803 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
7805 memset(&hal_caps, 0, sizeof(hal_caps));
7806 hal_caps.dwSize = sizeof(hal_caps);
7807 hr = IDirectDraw4_GetCaps(ddraw, &hal_caps, NULL);
7808 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
7809 if ((hal_caps.ddsCaps.dwCaps & (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP)) != (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP))
7811 skip("Mipmapped textures not supported, skipping tests.\n");
7812 IDirectDraw4_Release(ddraw);
7813 DestroyWindow(window);
7814 return;
7817 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
7819 memset(&surface_desc, 0, sizeof(surface_desc));
7820 surface_desc.dwSize = sizeof(surface_desc);
7821 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | tests[i].flags;
7822 surface_desc.ddsCaps.dwCaps = tests[i].caps;
7823 surface_desc.dwWidth = tests[i].width;
7824 surface_desc.dwHeight = tests[i].height;
7825 if (tests[i].flags & DDSD_MIPMAPCOUNT)
7826 U2(surface_desc).dwMipMapCount = tests[i].mipmap_count_in;
7827 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7828 ok(hr == tests[i].hr, "Test %u: Got unexpected hr %#x.\n", i, hr);
7829 if (FAILED(hr))
7830 continue;
7832 memset(&surface_desc, 0, sizeof(surface_desc));
7833 surface_desc.dwSize = sizeof(surface_desc);
7834 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &surface_desc);
7835 ok(SUCCEEDED(hr), "Test %u: Failed to get surface desc, hr %#x.\n", i, hr);
7836 ok(surface_desc.dwFlags & DDSD_MIPMAPCOUNT,
7837 "Test %u: Got unexpected flags %#x.\n", i, surface_desc.dwFlags);
7838 ok(U2(surface_desc).dwMipMapCount == tests[i].mipmap_count_out,
7839 "Test %u: Got unexpected mipmap count %u.\n", i, U2(surface_desc).dwMipMapCount);
7841 if (U2(surface_desc).dwMipMapCount > 1)
7843 hr = IDirectDrawSurface4_GetAttachedSurface(surface, &caps, &surface2);
7844 ok(SUCCEEDED(hr), "Test %u: Failed to get attached surface, hr %#x.\n", i, hr);
7846 memset(&surface_desc, 0, sizeof(surface_desc));
7847 surface_desc.dwSize = sizeof(surface_desc);
7848 hr = IDirectDrawSurface4_Lock(surface, NULL, &surface_desc, 0, NULL);
7849 ok(SUCCEEDED(hr), "Test %u: Failed to lock surface, hr %#x.\n", i, hr);
7850 memset(&surface_desc, 0, sizeof(surface_desc));
7851 surface_desc.dwSize = sizeof(surface_desc);
7852 hr = IDirectDrawSurface4_Lock(surface2, NULL, &surface_desc, 0, NULL);
7853 ok(SUCCEEDED(hr), "Test %u: Failed to lock surface, hr %#x.\n", i, hr);
7854 IDirectDrawSurface4_Unlock(surface2, NULL);
7855 IDirectDrawSurface4_Unlock(surface, NULL);
7857 IDirectDrawSurface4_Release(surface2);
7860 IDirectDrawSurface4_Release(surface);
7863 refcount = IDirectDraw4_Release(ddraw);
7864 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7865 DestroyWindow(window);
7868 static void test_palette_complex(void)
7870 IDirectDrawSurface4 *surface, *mipmap, *tmp;
7871 DDSURFACEDESC2 surface_desc;
7872 IDirectDraw4 *ddraw;
7873 IDirectDrawPalette *palette, *palette2, *palette_mipmap;
7874 ULONG refcount;
7875 HWND window;
7876 HRESULT hr;
7877 DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, {0}};
7878 DDCAPS hal_caps;
7879 PALETTEENTRY palette_entries[256];
7880 unsigned int i;
7881 HDC dc;
7882 RGBQUAD rgbquad;
7883 UINT count;
7885 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
7886 0, 0, 640, 480, 0, 0, 0, 0);
7887 ddraw = create_ddraw();
7888 ok(!!ddraw, "Failed to create a ddraw object.\n");
7889 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
7890 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
7892 memset(&hal_caps, 0, sizeof(hal_caps));
7893 hal_caps.dwSize = sizeof(hal_caps);
7894 hr = IDirectDraw4_GetCaps(ddraw, &hal_caps, NULL);
7895 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
7896 if ((hal_caps.ddsCaps.dwCaps & (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP)) != (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP))
7898 skip("Mipmapped textures not supported, skipping mipmap palette test.\n");
7899 IDirectDraw4_Release(ddraw);
7900 DestroyWindow(window);
7901 return;
7904 memset(&surface_desc, 0, sizeof(surface_desc));
7905 surface_desc.dwSize = sizeof(surface_desc);
7906 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
7907 surface_desc.dwWidth = 128;
7908 surface_desc.dwHeight = 128;
7909 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
7910 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
7911 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
7912 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 8;
7913 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7914 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7916 memset(palette_entries, 0, sizeof(palette_entries));
7917 hr = IDirectDraw4_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
7918 palette_entries, &palette, NULL);
7919 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
7921 memset(palette_entries, 0, sizeof(palette_entries));
7922 palette_entries[1].peRed = 0xff;
7923 palette_entries[1].peGreen = 0x80;
7924 hr = IDirectDraw4_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
7925 palette_entries, &palette_mipmap, NULL);
7926 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
7928 palette2 = (void *)0xdeadbeef;
7929 hr = IDirectDrawSurface4_GetPalette(surface, &palette2);
7930 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x.\n", hr);
7931 ok(!palette2, "Got unexpected palette %p.\n", palette2);
7932 hr = IDirectDrawSurface4_SetPalette(surface, palette);
7933 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
7934 hr = IDirectDrawSurface4_GetPalette(surface, &palette2);
7935 ok(SUCCEEDED(hr), "Failed to get palette, hr %#x.\n", hr);
7936 ok(palette == palette2, "Got unexpected palette %p.\n", palette2);
7937 IDirectDrawPalette_Release(palette2);
7939 mipmap = surface;
7940 IDirectDrawSurface4_AddRef(mipmap);
7941 for (i = 0; i < 7; ++i)
7943 hr = IDirectDrawSurface4_GetAttachedSurface(mipmap, &caps, &tmp);
7944 ok(SUCCEEDED(hr), "Failed to get attached surface, i %u, hr %#x.\n", i, hr);
7945 palette2 = (void *)0xdeadbeef;
7946 hr = IDirectDrawSurface4_GetPalette(tmp, &palette2);
7947 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x, i %u.\n", hr, i);
7948 ok(!palette2, "Got unexpected palette %p, i %u.\n", palette2, i);
7950 hr = IDirectDrawSurface4_SetPalette(tmp, palette_mipmap);
7951 ok(SUCCEEDED(hr), "Failed to set palette, i %u, hr %#x.\n", i, hr);
7953 hr = IDirectDrawSurface4_GetPalette(tmp, &palette2);
7954 ok(SUCCEEDED(hr), "Failed to get palette, i %u, hr %#x.\n", i, hr);
7955 ok(palette_mipmap == palette2, "Got unexpected palette %p.\n", palette2);
7956 IDirectDrawPalette_Release(palette2);
7958 hr = IDirectDrawSurface4_GetDC(tmp, &dc);
7959 ok(SUCCEEDED(hr), "Failed to get DC, i %u, hr %#x.\n", i, hr);
7960 count = GetDIBColorTable(dc, 1, 1, &rgbquad);
7961 ok(count == 1, "Expected count 1, got %u.\n", count);
7962 ok(rgbquad.rgbRed == 0xff, "Expected rgbRed = 0xff, got %#x.\n", rgbquad.rgbRed);
7963 ok(rgbquad.rgbGreen == 0x80, "Expected rgbGreen = 0x80, got %#x.\n", rgbquad.rgbGreen);
7964 ok(rgbquad.rgbBlue == 0x0, "Expected rgbBlue = 0x0, got %#x.\n", rgbquad.rgbBlue);
7965 hr = IDirectDrawSurface4_ReleaseDC(tmp, dc);
7966 ok(SUCCEEDED(hr), "Failed to release DC, i %u, hr %#x.\n", i, hr);
7968 IDirectDrawSurface4_Release(mipmap);
7969 mipmap = tmp;
7972 hr = IDirectDrawSurface4_GetAttachedSurface(mipmap, &caps, &tmp);
7973 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
7974 IDirectDrawSurface4_Release(mipmap);
7975 refcount = IDirectDrawSurface4_Release(surface);
7976 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7977 refcount = IDirectDrawPalette_Release(palette_mipmap);
7978 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7979 refcount = IDirectDrawPalette_Release(palette);
7980 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7982 refcount = IDirectDraw4_Release(ddraw);
7983 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7984 DestroyWindow(window);
7987 static void test_p8_blit(void)
7989 IDirectDrawSurface4 *src, *dst, *dst_p8;
7990 DDSURFACEDESC2 surface_desc;
7991 IDirectDraw4 *ddraw;
7992 IDirectDrawPalette *palette, *palette2;
7993 ULONG refcount;
7994 HWND window;
7995 HRESULT hr;
7996 PALETTEENTRY palette_entries[256];
7997 unsigned int x;
7998 DDBLTFX fx;
7999 BOOL is_warp;
8000 static const BYTE src_data[] = {0x10, 0x1, 0x2, 0x3, 0x4, 0x5, 0xff, 0x80};
8001 static const BYTE src_data2[] = {0x10, 0x5, 0x4, 0x3, 0x2, 0x1, 0xff, 0x80};
8002 static const BYTE expected_p8[] = {0x10, 0x1, 0x4, 0x3, 0x4, 0x5, 0xff, 0x80};
8003 static const D3DCOLOR expected[] =
8005 0x00101010, 0x00010101, 0x00020202, 0x00030303,
8006 0x00040404, 0x00050505, 0x00ffffff, 0x00808080,
8008 D3DCOLOR color;
8010 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
8011 0, 0, 640, 480, 0, 0, 0, 0);
8012 ddraw = create_ddraw();
8013 ok(!!ddraw, "Failed to create a ddraw object.\n");
8014 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
8015 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
8016 is_warp = ddraw_is_warp(ddraw);
8018 memset(palette_entries, 0, sizeof(palette_entries));
8019 palette_entries[1].peGreen = 0xff;
8020 palette_entries[2].peBlue = 0xff;
8021 palette_entries[3].peFlags = 0xff;
8022 palette_entries[4].peRed = 0xff;
8023 hr = IDirectDraw4_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
8024 palette_entries, &palette, NULL);
8025 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
8026 palette_entries[1].peBlue = 0xff;
8027 palette_entries[2].peGreen = 0xff;
8028 palette_entries[3].peRed = 0xff;
8029 palette_entries[4].peFlags = 0x0;
8030 hr = IDirectDraw4_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
8031 palette_entries, &palette2, NULL);
8032 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
8034 memset(&surface_desc, 0, sizeof(surface_desc));
8035 surface_desc.dwSize = sizeof(surface_desc);
8036 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
8037 surface_desc.dwWidth = 8;
8038 surface_desc.dwHeight = 1;
8039 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
8040 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
8041 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
8042 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 8;
8043 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &src, NULL);
8044 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8045 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &dst_p8, NULL);
8046 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8047 hr = IDirectDrawSurface4_SetPalette(dst_p8, palette2);
8048 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
8050 memset(&surface_desc, 0, sizeof(surface_desc));
8051 surface_desc.dwSize = sizeof(surface_desc);
8052 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
8053 surface_desc.dwWidth = 8;
8054 surface_desc.dwHeight = 1;
8055 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
8056 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
8057 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
8058 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
8059 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
8060 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
8061 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
8062 U5(U4(surface_desc).ddpfPixelFormat).dwRGBAlphaBitMask = 0xff000000;
8063 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &dst, NULL);
8064 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8066 memset(&surface_desc, 0, sizeof(surface_desc));
8067 surface_desc.dwSize = sizeof(surface_desc);
8068 hr = IDirectDrawSurface4_Lock(src, NULL, &surface_desc, DDLOCK_WAIT, NULL);
8069 ok(SUCCEEDED(hr), "Failed to lock source surface, hr %#x.\n", hr);
8070 memcpy(surface_desc.lpSurface, src_data, sizeof(src_data));
8071 hr = IDirectDrawSurface4_Unlock(src, NULL);
8072 ok(SUCCEEDED(hr), "Failed to unlock source surface, hr %#x.\n", hr);
8074 hr = IDirectDrawSurface4_Lock(dst_p8, NULL, &surface_desc, DDLOCK_WAIT, NULL);
8075 ok(SUCCEEDED(hr), "Failed to lock destination surface, hr %#x.\n", hr);
8076 memcpy(surface_desc.lpSurface, src_data2, sizeof(src_data2));
8077 hr = IDirectDrawSurface4_Unlock(dst_p8, NULL);
8078 ok(SUCCEEDED(hr), "Failed to unlock destination surface, hr %#x.\n", hr);
8080 hr = IDirectDrawSurface4_SetPalette(src, palette);
8081 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
8082 hr = IDirectDrawSurface4_Blt(dst, NULL, src, NULL, DDBLT_WAIT, NULL);
8083 /* The r500 Windows 7 driver returns E_NOTIMPL. r200 on Windows XP works.
8084 * The Geforce 7 driver on Windows Vista returns E_FAIL. Newer Nvidia GPUs work. */
8085 ok(SUCCEEDED(hr) || broken(hr == E_NOTIMPL) || broken(hr == E_FAIL),
8086 "Failed to blit, hr %#x.\n", hr);
8088 if (SUCCEEDED(hr))
8090 for (x = 0; x < sizeof(expected) / sizeof(*expected); x++)
8092 color = get_surface_color(dst, x, 0);
8093 todo_wine ok(compare_color(color, expected[x], 0),
8094 "Pixel %u: Got color %#x, expected %#x.\n",
8095 x, color, expected[x]);
8099 memset(&fx, 0, sizeof(fx));
8100 fx.dwSize = sizeof(fx);
8101 fx.ddckSrcColorkey.dwColorSpaceHighValue = 0x2;
8102 fx.ddckSrcColorkey.dwColorSpaceLowValue = 0x2;
8103 hr = IDirectDrawSurface4_Blt(dst_p8, NULL, src, NULL, DDBLT_WAIT | DDBLT_KEYSRCOVERRIDE, &fx);
8104 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
8106 hr = IDirectDrawSurface4_Lock(dst_p8, NULL, &surface_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
8107 ok(SUCCEEDED(hr), "Failed to lock destination surface, hr %#x.\n", hr);
8108 /* A color keyed P8 blit doesn't do anything on WARP - it just leaves the data in the destination
8109 * surface untouched. P8 blits without color keys work. Error checking (DDBLT_KEYSRC without a key
8110 * for example) also works as expected.
8112 * Using DDBLT_KEYSRC instead of DDBLT_KEYSRCOVERRIDE doesn't change this. Doing this blit with
8113 * the display mode set to P8 doesn't help either. */
8114 ok(!memcmp(surface_desc.lpSurface, expected_p8, sizeof(expected_p8))
8115 || broken(is_warp && !memcmp(surface_desc.lpSurface, src_data2, sizeof(src_data2))),
8116 "Got unexpected P8 color key blit result.\n");
8117 hr = IDirectDrawSurface4_Unlock(dst_p8, NULL);
8118 ok(SUCCEEDED(hr), "Failed to unlock destination surface, hr %#x.\n", hr);
8120 IDirectDrawSurface4_Release(src);
8121 IDirectDrawSurface4_Release(dst);
8122 IDirectDrawSurface4_Release(dst_p8);
8123 IDirectDrawPalette_Release(palette);
8124 IDirectDrawPalette_Release(palette2);
8126 refcount = IDirectDraw4_Release(ddraw);
8127 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8128 DestroyWindow(window);
8131 static void test_material(void)
8133 D3DMATERIALHANDLE mat_handle, tmp;
8134 IDirect3DMaterial3 *material;
8135 IDirect3DViewport3 *viewport;
8136 IDirect3DDevice3 *device;
8137 IDirectDrawSurface4 *rt;
8138 D3DCOLOR color;
8139 ULONG refcount;
8140 unsigned int i;
8141 HWND window;
8142 HRESULT hr;
8143 BOOL valid;
8145 static struct
8147 struct vec3 position;
8148 struct vec3 normal;
8149 D3DCOLOR diffuse;
8151 quad1[] =
8153 {{-1.0f, -1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffffffff},
8154 {{-1.0f, 1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffffffff},
8155 {{ 1.0f, -1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffffffff},
8156 {{ 1.0f, 1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffffffff},
8158 quad2[] =
8160 {{-1.0f, -1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000},
8161 {{-1.0f, 1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000},
8162 {{ 1.0f, -1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000},
8163 {{ 1.0f, 1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000},
8165 static const struct
8167 void *data;
8168 BOOL material;
8169 D3DCOLOR expected_color;
8171 test_data[] =
8173 {quad1, TRUE, 0x0000ff00},
8174 {quad2, TRUE, 0x0000ff00},
8175 {quad1, FALSE, 0x00ffffff},
8176 {quad2, FALSE, 0x00ff0000},
8178 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
8180 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
8181 0, 0, 640, 480, 0, 0, 0, 0);
8182 if (!(device = create_device(window, DDSCL_NORMAL)))
8184 skip("Failed to create a 3D device, skipping test.\n");
8185 DestroyWindow(window);
8186 return;
8189 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
8190 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
8192 viewport = create_viewport(device, 0, 0, 640, 480);
8193 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
8194 ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr);
8196 material = create_emissive_material(device, 0.0f, 1.0f, 0.0f, 0.0f);
8197 hr = IDirect3DMaterial3_GetHandle(material, device, &mat_handle);
8198 ok(SUCCEEDED(hr), "Failed to get material handle, hr %#x.\n", hr);
8200 hr = IDirect3DDevice3_GetLightState(device, D3DLIGHTSTATE_MATERIAL, &tmp);
8201 ok(SUCCEEDED(hr), "Failed to get light state, hr %#x.\n", hr);
8202 ok(!tmp, "Got unexpected material handle %#x.\n", tmp);
8203 hr = IDirect3DDevice3_SetLightState(device, D3DLIGHTSTATE_MATERIAL, mat_handle);
8204 ok(SUCCEEDED(hr), "Failed to set material state, hr %#x.\n", hr);
8205 hr = IDirect3DDevice3_GetLightState(device, D3DLIGHTSTATE_MATERIAL, &tmp);
8206 ok(SUCCEEDED(hr), "Failed to get light state, hr %#x.\n", hr);
8207 ok(tmp == mat_handle, "Got unexpected material handle %#x, expected %#x.\n", tmp, mat_handle);
8208 hr = IDirect3DDevice3_SetLightState(device, D3DLIGHTSTATE_MATERIAL, 0);
8209 ok(SUCCEEDED(hr), "Failed to set material state, hr %#x.\n", hr);
8210 hr = IDirect3DDevice3_GetLightState(device, D3DLIGHTSTATE_MATERIAL, &tmp);
8211 ok(SUCCEEDED(hr), "Failed to get light state, hr %#x.\n", hr);
8212 ok(!tmp, "Got unexpected material handle %#x.\n", tmp);
8214 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
8216 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect,
8217 D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff0000ff, 1.0f, 0);
8218 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
8220 hr = IDirect3DDevice3_SetLightState(device, D3DLIGHTSTATE_MATERIAL, test_data[i].material ? mat_handle : 0);
8221 ok(SUCCEEDED(hr), "Failed to set material state, hr %#x.\n", hr);
8223 hr = IDirect3DDevice3_BeginScene(device);
8224 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
8225 hr = IDirect3DDevice2_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
8226 D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE, test_data[i].data, 4, 0);
8227 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
8228 hr = IDirect3DDevice3_EndScene(device);
8229 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
8230 color = get_surface_color(rt, 320, 240);
8231 ok(compare_color(color, test_data[i].expected_color, 1),
8232 "Got unexpected color 0x%08x, test %u.\n", color, i);
8235 destroy_material(material);
8236 material = create_diffuse_material(device, 1.0f, 0.0f, 0.0f, 1.0f);
8237 hr = IDirect3DMaterial3_GetHandle(material, device, &mat_handle);
8238 ok(SUCCEEDED(hr), "Failed to get material handle, hr %#x.\n", hr);
8240 hr = IDirect3DViewport3_SetBackground(viewport, mat_handle);
8241 ok(SUCCEEDED(hr), "Failed to set viewport background, hr %#x.\n", hr);
8242 hr = IDirect3DViewport3_GetBackground(viewport, &tmp, &valid);
8243 ok(SUCCEEDED(hr), "Failed to get viewport background, hr %#x.\n", hr);
8244 ok(tmp == mat_handle, "Got unexpected material handle %#x, expected %#x.\n", tmp, mat_handle);
8245 ok(valid, "Got unexpected valid %#x.\n", valid);
8246 hr = IDirect3DViewport3_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
8247 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
8248 color = get_surface_color(rt, 320, 240);
8249 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
8251 hr = IDirect3DViewport3_SetBackground(viewport, 0);
8252 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
8253 hr = IDirect3DViewport3_GetBackground(viewport, &tmp, &valid);
8254 ok(SUCCEEDED(hr), "Failed to get viewport background, hr %#x.\n", hr);
8255 ok(tmp == mat_handle, "Got unexpected material handle %#x, expected %#x.\n", tmp, mat_handle);
8256 ok(valid, "Got unexpected valid %#x.\n", valid);
8257 hr = IDirect3DViewport3_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
8258 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
8259 color = get_surface_color(rt, 320, 240);
8260 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
8262 destroy_viewport(device, viewport);
8263 viewport = create_viewport(device, 0, 0, 640, 480);
8265 hr = IDirect3DViewport3_GetBackground(viewport, &tmp, &valid);
8266 ok(SUCCEEDED(hr), "Failed to get viewport background, hr %#x.\n", hr);
8267 ok(!tmp, "Got unexpected material handle %#x.\n", tmp);
8268 ok(!valid, "Got unexpected valid %#x.\n", valid);
8269 hr = IDirect3DViewport3_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
8270 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
8271 color = get_surface_color(rt, 320, 240);
8272 ok(compare_color(color, 0x00000000, 1), "Got unexpected color 0x%08x.\n", color);
8274 destroy_viewport(device, viewport);
8275 destroy_material(material);
8276 IDirectDrawSurface4_Release(rt);
8277 refcount = IDirect3DDevice3_Release(device);
8278 ok(!refcount, "Device has %u references left.\n", refcount);
8279 DestroyWindow(window);
8282 static void test_palette_gdi(void)
8284 IDirectDrawSurface4 *surface, *primary;
8285 DDSURFACEDESC2 surface_desc;
8286 IDirectDraw4 *ddraw;
8287 IDirectDrawPalette *palette, *palette2;
8288 ULONG refcount;
8289 HWND window;
8290 HRESULT hr;
8291 PALETTEENTRY palette_entries[256];
8292 UINT i;
8293 HDC dc;
8294 DDBLTFX fx;
8295 RECT r;
8296 COLORREF color;
8297 /* On the Windows 8 testbot palette index 0 of the onscreen palette is forced to
8298 * r = 0, g = 0, b = 0. Do not attempt to set it to something else as this is
8299 * not the point of this test. */
8300 static const RGBQUAD expected1[] =
8302 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
8303 {0x03, 0x00, 0x00, 0x00}, {0x15, 0x14, 0x13, 0x00},
8305 static const RGBQUAD expected2[] =
8307 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
8308 {0x03, 0x00, 0x00, 0x00}, {0x25, 0x24, 0x23, 0x00},
8310 static const RGBQUAD expected3[] =
8312 {0x00, 0x00, 0x00, 0x00}, {0x40, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x40, 0x00},
8313 {0x00, 0x40, 0x00, 0x00}, {0x56, 0x34, 0x12, 0x00},
8315 HPALETTE ddraw_palette_handle;
8316 /* Similar to index 0, index 255 is r = 0xff, g = 0xff, b = 0xff on the Win8 VMs. */
8317 RGBQUAD rgbquad[255];
8318 static const RGBQUAD rgb_zero = {0, 0, 0, 0};
8320 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
8321 0, 0, 640, 480, 0, 0, 0, 0);
8322 ddraw = create_ddraw();
8323 ok(!!ddraw, "Failed to create a ddraw object.\n");
8324 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
8325 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
8327 memset(&surface_desc, 0, sizeof(surface_desc));
8328 surface_desc.dwSize = sizeof(surface_desc);
8329 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
8330 surface_desc.dwWidth = 16;
8331 surface_desc.dwHeight = 16;
8332 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
8333 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
8334 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
8335 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 8;
8336 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8337 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8339 /* Avoid colors from the Windows default palette. */
8340 memset(palette_entries, 0, sizeof(palette_entries));
8341 palette_entries[1].peRed = 0x01;
8342 palette_entries[2].peGreen = 0x02;
8343 palette_entries[3].peBlue = 0x03;
8344 palette_entries[4].peRed = 0x13;
8345 palette_entries[4].peGreen = 0x14;
8346 palette_entries[4].peBlue = 0x15;
8347 hr = IDirectDraw4_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
8348 palette_entries, &palette, NULL);
8349 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
8351 /* If there is no palette assigned and the display mode is not 8 bpp, some
8352 * drivers refuse to create a DC while others allow it. If a DC is created,
8353 * the DIB color table is uninitialized and contains random colors. No error
8354 * is generated when trying to read pixels and random garbage is returned.
8356 * The most likely explanation is that if the driver creates a DC, it (or
8357 * the higher-level runtime) uses GetSystemPaletteEntries to find the
8358 * palette, but GetSystemPaletteEntries fails when bpp > 8 and the palette
8359 * contains uninitialized garbage. See comments below for the P8 case. */
8361 hr = IDirectDrawSurface4_SetPalette(surface, palette);
8362 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
8363 hr = IDirectDrawSurface4_GetDC(surface, &dc);
8364 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
8365 ddraw_palette_handle = SelectPalette(dc, GetStockObject(DEFAULT_PALETTE), FALSE);
8366 ok(ddraw_palette_handle == GetStockObject(DEFAULT_PALETTE),
8367 "Got unexpected palette %p, expected %p.\n",
8368 ddraw_palette_handle, GetStockObject(DEFAULT_PALETTE));
8370 i = GetDIBColorTable(dc, 0, sizeof(rgbquad) / sizeof(*rgbquad), rgbquad);
8371 ok(i == sizeof(rgbquad) / sizeof(*rgbquad), "Expected count 255, got %u.\n", i);
8372 for (i = 0; i < sizeof(expected1) / sizeof(*expected1); i++)
8374 ok(!memcmp(&rgbquad[i], &expected1[i], sizeof(rgbquad[i])),
8375 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8376 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
8377 expected1[i].rgbRed, expected1[i].rgbGreen, expected1[i].rgbBlue);
8379 for (; i < sizeof(rgbquad) / sizeof(*rgbquad); i++)
8381 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
8382 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
8383 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
8386 /* Update the palette while the DC is in use. This does not modify the DC. */
8387 palette_entries[4].peRed = 0x23;
8388 palette_entries[4].peGreen = 0x24;
8389 palette_entries[4].peBlue = 0x25;
8390 hr = IDirectDrawPalette_SetEntries(palette, 0, 4, 1, &palette_entries[4]);
8391 ok(SUCCEEDED(hr), "Failed to set palette entries, hr %#x.\n", hr);
8393 i = GetDIBColorTable(dc, 4, 1, &rgbquad[4]);
8394 ok(i == 1, "Expected count 1, got %u.\n", i);
8395 ok(!memcmp(&rgbquad[4], &expected1[4], sizeof(rgbquad[4])),
8396 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8397 i, rgbquad[4].rgbRed, rgbquad[4].rgbGreen, rgbquad[4].rgbBlue,
8398 expected1[4].rgbRed, expected1[4].rgbGreen, expected1[4].rgbBlue);
8400 /* Neither does re-setting the palette. */
8401 hr = IDirectDrawSurface4_SetPalette(surface, NULL);
8402 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
8403 hr = IDirectDrawSurface4_SetPalette(surface, palette);
8404 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
8406 i = GetDIBColorTable(dc, 4, 1, &rgbquad[4]);
8407 ok(i == 1, "Expected count 1, got %u.\n", i);
8408 ok(!memcmp(&rgbquad[4], &expected1[4], sizeof(rgbquad[4])),
8409 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8410 i, rgbquad[4].rgbRed, rgbquad[4].rgbGreen, rgbquad[4].rgbBlue,
8411 expected1[4].rgbRed, expected1[4].rgbGreen, expected1[4].rgbBlue);
8413 hr = IDirectDrawSurface4_ReleaseDC(surface, dc);
8414 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
8416 /* Refresh the DC. This updates the palette. */
8417 hr = IDirectDrawSurface4_GetDC(surface, &dc);
8418 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
8419 i = GetDIBColorTable(dc, 0, sizeof(rgbquad) / sizeof(*rgbquad), rgbquad);
8420 ok(i == sizeof(rgbquad) / sizeof(*rgbquad), "Expected count 255, got %u.\n", i);
8421 for (i = 0; i < sizeof(expected2) / sizeof(*expected2); i++)
8423 ok(!memcmp(&rgbquad[i], &expected2[i], sizeof(rgbquad[i])),
8424 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8425 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
8426 expected2[i].rgbRed, expected2[i].rgbGreen, expected2[i].rgbBlue);
8428 for (; i < sizeof(rgbquad) / sizeof(*rgbquad); i++)
8430 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
8431 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
8432 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
8434 hr = IDirectDrawSurface4_ReleaseDC(surface, dc);
8435 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
8437 refcount = IDirectDrawSurface4_Release(surface);
8438 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8440 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
8441 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
8442 if (FAILED(IDirectDraw4_SetDisplayMode(ddraw, 640, 480, 8, 0, 0)))
8444 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
8445 IDirectDrawPalette_Release(palette);
8446 IDirectDraw4_Release(ddraw);
8447 DestroyWindow(window);
8448 return;
8450 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
8452 memset(&surface_desc, 0, sizeof(surface_desc));
8453 surface_desc.dwSize = sizeof(surface_desc);
8454 surface_desc.dwFlags = DDSD_CAPS;
8455 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
8456 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &primary, NULL);
8457 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8459 memset(&fx, 0, sizeof(fx));
8460 fx.dwSize = sizeof(fx);
8461 U5(fx).dwFillColor = 3;
8462 SetRect(&r, 0, 0, 319, 479);
8463 hr = IDirectDrawSurface4_Blt(primary, &r, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
8464 ok(SUCCEEDED(hr), "Failed to clear surface, hr %#x.\n", hr);
8465 SetRect(&r, 320, 0, 639, 479);
8466 U5(fx).dwFillColor = 4;
8467 hr = IDirectDrawSurface4_Blt(primary, &r, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
8468 ok(SUCCEEDED(hr), "Failed to clear surface, hr %#x.\n", hr);
8470 hr = IDirectDrawSurface4_SetPalette(primary, palette);
8471 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
8472 hr = IDirectDrawSurface4_GetDC(primary, &dc);
8473 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
8475 color = GetPixel(dc, 160, 240);
8476 ok(color == 0x00030000, "Clear index 3: Got unexpected color 0x%08x.\n", color);
8477 color = GetPixel(dc, 480, 240);
8478 ok(color == 0x00252423, "Clear index 4: Got unexpected color 0x%08x.\n", color);
8480 ddraw_palette_handle = SelectPalette(dc, GetStockObject(DEFAULT_PALETTE), FALSE);
8481 ok(ddraw_palette_handle == GetStockObject(DEFAULT_PALETTE),
8482 "Got unexpected palette %p, expected %p.\n",
8483 ddraw_palette_handle, GetStockObject(DEFAULT_PALETTE));
8484 SelectPalette(dc, ddraw_palette_handle, FALSE);
8486 /* The primary uses the system palette. In exclusive mode, the system palette matches
8487 * the ddraw palette attached to the primary, so the result is what you would expect
8488 * from a regular surface. Tests for the interaction between the ddraw palette and
8489 * the system palette are not included pending an application that depends on this.
8490 * The relation between those causes problems on Windows Vista and newer for games
8491 * like Age of Empires or StarCraft. Don't emulate it without a real need. */
8492 i = GetDIBColorTable(dc, 0, sizeof(rgbquad) / sizeof(*rgbquad), rgbquad);
8493 ok(i == sizeof(rgbquad) / sizeof(*rgbquad), "Expected count 255, got %u.\n", i);
8494 for (i = 0; i < sizeof(expected2) / sizeof(*expected2); i++)
8496 ok(!memcmp(&rgbquad[i], &expected2[i], sizeof(rgbquad[i])),
8497 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8498 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
8499 expected2[i].rgbRed, expected2[i].rgbGreen, expected2[i].rgbBlue);
8501 for (; i < sizeof(rgbquad) / sizeof(*rgbquad); i++)
8503 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
8504 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
8505 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
8507 hr = IDirectDrawSurface4_ReleaseDC(primary, dc);
8508 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
8510 memset(&surface_desc, 0, sizeof(surface_desc));
8511 surface_desc.dwSize = sizeof(surface_desc);
8512 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
8513 surface_desc.dwWidth = 16;
8514 surface_desc.dwHeight = 16;
8515 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
8516 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8517 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8519 /* Here the offscreen surface appears to use the primary's palette,
8520 * but in all likelihood it is actually the system palette. */
8521 hr = IDirectDrawSurface4_GetDC(surface, &dc);
8522 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
8523 i = GetDIBColorTable(dc, 0, sizeof(rgbquad) / sizeof(*rgbquad), rgbquad);
8524 ok(i == sizeof(rgbquad) / sizeof(*rgbquad), "Expected count 255, got %u.\n", i);
8525 for (i = 0; i < sizeof(expected2) / sizeof(*expected2); i++)
8527 ok(!memcmp(&rgbquad[i], &expected2[i], sizeof(rgbquad[i])),
8528 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8529 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
8530 expected2[i].rgbRed, expected2[i].rgbGreen, expected2[i].rgbBlue);
8532 for (; i < sizeof(rgbquad) / sizeof(*rgbquad); i++)
8534 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
8535 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
8536 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
8538 hr = IDirectDrawSurface4_ReleaseDC(surface, dc);
8539 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
8541 /* On real hardware a change to the primary surface's palette applies immediately,
8542 * even on device contexts from offscreen surfaces that do not have their own
8543 * palette. On the testbot VMs this is not the case. Don't test this until we
8544 * know of an application that depends on this. */
8546 memset(palette_entries, 0, sizeof(palette_entries));
8547 palette_entries[1].peBlue = 0x40;
8548 palette_entries[2].peRed = 0x40;
8549 palette_entries[3].peGreen = 0x40;
8550 palette_entries[4].peRed = 0x12;
8551 palette_entries[4].peGreen = 0x34;
8552 palette_entries[4].peBlue = 0x56;
8553 hr = IDirectDraw4_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
8554 palette_entries, &palette2, NULL);
8555 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
8556 hr = IDirectDrawSurface4_SetPalette(surface, palette2);
8557 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
8559 /* A palette assigned to the offscreen surface overrides the primary / system
8560 * palette. */
8561 hr = IDirectDrawSurface4_GetDC(surface, &dc);
8562 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
8563 i = GetDIBColorTable(dc, 0, sizeof(rgbquad) / sizeof(*rgbquad), rgbquad);
8564 ok(i == sizeof(rgbquad) / sizeof(*rgbquad), "Expected count 255, got %u.\n", i);
8565 for (i = 0; i < sizeof(expected3) / sizeof(*expected3); i++)
8567 ok(!memcmp(&rgbquad[i], &expected3[i], sizeof(rgbquad[i])),
8568 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8569 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
8570 expected3[i].rgbRed, expected3[i].rgbGreen, expected3[i].rgbBlue);
8572 for (; i < sizeof(rgbquad) / sizeof(*rgbquad); i++)
8574 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
8575 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
8576 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
8578 hr = IDirectDrawSurface4_ReleaseDC(surface, dc);
8579 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
8581 refcount = IDirectDrawSurface4_Release(surface);
8582 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8584 /* The Windows 8 testbot keeps extra references to the primary and
8585 * backbuffer while in 8 bpp mode. */
8586 hr = IDirectDraw4_RestoreDisplayMode(ddraw);
8587 ok(SUCCEEDED(hr), "Failed to restore display mode, hr %#x.\n", hr);
8589 refcount = IDirectDrawSurface4_Release(primary);
8590 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8591 refcount = IDirectDrawPalette_Release(palette2);
8592 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8593 refcount = IDirectDrawPalette_Release(palette);
8594 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8595 refcount = IDirectDraw4_Release(ddraw);
8596 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8597 DestroyWindow(window);
8600 static void test_palette_alpha(void)
8602 IDirectDrawSurface4 *surface;
8603 DDSURFACEDESC2 surface_desc;
8604 IDirectDraw4 *ddraw;
8605 IDirectDrawPalette *palette;
8606 ULONG refcount;
8607 HWND window;
8608 HRESULT hr;
8609 PALETTEENTRY palette_entries[256];
8610 unsigned int i;
8611 static const struct
8613 DWORD caps, flags;
8614 BOOL attach_allowed;
8615 const char *name;
8617 test_data[] =
8619 {DDSCAPS_OFFSCREENPLAIN, DDSD_WIDTH | DDSD_HEIGHT, FALSE, "offscreenplain"},
8620 {DDSCAPS_TEXTURE, DDSD_WIDTH | DDSD_HEIGHT, TRUE, "texture"},
8621 {DDSCAPS_PRIMARYSURFACE, 0, FALSE, "primary"}
8624 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
8625 0, 0, 640, 480, 0, 0, 0, 0);
8626 ddraw = create_ddraw();
8627 ok(!!ddraw, "Failed to create a ddraw object.\n");
8628 if (FAILED(IDirectDraw4_SetDisplayMode(ddraw, 640, 480, 8, 0, 0)))
8630 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
8631 IDirectDraw4_Release(ddraw);
8632 DestroyWindow(window);
8633 return;
8635 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
8636 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
8638 memset(palette_entries, 0, sizeof(palette_entries));
8639 palette_entries[1].peFlags = 0x42;
8640 palette_entries[2].peFlags = 0xff;
8641 palette_entries[3].peFlags = 0x80;
8642 hr = IDirectDraw4_CreatePalette(ddraw, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, palette_entries, &palette, NULL);
8643 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
8645 memset(palette_entries, 0x66, sizeof(palette_entries));
8646 hr = IDirectDrawPalette_GetEntries(palette, 0, 1, 4, palette_entries);
8647 ok(SUCCEEDED(hr), "Failed to get palette entries, hr %#x.\n", hr);
8648 ok(palette_entries[0].peFlags == 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
8649 palette_entries[0].peFlags);
8650 ok(palette_entries[1].peFlags == 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
8651 palette_entries[1].peFlags);
8652 ok(palette_entries[2].peFlags == 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
8653 palette_entries[2].peFlags);
8654 ok(palette_entries[3].peFlags == 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
8655 palette_entries[3].peFlags);
8657 IDirectDrawPalette_Release(palette);
8659 memset(palette_entries, 0, sizeof(palette_entries));
8660 palette_entries[1].peFlags = 0x42;
8661 palette_entries[1].peRed = 0xff;
8662 palette_entries[2].peFlags = 0xff;
8663 palette_entries[3].peFlags = 0x80;
8664 hr = IDirectDraw4_CreatePalette(ddraw, DDPCAPS_ALLOW256 | DDPCAPS_8BIT | DDPCAPS_ALPHA,
8665 palette_entries, &palette, NULL);
8666 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
8668 memset(palette_entries, 0x66, sizeof(palette_entries));
8669 hr = IDirectDrawPalette_GetEntries(palette, 0, 1, 4, palette_entries);
8670 ok(SUCCEEDED(hr), "Failed to get palette entries, hr %#x.\n", hr);
8671 ok(palette_entries[0].peFlags == 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
8672 palette_entries[0].peFlags);
8673 ok(palette_entries[1].peFlags == 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
8674 palette_entries[1].peFlags);
8675 ok(palette_entries[2].peFlags == 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
8676 palette_entries[2].peFlags);
8677 ok(palette_entries[3].peFlags == 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
8678 palette_entries[3].peFlags);
8680 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); i++)
8682 memset(&surface_desc, 0, sizeof(surface_desc));
8683 surface_desc.dwSize = sizeof(surface_desc);
8684 surface_desc.dwFlags = DDSD_CAPS | test_data[i].flags;
8685 surface_desc.dwWidth = 128;
8686 surface_desc.dwHeight = 128;
8687 surface_desc.ddsCaps.dwCaps = test_data[i].caps;
8688 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8689 ok(SUCCEEDED(hr), "Failed to create %s surface, hr %#x.\n", test_data[i].name, hr);
8691 hr = IDirectDrawSurface4_SetPalette(surface, palette);
8692 if (test_data[i].attach_allowed)
8693 ok(SUCCEEDED(hr), "Failed to attach palette to %s surface, hr %#x.\n", test_data[i].name, hr);
8694 else
8695 ok(hr == DDERR_INVALIDSURFACETYPE, "Got unexpected hr %#x, %s surface.\n", hr, test_data[i].name);
8697 if (SUCCEEDED(hr))
8699 HDC dc;
8700 RGBQUAD rgbquad;
8701 UINT retval;
8703 hr = IDirectDrawSurface4_GetDC(surface, &dc);
8704 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x, %s surface.\n", hr, test_data[i].name);
8705 retval = GetDIBColorTable(dc, 1, 1, &rgbquad);
8706 ok(retval == 1, "GetDIBColorTable returned unexpected result %u.\n", retval);
8707 ok(rgbquad.rgbRed == 0xff, "Expected rgbRed = 0xff, got %#x, %s surface.\n",
8708 rgbquad.rgbRed, test_data[i].name);
8709 ok(rgbquad.rgbGreen == 0, "Expected rgbGreen = 0, got %#x, %s surface.\n",
8710 rgbquad.rgbGreen, test_data[i].name);
8711 ok(rgbquad.rgbBlue == 0, "Expected rgbBlue = 0, got %#x, %s surface.\n",
8712 rgbquad.rgbBlue, test_data[i].name);
8713 ok(rgbquad.rgbReserved == 0, "Expected rgbReserved = 0, got %u, %s surface.\n",
8714 rgbquad.rgbReserved, test_data[i].name);
8715 hr = IDirectDrawSurface4_ReleaseDC(surface, dc);
8716 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
8718 IDirectDrawSurface4_Release(surface);
8721 /* Test INVALIDSURFACETYPE vs INVALIDPIXELFORMAT. */
8722 memset(&surface_desc, 0, sizeof(surface_desc));
8723 surface_desc.dwSize = sizeof(surface_desc);
8724 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
8725 surface_desc.dwWidth = 128;
8726 surface_desc.dwHeight = 128;
8727 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
8728 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
8729 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
8730 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
8731 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
8732 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
8733 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
8734 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8735 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8736 hr = IDirectDrawSurface4_SetPalette(surface, palette);
8737 ok(hr == DDERR_INVALIDSURFACETYPE, "Got unexpected hr %#x.\n", hr);
8738 IDirectDrawSurface4_Release(surface);
8740 /* The Windows 8 testbot keeps extra references to the primary
8741 * while in 8 bpp mode. */
8742 hr = IDirectDraw4_RestoreDisplayMode(ddraw);
8743 ok(SUCCEEDED(hr), "Failed to restore display mode, hr %#x.\n", hr);
8745 refcount = IDirectDrawPalette_Release(palette);
8746 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8747 refcount = IDirectDraw4_Release(ddraw);
8748 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8749 DestroyWindow(window);
8752 static void test_vb_writeonly(void)
8754 IDirect3DDevice3 *device;
8755 IDirect3D3 *d3d;
8756 IDirect3DVertexBuffer *buffer;
8757 HWND window;
8758 HRESULT hr;
8759 D3DVERTEXBUFFERDESC desc;
8760 void *ptr;
8761 static const struct vec4 quad[] =
8763 { 0.0f, 480.0f, 0.0f, 1.0f},
8764 { 0.0f, 0.0f, 0.0f, 1.0f},
8765 {640.0f, 480.0f, 0.0f, 1.0f},
8766 {640.0f, 0.0f, 0.0f, 1.0f},
8769 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
8770 0, 0, 640, 480, 0, 0, 0, 0);
8772 if (!(device = create_device(window, DDSCL_NORMAL)))
8774 skip("Failed to create a 3D device, skipping test.\n");
8775 DestroyWindow(window);
8776 return;
8779 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
8780 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
8782 memset(&desc, 0, sizeof(desc));
8783 desc.dwSize = sizeof(desc);
8784 desc.dwCaps = D3DVBCAPS_WRITEONLY;
8785 desc.dwFVF = D3DFVF_XYZRHW;
8786 desc.dwNumVertices = sizeof(quad) / sizeof(*quad);
8787 hr = IDirect3D3_CreateVertexBuffer(d3d, &desc, &buffer, 0, NULL);
8788 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
8790 hr = IDirect3DVertexBuffer_Lock(buffer, DDLOCK_DISCARDCONTENTS, &ptr, NULL);
8791 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
8792 memcpy(ptr, quad, sizeof(quad));
8793 hr = IDirect3DVertexBuffer_Unlock(buffer);
8794 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
8796 hr = IDirect3DDevice3_BeginScene(device);
8797 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
8798 hr = IDirect3DDevice3_DrawPrimitiveVB(device, D3DPT_TRIANGLESTRIP, buffer, 0, 4, 0);
8799 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
8800 hr = IDirect3DDevice3_EndScene(device);
8801 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
8803 hr = IDirect3DVertexBuffer_Lock(buffer, 0, &ptr, NULL);
8804 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
8805 ok (!memcmp(ptr, quad, sizeof(quad)), "Got unexpected vertex buffer data.\n");
8806 hr = IDirect3DVertexBuffer_Unlock(buffer);
8807 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
8809 hr = IDirect3DVertexBuffer_Lock(buffer, DDLOCK_READONLY, &ptr, NULL);
8810 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
8811 ok (!memcmp(ptr, quad, sizeof(quad)), "Got unexpected vertex buffer data.\n");
8812 hr = IDirect3DVertexBuffer_Unlock(buffer);
8813 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
8815 IDirect3DVertexBuffer_Release(buffer);
8816 IDirect3D3_Release(d3d);
8817 IDirect3DDevice3_Release(device);
8818 DestroyWindow(window);
8821 static void test_lost_device(void)
8823 IDirectDrawSurface4 *surface;
8824 DDSURFACEDESC2 surface_desc;
8825 HWND window1, window2;
8826 IDirectDraw4 *ddraw;
8827 ULONG refcount;
8828 HRESULT hr;
8829 BOOL ret;
8831 window1 = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
8832 0, 0, 640, 480, 0, 0, 0, 0);
8833 window2 = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
8834 0, 0, 640, 480, 0, 0, 0, 0);
8835 ddraw = create_ddraw();
8836 ok(!!ddraw, "Failed to create a ddraw object.\n");
8837 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window1, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
8838 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
8840 memset(&surface_desc, 0, sizeof(surface_desc));
8841 surface_desc.dwSize = sizeof(surface_desc);
8842 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
8843 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
8844 U5(surface_desc).dwBackBufferCount = 1;
8845 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8846 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8848 hr = IDirectDraw4_TestCooperativeLevel(ddraw);
8849 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8850 hr = IDirectDrawSurface4_IsLost(surface);
8851 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8852 hr = IDirectDrawSurface4_Flip(surface, NULL, DDFLIP_WAIT);
8853 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8855 ret = SetForegroundWindow(GetDesktopWindow());
8856 ok(ret, "Failed to set foreground window.\n");
8857 hr = IDirectDraw4_TestCooperativeLevel(ddraw);
8858 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
8859 hr = IDirectDrawSurface4_IsLost(surface);
8860 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
8861 hr = IDirectDrawSurface4_Flip(surface, NULL, DDFLIP_WAIT);
8862 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
8864 ret = SetForegroundWindow(window1);
8865 ok(ret, "Failed to set foreground window.\n");
8866 hr = IDirectDraw4_TestCooperativeLevel(ddraw);
8867 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8868 hr = IDirectDrawSurface4_IsLost(surface);
8869 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
8870 hr = IDirectDrawSurface4_Flip(surface, NULL, DDFLIP_WAIT);
8871 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
8873 hr = IDirectDraw4_RestoreAllSurfaces(ddraw);
8874 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8875 hr = IDirectDraw4_TestCooperativeLevel(ddraw);
8876 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8877 hr = IDirectDrawSurface4_IsLost(surface);
8878 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8879 hr = IDirectDrawSurface4_Flip(surface, NULL, DDFLIP_WAIT);
8880 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8882 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window1, DDSCL_NORMAL);
8883 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8884 hr = IDirectDraw4_TestCooperativeLevel(ddraw);
8885 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8886 hr = IDirectDrawSurface4_IsLost(surface);
8887 todo_wine ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
8888 hr = IDirectDrawSurface4_Flip(surface, NULL, DDFLIP_WAIT);
8889 todo_wine ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
8891 /* Trying to restore the primary will crash, probably because flippable
8892 * surfaces can't exist in DDSCL_NORMAL. */
8893 IDirectDrawSurface4_Release(surface);
8894 memset(&surface_desc, 0, sizeof(surface_desc));
8895 surface_desc.dwSize = sizeof(surface_desc);
8896 surface_desc.dwFlags = DDSD_CAPS;
8897 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
8898 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8899 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8901 hr = IDirectDraw4_TestCooperativeLevel(ddraw);
8902 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8903 hr = IDirectDrawSurface4_IsLost(surface);
8904 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8906 ret = SetForegroundWindow(GetDesktopWindow());
8907 ok(ret, "Failed to set foreground window.\n");
8908 hr = IDirectDraw4_TestCooperativeLevel(ddraw);
8909 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8910 hr = IDirectDrawSurface4_IsLost(surface);
8911 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8913 ret = SetForegroundWindow(window1);
8914 ok(ret, "Failed to set foreground window.\n");
8915 hr = IDirectDraw4_TestCooperativeLevel(ddraw);
8916 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8917 hr = IDirectDrawSurface4_IsLost(surface);
8918 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8920 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window1, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
8921 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8922 hr = IDirectDraw4_TestCooperativeLevel(ddraw);
8923 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8924 hr = IDirectDrawSurface4_IsLost(surface);
8925 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
8927 hr = IDirectDraw4_RestoreAllSurfaces(ddraw);
8928 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8929 hr = IDirectDraw4_TestCooperativeLevel(ddraw);
8930 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8931 hr = IDirectDrawSurface4_IsLost(surface);
8932 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8934 IDirectDrawSurface4_Release(surface);
8935 memset(&surface_desc, 0, sizeof(surface_desc));
8936 surface_desc.dwSize = sizeof(surface_desc);
8937 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
8938 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
8939 U5(surface_desc).dwBackBufferCount = 1;
8940 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8941 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8943 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window1, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
8944 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8945 hr = IDirectDraw4_TestCooperativeLevel(ddraw);
8946 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8947 hr = IDirectDrawSurface4_IsLost(surface);
8948 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8949 hr = IDirectDrawSurface4_Flip(surface, NULL, DDFLIP_WAIT);
8950 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8952 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window1, DDSCL_NORMAL | DDSCL_FULLSCREEN);
8953 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8954 hr = IDirectDraw4_TestCooperativeLevel(ddraw);
8955 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8956 hr = IDirectDrawSurface4_IsLost(surface);
8957 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8958 hr = IDirectDrawSurface4_Flip(surface, NULL, DDFLIP_WAIT);
8959 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
8961 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window1, DDSCL_NORMAL);
8962 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8963 hr = IDirectDraw4_TestCooperativeLevel(ddraw);
8964 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8965 hr = IDirectDrawSurface4_IsLost(surface);
8966 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8967 hr = IDirectDrawSurface4_Flip(surface, NULL, DDFLIP_WAIT);
8968 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
8970 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window2, DDSCL_NORMAL);
8971 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8972 hr = IDirectDraw4_TestCooperativeLevel(ddraw);
8973 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8974 hr = IDirectDrawSurface4_IsLost(surface);
8975 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8976 hr = IDirectDrawSurface4_Flip(surface, NULL, DDFLIP_WAIT);
8977 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
8979 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window2, DDSCL_NORMAL | DDSCL_FULLSCREEN);
8980 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8981 hr = IDirectDraw4_TestCooperativeLevel(ddraw);
8982 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8983 hr = IDirectDrawSurface4_IsLost(surface);
8984 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8985 hr = IDirectDrawSurface4_Flip(surface, NULL, DDFLIP_WAIT);
8986 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
8988 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window2, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
8989 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8990 hr = IDirectDraw4_TestCooperativeLevel(ddraw);
8991 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8992 hr = IDirectDrawSurface4_IsLost(surface);
8993 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
8994 hr = IDirectDrawSurface4_Flip(surface, NULL, DDFLIP_WAIT);
8995 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
8997 IDirectDrawSurface4_Release(surface);
8998 refcount = IDirectDraw4_Release(ddraw);
8999 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
9000 DestroyWindow(window2);
9001 DestroyWindow(window1);
9004 static void test_surface_desc_lock(void)
9006 IDirectDrawSurface4 *surface;
9007 DDSURFACEDESC2 surface_desc;
9008 IDirectDraw4 *ddraw;
9009 ULONG refcount;
9010 HWND window;
9011 HRESULT hr;
9013 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
9014 0, 0, 640, 480, 0, 0, 0, 0);
9015 ddraw = create_ddraw();
9016 ok(!!ddraw, "Failed to create a ddraw object.\n");
9017 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
9018 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
9020 memset(&surface_desc, 0, sizeof(surface_desc));
9021 surface_desc.dwSize = sizeof(surface_desc);
9022 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
9023 surface_desc.dwWidth = 16;
9024 surface_desc.dwHeight = 16;
9025 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
9026 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
9027 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
9029 memset(&surface_desc, 0xaa, sizeof(surface_desc));
9030 surface_desc.dwSize = sizeof(surface_desc);
9031 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &surface_desc);
9032 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
9033 ok(!surface_desc.lpSurface, "Got unexpected lpSurface %p.\n", surface_desc.lpSurface);
9035 memset(&surface_desc, 0xaa, sizeof(surface_desc));
9036 surface_desc.dwSize = sizeof(surface_desc);
9037 hr = IDirectDrawSurface4_Lock(surface, NULL, &surface_desc, 0, NULL);
9038 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
9039 ok(surface_desc.lpSurface != NULL, "Got unexpected lpSurface %p.\n", surface_desc.lpSurface);
9040 memset(&surface_desc, 0xaa, sizeof(surface_desc));
9041 surface_desc.dwSize = sizeof(surface_desc);
9042 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &surface_desc);
9043 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
9044 ok(!surface_desc.lpSurface, "Got unexpected lpSurface %p.\n", surface_desc.lpSurface);
9045 hr = IDirectDrawSurface4_Unlock(surface, NULL);
9046 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
9048 memset(&surface_desc, 0xaa, sizeof(surface_desc));
9049 surface_desc.dwSize = sizeof(surface_desc);
9050 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &surface_desc);
9051 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
9052 ok(!surface_desc.lpSurface, "Got unexpected lpSurface %p.\n", surface_desc.lpSurface);
9054 IDirectDrawSurface4_Release(surface);
9055 refcount = IDirectDraw4_Release(ddraw);
9056 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
9057 DestroyWindow(window);
9060 static void test_signed_formats(void)
9062 HRESULT hr;
9063 IDirect3DDevice3 *device;
9064 IDirect3D3 *d3d;
9065 IDirectDraw4 *ddraw;
9066 IDirectDrawSurface4 *surface, *rt;
9067 IDirect3DTexture2 *texture;
9068 IDirect3DViewport3 *viewport;
9069 DDSURFACEDESC2 surface_desc;
9070 ULONG refcount;
9071 HWND window;
9072 D3DCOLOR color, expected_color;
9073 D3DRECT clear_rect;
9074 static struct
9076 struct vec3 position;
9077 struct vec2 texcoord;
9079 quad[] =
9081 {{-1.0f, -1.0f, 0.0f}, {0.0f, 1.0f}},
9082 {{-1.0f, 1.0f, 0.0f}, {0.0f, 0.0f}},
9083 {{ 1.0f, -1.0f, 0.0f}, {1.0f, 1.0f}},
9084 {{ 1.0f, 1.0f, 0.0f}, {1.0f, 0.0f}},
9086 /* See test_signed_formats() in dlls/d3d9/tests/visual.c for an explanation
9087 * of these values. */
9088 static const USHORT content_v8u8[4][4] =
9090 {0x0000, 0x7f7f, 0x8880, 0x0000},
9091 {0x0080, 0x8000, 0x7f00, 0x007f},
9092 {0x193b, 0xe8c8, 0x0808, 0xf8f8},
9093 {0x4444, 0xc0c0, 0xa066, 0x22e0},
9095 static const DWORD content_x8l8v8u8[4][4] =
9097 {0x00000000, 0x00ff7f7f, 0x00008880, 0x00ff0000},
9098 {0x00000080, 0x00008000, 0x00007f00, 0x0000007f},
9099 {0x0041193b, 0x0051e8c8, 0x00040808, 0x00fff8f8},
9100 {0x00824444, 0x0000c0c0, 0x00c2a066, 0x009222e0},
9102 static const USHORT content_l6v5u5[4][4] =
9104 {0x0000, 0xfdef, 0x0230, 0xfc00},
9105 {0x0010, 0x0200, 0x01e0, 0x000f},
9106 {0x4067, 0x53b9, 0x0421, 0xffff},
9107 {0x8108, 0x0318, 0xc28c, 0x909c},
9109 static const struct
9111 const char *name;
9112 const void *content;
9113 SIZE_T pixel_size;
9114 BOOL blue;
9115 unsigned int slop, slop_broken;
9116 DDPIXELFORMAT format;
9118 formats[] =
9121 "D3DFMT_V8U8", content_v8u8, sizeof(WORD), FALSE, 1, 0,
9123 sizeof(DDPIXELFORMAT), DDPF_BUMPDUDV, 0,
9124 {16}, {0x000000ff}, {0x0000ff00}, {0x00000000}, {0x00000000}
9128 "D3DFMT_X8L8V8U8", content_x8l8v8u8, sizeof(DWORD), TRUE, 1, 0,
9130 sizeof(DDPIXELFORMAT), DDPF_BUMPDUDV | DDPF_BUMPLUMINANCE, 0,
9131 {32}, {0x000000ff}, {0x0000ff00}, {0x00ff0000}, {0x00000000}
9135 "D3DFMT_L6V5U5", content_l6v5u5, sizeof(WORD), TRUE, 4, 7,
9137 sizeof(DDPIXELFORMAT), DDPF_BUMPDUDV | DDPF_BUMPLUMINANCE, 0,
9138 {16}, {0x0000001f}, {0x000003e0}, {0x0000fc00}, {0x00000000}
9142 /* No V16U16 or Q8W8V8U8 support in ddraw. */
9144 static const D3DCOLOR expected_colors[4][4] =
9146 {0x00808080, 0x00fefeff, 0x00010780, 0x008080ff},
9147 {0x00018080, 0x00800180, 0x0080fe80, 0x00fe8080},
9148 {0x00ba98a0, 0x004767a8, 0x00888881, 0x007878ff},
9149 {0x00c3c3c0, 0x003f3f80, 0x00e51fe1, 0x005fa2c8},
9151 unsigned int i, width, x, y;
9152 D3DDEVICEDESC device_desc, hel_desc;
9154 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
9155 0, 0, 640, 480, 0, 0, 0, 0);
9157 if (!(device = create_device(window, DDSCL_NORMAL)))
9159 skip("Failed to create a 3D device, skipping test.\n");
9160 DestroyWindow(window);
9161 return;
9164 memset(&device_desc, 0, sizeof(device_desc));
9165 device_desc.dwSize = sizeof(device_desc);
9166 memset(&hel_desc, 0, sizeof(hel_desc));
9167 hel_desc.dwSize = sizeof(hel_desc);
9168 hr = IDirect3DDevice3_GetCaps(device, &device_desc, &hel_desc);
9169 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
9170 if (!(device_desc.dwTextureOpCaps & D3DTEXOPCAPS_BLENDFACTORALPHA))
9172 skip("D3DTOP_BLENDFACTORALPHA not supported, skipping bumpmap format tests.\n");
9173 goto done;
9176 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
9177 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
9178 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
9179 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
9180 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
9181 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
9183 memset(&surface_desc, 0, sizeof(surface_desc));
9184 surface_desc.dwSize = sizeof(surface_desc);
9185 hr = IDirectDrawSurface4_GetSurfaceDesc(rt, &surface_desc);
9186 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
9187 viewport = create_viewport(device, 0, 0, surface_desc.dwWidth, surface_desc.dwHeight);
9188 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
9189 ok(SUCCEEDED(hr), "Failed to activate the viewport, hr %#x.\n", hr);
9190 U1(clear_rect).x1 = 0;
9191 U2(clear_rect).y1 = 0;
9192 U3(clear_rect).x2 = surface_desc.dwWidth;
9193 U4(clear_rect).y2 = surface_desc.dwHeight;
9195 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
9196 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9198 /* dst = tex * 0.5 + 1.0 * (1.0 - 0.5) = tex * 0.5 + 0.5 */
9199 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_TEXTUREFACTOR, 0x80ffffff);
9200 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9201 hr = IDirect3DDevice3_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_BLENDFACTORALPHA);
9202 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
9203 hr = IDirect3DDevice3_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
9204 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
9205 hr = IDirect3DDevice3_SetTextureStageState(device, 0, D3DTSS_COLORARG2, D3DTA_TFACTOR);
9206 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
9208 for (i = 0; i < sizeof(formats) / sizeof(*formats); i++)
9210 for (width = 1; width < 5; width += 3)
9212 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0x00000000, 0.0f, 0);
9213 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
9215 memset(&surface_desc, 0, sizeof(surface_desc));
9216 surface_desc.dwSize = sizeof(surface_desc);
9217 surface_desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS;
9218 surface_desc.dwWidth = width;
9219 surface_desc.dwHeight = 4;
9220 U4(surface_desc).ddpfPixelFormat = formats[i].format;
9221 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY;
9222 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
9223 if (FAILED(hr))
9225 skip("%s textures not supported, skipping.\n", formats[i].name);
9226 continue;
9228 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x, format %s.\n", hr, formats[i].name);
9230 hr = IDirectDrawSurface4_QueryInterface(surface, &IID_IDirect3DTexture2, (void **)&texture);
9231 ok(SUCCEEDED(hr), "Failed to get Direct3DTexture2 interface, hr %#x, format %s.\n",
9232 hr, formats[i].name);
9233 hr = IDirect3DDevice3_SetTexture(device, 0, texture);
9234 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x, format %s.\n", hr, formats[i].name);
9235 IDirect3DTexture2_Release(texture);
9237 memset(&surface_desc, 0, sizeof(surface_desc));
9238 surface_desc.dwSize = sizeof(surface_desc);
9239 hr = IDirectDrawSurface4_Lock(surface, NULL, &surface_desc, 0, NULL);
9240 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x, format %s.\n", hr, formats[i].name);
9241 for (y = 0; y < 4; y++)
9243 memcpy((char *)surface_desc.lpSurface + y * U1(surface_desc).lPitch,
9244 (char *)formats[i].content + y * 4 * formats[i].pixel_size,
9245 width * formats[i].pixel_size);
9247 hr = IDirectDrawSurface4_Unlock(surface, NULL);
9248 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, format %s.\n", hr, formats[i].name);
9250 hr = IDirect3DDevice3_BeginScene(device);
9251 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
9252 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
9253 D3DFVF_XYZ | D3DFVF_TEX1, quad, 4, 0);
9254 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9255 hr = IDirect3DDevice3_EndScene(device);
9256 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
9258 for (y = 0; y < 4; y++)
9260 for (x = 0; x < width; x++)
9262 expected_color = expected_colors[y][x];
9263 if (!formats[i].blue)
9264 expected_color |= 0x000000ff;
9266 color = get_surface_color(rt, 80 + 160 * x, 60 + 120 * y);
9267 ok(compare_color(color, expected_color, formats[i].slop)
9268 || broken(compare_color(color, expected_color, formats[i].slop_broken)),
9269 "Expected color 0x%08x, got 0x%08x, format %s, location %ux%u.\n",
9270 expected_color, color, formats[i].name, x, y);
9274 IDirectDrawSurface4_Release(surface);
9278 destroy_viewport(device, viewport);
9279 IDirectDrawSurface4_Release(rt);
9280 IDirectDraw4_Release(ddraw);
9281 IDirect3D3_Release(d3d);
9283 done:
9284 refcount = IDirect3DDevice3_Release(device);
9285 ok(!refcount, "Device has %u references left.\n", refcount);
9286 DestroyWindow(window);
9289 static void test_color_fill(void)
9291 HRESULT hr;
9292 IDirect3DDevice3 *device;
9293 IDirect3D3 *d3d;
9294 IDirectDraw4 *ddraw;
9295 IDirectDrawSurface4 *surface, *surface2;
9296 DDSURFACEDESC2 surface_desc;
9297 DDPIXELFORMAT z_fmt;
9298 ULONG refcount;
9299 HWND window;
9300 unsigned int i;
9301 DDBLTFX fx;
9302 RECT rect = {5, 5, 7, 7};
9303 DWORD *color;
9304 DWORD supported_fmts = 0, num_fourcc_codes, *fourcc_codes;
9305 DDCAPS hal_caps;
9306 static const struct
9308 DWORD caps, caps2;
9309 HRESULT colorfill_hr, depthfill_hr;
9310 BOOL rop_success;
9311 const char *name;
9312 DWORD result;
9313 BOOL check_result;
9314 DDPIXELFORMAT format;
9316 tests[] =
9319 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0,
9320 DD_OK, DDERR_INVALIDPARAMS, TRUE, "vidmem offscreenplain RGB", 0xdeadbeef, TRUE,
9322 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
9323 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9327 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY, 0,
9328 DD_OK, DDERR_INVALIDPARAMS, TRUE, "sysmem offscreenplain RGB", 0xdeadbeef, TRUE,
9330 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
9331 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9335 DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, 0,
9336 DD_OK, DDERR_INVALIDPARAMS, TRUE, "vidmem texture RGB", 0xdeadbeef, TRUE,
9338 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
9339 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9343 DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, 0,
9344 DD_OK, DDERR_INVALIDPARAMS, TRUE, "sysmem texture RGB", 0xdeadbeef, TRUE,
9346 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
9347 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9351 DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE,
9352 DD_OK, DDERR_INVALIDPARAMS, TRUE, "managed texture RGB", 0xdeadbeef, TRUE,
9354 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
9355 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9359 DDSCAPS_ZBUFFER | DDSCAPS_VIDEOMEMORY, 0,
9360 DDERR_INVALIDPARAMS, DD_OK, TRUE, "vidmem zbuffer", 0, FALSE,
9361 {0, 0, 0, {0}, {0}, {0}, {0}, {0}}
9364 DDSCAPS_ZBUFFER | DDSCAPS_SYSTEMMEMORY, 0,
9365 DDERR_INVALIDPARAMS, DD_OK, TRUE, "sysmem zbuffer", 0, FALSE,
9366 {0, 0, 0, {0}, {0}, {0}, {0}, {0}}
9369 /* Colorfill on YUV surfaces always returns DD_OK, but the content is
9370 * different afterwards. DX9+ GPUs set one of the two luminance values
9371 * in each block, but AMD and Nvidia GPUs disagree on which luminance
9372 * value they set. r200 (dx8) just sets the entire block to the clear
9373 * value. */
9374 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0,
9375 DD_OK, DDERR_INVALIDPARAMS, FALSE, "vidmem offscreenplain YUY2", 0, FALSE,
9377 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y', 'U', 'Y', '2'),
9378 {0}, {0}, {0}, {0}, {0}
9382 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0,
9383 DD_OK, DDERR_INVALIDPARAMS, FALSE, "vidmem offscreenplain UYVY", 0, FALSE,
9385 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('U', 'Y', 'V', 'Y'),
9386 {0}, {0}, {0}, {0}, {0}
9390 DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY, 0,
9391 DD_OK, DDERR_INVALIDPARAMS, FALSE, "vidmem overlay YUY2", 0, FALSE,
9393 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y', 'U', 'Y', '2'),
9394 {0}, {0}, {0}, {0}, {0}
9398 DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY, 0,
9399 DD_OK, DDERR_INVALIDPARAMS, FALSE, "vidmem overlay UYVY", 0, FALSE,
9401 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('U', 'Y', 'V', 'Y'),
9402 {0}, {0}, {0}, {0}, {0}
9406 DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, 0,
9407 E_NOTIMPL, DDERR_INVALIDPARAMS, FALSE, "vidmem texture DXT1", 0, FALSE,
9409 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('D', 'X', 'T', '1'),
9410 {0}, {0}, {0}, {0}, {0}
9414 DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, 0,
9415 E_NOTIMPL, DDERR_INVALIDPARAMS, FALSE, "sysmem texture DXT1", 0, FALSE,
9417 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('D', 'X', 'T', '1'),
9418 {0}, {0}, {0}, {0}, {0}
9422 /* The testbot fills this with 0x00 instead of the blue channel. The sysmem
9423 * surface works, presumably because it is handled by the runtime instead of
9424 * the driver. */
9425 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0,
9426 DD_OK, DDERR_INVALIDPARAMS, TRUE, "vidmem offscreenplain P8", 0xefefefef, FALSE,
9428 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_PALETTEINDEXED8, 0,
9429 {8}, {0}, {0}, {0}, {0}
9433 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY, 0,
9434 DD_OK, DDERR_INVALIDPARAMS, TRUE, "sysmem offscreenplain P8", 0xefefefef, TRUE,
9436 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_PALETTEINDEXED8, 0,
9437 {8}, {0}, {0}, {0}, {0}
9441 static const struct
9443 DWORD rop;
9444 const char *name;
9445 HRESULT hr;
9447 rops[] =
9449 {SRCCOPY, "SRCCOPY", DD_OK},
9450 {SRCPAINT, "SRCPAINT", DDERR_NORASTEROPHW},
9451 {SRCAND, "SRCAND", DDERR_NORASTEROPHW},
9452 {SRCINVERT, "SRCINVERT", DDERR_NORASTEROPHW},
9453 {SRCERASE, "SRCERASE", DDERR_NORASTEROPHW},
9454 {NOTSRCCOPY, "NOTSRCCOPY", DDERR_NORASTEROPHW},
9455 {NOTSRCERASE, "NOTSRCERASE", DDERR_NORASTEROPHW},
9456 {MERGECOPY, "MERGECOPY", DDERR_NORASTEROPHW},
9457 {MERGEPAINT, "MERGEPAINT", DDERR_NORASTEROPHW},
9458 {PATCOPY, "PATCOPY", DDERR_NORASTEROPHW},
9459 {PATPAINT, "PATPAINT", DDERR_NORASTEROPHW},
9460 {PATINVERT, "PATINVERT", DDERR_NORASTEROPHW},
9461 {DSTINVERT, "DSTINVERT", DDERR_NORASTEROPHW},
9462 {BLACKNESS, "BLACKNESS", DD_OK},
9463 {WHITENESS, "WHITENESS", DD_OK},
9464 {0xaa0029, "0xaa0029", DDERR_NORASTEROPHW} /* noop */
9467 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
9468 0, 0, 640, 480, 0, 0, 0, 0);
9470 if (!(device = create_device(window, DDSCL_NORMAL)))
9472 skip("Failed to create a 3D device, skipping test.\n");
9473 DestroyWindow(window);
9474 return;
9477 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
9478 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
9479 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
9480 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
9482 memset(&z_fmt, 0, sizeof(z_fmt));
9483 IDirect3D3_EnumZBufferFormats(d3d, &IID_IDirect3DHALDevice, enum_z_fmt, &z_fmt);
9484 if (!z_fmt.dwSize)
9485 skip("No Z buffer formats supported, skipping Z buffer colorfill test.\n");
9487 IDirect3DDevice3_EnumTextureFormats(device, test_block_formats_creation_cb, &supported_fmts);
9488 if (!(supported_fmts & SUPPORT_DXT1))
9489 skip("DXT1 textures not supported, skipping DXT1 colorfill test.\n");
9491 IDirect3D3_Release(d3d);
9493 hr = IDirectDraw4_GetFourCCCodes(ddraw, &num_fourcc_codes, NULL);
9494 ok(SUCCEEDED(hr), "Failed to get fourcc codes %#x.\n", hr);
9495 fourcc_codes = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
9496 num_fourcc_codes * sizeof(*fourcc_codes));
9497 if (!fourcc_codes)
9498 goto done;
9499 hr = IDirectDraw4_GetFourCCCodes(ddraw, &num_fourcc_codes, fourcc_codes);
9500 ok(SUCCEEDED(hr), "Failed to get fourcc codes %#x.\n", hr);
9501 for (i = 0; i < num_fourcc_codes; i++)
9503 if (fourcc_codes[i] == MAKEFOURCC('Y', 'U', 'Y', '2'))
9504 supported_fmts |= SUPPORT_YUY2;
9505 else if (fourcc_codes[i] == MAKEFOURCC('U', 'Y', 'V', 'Y'))
9506 supported_fmts |= SUPPORT_UYVY;
9508 HeapFree(GetProcessHeap(), 0, fourcc_codes);
9510 memset(&hal_caps, 0, sizeof(hal_caps));
9511 hal_caps.dwSize = sizeof(hal_caps);
9512 hr = IDirectDraw4_GetCaps(ddraw, &hal_caps, NULL);
9513 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
9515 if (!(supported_fmts & (SUPPORT_YUY2 | SUPPORT_UYVY)) || !(hal_caps.dwCaps & DDCAPS_OVERLAY))
9516 skip("Overlays or some YUV formats not supported, skipping YUV colorfill tests.\n");
9518 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
9520 /* Some Windows drivers modify dwFillColor when it is used on P8 or FourCC formats. */
9521 memset(&fx, 0, sizeof(fx));
9522 fx.dwSize = sizeof(fx);
9523 U5(fx).dwFillColor = 0xdeadbeef;
9525 memset(&surface_desc, 0, sizeof(surface_desc));
9526 surface_desc.dwSize = sizeof(surface_desc);
9527 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
9528 surface_desc.dwWidth = 64;
9529 surface_desc.dwHeight = 64;
9530 U4(surface_desc).ddpfPixelFormat = tests[i].format;
9531 surface_desc.ddsCaps.dwCaps = tests[i].caps;
9532 surface_desc.ddsCaps.dwCaps2 = tests[i].caps2;
9534 if (tests[i].format.dwFourCC == MAKEFOURCC('D','X','T','1') && !(supported_fmts & SUPPORT_DXT1))
9535 continue;
9536 if (tests[i].format.dwFourCC == MAKEFOURCC('Y','U','Y','2') && !(supported_fmts & SUPPORT_YUY2))
9537 continue;
9538 if (tests[i].format.dwFourCC == MAKEFOURCC('U','Y','V','Y') && !(supported_fmts & SUPPORT_UYVY))
9539 continue;
9540 if (tests[i].caps & DDSCAPS_OVERLAY && !(hal_caps.dwCaps & DDCAPS_OVERLAY))
9541 continue;
9543 if (tests[i].caps & DDSCAPS_ZBUFFER)
9545 if (!z_fmt.dwSize)
9546 continue;
9548 U4(surface_desc).ddpfPixelFormat = z_fmt;
9551 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
9552 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x, surface %s.\n", hr, tests[i].name);
9554 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
9555 todo_wine_if (tests[i].format.dwFourCC)
9556 ok(hr == tests[i].colorfill_hr, "Blt returned %#x, expected %#x, surface %s.\n",
9557 hr, tests[i].colorfill_hr, tests[i].name);
9559 hr = IDirectDrawSurface4_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
9560 todo_wine_if (tests[i].format.dwFourCC)
9561 ok(hr == tests[i].colorfill_hr, "Blt returned %#x, expected %#x, surface %s.\n",
9562 hr, tests[i].colorfill_hr, tests[i].name);
9564 if (SUCCEEDED(hr) && tests[i].check_result)
9566 memset(&surface_desc, 0, sizeof(surface_desc));
9567 surface_desc.dwSize = sizeof(surface_desc);
9568 hr = IDirectDrawSurface4_Lock(surface, NULL, &surface_desc, DDLOCK_READONLY, 0);
9569 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x, surface %s.\n", hr, tests[i].name);
9570 color = surface_desc.lpSurface;
9571 ok(*color == tests[i].result, "Got clear result 0x%08x, expected 0x%08x, surface %s.\n",
9572 *color, tests[i].result, tests[i].name);
9573 hr = IDirectDrawSurface4_Unlock(surface, NULL);
9574 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, surface %s.\n", hr, tests[i].name);
9577 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
9578 ok(hr == tests[i].depthfill_hr, "Blt returned %#x, expected %#x, surface %s.\n",
9579 hr, tests[i].depthfill_hr, tests[i].name);
9580 hr = IDirectDrawSurface4_Blt(surface, &rect, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
9581 ok(hr == tests[i].depthfill_hr, "Blt returned %#x, expected %#x, surface %s.\n",
9582 hr, tests[i].depthfill_hr, tests[i].name);
9584 U5(fx).dwFillColor = 0xdeadbeef;
9585 fx.dwROP = BLACKNESS;
9586 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, NULL, DDBLT_ROP | DDBLT_WAIT, &fx);
9587 ok(FAILED(hr) == !tests[i].rop_success, "Blt returned %#x, expected %s, surface %s.\n",
9588 hr, tests[i].rop_success ? "success" : "failure", tests[i].name);
9589 ok(U5(fx).dwFillColor == 0xdeadbeef, "dwFillColor was set to 0x%08x, surface %s\n",
9590 U5(fx).dwFillColor, tests[i].name);
9592 if (SUCCEEDED(hr) && tests[i].check_result)
9594 memset(&surface_desc, 0, sizeof(surface_desc));
9595 surface_desc.dwSize = sizeof(surface_desc);
9596 hr = IDirectDrawSurface4_Lock(surface, NULL, &surface_desc, DDLOCK_READONLY, 0);
9597 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x, surface %s.\n", hr, tests[i].name);
9598 color = surface_desc.lpSurface;
9599 ok(*color == 0, "Got clear result 0x%08x, expected 0x00000000, surface %s.\n",
9600 *color, tests[i].name);
9601 hr = IDirectDrawSurface4_Unlock(surface, NULL);
9602 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, surface %s.\n", hr, tests[i].name);
9605 fx.dwROP = WHITENESS;
9606 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, NULL, DDBLT_ROP | DDBLT_WAIT, &fx);
9607 ok(FAILED(hr) == !tests[i].rop_success, "Blt returned %#x, expected %s, surface %s.\n",
9608 hr, tests[i].rop_success ? "success" : "failure", tests[i].name);
9609 ok(U5(fx).dwFillColor == 0xdeadbeef, "dwFillColor was set to 0x%08x, surface %s\n",
9610 U5(fx).dwFillColor, tests[i].name);
9612 if (SUCCEEDED(hr) && tests[i].check_result)
9614 memset(&surface_desc, 0, sizeof(surface_desc));
9615 surface_desc.dwSize = sizeof(surface_desc);
9616 hr = IDirectDrawSurface4_Lock(surface, NULL, &surface_desc, DDLOCK_READONLY, 0);
9617 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x, surface %s.\n", hr, tests[i].name);
9618 color = surface_desc.lpSurface;
9619 /* WHITENESS sets the alpha channel to 0x00. Ignore this for now. */
9620 ok((*color & 0x00ffffff) == 0x00ffffff, "Got clear result 0x%08x, expected 0xffffffff, surface %s.\n",
9621 *color, tests[i].name);
9622 hr = IDirectDrawSurface4_Unlock(surface, NULL);
9623 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, surface %s.\n", hr, tests[i].name);
9626 IDirectDrawSurface4_Release(surface);
9629 memset(&fx, 0, sizeof(fx));
9630 fx.dwSize = sizeof(fx);
9631 U5(fx).dwFillColor = 0xdeadbeef;
9632 fx.dwROP = WHITENESS;
9634 memset(&surface_desc, 0, sizeof(surface_desc));
9635 surface_desc.dwSize = sizeof(surface_desc);
9636 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
9637 surface_desc.dwWidth = 64;
9638 surface_desc.dwHeight = 64;
9639 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
9640 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
9641 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
9642 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
9643 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
9644 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
9645 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
9646 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
9647 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
9648 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface2, NULL);
9649 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
9651 /* No DDBLTFX. */
9652 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, &rect, DDBLT_COLORFILL | DDBLT_WAIT, NULL);
9653 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
9654 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, &rect, DDBLT_ROP | DDBLT_WAIT, NULL);
9655 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
9657 /* Unused source rectangle. */
9658 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
9659 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
9660 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, &rect, DDBLT_ROP | DDBLT_WAIT, &fx);
9661 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
9663 /* Unused source surface. */
9664 hr = IDirectDrawSurface4_Blt(surface, NULL, surface2, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
9665 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
9666 hr = IDirectDrawSurface4_Blt(surface, NULL, surface2, NULL, DDBLT_ROP | DDBLT_WAIT, &fx);
9667 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
9668 hr = IDirectDrawSurface4_Blt(surface, NULL, surface2, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
9669 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
9670 hr = IDirectDrawSurface4_Blt(surface, NULL, surface2, &rect, DDBLT_ROP | DDBLT_WAIT, &fx);
9671 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
9673 /* Inverted destination or source rectangle. */
9674 SetRect(&rect, 5, 7, 7, 5);
9675 hr = IDirectDrawSurface4_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
9676 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
9677 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
9678 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
9679 hr = IDirectDrawSurface4_Blt(surface, &rect, surface2, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
9680 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
9681 hr = IDirectDrawSurface4_Blt(surface, NULL, surface2, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
9682 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
9683 hr = IDirectDrawSurface4_Blt(surface, NULL, surface2, &rect, DDBLT_ROP | DDBLT_WAIT, &fx);
9684 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
9686 /* Negative rectangle. */
9687 SetRect(&rect, -1, -1, 5, 5);
9688 hr = IDirectDrawSurface4_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
9689 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
9690 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
9691 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
9692 hr = IDirectDrawSurface4_Blt(surface, &rect, surface2, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
9693 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
9694 hr = IDirectDrawSurface4_Blt(surface, &rect, surface2, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
9695 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
9696 hr = IDirectDrawSurface4_Blt(surface, NULL, surface2, &rect, DDBLT_ROP | DDBLT_WAIT, &fx);
9697 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
9699 /* Out of bounds rectangle. */
9700 SetRect(&rect, 0, 0, 65, 65);
9701 hr = IDirectDrawSurface4_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
9702 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
9703 hr = IDirectDrawSurface4_Blt(surface, NULL, surface2, &rect, DDBLT_ROP | DDBLT_WAIT, &fx);
9704 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
9706 /* Combine multiple flags. */
9707 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
9708 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
9709 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_ROP | DDBLT_WAIT, &fx);
9710 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
9711 hr = IDirectDrawSurface4_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_ROP | DDBLT_WAIT, &fx);
9712 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
9714 for (i = 0; i < sizeof(rops) / sizeof(*rops); i++)
9716 fx.dwROP = rops[i].rop;
9717 hr = IDirectDrawSurface4_Blt(surface, NULL, surface2, NULL, DDBLT_ROP | DDBLT_WAIT, &fx);
9718 ok(hr == rops[i].hr, "Got unexpected hr %#x for rop %s.\n", hr, rops[i].name);
9721 IDirectDrawSurface4_Release(surface2);
9722 IDirectDrawSurface4_Release(surface);
9724 if (!z_fmt.dwSize)
9725 goto done;
9727 memset(&surface_desc, 0, sizeof(surface_desc));
9728 surface_desc.dwSize = sizeof(surface_desc);
9729 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
9730 surface_desc.dwWidth = 64;
9731 surface_desc.dwHeight = 64;
9732 U4(surface_desc).ddpfPixelFormat = z_fmt;
9733 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
9734 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
9735 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
9736 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface2, NULL);
9737 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
9739 /* No DDBLTFX. */
9740 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, NULL);
9741 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
9743 /* Unused source rectangle. */
9744 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
9745 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
9747 /* Unused source surface. */
9748 hr = IDirectDrawSurface4_Blt(surface, NULL, surface2, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
9749 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
9750 hr = IDirectDrawSurface4_Blt(surface, NULL, surface2, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
9751 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
9753 /* Inverted destination or source rectangle. */
9754 SetRect(&rect, 5, 7, 7, 5);
9755 hr = IDirectDrawSurface4_Blt(surface, &rect, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
9756 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
9757 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
9758 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
9759 hr = IDirectDrawSurface4_Blt(surface, &rect, surface2, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
9760 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
9761 hr = IDirectDrawSurface4_Blt(surface, NULL, surface2, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
9762 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
9764 /* Negative rectangle. */
9765 SetRect(&rect, -1, -1, 5, 5);
9766 hr = IDirectDrawSurface4_Blt(surface, &rect, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
9767 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
9768 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
9769 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
9770 hr = IDirectDrawSurface4_Blt(surface, &rect, surface2, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
9771 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
9772 hr = IDirectDrawSurface4_Blt(surface, &rect, surface2, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
9773 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
9775 /* Out of bounds rectangle. */
9776 SetRect(&rect, 0, 0, 65, 65);
9777 hr = IDirectDrawSurface4_Blt(surface, &rect, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
9778 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
9780 /* Combine multiple flags. */
9781 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
9782 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
9784 IDirectDrawSurface4_Release(surface2);
9785 IDirectDrawSurface4_Release(surface);
9787 done:
9788 IDirectDraw4_Release(ddraw);
9789 refcount = IDirect3DDevice3_Release(device);
9790 ok(!refcount, "Device has %u references left.\n", refcount);
9791 DestroyWindow(window);
9794 static void test_texcoordindex(void)
9796 static struct
9798 struct vec3 pos;
9799 struct vec2 texcoord1;
9800 struct vec2 texcoord2;
9801 struct vec2 texcoord3;
9803 quad[] =
9805 {{-1.0f, -1.0f, 0.0f}, {0.0f, 1.0f}, {0.0f, 0.0f}, {1.0f, 1.0f}},
9806 {{-1.0f, 1.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 1.0f}, {1.0f, 0.0f}},
9807 {{ 1.0f, -1.0f, 0.0f}, {1.0f, 1.0f}, {1.0f, 0.0f}, {0.0f, 1.0f}},
9808 {{ 1.0f, 1.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 0.0f}},
9810 static const DWORD fvf = D3DFVF_XYZ | D3DFVF_TEX3;
9811 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
9812 IDirect3DDevice3 *device;
9813 IDirect3D3 *d3d;
9814 IDirectDraw4 *ddraw;
9815 IDirectDrawSurface4 *rt;
9816 IDirect3DViewport3 *viewport;
9817 HWND window;
9818 HRESULT hr;
9819 IDirectDrawSurface4 *surface1, *surface2;
9820 IDirect3DTexture2 *texture1, *texture2;
9821 DDSURFACEDESC2 surface_desc;
9822 ULONG refcount;
9823 D3DCOLOR color;
9824 DWORD *ptr;
9826 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
9827 0, 0, 640, 480, 0, 0, 0, 0);
9828 if (!(device = create_device(window, DDSCL_NORMAL)))
9830 skip("Failed to create a 3D device, skipping test.\n");
9831 DestroyWindow(window);
9832 return;
9835 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
9836 ok(SUCCEEDED(hr), "Failed to get Direct3D3 interface, hr %#x.\n", hr);
9837 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
9838 ok(SUCCEEDED(hr), "Failed to get DirectDraw4 interface, hr %#x.\n", hr);
9839 IDirect3D3_Release(d3d);
9841 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
9842 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
9844 memset(&surface_desc, 0, sizeof(surface_desc));
9845 surface_desc.dwSize = sizeof(surface_desc);
9846 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
9847 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
9848 surface_desc.dwWidth = 2;
9849 surface_desc.dwHeight = 2;
9850 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
9851 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
9852 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
9853 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
9854 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
9855 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
9856 U5(U4(surface_desc).ddpfPixelFormat).dwRGBAlphaBitMask = 0xff000000;
9857 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface1, NULL);
9858 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
9859 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface2, NULL);
9860 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
9862 memset(&surface_desc, 0, sizeof(surface_desc));
9863 surface_desc.dwSize = sizeof(surface_desc);
9864 hr = IDirectDrawSurface4_Lock(surface1, 0, &surface_desc, 0, NULL);
9865 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
9866 ptr = surface_desc.lpSurface;
9867 ptr[0] = 0xff000000;
9868 ptr[1] = 0xff00ff00;
9869 ptr += U1(surface_desc).lPitch / sizeof(*ptr);
9870 ptr[0] = 0xff0000ff;
9871 ptr[1] = 0xff00ffff;
9872 hr = IDirectDrawSurface4_Unlock(surface1, NULL);
9873 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
9875 memset(&surface_desc, 0, sizeof(surface_desc));
9876 surface_desc.dwSize = sizeof(surface_desc);
9877 hr = IDirectDrawSurface4_Lock(surface2, 0, &surface_desc, 0, NULL);
9878 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
9879 ptr = surface_desc.lpSurface;
9880 ptr[0] = 0xff000000;
9881 ptr[1] = 0xff0000ff;
9882 ptr += U1(surface_desc).lPitch / sizeof(*ptr);
9883 ptr[0] = 0xffff0000;
9884 ptr[1] = 0xffff00ff;
9885 hr = IDirectDrawSurface4_Unlock(surface2, 0);
9886 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
9888 viewport = create_viewport(device, 0, 0, 640, 480);
9889 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
9890 ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr);
9892 hr = IDirectDrawSurface4_QueryInterface(surface1, &IID_IDirect3DTexture2, (void **)&texture1);
9893 ok(SUCCEEDED(hr), "Failed to get texture interface, hr %#x.\n", hr);
9894 hr = IDirectDrawSurface4_QueryInterface(surface2, &IID_IDirect3DTexture2, (void **)&texture2);
9895 ok(SUCCEEDED(hr), "Failed to get texture interface, hr %#x.\n", hr);
9896 hr = IDirect3DDevice3_SetTexture(device, 0, texture1);
9897 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
9898 hr = IDirect3DDevice3_SetTexture(device, 1, texture2);
9899 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
9900 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
9901 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9902 hr = IDirect3DDevice3_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
9903 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
9904 hr = IDirect3DDevice3_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
9905 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
9906 hr = IDirect3DDevice3_SetTextureStageState(device, 1, D3DTSS_COLOROP, D3DTOP_ADD);
9907 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
9908 hr = IDirect3DDevice3_SetTextureStageState(device, 1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
9909 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
9910 hr = IDirect3DDevice3_SetTextureStageState(device, 1, D3DTSS_COLORARG2, D3DTA_CURRENT);
9911 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
9912 hr = IDirect3DDevice3_SetTextureStageState(device, 2, D3DTSS_COLOROP, D3DTOP_DISABLE);
9913 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
9915 hr = IDirect3DDevice3_SetTextureStageState(device, 0, D3DTSS_TEXCOORDINDEX, 1);
9916 ok(SUCCEEDED(hr), "Failed to set texcoord index, hr %#x.\n", hr);
9917 hr = IDirect3DDevice3_SetTextureStageState(device, 1, D3DTSS_TEXCOORDINDEX, 0);
9918 ok(SUCCEEDED(hr), "Failed to set texcoord index, hr %#x.\n", hr);
9920 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ZENABLE, FALSE);
9921 ok(SUCCEEDED(hr), "Failed to disable z-buffering, hr %#x.\n", hr);
9923 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xffffff00, 1.0f, 0);
9924 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
9926 hr = IDirect3DDevice3_BeginScene(device);
9927 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
9928 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, fvf, quad, 4, 0);
9929 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9930 hr = IDirect3DDevice3_EndScene(device);
9931 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
9933 color = get_surface_color(rt, 160, 120);
9934 ok(compare_color(color, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color);
9935 color = get_surface_color(rt, 480, 120);
9936 ok(compare_color(color, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color);
9937 color = get_surface_color(rt, 160, 360);
9938 ok(compare_color(color, 0x00ff0000, 2), "Got unexpected color 0x%08x.\n", color);
9939 color = get_surface_color(rt, 480, 360);
9940 ok(compare_color(color, 0x00ffffff, 2), "Got unexpected color 0x%08x.\n", color);
9942 /* D3DTSS_TEXTURETRANSFORMFLAGS was introduced in D3D7, can't test it here. */
9944 hr = IDirect3DDevice3_SetTextureStageState(device, 1, D3DTSS_TEXCOORDINDEX, 2);
9945 ok(SUCCEEDED(hr), "Failed to set texcoord index, hr %#x.\n", hr);
9947 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xffffff00, 1.0f, 0);
9948 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
9950 hr = IDirect3DDevice3_BeginScene(device);
9951 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
9952 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, fvf, quad, 4, 0);
9953 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9954 hr = IDirect3DDevice3_EndScene(device);
9955 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
9957 color = get_surface_color(rt, 160, 120);
9958 ok(compare_color(color, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color);
9959 color = get_surface_color(rt, 480, 120);
9960 ok(compare_color(color, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color);
9961 color = get_surface_color(rt, 160, 360);
9962 ok(compare_color(color, 0x00ff00ff, 2), "Got unexpected color 0x%08x.\n", color);
9963 color = get_surface_color(rt, 480, 360);
9964 ok(compare_color(color, 0x00ffff00, 2), "Got unexpected color 0x%08x.\n", color);
9966 IDirect3DTexture2_Release(texture2);
9967 IDirect3DTexture2_Release(texture1);
9968 IDirectDrawSurface4_Release(surface2);
9969 IDirectDrawSurface4_Release(surface1);
9971 destroy_viewport(device, viewport);
9973 IDirectDrawSurface4_Release(rt);
9974 IDirectDraw_Release(ddraw);
9975 refcount = IDirect3DDevice3_Release(device);
9976 ok(!refcount, "Device has %u references left.\n", refcount);
9977 DestroyWindow(window);
9980 static void test_colorkey_precision(void)
9982 static struct
9984 struct vec3 pos;
9985 struct vec2 texcoord;
9987 quad[] =
9989 {{-1.0f, -1.0f, 0.0f}, {0.0f, 1.0f}},
9990 {{-1.0f, 1.0f, 0.0f}, {0.0f, 0.0f}},
9991 {{ 1.0f, -1.0f, 0.0f}, {1.0f, 1.0f}},
9992 {{ 1.0f, 1.0f, 0.0f}, {1.0f, 0.0f}},
9994 IDirect3DDevice3 *device;
9995 IDirect3D3 *d3d;
9996 IDirectDraw4 *ddraw;
9997 IDirectDrawSurface4 *rt;
9998 IDirect3DViewport3 *viewport;
9999 HWND window;
10000 HRESULT hr;
10001 IDirectDrawSurface4 *src, *dst, *texture;
10002 IDirect3DTexture2 *d3d_texture;
10003 DDSURFACEDESC2 surface_desc, lock_desc;
10004 ULONG refcount;
10005 D3DCOLOR color;
10006 unsigned int t, c;
10007 DDCOLORKEY ckey;
10008 DDBLTFX fx;
10009 DWORD data[4] = {0}, color_mask;
10010 D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
10011 BOOL is_nvidia, is_warp;
10012 static const struct
10014 unsigned int max, shift, bpp, clear;
10015 const char *name;
10016 BOOL skip_nv;
10017 DDPIXELFORMAT fmt;
10019 tests[] =
10022 255, 0, 4, 0x00345678, "D3DFMT_X8R8G8B8", FALSE,
10024 sizeof(DDPIXELFORMAT), DDPF_RGB, 0,
10025 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0x00000000}
10030 63, 5, 2, 0x5678, "D3DFMT_R5G6B5, G channel", FALSE,
10032 sizeof(DDPIXELFORMAT), DDPF_RGB, 0,
10033 {16}, {0xf800}, {0x07e0}, {0x001f}, {0x0000}
10038 31, 0, 2, 0x5678, "D3DFMT_R5G6B5, B channel", FALSE,
10040 sizeof(DDPIXELFORMAT), DDPF_RGB, 0,
10041 {16}, {0xf800}, {0x07e0}, {0x001f}, {0x0000}
10046 15, 0, 2, 0x0678, "D3DFMT_A4R4G4B4", TRUE,
10048 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
10049 {16}, {0x0f00}, {0x00f0}, {0x000f}, {0xf000}
10054 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
10055 0, 0, 640, 480, 0, 0, 0, 0);
10056 if (!(device = create_device(window, DDSCL_NORMAL)))
10058 skip("Failed to create a 3D device, skipping test.\n");
10059 DestroyWindow(window);
10060 return;
10063 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
10064 ok(SUCCEEDED(hr), "Failed to get Direct3D3 interface, hr %#x.\n", hr);
10065 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
10066 ok(SUCCEEDED(hr), "Failed to get DirectDraw4 interface, hr %#x.\n", hr);
10067 IDirect3D3_Release(d3d);
10068 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
10069 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
10071 is_nvidia = ddraw_is_nvidia(ddraw);
10072 /* The Windows 8 WARP driver has plenty of false negatives in X8R8G8B8
10073 * (color key doesn't match although the values are equal), and a false
10074 * positive when the color key is 0 and the texture contains the value 1.
10075 * I don't want to mark this broken unconditionally since this would
10076 * essentially disable the test on Windows. Also on random occasions
10077 * 254 == 255 and 255 != 255.*/
10078 is_warp = ddraw_is_warp(ddraw);
10080 viewport = create_viewport(device, 0, 0, 640, 480);
10081 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
10082 ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr);
10084 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
10085 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
10086 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
10087 ok(SUCCEEDED(hr), "Failed to disable z-buffering, hr %#x.\n", hr);
10088 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, TRUE);
10089 ok(SUCCEEDED(hr), "Failed to enable color keying, hr %#x.\n", hr);
10090 /* Multiply the texture read result with 0, that way the result color if the key doesn't
10091 * match is constant. In theory color keying works without reading the texture result
10092 * (meaning we could just op=arg1, arg1=tfactor), but the Geforce7 Windows driver begs
10093 * to differ. */
10094 hr = IDirect3DDevice3_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_MODULATE);
10095 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
10096 hr = IDirect3DDevice3_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
10097 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
10098 hr = IDirect3DDevice3_SetTextureStageState(device, 0, D3DTSS_COLORARG2, D3DTA_TFACTOR);
10099 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
10100 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_TEXTUREFACTOR, 0x00000000);
10101 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
10103 memset(&fx, 0, sizeof(fx));
10104 fx.dwSize = sizeof(fx);
10105 memset(&lock_desc, 0, sizeof(lock_desc));
10106 lock_desc.dwSize = sizeof(lock_desc);
10108 for (t = 0; t < sizeof(tests) / sizeof(*tests); ++t)
10110 if (is_nvidia && tests[t].skip_nv)
10112 win_skip("Skipping test %s on Nvidia Windows drivers.\n", tests[t].name);
10113 continue;
10116 memset(&surface_desc, 0, sizeof(surface_desc));
10117 surface_desc.dwSize = sizeof(surface_desc);
10118 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
10119 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
10120 surface_desc.dwWidth = 4;
10121 surface_desc.dwHeight = 1;
10122 U4(surface_desc).ddpfPixelFormat = tests[t].fmt;
10123 /* Windows XP (at least with the r200 driver, other drivers untested) produces
10124 * garbage when doing color keyed texture->texture blits. */
10125 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &src, NULL);
10126 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
10127 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &dst, NULL);
10128 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
10130 U5(fx).dwFillColor = tests[t].clear;
10131 /* On the w8 testbot (WARP driver) the blit result has different values in the
10132 * X channel. */
10133 color_mask = U2(tests[t].fmt).dwRBitMask
10134 | U3(tests[t].fmt).dwGBitMask
10135 | U4(tests[t].fmt).dwBBitMask;
10137 for (c = 0; c <= tests[t].max; ++c)
10139 /* The idiotic Nvidia Windows driver can't change the color key on a d3d
10140 * texture after it has been set once... */
10141 surface_desc.dwFlags |= DDSD_CKSRCBLT;
10142 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
10143 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = c << tests[t].shift;
10144 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = c << tests[t].shift;
10145 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &texture, NULL);
10146 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
10147 hr = IDirectDrawSurface4_QueryInterface(texture, &IID_IDirect3DTexture2, (void **)&d3d_texture);
10148 ok(SUCCEEDED(hr), "Failed to get texture interface, hr %#x.\n", hr);
10149 hr = IDirect3DDevice3_SetTexture(device, 0, d3d_texture);
10150 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
10152 hr = IDirectDrawSurface4_Blt(dst, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
10153 ok(SUCCEEDED(hr), "Failed to clear destination surface, hr %#x.\n", hr);
10155 hr = IDirectDrawSurface4_Lock(src, NULL, &lock_desc, DDLOCK_WAIT, NULL);
10156 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
10157 switch (tests[t].bpp)
10159 case 4:
10160 ((DWORD *)lock_desc.lpSurface)[0] = (c ? c - 1 : 0) << tests[t].shift;
10161 ((DWORD *)lock_desc.lpSurface)[1] = c << tests[t].shift;
10162 ((DWORD *)lock_desc.lpSurface)[2] = min(c + 1, tests[t].max) << tests[t].shift;
10163 ((DWORD *)lock_desc.lpSurface)[3] = 0xffffffff;
10164 break;
10166 case 2:
10167 ((WORD *)lock_desc.lpSurface)[0] = (c ? c - 1 : 0) << tests[t].shift;
10168 ((WORD *)lock_desc.lpSurface)[1] = c << tests[t].shift;
10169 ((WORD *)lock_desc.lpSurface)[2] = min(c + 1, tests[t].max) << tests[t].shift;
10170 ((WORD *)lock_desc.lpSurface)[3] = 0xffff;
10171 break;
10173 hr = IDirectDrawSurface4_Unlock(src, 0);
10174 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
10175 hr = IDirectDrawSurface4_Blt(texture, NULL, src, NULL, DDBLT_WAIT, NULL);
10176 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
10178 ckey.dwColorSpaceLowValue = c << tests[t].shift;
10179 ckey.dwColorSpaceHighValue = c << tests[t].shift;
10180 hr = IDirectDrawSurface4_SetColorKey(src, DDCKEY_SRCBLT, &ckey);
10181 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
10183 hr = IDirectDrawSurface4_Blt(dst, NULL, src, NULL, DDBLT_KEYSRC | DDBLT_WAIT, NULL);
10184 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
10186 /* Don't make this read only, it somehow breaks the detection of the Nvidia bug below. */
10187 hr = IDirectDrawSurface4_Lock(dst, NULL, &lock_desc, DDLOCK_WAIT, NULL);
10188 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
10189 switch (tests[t].bpp)
10191 case 4:
10192 data[0] = ((DWORD *)lock_desc.lpSurface)[0] & color_mask;
10193 data[1] = ((DWORD *)lock_desc.lpSurface)[1] & color_mask;
10194 data[2] = ((DWORD *)lock_desc.lpSurface)[2] & color_mask;
10195 data[3] = ((DWORD *)lock_desc.lpSurface)[3] & color_mask;
10196 break;
10198 case 2:
10199 data[0] = ((WORD *)lock_desc.lpSurface)[0] & color_mask;
10200 data[1] = ((WORD *)lock_desc.lpSurface)[1] & color_mask;
10201 data[2] = ((WORD *)lock_desc.lpSurface)[2] & color_mask;
10202 data[3] = ((WORD *)lock_desc.lpSurface)[3] & color_mask;
10203 break;
10205 hr = IDirectDrawSurface4_Unlock(dst, 0);
10206 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
10208 if (!c)
10210 ok(data[0] == tests[t].clear, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10211 tests[t].clear, data[0], tests[t].name, c);
10213 if (data[3] == tests[t].clear)
10215 /* My Geforce GTX 460 on Windows 7 misbehaves when A4R4G4B4 is blitted with color
10216 * keying: The blit takes ~0.5 seconds, and subsequent color keying draws are broken,
10217 * even when a different surface is used. The blit itself doesn't draw anything,
10218 * so we can detect the bug by looking at the otherwise unused 4th texel. It should
10219 * never be masked out by the key.
10221 * On Windows 10 the problem is worse, Blt just hangs. For this reason the ARGB4444
10222 * test is disabled entirely.
10224 * Also appears to affect the testbot in some way with R5G6B5. Color keying is
10225 * terrible on WARP. */
10226 skip("Nvidia A4R4G4B4 color keying blit bug detected, skipping.\n");
10227 IDirect3DTexture2_Release(d3d_texture);
10228 IDirectDrawSurface4_Release(texture);
10229 IDirectDrawSurface4_Release(src);
10230 IDirectDrawSurface4_Release(dst);
10231 goto done;
10234 else
10235 ok(data[0] == (c - 1) << tests[t].shift, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10236 (c - 1) << tests[t].shift, data[0], tests[t].name, c);
10238 ok(data[1] == tests[t].clear, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10239 tests[t].clear, data[1], tests[t].name, c);
10241 if (c == tests[t].max)
10242 ok(data[2] == tests[t].clear, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10243 tests[t].clear, data[2], tests[t].name, c);
10244 else
10245 ok(data[2] == (c + 1) << tests[t].shift, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10246 (c + 1) << tests[t].shift, data[2], tests[t].name, c);
10248 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0x0000ff00, 1.0f, 0);
10249 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
10251 hr = IDirect3DDevice3_BeginScene(device);
10252 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
10253 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_TEX1, quad, 4, 0);
10254 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10255 hr = IDirect3DDevice3_EndScene(device);
10256 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
10258 color = get_surface_color(rt, 80, 240);
10259 if (!c)
10260 ok(compare_color(color, 0x0000ff00, 1) || broken(is_warp && compare_color(color, 0x00000000, 1)),
10261 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10262 color, tests[t].name, c);
10263 else
10264 ok(compare_color(color, 0x00000000, 1) || broken(is_warp && compare_color(color, 0x0000ff00, 1)),
10265 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10266 color, tests[t].name, c);
10268 color = get_surface_color(rt, 240, 240);
10269 ok(compare_color(color, 0x0000ff00, 1) || broken(is_warp && compare_color(color, 0x00000000, 1)),
10270 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10271 color, tests[t].name, c);
10273 color = get_surface_color(rt, 400, 240);
10274 if (c == tests[t].max)
10275 ok(compare_color(color, 0x0000ff00, 1) || broken(is_warp && compare_color(color, 0x00000000, 1)),
10276 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10277 color, tests[t].name, c);
10278 else
10279 ok(compare_color(color, 0x00000000, 1) || broken(is_warp && compare_color(color, 0x0000ff00, 1)),
10280 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10281 color, tests[t].name, c);
10283 IDirect3DTexture2_Release(d3d_texture);
10284 IDirectDrawSurface4_Release(texture);
10286 IDirectDrawSurface4_Release(src);
10287 IDirectDrawSurface4_Release(dst);
10289 done:
10291 destroy_viewport(device, viewport);
10292 IDirectDrawSurface4_Release(rt);
10293 IDirectDraw4_Release(ddraw);
10294 refcount = IDirect3DDevice3_Release(device);
10295 ok(!refcount, "Device has %u references left.\n", refcount);
10296 DestroyWindow(window);
10299 static void test_range_colorkey(void)
10301 IDirectDraw4 *ddraw;
10302 HWND window;
10303 HRESULT hr;
10304 IDirectDrawSurface4 *surface;
10305 DDSURFACEDESC2 surface_desc;
10306 ULONG refcount;
10307 DDCOLORKEY ckey;
10309 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
10310 0, 0, 640, 480, 0, 0, 0, 0);
10311 ddraw = create_ddraw();
10312 ok(!!ddraw, "Failed to create a ddraw object.\n");
10313 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
10314 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
10316 memset(&surface_desc, 0, sizeof(surface_desc));
10317 surface_desc.dwSize = sizeof(surface_desc);
10318 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CKSRCBLT;
10319 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
10320 surface_desc.dwWidth = 1;
10321 surface_desc.dwHeight = 1;
10322 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
10323 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
10324 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
10325 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
10326 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
10327 U5(U4(surface_desc).ddpfPixelFormat).dwRGBAlphaBitMask = 0x00000000;
10329 /* Creating a surface with a range color key fails with DDERR_NOCOLORKEY. */
10330 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00000000;
10331 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00000001;
10332 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
10333 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
10335 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00000001;
10336 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00000000;
10337 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
10338 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
10340 /* Same for DDSCAPS_OFFSCREENPLAIN. */
10341 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
10342 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00000000;
10343 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00000001;
10344 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
10345 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
10347 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00000001;
10348 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00000000;
10349 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
10350 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
10352 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00000000;
10353 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00000000;
10354 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
10355 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
10357 /* Setting a range color key without DDCKEY_COLORSPACE collapses the key. */
10358 ckey.dwColorSpaceLowValue = 0x00000000;
10359 ckey.dwColorSpaceHighValue = 0x00000001;
10360 hr = IDirectDrawSurface4_SetColorKey(surface, DDCKEY_SRCBLT, &ckey);
10361 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
10363 hr = IDirectDrawSurface4_GetColorKey(surface, DDCKEY_SRCBLT, &ckey);
10364 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
10365 ok(!ckey.dwColorSpaceLowValue, "Got unexpected value 0x%08x.\n", ckey.dwColorSpaceLowValue);
10366 ok(!ckey.dwColorSpaceHighValue, "Got unexpected value 0x%08x.\n", ckey.dwColorSpaceHighValue);
10368 ckey.dwColorSpaceLowValue = 0x00000001;
10369 ckey.dwColorSpaceHighValue = 0x00000000;
10370 hr = IDirectDrawSurface4_SetColorKey(surface, DDCKEY_SRCBLT, &ckey);
10371 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
10373 hr = IDirectDrawSurface4_GetColorKey(surface, DDCKEY_SRCBLT, &ckey);
10374 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
10375 ok(ckey.dwColorSpaceLowValue == 0x00000001, "Got unexpected value 0x%08x.\n", ckey.dwColorSpaceLowValue);
10376 ok(ckey.dwColorSpaceHighValue == 0x00000001, "Got unexpected value 0x%08x.\n", ckey.dwColorSpaceHighValue);
10378 /* DDCKEY_COLORSPACE is ignored if the key is a single value. */
10379 ckey.dwColorSpaceLowValue = 0x00000000;
10380 ckey.dwColorSpaceHighValue = 0x00000000;
10381 hr = IDirectDrawSurface4_SetColorKey(surface, DDCKEY_SRCBLT | DDCKEY_COLORSPACE, &ckey);
10382 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
10384 /* Using it with a range key results in DDERR_NOCOLORKEYHW. */
10385 ckey.dwColorSpaceLowValue = 0x00000001;
10386 ckey.dwColorSpaceHighValue = 0x00000000;
10387 hr = IDirectDrawSurface4_SetColorKey(surface, DDCKEY_SRCBLT | DDCKEY_COLORSPACE, &ckey);
10388 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
10389 ckey.dwColorSpaceLowValue = 0x00000000;
10390 ckey.dwColorSpaceHighValue = 0x00000001;
10391 hr = IDirectDrawSurface4_SetColorKey(surface, DDCKEY_SRCBLT | DDCKEY_COLORSPACE, &ckey);
10392 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
10393 /* Range destination keys don't work either. */
10394 hr = IDirectDrawSurface4_SetColorKey(surface, DDCKEY_DESTBLT | DDCKEY_COLORSPACE, &ckey);
10395 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
10397 /* Just to show it's not because of A, R, and G having equal values. */
10398 ckey.dwColorSpaceLowValue = 0x00000000;
10399 ckey.dwColorSpaceHighValue = 0x01010101;
10400 hr = IDirectDrawSurface4_SetColorKey(surface, DDCKEY_SRCBLT | DDCKEY_COLORSPACE, &ckey);
10401 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
10403 /* None of these operations modified the key. */
10404 hr = IDirectDrawSurface4_GetColorKey(surface, DDCKEY_SRCBLT, &ckey);
10405 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
10406 ok(!ckey.dwColorSpaceLowValue, "Got unexpected value 0x%08x.\n", ckey.dwColorSpaceLowValue);
10407 ok(!ckey.dwColorSpaceHighValue, "Got unexpected value 0x%08x.\n", ckey.dwColorSpaceHighValue);
10409 IDirectDrawSurface4_Release(surface),
10410 refcount = IDirectDraw4_Release(ddraw);
10411 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
10412 DestroyWindow(window);
10415 static void test_shademode(void)
10417 IDirect3DVertexBuffer *vb_strip, *vb_list, *buffer;
10418 IDirect3DViewport3 *viewport;
10419 IDirect3DDevice3 *device;
10420 D3DVERTEXBUFFERDESC desc;
10421 IDirectDrawSurface4 *rt;
10422 DWORD color0, color1;
10423 void *data = NULL;
10424 IDirect3D3 *d3d;
10425 ULONG refcount;
10426 UINT i, count;
10427 HWND window;
10428 HRESULT hr;
10429 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
10430 static const struct
10432 struct vec3 position;
10433 DWORD diffuse;
10435 quad_strip[] =
10437 {{-1.0f, -1.0f, 0.0f}, 0xffff0000},
10438 {{-1.0f, 1.0f, 0.0f}, 0xff00ff00},
10439 {{ 1.0f, -1.0f, 0.0f}, 0xff0000ff},
10440 {{ 1.0f, 1.0f, 0.0f}, 0xffffffff},
10442 quad_list[] =
10444 {{-1.0f, -1.0f, 0.0f}, 0xffff0000},
10445 {{-1.0f, 1.0f, 0.0f}, 0xff00ff00},
10446 {{ 1.0f, -1.0f, 0.0f}, 0xff0000ff},
10448 {{ 1.0f, -1.0f, 0.0f}, 0xff0000ff},
10449 {{-1.0f, 1.0f, 0.0f}, 0xff00ff00},
10450 {{ 1.0f, 1.0f, 0.0f}, 0xffffffff},
10452 static const struct
10454 DWORD primtype;
10455 DWORD shademode;
10456 DWORD color0, color1;
10458 tests[] =
10460 {D3DPT_TRIANGLESTRIP, D3DSHADE_FLAT, 0x00ff0000, 0x0000ff00},
10461 {D3DPT_TRIANGLESTRIP, D3DSHADE_PHONG, 0x000dca28, 0x000d45c7},
10462 {D3DPT_TRIANGLESTRIP, D3DSHADE_GOURAUD, 0x000dca28, 0x000d45c7},
10463 {D3DPT_TRIANGLESTRIP, D3DSHADE_PHONG, 0x000dca28, 0x000d45c7},
10464 {D3DPT_TRIANGLELIST, D3DSHADE_FLAT, 0x00ff0000, 0x000000ff},
10465 {D3DPT_TRIANGLELIST, D3DSHADE_GOURAUD, 0x000dca28, 0x000d45c7},
10468 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
10469 0, 0, 640, 480, 0, 0, 0, 0);
10471 if (!(device = create_device(window, DDSCL_NORMAL)))
10473 skip("Failed to create a 3D device, skipping test.\n");
10474 DestroyWindow(window);
10475 return;
10478 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
10479 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
10480 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
10481 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
10483 viewport = create_viewport(device, 0, 0, 640, 480);
10484 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
10485 ok(SUCCEEDED(hr), "Failed to activate the viewport, hr %#x.\n", hr);
10487 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, FALSE);
10488 ok(SUCCEEDED(hr), "Failed to disable fog, hr %#x.\n", hr);
10490 memset(&desc, 0, sizeof(desc));
10491 desc.dwSize = sizeof(desc);
10492 desc.dwCaps = D3DVBCAPS_WRITEONLY;
10493 desc.dwFVF = D3DFVF_XYZ | D3DFVF_DIFFUSE;
10494 desc.dwNumVertices = sizeof(quad_strip) / sizeof(*quad_strip);
10495 hr = IDirect3D3_CreateVertexBuffer(d3d, &desc, &vb_strip, 0, NULL);
10496 ok(hr == D3D_OK, "Failed to create vertex buffer, hr %#x.\n", hr);
10497 hr = IDirect3DVertexBuffer_Lock(vb_strip, 0, &data, NULL);
10498 ok(hr == D3D_OK, "Failed to lock vertex buffer, hr %#x.\n", hr);
10499 memcpy(data, quad_strip, sizeof(quad_strip));
10500 hr = IDirect3DVertexBuffer_Unlock(vb_strip);
10501 ok(hr == D3D_OK, "Failed to unlock vertex buffer, hr %#x.\n", hr);
10503 desc.dwNumVertices = sizeof(quad_list) / sizeof(*quad_list);
10504 hr = IDirect3D3_CreateVertexBuffer(d3d, &desc, &vb_list, 0, NULL);
10505 ok(hr == D3D_OK, "Failed to create vertex buffer, hr %#x.\n", hr);
10506 hr = IDirect3DVertexBuffer_Lock(vb_list, 0, &data, NULL);
10507 ok(hr == D3D_OK, "Failed to lock vertex buffer, hr %#x.\n", hr);
10508 memcpy(data, quad_list, sizeof(quad_list));
10509 hr = IDirect3DVertexBuffer_Unlock(vb_list);
10510 ok(hr == D3D_OK, "Failed to unlock vertex buffer, hr %#x.\n", hr);
10512 /* Try it first with a TRIANGLESTRIP. Do it with different geometry because
10513 * the color fixups we have to do for FLAT shading will be dependent on that. */
10515 for (i = 0; i < sizeof(tests) / sizeof(tests[0]); ++i)
10517 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xffffffff, 0.0f, 0);
10518 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
10520 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_SHADEMODE, tests[i].shademode);
10521 ok(hr == D3D_OK, "Failed to set shade mode, hr %#x.\n", hr);
10523 hr = IDirect3DDevice3_BeginScene(device);
10524 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
10525 buffer = tests[i].primtype == D3DPT_TRIANGLESTRIP ? vb_strip : vb_list;
10526 count = tests[i].primtype == D3DPT_TRIANGLESTRIP ? 4 : 6;
10527 hr = IDirect3DDevice3_DrawPrimitiveVB(device, tests[i].primtype, buffer, 0, count, 0);
10528 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10529 hr = IDirect3DDevice3_EndScene(device);
10530 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
10532 color0 = get_surface_color(rt, 100, 100); /* Inside first triangle */
10533 color1 = get_surface_color(rt, 500, 350); /* Inside second triangle */
10535 /* For D3DSHADE_FLAT it should take the color of the first vertex of
10536 * each triangle. This requires EXT_provoking_vertex or similar
10537 * functionality being available. */
10538 /* PHONG should be the same as GOURAUD, since no hardware implements
10539 * this. */
10540 ok(compare_color(color0, tests[i].color0, 1), "Test %u shading has color0 %08x, expected %08x.\n",
10541 i, color0, tests[i].color0);
10542 ok(compare_color(color1, tests[i].color1, 1), "Test %u shading has color1 %08x, expected %08x.\n",
10543 i, color1, tests[i].color1);
10546 IDirect3DVertexBuffer_Release(vb_strip);
10547 IDirect3DVertexBuffer_Release(vb_list);
10548 destroy_viewport(device, viewport);
10549 IDirectDrawSurface4_Release(rt);
10550 IDirect3D3_Release(d3d);
10551 refcount = IDirect3DDevice3_Release(device);
10552 ok(!refcount, "Device has %u references left.\n", refcount);
10553 DestroyWindow(window);
10556 static void test_lockrect_invalid(void)
10558 unsigned int i, r;
10559 IDirectDraw4 *ddraw;
10560 IDirectDrawSurface4 *surface;
10561 HWND window;
10562 HRESULT hr;
10563 DDSURFACEDESC2 surface_desc;
10564 DDCAPS hal_caps;
10565 DWORD needed_caps = DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY;
10566 static RECT valid[] =
10568 {60, 60, 68, 68},
10569 {60, 60, 60, 68},
10570 {60, 60, 68, 60},
10571 {120, 60, 128, 68},
10572 {60, 120, 68, 128},
10574 static RECT invalid[] =
10576 {68, 60, 60, 68}, /* left > right */
10577 {60, 68, 68, 60}, /* top > bottom */
10578 {-8, 60, 0, 68}, /* left < surface */
10579 {60, -8, 68, 0}, /* top < surface */
10580 {-16, 60, -8, 68}, /* right < surface */
10581 {60, -16, 68, -8}, /* bottom < surface */
10582 {60, 60, 136, 68}, /* right > surface */
10583 {60, 60, 68, 136}, /* bottom > surface */
10584 {136, 60, 144, 68}, /* left > surface */
10585 {60, 136, 68, 144}, /* top > surface */
10587 static const struct
10589 DWORD caps, caps2;
10590 const char *name;
10591 HRESULT hr;
10593 resources[] =
10595 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY, 0, "sysmem offscreenplain", DDERR_INVALIDPARAMS},
10596 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0, "vidmem offscreenplain", DDERR_INVALIDPARAMS},
10597 {DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, 0, "sysmem texture", DDERR_INVALIDPARAMS},
10598 {DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, 0, "vidmem texture", DDERR_INVALIDPARAMS},
10599 {DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, "managed texture", DDERR_INVALIDPARAMS},
10602 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
10603 0, 0, 640, 480, 0, 0, 0, 0);
10604 ddraw = create_ddraw();
10605 ok(!!ddraw, "Failed to create a ddraw object.\n");
10606 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
10607 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
10609 memset(&hal_caps, 0, sizeof(hal_caps));
10610 hal_caps.dwSize = sizeof(hal_caps);
10611 hr = IDirectDraw4_GetCaps(ddraw, &hal_caps, NULL);
10612 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
10613 if ((hal_caps.ddsCaps.dwCaps & needed_caps) != needed_caps
10614 || !(hal_caps.ddsCaps.dwCaps & DDSCAPS2_TEXTUREMANAGE))
10616 skip("Required surface types not supported, skipping test.\n");
10617 goto done;
10620 for (r = 0; r < sizeof(resources) / sizeof(*resources); ++r)
10622 memset(&surface_desc, 0, sizeof(surface_desc));
10623 surface_desc.dwSize = sizeof(surface_desc);
10624 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
10625 surface_desc.ddsCaps.dwCaps = resources[r].caps;
10626 surface_desc.ddsCaps.dwCaps2 = resources[r].caps2;
10627 surface_desc.dwWidth = 128;
10628 surface_desc.dwHeight = 128;
10629 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
10630 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
10631 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
10632 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0xff0000;
10633 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x00ff00;
10634 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x0000ff;
10636 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
10637 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x, type %s.\n", hr, resources[r].name);
10639 hr = IDirectDrawSurface4_Lock(surface, NULL, NULL, DDLOCK_WAIT, NULL);
10640 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x, type %s.\n", hr, resources[r].name);
10642 for (i = 0; i < sizeof(valid) / sizeof(*valid); ++i)
10644 RECT *rect = &valid[i];
10646 memset(&surface_desc, 0, sizeof(surface_desc));
10647 surface_desc.dwSize = sizeof(surface_desc);
10649 hr = IDirectDrawSurface4_Lock(surface, rect, &surface_desc, DDLOCK_WAIT, NULL);
10650 ok(SUCCEEDED(hr), "Lock failed (%#x) for rect %s, type %s.\n",
10651 hr, wine_dbgstr_rect(rect), resources[r].name);
10653 hr = IDirectDrawSurface4_Unlock(surface, NULL);
10654 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
10657 for (i = 0; i < sizeof(invalid) / sizeof(*invalid); ++i)
10659 RECT *rect = &invalid[i];
10661 memset(&surface_desc, 1, sizeof(surface_desc));
10662 surface_desc.dwSize = sizeof(surface_desc);
10664 hr = IDirectDrawSurface4_Lock(surface, rect, &surface_desc, DDLOCK_WAIT, NULL);
10665 ok(hr == resources[r].hr, "Lock returned %#x for rect %s, type %s.\n",
10666 hr, wine_dbgstr_rect(rect), resources[r].name);
10667 if (SUCCEEDED(hr))
10669 hr = IDirectDrawSurface4_Unlock(surface, NULL);
10670 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
10672 else
10673 ok(!surface_desc.lpSurface, "Got unexpected lpSurface %p.\n", surface_desc.lpSurface);
10676 hr = IDirectDrawSurface4_Lock(surface, NULL, &surface_desc, DDLOCK_WAIT, NULL);
10677 ok(SUCCEEDED(hr), "Lock(rect = NULL) failed, hr %#x, type %s.\n",
10678 hr, resources[r].name);
10679 hr = IDirectDrawSurface4_Lock(surface, NULL, &surface_desc, DDLOCK_WAIT, NULL);
10680 ok(hr == DDERR_SURFACEBUSY, "Double lock(rect = NULL) returned %#x, type %s.\n",
10681 hr, resources[r].name);
10682 hr = IDirectDrawSurface4_Unlock(surface, NULL);
10683 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
10685 hr = IDirectDrawSurface4_Lock(surface, &valid[0], &surface_desc, DDLOCK_WAIT, NULL);
10686 ok(SUCCEEDED(hr), "Lock(rect = %s) failed (%#x).\n", wine_dbgstr_rect(&valid[0]), hr);
10687 hr = IDirectDrawSurface4_Lock(surface, &valid[0], &surface_desc, DDLOCK_WAIT, NULL);
10688 ok(hr == DDERR_SURFACEBUSY, "Double lock(rect = %s) failed (%#x).\n",
10689 wine_dbgstr_rect(&valid[0]), hr);
10691 /* Locking a different rectangle returns DD_OK, but it seems to break the surface.
10692 * Afterwards unlocking the surface fails(NULL rectangle or both locked rectangles) */
10694 hr = IDirectDrawSurface4_Unlock(surface, NULL);
10695 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
10697 IDirectDrawSurface4_Release(surface);
10700 done:
10701 IDirectDraw4_Release(ddraw);
10702 DestroyWindow(window);
10705 static void test_yv12_overlay(void)
10707 IDirectDrawSurface4 *src_surface, *dst_surface;
10708 RECT rect = {13, 17, 14, 18};
10709 unsigned int offset, y;
10710 DDSURFACEDESC2 desc;
10711 unsigned char *base;
10712 IDirectDraw4 *ddraw;
10713 HWND window;
10714 HRESULT hr;
10716 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
10717 0, 0, 640, 480, 0, 0, 0, 0);
10718 ddraw = create_ddraw();
10719 ok(!!ddraw, "Failed to create a ddraw object.\n");
10720 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
10721 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
10723 if (!(src_surface = create_overlay(ddraw, 256, 256, MAKEFOURCC('Y','V','1','2'))))
10725 skip("Failed to create a YV12 overlay, skipping test.\n");
10726 goto done;
10729 memset(&desc, 0, sizeof(desc));
10730 desc.dwSize = sizeof(desc);
10731 hr = IDirectDrawSurface4_Lock(src_surface, NULL, &desc, DDLOCK_WAIT, NULL);
10732 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
10734 ok(desc.dwFlags == (DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_PITCH),
10735 "Got unexpected flags %#x.\n", desc.dwFlags);
10736 ok(desc.ddsCaps.dwCaps == (DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM | DDSCAPS_HWCODEC)
10737 || desc.ddsCaps.dwCaps == (DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM),
10738 "Got unexpected caps %#x.\n", desc.ddsCaps.dwCaps);
10739 ok(desc.dwWidth == 256, "Got unexpected width %u.\n", desc.dwWidth);
10740 ok(desc.dwHeight == 256, "Got unexpected height %u.\n", desc.dwHeight);
10741 /* The overlay pitch seems to have 256 byte alignment. */
10742 ok(!(U1(desc).lPitch & 0xff), "Got unexpected pitch %u.\n", U1(desc).lPitch);
10744 /* Fill the surface with some data for the blit test. */
10745 base = desc.lpSurface;
10746 /* Luminance */
10747 for (y = 0; y < desc.dwHeight; ++y)
10749 memset(base + U1(desc).lPitch * y, 0x10, desc.dwWidth);
10751 /* V */
10752 for (; y < desc.dwHeight + desc.dwHeight / 4; ++y)
10754 memset(base + U1(desc).lPitch * y, 0x20, desc.dwWidth);
10756 /* U */
10757 for (; y < desc.dwHeight + desc.dwHeight / 2; ++y)
10759 memset(base + U1(desc).lPitch * y, 0x30, desc.dwWidth);
10762 hr = IDirectDrawSurface4_Unlock(src_surface, NULL);
10763 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
10765 /* YV12 uses 2x2 blocks with 6 bytes per block (4*Y, 1*U, 1*V). Unlike
10766 * other block-based formats like DXT the entire Y channel is stored in
10767 * one big chunk of memory, followed by the chroma channels. So partial
10768 * locks do not really make sense. Show that they are allowed nevertheless
10769 * and the offset points into the luminance data. */
10770 hr = IDirectDrawSurface4_Lock(src_surface, &rect, &desc, DDLOCK_WAIT, NULL);
10771 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
10772 offset = ((const unsigned char *)desc.lpSurface - base);
10773 ok(offset == rect.top * U1(desc).lPitch + rect.left, "Got unexpected offset %u, expected %u.\n",
10774 offset, rect.top * U1(desc).lPitch + rect.left);
10775 hr = IDirectDrawSurface4_Unlock(src_surface, NULL);
10776 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
10778 if (!(dst_surface = create_overlay(ddraw, 256, 256, MAKEFOURCC('Y','V','1','2'))))
10780 /* Windows XP with a Radeon X1600 GPU refuses to create a second
10781 * overlay surface, DDERR_NOOVERLAYHW, making the blit tests moot. */
10782 skip("Failed to create a second YV12 surface, skipping blit test.\n");
10783 IDirectDrawSurface4_Release(src_surface);
10784 goto done;
10787 hr = IDirectDrawSurface4_Blt(dst_surface, NULL, src_surface, NULL, DDBLT_WAIT, NULL);
10788 /* VMware rejects YV12 blits. This behavior has not been seen on real
10789 * hardware yet, so mark it broken. */
10790 ok(SUCCEEDED(hr) || broken(hr == E_NOTIMPL), "Failed to blit, hr %#x.\n", hr);
10792 if (SUCCEEDED(hr))
10794 memset(&desc, 0, sizeof(desc));
10795 desc.dwSize = sizeof(desc);
10796 hr = IDirectDrawSurface4_Lock(dst_surface, NULL, &desc, DDLOCK_WAIT, NULL);
10797 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
10799 base = desc.lpSurface;
10800 ok(base[0] == 0x10, "Got unexpected Y data 0x%02x.\n", base[0]);
10801 base += desc.dwHeight * U1(desc).lPitch;
10802 todo_wine ok(base[0] == 0x20, "Got unexpected V data 0x%02x.\n", base[0]);
10803 base += desc.dwHeight / 4 * U1(desc).lPitch;
10804 todo_wine ok(base[0] == 0x30, "Got unexpected U data 0x%02x.\n", base[0]);
10806 hr = IDirectDrawSurface4_Unlock(dst_surface, NULL);
10807 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
10810 IDirectDrawSurface4_Release(dst_surface);
10811 IDirectDrawSurface4_Release(src_surface);
10812 done:
10813 IDirectDraw4_Release(ddraw);
10814 DestroyWindow(window);
10817 static BOOL dwm_enabled(void)
10819 BOOL ret = FALSE;
10821 if (!strcmp(winetest_platform, "wine"))
10822 return FALSE;
10823 if (!pDwmIsCompositionEnabled)
10824 return FALSE;
10825 if (FAILED(pDwmIsCompositionEnabled(&ret)))
10826 return FALSE;
10827 return ret;
10830 static void test_offscreen_overlay(void)
10832 IDirectDrawSurface4 *overlay, *offscreen, *primary;
10833 DDSURFACEDESC2 surface_desc;
10834 IDirectDraw4 *ddraw;
10835 HWND window;
10836 HRESULT hr;
10837 HDC dc;
10839 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
10840 0, 0, 640, 480, 0, 0, 0, 0);
10841 ddraw = create_ddraw();
10842 ok(!!ddraw, "Failed to create a ddraw object.\n");
10843 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
10844 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
10846 if (!(overlay = create_overlay(ddraw, 64, 64, MAKEFOURCC('U','Y','V','Y'))))
10848 skip("Failed to create a UYVY overlay, skipping test.\n");
10849 goto done;
10852 memset(&surface_desc, 0, sizeof(surface_desc));
10853 surface_desc.dwSize = sizeof(surface_desc);
10854 surface_desc.dwFlags = DDSD_CAPS;
10855 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
10856 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &primary, NULL);
10857 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
10859 /* On Windows 7, and probably Vista, UpdateOverlay() will return
10860 * DDERR_OUTOFCAPS if the dwm is active. Calling GetDC() on the primary
10861 * surface prevents this by disabling the dwm. */
10862 hr = IDirectDrawSurface4_GetDC(primary, &dc);
10863 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
10864 hr = IDirectDrawSurface4_ReleaseDC(primary, dc);
10865 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
10867 /* Try to overlay a NULL surface. */
10868 hr = IDirectDrawSurface4_UpdateOverlay(overlay, NULL, NULL, NULL, DDOVER_SHOW, NULL);
10869 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10870 hr = IDirectDrawSurface4_UpdateOverlay(overlay, NULL, NULL, NULL, DDOVER_HIDE, NULL);
10871 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10873 /* Try to overlay an offscreen surface. */
10874 memset(&surface_desc, 0, sizeof(surface_desc));
10875 surface_desc.dwSize = sizeof(surface_desc);
10876 surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
10877 surface_desc.dwWidth = 64;
10878 surface_desc.dwHeight = 64;
10879 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
10880 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
10881 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
10882 U4(surface_desc).ddpfPixelFormat.dwFourCC = 0;
10883 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 16;
10884 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0xf800;
10885 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x07e0;
10886 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x001f;
10887 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &offscreen, NULL);
10888 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
10890 hr = IDirectDrawSurface4_UpdateOverlay(overlay, NULL, offscreen, NULL, DDOVER_SHOW, NULL);
10891 ok(SUCCEEDED(hr) || broken(hr == DDERR_OUTOFCAPS && dwm_enabled()),
10892 "Failed to update overlay, hr %#x.\n", hr);
10894 /* Try to overlay the primary with a non-overlay surface. */
10895 hr = IDirectDrawSurface4_UpdateOverlay(offscreen, NULL, primary, NULL, DDOVER_SHOW, NULL);
10896 ok(hr == DDERR_NOTAOVERLAYSURFACE, "Got unexpected hr %#x.\n", hr);
10897 hr = IDirectDrawSurface4_UpdateOverlay(offscreen, NULL, primary, NULL, DDOVER_HIDE, NULL);
10898 ok(hr == DDERR_NOTAOVERLAYSURFACE, "Got unexpected hr %#x.\n", hr);
10900 IDirectDrawSurface4_Release(offscreen);
10901 IDirectDrawSurface4_Release(primary);
10902 IDirectDrawSurface4_Release(overlay);
10903 done:
10904 IDirectDraw4_Release(ddraw);
10905 DestroyWindow(window);
10908 static void test_overlay_rect(void)
10910 IDirectDrawSurface4 *overlay, *primary = NULL;
10911 DDSURFACEDESC2 surface_desc;
10912 RECT rect = {0, 0, 64, 64};
10913 IDirectDraw4 *ddraw;
10914 LONG pos_x, pos_y;
10915 HRESULT hr, hr2;
10916 HWND window;
10917 HDC dc;
10919 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
10920 0, 0, 640, 480, 0, 0, 0, 0);
10921 ddraw = create_ddraw();
10922 ok(!!ddraw, "Failed to create a ddraw object.\n");
10923 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
10924 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
10926 if (!(overlay = create_overlay(ddraw, 64, 64, MAKEFOURCC('U','Y','V','Y'))))
10928 skip("Failed to create a UYVY overlay, skipping test.\n");
10929 goto done;
10932 memset(&surface_desc, 0, sizeof(surface_desc));
10933 surface_desc.dwSize = sizeof(surface_desc);
10934 surface_desc.dwFlags = DDSD_CAPS;
10935 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
10936 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &primary, NULL);
10937 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
10939 /* On Windows 7, and probably Vista, UpdateOverlay() will return
10940 * DDERR_OUTOFCAPS if the dwm is active. Calling GetDC() on the primary
10941 * surface prevents this by disabling the dwm. */
10942 hr = IDirectDrawSurface4_GetDC(primary, &dc);
10943 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
10944 hr = IDirectDrawSurface4_ReleaseDC(primary, dc);
10945 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
10947 /* On Windows 8 and newer DWM can't be turned off, making overlays unusable. */
10948 if (dwm_enabled())
10950 win_skip("Cannot disable DWM, skipping overlay test.\n");
10951 goto done;
10954 /* The dx sdk sort of implies that rect must be set when DDOVER_SHOW is
10955 * used. This is not true in Windows Vista and earlier, but changed in
10956 * Windows 7. */
10957 hr = IDirectDrawSurface4_UpdateOverlay(overlay, NULL, primary, &rect, DDOVER_SHOW, NULL);
10958 ok(SUCCEEDED(hr), "Failed to update overlay, hr %#x.\n", hr);
10959 hr = IDirectDrawSurface4_UpdateOverlay(overlay, NULL, primary, NULL, DDOVER_HIDE, NULL);
10960 ok(SUCCEEDED(hr), "Failed to update overlay, hr %#x.\n", hr);
10961 hr = IDirectDrawSurface4_UpdateOverlay(overlay, NULL, primary, NULL, DDOVER_SHOW, NULL);
10962 ok(hr == DD_OK || hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
10964 /* Show that the overlay position is the (top, left) coordinate of the
10965 * destination rectangle. */
10966 OffsetRect(&rect, 32, 16);
10967 hr = IDirectDrawSurface4_UpdateOverlay(overlay, NULL, primary, &rect, DDOVER_SHOW, NULL);
10968 ok(SUCCEEDED(hr), "Failed to update overlay, hr %#x.\n", hr);
10969 pos_x = -1; pos_y = -1;
10970 hr = IDirectDrawSurface4_GetOverlayPosition(overlay, &pos_x, &pos_y);
10971 ok(SUCCEEDED(hr), "Failed to get overlay position, hr %#x.\n", hr);
10972 ok(pos_x == rect.left, "Got unexpected pos_x %d, expected %d.\n", pos_x, rect.left);
10973 ok(pos_y == rect.top, "Got unexpected pos_y %d, expected %d.\n", pos_y, rect.top);
10975 /* Passing a NULL dest rect sets the position to 0/0. Visually it can be
10976 * seen that the overlay overlays the whole primary(==screen). */
10977 hr2 = IDirectDrawSurface4_UpdateOverlay(overlay, NULL, primary, NULL, 0, NULL);
10978 ok(hr2 == DD_OK || hr2 == DDERR_INVALIDPARAMS || hr2 == DDERR_OUTOFCAPS, "Got unexpected hr %#x.\n", hr2);
10979 hr = IDirectDrawSurface4_GetOverlayPosition(overlay, &pos_x, &pos_y);
10980 ok(SUCCEEDED(hr), "Failed to get overlay position, hr %#x.\n", hr);
10981 if (SUCCEEDED(hr2))
10983 ok(!pos_x, "Got unexpected pos_x %d.\n", pos_x);
10984 ok(!pos_y, "Got unexpected pos_y %d.\n", pos_y);
10986 else
10988 ok(pos_x == 32, "Got unexpected pos_x %d.\n", pos_x);
10989 ok(pos_y == 16, "Got unexpected pos_y %d.\n", pos_y);
10992 /* The position cannot be retrieved when the overlay is not shown. */
10993 hr = IDirectDrawSurface4_UpdateOverlay(overlay, NULL, primary, &rect, DDOVER_HIDE, NULL);
10994 ok(SUCCEEDED(hr), "Failed to update overlay, hr %#x.\n", hr);
10995 pos_x = -1; pos_y = -1;
10996 hr = IDirectDrawSurface4_GetOverlayPosition(overlay, &pos_x, &pos_y);
10997 ok(hr == DDERR_OVERLAYNOTVISIBLE, "Got unexpected hr %#x.\n", hr);
10998 ok(!pos_x, "Got unexpected pos_x %d.\n", pos_x);
10999 ok(!pos_y, "Got unexpected pos_y %d.\n", pos_y);
11001 IDirectDrawSurface4_Release(overlay);
11002 done:
11003 if (primary)
11004 IDirectDrawSurface4_Release(primary);
11005 IDirectDraw4_Release(ddraw);
11006 DestroyWindow(window);
11009 static void test_blt(void)
11011 IDirectDrawSurface4 *surface, *rt;
11012 DDSURFACEDESC2 surface_desc;
11013 IDirect3DDevice3 *device;
11014 IDirectDraw4 *ddraw;
11015 IDirect3D3 *d3d;
11016 unsigned int i;
11017 ULONG refcount;
11018 HWND window;
11019 HRESULT hr;
11021 static struct
11023 RECT src_rect;
11024 RECT dst_rect;
11025 HRESULT hr;
11027 test_data[] =
11029 {{160, 0, 640, 480}, { 0, 0, 480, 480}, DD_OK}, /* Overlapped blit. */
11030 {{160, 480, 640, 0}, { 0, 0, 480, 480}, DDERR_INVALIDRECT}, /* Overlapped blit, flipped source. */
11031 {{640, 0, 160, 480}, { 0, 0, 480, 480}, DDERR_INVALIDRECT}, /* Overlapped blit, mirrored source. */
11032 {{160, 0, 480, 480}, { 0, 0, 480, 480}, DD_OK}, /* Overlapped blit, stretched x. */
11033 {{160, 160, 640, 480}, { 0, 0, 480, 480}, DD_OK}, /* Overlapped blit, stretched y. */
11034 {{ 0, 0, 640, 480}, { 0, 0, 640, 480}, DD_OK}, /* Full surface blit. */
11035 {{ 0, 0, 640, 480}, { 0, 480, 640, 0}, DDERR_INVALIDRECT}, /* Full surface, flipped destination. */
11036 {{ 0, 0, 640, 480}, {640, 0, 0, 480}, DDERR_INVALIDRECT}, /* Full surface, mirrored destination. */
11037 {{ 0, 480, 640, 0}, { 0, 0, 640, 480}, DDERR_INVALIDRECT}, /* Full surface, flipped source. */
11038 {{640, 0, 0, 480}, { 0, 0, 640, 480}, DDERR_INVALIDRECT}, /* Full surface, mirrored source. */
11041 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
11042 0, 0, 640, 480, 0, 0, 0, 0);
11043 if (!(device = create_device(window, DDSCL_NORMAL)))
11045 skip("Failed to create a 3D device, skipping test.\n");
11046 DestroyWindow(window);
11047 return;
11050 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
11051 ok(SUCCEEDED(hr), "Failed to get Direct3D3 interface, hr %#x.\n", hr);
11052 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
11053 ok(SUCCEEDED(hr), "Failed to get DirectDraw4 interface, hr %#x.\n", hr);
11054 IDirect3D3_Release(d3d);
11055 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
11056 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
11058 memset(&surface_desc, 0, sizeof(surface_desc));
11059 surface_desc.dwSize = sizeof(surface_desc);
11060 surface_desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
11061 surface_desc.dwWidth = 640;
11062 surface_desc.dwHeight = 480;
11063 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
11064 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
11065 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
11067 hr = IDirectDrawSurface_Blt(surface, NULL, surface, NULL, 0, NULL);
11068 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
11070 hr = IDirectDrawSurface_Blt(surface, NULL, rt, NULL, 0, NULL);
11071 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
11073 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
11075 hr = IDirectDrawSurface_Blt(surface, &test_data[i].dst_rect,
11076 surface, &test_data[i].src_rect, DDBLT_WAIT, NULL);
11077 ok(hr == test_data[i].hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, test_data[i].hr);
11079 hr = IDirectDrawSurface_Blt(surface, &test_data[i].dst_rect,
11080 rt, &test_data[i].src_rect, DDBLT_WAIT, NULL);
11081 ok(hr == test_data[i].hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, test_data[i].hr);
11084 IDirectDrawSurface4_Release(surface);
11085 IDirectDrawSurface4_Release(rt);
11086 IDirectDraw4_Release(ddraw);
11087 refcount = IDirect3DDevice3_Release(device);
11088 ok(!refcount, "Device has %u references left.\n", refcount);
11089 DestroyWindow(window);
11092 static void test_color_clamping(void)
11094 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
11095 static D3DMATRIX mat =
11097 1.0f, 0.0f, 0.0f, 0.0f,
11098 0.0f, 1.0f, 0.0f, 0.0f,
11099 0.0f, 0.0f, 1.0f, 0.0f,
11100 0.0f, 0.0f, 0.0f, 1.0f,
11102 static struct vec3 quad[] =
11104 {-1.0f, -1.0f, 0.1f},
11105 {-1.0f, 1.0f, 0.1f},
11106 { 1.0f, -1.0f, 0.1f},
11107 { 1.0f, 1.0f, 0.1f},
11109 IDirect3DViewport3 *viewport;
11110 IDirect3DDevice3 *device;
11111 IDirectDrawSurface4 *rt;
11112 ULONG refcount;
11113 D3DCOLOR color;
11114 HWND window;
11115 HRESULT hr;
11117 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
11118 0, 0, 640, 480, NULL, NULL, NULL, NULL);
11120 if (!(device = create_device(window, DDSCL_NORMAL)))
11122 skip("Failed to create a 3D device, skipping test.\n");
11123 DestroyWindow(window);
11124 return;
11127 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
11128 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
11130 viewport = create_viewport(device, 0, 0, 640, 480);
11131 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
11132 ok(SUCCEEDED(hr), "Failed to activate the viewport, hr %#x.\n", hr);
11134 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &mat);
11135 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#x.\n", hr);
11136 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_VIEW, &mat);
11137 ok(SUCCEEDED(hr), "Failed to set view transform, hr %#x.\n", hr);
11138 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &mat);
11139 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
11140 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_CLIPPING, FALSE);
11141 ok(SUCCEEDED(hr), "Failed to disable clipping, hr %#x.\n", hr);
11142 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ZENABLE, FALSE);
11143 ok(SUCCEEDED(hr), "Failed to disable Z test, hr %#x.\n", hr);
11144 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, FALSE);
11145 ok(SUCCEEDED(hr), "Failed to disable fog, hr %#x.\n", hr);
11146 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_STENCILENABLE, FALSE);
11147 ok(SUCCEEDED(hr), "Failed to disable stencil test, hr %#x.\n", hr);
11148 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_CULLMODE, D3DCULL_NONE);
11149 ok(SUCCEEDED(hr), "Failed to disable culling, hr %#x.\n", hr);
11150 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
11151 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
11153 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_TEXTUREFACTOR, 0xff404040);
11154 ok(SUCCEEDED(hr), "Failed to set texture factor, hr %#x.\n", hr);
11155 hr = IDirect3DDevice3_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_ADD);
11156 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
11157 hr = IDirect3DDevice3_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);
11158 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
11159 hr = IDirect3DDevice3_SetTextureStageState(device, 0, D3DTSS_COLORARG2, D3DTA_SPECULAR);
11160 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
11161 hr = IDirect3DDevice3_SetTextureStageState(device, 1, D3DTSS_COLOROP, D3DTOP_MODULATE);
11162 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
11163 hr = IDirect3DDevice3_SetTextureStageState(device, 1, D3DTSS_COLORARG1, D3DTA_TFACTOR);
11164 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
11165 hr = IDirect3DDevice3_SetTextureStageState(device, 1, D3DTSS_COLORARG2, D3DTA_CURRENT);
11166 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
11168 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xff00ff00, 0.0f, 0);
11169 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
11171 hr = IDirect3DDevice3_BeginScene(device);
11172 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
11174 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, quad, 4, 0);
11175 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
11177 hr = IDirect3DDevice3_EndScene(device);
11178 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
11180 color = get_surface_color(rt, 320, 240);
11181 ok(compare_color(color, 0x00404040, 1), "Got unexpected color 0x%08x.\n", color);
11183 destroy_viewport(device, viewport);
11184 IDirectDrawSurface4_Release(rt);
11185 refcount = IDirect3DDevice3_Release(device);
11186 ok(!refcount, "Device has %u references left.\n", refcount);
11187 DestroyWindow(window);
11190 static void test_getdc(void)
11192 DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, {0}};
11193 IDirectDrawSurface4 *surface, *surface2, *tmp;
11194 DDSURFACEDESC2 surface_desc, map_desc;
11195 IDirectDraw4 *ddraw;
11196 unsigned int i;
11197 HWND window;
11198 HDC dc, dc2;
11199 HRESULT hr;
11201 static const struct
11203 const char *name;
11204 DDPIXELFORMAT format;
11205 BOOL getdc_supported;
11206 HRESULT alt_result;
11208 test_data[] =
11210 {"D3DFMT_A8R8G8B8", {sizeof(test_data->format), DDPF_RGB | DDPF_ALPHAPIXELS, 0, {32},
11211 {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}}, TRUE},
11212 {"D3DFMT_X8R8G8B8", {sizeof(test_data->format), DDPF_RGB, 0, {32},
11213 {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0x00000000}}, TRUE},
11214 {"D3DFMT_R5G6B5", {sizeof(test_data->format), DDPF_RGB, 0, {16},
11215 {0x0000f800}, {0x000007e0}, {0x0000001f}, {0x00000000}}, TRUE},
11216 {"D3DFMT_X1R5G5B5", {sizeof(test_data->format), DDPF_RGB, 0, {16},
11217 {0x00007c00}, {0x000003e0}, {0x0000001f}, {0x00000000}}, TRUE},
11218 {"D3DFMT_A1R5G5B5", {sizeof(test_data->format), DDPF_RGB | DDPF_ALPHAPIXELS, 0, {16},
11219 {0x00007c00}, {0x000003e0}, {0x0000001f}, {0x00008000}}, TRUE},
11220 {"D3DFMT_A4R4G4B4", {sizeof(test_data->format), DDPF_RGB | DDPF_ALPHAPIXELS, 0, {16},
11221 {0x00000f00}, {0x000000f0}, {0x0000000f}, {0x0000f000}}, TRUE, DDERR_CANTCREATEDC /* Vista+ */},
11222 {"D3DFMT_X4R4G4B4", {sizeof(test_data->format), DDPF_RGB, 0, {16},
11223 {0x00000f00}, {0x000000f0}, {0x0000000f}, {0x00000000}}, TRUE, DDERR_CANTCREATEDC /* Vista+ */},
11224 {"D3DFMT_A2R10G10B10", {sizeof(test_data->format), DDPF_RGB | DDPF_ALPHAPIXELS, 0, {32},
11225 {0xc0000000}, {0x3ff00000}, {0x000ffc00}, {0x000003ff}}, TRUE},
11226 {"D3DFMT_A8B8G8R8", {sizeof(test_data->format), DDPF_RGB | DDPF_ALPHAPIXELS, 0, {32},
11227 {0x000000ff}, {0x0000ff00}, {0x00ff0000}, {0xff000000}}, TRUE, DDERR_CANTCREATEDC /* Vista+ */},
11228 {"D3DFMT_X8B8G8R8", {sizeof(test_data->format), DDPF_RGB, 0, {32},
11229 {0x000000ff}, {0x0000ff00}, {0x00ff0000}, {0x00000000}}, TRUE, DDERR_CANTCREATEDC /* Vista+ */},
11230 {"D3DFMT_R3G3B2", {sizeof(test_data->format), DDPF_RGB, 0, {8},
11231 {0x000000e0}, {0x0000001c}, {0x00000003}, {0x00000000}}, FALSE},
11232 /* GetDC() on a P8 surface fails unless the display mode is 8 bpp.
11233 * This is not implemented in wine yet, so disable the test for now.
11234 * Succeeding P8 GetDC() calls are tested in the ddraw:visual test.
11235 {"D3DFMT_P8", {sizeof(test_data->format), DDPF_PALETTEINDEXED8 | DDPF_RGB, 0, {8 },
11236 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
11238 {"D3DFMT_L8", {sizeof(test_data->format), DDPF_LUMINANCE, 0, {8},
11239 {0x000000ff}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
11240 {"D3DFMT_A8L8", {sizeof(test_data->format), DDPF_ALPHAPIXELS | DDPF_LUMINANCE, 0, {16},
11241 {0x000000ff}, {0x00000000}, {0x00000000}, {0x0000ff00}}, FALSE},
11242 {"D3DFMT_DXT1", {sizeof(test_data->format), DDPF_FOURCC, MAKEFOURCC('D','X','T','1'), {0},
11243 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
11244 {"D3DFMT_DXT2", {sizeof(test_data->format), DDPF_FOURCC, MAKEFOURCC('D','X','T','2'), {0},
11245 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
11246 {"D3DFMT_DXT3", {sizeof(test_data->format), DDPF_FOURCC, MAKEFOURCC('D','X','T','3'), {0},
11247 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
11248 {"D3DFMT_DXT4", {sizeof(test_data->format), DDPF_FOURCC, MAKEFOURCC('D','X','T','4'), {0},
11249 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
11250 {"D3DFMT_DXT5", {sizeof(test_data->format), DDPF_FOURCC, MAKEFOURCC('D','X','T','5'), {0},
11251 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
11254 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
11255 0, 0, 640, 480, 0, 0, 0, 0);
11256 ddraw = create_ddraw();
11257 ok(!!ddraw, "Failed to create a ddraw object.\n");
11258 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
11259 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
11261 for (i = 0; i < (sizeof(test_data) / sizeof(*test_data)); ++i)
11263 memset(&surface_desc, 0, sizeof(surface_desc));
11264 surface_desc.dwSize = sizeof(surface_desc);
11265 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
11266 surface_desc.dwWidth = 64;
11267 surface_desc.dwHeight = 64;
11268 U4(surface_desc).ddpfPixelFormat = test_data[i].format;
11269 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
11271 if (FAILED(IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL)))
11273 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
11274 surface_desc.ddsCaps.dwCaps2 = DDSCAPS2_TEXTUREMANAGE;
11275 if (FAILED(hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL)))
11277 skip("Failed to create surface for format %s (hr %#x), skipping tests.\n", test_data[i].name, hr);
11278 continue;
11282 dc = (void *)0x1234;
11283 hr = IDirectDrawSurface4_GetDC(surface, &dc);
11284 if (test_data[i].getdc_supported)
11285 ok(SUCCEEDED(hr) || (test_data[i].alt_result && hr == test_data[i].alt_result),
11286 "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11287 else
11288 ok(FAILED(hr), "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11290 if (SUCCEEDED(hr))
11292 unsigned int width_bytes;
11293 DIBSECTION dib;
11294 HBITMAP bitmap;
11295 DWORD type;
11296 int size;
11298 type = GetObjectType(dc);
11299 ok(type == OBJ_MEMDC, "Got unexpected object type %#x for format %s.\n", type, test_data[i].name);
11300 bitmap = GetCurrentObject(dc, OBJ_BITMAP);
11301 type = GetObjectType(bitmap);
11302 ok(type == OBJ_BITMAP, "Got unexpected object type %#x for format %s.\n", type, test_data[i].name);
11304 size = GetObjectA(bitmap, sizeof(dib), &dib);
11305 ok(size == sizeof(dib), "Got unexpected size %d for format %s.\n", size, test_data[i].name);
11306 ok(!dib.dsBm.bmType, "Got unexpected type %#x for format %s.\n",
11307 dib.dsBm.bmType, test_data[i].name);
11308 ok(dib.dsBm.bmWidth == surface_desc.dwWidth, "Got unexpected width %d for format %s.\n",
11309 dib.dsBm.bmWidth, test_data[i].name);
11310 ok(dib.dsBm.bmHeight == surface_desc.dwHeight, "Got unexpected height %d for format %s.\n",
11311 dib.dsBm.bmHeight, test_data[i].name);
11312 width_bytes = ((dib.dsBm.bmWidth * U1(test_data[i].format).dwRGBBitCount + 31) >> 3) & ~3;
11313 ok(dib.dsBm.bmWidthBytes == width_bytes, "Got unexpected width bytes %d for format %s.\n",
11314 dib.dsBm.bmWidthBytes, test_data[i].name);
11315 ok(dib.dsBm.bmPlanes == 1, "Got unexpected plane count %d for format %s.\n",
11316 dib.dsBm.bmPlanes, test_data[i].name);
11317 ok(dib.dsBm.bmBitsPixel == U1(test_data[i].format).dwRGBBitCount,
11318 "Got unexpected bit count %d for format %s.\n",
11319 dib.dsBm.bmBitsPixel, test_data[i].name);
11320 ok(!!dib.dsBm.bmBits, "Got unexpected bits %p for format %s.\n",
11321 dib.dsBm.bmBits, test_data[i].name);
11323 ok(dib.dsBmih.biSize == sizeof(dib.dsBmih), "Got unexpected size %u for format %s.\n",
11324 dib.dsBmih.biSize, test_data[i].name);
11325 ok(dib.dsBmih.biWidth == surface_desc.dwWidth, "Got unexpected width %d for format %s.\n",
11326 dib.dsBmih.biHeight, test_data[i].name);
11327 ok(dib.dsBmih.biHeight == surface_desc.dwHeight, "Got unexpected height %d for format %s.\n",
11328 dib.dsBmih.biHeight, test_data[i].name);
11329 ok(dib.dsBmih.biPlanes == 1, "Got unexpected plane count %u for format %s.\n",
11330 dib.dsBmih.biPlanes, test_data[i].name);
11331 ok(dib.dsBmih.biBitCount == U1(test_data[i].format).dwRGBBitCount,
11332 "Got unexpected bit count %u for format %s.\n",
11333 dib.dsBmih.biBitCount, test_data[i].name);
11334 ok(dib.dsBmih.biCompression == (U1(test_data[i].format).dwRGBBitCount == 16 ? BI_BITFIELDS : BI_RGB)
11335 || broken(U1(test_data[i].format).dwRGBBitCount == 32 && dib.dsBmih.biCompression == BI_BITFIELDS),
11336 "Got unexpected compression %#x for format %s.\n",
11337 dib.dsBmih.biCompression, test_data[i].name);
11338 ok(!dib.dsBmih.biSizeImage, "Got unexpected image size %u for format %s.\n",
11339 dib.dsBmih.biSizeImage, test_data[i].name);
11340 ok(!dib.dsBmih.biXPelsPerMeter, "Got unexpected horizontal resolution %d for format %s.\n",
11341 dib.dsBmih.biXPelsPerMeter, test_data[i].name);
11342 ok(!dib.dsBmih.biYPelsPerMeter, "Got unexpected vertical resolution %d for format %s.\n",
11343 dib.dsBmih.biYPelsPerMeter, test_data[i].name);
11344 ok(!dib.dsBmih.biClrUsed, "Got unexpected used colour count %u for format %s.\n",
11345 dib.dsBmih.biClrUsed, test_data[i].name);
11346 ok(!dib.dsBmih.biClrImportant, "Got unexpected important colour count %u for format %s.\n",
11347 dib.dsBmih.biClrImportant, test_data[i].name);
11349 if (dib.dsBmih.biCompression == BI_BITFIELDS)
11351 ok((dib.dsBitfields[0] == U2(test_data[i].format).dwRBitMask
11352 && dib.dsBitfields[1] == U3(test_data[i].format).dwGBitMask
11353 && dib.dsBitfields[2] == U4(test_data[i].format).dwBBitMask)
11354 || broken(!dib.dsBitfields[0] && !dib.dsBitfields[1] && !dib.dsBitfields[2]),
11355 "Got unexpected colour masks 0x%08x 0x%08x 0x%08x for format %s.\n",
11356 dib.dsBitfields[0], dib.dsBitfields[1], dib.dsBitfields[2], test_data[i].name);
11358 else
11360 ok(!dib.dsBitfields[0] && !dib.dsBitfields[1] && !dib.dsBitfields[2],
11361 "Got unexpected colour masks 0x%08x 0x%08x 0x%08x for format %s.\n",
11362 dib.dsBitfields[0], dib.dsBitfields[1], dib.dsBitfields[2], test_data[i].name);
11364 ok(!dib.dshSection, "Got unexpected section %p for format %s.\n", dib.dshSection, test_data[i].name);
11365 ok(!dib.dsOffset, "Got unexpected offset %u for format %s.\n", dib.dsOffset, test_data[i].name);
11367 hr = IDirectDrawSurface4_ReleaseDC(surface, dc);
11368 ok(hr == DD_OK, "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11370 else
11372 ok(!dc, "Got unexpected dc %p for format %s.\n", dc, test_data[i].name);
11375 IDirectDrawSurface4_Release(surface);
11377 if (FAILED(hr))
11378 continue;
11380 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
11381 surface_desc.ddsCaps.dwCaps2 = DDSCAPS2_TEXTUREMANAGE;
11382 if (FAILED(hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL)))
11384 skip("Failed to create mip-mapped texture for format %s (hr %#x), skipping tests.\n",
11385 test_data[i].name, hr);
11386 continue;
11389 hr = IDirectDrawSurface4_GetAttachedSurface(surface, &caps, &tmp);
11390 ok(SUCCEEDED(hr), "Failed to get attached surface for format %s, hr %#x.\n", test_data[i].name, hr);
11391 hr = IDirectDrawSurface4_GetAttachedSurface(tmp, &caps, &surface2);
11392 ok(SUCCEEDED(hr), "Failed to get attached surface for format %s, hr %#x.\n", test_data[i].name, hr);
11393 IDirectDrawSurface4_Release(tmp);
11395 hr = IDirectDrawSurface4_GetDC(surface, &dc);
11396 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11397 hr = IDirectDrawSurface4_ReleaseDC(surface, dc);
11398 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11399 hr = IDirectDrawSurface4_GetDC(surface2, &dc);
11400 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11401 hr = IDirectDrawSurface4_ReleaseDC(surface2, dc);
11402 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11404 hr = IDirectDrawSurface4_GetDC(surface, &dc);
11405 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11406 dc2 = (void *)0x1234;
11407 hr = IDirectDrawSurface4_GetDC(surface, &dc2);
11408 ok(hr == DDERR_DCALREADYCREATED, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11409 ok(dc2 == (void *)0x1234, "Got unexpected dc %p for format %s.\n", dc, test_data[i].name);
11410 hr = IDirectDrawSurface4_ReleaseDC(surface, dc);
11411 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11412 hr = IDirectDrawSurface4_ReleaseDC(surface, dc);
11413 ok(hr == DDERR_NODC, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11415 map_desc.dwSize = sizeof(map_desc);
11416 hr = IDirectDrawSurface4_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
11417 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
11418 hr = IDirectDrawSurface4_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
11419 ok(hr == DDERR_SURFACEBUSY, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11420 hr = IDirectDrawSurface4_Unlock(surface, NULL);
11421 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
11422 hr = IDirectDrawSurface4_Unlock(surface, NULL);
11423 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11425 hr = IDirectDrawSurface4_GetDC(surface, &dc);
11426 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11427 hr = IDirectDrawSurface4_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
11428 ok(hr == DDERR_SURFACEBUSY, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11429 hr = IDirectDrawSurface4_ReleaseDC(surface, dc);
11430 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11432 hr = IDirectDrawSurface4_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
11433 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
11434 hr = IDirectDrawSurface4_GetDC(surface, &dc);
11435 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11436 hr = IDirectDrawSurface4_ReleaseDC(surface, dc);
11437 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11438 hr = IDirectDrawSurface4_Unlock(surface, NULL);
11439 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
11441 hr = IDirectDrawSurface4_GetDC(surface, &dc);
11442 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11443 hr = IDirectDrawSurface4_GetDC(surface2, &dc2);
11444 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11445 hr = IDirectDrawSurface4_ReleaseDC(surface2, dc2);
11446 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11447 hr = IDirectDrawSurface4_ReleaseDC(surface, dc);
11448 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11450 hr = IDirectDrawSurface4_GetDC(surface2, &dc);
11451 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11452 hr = IDirectDrawSurface4_GetDC(surface, &dc2);
11453 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11454 hr = IDirectDrawSurface4_ReleaseDC(surface, dc2);
11455 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11456 hr = IDirectDrawSurface4_ReleaseDC(surface2, dc);
11457 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11459 hr = IDirectDrawSurface4_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
11460 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
11461 hr = IDirectDrawSurface4_Lock(surface2, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
11462 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
11463 hr = IDirectDrawSurface4_Unlock(surface2, NULL);
11464 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
11465 hr = IDirectDrawSurface4_Unlock(surface, NULL);
11466 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
11468 hr = IDirectDrawSurface4_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
11469 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
11470 hr = IDirectDrawSurface4_GetDC(surface, &dc);
11471 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11472 hr = IDirectDrawSurface4_ReleaseDC(surface, dc);
11473 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11474 hr = IDirectDrawSurface4_Unlock(surface, NULL);
11475 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
11477 hr = IDirectDrawSurface4_Lock(surface2, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
11478 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
11479 hr = IDirectDrawSurface4_GetDC(surface, &dc);
11480 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11481 hr = IDirectDrawSurface4_ReleaseDC(surface, dc);
11482 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11483 hr = IDirectDrawSurface4_Unlock(surface2, NULL);
11484 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
11486 hr = IDirectDrawSurface4_GetDC(surface, &dc);
11487 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11488 hr = IDirectDrawSurface4_Lock(surface2, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
11489 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
11490 hr = IDirectDrawSurface4_Unlock(surface2, NULL);
11491 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
11492 hr = IDirectDrawSurface4_ReleaseDC(surface, dc);
11493 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11495 hr = IDirectDrawSurface4_GetDC(surface2, &dc);
11496 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11497 hr = IDirectDrawSurface4_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
11498 ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
11499 hr = IDirectDrawSurface4_Unlock(surface, NULL);
11500 ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
11501 hr = IDirectDrawSurface4_ReleaseDC(surface2, dc);
11502 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11504 hr = IDirectDrawSurface4_Unlock(surface, NULL);
11505 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11506 hr = IDirectDrawSurface4_GetDC(surface2, &dc);
11507 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11508 hr = IDirectDrawSurface4_Unlock(surface, NULL);
11509 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11510 hr = IDirectDrawSurface4_ReleaseDC(surface2, dc);
11511 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11512 hr = IDirectDrawSurface4_Unlock(surface, NULL);
11513 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11515 hr = IDirectDrawSurface4_Unlock(surface2, NULL);
11516 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11517 hr = IDirectDrawSurface4_GetDC(surface, &dc);
11518 ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
11519 hr = IDirectDrawSurface4_Unlock(surface2, NULL);
11520 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11521 hr = IDirectDrawSurface4_ReleaseDC(surface, dc);
11522 ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
11523 hr = IDirectDrawSurface4_Unlock(surface2, NULL);
11524 ok(hr == DDERR_NOTLOCKED, "Got unexpected hr %#x for format %s.\n", hr, test_data[i].name);
11526 IDirectDrawSurface4_Release(surface2);
11527 IDirectDrawSurface4_Release(surface);
11530 IDirectDraw4_Release(ddraw);
11531 DestroyWindow(window);
11534 static void test_draw_primitive(void)
11536 static WORD indices[] = {0, 1, 2, 3};
11537 static struct vec3 quad[] =
11539 {-1.0f, -1.0f, 0.0f},
11540 {-1.0f, 1.0f, 0.0f},
11541 { 1.0f, -1.0f, 0.0f},
11542 { 1.0f, 1.0f, 0.0f},
11544 D3DDRAWPRIMITIVESTRIDEDDATA strided;
11545 IDirect3DViewport3 *viewport;
11546 D3DVERTEXBUFFERDESC vb_desc;
11547 IDirect3DVertexBuffer *vb;
11548 IDirect3DDevice3 *device;
11549 IDirect3D3 *d3d;
11550 ULONG refcount;
11551 HWND window;
11552 HRESULT hr;
11553 void *data;
11555 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
11556 0, 0, 640, 480, NULL, NULL, NULL, NULL);
11558 if (!(device = create_device(window, DDSCL_NORMAL)))
11560 skip("Failed to create a 3D device, skipping test.\n");
11561 DestroyWindow(window);
11562 return;
11565 viewport = create_viewport(device, 0, 0, 640, 480);
11566 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
11567 ok(SUCCEEDED(hr), "Failed to activate the viewport, hr %#x.\n", hr);
11569 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
11570 ok(SUCCEEDED(hr), "Failed to get D3D interface, hr %#x.\n", hr);
11572 memset(&vb_desc, 0, sizeof(vb_desc));
11573 vb_desc.dwSize = sizeof(vb_desc);
11574 vb_desc.dwFVF = D3DFVF_XYZ;
11575 vb_desc.dwNumVertices = 4;
11576 hr = IDirect3D3_CreateVertexBuffer(d3d, &vb_desc, &vb, 0, NULL);
11577 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
11579 IDirect3D3_Release(d3d);
11581 memset(&strided, 0, sizeof(strided));
11583 hr = IDirect3DDevice3_DrawIndexedPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, NULL, 0, NULL, 0, 0);
11584 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
11585 hr = IDirect3DDevice3_DrawIndexedPrimitiveStrided(device,
11586 D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, &strided, 0, NULL, 0, 0);
11587 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
11588 hr = IDirect3DDevice3_DrawIndexedPrimitiveVB(device, D3DPT_TRIANGLESTRIP, vb, NULL, 0, 0);
11589 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
11590 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, NULL, 0, 0);
11591 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
11592 hr = IDirect3DDevice3_DrawPrimitiveStrided(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, &strided, 0, 0);
11593 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
11594 hr = IDirect3DDevice3_DrawPrimitiveVB(device, D3DPT_TRIANGLESTRIP, vb, 0, 0, 0);
11595 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
11597 hr = IDirect3DDevice3_DrawIndexedPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, NULL, 0, indices, 4, 0);
11598 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
11599 hr = IDirect3DDevice3_DrawIndexedPrimitiveStrided(device,
11600 D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, &strided, 0, indices, 4, 0);
11601 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
11602 hr = IDirect3DDevice3_DrawIndexedPrimitiveVB(device, D3DPT_TRIANGLESTRIP, vb, indices, 4, 0);
11603 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
11605 strided.position.lpvData = quad;
11606 strided.position.dwStride = sizeof(*quad);
11607 hr = IDirect3DVertexBuffer_Lock(vb, 0, &data, NULL);
11608 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
11609 memcpy(data, quad, sizeof(quad));
11610 hr = IDirect3DVertexBuffer_Unlock(vb);
11611 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
11613 hr = IDirect3DDevice3_DrawIndexedPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, quad, 4, NULL, 0, 0);
11614 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
11615 hr = IDirect3DDevice3_DrawIndexedPrimitiveStrided(device,
11616 D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, &strided, 4, NULL, 0, 0);
11617 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
11618 hr = IDirect3DDevice3_DrawIndexedPrimitiveVB(device, D3DPT_TRIANGLESTRIP, vb, NULL, 0, 0);
11619 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
11620 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, quad, 4, 0);
11621 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
11622 hr = IDirect3DDevice3_DrawPrimitiveStrided(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, &strided, 4, 0);
11623 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
11624 hr = IDirect3DDevice3_DrawPrimitiveVB(device, D3DPT_TRIANGLESTRIP, vb, 0, 4, 0);
11625 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
11626 hr = IDirect3DDevice3_DrawIndexedPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, quad, 4, indices, 4, 0);
11627 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
11628 hr = IDirect3DDevice3_DrawIndexedPrimitiveStrided(device,
11629 D3DPT_TRIANGLESTRIP, D3DFVF_XYZ, &strided, 4, indices, 4, 0);
11630 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
11631 hr = IDirect3DDevice3_DrawIndexedPrimitiveVB(device, D3DPT_TRIANGLESTRIP, vb, indices, 4, 0);
11632 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
11634 IDirect3DVertexBuffer_Release(vb);
11635 destroy_viewport(device, viewport);
11636 refcount = IDirect3DDevice3_Release(device);
11637 ok(!refcount, "Device has %u references left.\n", refcount);
11638 DestroyWindow(window);
11641 static void test_edge_antialiasing_blending(void)
11643 D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
11644 IDirectDrawSurface4 *offscreen, *ds;
11645 D3DDEVICEDESC hal_desc, hel_desc;
11646 IDirect3DViewport3 *viewport;
11647 DDSURFACEDESC2 surface_desc;
11648 IDirect3DDevice3 *device;
11649 IDirectDraw4 *ddraw;
11650 IDirect3D3 *d3d;
11651 ULONG refcount;
11652 D3DCOLOR color;
11653 HWND window;
11654 HRESULT hr;
11656 static D3DMATRIX mat =
11658 1.0f, 0.0f, 0.0f, 0.0f,
11659 0.0f, 1.0f, 0.0f, 0.0f,
11660 0.0f, 0.0f, 1.0f, 0.0f,
11661 0.0f, 0.0f, 0.0f, 1.0f,
11663 static struct
11665 struct vec3 position;
11666 DWORD diffuse;
11668 green_quad[] =
11670 {{-1.0f, -1.0f, 0.1f}, 0x7f00ff00},
11671 {{-1.0f, 1.0f, 0.1f}, 0x7f00ff00},
11672 {{ 1.0f, -1.0f, 0.1f}, 0x7f00ff00},
11673 {{ 1.0f, 1.0f, 0.1f}, 0x7f00ff00},
11675 static struct
11677 struct vec3 position;
11678 DWORD diffuse;
11680 red_quad[] =
11682 {{-1.0f, -1.0f, 0.1f}, 0xccff0000},
11683 {{-1.0f, 1.0f, 0.1f}, 0xccff0000},
11684 {{ 1.0f, -1.0f, 0.1f}, 0xccff0000},
11685 {{ 1.0f, 1.0f, 0.1f}, 0xccff0000},
11688 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
11689 0, 0, 640, 480, NULL, NULL, NULL, NULL);
11690 if (!(device = create_device(window, DDSCL_NORMAL)))
11692 skip("Failed to create a 3D device.\n");
11693 DestroyWindow(window);
11694 return;
11697 memset(&hal_desc, 0, sizeof(hal_desc));
11698 hal_desc.dwSize = sizeof(hal_desc);
11699 memset(&hel_desc, 0, sizeof(hel_desc));
11700 hel_desc.dwSize = sizeof(hel_desc);
11701 hr = IDirect3DDevice3_GetCaps(device, &hal_desc, &hel_desc);
11702 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
11703 trace("HAL line edge antialiasing support: %#x.\n",
11704 hal_desc.dpcLineCaps.dwRasterCaps & D3DPRASTERCAPS_ANTIALIASEDGES);
11705 trace("HAL triangle edge antialiasing support: %#x.\n",
11706 hal_desc.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_ANTIALIASEDGES);
11707 trace("HEL line edge antialiasing support: %#x.\n",
11708 hel_desc.dpcLineCaps.dwRasterCaps & D3DPRASTERCAPS_ANTIALIASEDGES);
11709 trace("HEL triangle edge antialiasing support: %#x.\n",
11710 hel_desc.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_ANTIALIASEDGES);
11712 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
11713 ok(SUCCEEDED(hr), "Failed to get D3D interface, hr %#x.\n", hr);
11714 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
11715 ok(SUCCEEDED(hr), "Failed to get DirectDraw4 interface, hr %#x.\n", hr);
11716 IDirect3D3_Release(d3d);
11718 memset(&surface_desc, 0, sizeof(surface_desc));
11719 surface_desc.dwSize = sizeof(surface_desc);
11720 surface_desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_PIXELFORMAT;
11721 surface_desc.dwWidth = 640;
11722 surface_desc.dwHeight = 480;
11723 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_3DDEVICE;
11724 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
11725 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
11726 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
11727 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
11728 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
11729 U5(U4(surface_desc).ddpfPixelFormat).dwRGBAlphaBitMask = 0xff000000;
11730 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &offscreen, NULL);
11731 ok(hr == D3D_OK, "Creating the offscreen render target failed, hr %#x.\n", hr);
11733 ds = get_depth_stencil(device);
11734 hr = IDirectDrawSurface_AddAttachedSurface(offscreen, ds);
11735 todo_wine ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
11736 IDirectDrawSurface_Release(ds);
11738 hr = IDirect3DDevice3_SetRenderTarget(device, offscreen, 0);
11739 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
11741 viewport = create_viewport(device, 0, 0, 640, 480);
11742 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
11743 ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr);
11745 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &mat);
11746 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#x.\n", hr);
11747 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_VIEW, &mat);
11748 ok(SUCCEEDED(hr), "Failed to set view transform, hr %#x.\n", hr);
11749 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &mat);
11750 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
11751 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_CLIPPING, FALSE);
11752 ok(SUCCEEDED(hr), "Failed to disable clipping, hr %#x.\n", hr);
11753 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ZENABLE, FALSE);
11754 ok(SUCCEEDED(hr), "Failed to disable Z test, hr %#x.\n", hr);
11755 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, FALSE);
11756 ok(SUCCEEDED(hr), "Failed to disable fog, hr %#x.\n", hr);
11757 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_STENCILENABLE, FALSE);
11758 ok(SUCCEEDED(hr), "Failed to disable stencil test, hr %#x.\n", hr);
11759 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_CULLMODE, D3DCULL_NONE);
11760 ok(SUCCEEDED(hr), "Failed to disable culling, hr %#x.\n", hr);
11761 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
11762 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
11764 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);
11765 ok(SUCCEEDED(hr), "Failed to enable blending, hr %#x.\n", hr);
11766 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);
11767 ok(SUCCEEDED(hr), "Failed to set src blend, hr %#x.\n", hr);
11768 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_DESTBLEND, D3DBLEND_DESTALPHA);
11769 ok(SUCCEEDED(hr), "Failed to set dest blend, hr %#x.\n", hr);
11771 hr = IDirect3DDevice3_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
11772 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
11773 hr = IDirect3DDevice3_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);
11774 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
11775 hr = IDirect3DDevice3_SetTextureStageState(device, 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
11776 ok(SUCCEEDED(hr), "Failed to set alpha op, hr %#x.\n", hr);
11777 hr = IDirect3DDevice3_SetTextureStageState(device, 0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);
11778 ok(SUCCEEDED(hr), "Failed to set alpha arg, hr %#x.\n", hr);
11780 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xccff0000, 0.0f, 0);
11781 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
11782 hr = IDirect3DDevice3_BeginScene(device);
11783 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
11784 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE,
11785 green_quad, 4, 0);
11786 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
11787 hr = IDirect3DDevice3_EndScene(device);
11788 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
11789 color = get_surface_color(offscreen, 320, 240);
11790 ok(compare_color(color, 0x00cc7f00, 1), "Got unexpected color 0x%08x.\n", color);
11792 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0x7f00ff00, 0.0f, 0);
11793 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
11794 hr = IDirect3DDevice3_BeginScene(device);
11795 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
11796 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE,
11797 red_quad, 4, 0);
11798 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
11799 hr = IDirect3DDevice3_EndScene(device);
11800 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
11801 color = get_surface_color(offscreen, 320, 240);
11802 ok(compare_color(color, 0x00cc7f00, 1), "Got unexpected color 0x%08x.\n", color);
11804 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, FALSE);
11805 ok(SUCCEEDED(hr), "Failed to disable blending, hr %#x.\n", hr);
11807 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xccff0000, 0.0f, 0);
11808 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
11809 hr = IDirect3DDevice3_BeginScene(device);
11810 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
11811 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE,
11812 green_quad, 4, 0);
11813 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
11814 hr = IDirect3DDevice3_EndScene(device);
11815 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
11816 color = get_surface_color(offscreen, 320, 240);
11817 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
11819 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0x7f00ff00, 0.0f, 0);
11820 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
11821 hr = IDirect3DDevice3_BeginScene(device);
11822 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
11823 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE,
11824 red_quad, 4, 0);
11825 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
11826 hr = IDirect3DDevice3_EndScene(device);
11827 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
11828 color = get_surface_color(offscreen, 320, 240);
11829 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
11831 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_EDGEANTIALIAS, TRUE);
11832 ok(SUCCEEDED(hr), "Failed to enable edge antialiasing, hr %#x.\n", hr);
11834 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xccff0000, 0.0f, 0);
11835 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
11836 hr = IDirect3DDevice3_BeginScene(device);
11837 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
11838 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE,
11839 green_quad, 4, 0);
11840 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
11841 hr = IDirect3DDevice3_EndScene(device);
11842 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
11843 color = get_surface_color(offscreen, 320, 240);
11844 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
11846 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0x7f00ff00, 0.0f, 0);
11847 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
11848 hr = IDirect3DDevice3_BeginScene(device);
11849 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
11850 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE,
11851 red_quad, 4, 0);
11852 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
11853 hr = IDirect3DDevice3_EndScene(device);
11854 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
11855 color = get_surface_color(offscreen, 320, 240);
11856 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
11858 IDirectDrawSurface4_Release(offscreen);
11859 IDirectDraw3_Release(ddraw);
11860 destroy_viewport(device, viewport);
11861 refcount = IDirect3DDevice3_Release(device);
11862 ok(!refcount, "Device has %u references left.\n", refcount);
11863 DestroyWindow(window);
11866 /* TransformVertices always writes 32 bytes regardless of the input / output stride.
11867 * The stride is honored for navigating to the next vertex. 3 floats input position
11868 * are read, and 16 bytes extra vertex data are copied around. */
11869 struct transform_input
11871 float x, y, z, unused1; /* Position data, transformed. */
11872 DWORD v1, v2, v3, v4; /* Extra data, e.g. color and texture coords, copied. */
11873 DWORD unused2;
11876 struct transform_output
11878 float x, y, z, w;
11879 DWORD v1, v2, v3, v4;
11880 DWORD unused3, unused4;
11883 static void test_transform_vertices(void)
11885 IDirect3DDevice3 *device;
11886 IDirectDrawSurface4 *rt;
11887 ULONG refcount;
11888 HWND window;
11889 HRESULT hr;
11890 D3DCOLOR color;
11891 IDirect3DViewport3 *viewport;
11892 static struct transform_input position_tests[] =
11894 { 0.0f, 0.0f, 0.0f, 0.0f, 1, 2, 3, 4, 5},
11895 { 1.0f, 1.0f, 1.0f, 8.0f, 6, 7, 8, 9, 10},
11896 {-1.0f, -1.0f, -1.0f, 4.0f, 11, 12, 13, 14, 15},
11897 { 0.5f, 0.5f, 0.5f, 2.0f, 16, 17, 18, 19, 20},
11898 {-0.5f, -0.5f, -0.5f, 1.0f, ~1U, ~2U, ~3U, ~4U, ~5U},
11899 {-0.5f, -0.5f, 0.0f, 0.0f, ~6U, ~7U, ~8U, ~9U, ~0U},
11901 static struct transform_input cliptest[] =
11903 { 25.59f, 25.59f, 1.0f, 0.0f, 1, 2, 3, 4, 5},
11904 { 25.61f, 25.61f, 1.01f, 0.0f, 1, 2, 3, 4, 5},
11905 {-25.59f, -25.59f, 0.0f, 0.0f, 1, 2, 3, 4, 5},
11906 {-25.61f, -25.61f, -0.01f, 0.0f, 1, 2, 3, 4, 5},
11908 static struct transform_input offscreentest[] =
11910 {128.1f, 0.0f, 0.0f, 0.0f, 1, 2, 3, 4, 5},
11912 struct transform_output out[ARRAY_SIZE(position_tests)];
11913 D3DHVERTEX out_h[ARRAY_SIZE(position_tests)];
11914 D3DTRANSFORMDATA transformdata;
11915 static const D3DVIEWPORT vp_template =
11917 sizeof(vp_template), 0, 0, 256, 256, 5.0f, 5.0f, 256.0f, 256.0f, -25.0f, 60.0f
11919 D3DVIEWPORT vp_data =
11921 sizeof(vp_data), 0, 0, 256, 256, 1.0f, 1.0f, 256.0f, 256.0f, 0.0f, 1.0f
11923 D3DVIEWPORT2 vp2_data;
11924 unsigned int i;
11925 DWORD offscreen;
11926 static D3DMATRIX mat_scale =
11928 2.0f, 0.0f, 0.0f, 0.0f,
11929 0.0f, 2.0f, 0.0f, 0.0f,
11930 0.0f, 0.0f, 2.0f, 0.0f,
11931 0.0f, 0.0f, 0.0f, 1.0f,
11933 mat_translate1 =
11935 1.0f, 0.0f, 0.0f, 0.0f,
11936 0.0f, 1.0f, 0.0f, 0.0f,
11937 0.0f, 0.0f, 1.0f, 0.0f,
11938 1.0f, 0.0f, 0.0f, 1.0f,
11940 mat_translate2 =
11942 1.0f, 0.0f, 0.0f, 0.0f,
11943 0.0f, 1.0f, 0.0f, 0.0f,
11944 0.0f, 0.0f, 1.0f, 0.0f,
11945 0.0f, 1.0f, 0.0f, 1.0f,
11947 mat_transform3 =
11949 1.0f, 0.0f, 0.0f, 0.0f,
11950 0.0f, 1.0f, 0.0f, 0.0f,
11951 0.0f, 0.0f, 1.0f, 0.0f,
11952 0.0f, 19.2f, 0.0f, 2.0f,
11954 mat_identity =
11956 1.0f, 0.0f, 0.0f, 0.0f,
11957 0.0f, 1.0f, 0.0f, 0.0f,
11958 0.0f, 0.0f, 1.0f, 0.0f,
11959 0.0f, 0.0f, 0.0f, 1.0f,
11961 static struct
11963 struct vec3 position;
11964 DWORD color;
11966 quad[] =
11968 {{-0.75f, -0.5f , 0.0f}, 0xffff0000},
11969 {{-0.75f, 0.25f, 0.0f}, 0xffff0000},
11970 {{ 0.5f, -0.5f , 0.0f}, 0xffff0000},
11971 {{ 0.5f, 0.25f, 0.0f}, 0xffff0000},
11973 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
11975 for (i = 0; i < ARRAY_SIZE(out); ++i)
11977 out[i].unused3 = 0xdeadbeef;
11978 out[i].unused4 = 0xcafecafe;
11981 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
11982 0, 0, 640, 480, NULL, NULL, NULL, NULL);
11983 if (!(device = create_device(window, DDSCL_NORMAL)))
11985 skip("Failed to create a 3D device.\n");
11986 DestroyWindow(window);
11987 return;
11989 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
11990 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
11992 viewport = create_viewport(device, 0, 0, 256, 256);
11993 hr = IDirect3DViewport2_SetViewport(viewport, &vp_data);
11994 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#x.\n", hr);
11996 memset(&transformdata, 0, sizeof(transformdata));
11997 transformdata.dwSize = sizeof(transformdata);
11998 transformdata.lpIn = position_tests;
11999 transformdata.dwInSize = sizeof(position_tests[0]);
12000 transformdata.lpOut = out;
12001 transformdata.dwOutSize = sizeof(out[0]);
12002 transformdata.lpHOut = NULL;
12004 hr = IDirect3DViewport2_TransformVertices(viewport, ARRAY_SIZE(position_tests),
12005 &transformdata, D3DTRANSFORM_UNCLIPPED, &offscreen);
12006 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#x.\n", hr);
12007 ok(!offscreen, "Offscreen is %x.\n", offscreen);
12009 for (i = 0; i < ARRAY_SIZE(position_tests); ++i)
12011 static const struct vec4 cmp[] =
12013 {128.0f, 128.0f, 0.0f, 1.0f}, {129.0f, 127.0f, 1.0f, 1.0f}, {127.0f, 129.0f, -1.0f, 1.0f},
12014 {128.5f, 127.5f, 0.5f, 1.0f}, {127.5f, 128.5f, -0.5f, 1.0f}, {127.5f, 128.5f, 0.0f, 1.0f}
12017 ok(compare_vec4(&cmp[i], out[i].x, out[i].y, out[i].z, out[i].w, 4096),
12018 "Vertex %u differs. Got %f %f %f %f.\n", i,
12019 out[i].x, out[i].y, out[i].z, out[i].w);
12020 ok(out[i].v1 == position_tests[i].v1 && out[i].v2 == position_tests[i].v2
12021 && out[i].v3 == position_tests[i].v3 && out[i].v4 == position_tests[i].v4,
12022 "Vertex %u payload is %u %u %u %u.\n", i, out[i].v1, out[i].v2, out[i].v3, out[i].v4);
12023 ok(out[i].unused3 == 0xdeadbeef && out[i].unused4 == 0xcafecafe,
12024 "Vertex %u unused data is %#x, %#x.\n", i, out[i].unused3, out[i].unused4);
12027 vp_data = vp_template;
12028 hr = IDirect3DViewport2_SetViewport(viewport, &vp_data);
12029 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#x.\n", hr);
12030 offscreen = 0xdeadbeef;
12031 hr = IDirect3DViewport2_TransformVertices(viewport, ARRAY_SIZE(position_tests),
12032 &transformdata, D3DTRANSFORM_UNCLIPPED, &offscreen);
12033 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#x.\n", hr);
12034 ok(!offscreen, "Offscreen is %x.\n", offscreen);
12036 for (i = 0; i < ARRAY_SIZE(position_tests); ++i)
12038 static const struct vec4 cmp[] =
12040 {128.0f, 128.0f, 0.0f, 1.0f}, {133.0f, 123.0f, 1.0f, 1.0f}, {123.0f, 133.0f, -1.0f, 1.0f},
12041 {130.5f, 125.5f, 0.5f, 1.0f}, {125.5f, 130.5f, -0.5f, 1.0f}, {125.5f, 130.5f, 0.0f, 1.0f}
12043 ok(compare_vec4(&cmp[i], out[i].x, out[i].y, out[i].z, out[i].w, 4096),
12044 "Vertex %u differs. Got %f %f %f %f.\n", i,
12045 out[i].x, out[i].y, out[i].z, out[i].w);
12048 vp_data.dwX = 10;
12049 vp_data.dwY = 20;
12050 hr = IDirect3DViewport2_SetViewport(viewport, &vp_data);
12051 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#x.\n", hr);
12052 offscreen = 0xdeadbeef;
12053 hr = IDirect3DViewport2_TransformVertices(viewport, ARRAY_SIZE(position_tests),
12054 &transformdata, D3DTRANSFORM_UNCLIPPED, &offscreen);
12055 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#x.\n", hr);
12056 ok(!offscreen, "Offscreen is %x.\n", offscreen);
12057 for (i = 0; i < ARRAY_SIZE(position_tests); ++i)
12059 static const struct vec4 cmp[] =
12061 {138.0f, 148.0f, 0.0f, 1.0f}, {143.0f, 143.0f, 1.0f, 1.0f}, {133.0f, 153.0f, -1.0f, 1.0f},
12062 {140.5f, 145.5f, 0.5f, 1.0f}, {135.5f, 150.5f, -0.5f, 1.0f}, {135.5f, 150.5f, 0.0f, 1.0f}
12064 ok(compare_vec4(&cmp[i], out[i].x, out[i].y, out[i].z, out[i].w, 4096),
12065 "Vertex %u differs. Got %f %f %f %f.\n", i,
12066 out[i].x, out[i].y, out[i].z, out[i].w);
12069 transformdata.lpHOut = out_h;
12070 offscreen = 0xdeadbeef;
12071 hr = IDirect3DViewport2_TransformVertices(viewport, ARRAY_SIZE(position_tests),
12072 &transformdata, D3DTRANSFORM_CLIPPED, &offscreen);
12073 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#x.\n", hr);
12074 ok(!offscreen, "Offscreen is %x.\n", offscreen);
12075 for (i = 0; i < ARRAY_SIZE(position_tests); ++i)
12077 static const D3DHVERTEX cmp_h[] =
12079 {0, { 0.0f}, { 0.0f}, { 0.0f}}, {0, { 1.0f}, { 1.0f}, {1.0f}},
12080 {D3DCLIP_FRONT, {-1.0f}, {-1.0f}, {-1.0f}}, {0, { 0.5f}, { 0.5f}, {0.5f}},
12081 {D3DCLIP_FRONT, {-0.5f}, {-0.5f}, {-0.5f}}, {0, {-0.5f}, {-0.5f}, {0.0f}}
12083 ok(compare_float(U1(cmp_h[i]).hx, U1(out_h[i]).hx, 4096)
12084 && compare_float(U2(cmp_h[i]).hy, U2(out_h[i]).hy, 4096)
12085 && compare_float(U3(cmp_h[i]).hz, U3(out_h[i]).hz, 4096)
12086 && cmp_h[i].dwFlags == out_h[i].dwFlags,
12087 "HVertex %u differs. Got %#x %f %f %f.\n", i,
12088 out_h[i].dwFlags, U1(out_h[i]).hx, U2(out_h[i]).hy, U3(out_h[i]).hz);
12090 /* No scheme has been found behind those return values. It seems to be
12091 * whatever data windows has when throwing the vertex away. Modify the
12092 * input test vertices to test this more. Depending on the input data
12093 * it can happen that the z coord gets written into y, or similar things. */
12094 if (0)
12096 static const struct vec4 cmp[] =
12098 {138.0f, 148.0f, 0.0f, 1.0f}, {143.0f, 143.0f, 1.0f, 1.0f}, { -1.0f, -1.0f, 0.5f, 1.0f},
12099 {140.5f, 145.5f, 0.5f, 1.0f}, { -0.5f, -0.5f, -0.5f, 1.0f}, {135.5f, 150.5f, 0.0f, 1.0f}
12101 ok(compare_vec4(&cmp[i], out[i].x, out[i].y, out[i].z, out[i].w, 4096),
12102 "Vertex %u differs. Got %f %f %f %f.\n", i,
12103 out[i].x, out[i].y, out[i].z, out[i].w);
12107 transformdata.lpIn = cliptest;
12108 transformdata.dwInSize = sizeof(cliptest[0]);
12109 offscreen = 0xdeadbeef;
12110 hr = IDirect3DViewport2_TransformVertices(viewport, ARRAY_SIZE(cliptest),
12111 &transformdata, D3DTRANSFORM_CLIPPED, &offscreen);
12112 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#x.\n", hr);
12113 ok(!offscreen, "Offscreen is %x.\n", offscreen);
12114 for (i = 0; i < ARRAY_SIZE(cliptest); ++i)
12116 static const DWORD flags[] =
12119 D3DCLIP_RIGHT | D3DCLIP_BACK | D3DCLIP_TOP,
12121 D3DCLIP_LEFT | D3DCLIP_BOTTOM | D3DCLIP_FRONT,
12123 ok(flags[i] == out_h[i].dwFlags, "Cliptest %u returned %#x.\n", i, out_h[i].dwFlags);
12126 vp_data = vp_template;
12127 vp_data.dwWidth = 10;
12128 vp_data.dwHeight = 480;
12129 hr = IDirect3DViewport2_SetViewport(viewport, &vp_data);
12130 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#x.\n", hr);
12131 offscreen = 0xdeadbeef;
12132 hr = IDirect3DViewport2_TransformVertices(viewport, ARRAY_SIZE(cliptest),
12133 &transformdata, D3DTRANSFORM_CLIPPED, &offscreen);
12134 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#x.\n", hr);
12135 ok(!offscreen, "Offscreen is %x.\n", offscreen);
12136 for (i = 0; i < ARRAY_SIZE(cliptest); ++i)
12138 static const DWORD flags[] =
12140 D3DCLIP_RIGHT,
12141 D3DCLIP_RIGHT | D3DCLIP_BACK,
12142 D3DCLIP_LEFT,
12143 D3DCLIP_LEFT | D3DCLIP_FRONT,
12145 ok(flags[i] == out_h[i].dwFlags, "Cliptest %u returned %#x.\n", i, out_h[i].dwFlags);
12148 vp_data = vp_template;
12149 vp_data.dwWidth = 256;
12150 vp_data.dwHeight = 256;
12151 vp_data.dvScaleX = 1;
12152 vp_data.dvScaleY = 1;
12153 hr = IDirect3DViewport2_SetViewport(viewport, &vp_data);
12154 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#x.\n", hr);
12155 hr = IDirect3DViewport2_TransformVertices(viewport, ARRAY_SIZE(cliptest),
12156 &transformdata, D3DTRANSFORM_CLIPPED, &offscreen);
12157 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#x.\n", hr);
12158 ok(!offscreen, "Offscreen is %x.\n", offscreen);
12159 for (i = 0; i < ARRAY_SIZE(cliptest); ++i)
12161 static const DWORD flags[] =
12164 D3DCLIP_BACK,
12166 D3DCLIP_FRONT,
12168 ok(flags[i] == out_h[i].dwFlags, "Cliptest %u returned %#x.\n", i, out_h[i].dwFlags);
12171 /* Finally try to figure out how the DWORD dwOffscreen works.
12172 * It is a logical AND of the vertices' dwFlags members. */
12173 vp_data = vp_template;
12174 vp_data.dwWidth = 5;
12175 vp_data.dwHeight = 5;
12176 vp_data.dvScaleX = 10000.0f;
12177 vp_data.dvScaleY = 10000.0f;
12178 hr = IDirect3DViewport2_SetViewport(viewport, &vp_data);
12179 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#x.\n", hr);
12180 transformdata.lpIn = cliptest;
12181 offscreen = 0xdeadbeef;
12182 hr = IDirect3DViewport2_TransformVertices(viewport, 1,
12183 &transformdata, D3DTRANSFORM_UNCLIPPED, &offscreen);
12184 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#x.\n", hr);
12185 ok(!offscreen, "Offscreen is %x.\n", offscreen);
12187 offscreen = 0xdeadbeef;
12188 hr = IDirect3DViewport2_TransformVertices(viewport, 1,
12189 &transformdata, D3DTRANSFORM_CLIPPED, &offscreen);
12190 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#x.\n", hr);
12191 ok(offscreen == (D3DCLIP_RIGHT | D3DCLIP_TOP), "Offscreen is %x.\n", offscreen);
12192 offscreen = 0xdeadbeef;
12193 hr = IDirect3DViewport2_TransformVertices(viewport, 2,
12194 &transformdata, D3DTRANSFORM_CLIPPED, &offscreen);
12195 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#x.\n", hr);
12196 ok(offscreen == (D3DCLIP_RIGHT | D3DCLIP_TOP), "Offscreen is %x.\n", offscreen);
12197 hr = IDirect3DViewport2_TransformVertices(viewport, 3,
12198 &transformdata, D3DTRANSFORM_CLIPPED, &offscreen);
12199 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#x.\n", hr);
12200 ok(!offscreen, "Offscreen is %x.\n", offscreen);
12202 transformdata.lpIn = cliptest + 1;
12203 hr = IDirect3DViewport2_TransformVertices(viewport, 1,
12204 &transformdata, D3DTRANSFORM_CLIPPED, &offscreen);
12205 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#x.\n", hr);
12206 ok(offscreen == (D3DCLIP_BACK | D3DCLIP_RIGHT | D3DCLIP_TOP), "Offscreen is %x.\n", offscreen);
12208 transformdata.lpIn = cliptest + 2;
12209 hr = IDirect3DViewport2_TransformVertices(viewport, 1,
12210 &transformdata, D3DTRANSFORM_CLIPPED, &offscreen);
12211 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#x.\n", hr);
12212 ok(offscreen == (D3DCLIP_BOTTOM | D3DCLIP_LEFT), "Offscreen is %x.\n", offscreen);
12213 offscreen = 0xdeadbeef;
12214 hr = IDirect3DViewport2_TransformVertices(viewport, 2,
12215 &transformdata, D3DTRANSFORM_CLIPPED, &offscreen);
12216 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#x.\n", hr);
12217 ok(offscreen == (D3DCLIP_BOTTOM | D3DCLIP_LEFT), "Offscreen is %x.\n", offscreen);
12219 transformdata.lpIn = cliptest + 3;
12220 hr = IDirect3DViewport2_TransformVertices(viewport, 1,
12221 &transformdata, D3DTRANSFORM_CLIPPED, &offscreen);
12222 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#x.\n", hr);
12223 ok(offscreen == (D3DCLIP_FRONT | D3DCLIP_BOTTOM | D3DCLIP_LEFT), "Offscreen is %x.\n", offscreen);
12225 transformdata.lpIn = offscreentest;
12226 transformdata.dwInSize = sizeof(offscreentest[0]);
12227 vp_data = vp_template;
12228 vp_data.dwWidth = 257;
12229 vp_data.dwHeight = 257;
12230 vp_data.dvScaleX = 1.0f;
12231 vp_data.dvScaleY = 1.0f;
12232 hr = IDirect3DViewport2_SetViewport(viewport, &vp_data);
12233 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#x.\n", hr);
12234 offscreen = 0xdeadbeef;
12235 hr = IDirect3DViewport2_TransformVertices(viewport, 1,
12236 &transformdata, D3DTRANSFORM_CLIPPED, &offscreen);
12237 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#x.\n", hr);
12238 ok(!offscreen, "Offscreen is %x.\n", offscreen);
12240 vp_data.dwWidth = 256;
12241 vp_data.dwHeight = 256;
12242 hr = IDirect3DViewport2_SetViewport(viewport, &vp_data);
12243 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#x.\n", hr);
12244 hr = IDirect3DViewport2_TransformVertices(viewport, 1,
12245 &transformdata, D3DTRANSFORM_CLIPPED, &offscreen);
12246 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#x.\n", hr);
12247 ok(offscreen == D3DCLIP_RIGHT, "Offscreen is %x.\n", offscreen);
12249 /* Test the effect of Matrices.
12251 * Basically the x coordinate ends up as ((x + 1) * 2 + 0) * 5 and
12252 * y as ((y + 0) * 2 + 1) * 5. The 5 comes from dvScaleX/Y, 2 from
12253 * the view matrix and the +1's from the world and projection matrix. */
12254 vp_data.dwX = 0;
12255 vp_data.dwY = 0;
12256 vp_data.dwWidth = 256;
12257 vp_data.dwHeight = 256;
12258 vp_data.dvScaleX = 5.0f;
12259 vp_data.dvScaleY = 5.0f;
12260 vp_data.dvMinZ = 0.0f;
12261 vp_data.dvMaxZ = 1.0f;
12262 hr = IDirect3DViewport2_SetViewport(viewport, &vp_data);
12263 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#x.\n", hr);
12265 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &mat_translate1);
12266 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#x.\n", hr);
12267 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_VIEW, &mat_scale);
12268 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#x.\n", hr);
12269 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &mat_translate2);
12270 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#x.\n", hr);
12272 transformdata.lpIn = position_tests;
12273 transformdata.dwInSize = sizeof(position_tests[0]);
12274 hr = IDirect3DViewport2_TransformVertices(viewport, ARRAY_SIZE(position_tests),
12275 &transformdata, D3DTRANSFORM_UNCLIPPED, &offscreen);
12276 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#x.\n", hr);
12278 for (i = 0; i < ARRAY_SIZE(position_tests); ++i)
12280 static const struct vec4 cmp[] =
12282 {138.0f, 123.0f, 0.0f, 1.0f}, {148.0f, 113.0f, 2.0f, 1.0f}, {128.0f, 133.0f, -2.0f, 1.0f},
12283 {143.0f, 118.0f, 1.0f, 1.0f}, {133.0f, 128.0f, -1.0f, 1.0f}, {133.0f, 128.0f, 0.0f, 1.0f}
12286 ok(compare_vec4(&cmp[i], out[i].x, out[i].y, out[i].z, out[i].w, 4096),
12287 "Vertex %u differs. Got %f %f %f %f.\n", i,
12288 out[i].x, out[i].y, out[i].z, out[i].w);
12291 /* Invalid flags. */
12292 offscreen = 0xdeadbeef;
12293 hr = IDirect3DViewport2_TransformVertices(viewport, ARRAY_SIZE(position_tests),
12294 &transformdata, 0, &offscreen);
12295 ok(hr == DDERR_INVALIDPARAMS, "TransformVertices returned %#x.\n", hr);
12296 ok(offscreen == 0xdeadbeef, "Offscreen is %x.\n", offscreen);
12298 /* NULL transform data. */
12299 hr = IDirect3DViewport2_TransformVertices(viewport, 1,
12300 NULL, D3DTRANSFORM_UNCLIPPED, &offscreen);
12301 ok(hr == DDERR_INVALIDPARAMS, "TransformVertices returned %#x.\n", hr);
12302 ok(offscreen == 0xdeadbeef, "Offscreen is %x.\n", offscreen);
12303 hr = IDirect3DViewport2_TransformVertices(viewport, 0,
12304 NULL, D3DTRANSFORM_UNCLIPPED, &offscreen);
12305 ok(hr == DDERR_INVALIDPARAMS, "TransformVertices returned %#x.\n", hr);
12306 ok(offscreen == 0xdeadbeef, "Offscreen is %x.\n", offscreen);
12308 /* NULL transform data and NULL dwOffscreen.
12310 * Valid transform data + NULL dwOffscreen -> crash. */
12311 hr = IDirect3DViewport2_TransformVertices(viewport, 1,
12312 NULL, D3DTRANSFORM_UNCLIPPED, NULL);
12313 ok(hr == DDERR_INVALIDPARAMS, "TransformVertices returned %#x.\n", hr);
12315 /* No vertices. */
12316 hr = IDirect3DViewport2_TransformVertices(viewport, 0,
12317 &transformdata, D3DTRANSFORM_UNCLIPPED, &offscreen);
12318 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#x.\n", hr);
12319 ok(!offscreen, "Offscreen is %x.\n", offscreen);
12320 hr = IDirect3DViewport2_TransformVertices(viewport, 0,
12321 &transformdata, D3DTRANSFORM_CLIPPED, &offscreen);
12322 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#x.\n", hr);
12323 ok(offscreen == ~0U, "Offscreen is %x.\n", offscreen);
12325 /* Invalid sizes. */
12326 offscreen = 0xdeadbeef;
12327 transformdata.dwSize = sizeof(transformdata) - 1;
12328 hr = IDirect3DViewport2_TransformVertices(viewport, 1,
12329 &transformdata, D3DTRANSFORM_UNCLIPPED, &offscreen);
12330 ok(hr == DDERR_INVALIDPARAMS, "TransformVertices returned %#x.\n", hr);
12331 ok(offscreen == 0xdeadbeef, "Offscreen is %x.\n", offscreen);
12332 transformdata.dwSize = sizeof(transformdata) + 1;
12333 hr = IDirect3DViewport2_TransformVertices(viewport, 1,
12334 &transformdata, D3DTRANSFORM_UNCLIPPED, &offscreen);
12335 ok(hr == DDERR_INVALIDPARAMS, "TransformVertices returned %#x.\n", hr);
12336 ok(offscreen == 0xdeadbeef, "Offscreen is %x.\n", offscreen);
12338 /* NULL lpIn or lpOut -> crash, except when transforming 0 vertices. */
12339 transformdata.dwSize = sizeof(transformdata);
12340 transformdata.lpIn = NULL;
12341 transformdata.lpOut = NULL;
12342 offscreen = 0xdeadbeef;
12343 hr = IDirect3DViewport2_TransformVertices(viewport, 0,
12344 &transformdata, D3DTRANSFORM_CLIPPED, &offscreen);
12345 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#x.\n", hr);
12346 ok(offscreen == ~0U, "Offscreen is %x.\n", offscreen);
12348 /* Test how vertices are transformed during draws. */
12349 vp_data.dwX = 20;
12350 vp_data.dwY = 20;
12351 vp_data.dwWidth = 200;
12352 vp_data.dwHeight = 400;
12353 vp_data.dvScaleX = 20.0f;
12354 vp_data.dvScaleY = 50.0f;
12355 vp_data.dvMinZ = 0.0f;
12356 vp_data.dvMaxZ = 1.0f;
12357 hr = IDirect3DViewport3_SetViewport(viewport, &vp_data);
12358 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#x.\n", hr);
12359 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
12360 ok(SUCCEEDED(hr), "Failed to activate the viewport, hr %#x.\n", hr);
12362 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0x000000ff, 0.0f, 0);
12363 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
12365 hr = IDirect3DDevice3_BeginScene(device);
12366 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
12367 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE,
12368 quad, 4, 0);
12369 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12370 hr = IDirect3DDevice3_EndScene(device);
12371 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
12373 color = get_surface_color(rt, 128, 143);
12374 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
12375 color = get_surface_color(rt, 132, 143);
12376 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
12377 color = get_surface_color(rt, 128, 147);
12378 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
12379 color = get_surface_color(rt, 132, 147);
12380 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
12382 color = get_surface_color(rt, 177, 217);
12383 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
12384 color = get_surface_color(rt, 181, 217);
12385 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
12386 color = get_surface_color(rt, 177, 221);
12387 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
12388 color = get_surface_color(rt, 181, 221);
12389 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
12391 /* Test D3DVIEWPORT2 behavior. */
12392 vp2_data.dwSize = sizeof(vp2_data);
12393 vp2_data.dwX = 20;
12394 vp2_data.dwY = 20;
12395 vp2_data.dwWidth = 200;
12396 vp2_data.dwHeight = 400;
12397 vp2_data.dvClipX = -0.5f;
12398 vp2_data.dvClipY = 4.0f;
12399 vp2_data.dvClipWidth = 5.0f;
12400 vp2_data.dvClipHeight = 10.0f;
12401 vp2_data.dvMinZ = 0.0f;
12402 vp2_data.dvMaxZ = 2.0f;
12403 hr = IDirect3DViewport3_SetViewport2(viewport, &vp2_data);
12404 ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
12405 transformdata.lpIn = position_tests;
12406 transformdata.lpOut = out;
12407 hr = IDirect3DViewport3_TransformVertices(viewport, ARRAY_SIZE(position_tests),
12408 &transformdata, D3DTRANSFORM_UNCLIPPED, &offscreen);
12409 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#x.\n", hr);
12410 for (i = 0; i < ARRAY_SIZE(position_tests); ++i)
12412 static const struct vec4 cmp[] =
12414 {120.0f, 140.0f, 0.0f, 1.0f}, {200.0f, 60.0f, 1.0f, 1.0f}, {40.0f, 220.0f, -1.0f, 1.0f},
12415 {160.0f, 100.0f, 0.5f, 1.0f}, { 80.0f, 180.0f, -0.5f, 1.0f}, {80.0f, 180.0f, 0.0f, 1.0f}
12418 ok(compare_vec4(&cmp[i], out[i].x, out[i].y, out[i].z, out[i].w, 4096),
12419 "Vertex %u differs. Got %f %f %f %f.\n", i,
12420 out[i].x, out[i].y, out[i].z, out[i].w);
12423 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0x0000ff00, 0.0f, 0);
12424 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
12426 hr = IDirect3DDevice3_BeginScene(device);
12427 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
12428 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE,
12429 quad, 4, 0);
12430 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12431 hr = IDirect3DDevice3_EndScene(device);
12432 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
12434 color = get_surface_color(rt, 58, 118);
12435 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
12436 color = get_surface_color(rt, 62, 118);
12437 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
12438 color = get_surface_color(rt, 58, 122);
12439 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
12440 color = get_surface_color(rt, 62, 122);
12441 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
12443 color = get_surface_color(rt, 157, 177);
12444 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
12445 color = get_surface_color(rt, 161, 177);
12446 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
12447 color = get_surface_color(rt, 157, 181);
12448 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
12449 color = get_surface_color(rt, 161, 181);
12450 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
12452 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &mat_identity);
12453 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#x.\n", hr);
12454 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_VIEW, &mat_identity);
12455 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#x.\n", hr);
12456 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &mat_transform3);
12457 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#x.\n", hr);
12459 vp2_data.dwX = 0.0;
12460 vp2_data.dwY = 0.0;
12461 vp2_data.dwWidth = 1;
12462 vp2_data.dwHeight = 1;
12463 vp2_data.dvClipX = -12.8f;
12464 vp2_data.dvClipY = 12.8f + mat_transform3._42 / mat_transform3._44;
12465 vp2_data.dvClipWidth = 25.6f;
12466 vp2_data.dvClipHeight = 25.6f;
12467 vp2_data.dvMinZ = 0.0f;
12468 vp2_data.dvMaxZ = 0.5f;
12469 hr = IDirect3DViewport3_SetViewport2(viewport, &vp2_data);
12470 ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
12471 transformdata.lpIn = cliptest;
12472 transformdata.dwInSize = sizeof(cliptest[0]);
12473 offscreen = 0xdeadbeef;
12474 hr = IDirect3DViewport3_TransformVertices(viewport, ARRAY_SIZE(cliptest),
12475 &transformdata, D3DTRANSFORM_CLIPPED, &offscreen);
12476 ok(SUCCEEDED(hr), "Failed to transform vertices, hr %#x.\n", hr);
12477 ok(!offscreen, "Offscreen is %x.\n", offscreen);
12478 for (i = 0; i < ARRAY_SIZE(cliptest); ++i)
12480 static const D3DHVERTEX cmp_h[] =
12482 {0, { 25.59f}, { 44.79f}, { 1.0f }},
12483 {D3DCLIP_RIGHT | D3DCLIP_TOP | D3DCLIP_BACK, { 25.61f}, { 44.81f}, { 1.01f}},
12484 {0, {-25.59f}, {-6.39f }, { 0.0f }},
12485 {D3DCLIP_LEFT | D3DCLIP_BOTTOM | D3DCLIP_FRONT,{-25.61f}, {-6.41f }, {-0.01f}},
12487 ok(compare_float(U1(cmp_h[i]).hx, U1(out_h[i]).hx, 4096)
12488 && compare_float(U2(cmp_h[i]).hy, U2(out_h[i]).hy, 4096)
12489 && compare_float(U3(cmp_h[i]).hz, U3(out_h[i]).hz, 4096)
12490 && cmp_h[i].dwFlags == out_h[i].dwFlags,
12491 "HVertex %u differs. Got %#x %f %f %f.\n", i,
12492 out_h[i].dwFlags, U1(out_h[i]).hx, U2(out_h[i]).hy, U3(out_h[i]).hz);
12495 destroy_viewport(device, viewport);
12496 IDirectDrawSurface4_Release(rt);
12497 refcount = IDirect3DDevice3_Release(device);
12498 ok(!refcount, "Device has %u references left.\n", refcount);
12499 DestroyWindow(window);
12502 static void test_display_mode_surface_pixel_format(void)
12504 unsigned int width, height, bpp;
12505 IDirectDrawSurface4 *surface;
12506 DDSURFACEDESC2 surface_desc;
12507 IDirectDraw4 *ddraw;
12508 ULONG refcount;
12509 HWND window;
12510 HRESULT hr;
12512 if (!(ddraw = create_ddraw()))
12514 skip("Failed to create ddraw.\n");
12515 return;
12518 surface_desc.dwSize = sizeof(surface_desc);
12519 hr = IDirectDraw4_GetDisplayMode(ddraw, &surface_desc);
12520 ok(SUCCEEDED(hr), "Failed to get display mode, hr %#x.\n", hr);
12521 width = surface_desc.dwWidth;
12522 height = surface_desc.dwHeight;
12524 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
12525 0, 0, width, height, NULL, NULL, NULL, NULL);
12526 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
12527 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
12529 bpp = 0;
12530 if (SUCCEEDED(IDirectDraw4_SetDisplayMode(ddraw, width, height, 16, 0, 0)))
12531 bpp = 16;
12532 if (SUCCEEDED(IDirectDraw4_SetDisplayMode(ddraw, width, height, 24, 0, 0)))
12533 bpp = 24;
12534 if (SUCCEEDED(IDirectDraw4_SetDisplayMode(ddraw, width, height, 32, 0, 0)))
12535 bpp = 32;
12536 ok(bpp, "Set display mode failed.\n");
12538 surface_desc.dwSize = sizeof(surface_desc);
12539 hr = IDirectDraw4_GetDisplayMode(ddraw, &surface_desc);
12540 ok(SUCCEEDED(hr), "Failed to get display mode, hr %#x.\n", hr);
12541 ok(surface_desc.dwWidth == width, "Got width %u, expected %u.\n", surface_desc.dwWidth, width);
12542 ok(surface_desc.dwHeight == height, "Got height %u, expected %u.\n", surface_desc.dwHeight, height);
12543 ok(U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount == bpp, "Got bpp %u, expected %u.\n",
12544 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount, bpp);
12546 memset(&surface_desc, 0, sizeof(surface_desc));
12547 surface_desc.dwSize = sizeof(surface_desc);
12548 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
12549 U5(surface_desc).dwBackBufferCount = 1;
12550 surface_desc.ddsCaps.dwCaps = DDSCAPS_COMPLEX | DDSCAPS_FLIP | DDSCAPS_PRIMARYSURFACE;
12551 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
12552 ok(hr == D3D_OK, "Failed to create surface, hr %#x.\n", hr);
12553 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &surface_desc);
12554 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
12555 ok(surface_desc.dwWidth == width, "Got width %u, expected %u.\n", surface_desc.dwWidth, width);
12556 ok(surface_desc.dwHeight == height, "Got height %u, expected %u.\n", surface_desc.dwHeight, height);
12557 ok(U4(surface_desc).ddpfPixelFormat.dwFlags == DDPF_RGB, "Got unexpected pixel format flags %#x.\n",
12558 U4(surface_desc).ddpfPixelFormat.dwFlags);
12559 ok(U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount == bpp, "Got bpp %u, expected %u.\n",
12560 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount, bpp);
12561 IDirectDrawSurface4_Release(surface);
12563 memset(&surface_desc, 0, sizeof(surface_desc));
12564 surface_desc.dwSize = sizeof(surface_desc);
12565 surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
12566 surface_desc.dwWidth = width;
12567 surface_desc.dwHeight = height;
12568 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
12569 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
12570 ok(hr == D3D_OK, "Failed to create surface, hr %#x.\n", hr);
12571 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &surface_desc);
12572 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
12573 ok(U4(surface_desc).ddpfPixelFormat.dwFlags == DDPF_RGB, "Got unexpected pixel format flags %#x.\n",
12574 U4(surface_desc).ddpfPixelFormat.dwFlags);
12575 ok(U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount == bpp, "Got bpp %u, expected %u.\n",
12576 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount, bpp);
12577 IDirectDrawSurface4_Release(surface);
12579 refcount = IDirectDraw4_Release(ddraw);
12580 ok(!refcount, "DirectDraw has %u references left.\n", refcount);
12581 DestroyWindow(window);
12584 static void test_surface_desc_size(void)
12586 union
12588 DWORD dwSize;
12589 DDSURFACEDESC desc1;
12590 DDSURFACEDESC2 desc2;
12591 BYTE blob[1024];
12592 } desc;
12593 IDirectDrawSurface4 *surface4;
12594 IDirectDrawSurface3 *surface3;
12595 IDirectDrawSurface *surface;
12596 DDSURFACEDESC2 surface_desc;
12597 HRESULT expected_hr, hr;
12598 IDirectDraw4 *ddraw;
12599 unsigned int i, j;
12600 ULONG refcount;
12602 static const struct
12604 unsigned int caps;
12605 const char *name;
12607 surface_caps[] =
12609 {DDSCAPS_OFFSCREENPLAIN, "offscreenplain"},
12610 {DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, "systemmemory texture"},
12611 {DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, "videomemory texture"},
12613 static const unsigned int desc_sizes[] =
12615 sizeof(DDSURFACEDESC),
12616 sizeof(DDSURFACEDESC2),
12617 sizeof(DDSURFACEDESC) + 1,
12618 sizeof(DDSURFACEDESC2) + 1,
12619 2 * sizeof(DDSURFACEDESC),
12620 2 * sizeof(DDSURFACEDESC2),
12621 sizeof(DDSURFACEDESC) - 1,
12622 sizeof(DDSURFACEDESC2) - 1,
12623 sizeof(DDSURFACEDESC) / 2,
12624 sizeof(DDSURFACEDESC2) / 2,
12628 sizeof(desc) / 2,
12629 sizeof(desc) - 100,
12632 if (!(ddraw = create_ddraw()))
12634 skip("Failed to create ddraw.\n");
12635 return;
12637 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
12638 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
12640 for (i = 0; i < sizeof(surface_caps) / sizeof(*surface_caps); ++i)
12642 memset(&surface_desc, 0, sizeof(surface_desc));
12643 surface_desc.dwSize = sizeof(surface_desc);
12644 surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
12645 surface_desc.ddsCaps.dwCaps = surface_caps[i].caps;
12646 surface_desc.dwHeight = 128;
12647 surface_desc.dwWidth = 128;
12648 if (FAILED(IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface4, NULL)))
12650 skip("Failed to create surface, type %s.\n", surface_caps[i].name);
12651 continue;
12653 hr = IDirectDrawSurface_QueryInterface(surface4, &IID_IDirectDrawSurface, (void **)&surface);
12654 ok(hr == DD_OK, "Failed to query IDirectDrawSurface, hr %#x, type %s.\n", hr, surface_caps[i].name);
12655 hr = IDirectDrawSurface_QueryInterface(surface4, &IID_IDirectDrawSurface3, (void **)&surface3);
12656 ok(hr == DD_OK, "Failed to query IDirectDrawSurface3, hr %#x, type %s.\n", hr, surface_caps[i].name);
12658 /* GetSurfaceDesc() */
12659 for (j = 0; j < sizeof(desc_sizes) / sizeof(*desc_sizes); ++j)
12661 memset(&desc, 0, sizeof(desc));
12662 desc.dwSize = desc_sizes[j];
12663 expected_hr = desc.dwSize == sizeof(DDSURFACEDESC) ? DD_OK : DDERR_INVALIDPARAMS;
12664 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &desc.desc1);
12665 ok(hr == expected_hr, "Got hr %#x, expected %#x, dwSize %u, type %s.\n",
12666 hr, expected_hr, desc_sizes[j], surface_caps[i].name);
12668 memset(&desc, 0, sizeof(desc));
12669 desc.dwSize = desc_sizes[j];
12670 expected_hr = desc.dwSize == sizeof(DDSURFACEDESC) ? DD_OK : DDERR_INVALIDPARAMS;
12671 hr = IDirectDrawSurface3_GetSurfaceDesc(surface3, &desc.desc1);
12672 ok(hr == expected_hr, "Got hr %#x, expected %#x, dwSize %u, type %s.\n",
12673 hr, expected_hr, desc_sizes[j], surface_caps[i].name);
12675 memset(&desc, 0, sizeof(desc));
12676 desc.dwSize = desc_sizes[j];
12677 expected_hr = desc.dwSize == sizeof(DDSURFACEDESC2) ? DD_OK : DDERR_INVALIDPARAMS;
12678 hr = IDirectDrawSurface4_GetSurfaceDesc(surface4, &desc.desc2);
12679 ok(hr == expected_hr, "Got hr %#x, expected %#x, dwSize %u, type %s.\n",
12680 hr, expected_hr, desc_sizes[j], surface_caps[i].name);
12683 /* Lock() */
12684 for (j = 0; j < sizeof(desc_sizes) / sizeof(*desc_sizes); ++j)
12686 const BOOL valid_size = desc_sizes[j] == sizeof(DDSURFACEDESC)
12687 || desc_sizes[j] == sizeof(DDSURFACEDESC2);
12688 DWORD expected_texture_stage;
12690 memset(&desc, 0, sizeof(desc));
12691 desc.dwSize = desc_sizes[j];
12692 desc.desc2.dwTextureStage = 0xdeadbeef;
12693 desc.blob[sizeof(DDSURFACEDESC2)] = 0xef;
12694 hr = IDirectDrawSurface_Lock(surface, NULL, &desc.desc1, 0, 0);
12695 expected_hr = valid_size ? DD_OK : DDERR_INVALIDPARAMS;
12696 ok(hr == expected_hr, "Got hr %#x, expected %#x, dwSize %u, type %s.\n",
12697 hr, expected_hr, desc_sizes[j], surface_caps[i].name);
12698 ok(desc.dwSize == desc_sizes[j], "dwSize was changed from %u to %u, type %s.\n",
12699 desc_sizes[j], desc.dwSize, surface_caps[i].name);
12700 ok(desc.blob[sizeof(DDSURFACEDESC2)] == 0xef, "Got unexpected byte %02x, dwSize %u, type %s.\n",
12701 desc.blob[sizeof(DDSURFACEDESC2)], desc_sizes[j], surface_caps[i].name);
12702 if (SUCCEEDED(hr))
12704 ok(desc.desc1.dwWidth == 128, "Got unexpected width %u, dwSize %u, type %s.\n",
12705 desc.desc1.dwWidth, desc_sizes[j], surface_caps[i].name);
12706 ok(desc.desc1.dwHeight == 128, "Got unexpected height %u, dwSize %u, type %s.\n",
12707 desc.desc1.dwHeight, desc_sizes[j], surface_caps[i].name);
12708 expected_texture_stage = desc_sizes[j] >= sizeof(DDSURFACEDESC2) ? 0 : 0xdeadbeef;
12709 todo_wine_if(!expected_texture_stage)
12710 ok(desc.desc2.dwTextureStage == expected_texture_stage,
12711 "Got unexpected texture stage %#x, dwSize %u, type %s.\n",
12712 desc.desc2.dwTextureStage, desc_sizes[j], surface_caps[i].name);
12713 IDirectDrawSurface_Unlock(surface, NULL);
12716 memset(&desc, 0, sizeof(desc));
12717 desc.dwSize = desc_sizes[j];
12718 desc.desc2.dwTextureStage = 0xdeadbeef;
12719 desc.blob[sizeof(DDSURFACEDESC2)] = 0xef;
12720 hr = IDirectDrawSurface3_Lock(surface3, NULL, &desc.desc1, 0, 0);
12721 expected_hr = valid_size ? DD_OK : DDERR_INVALIDPARAMS;
12722 ok(hr == expected_hr, "Got hr %#x, expected %#x, dwSize %u, type %s.\n",
12723 hr, expected_hr, desc_sizes[j], surface_caps[i].name);
12724 ok(desc.dwSize == desc_sizes[j], "dwSize was changed from %u to %u, type %s.\n",
12725 desc_sizes[j], desc.dwSize, surface_caps[i].name);
12726 ok(desc.blob[sizeof(DDSURFACEDESC2)] == 0xef, "Got unexpected byte %02x, dwSize %u, type %s.\n",
12727 desc.blob[sizeof(DDSURFACEDESC2)], desc_sizes[j], surface_caps[i].name);
12728 if (SUCCEEDED(hr))
12730 ok(desc.desc1.dwWidth == 128, "Got unexpected width %u, dwSize %u, type %s.\n",
12731 desc.desc1.dwWidth, desc_sizes[j], surface_caps[i].name);
12732 ok(desc.desc1.dwHeight == 128, "Got unexpected height %u, dwSize %u, type %s.\n",
12733 desc.desc1.dwHeight, desc_sizes[j], surface_caps[i].name);
12734 expected_texture_stage = desc_sizes[j] >= sizeof(DDSURFACEDESC2) ? 0 : 0xdeadbeef;
12735 todo_wine_if(!expected_texture_stage)
12736 ok(desc.desc2.dwTextureStage == expected_texture_stage,
12737 "Got unexpected texture stage %#x, dwSize %u, type %s.\n",
12738 desc.desc2.dwTextureStage, desc_sizes[j], surface_caps[i].name);
12739 IDirectDrawSurface3_Unlock(surface3, NULL);
12742 memset(&desc, 0, sizeof(desc));
12743 desc.dwSize = desc_sizes[j];
12744 desc.desc2.dwTextureStage = 0xdeadbeef;
12745 desc.blob[sizeof(DDSURFACEDESC2)] = 0xef;
12746 hr = IDirectDrawSurface4_Lock(surface4, NULL, &desc.desc2, 0, 0);
12747 expected_hr = valid_size ? DD_OK : DDERR_INVALIDPARAMS;
12748 ok(hr == expected_hr, "Got hr %#x, expected %#x, dwSize %u, type %s.\n",
12749 hr, expected_hr, desc_sizes[j], surface_caps[i].name);
12750 ok(desc.dwSize == desc_sizes[j], "dwSize was changed from %u to %u, type %s.\n",
12751 desc_sizes[j], desc.dwSize, surface_caps[i].name);
12752 ok(desc.blob[sizeof(DDSURFACEDESC2)] == 0xef, "Got unexpected byte %02x, dwSize %u, type %s.\n",
12753 desc.blob[sizeof(DDSURFACEDESC2)], desc_sizes[j], surface_caps[i].name);
12754 if (SUCCEEDED(hr))
12756 ok(desc.desc2.dwWidth == 128, "Got unexpected width %u, dwSize %u, type %s.\n",
12757 desc.desc2.dwWidth, desc_sizes[j], surface_caps[i].name);
12758 ok(desc.desc2.dwHeight == 128, "Got unexpected height %u, dwSize %u, type %s.\n",
12759 desc.desc2.dwHeight, desc_sizes[j], surface_caps[i].name);
12760 expected_texture_stage = desc_sizes[j] >= sizeof(DDSURFACEDESC2) ? 0 : 0xdeadbeef;
12761 ok(desc.desc2.dwTextureStage == expected_texture_stage,
12762 "Got unexpected texture stage %#x, dwSize %u, type %s.\n",
12763 desc.desc2.dwTextureStage, desc_sizes[j], surface_caps[i].name);
12764 IDirectDrawSurface4_Unlock(surface4, NULL);
12768 IDirectDrawSurface4_Release(surface4);
12769 IDirectDrawSurface3_Release(surface3);
12770 IDirectDrawSurface_Release(surface);
12773 refcount = IDirectDraw4_Release(ddraw);
12774 ok(!refcount, "DirectDraw has %u references left.\n", refcount);
12777 static void test_get_surface_from_dc(void)
12779 IDirectDrawSurface *surface1, *tmp;
12780 IDirectDrawSurface4 *surface;
12781 DDSURFACEDESC2 surface_desc;
12782 IDirectDraw4 *ddraw;
12783 HDC dc, device_dc;
12784 ULONG refcount;
12785 HWND window;
12786 HRESULT hr;
12787 DWORD ret;
12789 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
12790 0, 0, 640, 480, 0, 0, 0, 0);
12791 ddraw = create_ddraw();
12792 ok(!!ddraw, "Failed to create a ddraw object.\n");
12793 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
12794 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
12796 memset(&surface_desc, 0, sizeof(surface_desc));
12797 surface_desc.dwSize = sizeof(surface_desc);
12798 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
12799 surface_desc.dwWidth = 64;
12800 surface_desc.dwHeight = 64;
12801 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
12803 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
12804 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
12805 hr = IDirectDrawSurface4_QueryInterface(surface, &IID_IDirectDrawSurface, (void **)&surface1);
12806 ok(SUCCEEDED(hr), "Failed to query IDirectDrawSurface interface, hr %#x.\n", hr);
12808 refcount = get_refcount((IUnknown *)surface1);
12809 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
12810 refcount = get_refcount((IUnknown *)surface);
12811 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
12813 hr = IDirectDrawSurface4_GetDC(surface, &dc);
12814 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
12816 tmp = (void *)0xdeadbeef;
12817 device_dc = (void *)0xdeadbeef;
12818 hr = GetSurfaceFromDC(NULL, &tmp, &device_dc);
12819 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
12820 ok(!tmp, "Got unexpected surface %p.\n", tmp);
12821 ok(!device_dc, "Got unexpected device_dc %p.\n", device_dc);
12823 device_dc = (void *)0xdeadbeef;
12824 hr = GetSurfaceFromDC(dc, NULL, &device_dc);
12825 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
12826 ok(device_dc == (void *)0xdeadbeef, "Got unexpected device_dc %p.\n", device_dc);
12828 tmp = (void *)0xdeadbeef;
12829 hr = GetSurfaceFromDC(dc, &tmp, NULL);
12830 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
12831 ok(!tmp, "Got unexpected surface %p.\n", tmp);
12833 hr = GetSurfaceFromDC(dc, &tmp, &device_dc);
12834 ok(SUCCEEDED(hr), "GetSurfaceFromDC failed, hr %#x.\n", hr);
12835 ok(tmp == surface1, "Got unexpected surface %p, expected %p.\n", tmp, surface1);
12836 IDirectDrawSurface_Release(tmp);
12838 ret = GetObjectType(device_dc);
12839 todo_wine ok(ret == OBJ_DC, "Got unexpected object type %#x.\n", ret);
12840 ret = GetDeviceCaps(device_dc, TECHNOLOGY);
12841 todo_wine ok(ret == DT_RASDISPLAY, "Got unexpected technology %#x.\n", ret);
12843 hr = IDirectDraw4_GetSurfaceFromDC(ddraw, dc, NULL);
12844 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
12846 hr = IDirectDraw4_GetSurfaceFromDC(ddraw, dc, (IDirectDrawSurface4 **)&tmp);
12847 ok(SUCCEEDED(hr), "GetSurfaceFromDC failed, hr %#x.\n", hr);
12848 ok(tmp == surface1, "Got unexpected surface %p, expected %p.\n", tmp, surface1);
12850 refcount = get_refcount((IUnknown *)surface1);
12851 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
12852 refcount = get_refcount((IUnknown *)surface);
12853 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
12855 hr = IDirectDrawSurface4_ReleaseDC(surface, dc);
12856 ok(SUCCEEDED(hr), "ReleaseDC failed, hr %#x.\n", hr);
12858 IDirectDrawSurface_Release(tmp);
12860 dc = CreateCompatibleDC(NULL);
12861 ok(!!dc, "CreateCompatibleDC failed.\n");
12863 tmp = (void *)0xdeadbeef;
12864 device_dc = (void *)0xdeadbeef;
12865 hr = GetSurfaceFromDC(dc, &tmp, &device_dc);
12866 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
12867 ok(!tmp, "Got unexpected surface %p.\n", tmp);
12868 ok(!device_dc, "Got unexpected device_dc %p.\n", device_dc);
12870 tmp = (void *)0xdeadbeef;
12871 hr = IDirectDraw4_GetSurfaceFromDC(ddraw, dc, (IDirectDrawSurface4 **)&tmp);
12872 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
12873 ok(!tmp, "Got unexpected surface %p.\n", tmp);
12875 ok(DeleteDC(dc), "DeleteDC failed.\n");
12877 tmp = (void *)0xdeadbeef;
12878 hr = IDirectDraw4_GetSurfaceFromDC(ddraw, NULL, (IDirectDrawSurface4 **)&tmp);
12879 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
12880 ok(!tmp, "Got unexpected surface %p.\n", tmp);
12882 IDirectDrawSurface4_Release(surface);
12883 IDirectDrawSurface_Release(surface1);
12884 IDirectDraw4_Release(ddraw);
12885 DestroyWindow(window);
12888 START_TEST(ddraw4)
12890 IDirectDraw4 *ddraw;
12891 DEVMODEW current_mode;
12892 HMODULE dwmapi;
12894 if (!(ddraw = create_ddraw()))
12896 skip("Failed to create a ddraw object, skipping tests.\n");
12897 return;
12899 IDirectDraw4_Release(ddraw);
12901 memset(&current_mode, 0, sizeof(current_mode));
12902 current_mode.dmSize = sizeof(current_mode);
12903 ok(EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &current_mode), "Failed to get display mode.\n");
12904 registry_mode.dmSize = sizeof(registry_mode);
12905 ok(EnumDisplaySettingsW(NULL, ENUM_REGISTRY_SETTINGS, &registry_mode), "Failed to get display mode.\n");
12906 if (registry_mode.dmPelsWidth != current_mode.dmPelsWidth
12907 || registry_mode.dmPelsHeight != current_mode.dmPelsHeight)
12909 skip("Current mode does not match registry mode, skipping test.\n");
12910 return;
12913 if ((dwmapi = LoadLibraryA("dwmapi.dll")))
12914 pDwmIsCompositionEnabled = (void *)GetProcAddress(dwmapi, "DwmIsCompositionEnabled");
12916 test_process_vertices();
12917 test_coop_level_create_device_window();
12918 test_clipper_blt();
12919 test_coop_level_d3d_state();
12920 test_surface_interface_mismatch();
12921 test_coop_level_threaded();
12922 test_depth_blit();
12923 test_texture_load_ckey();
12924 test_viewport();
12925 test_zenable();
12926 test_ck_rgba();
12927 test_ck_default();
12928 test_ck_complex();
12929 test_surface_qi();
12930 test_device_qi();
12931 test_wndproc();
12932 test_window_style();
12933 test_redundant_mode_set();
12934 test_coop_level_mode_set();
12935 test_coop_level_mode_set_multi();
12936 test_initialize();
12937 test_coop_level_surf_create();
12938 test_vb_discard();
12939 test_coop_level_multi_window();
12940 test_draw_strided();
12941 test_lighting();
12942 test_specular_lighting();
12943 test_clear_rect_count();
12944 test_coop_level_versions();
12945 test_lighting_interface_versions();
12946 test_coop_level_activateapp();
12947 test_texturemanage();
12948 test_block_formats_creation();
12949 test_unsupported_formats();
12950 test_rt_caps();
12951 test_primary_caps();
12952 test_surface_lock();
12953 test_surface_discard();
12954 test_flip();
12955 test_set_surface_desc();
12956 test_user_memory_getdc();
12957 test_sysmem_overlay();
12958 test_primary_palette();
12959 test_surface_attachment();
12960 test_private_data();
12961 test_pixel_format();
12962 test_create_surface_pitch();
12963 test_mipmap();
12964 test_palette_complex();
12965 test_p8_blit();
12966 test_material();
12967 test_palette_gdi();
12968 test_palette_alpha();
12969 test_vb_writeonly();
12970 test_lost_device();
12971 test_surface_desc_lock();
12972 test_signed_formats();
12973 test_color_fill();
12974 test_texcoordindex();
12975 test_colorkey_precision();
12976 test_range_colorkey();
12977 test_shademode();
12978 test_lockrect_invalid();
12979 test_yv12_overlay();
12980 test_offscreen_overlay();
12981 test_overlay_rect();
12982 test_blt();
12983 test_color_clamping();
12984 test_getdc();
12985 test_draw_primitive();
12986 test_edge_antialiasing_blending();
12987 test_transform_vertices();
12988 test_display_mode_surface_pixel_format();
12989 test_surface_desc_size();
12990 test_get_surface_from_dc();