2 * Unit tests for ddrawex surfaces
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 /* For IID_IDirectDraw3 - it is not in dxguid.dll */
22 #include "wine/test.h"
29 static IDirectDrawFactory
*factory
;
30 static HRESULT (WINAPI
*pDllGetClassObject
)(REFCLSID rclsid
, REFIID riid
, void **out
);
32 static IDirectDraw
*createDD(void)
37 hr
= IDirectDrawFactory_CreateDirectDraw(factory
, NULL
, NULL
, DDSCL_NORMAL
, 0,
39 ok(hr
== DD_OK
, "Failed to create an IDirectDraw interface, hr = 0x%08x\n", hr
);
40 return SUCCEEDED(hr
) ? dd
: NULL
;
43 static void dctest_surf(IDirectDrawSurface
*surf
, int ddsdver
) {
45 HDC dc
, dc2
= (HDC
) 0x1234;
49 memset(&ddsd
, 0, sizeof(ddsd
));
50 ddsd
.dwSize
= sizeof(ddsd
);
51 memset(&ddsd2
, 0, sizeof(ddsd2
));
52 ddsd2
.dwSize
= sizeof(ddsd2
);
54 hr
= IDirectDrawSurface_GetDC(surf
, &dc
);
55 ok(hr
== DD_OK
, "IDirectDrawSurface_GetDC failed: 0x%08x\n", hr
);
57 hr
= IDirectDrawSurface_GetDC(surf
, &dc
);
58 ok(hr
== DDERR_DCALREADYCREATED
, "IDirectDrawSurface_GetDC failed: 0x%08x\n", hr
);
59 ok(dc2
== (HDC
) 0x1234, "The failed GetDC call changed the dc: %p\n", dc2
);
61 hr
= IDirectDrawSurface_Lock(surf
, NULL
, ddsdver
== 1 ? &ddsd
: ((DDSURFACEDESC
*) &ddsd2
), 0, NULL
);
62 ok(hr
== DDERR_SURFACEBUSY
, "IDirectDrawSurface_Lock returned 0x%08x, expected DDERR_SURFACEBUSY\n", hr
);
64 hr
= IDirectDrawSurface_ReleaseDC(surf
, dc
);
65 ok(hr
== DD_OK
, "IDirectDrawSurface_ReleaseDC failed: 0x%08x\n", hr
);
66 hr
= IDirectDrawSurface_ReleaseDC(surf
, dc
);
67 ok(hr
== DDERR_NODC
, "IDirectDrawSurface_ReleaseDC returned 0x%08x, expected DDERR_NODC\n", hr
);
70 static void GetDCTest_main(DDSURFACEDESC
*ddsd
, DDSURFACEDESC2
*ddsd2
, void (*testfunc
)(IDirectDrawSurface
*surf
, int ddsdver
))
72 IDirectDrawSurface
*surf
;
73 IDirectDrawSurface2
*surf2
;
74 IDirectDrawSurface2
*surf3
;
75 IDirectDrawSurface4
*surf4
;
77 IDirectDraw
*dd1
= createDD();
82 hr
= IDirectDraw_CreateSurface(dd1
, ddsd
, &surf
, NULL
);
83 if (hr
== DDERR_UNSUPPORTEDMODE
) {
84 win_skip("Unsupported mode\n");
87 ok(hr
== DD_OK
, "IDirectDraw_CreateSurface failed: 0x%08x\n", hr
);
89 IDirectDrawSurface_Release(surf
);
91 hr
= IDirectDraw_QueryInterface(dd1
, &IID_IDirectDraw2
, (void **) &dd2
);
92 ok(hr
== DD_OK
, "IDirectDraw_QueryInterface failed: 0x%08x\n", hr
);
94 hr
= IDirectDraw2_CreateSurface(dd2
, ddsd
, &surf
, NULL
);
95 ok(hr
== DD_OK
, "IDirectDraw2_CreateSurface failed: 0x%08x\n", hr
);
98 hr
= IDirectDrawSurface_QueryInterface(surf
, &IID_IDirectDrawSurface2
, (void **) &surf2
);
99 ok(hr
== DD_OK
, "IDirectDrawSurface_QueryInterface failed: 0x%08x\n", hr
);
100 testfunc((IDirectDrawSurface
*) surf2
, 1);
102 IDirectDrawSurface2_Release(surf2
);
103 IDirectDrawSurface_Release(surf
);
104 IDirectDraw2_Release(dd2
);
106 hr
= IDirectDraw_QueryInterface(dd1
, &IID_IDirectDraw3
, (void **) &dd3
);
107 ok(hr
== DD_OK
, "IDirectDraw_QueryInterface failed: 0x%08x\n", hr
);
109 hr
= IDirectDraw3_CreateSurface(dd3
, ddsd
, &surf
, NULL
);
110 ok(hr
== DD_OK
, "IDirectDraw3_CreateSurface failed: 0x%08x\n", hr
);
113 hr
= IDirectDrawSurface_QueryInterface(surf
, &IID_IDirectDrawSurface3
, (void **) &surf3
);
114 ok(hr
== DD_OK
, "IDirectDrawSurface_QueryInterface failed: 0x%08x\n", hr
);
115 testfunc((IDirectDrawSurface
*) surf3
, 1);
117 IDirectDrawSurface3_Release(surf3
);
118 IDirectDrawSurface_Release(surf
);
119 IDirectDraw3_Release(dd3
);
121 hr
= IDirectDraw_QueryInterface(dd1
, &IID_IDirectDraw4
, (void **) &dd4
);
122 ok(hr
== DD_OK
, "IDirectDraw_QueryInterface failed: 0x%08x\n", hr
);
125 hr
= IDirectDraw4_CreateSurface(dd4
, ddsd2
, &surf4
, NULL
);
126 ok(hr
== DD_OK
, "IDirectDraw4_CreateSurface failed: 0x%08x\n", hr
);
127 testfunc((IDirectDrawSurface
*) surf4
, 2);
129 IDirectDrawSurface4_Release(surf4
);
130 IDirectDraw4_Release(dd4
);
132 IDirectDraw_Release(dd1
);
135 static void GetDCTest(void)
138 DDSURFACEDESC2 ddsd2
;
140 memset(&ddsd
, 0, sizeof(ddsd
));
141 ddsd
.dwSize
= sizeof(ddsd
);
142 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
145 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
146 memset(&ddsd2
, 0, sizeof(ddsd2
));
147 ddsd2
.dwSize
= sizeof(ddsd2
);
148 ddsd2
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
151 ddsd2
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
153 GetDCTest_main(&ddsd
, &ddsd2
, dctest_surf
);
156 static void CapsTest(void)
159 IDirectDraw
*dd1
= createDD();
160 IDirectDrawSurface
*surf
;
163 memset(&ddsd
, 0, sizeof(ddsd
));
164 ddsd
.dwSize
= sizeof(ddsd
);
165 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
166 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_VIDEOMEMORY
;
169 hr
= IDirectDraw_CreateSurface(dd1
, &ddsd
, &surf
, NULL
);
170 if (hr
== DDERR_UNSUPPORTEDMODE
) {
171 win_skip("Unsupported mode\n");
174 ok(hr
== DD_OK
, "Creating a SYSMEM | VIDMEM surface returned 0x%08x, expected DD_OK\n", hr
);
175 if(surf
) IDirectDrawSurface_Release(surf
);
177 IDirectDraw_Release(dd1
);
180 static void dctest_sysvidmem(IDirectDrawSurface
*surf
, int ddsdver
) {
182 HDC dc
, dc2
= (HDC
) 0x1234;
184 DDSURFACEDESC2 ddsd2
;
186 memset(&ddsd
, 0, sizeof(ddsd
));
187 ddsd
.dwSize
= sizeof(ddsd
);
188 memset(&ddsd2
, 0, sizeof(ddsd2
));
189 ddsd2
.dwSize
= sizeof(ddsd2
);
191 hr
= IDirectDrawSurface_GetDC(surf
, &dc
);
192 ok(hr
== DD_OK
, "IDirectDrawSurface_GetDC failed: 0x%08x\n", hr
);
194 hr
= IDirectDrawSurface_GetDC(surf
, &dc2
);
195 ok(hr
== DD_OK
, "IDirectDrawSurface_GetDC failed: 0x%08x\n", hr
);
196 ok(dc
== dc2
, "Got two different DCs\n");
198 hr
= IDirectDrawSurface_Lock(surf
, NULL
, ddsdver
== 1 ? &ddsd
: ((DDSURFACEDESC
*) &ddsd2
), 0, NULL
);
199 ok(hr
== DD_OK
, "IDirectDrawSurface_Lock returned 0x%08x, expected DD_OK\n", hr
);
201 hr
= IDirectDrawSurface_Lock(surf
, NULL
, ddsdver
== 1 ? &ddsd
: ((DDSURFACEDESC
*) &ddsd2
), 0, NULL
);
202 ok(hr
== DDERR_SURFACEBUSY
, "IDirectDrawSurface_Lock returned 0x%08x, expected DDERR_SURFACEBUSY\n", hr
);
204 hr
= IDirectDrawSurface_Unlock(surf
, NULL
);
205 ok(hr
== DD_OK
, "IDirectDrawSurface_Unlock returned 0x%08x, expected DD_OK\n", hr
);
206 hr
= IDirectDrawSurface_Unlock(surf
, NULL
);
207 ok(hr
== DDERR_NOTLOCKED
, "IDirectDrawSurface_Unlock returned 0x%08x, expected DDERR_NOTLOCKED\n", hr
);
209 hr
= IDirectDrawSurface_ReleaseDC(surf
, dc
);
210 ok(hr
== DD_OK
, "IDirectDrawSurface_ReleaseDC failed: 0x%08x\n", hr
);
211 hr
= IDirectDrawSurface_ReleaseDC(surf
, dc
);
212 ok(hr
== DD_OK
, "IDirectDrawSurface_ReleaseDC failed: 0x%08x\n", hr
);
213 /* That works any number of times... */
214 hr
= IDirectDrawSurface_ReleaseDC(surf
, dc
);
215 ok(hr
== DD_OK
, "IDirectDrawSurface_ReleaseDC failed: 0x%08x\n", hr
);
218 static void SysVidMemTest(void)
221 DDSURFACEDESC2 ddsd2
;
223 memset(&ddsd
, 0, sizeof(ddsd
));
224 ddsd
.dwSize
= sizeof(ddsd
);
225 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
228 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_VIDEOMEMORY
;
229 memset(&ddsd2
, 0, sizeof(ddsd2
));
230 ddsd2
.dwSize
= sizeof(ddsd2
);
231 ddsd2
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
234 ddsd2
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_VIDEOMEMORY
;
236 GetDCTest_main(&ddsd
, &ddsd2
, dctest_sysvidmem
);
239 static void test_surface_from_dc3(void)
241 IDirectDrawSurface3
*surf3
;
242 IDirectDrawSurface
*surf1
;
243 IDirectDrawSurface
*tmp
;
251 hr
= IDirectDraw_QueryInterface(dd1
, &IID_IDirectDraw3
, (void **)&dd3
);
252 ok(SUCCEEDED(hr
), "IDirectDraw_QueryInterface failed, hr %#x.\n", hr
);
253 IDirectDraw_Release(dd1
);
255 memset(&ddsd
, 0, sizeof(ddsd
));
256 ddsd
.dwSize
= sizeof(ddsd
);
257 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
260 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
262 hr
= IDirectDraw3_CreateSurface(dd3
, &ddsd
, &surf1
, NULL
);
263 if (hr
== DDERR_UNSUPPORTEDMODE
) {
264 win_skip("Unsupported mode\n");
265 IDirectDraw3_Release(dd3
);
268 ok(SUCCEEDED(hr
), "CreateSurface failed, hr %#x.\n", hr
);
270 hr
= IDirectDrawSurface3_QueryInterface(surf1
, &IID_IDirectDrawSurface
, (void **)&surf3
);
271 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
272 IDirectDrawSurface_Release(surf1
);
274 hr
= IDirectDrawSurface3_GetDC(surf3
, &dc
);
275 ok(SUCCEEDED(hr
), "GetDC failed, hr %#x.\n", hr
);
277 hr
= IDirectDraw3_GetSurfaceFromDC(dd3
, dc
, NULL
);
278 ok(hr
== E_POINTER
, "Expected E_POINTER, got %#x.\n", hr
);
280 hr
= IDirectDraw3_GetSurfaceFromDC(dd3
, dc
, &tmp
);
281 ok(SUCCEEDED(hr
), "GetSurfaceFromDC failed, hr %#x.\n", hr
);
282 ok((IDirectDrawSurface3
*)tmp
== surf3
, "Expected surface != %p.\n", surf3
);
284 IUnknown_Release(tmp
);
286 hr
= IDirectDrawSurface3_ReleaseDC(surf3
, dc
);
287 ok(SUCCEEDED(hr
), "ReleaseDC failed, hr %#x.\n", hr
);
289 dc
= CreateCompatibleDC(NULL
);
290 ok(!!dc
, "CreateCompatibleDC failed.\n");
292 tmp
= (IDirectDrawSurface
*)0xdeadbeef;
293 hr
= IDirectDraw3_GetSurfaceFromDC(dd3
, dc
, &tmp
);
294 ok(hr
== DDERR_NOTFOUND
, "Expected DDERR_NOTFOUND, got %#x.\n", hr
);
295 ok(!tmp
, "Expected surface NULL, got %p.\n", tmp
);
297 ok(DeleteDC(dc
), "DeleteDC failed.\n");
299 IDirectDrawSurface3_Release(surf3
);
300 IDirectDraw3_Release(dd3
);
303 DEFINE_GUID(guid
, 0x38594b23, 0x2311, 0x4332, 0x95, 0xde, 0x2b, 0x0c, 0x61, 0xbf, 0x7b, 0x84);
305 static void test_surface_from_dc4(void)
307 IDirectDrawSurface4
*surf4
;
308 IDirectDrawSurface
*surf1
;
309 DDSURFACEDESC2 ddsd2
;
310 IUnknown
*tmp
, *tmp2
;
318 hr
= IDirectDraw_QueryInterface(dd1
, &IID_IDirectDraw4
, (void **)&dd4
);
319 if (hr
== E_NOINTERFACE
) {
320 win_skip("DirectDraw4 is not supported\n");
321 IDirectDraw_Release(dd1
);
324 ok(SUCCEEDED(hr
), "IDirectDraw_QueryInterface failed, hr %#x.\n", hr
);
325 IDirectDraw_Release(dd1
);
327 memset(&ddsd2
, 0, sizeof(ddsd2
));
328 ddsd2
.dwSize
= sizeof(ddsd2
);
329 ddsd2
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
332 ddsd2
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
334 hr
= IDirectDraw4_CreateSurface(dd4
, &ddsd2
, &surf4
, NULL
);
335 if (hr
== DDERR_UNSUPPORTEDMODE
) {
336 win_skip("Unsupported mode\n");
337 IDirectDraw3_Release(dd4
);
340 ok(SUCCEEDED(hr
), "CreateSurface failed, hr %#x.\n", hr
);
342 hr
= IDirectDrawSurface4_QueryInterface(surf4
, &IID_IDirectDrawSurface
, (void **)&surf1
);
343 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
347 hr
= IDirectDrawSurface4_SetPrivateData(surf4
, &guid
, &priv
, size
, 0);
348 ok(SUCCEEDED(hr
), "SetPrivateData failed, hr %#x.\n", hr
);
351 hr
= IDirectDrawSurface4_GetPrivateData(surf4
, &guid
, &priv
, &size
);
352 ok(SUCCEEDED(hr
), "GetPrivateData failed, hr %#x.\n", hr
);
353 ok(priv
== 0xdeadbeef, "Expected private data 0xdeadbeef, got %#x.\n", priv
);
355 hr
= IDirectDrawSurface4_GetDC(surf4
, &dc
);
356 ok(SUCCEEDED(hr
), "GetDC failed, hr %#x.\n", hr
);
358 hr
= IDirectDraw4_GetSurfaceFromDC(dd4
, dc
, NULL
);
359 ok(hr
== E_INVALIDARG
, "Expected E_INVALIDARG, got %#x.\n", hr
);
361 hr
= IDirectDraw4_GetSurfaceFromDC(dd4
, dc
, (IDirectDrawSurface4
**)&tmp
);
362 ok(SUCCEEDED(hr
), "GetSurfaceFromDC failed, hr %#x.\n", hr
);
363 ok((IDirectDrawSurface4
*)tmp
!= surf4
, "Expected surface != %p.\n", surf4
);
365 hr
= IUnknown_QueryInterface(tmp
, &IID_IDirectDrawSurface
, (void **)&tmp2
);
366 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
367 ok(tmp2
== tmp
, "Expected %p, got %p.\n", tmp
, tmp2
);
368 ok((IDirectDrawSurface
*)tmp2
!= surf1
, "Expected surface != %p.\n", surf1
);
369 IUnknown_Release(tmp2
);
371 hr
= IUnknown_QueryInterface(tmp
, &IID_IDirectDrawSurface4
, (void **)&tmp2
);
372 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
373 ok((IDirectDrawSurface4
*)tmp2
!= surf4
, "Expected surface != %p.\n", surf4
);
376 hr
= IDirectDrawSurface4_GetPrivateData((IDirectDrawSurface4
*)tmp2
, &guid
, &priv
, &size
);
377 ok(SUCCEEDED(hr
), "GetPrivateData failed, hr %#x.\n", hr
);
378 ok(priv
== 0xdeadbeef, "Expected private data 0xdeadbeef, got %#x.\n", priv
);
379 IUnknown_Release(tmp2
);
381 IUnknown_Release(tmp
);
383 hr
= IDirectDrawSurface4_ReleaseDC(surf4
, dc
);
384 ok(SUCCEEDED(hr
), "ReleaseDC failed, hr %#x.\n", hr
);
386 dc
= CreateCompatibleDC(NULL
);
387 ok(!!dc
, "CreateCompatibleDC failed.\n");
389 tmp
= (IUnknown
*)0xdeadbeef;
390 hr
= IDirectDraw4_GetSurfaceFromDC(dd4
, dc
, (IDirectDrawSurface4
**)&tmp
);
391 ok(hr
== DDERR_NOTFOUND
, "Expected DDERR_NOTFOUND, got %#x.\n", hr
);
392 ok(!tmp
, "Expected surface NULL, got %p.\n", tmp
);
394 ok(DeleteDC(dc
), "DeleteDC failed.\n");
396 tmp
= (IUnknown
*)0xdeadbeef;
397 hr
= IDirectDraw4_GetSurfaceFromDC(dd4
, NULL
, (IDirectDrawSurface4
**)&tmp
);
398 ok(hr
== DDERR_NOTFOUND
, "Expected DDERR_NOTFOUND, got %#x.\n", hr
);
399 ok(!tmp
, "Expected surface NULL, got %p.\n", tmp
);
401 IDirectDrawSurface_Release(surf1
);
402 IDirectDrawSurface4_Release(surf4
);
403 IDirectDraw4_Release(dd4
);
408 IClassFactory
*classfactory
= NULL
;
411 HMODULE hmod
= LoadLibraryA("ddrawex.dll");
413 skip("Failed to load ddrawex.dll\n");
416 pDllGetClassObject
= (void*)GetProcAddress(hmod
, "DllGetClassObject");
417 if(pDllGetClassObject
== NULL
) {
418 skip("Failed to get DllGetClassObject\n");
422 hr
= pDllGetClassObject(&CLSID_DirectDrawFactory
, &IID_IClassFactory
, (void **) &classfactory
);
423 ok(hr
== S_OK
, "Failed to create a IClassFactory\n");
425 skip("Failed to get DirectDrawFactory\n");
428 hr
= IClassFactory_CreateInstance(classfactory
, NULL
, &IID_IDirectDrawFactory
, (void **) &factory
);
429 ok(hr
== S_OK
, "Failed to create a IDirectDrawFactory\n");
431 IClassFactory_Release(classfactory
);
432 skip("Failed to get a DirectDrawFactory\n");
439 test_surface_from_dc3();
440 test_surface_from_dc4();
442 ref
= IDirectDrawFactory_Release(factory
);
443 ok(ref
== 0, "IDirectDrawFactory not cleanly released\n");
444 ref
= IClassFactory_Release(classfactory
);
445 todo_wine
ok(ref
== 1, "IClassFactory refcount wrong, ref = %u\n", ref
);