2 * Unit tests for (a few) ddraw surface functions
4 * Copyright (C) 2005 Antoine Chavasse (a.chavasse@gmail.com)
5 * Copyright (C) 2005 Christian Costa
6 * Copyright 2005 Ivan Leo Puoti
7 * Copyright (C) 2007 Stefan Dösinger
8 * Copyright (C) 2008 Alexander Dorofeyev
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "wine/test.h"
28 #include "wine/exception.h"
33 static LPDIRECTDRAW lpDD
= NULL
;
36 static BOOL
CreateDirectDraw(void)
40 rc
= DirectDrawCreate(NULL
, &lpDD
, NULL
);
41 ok(rc
==DD_OK
|| rc
==DDERR_NODIRECTDRAWSUPPORT
, "DirectDrawCreateEx returned: %x\n", rc
);
43 trace("DirectDrawCreateEx() failed with an error %x\n", rc
);
47 rc
= IDirectDraw_SetCooperativeLevel(lpDD
, NULL
, DDSCL_NORMAL
);
48 ok(rc
==DD_OK
,"SetCooperativeLevel returned: %x\n",rc
);
54 static void ReleaseDirectDraw(void)
58 IDirectDraw_Release(lpDD
);
63 static void MipMapCreationTest(void)
65 LPDIRECTDRAWSURFACE lpDDSMipMapTest
;
69 /* First mipmap creation test: create a surface with DDSCAPS_COMPLEX,
70 DDSCAPS_MIPMAP, and DDSD_MIPMAPCOUNT. This create the number of
71 requested mipmap levels. */
72 ddsd
.dwSize
= sizeof(ddsd
);
73 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_MIPMAPCOUNT
;
74 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
75 U2(ddsd
).dwMipMapCount
= 3;
78 rc
= IDirectDraw_CreateSurface(lpDD
, &ddsd
, &lpDDSMipMapTest
, NULL
);
79 ok(rc
==DD_OK
,"CreateSurface returned: %x\n",rc
);
82 skip("failed to create surface\n");
86 /* Check the number of created mipmaps */
87 memset(&ddsd
, 0, sizeof(DDSURFACEDESC
));
88 ddsd
.dwSize
= sizeof(ddsd
);
89 rc
= IDirectDrawSurface_GetSurfaceDesc(lpDDSMipMapTest
, &ddsd
);
90 ok(rc
==DD_OK
,"GetSurfaceDesc returned: %x\n",rc
);
91 ok(ddsd
.dwFlags
& DDSD_MIPMAPCOUNT
,
92 "GetSurfaceDesc returned no mipmapcount.\n");
93 ok(U2(ddsd
).dwMipMapCount
== 3, "Incorrect mipmap count: %d.\n",
94 U2(ddsd
).dwMipMapCount
);
96 /* Destroy the surface. */
97 IDirectDrawSurface_Release(lpDDSMipMapTest
);
100 /* Second mipmap creation test: create a surface without a mipmap
101 count, with DDSCAPS_MIPMAP and without DDSCAPS_COMPLEX.
102 This creates a single mipmap level. */
103 memset(&ddsd
, 0, sizeof(DDSURFACEDESC
));
104 ddsd
.dwSize
= sizeof(ddsd
);
105 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
106 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
;
109 rc
= IDirectDraw_CreateSurface(lpDD
, &ddsd
, &lpDDSMipMapTest
, NULL
);
110 ok(rc
==DD_OK
,"CreateSurface returned: %x\n",rc
);
113 skip("failed to create surface\n");
116 /* Check the number of created mipmaps */
117 memset(&ddsd
, 0, sizeof(DDSURFACEDESC
));
118 ddsd
.dwSize
= sizeof(ddsd
);
119 rc
= IDirectDrawSurface_GetSurfaceDesc(lpDDSMipMapTest
, &ddsd
);
120 ok(rc
==DD_OK
,"GetSurfaceDesc returned: %x\n",rc
);
121 ok(ddsd
.dwFlags
& DDSD_MIPMAPCOUNT
,
122 "GetSurfaceDesc returned no mipmapcount.\n");
123 ok(U2(ddsd
).dwMipMapCount
== 1, "Incorrect mipmap count: %d.\n",
124 U2(ddsd
).dwMipMapCount
);
126 /* Destroy the surface. */
127 IDirectDrawSurface_Release(lpDDSMipMapTest
);
130 /* Third mipmap creation test: create a surface with DDSCAPS_MIPMAP,
131 DDSCAPS_COMPLEX and without DDSD_MIPMAPCOUNT.
132 It's an undocumented features where a chain of mipmaps, starting from
133 he specified size and down to the smallest size, is automatically
135 Anarchy Online needs this feature to work. */
136 memset(&ddsd
, 0, sizeof(DDSURFACEDESC
));
137 ddsd
.dwSize
= sizeof(ddsd
);
138 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
139 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
142 rc
= IDirectDraw_CreateSurface(lpDD
, &ddsd
, &lpDDSMipMapTest
, NULL
);
143 ok(rc
==DD_OK
,"CreateSurface returned: %x\n",rc
);
146 skip("failed to create surface\n");
150 /* Check the number of created mipmaps */
151 memset(&ddsd
, 0, sizeof(DDSURFACEDESC
));
152 ddsd
.dwSize
= sizeof(ddsd
);
153 rc
= IDirectDrawSurface_GetSurfaceDesc(lpDDSMipMapTest
, &ddsd
);
154 ok(rc
==DD_OK
,"GetSurfaceDesc returned: %x\n",rc
);
155 ok(ddsd
.dwFlags
& DDSD_MIPMAPCOUNT
,
156 "GetSurfaceDesc returned no mipmapcount.\n");
157 ok(U2(ddsd
).dwMipMapCount
== 6, "Incorrect mipmap count: %d.\n",
158 U2(ddsd
).dwMipMapCount
);
160 /* Destroy the surface. */
161 IDirectDrawSurface_Release(lpDDSMipMapTest
);
164 /* Fourth mipmap creation test: same as above with a different texture
166 The purpose is to verify that the number of generated mipmaps is
167 dependent on the smallest dimension. */
168 memset(&ddsd
, 0, sizeof(DDSURFACEDESC
));
169 ddsd
.dwSize
= sizeof(ddsd
);
170 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
171 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
174 rc
= IDirectDraw_CreateSurface(lpDD
, &ddsd
, &lpDDSMipMapTest
, NULL
);
175 ok(rc
==DD_OK
,"CreateSurface returned: %x\n",rc
);
178 skip("failed to create surface\n");
182 /* Check the number of created mipmaps */
183 memset(&ddsd
, 0, sizeof(DDSURFACEDESC
));
184 ddsd
.dwSize
= sizeof(ddsd
);
185 rc
= IDirectDrawSurface_GetSurfaceDesc(lpDDSMipMapTest
, &ddsd
);
186 ok(rc
==DD_OK
,"GetSurfaceDesc returned: %x\n",rc
);
187 ok(ddsd
.dwFlags
& DDSD_MIPMAPCOUNT
,
188 "GetSurfaceDesc returned no mipmapcount.\n");
189 ok(U2(ddsd
).dwMipMapCount
== 6, "Incorrect mipmap count: %d.\n",
190 U2(ddsd
).dwMipMapCount
);
192 /* Destroy the surface. */
193 IDirectDrawSurface_Release(lpDDSMipMapTest
);
196 /* Fifth mipmap creation test: try to create a surface with
197 DDSCAPS_COMPLEX, DDSCAPS_MIPMAP, DDSD_MIPMAPCOUNT,
198 where dwMipMapCount = 0. This should fail. */
200 ddsd
.dwSize
= sizeof(ddsd
);
201 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_MIPMAPCOUNT
;
202 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
203 U2(ddsd
).dwMipMapCount
= 0;
206 rc
= IDirectDraw_CreateSurface(lpDD
, &ddsd
, &lpDDSMipMapTest
, NULL
);
207 ok(rc
==DDERR_INVALIDPARAMS
,"CreateSurface returned: %x\n",rc
);
209 /* Destroy the surface. */
211 IDirectDrawSurface_Release(lpDDSMipMapTest
);
215 static void SrcColorKey32BlitTest(void)
217 LPDIRECTDRAWSURFACE lpSrc
;
218 LPDIRECTDRAWSURFACE lpDst
;
219 DDSURFACEDESC ddsd
, ddsd2
, ddsd3
;
220 DDCOLORKEY DDColorKey
;
225 ddsd2
.dwSize
= sizeof(ddsd2
);
226 ddsd2
.ddpfPixelFormat
.dwSize
= sizeof(ddsd2
.ddpfPixelFormat
);
228 ddsd
.dwSize
= sizeof(ddsd
);
229 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
230 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
231 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
234 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
235 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
236 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0xFF0000;
237 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x00FF00;
238 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x0000FF;
239 rc
= IDirectDraw_CreateSurface(lpDD
, &ddsd
, &lpDst
, NULL
);
240 ok(rc
==DD_OK
,"CreateSurface returned: %x\n",rc
);
243 skip("failed to create surface\n");
247 ddsd
.dwFlags
|= DDSD_CKSRCBLT
;
248 ddsd
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0xFF00FF;
249 ddsd
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0xFF00FF;
250 rc
= IDirectDraw_CreateSurface(lpDD
, &ddsd
, &lpSrc
, NULL
);
251 ok(rc
==DD_OK
,"CreateSurface returned: %x\n",rc
);
254 skip("failed to create surface\n");
258 rc
= IDirectDrawSurface_Lock(lpDst
, NULL
, &ddsd2
, DDLOCK_WAIT
, NULL
);
259 ok(rc
==DD_OK
,"Lock returned: %x\n",rc
);
260 lpData
= ddsd2
.lpSurface
;
261 lpData
[0] = 0xCCCCCCCC;
262 lpData
[1] = 0xCCCCCCCC;
263 lpData
[2] = 0xCCCCCCCC;
264 lpData
[3] = 0xCCCCCCCC;
266 memset(&ddsd3
, 0, sizeof(ddsd3
));
267 ddsd3
.dwSize
= sizeof(ddsd3
);
268 ddsd3
.ddpfPixelFormat
.dwSize
= sizeof(ddsd3
.ddpfPixelFormat
);
269 rc
= IDirectDrawSurface_GetSurfaceDesc(lpDst
, &ddsd3
);
270 ok(rc
== DD_OK
, "IDirectDrawSurface_GetSurfaceDesc between a lock/unlock pair returned %08x\n", rc
);
271 ok(ddsd3
.lpSurface
== ddsd3
.lpSurface
, "lpSurface from GetSurfaceDesc(%p) differs from the one returned by Lock(%p)\n", ddsd3
.lpSurface
, ddsd2
.lpSurface
);
273 rc
= IDirectDrawSurface_Unlock(lpDst
, NULL
);
274 ok(rc
==DD_OK
,"Unlock returned: %x\n",rc
);
276 memset(&ddsd3
, 0, sizeof(ddsd3
));
277 ddsd3
.dwSize
= sizeof(ddsd3
);
278 ddsd3
.ddpfPixelFormat
.dwSize
= sizeof(ddsd3
.ddpfPixelFormat
);
279 rc
= IDirectDrawSurface_GetSurfaceDesc(lpDst
, &ddsd3
);
280 ok(rc
== DD_OK
, "IDirectDrawSurface_GetSurfaceDesc between a lock/unlock pair returned %08x\n", rc
);
281 ok(ddsd3
.lpSurface
== NULL
, "lpSurface from GetSurfaceDesc(%p) is not NULL after unlock\n", ddsd3
.lpSurface
);
283 rc
= IDirectDrawSurface_Lock(lpSrc
, NULL
, &ddsd2
, DDLOCK_WAIT
, NULL
);
284 ok(rc
==DD_OK
,"Lock returned: %x\n",rc
);
285 ok((ddsd2
.dwFlags
& DDSD_LPSURFACE
) == 0, "Surface desc has LPSURFACE Flags set\n");
286 lpData
= ddsd2
.lpSurface
;
287 lpData
[0] = 0x77010203;
288 lpData
[1] = 0x00010203;
289 lpData
[2] = 0x77FF00FF;
290 lpData
[3] = 0x00FF00FF;
291 rc
= IDirectDrawSurface_Unlock(lpSrc
, NULL
);
292 ok(rc
==DD_OK
,"Unlock returned: %x\n",rc
);
294 IDirectDrawSurface_Blt(lpDst
, NULL
, lpSrc
, NULL
, DDBLT_KEYSRC
, NULL
);
296 rc
= IDirectDrawSurface_Lock(lpDst
, NULL
, &ddsd2
, DDLOCK_WAIT
, NULL
);
297 ok(rc
==DD_OK
,"Lock returned: %x\n",rc
);
298 ok((ddsd2
.dwFlags
& DDSD_LPSURFACE
) == 0, "Surface desc has LPSURFACE Flags set\n");
299 lpData
= ddsd2
.lpSurface
;
300 /* Different behavior on some drivers / windows versions. Some versions ignore the X channel when
301 * color keying, but copy it to the destination surface. Others apply it for color keying, but
302 * do not copy it into the destination surface.
304 if(lpData
[0]==0x00010203) {
305 trace("X channel was not copied into the destination surface\n");
306 ok((lpData
[0]==0x00010203)&&(lpData
[1]==0x00010203)&&(lpData
[2]==0x00FF00FF)&&(lpData
[3]==0xCCCCCCCC),
307 "Destination data after blitting is not correct\n");
309 ok((lpData
[0]==0x77010203)&&(lpData
[1]==0x00010203)&&(lpData
[2]==0xCCCCCCCC)&&(lpData
[3]==0xCCCCCCCC),
310 "Destination data after blitting is not correct\n");
312 rc
= IDirectDrawSurface_Unlock(lpDst
, NULL
);
313 ok(rc
==DD_OK
,"Unlock returned: %x\n",rc
);
315 /* Below we repeat the same test as above but now using BltFast instead of Blt. Before
316 * we can carry out the test we need to restore the color of the destination surface.
318 rc
= IDirectDrawSurface_Lock(lpDst
, NULL
, &ddsd2
, DDLOCK_WAIT
, NULL
);
319 ok(rc
==DD_OK
,"Lock returned: %x\n",rc
);
320 lpData
= ddsd2
.lpSurface
;
321 lpData
[0] = 0xCCCCCCCC;
322 lpData
[1] = 0xCCCCCCCC;
323 lpData
[2] = 0xCCCCCCCC;
324 lpData
[3] = 0xCCCCCCCC;
325 rc
= IDirectDrawSurface_Unlock(lpDst
, NULL
);
326 ok(rc
==DD_OK
,"Unlock returned: %x\n",rc
);
328 IDirectDrawSurface_BltFast(lpDst
, 0, 0, lpSrc
, NULL
, DDBLTFAST_SRCCOLORKEY
);
330 rc
= IDirectDrawSurface_Lock(lpDst
, NULL
, &ddsd2
, DDLOCK_WAIT
, NULL
);
331 ok(rc
==DD_OK
,"Lock returned: %x\n",rc
);
332 ok((ddsd2
.dwFlags
& DDSD_LPSURFACE
) == 0, "Surface desc has LPSURFACE Flags set\n");
333 lpData
= ddsd2
.lpSurface
;
334 /* Different behavior on some drivers / windows versions. Some versions ignore the X channel when
335 * color keying, but copy it to the destination surface. Others apply it for color keying, but
336 * do not copy it into the destination surface.
338 if(lpData
[0]==0x00010203) {
339 trace("X channel was not copied into the destination surface\n");
340 ok((lpData
[0]==0x00010203)&&(lpData
[1]==0x00010203)&&(lpData
[2]==0x00FF00FF)&&(lpData
[3]==0xCCCCCCCC),
341 "Destination data after blitting is not correct\n");
343 ok((lpData
[0]==0x77010203)&&(lpData
[1]==0x00010203)&&(lpData
[2]==0xCCCCCCCC)&&(lpData
[3]==0xCCCCCCCC),
344 "Destination data after blitting is not correct\n");
346 rc
= IDirectDrawSurface_Unlock(lpDst
, NULL
);
347 ok(rc
==DD_OK
,"Unlock returned: %x\n",rc
);
349 /* Also test SetColorKey */
350 IDirectDrawSurface_GetColorKey(lpSrc
, DDCKEY_SRCBLT
, &DDColorKey
);
351 ok(DDColorKey
.dwColorSpaceLowValue
== 0xFF00FF && DDColorKey
.dwColorSpaceHighValue
== 0xFF00FF,
352 "GetColorKey does not return the colorkey used at surface creation\n");
354 DDColorKey
.dwColorSpaceLowValue
= 0x00FF00;
355 DDColorKey
.dwColorSpaceHighValue
= 0x00FF00;
356 IDirectDrawSurface_SetColorKey(lpSrc
, DDCKEY_SRCBLT
, &DDColorKey
);
358 DDColorKey
.dwColorSpaceLowValue
= 0;
359 DDColorKey
.dwColorSpaceHighValue
= 0;
360 IDirectDrawSurface_GetColorKey(lpSrc
, DDCKEY_SRCBLT
, &DDColorKey
);
361 ok(DDColorKey
.dwColorSpaceLowValue
== 0x00FF00 && DDColorKey
.dwColorSpaceHighValue
== 0x00FF00,
362 "GetColorKey does not return the colorkey set with SetColorKey\n");
364 ddsd
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0;
365 ddsd
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0;
366 IDirectDrawSurface_GetSurfaceDesc(lpSrc
, &ddsd
);
367 ok(ddsd
.ddckCKSrcBlt
.dwColorSpaceLowValue
== 0x00FF00 && ddsd
.ddckCKSrcBlt
.dwColorSpaceHighValue
== 0x00FF00,
368 "GetSurfaceDesc does not return the colorkey set with SetColorKey\n");
370 /* Test SetColorKey with dwColorSpaceHighValue < dwColorSpaceLowValue */
371 DDColorKey
.dwColorSpaceLowValue
= 0x0000FF;
372 DDColorKey
.dwColorSpaceHighValue
= 0x000000;
373 IDirectDrawSurface_SetColorKey(lpSrc
, DDCKEY_SRCBLT
, &DDColorKey
);
375 DDColorKey
.dwColorSpaceLowValue
= 0;
376 DDColorKey
.dwColorSpaceHighValue
= 0;
377 IDirectDrawSurface_GetColorKey(lpSrc
, DDCKEY_SRCBLT
, &DDColorKey
);
378 ok(DDColorKey
.dwColorSpaceLowValue
== 0x0000FF && DDColorKey
.dwColorSpaceHighValue
== 0x0000FF,
379 "GetColorKey does not return the colorkey set with SetColorKey (%x %x)\n", DDColorKey
.dwColorSpaceLowValue
, DDColorKey
.dwColorSpaceHighValue
);
381 DDColorKey
.dwColorSpaceLowValue
= 0x0000FF;
382 DDColorKey
.dwColorSpaceHighValue
= 0x000001;
383 IDirectDrawSurface_SetColorKey(lpSrc
, DDCKEY_SRCBLT
, &DDColorKey
);
385 DDColorKey
.dwColorSpaceLowValue
= 0;
386 DDColorKey
.dwColorSpaceHighValue
= 0;
387 IDirectDrawSurface_GetColorKey(lpSrc
, DDCKEY_SRCBLT
, &DDColorKey
);
388 ok(DDColorKey
.dwColorSpaceLowValue
== 0x0000FF && DDColorKey
.dwColorSpaceHighValue
== 0x0000FF,
389 "GetColorKey does not return the colorkey set with SetColorKey (%x %x)\n", DDColorKey
.dwColorSpaceLowValue
, DDColorKey
.dwColorSpaceHighValue
);
391 DDColorKey
.dwColorSpaceLowValue
= 0x0000FF;
392 DDColorKey
.dwColorSpaceHighValue
= 0x0000FE;
393 IDirectDrawSurface_SetColorKey(lpSrc
, DDCKEY_SRCBLT
, &DDColorKey
);
395 DDColorKey
.dwColorSpaceLowValue
= 0;
396 DDColorKey
.dwColorSpaceHighValue
= 0;
397 IDirectDrawSurface_GetColorKey(lpSrc
, DDCKEY_SRCBLT
, &DDColorKey
);
398 ok(DDColorKey
.dwColorSpaceLowValue
== 0x0000FF && DDColorKey
.dwColorSpaceHighValue
== 0x0000FF,
399 "GetColorKey does not return the colorkey set with SetColorKey (%x %x)\n", DDColorKey
.dwColorSpaceLowValue
, DDColorKey
.dwColorSpaceHighValue
);
401 IDirectDrawSurface_Release(lpSrc
);
402 IDirectDrawSurface_Release(lpDst
);
404 /* start with a new set of surfaces to test the color keying parameters to blit */
405 memset(&ddsd
, 0, sizeof(ddsd
));
406 ddsd
.dwSize
= sizeof(ddsd
);
407 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
408 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CKSRCBLT
| DDSD_CKDESTBLT
;
409 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
412 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
413 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
414 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0xFF0000;
415 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x00FF00;
416 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x0000FF;
417 ddsd
.ddckCKDestBlt
.dwColorSpaceLowValue
= 0xFF0000;
418 ddsd
.ddckCKDestBlt
.dwColorSpaceHighValue
= 0xFF0000;
419 ddsd
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00FF00;
420 ddsd
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00FF00;
421 rc
= IDirectDraw_CreateSurface(lpDD
, &ddsd
, &lpDst
, NULL
);
422 ok(rc
==DD_OK
|| rc
== DDERR_NOCOLORKEYHW
,"CreateSurface returned: %x\n",rc
);
425 skip("Failed to create surface\n");
429 /* start with a new set of surfaces to test the color keying parameters to blit */
430 memset(&ddsd
, 0, sizeof(ddsd
));
431 ddsd
.dwSize
= sizeof(ddsd
);
432 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
433 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CKSRCBLT
| DDSD_CKDESTBLT
;
434 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
437 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
438 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
439 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0xFF0000;
440 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x00FF00;
441 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x0000FF;
442 ddsd
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x0000FF;
443 ddsd
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x0000FF;
444 ddsd
.ddckCKDestBlt
.dwColorSpaceLowValue
= 0x000000;
445 ddsd
.ddckCKDestBlt
.dwColorSpaceHighValue
= 0x000000;
446 rc
= IDirectDraw_CreateSurface(lpDD
, &ddsd
, &lpSrc
, NULL
);
447 ok(rc
==DD_OK
|| rc
== DDERR_NOCOLORKEYHW
,"CreateSurface returned: %x\n",rc
);
450 skip("Failed to create surface\n");
451 IDirectDrawSurface_Release(lpDst
);
455 memset(&fx
, 0, sizeof(fx
));
456 fx
.dwSize
= sizeof(fx
);
457 fx
.ddckSrcColorkey
.dwColorSpaceHighValue
= 0x110000;
458 fx
.ddckSrcColorkey
.dwColorSpaceLowValue
= 0x110000;
459 fx
.ddckDestColorkey
.dwColorSpaceHighValue
= 0x001100;
460 fx
.ddckDestColorkey
.dwColorSpaceLowValue
= 0x001100;
462 rc
= IDirectDrawSurface_Lock(lpSrc
, NULL
, &ddsd2
, DDLOCK_WAIT
, NULL
);
463 ok(rc
==DD_OK
,"Lock returned: %x\n",rc
);
464 ok((ddsd2
.dwFlags
& DDSD_LPSURFACE
) == 0, "Surface desc has LPSURFACE Flags set\n");
465 lpData
= ddsd2
.lpSurface
;
466 lpData
[0] = 0x000000FF; /* Applies to src blt key in src surface */
467 lpData
[1] = 0x00000000; /* Applies to dst blt key in src surface */
468 lpData
[2] = 0x00FF0000; /* Dst color key in dst surface */
469 lpData
[3] = 0x0000FF00; /* Src color key in dst surface */
470 lpData
[4] = 0x00001100; /* Src color key in ddbltfx */
471 lpData
[5] = 0x00110000; /* Dst color key in ddbltfx */
472 rc
= IDirectDrawSurface_Unlock(lpSrc
, NULL
);
473 ok(rc
==DD_OK
,"Unlock returned: %x\n",rc
);
475 rc
= IDirectDrawSurface_Lock(lpDst
, NULL
, &ddsd2
, DDLOCK_WAIT
, NULL
);
476 ok(rc
==DD_OK
,"Lock returned: %x\n",rc
);
477 ok((ddsd2
.dwFlags
& DDSD_LPSURFACE
) == 0, "Surface desc has LPSURFACE Flags set\n");
478 lpData
= ddsd2
.lpSurface
;
479 lpData
[0] = 0x55555555;
480 lpData
[1] = 0x55555555;
481 lpData
[2] = 0x55555555;
482 lpData
[3] = 0x55555555;
483 lpData
[4] = 0x55555555;
484 lpData
[5] = 0x55555555;
485 rc
= IDirectDrawSurface_Unlock(lpDst
, NULL
);
486 ok(rc
==DD_OK
,"Unlock returned: %x\n",rc
);
488 /* Test a blit without keying */
489 rc
= IDirectDrawSurface_Blt(lpDst
, NULL
, lpSrc
, NULL
, 0, &fx
);
490 ok(rc
== DD_OK
, "IDirectDrawSurface_Blt returned %08x\n", rc
);
492 rc
= IDirectDrawSurface_Lock(lpDst
, NULL
, &ddsd2
, DDLOCK_WAIT
, NULL
);
493 ok(rc
==DD_OK
,"Lock returned: %x\n",rc
);
494 ok((ddsd2
.dwFlags
& DDSD_LPSURFACE
) == 0, "Surface desc has LPSURFACE Flags set\n");
495 lpData
= ddsd2
.lpSurface
;
496 /* Should have copied src data unmodified to dst */
497 ok(lpData
[0] == 0x000000FF &&
498 lpData
[1] == 0x00000000 &&
499 lpData
[2] == 0x00FF0000 &&
500 lpData
[3] == 0x0000FF00 &&
501 lpData
[4] == 0x00001100 &&
502 lpData
[5] == 0x00110000, "Surface data after unkeyed blit does not match\n");
504 lpData
[0] = 0x55555555;
505 lpData
[1] = 0x55555555;
506 lpData
[2] = 0x55555555;
507 lpData
[3] = 0x55555555;
508 lpData
[4] = 0x55555555;
509 lpData
[5] = 0x55555555;
510 rc
= IDirectDrawSurface_Unlock(lpDst
, NULL
);
511 ok(rc
==DD_OK
,"Unlock returned: %x\n",rc
);
514 rc
= IDirectDrawSurface_Blt(lpDst
, NULL
, lpSrc
, NULL
, DDBLT_KEYSRC
, &fx
);
515 ok(rc
== DD_OK
, "IDirectDrawSurface_Blt returned %08x\n", rc
);
517 rc
= IDirectDrawSurface_Lock(lpDst
, NULL
, &ddsd2
, DDLOCK_WAIT
, NULL
);
518 ok(rc
==DD_OK
,"Lock returned: %x\n",rc
);
519 ok((ddsd2
.dwFlags
& DDSD_LPSURFACE
) == 0, "Surface desc has LPSURFACE Flags set\n");
520 lpData
= ddsd2
.lpSurface
;
522 ok(lpData
[0] == 0x55555555 && /* Here the src key applied */
523 lpData
[1] == 0x00000000 &&
524 lpData
[2] == 0x00FF0000 &&
525 lpData
[3] == 0x0000FF00 &&
526 lpData
[4] == 0x00001100 &&
527 lpData
[5] == 0x00110000, "Surface data after srckey blit does not match\n");
529 lpData
[0] = 0x55555555;
530 lpData
[1] = 0x55555555;
531 lpData
[2] = 0x55555555;
532 lpData
[3] = 0x55555555;
533 lpData
[4] = 0x55555555;
534 lpData
[5] = 0x55555555;
535 rc
= IDirectDrawSurface_Unlock(lpDst
, NULL
);
536 ok(rc
==DD_OK
,"Unlock returned: %x\n",rc
);
539 rc
= IDirectDrawSurface_Blt(lpDst
, NULL
, lpSrc
, NULL
, DDBLT_KEYSRCOVERRIDE
, &fx
);
540 ok(rc
== DD_OK
, "IDirectDrawSurface_Blt returned %08x\n", rc
);
542 rc
= IDirectDrawSurface_Lock(lpDst
, NULL
, &ddsd2
, DDLOCK_WAIT
, NULL
);
543 ok(rc
==DD_OK
,"Lock returned: %x\n",rc
);
544 ok((ddsd2
.dwFlags
& DDSD_LPSURFACE
) == 0, "Surface desc has LPSURFACE Flags set\n");
545 lpData
= ddsd2
.lpSurface
;
547 ok(lpData
[0] == 0x000000FF &&
548 lpData
[1] == 0x00000000 &&
549 lpData
[2] == 0x00FF0000 &&
550 lpData
[3] == 0x0000FF00 &&
551 lpData
[4] == 0x00001100 &&
552 lpData
[5] == 0x55555555, /* Override key applies here */
553 "Surface data after src override key blit does not match\n");
555 lpData
[0] = 0x55555555;
556 lpData
[1] = 0x55555555;
557 lpData
[2] = 0x55555555;
558 lpData
[3] = 0x55555555;
559 lpData
[4] = 0x55555555;
560 lpData
[5] = 0x55555555;
561 rc
= IDirectDrawSurface_Unlock(lpDst
, NULL
);
562 ok(rc
==DD_OK
,"Unlock returned: %x\n",rc
);
564 /* Src override AND src key. That is not supposed to work */
565 rc
= IDirectDrawSurface_Blt(lpDst
, NULL
, lpSrc
, NULL
, DDBLT_KEYSRC
| DDBLT_KEYSRCOVERRIDE
, &fx
);
566 ok(rc
== DDERR_INVALIDPARAMS
, "IDirectDrawSurface_Blt returned %08x\n", rc
);
568 /* Verify that the destination is unchanged */
569 rc
= IDirectDrawSurface_Lock(lpDst
, NULL
, &ddsd2
, DDLOCK_WAIT
, NULL
);
570 ok(rc
==DD_OK
,"Lock returned: %x\n",rc
);
571 ok((ddsd2
.dwFlags
& DDSD_LPSURFACE
) == 0, "Surface desc has LPSURFACE Flags set\n");
572 lpData
= ddsd2
.lpSurface
;
574 ok(lpData
[0] == 0x55555555 &&
575 lpData
[1] == 0x55555555 &&
576 lpData
[2] == 0x55555555 &&
577 lpData
[3] == 0x55555555 &&
578 lpData
[4] == 0x55555555 &&
579 lpData
[5] == 0x55555555, /* Override key applies here */
580 "Surface data after src key blit with override does not match\n");
582 lpData
[0] = 0x00FF0000; /* Dest key in dst surface */
583 lpData
[1] = 0x00FF0000; /* Dest key in dst surface */
584 lpData
[2] = 0x00001100; /* Dest key in override */
585 lpData
[3] = 0x00001100; /* Dest key in override */
586 lpData
[4] = 0x00000000; /* Dest key in src surface */
587 lpData
[5] = 0x00000000; /* Dest key in src surface */
588 rc
= IDirectDrawSurface_Unlock(lpDst
, NULL
);
589 ok(rc
==DD_OK
,"Unlock returned: %x\n",rc
);
592 rc
= IDirectDrawSurface_Blt(lpDst
, NULL
, lpSrc
, NULL
, DDBLT_KEYDEST
, &fx
);
593 ok(rc
== DD_OK
, "IDirectDrawSurface_Blt returned %08x\n", rc
);
595 rc
= IDirectDrawSurface_Lock(lpDst
, NULL
, &ddsd2
, DDLOCK_WAIT
, NULL
);
596 ok(rc
==DD_OK
,"Lock returned: %x\n",rc
);
597 ok((ddsd2
.dwFlags
& DDSD_LPSURFACE
) == 0, "Surface desc has LPSURFACE Flags set\n");
598 lpData
= ddsd2
.lpSurface
;
600 /* DirectDraw uses the dest blit key from the SOURCE surface ! */
601 ok(lpData
[0] == 0x00ff0000 &&
602 lpData
[1] == 0x00ff0000 &&
603 lpData
[2] == 0x00001100 &&
604 lpData
[3] == 0x00001100 &&
605 lpData
[4] == 0x00001100 && /* Key applies here */
606 lpData
[5] == 0x00110000, /* Key applies here */
607 "Surface data after dest key blit does not match\n");
609 lpData
[0] = 0x00FF0000; /* Dest key in dst surface */
610 lpData
[1] = 0x00FF0000; /* Dest key in dst surface */
611 lpData
[2] = 0x00001100; /* Dest key in override */
612 lpData
[3] = 0x00001100; /* Dest key in override */
613 lpData
[4] = 0x00000000; /* Dest key in src surface */
614 lpData
[5] = 0x00000000; /* Dest key in src surface */
615 rc
= IDirectDrawSurface_Unlock(lpDst
, NULL
);
616 ok(rc
==DD_OK
,"Unlock returned: %x\n",rc
);
618 /* Dest override key blit */
619 rc
= IDirectDrawSurface_Blt(lpDst
, NULL
, lpSrc
, NULL
, DDBLT_KEYDESTOVERRIDE
, &fx
);
620 ok(rc
== DD_OK
, "IDirectDrawSurface_Blt returned %08x\n", rc
);
622 rc
= IDirectDrawSurface_Lock(lpDst
, NULL
, &ddsd2
, DDLOCK_WAIT
, NULL
);
623 ok(rc
==DD_OK
,"Lock returned: %x\n",rc
);
624 ok((ddsd2
.dwFlags
& DDSD_LPSURFACE
) == 0, "Surface desc has LPSURFACE Flags set\n");
625 lpData
= ddsd2
.lpSurface
;
627 ok(lpData
[0] == 0x00FF0000 &&
628 lpData
[1] == 0x00FF0000 &&
629 lpData
[2] == 0x00FF0000 && /* Key applies here */
630 lpData
[3] == 0x0000FF00 && /* Key applies here */
631 lpData
[4] == 0x00000000 &&
632 lpData
[5] == 0x00000000,
633 "Surface data after dest key override blit does not match\n");
635 lpData
[0] = 0x00FF0000; /* Dest key in dst surface */
636 lpData
[1] = 0x00FF0000; /* Dest key in dst surface */
637 lpData
[2] = 0x00001100; /* Dest key in override */
638 lpData
[3] = 0x00001100; /* Dest key in override */
639 lpData
[4] = 0x00000000; /* Dest key in src surface */
640 lpData
[5] = 0x00000000; /* Dest key in src surface */
641 rc
= IDirectDrawSurface_Unlock(lpDst
, NULL
);
642 ok(rc
==DD_OK
,"Unlock returned: %x\n",rc
);
644 /* Dest override key blit. Supposed to fail too */
645 rc
= IDirectDrawSurface_Blt(lpDst
, NULL
, lpSrc
, NULL
, DDBLT_KEYDEST
| DDBLT_KEYDESTOVERRIDE
, &fx
);
646 ok(rc
== DDERR_INVALIDPARAMS
, "IDirectDrawSurface_Blt returned %08x\n", rc
);
648 /* Check for unchanged data */
649 rc
= IDirectDrawSurface_Lock(lpDst
, NULL
, &ddsd2
, DDLOCK_WAIT
, NULL
);
650 ok(rc
==DD_OK
,"Lock returned: %x\n",rc
);
651 ok((ddsd2
.dwFlags
& DDSD_LPSURFACE
) == 0, "Surface desc has LPSURFACE Flags set\n");
652 lpData
= ddsd2
.lpSurface
;
654 ok(lpData
[0] == 0x00FF0000 &&
655 lpData
[1] == 0x00FF0000 &&
656 lpData
[2] == 0x00001100 && /* Key applies here */
657 lpData
[3] == 0x00001100 && /* Key applies here */
658 lpData
[4] == 0x00000000 &&
659 lpData
[5] == 0x00000000,
660 "Surface data with dest key and dest override does not match\n");
662 lpData
[0] = 0x00FF0000; /* Dest key in dst surface */
663 lpData
[1] = 0x00FF0000; /* Dest key in dst surface */
664 lpData
[2] = 0x00001100; /* Dest key in override */
665 lpData
[3] = 0x00001100; /* Dest key in override */
666 lpData
[4] = 0x00000000; /* Dest key in src surface */
667 lpData
[5] = 0x00000000; /* Dest key in src surface */
668 rc
= IDirectDrawSurface_Unlock(lpDst
, NULL
);
669 ok(rc
==DD_OK
,"Unlock returned: %x\n",rc
);
671 /* Modify the source data a bit to give some more conclusive results */
672 rc
= IDirectDrawSurface_Lock(lpSrc
, NULL
, &ddsd2
, DDLOCK_WAIT
, NULL
);
673 ok(rc
==DD_OK
,"Lock returned: %x\n",rc
);
674 ok((ddsd2
.dwFlags
& DDSD_LPSURFACE
) == 0, "Surface desc has LPSURFACE Flags set\n");
675 lpData
= ddsd2
.lpSurface
;
676 lpData
[5] = 0x000000FF; /* Applies to src blt key in src surface */
677 rc
= IDirectDrawSurface_Unlock(lpSrc
, NULL
);
678 ok(rc
==DD_OK
,"Unlock returned: %x\n",rc
);
680 /* Source and destination key */
681 rc
= IDirectDrawSurface_Blt(lpDst
, NULL
, lpSrc
, NULL
, DDBLT_KEYDEST
| DDBLT_KEYSRC
, &fx
);
682 ok(rc
== DD_OK
, "IDirectDrawSurface_Blt returned %08x\n", rc
);
684 rc
= IDirectDrawSurface_Lock(lpDst
, NULL
, &ddsd2
, DDLOCK_WAIT
, NULL
);
685 ok(rc
==DD_OK
,"Lock returned: %x\n",rc
);
686 ok((ddsd2
.dwFlags
& DDSD_LPSURFACE
) == 0, "Surface desc has LPSURFACE Flags set\n");
687 lpData
= ddsd2
.lpSurface
;
689 ok(lpData
[0] == 0x00FF0000 && /* Masked by Destination key */
690 lpData
[1] == 0x00FF0000 && /* Masked by Destination key */
691 lpData
[2] == 0x00001100 && /* Masked by Destination key */
692 lpData
[3] == 0x00001100 && /* Masked by Destination key */
693 lpData
[4] == 0x00001100 && /* Allowed by destination key, not masked by source key */
694 lpData
[5] == 0x00000000, /* Allowed by dst key, but masked by source key */
695 "Surface data with src key and dest key blit does not match\n");
697 lpData
[0] = 0x00FF0000; /* Dest key in dst surface */
698 lpData
[1] = 0x00FF0000; /* Dest key in dst surface */
699 lpData
[2] = 0x00001100; /* Dest key in override */
700 lpData
[3] = 0x00001100; /* Dest key in override */
701 lpData
[4] = 0x00000000; /* Dest key in src surface */
702 lpData
[5] = 0x00000000; /* Dest key in src surface */
703 rc
= IDirectDrawSurface_Unlock(lpDst
, NULL
);
704 ok(rc
==DD_OK
,"Unlock returned: %x\n",rc
);
706 /* Override keys without ddbltfx parameter fail */
707 rc
= IDirectDrawSurface_Blt(lpDst
, NULL
, lpSrc
, NULL
, DDBLT_KEYDESTOVERRIDE
, NULL
);
708 ok(rc
== DDERR_INVALIDPARAMS
, "IDirectDrawSurface_Blt returned %08x\n", rc
);
709 rc
= IDirectDrawSurface_Blt(lpDst
, NULL
, lpSrc
, NULL
, DDBLT_KEYSRCOVERRIDE
, NULL
);
710 ok(rc
== DDERR_INVALIDPARAMS
, "IDirectDrawSurface_Blt returned %08x\n", rc
);
712 /* Try blitting without keys in the source surface*/
713 rc
= IDirectDrawSurface_SetColorKey(lpSrc
, DDCKEY_SRCBLT
, NULL
);
714 ok(rc
== DD_OK
, "SetColorKey returned %x\n", rc
);
715 rc
= IDirectDrawSurface_SetColorKey(lpSrc
, DDCKEY_DESTBLT
, NULL
);
716 ok(rc
== DD_OK
, "SetColorKey returned %x\n", rc
);
718 /* That fails now. Do not bother to check that the data is unmodified */
719 rc
= IDirectDrawSurface_Blt(lpDst
, NULL
, lpSrc
, NULL
, DDBLT_KEYSRC
, &fx
);
720 ok(rc
== DDERR_INVALIDPARAMS
, "IDirectDrawSurface_Blt returned %08x\n", rc
);
722 /* Dest key blit still works. Which key is used this time??? */
723 rc
= IDirectDrawSurface_Blt(lpDst
, NULL
, lpSrc
, NULL
, DDBLT_KEYDEST
, &fx
);
724 ok(rc
== DD_OK
, "IDirectDrawSurface_Blt returned %08x\n", rc
);
726 /* With correctly passed override keys no key in the surface is needed.
727 * Again, the result was checked before, no need to do that again
729 rc
= IDirectDrawSurface_Blt(lpDst
, NULL
, lpSrc
, NULL
, DDBLT_KEYDESTOVERRIDE
, &fx
);
730 ok(rc
== DD_OK
, "IDirectDrawSurface_Blt returned %08x\n", rc
);
731 rc
= IDirectDrawSurface_Blt(lpDst
, NULL
, lpSrc
, NULL
, DDBLT_KEYSRCOVERRIDE
, &fx
);
732 ok(rc
== DD_OK
, "IDirectDrawSurface_Blt returned %08x\n", rc
);
734 IDirectDrawSurface_Release(lpSrc
);
735 IDirectDrawSurface_Release(lpDst
);
738 static void QueryInterface(void)
740 LPDIRECTDRAWSURFACE dsurface
;
741 DDSURFACEDESC surface
;
745 /* Create a surface */
746 ZeroMemory(&surface
, sizeof(surface
));
747 surface
.dwSize
= sizeof(surface
);
748 surface
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
;
749 surface
.dwHeight
= 10;
750 surface
.dwWidth
= 10;
751 ret
= IDirectDraw_CreateSurface(lpDD
, &surface
, &dsurface
, NULL
);
754 ok(FALSE
, "IDirectDraw::CreateSurface failed with error %x\n", ret
);
758 /* Call IUnknown::QueryInterface */
759 ret
= IDirectDrawSurface_QueryInterface(dsurface
, 0, &object
);
760 ok(ret
== DDERR_INVALIDPARAMS
, "IDirectDrawSurface::QueryInterface returned %x\n", ret
);
762 IDirectDrawSurface_Release(dsurface
);
765 /* The following tests test which interface is returned by IDirectDrawSurfaceX::GetDDInterface.
766 * It uses refcounts to test that and compares the interface addresses. Partially fits here, and
767 * partially in the refcount test
770 static ULONG
getref(IUnknown
*iface
)
772 IUnknown_AddRef(iface
);
773 return IUnknown_Release(iface
);
776 static void GetDDInterface_1(void)
778 LPDIRECTDRAWSURFACE dsurface
;
779 LPDIRECTDRAWSURFACE2 dsurface2
;
780 DDSURFACEDESC surface
;
785 ULONG ref1
, ref2
, ref4
, ref7
;
788 /* Create a surface */
789 ZeroMemory(&surface
, sizeof(surface
));
790 surface
.dwSize
= sizeof(surface
);
791 surface
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
;
792 surface
.dwHeight
= 10;
793 surface
.dwWidth
= 10;
794 ret
= IDirectDraw_CreateSurface(lpDD
, &surface
, &dsurface
, NULL
);
797 ok(FALSE
, "IDirectDraw::CreateSurface failed with error %x\n", ret
);
800 ret
= IDirectDrawSurface_QueryInterface(dsurface
, &IID_IDirectDrawSurface2
, (void **) &dsurface2
);
801 ok(ret
== DD_OK
, "IDirectDrawSurface_QueryInterface returned %08x\n", ret
);
802 ret
= IDirectDraw_QueryInterface(lpDD
, &IID_IDirectDraw2
, (void **) &dd2
);
803 ok(ret
== DD_OK
, "IDirectDraw7_QueryInterface returned %08x\n", ret
);
804 ret
= IDirectDraw_QueryInterface(lpDD
, &IID_IDirectDraw4
, (void **) &dd4
);
805 ok(ret
== DD_OK
, "IDirectDraw7_QueryInterface returned %08x\n", ret
);
806 ret
= IDirectDraw_QueryInterface(lpDD
, &IID_IDirectDraw7
, (void **) &dd7
);
807 ok(ret
== DD_OK
, "IDirectDraw7_QueryInterface returned %08x\n", ret
);
809 ref1
= getref((IUnknown
*) lpDD
);
810 ok(ref1
== 1, "IDirectDraw refcount is %d\n", ref1
);
811 ref2
= getref((IUnknown
*) dd2
);
812 ok(ref2
== 1, "IDirectDraw2 refcount is %d\n", ref2
);
813 ref4
= getref((IUnknown
*) dd4
);
814 ok(ref4
== 1, "IDirectDraw4 refcount is %d\n", ref4
);
815 ref7
= getref((IUnknown
*) dd7
);
816 ok(ref7
== 1, "IDirectDraw7 refcount is %d\n", ref7
);
819 ret
= IDirectDrawSurface2_GetDDInterface(dsurface2
, &dd
);
820 ok(ret
== DD_OK
, "IDirectDrawSurface7_GetDDInterface returned %08x\n", ret
);
821 ok(getref((IUnknown
*) lpDD
) == ref1
+ 1, "IDirectDraw refcount was increased by %d\n", getref((IUnknown
*) lpDD
) - ref1
);
822 ok(getref((IUnknown
*) dd2
) == ref2
+ 0, "IDirectDraw2 refcount was increased by %d\n", getref((IUnknown
*) dd2
) - ref2
);
823 ok(getref((IUnknown
*) dd4
) == ref4
+ 0, "IDirectDraw4 refcount was increased by %d\n", getref((IUnknown
*) dd4
) - ref4
);
824 ok(getref((IUnknown
*) dd7
) == ref7
+ 0, "IDirectDraw7 refcount was increased by %d\n", getref((IUnknown
*) dd7
) - ref7
);
826 ok(dd
== lpDD
, "Returned interface pointer is not equal to the creation interface\n");
827 IUnknown_Release((IUnknown
*) dd
);
829 /* try a NULL pointer */
830 ret
= IDirectDrawSurface2_GetDDInterface(dsurface2
, NULL
);
831 ok(ret
== DDERR_INVALIDPARAMS
, "IDirectDrawSurface7_GetDDInterface returned %08x\n", ret
);
833 IDirectDraw_Release(dd2
);
834 IDirectDraw_Release(dd4
);
835 IDirectDraw_Release(dd7
);
836 IDirectDrawSurface2_Release(dsurface2
);
837 IDirectDrawSurface_Release(dsurface
);
840 static void GetDDInterface_2(void)
842 LPDIRECTDRAWSURFACE dsurface
;
843 LPDIRECTDRAWSURFACE2 dsurface2
;
844 DDSURFACEDESC surface
;
849 ULONG ref1
, ref2
, ref4
, ref7
;
852 ret
= IDirectDraw_QueryInterface(lpDD
, &IID_IDirectDraw2
, (void **) &dd2
);
853 ok(ret
== DD_OK
, "IDirectDraw7_QueryInterface returned %08x\n", ret
);
854 ret
= IDirectDraw_QueryInterface(lpDD
, &IID_IDirectDraw4
, (void **) &dd4
);
855 ok(ret
== DD_OK
, "IDirectDraw7_QueryInterface returned %08x\n", ret
);
856 ret
= IDirectDraw_QueryInterface(lpDD
, &IID_IDirectDraw7
, (void **) &dd7
);
857 ok(ret
== DD_OK
, "IDirectDraw7_QueryInterface returned %08x\n", ret
);
859 /* Create a surface */
860 ZeroMemory(&surface
, sizeof(surface
));
861 surface
.dwSize
= sizeof(surface
);
862 surface
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
;
863 surface
.dwHeight
= 10;
864 surface
.dwWidth
= 10;
865 ret
= IDirectDraw2_CreateSurface(dd2
, &surface
, &dsurface
, NULL
);
868 ok(FALSE
, "IDirectDraw::CreateSurface failed with error %x\n", ret
);
871 ret
= IDirectDrawSurface_QueryInterface(dsurface
, &IID_IDirectDrawSurface2
, (void **) &dsurface2
);
872 ok(ret
== DD_OK
, "IDirectDrawSurface_QueryInterface returned %08x\n", ret
);
874 ref1
= getref((IUnknown
*) lpDD
);
875 ok(ref1
== 1, "IDirectDraw refcount is %d\n", ref1
);
876 ref2
= getref((IUnknown
*) dd2
);
877 ok(ref2
== 1, "IDirectDraw2 refcount is %d\n", ref2
);
878 ref4
= getref((IUnknown
*) dd4
);
879 ok(ref4
== 1, "IDirectDraw4 refcount is %d\n", ref4
);
880 ref7
= getref((IUnknown
*) dd7
);
881 ok(ref7
== 1, "IDirectDraw7 refcount is %d\n", ref7
);
884 ret
= IDirectDrawSurface2_GetDDInterface(dsurface2
, &dd
);
885 ok(ret
== DD_OK
, "IDirectDrawSurface7_GetDDInterface returned %08x\n", ret
);
886 ok(getref((IUnknown
*) lpDD
) == ref1
+ 0, "IDirectDraw refcount was increased by %d\n", getref((IUnknown
*) lpDD
) - ref1
);
887 ok(getref((IUnknown
*) dd2
) == ref2
+ 1, "IDirectDraw2 refcount was increased by %d\n", getref((IUnknown
*) dd2
) - ref2
);
888 ok(getref((IUnknown
*) dd4
) == ref4
+ 0, "IDirectDraw4 refcount was increased by %d\n", getref((IUnknown
*) dd4
) - ref4
);
889 ok(getref((IUnknown
*) dd7
) == ref7
+ 0, "IDirectDraw7 refcount was increased by %d\n", getref((IUnknown
*) dd7
) - ref7
);
891 ok(dd
== dd2
, "Returned interface pointer is not equal to the creation interface\n");
892 IUnknown_Release((IUnknown
*) dd
);
894 IDirectDraw_Release(dd2
);
895 IDirectDraw_Release(dd4
);
896 IDirectDraw_Release(dd7
);
897 IDirectDrawSurface2_Release(dsurface2
);
898 IDirectDrawSurface_Release(dsurface
);
901 static void GetDDInterface_4(void)
903 LPDIRECTDRAWSURFACE2 dsurface2
;
904 LPDIRECTDRAWSURFACE4 dsurface4
;
905 DDSURFACEDESC2 surface
;
910 ULONG ref1
, ref2
, ref4
, ref7
;
913 ret
= IDirectDraw_QueryInterface(lpDD
, &IID_IDirectDraw2
, (void **) &dd2
);
914 ok(ret
== DD_OK
, "IDirectDraw7_QueryInterface returned %08x\n", ret
);
915 ret
= IDirectDraw_QueryInterface(lpDD
, &IID_IDirectDraw4
, (void **) &dd4
);
916 ok(ret
== DD_OK
, "IDirectDraw7_QueryInterface returned %08x\n", ret
);
917 ret
= IDirectDraw_QueryInterface(lpDD
, &IID_IDirectDraw7
, (void **) &dd7
);
918 ok(ret
== DD_OK
, "IDirectDraw7_QueryInterface returned %08x\n", ret
);
920 /* Create a surface */
921 ZeroMemory(&surface
, sizeof(surface
));
922 surface
.dwSize
= sizeof(surface
);
923 surface
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
;
924 surface
.dwHeight
= 10;
925 surface
.dwWidth
= 10;
926 ret
= IDirectDraw4_CreateSurface(dd4
, &surface
, &dsurface4
, NULL
);
929 ok(FALSE
, "IDirectDraw::CreateSurface failed with error %x\n", ret
);
932 ret
= IDirectDrawSurface4_QueryInterface(dsurface4
, &IID_IDirectDrawSurface2
, (void **) &dsurface2
);
933 ok(ret
== DD_OK
, "IDirectDrawSurface_QueryInterface returned %08x\n", ret
);
935 ref1
= getref((IUnknown
*) lpDD
);
936 ok(ref1
== 1, "IDirectDraw refcount is %d\n", ref1
);
937 ref2
= getref((IUnknown
*) dd2
);
938 ok(ref2
== 1, "IDirectDraw2 refcount is %d\n", ref2
);
939 ref4
= getref((IUnknown
*) dd4
);
940 ok(ref4
== 2, "IDirectDraw4 refcount is %d\n", ref4
);
941 ref7
= getref((IUnknown
*) dd7
);
942 ok(ref7
== 1, "IDirectDraw7 refcount is %d\n", ref7
);
944 ret
= IDirectDrawSurface4_GetDDInterface(dsurface4
, &dd
);
945 ok(ret
== DD_OK
, "IDirectDrawSurface7_GetDDInterface returned %08x\n", ret
);
946 ok(getref((IUnknown
*) lpDD
) == ref1
+ 0, "IDirectDraw refcount was increased by %d\n", getref((IUnknown
*) lpDD
) - ref1
);
947 ok(getref((IUnknown
*) dd2
) == ref2
+ 0, "IDirectDraw2 refcount was increased by %d\n", getref((IUnknown
*) dd2
) - ref2
);
948 ok(getref((IUnknown
*) dd4
) == ref4
+ 1, "IDirectDraw4 refcount was increased by %d\n", getref((IUnknown
*) dd4
) - ref4
);
949 ok(getref((IUnknown
*) dd7
) == ref7
+ 0, "IDirectDraw7 refcount was increased by %d\n", getref((IUnknown
*) dd7
) - ref7
);
951 ok(dd
== dd4
, "Returned interface pointer is not equal to the creation interface\n");
952 IUnknown_Release((IUnknown
*) dd
);
954 /* Now test what happens if we QI the surface for some other version - It should still return the creation interface */
955 ret
= IDirectDrawSurface2_GetDDInterface(dsurface2
, &dd
);
956 ok(ret
== DD_OK
, "IDirectDrawSurface7_GetDDInterface returned %08x\n", ret
);
957 ok(getref((IUnknown
*) lpDD
) == ref1
+ 0, "IDirectDraw refcount was increased by %d\n", getref((IUnknown
*) lpDD
) - ref1
);
958 ok(getref((IUnknown
*) dd2
) == ref2
+ 0, "IDirectDraw2 refcount was increased by %d\n", getref((IUnknown
*) dd2
) - ref2
);
959 ok(getref((IUnknown
*) dd4
) == ref4
+ 1, "IDirectDraw4 refcount was increased by %d\n", getref((IUnknown
*) dd4
) - ref4
);
960 ok(getref((IUnknown
*) dd7
) == ref7
+ 0, "IDirectDraw7 refcount was increased by %d\n", getref((IUnknown
*) dd7
) - ref7
);
962 ok(dd
== dd4
, "Returned interface pointer is not equal to the creation interface\n");
963 IUnknown_Release((IUnknown
*) dd
);
965 IDirectDraw_Release(dd2
);
966 IDirectDraw_Release(dd4
);
967 IDirectDraw_Release(dd7
);
968 IDirectDrawSurface4_Release(dsurface4
);
969 IDirectDrawSurface2_Release(dsurface2
);
972 static void GetDDInterface_7(void)
974 LPDIRECTDRAWSURFACE4 dsurface4
;
975 LPDIRECTDRAWSURFACE7 dsurface7
;
976 DDSURFACEDESC2 surface
;
981 ULONG ref1
, ref2
, ref4
, ref7
;
984 ret
= IDirectDraw_QueryInterface(lpDD
, &IID_IDirectDraw2
, (void **) &dd2
);
985 ok(ret
== DD_OK
, "IDirectDraw7_QueryInterface returned %08x\n", ret
);
986 ret
= IDirectDraw_QueryInterface(lpDD
, &IID_IDirectDraw4
, (void **) &dd4
);
987 ok(ret
== DD_OK
, "IDirectDraw7_QueryInterface returned %08x\n", ret
);
988 ret
= IDirectDraw_QueryInterface(lpDD
, &IID_IDirectDraw7
, (void **) &dd7
);
989 ok(ret
== DD_OK
, "IDirectDraw7_QueryInterface returned %08x\n", ret
);
991 /* Create a surface */
992 ZeroMemory(&surface
, sizeof(surface
));
993 surface
.dwSize
= sizeof(surface
);
994 surface
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
;
995 surface
.dwHeight
= 10;
996 surface
.dwWidth
= 10;
997 ret
= IDirectDraw7_CreateSurface(dd7
, &surface
, &dsurface7
, NULL
);
1000 ok(FALSE
, "IDirectDraw::CreateSurface failed with error %x\n", ret
);
1003 ret
= IDirectDrawSurface7_QueryInterface(dsurface7
, &IID_IDirectDrawSurface4
, (void **) &dsurface4
);
1004 ok(ret
== DD_OK
, "IDirectDrawSurface_QueryInterface returned %08x\n", ret
);
1006 ref1
= getref((IUnknown
*) lpDD
);
1007 ok(ref1
== 1, "IDirectDraw refcount is %d\n", ref1
);
1008 ref2
= getref((IUnknown
*) dd2
);
1009 ok(ref2
== 1, "IDirectDraw2 refcount is %d\n", ref2
);
1010 ref4
= getref((IUnknown
*) dd4
);
1011 ok(ref4
== 1, "IDirectDraw4 refcount is %d\n", ref4
);
1012 ref7
= getref((IUnknown
*) dd7
);
1013 ok(ref7
== 2, "IDirectDraw7 refcount is %d\n", ref7
);
1015 ret
= IDirectDrawSurface7_GetDDInterface(dsurface7
, &dd
);
1016 ok(ret
== DD_OK
, "IDirectDrawSurface7_GetDDInterface returned %08x\n", ret
);
1017 ok(getref((IUnknown
*) lpDD
) == ref1
+ 0, "IDirectDraw refcount was increased by %d\n", getref((IUnknown
*) lpDD
) - ref1
);
1018 ok(getref((IUnknown
*) dd2
) == ref2
+ 0, "IDirectDraw2 refcount was increased by %d\n", getref((IUnknown
*) dd2
) - ref2
);
1019 ok(getref((IUnknown
*) dd4
) == ref4
+ 0, "IDirectDraw4 refcount was increased by %d\n", getref((IUnknown
*) dd4
) - ref4
);
1020 ok(getref((IUnknown
*) dd7
) == ref7
+ 1, "IDirectDraw7 refcount was increased by %d\n", getref((IUnknown
*) dd7
) - ref7
);
1022 ok(dd
== dd7
, "Returned interface pointer is not equal to the creation interface\n");
1023 IUnknown_Release((IUnknown
*) dd
);
1025 /* Now test what happens if we QI the surface for some other version - It should still return the creation interface */
1026 ret
= IDirectDrawSurface4_GetDDInterface(dsurface4
, &dd
);
1027 ok(ret
== DD_OK
, "IDirectDrawSurface7_GetDDInterface returned %08x\n", ret
);
1028 ok(getref((IUnknown
*) lpDD
) == ref1
+ 0, "IDirectDraw refcount was increased by %d\n", getref((IUnknown
*) lpDD
) - ref1
);
1029 ok(getref((IUnknown
*) dd2
) == ref2
+ 0, "IDirectDraw2 refcount was increased by %d\n", getref((IUnknown
*) dd2
) - ref2
);
1030 ok(getref((IUnknown
*) dd4
) == ref4
+ 0, "IDirectDraw4 refcount was increased by %d\n", getref((IUnknown
*) dd4
) - ref4
);
1031 ok(getref((IUnknown
*) dd7
) == ref7
+ 1, "IDirectDraw7 refcount was increased by %d\n", getref((IUnknown
*) dd7
) - ref7
);
1033 ok(dd
== dd7
, "Returned interface pointer is not equal to the creation interface\n");
1034 IUnknown_Release((IUnknown
*) dd
);
1036 IDirectDraw_Release(dd2
);
1037 IDirectDraw_Release(dd4
);
1038 IDirectDraw_Release(dd7
);
1039 IDirectDrawSurface4_Release(dsurface4
);
1040 IDirectDrawSurface7_Release(dsurface7
);
1043 static ULONG
getRefcount(IUnknown
*iface
)
1045 IUnknown_AddRef(iface
);
1046 return IUnknown_Release(iface
);
1049 static void IFaceRefCount(void)
1051 LPDIRECTDRAWSURFACE surf
;
1052 DDSURFACEDESC surface
;
1054 IDirectDrawSurface2
*surf2
;
1055 IDirectDrawSurface2
*surf2a
;
1056 IDirectDrawSurface3
*surf3
;
1057 IDirectDrawSurface4
*surf4
;
1058 IDirectDrawSurface7
*surf7a
;
1059 IDirectDrawSurface7
*surf7b
;
1060 IDirect3DTexture
* tex
;
1061 IDirect3DTexture2
* tex2
;
1062 IDirectDrawGammaControl
* gamma
;
1065 /* Create a surface */
1066 ZeroMemory(&surface
, sizeof(surface
));
1067 surface
.dwSize
= sizeof(surface
);
1068 surface
.dwFlags
= DDSD_CAPS
;
1069 surface
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
1070 ret
= IDirectDraw_CreateSurface(lpDD
, &surface
, &surf
, NULL
);
1074 ok(FALSE
, "Could not create surface, skipping test\n");
1078 ref
= getRefcount((IUnknown
*) surf
);
1079 ok(ref
== 1, "Refcount is %u, expected 1\n", ref
); /* Check the ref count is one */
1081 IDirectDrawSurface_QueryInterface(surf
, &IID_IDirectDrawSurface2
, (void **) &surf2
);
1082 ref
= getRefcount((IUnknown
*) surf
);
1083 ok(ref
== 1, "Refcount is %u, expected 1\n", ref
); /* Check the ref count is one */
1084 ref
= getRefcount((IUnknown
*) surf2
);
1085 ok(ref
== 1, "Refcount is %u, expected 1\n", ref
); /* This should also be one */
1087 IDirectDrawSurface_QueryInterface(surf
, &IID_IDirectDrawSurface2
, (void **) &surf2a
);
1088 ref
= getRefcount((IUnknown
*) surf2
);
1089 ok(ref
== 2, "Refcount is %u, expected 2\n", ref
); /* Surf2's refcount should be 2 now, but surf should be 1 */
1090 ref
= getRefcount((IUnknown
*) surf
);
1091 ok(ref
== 1, "Refcount is %u, expected 1\n", ref
);
1093 IDirectDrawSurface_QueryInterface(surf
, &IID_IDirectDrawSurface3
, (void **) &surf3
);
1094 ref
= getRefcount((IUnknown
*) surf3
);
1095 ok(ref
== 1, "Refcount is %u, expected 1\n", ref
);
1097 IDirectDrawSurface_QueryInterface(surf
, &IID_IDirectDrawSurface4
, (void **) &surf4
);
1098 ref
= getRefcount((IUnknown
*) surf4
);
1099 ok(ref
== 1, "Refcount is %u, expected 1\n", ref
);
1101 IDirectDrawSurface_QueryInterface(surf
, &IID_IDirectDrawSurface7
, (void **) &surf7a
);
1102 ref
= getRefcount((IUnknown
*) surf7a
);
1103 todo_wine
ok(ref
== 1, "Refcount is %u, expected 1\n", ref
);
1105 IDirectDrawSurface_QueryInterface(surf
, &IID_IDirectDrawSurface7
, (void **) &surf7b
);
1106 ref
= getRefcount((IUnknown
*) surf7b
);
1107 todo_wine
ok(ref
== 2, "Refcount is %u, expected 2\n", ref
);
1109 /* IDirect3DTexture interface (unlike the others) alters the original IDirectDrawSurface ref count */
1110 ret
= IDirectDrawSurface_QueryInterface(surf
, &IID_IDirect3DTexture
, (void **) &tex
);
1113 ref
= getRefcount((IUnknown
*) tex
);
1114 todo_wine
ok(ref
== 2, "Refcount is %u, expected 2\n", ref
);
1115 ref
= getRefcount((IUnknown
*) surf
);
1116 todo_wine
ok(ref
== 2, "Refcount is %u, expected 2\n", ref
);
1118 IDirectDrawSurface_QueryInterface(surf
, &IID_IDirect3DTexture2
, (void **) &tex2
);
1119 ref
= getRefcount((IUnknown
*) tex
);
1120 todo_wine
ok(ref
== 3, "Refcount is %u, expected 3\n", ref
);
1121 ref
= getRefcount((IUnknown
*) tex2
);
1122 todo_wine
ok(ref
== 3, "Refcount is %u, expected 3\n", ref
);
1123 ref
= getRefcount((IUnknown
*) surf
);
1124 todo_wine
ok(ref
== 3, "Refcount is %u, expected 3\n", ref
);
1126 IDirectDrawSurface_QueryInterface(surf
, &IID_IDirectDrawGammaControl
, (void **) &gamma
);
1127 ref
= getRefcount((IUnknown
*) gamma
);
1128 todo_wine
ok(ref
== 1, "Refcount is %u, expected 1\n", ref
);
1130 ref
= IDirect3DTexture2_Release(tex2
); /* Release the texture */
1131 todo_wine
ok(ref
== 2, "Refcount is %u, expected 2\n", ref
);
1132 ref
= getRefcount((IUnknown
*) surf
);
1133 todo_wine
ok(ref
== 2, "Refcount is %u, expected 2\n", ref
);
1135 ref
= IDirect3DTexture_Release(tex
); /* Release the texture */
1136 todo_wine
ok(ref
== 1, "Refcount is %u, expected 1\n", ref
);
1137 ref
= getRefcount((IUnknown
*) surf
);
1138 todo_wine
ok(ref
== 1, "Refcount is %u, expected 1\n", ref
);
1140 ref
= IDirectDrawGammaControl_Release(gamma
); /* Release the gamma control */
1141 todo_wine
ok(ref
== 0, "Refcount is %u, expected 0\n", ref
);
1144 ref
= IDirectDrawSurface2_Release(surf2
); /* Release one of the 2 surf2 interfaces */
1145 ok(ref
== 1, "Refcount is %u, expected 1\n", ref
);
1147 ref
= IDirectDrawSurface2_Release(surf2a
); /* Release the other */
1148 ok(ref
== 0, "Refcount is %u, expected 0\n", ref
);
1150 ref
= IDirectDrawSurface3_Release(surf3
);
1151 ok(ref
== 0, "Refcount is %u, expected 0\n", ref
);
1153 ref
= IDirectDrawSurface4_Release(surf4
);
1154 ok(ref
== 0, "Refcount is %u, expected 0\n", ref
);
1156 ref
= IDirectDrawSurface7_Release(surf7a
);
1157 todo_wine
ok(ref
== 1, "Refcount is %u, expected 1\n", ref
);
1159 ref
= IDirectDrawSurface7_Release(surf7b
);
1160 todo_wine
ok(ref
== 0, "Refcount is %u, expected 0\n", ref
);
1162 ref
= IDirectDrawSurface_Release(surf
);
1163 ok(ref
== 0, "Refcount is %u, expected 0\n", ref
);
1166 #define MAXEXPECTED 8 /* Can match up to 8 expected surfaces */
1169 IDirectDrawSurface
*expected
[MAXEXPECTED
];
1173 static HRESULT WINAPI
enumCB(IDirectDrawSurface
*surf
, DDSURFACEDESC
*desc
, void *ctx
)
1178 for(i
= 0; i
< MAXEXPECTED
; i
++)
1180 if(((struct enumstruct
*)ctx
)->expected
[i
] == surf
) found
= TRUE
;
1183 ok(found
, "Unexpected surface %p enumerated\n", surf
);
1184 ((struct enumstruct
*)ctx
)->count
++;
1185 IDirectDrawSurface_Release(surf
);
1186 return DDENUMRET_OK
;
1189 static void EnumTest(void)
1193 IDirectDrawSurface
*surface
;
1194 struct enumstruct ctx
;
1196 ddsd
.dwSize
= sizeof(ddsd
);
1197 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_MIPMAPCOUNT
;
1198 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
1199 U2(ddsd
).dwMipMapCount
= 3;
1202 rc
= IDirectDraw_CreateSurface(lpDD
, &ddsd
, &surface
, NULL
);
1203 ok(rc
==DD_OK
,"CreateSurface returned: %x\n",rc
);
1205 memset(&ctx
, 0, sizeof(ctx
));
1206 ctx
.expected
[0] = surface
;
1207 rc
= IDirectDrawSurface_GetAttachedSurface(ctx
.expected
[0], &ddsd
.ddsCaps
, &ctx
.expected
[1]);
1208 ok(rc
== DD_OK
, "GetAttachedSurface returned %08x\n", rc
);
1209 rc
= IDirectDrawSurface_GetAttachedSurface(ctx
.expected
[1], &ddsd
.ddsCaps
, &ctx
.expected
[2]);
1210 ok(rc
== DD_OK
, "GetAttachedSurface returned %08x\n", rc
);
1211 rc
= IDirectDrawSurface_GetAttachedSurface(ctx
.expected
[2], &ddsd
.ddsCaps
, &ctx
.expected
[3]);
1212 ok(rc
== DDERR_NOTFOUND
, "GetAttachedSurface returned %08x\n", rc
);
1213 ok(!ctx
.expected
[3], "expected NULL pointer\n");
1216 rc
= IDirectDraw_EnumSurfaces(lpDD
, DDENUMSURFACES_DOESEXIST
| DDENUMSURFACES_ALL
, &ddsd
, &ctx
, enumCB
);
1217 ok(rc
== DD_OK
, "IDirectDraw_EnumSurfaces returned %08x\n", rc
);
1218 ok(ctx
.count
== 3, "%d surfaces enumerated, expected 3\n", ctx
.count
);
1220 IDirectDrawSurface_Release(ctx
.expected
[2]);
1221 IDirectDrawSurface_Release(ctx
.expected
[1]);
1222 IDirectDrawSurface_Release(surface
);
1225 static HRESULT WINAPI
SurfaceCounter(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*desc
, void *context
)
1227 UINT
*num
= context
;
1229 IDirectDrawSurface_Release(surface
);
1230 return DDENUMRET_OK
;
1233 static void AttachmentTest7(void)
1237 IDirectDrawSurface7
*surface1
, *surface2
, *surface3
, *surface4
;
1238 DDSURFACEDESC2 ddsd
, ddsd2
;
1240 DDSCAPS2 caps
= {DDSCAPS_TEXTURE
, 0, 0, 0}, caps2
= {DDSCAPS_BACKBUFFER
,0,0,0};
1241 HWND window
= CreateWindow( "static", "ddraw_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
1243 hr
= IDirectDraw_QueryInterface(lpDD
, &IID_IDirectDraw7
, (void **) &dd7
);
1244 ok(hr
== DD_OK
, "IDirectDraw_QueryInterface returned %08x\n", hr
);
1246 memset(&ddsd
, 0, sizeof(ddsd
));
1247 ddsd
.dwSize
= sizeof(ddsd
);
1248 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_MIPMAPCOUNT
;
1249 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
1250 U2(ddsd
).dwMipMapCount
= 3; /* Will create 128x128, 64x64, 32x32 */
1252 ddsd
.dwHeight
= 128;
1253 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd
, &surface1
, NULL
);
1254 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
1258 IDirectDrawSurface7_EnumAttachedSurfaces(surface1
, &num
, SurfaceCounter
);
1259 ok(num
== 1, "Mipmap root has %d surfaces attached, expected 1\n", num
);
1263 hr
= IDirectDrawSurface7_GetAttachedSurface(surface1
, &caps
, &surface2
);
1264 ok(hr
== DD_OK
, "GetAttachedSurface returned %08x\n", hr
);
1266 IDirectDrawSurface7_EnumAttachedSurfaces(surface2
, &num
, SurfaceCounter
);
1267 ok(num
== 1, "First mip level has %d surfaces attached, expected 1\n", num
);
1271 hr
= IDirectDrawSurface7_GetAttachedSurface(surface2
, &caps
, &surface3
);
1272 ok(hr
== DD_OK
, "GetAttachedSurface returned %08x\n", hr
);
1273 IDirectDrawSurface7_Release(surface2
);
1275 IDirectDrawSurface7_EnumAttachedSurfaces(surface3
, &num
, SurfaceCounter
);
1276 ok(num
== 0, "Second mip level has %d surfaces attached, expected 1\n", num
);
1278 /* Mip level 3 is still needed */
1279 hr
= IDirectDrawSurface7_GetAttachedSurface(surface3
, &caps
, &surface4
);
1280 ok(hr
== DDERR_NOTFOUND
, "GetAttachedSurface returned %08x\n", hr
);
1281 ok(!surface4
, "expected NULL pointer\n");
1283 /* Try to attach a 16x16 miplevel - Should not work as far I can see */
1284 memset(&ddsd
, 0, sizeof(ddsd
));
1285 ddsd
.dwSize
= sizeof(ddsd
);
1286 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1287 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1290 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd
, &surface2
, NULL
);
1291 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
1293 hr
= IDirectDrawSurface7_AddAttachedSurface(surface1
, surface2
);
1294 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a 16x16 surface to a 128x128 texture root returned %08x\n", hr
);
1295 hr
= IDirectDrawSurface7_AddAttachedSurface(surface2
, surface1
);
1296 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a 128x128 texture root to a 16x16 texture returned %08x\n", hr
);
1297 hr
= IDirectDrawSurface7_AddAttachedSurface(surface3
, surface2
);
1298 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a 16x16 surface to a 32x32 texture mip level returned %08x\n", hr
);
1299 hr
= IDirectDrawSurface7_AddAttachedSurface(surface2
, surface3
);
1300 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a 32x32 texture mip level to a 16x16 surface returned %08x\n", hr
);
1302 IDirectDrawSurface7_Release(surface2
);
1304 memset(&ddsd
, 0, sizeof(ddsd
));
1305 ddsd
.dwSize
= sizeof(ddsd
);
1306 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1307 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
1310 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd
, &surface2
, NULL
);
1311 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
1313 hr
= IDirectDrawSurface7_AddAttachedSurface(surface1
, surface2
);
1314 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a 16x16 offscreen plain surface to a 128x128 texture root returned %08x\n", hr
);
1315 hr
= IDirectDrawSurface7_AddAttachedSurface(surface2
, surface1
);
1316 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a 128x128 texture root to a 16x16 offscreen plain surface returned %08x\n", hr
);
1317 hr
= IDirectDrawSurface7_AddAttachedSurface(surface3
, surface2
);
1318 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a 16x16 offscreen plain surface to a 32x32 texture mip level returned %08x\n", hr
);
1319 hr
= IDirectDrawSurface7_AddAttachedSurface(surface2
, surface3
);
1320 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a 32x32 texture mip level to a 16x16 offscreen plain surface returned %08x\n", hr
);
1322 IDirectDrawSurface7_Release(surface3
);
1323 IDirectDrawSurface7_Release(surface2
);
1324 IDirectDrawSurface7_Release(surface1
);
1326 hr
= IDirectDraw7_SetCooperativeLevel(dd7
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
1327 ok(hr
== DD_OK
, "SetCooperativeLevel returned %08x\n", hr
);
1329 memset(&ddsd
, 0, sizeof(ddsd
));
1330 ddsd
.dwSize
= sizeof(ddsd
);
1331 ddsd
.dwFlags
= DDSD_BACKBUFFERCOUNT
| DDSD_CAPS
;
1332 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
1333 ddsd
.dwBackBufferCount
= 2;
1334 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd
, &surface1
, NULL
);
1335 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
1337 /* backbuffer surfaces must not have dwBackBufferCount set */
1338 ddsd2
.dwSize
= sizeof(ddsd2
);
1339 hr
= IDirectDrawSurface7_GetAttachedSurface(surface1
, &caps2
, &surface2
);
1340 ok(hr
==DD_OK
,"GetAttachedSurface returned: %x\n", hr
);
1341 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface2
, &ddsd2
);
1342 ok(hr
==DD_OK
,"GetSurfaceDesc returned: %x\n", hr
);
1343 ok(ddsd2
.dwBackBufferCount
==0,"backbuffer surface has dwBackBufferCount==%u\n", ddsd2
.dwBackBufferCount
);
1346 IDirectDrawSurface7_EnumAttachedSurfaces(surface1
, &num
, SurfaceCounter
);
1347 ok(num
== 1, "Primary surface has %d surfaces attached, expected 1\n", num
);
1348 IDirectDrawSurface7_Release(surface1
);
1350 /* Those are some invalid descriptions, no need to test attachments with them */
1351 memset(&ddsd
, 0, sizeof(ddsd
));
1352 ddsd
.dwSize
= sizeof(ddsd
);
1353 ddsd
.dwFlags
= DDSD_CAPS
;
1354 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
;
1355 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd
, &surface1
, NULL
);
1356 ok(hr
==DDERR_INVALIDCAPS
,"CreateSurface returned: %x\n",hr
);
1357 memset(&ddsd
, 0, sizeof(ddsd
));
1358 ddsd
.dwSize
= sizeof(ddsd
);
1359 ddsd
.dwFlags
= DDSD_CAPS
;
1360 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_BACKBUFFER
;
1361 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd
, &surface2
, NULL
);
1362 ok(hr
==DDERR_INVALIDCAPS
,"CreateSurface returned: %x\n",hr
);
1364 /* Try a single primary and two offscreen plain surfaces */
1365 memset(&ddsd
, 0, sizeof(ddsd
));
1366 ddsd
.dwSize
= sizeof(ddsd
);
1367 ddsd
.dwFlags
= DDSD_CAPS
;
1368 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
1369 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd
, &surface1
, NULL
);
1370 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
1372 memset(&ddsd
, 0, sizeof(ddsd
));
1373 ddsd
.dwSize
= sizeof(ddsd
);
1374 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1375 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
1376 ddsd
.dwWidth
= GetSystemMetrics(SM_CXSCREEN
);
1377 ddsd
.dwHeight
= GetSystemMetrics(SM_CYSCREEN
);
1378 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd
, &surface2
, NULL
);
1379 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
1381 memset(&ddsd
, 0, sizeof(ddsd
));
1382 ddsd
.dwSize
= sizeof(ddsd
);
1383 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1384 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
1385 ddsd
.dwWidth
= GetSystemMetrics(SM_CXSCREEN
);
1386 ddsd
.dwHeight
= GetSystemMetrics(SM_CYSCREEN
);
1387 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd
, &surface3
, NULL
);
1388 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
1390 /* This one has a different size */
1391 memset(&ddsd
, 0, sizeof(ddsd
));
1392 ddsd
.dwSize
= sizeof(ddsd
);
1393 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1394 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
1396 ddsd
.dwHeight
= 128;
1397 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd
, &surface4
, NULL
);
1398 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
1400 hr
= IDirectDrawSurface7_AddAttachedSurface(surface1
, surface2
);
1401 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching an offscreen plain surface to a front buffer returned %08x\n", hr
);
1402 hr
= IDirectDrawSurface7_AddAttachedSurface(surface2
, surface1
);
1403 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a front buffer to an offscreen plain surface returned %08x\n", hr
);
1404 hr
= IDirectDrawSurface7_AddAttachedSurface(surface2
, surface3
);
1405 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching an offscreen plain surface to another offscreen plain surface returned %08x\n", hr
);
1406 hr
= IDirectDrawSurface7_AddAttachedSurface(surface1
, surface4
);
1407 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching an offscreen plain surface to a front buffer of different size returned %08x\n", hr
);
1408 hr
= IDirectDrawSurface7_AddAttachedSurface(surface4
, surface1
);
1409 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a front buffer to an offscreen plain surface of different size returned %08x\n", hr
);
1411 IDirectDrawSurface7_Release(surface4
);
1412 IDirectDrawSurface7_Release(surface3
);
1413 IDirectDrawSurface7_Release(surface2
);
1414 IDirectDrawSurface7_Release(surface1
);
1416 hr
=IDirectDraw7_SetCooperativeLevel(dd7
, NULL
, DDSCL_NORMAL
);
1417 ok(hr
== DD_OK
, "SetCooperativeLevel returned %08x\n", hr
);
1418 IDirectDraw7_Release(dd7
);
1421 static void AttachmentTest(void)
1424 IDirectDrawSurface
*surface1
, *surface2
, *surface3
, *surface4
;
1426 DDSCAPS caps
= {DDSCAPS_TEXTURE
};
1427 BOOL refrast
= FALSE
;
1428 HWND window
= CreateWindow( "static", "ddraw_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
1430 memset(&ddsd
, 0, sizeof(ddsd
));
1431 ddsd
.dwSize
= sizeof(ddsd
);
1432 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_MIPMAPCOUNT
;
1433 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
1434 U2(ddsd
).dwMipMapCount
= 3; /* Will create 128x128, 64x64, 32x32 */
1436 ddsd
.dwHeight
= 128;
1437 hr
= IDirectDraw7_CreateSurface(lpDD
, &ddsd
, &surface1
, NULL
);
1438 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
1440 hr
= IDirectDrawSurface7_GetAttachedSurface(surface1
, &caps
, &surface2
);
1441 ok(hr
== DD_OK
, "GetAttachedSurface returned %08x\n", hr
);
1442 hr
= IDirectDrawSurface7_GetAttachedSurface(surface2
, &caps
, &surface3
);
1443 ok(hr
== DD_OK
, "GetAttachedSurface returned %08x\n", hr
);
1445 /* Try to attach a 16x16 miplevel - Should not work as far I can see */
1446 memset(&ddsd
, 0, sizeof(ddsd
));
1447 ddsd
.dwSize
= sizeof(ddsd
);
1448 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1449 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1452 hr
= IDirectDraw_CreateSurface(lpDD
, &ddsd
, &surface4
, NULL
);
1453 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
1455 hr
= IDirectDrawSurface7_AddAttachedSurface(surface1
, surface4
);
1456 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a 16x16 surface to a 128x128 texture root returned %08x\n", hr
);
1457 hr
= IDirectDrawSurface7_AddAttachedSurface(surface4
, surface1
);
1458 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a 128x128 texture root to a 16x16 texture returned %08x\n", hr
);
1459 hr
= IDirectDrawSurface7_AddAttachedSurface(surface3
, surface4
);
1460 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a 16x16 surface to a 32x32 texture mip level returned %08x\n", hr
);
1461 hr
= IDirectDrawSurface7_AddAttachedSurface(surface4
, surface3
);
1462 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a 32x32 texture mip level to a 16x16 surface returned %08x\n", hr
);
1463 hr
= IDirectDrawSurface7_AddAttachedSurface(surface2
, surface4
);
1464 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a 16x16 surface to a 64x64 texture sublevel returned %08x\n", hr
);
1465 hr
= IDirectDrawSurface7_AddAttachedSurface(surface4
, surface2
);
1466 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a 64x64 texture sublevel to a 16x16 texture returned %08x\n", hr
);
1468 IDirectDrawSurface7_Release(surface4
);
1470 memset(&ddsd
, 0, sizeof(ddsd
));
1471 ddsd
.dwSize
= sizeof(ddsd
);
1472 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1473 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
1476 hr
= IDirectDraw7_CreateSurface(lpDD
, &ddsd
, &surface4
, NULL
);
1477 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
1479 if (SUCCEEDED(IDirectDrawSurface7_AddAttachedSurface(surface1
, surface4
)))
1481 IDirectDrawSurface7_DeleteAttachedSurface(surface1
, 0, surface4
);
1485 hr
= IDirectDrawSurface7_AddAttachedSurface(surface1
, surface4
); /* Succeeds on refrast */
1487 ok(hr
== S_OK
, "Attaching a 16x16 offscreen plain surface to a 128x128 texture root returned %08x\n", hr
);
1489 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a 16x16 offscreen plain surface to a 128x128 texture root returned %08x\n", hr
);
1490 if(SUCCEEDED(hr
)) IDirectDrawSurface7_DeleteAttachedSurface(surface1
, 0, surface4
);
1492 hr
= IDirectDrawSurface7_AddAttachedSurface(surface4
, surface1
); /* Succeeds on refrast */
1494 ok(hr
== S_OK
, "Attaching a 128x128 texture root to a 16x16 offscreen plain surface returned %08x\n", hr
);
1496 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a 128x128 texture root to a 16x16 offscreen plain surface returned %08x\n", hr
);
1497 if(SUCCEEDED(hr
)) IDirectDrawSurface7_DeleteAttachedSurface(surface1
, 0, surface1
);
1499 hr
= IDirectDrawSurface7_AddAttachedSurface(surface3
, surface4
); /* Succeeds on refrast */
1501 ok(hr
== S_OK
, "Attaching a 16x16 offscreen plain surface to a 32x32 texture mip level returned %08x\n", hr
);
1503 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a 16x16 offscreen plain surface to a 32x32 texture mip level returned %08x\n", hr
);
1504 if(SUCCEEDED(hr
)) IDirectDrawSurface7_DeleteAttachedSurface(surface3
, 0, surface4
);
1506 hr
= IDirectDrawSurface7_AddAttachedSurface(surface4
, surface3
);
1507 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a 32x32 texture mip level to a 16x16 offscreen plain surface returned %08x\n", hr
);
1508 if(SUCCEEDED(hr
)) IDirectDrawSurface7_DeleteAttachedSurface(surface4
, 0, surface3
);
1510 hr
= IDirectDrawSurface7_AddAttachedSurface(surface2
, surface4
); /* Succeeds on refrast */
1512 ok(hr
== S_OK
, "Attaching a 16x16 offscreen plain surface to a 64x64 texture sublevel returned %08x\n", hr
);
1514 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a 16x16 offscreen plain surface to a 64x64 texture sublevel returned %08x\n", hr
);
1515 if(SUCCEEDED(hr
)) IDirectDrawSurface7_DeleteAttachedSurface(surface2
, 0, surface4
);
1517 hr
= IDirectDrawSurface7_AddAttachedSurface(surface4
, surface2
);
1518 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a 64x64 texture sublevel to a 16x16 offscreen plain surface returned %08x\n", hr
);
1519 if(SUCCEEDED(hr
)) IDirectDrawSurface7_DeleteAttachedSurface(surface4
, 0, surface2
);
1521 IDirectDrawSurface7_Release(surface4
);
1522 IDirectDrawSurface7_Release(surface3
);
1523 IDirectDrawSurface7_Release(surface2
);
1524 IDirectDrawSurface7_Release(surface1
);
1526 hr
= IDirectDraw_SetCooperativeLevel(lpDD
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
1527 ok(hr
== DD_OK
, "SetCooperativeLevel returned %08x\n", hr
);
1529 /* Creating a back buffer as-is, is not allowed. No need to perform attachment tests */
1530 memset(&ddsd
, 0, sizeof(ddsd
));
1531 ddsd
.dwSize
= sizeof(ddsd
);
1532 ddsd
.dwFlags
= DDSD_CAPS
;
1533 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_BACKBUFFER
;
1534 hr
= IDirectDraw_CreateSurface(lpDD
, &ddsd
, &surface2
, NULL
);
1535 ok(hr
==DDERR_INVALIDCAPS
,"CreateSurface returned: %x\n",hr
);
1536 /* This old ddraw version happily creates explicit front buffers */
1537 memset(&ddsd
, 0, sizeof(ddsd
));
1538 ddsd
.dwSize
= sizeof(ddsd
);
1539 ddsd
.dwFlags
= DDSD_CAPS
;
1540 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
;
1541 hr
= IDirectDraw_CreateSurface(lpDD
, &ddsd
, &surface1
, NULL
);
1542 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
1543 IDirectDrawSurface_Release(surface1
);
1545 /* Try a single primary and two offscreen plain surfaces */
1546 memset(&ddsd
, 0, sizeof(ddsd
));
1547 ddsd
.dwSize
= sizeof(ddsd
);
1548 ddsd
.dwFlags
= DDSD_CAPS
;
1549 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
1550 hr
= IDirectDraw_CreateSurface(lpDD
, &ddsd
, &surface1
, NULL
);
1551 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
1553 memset(&ddsd
, 0, sizeof(ddsd
));
1554 ddsd
.dwSize
= sizeof(ddsd
);
1555 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1556 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
1557 ddsd
.dwWidth
= GetSystemMetrics(SM_CXSCREEN
);
1558 ddsd
.dwHeight
= GetSystemMetrics(SM_CYSCREEN
);
1559 hr
= IDirectDraw_CreateSurface(lpDD
, &ddsd
, &surface2
, NULL
);
1560 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
1562 memset(&ddsd
, 0, sizeof(ddsd
));
1563 ddsd
.dwSize
= sizeof(ddsd
);
1564 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1565 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
1566 ddsd
.dwWidth
= GetSystemMetrics(SM_CXSCREEN
);
1567 ddsd
.dwHeight
= GetSystemMetrics(SM_CYSCREEN
);
1568 hr
= IDirectDraw_CreateSurface(lpDD
, &ddsd
, &surface3
, NULL
);
1569 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
1571 /* This one has a different size */
1572 memset(&ddsd
, 0, sizeof(ddsd
));
1573 ddsd
.dwSize
= sizeof(ddsd
);
1574 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1575 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
1577 ddsd
.dwHeight
= 128;
1578 hr
= IDirectDraw_CreateSurface(lpDD
, &ddsd
, &surface4
, NULL
);
1579 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
1581 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface2
);
1582 ok(hr
== DD_OK
|| broken(hr
== DDERR_CANNOTATTACHSURFACE
),
1583 "Attaching an offscreen plain surface to a front buffer returned %08x\n", hr
);
1586 /* Try the reverse without detaching first */
1587 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface1
);
1588 ok(hr
== DDERR_SURFACEALREADYATTACHED
, "Attaching an attached surface to its attachee returned %08x\n", hr
);
1589 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1
, 0, surface2
);
1590 ok(hr
== DD_OK
, "DeleteAttachedSurface failed with %08x\n", hr
);
1592 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface1
);
1593 ok(hr
== DD_OK
|| broken(hr
== DDERR_CANNOTATTACHSURFACE
),
1594 "Attaching a front buffer to an offscreen plain surface returned %08x\n", hr
);
1597 /* Try to detach reversed */
1598 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1
, 0, surface2
);
1599 ok(hr
== DDERR_CANNOTDETACHSURFACE
, "DeleteAttachedSurface returned %08x\n", hr
);
1600 /* Now the proper detach */
1601 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface2
, 0, surface1
);
1602 ok(hr
== DD_OK
, "DeleteAttachedSurface failed with %08x\n", hr
);
1604 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface3
); /* Fails on refrast */
1605 ok(hr
== DD_OK
|| broken(hr
== DDERR_CANNOTATTACHSURFACE
),
1606 "Attaching an offscreen plain surface to another offscreen plain surface returned %08x\n", hr
);
1609 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface2
, 0, surface3
);
1610 ok(hr
== DD_OK
, "DeleteAttachedSurface failed with %08x\n", hr
);
1612 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface4
);
1613 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching an offscreen plain surface to a front buffer of different size returned %08x\n", hr
);
1614 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface1
);
1615 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a front buffer to an offscreen plain surface of different size returned %08x\n", hr
);
1617 IDirectDrawSurface_Release(surface4
);
1618 IDirectDrawSurface_Release(surface3
);
1619 IDirectDrawSurface_Release(surface2
);
1620 IDirectDrawSurface_Release(surface1
);
1622 hr
=IDirectDraw_SetCooperativeLevel(lpDD
, NULL
, DDSCL_NORMAL
);
1623 ok(hr
== DD_OK
, "SetCooperativeLevel returned %08x\n", hr
);
1625 DestroyWindow(window
);
1630 DWORD width
, height
;
1635 static HRESULT WINAPI
CubeTestLvl2Enum(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*desc
, void *context
)
1637 UINT
*mips
= context
;
1640 IDirectDrawSurface7_EnumAttachedSurfaces(surface
,
1644 return DDENUMRET_OK
;
1647 static HRESULT WINAPI
CubeTestLvl1Enum(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*desc
, void *context
)
1650 UINT
*num
= context
;
1651 static const struct compare expected
[] =
1655 DDSCAPS_MIPMAP
| DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_COMPLEX
,
1656 DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_NEGATIVEZ
,
1661 DDSCAPS_MIPMAP
| DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_COMPLEX
,
1662 DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_POSITIVEZ
,
1667 DDSCAPS_MIPMAP
| DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_COMPLEX
,
1668 DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_NEGATIVEY
,
1673 DDSCAPS_MIPMAP
| DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_COMPLEX
,
1674 DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_POSITIVEY
,
1679 DDSCAPS_MIPMAP
| DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_COMPLEX
,
1680 DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_NEGATIVEX
,
1684 64, 64, /* This is the first mipmap */
1685 DDSCAPS_MIPMAP
| DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_COMPLEX
,
1686 DDSCAPS2_MIPMAPSUBLEVEL
| DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_POSITIVEX
,
1692 IDirectDrawSurface7_EnumAttachedSurfaces(surface
,
1696 ok(desc
->dwWidth
== expected
[*num
].width
, "Surface width is %d expected %d\n", desc
->dwWidth
, expected
[*num
].width
);
1697 ok(desc
->dwHeight
== expected
[*num
].height
, "Surface height is %d expected %d\n", desc
->dwHeight
, expected
[*num
].height
);
1698 ok(desc
->ddsCaps
.dwCaps
== expected
[*num
].caps
, "Surface caps are %08x expected %08x\n", desc
->ddsCaps
.dwCaps
, expected
[*num
].caps
);
1699 ok(desc
->ddsCaps
.dwCaps2
== expected
[*num
].caps2
, "Surface caps2 are %08x expected %08x\n", desc
->ddsCaps
.dwCaps2
, expected
[*num
].caps2
);
1700 ok(mips
== expected
[*num
].mips
, "Surface has %d mipmaps, expected %d\n", mips
, expected
[*num
].mips
);
1704 IDirectDrawSurface7_Release(surface
);
1706 return DDENUMRET_OK
;
1709 static void CubeMapTest(void)
1711 IDirectDraw7
*dd7
= NULL
;
1712 IDirectDrawSurface7
*cubemap
= NULL
;
1713 DDSURFACEDESC2 ddsd
;
1716 struct enumstruct ctx
;
1718 hr
= IDirectDraw_QueryInterface(lpDD
, &IID_IDirectDraw7
, (void **) &dd7
);
1719 ok(hr
== DD_OK
, "IDirectDraw::QueryInterface returned %08x\n", hr
);
1720 if (FAILED(hr
)) goto err
;
1722 memset(&ddsd
, 0, sizeof(ddsd
));
1723 ddsd
.dwSize
= sizeof(ddsd
);
1724 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
1725 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CAPS
;
1727 ddsd
.dwHeight
= 128;
1728 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
| DDSCAPS_SYSTEMMEMORY
;
1729 ddsd
.ddsCaps
.dwCaps2
= DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_ALLFACES
;
1732 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
1733 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 16;
1734 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0xF800;
1735 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x07E0;
1736 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x001F;
1738 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd
, &cubemap
, NULL
);
1741 skip("Can't create cubemap surface\n");
1745 hr
= IDirectDrawSurface7_GetSurfaceDesc(cubemap
, &ddsd
);
1746 ok(hr
== DD_OK
, "IDirectDrawSurface7_GetSurfaceDesc returned %08x\n", hr
);
1747 ok(ddsd
.ddsCaps
.dwCaps
== (DDSCAPS_MIPMAP
| DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_COMPLEX
),
1748 "Root Caps are %08x\n", ddsd
.ddsCaps
.dwCaps
);
1749 ok(ddsd
.ddsCaps
.dwCaps2
== (DDSCAPS2_CUBEMAP_POSITIVEX
| DDSCAPS2_CUBEMAP
),
1750 "Root Caps2 are %08x\n", ddsd
.ddsCaps
.dwCaps2
);
1752 IDirectDrawSurface7_EnumAttachedSurfaces(cubemap
,
1755 ok(num
== 6, "Surface has %d attachments\n", num
);
1756 IDirectDrawSurface7_Release(cubemap
);
1758 /* What happens if I do not specify any faces? */
1759 memset(&ddsd
, 0, sizeof(ddsd
));
1760 ddsd
.dwSize
= sizeof(ddsd
);
1761 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
1762 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CAPS
;
1764 ddsd
.dwHeight
= 128;
1765 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
| DDSCAPS_SYSTEMMEMORY
;
1766 ddsd
.ddsCaps
.dwCaps2
= DDSCAPS2_CUBEMAP
;
1769 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
1770 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 16;
1771 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0xF800;
1772 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x07E0;
1773 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x001F;
1775 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd
, &cubemap
, NULL
);
1776 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDraw7::CreateSurface asking for a cube map without faces returned %08x\n", hr
);
1778 /* Cube map faces without a cube map? */
1779 memset(&ddsd
, 0, sizeof(ddsd
));
1780 ddsd
.dwSize
= sizeof(ddsd
);
1781 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
1782 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CAPS
;
1784 ddsd
.dwHeight
= 128;
1785 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
| DDSCAPS_SYSTEMMEMORY
;
1786 ddsd
.ddsCaps
.dwCaps2
= DDSCAPS2_CUBEMAP_ALLFACES
;
1789 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
1790 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 16;
1791 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0xF800;
1792 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x07E0;
1793 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x001F;
1795 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd
, &cubemap
, NULL
);
1796 ok(hr
== DDERR_INVALIDCAPS
, "IDirectDraw7::CreateSurface returned %08x\n", hr
);
1798 memset(&ddsd
, 0, sizeof(ddsd
));
1799 ddsd
.dwSize
= sizeof(ddsd
);
1800 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
1801 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CAPS
;
1803 ddsd
.dwHeight
= 128;
1804 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
| DDSCAPS_SYSTEMMEMORY
;
1805 ddsd
.ddsCaps
.dwCaps2
= DDSCAPS2_CUBEMAP_POSITIVEX
;
1808 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
1809 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 16;
1810 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0xF800;
1811 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x07E0;
1812 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x001F;
1814 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd
, &cubemap
, NULL
);
1815 ok(hr
== DDERR_INVALIDCAPS
, "IDirectDraw7::CreateSurface returned %08x\n", hr
);
1817 /* Make sure everything is cleaned up properly. Use the enumSurfaces test infrastructure */
1818 memset(&ctx
, 0, sizeof(ctx
));
1819 memset(&ddsd
, 0, sizeof(ddsd
));
1820 ddsd
.dwSize
= sizeof(DDSURFACEDESC
);
1821 hr
= IDirectDraw_EnumSurfaces(lpDD
, DDENUMSURFACES_DOESEXIST
| DDENUMSURFACES_ALL
, (DDSURFACEDESC
*) &ddsd
, (void *) &ctx
, enumCB
);
1822 ok(hr
== DD_OK
, "IDirectDraw_EnumSurfaces returned %08x\n", hr
);
1823 ok(ctx
.count
== 0, "%d surfaces enumerated, expected 0\n", ctx
.count
);
1826 if (dd7
) IDirectDraw7_Release(dd7
);
1829 static void test_lockrect_invalid(void)
1842 {68, 60, 60, 68}, /* left > right */
1843 {60, 68, 68, 60}, /* top > bottom */
1844 {-8, 60, 0, 68}, /* left < surface */
1845 {60, -8, 68, 0}, /* top < surface */
1846 {-16, 60, -8, 68}, /* right < surface */
1847 {60, -16, 68, -8}, /* bottom < surface */
1848 {60, 60, 136, 68}, /* right > surface */
1849 {60, 60, 68, 136}, /* bottom > surface */
1850 {136, 60, 144, 68}, /* left > surface */
1851 {60, 136, 68, 144}, /* top > surface */
1854 const DWORD dds_caps
[] = {
1855 DDSCAPS_OFFSCREENPLAIN
1858 for (j
= 0; j
< (sizeof(dds_caps
) / sizeof(*dds_caps
)); ++j
)
1860 IDirectDrawSurface
*surface
= 0;
1861 DDSURFACEDESC surface_desc
= {0};
1862 DDSURFACEDESC locked_desc
= {0};
1865 surface_desc
.dwSize
= sizeof(surface_desc
);
1866 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
1867 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
1868 surface_desc
.ddsCaps
.dwCaps
= dds_caps
[j
];
1869 surface_desc
.dwWidth
= 128;
1870 surface_desc
.dwHeight
= 128;
1871 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
1872 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
1873 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0xFF0000;
1874 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x00FF00;
1875 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x0000FF;
1877 hr
= IDirectDraw_CreateSurface(lpDD
, &surface_desc
, &surface
, NULL
);
1878 ok(SUCCEEDED(hr
), "CreateSurface failed (0x%08x)\n", hr
);
1881 skip("failed to create surface\n");
1885 for (i
= 0; i
< (sizeof(valid
) / sizeof(*valid
)); ++i
)
1887 RECT
*rect
= &valid
[i
];
1889 memset(&locked_desc
, 0, sizeof(locked_desc
));
1890 locked_desc
.dwSize
= sizeof(locked_desc
);
1892 hr
= IDirectDrawSurface_Lock(surface
, rect
, &locked_desc
, DDLOCK_WAIT
, NULL
);
1893 ok(SUCCEEDED(hr
), "Lock failed (0x%08x) for rect [%d, %d]->[%d, %d]\n",
1894 hr
, rect
->left
, rect
->top
, rect
->right
, rect
->bottom
);
1896 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
1897 ok(SUCCEEDED(hr
), "Unlock failed (0x%08x)\n", hr
);
1900 for (i
= 0; i
< (sizeof(invalid
) / sizeof(*invalid
)); ++i
)
1902 RECT
*rect
= &invalid
[i
];
1904 memset(&locked_desc
, 1, sizeof(locked_desc
));
1905 locked_desc
.dwSize
= sizeof(locked_desc
);
1907 hr
= IDirectDrawSurface_Lock(surface
, rect
, &locked_desc
, DDLOCK_WAIT
, NULL
);
1908 ok(hr
== DDERR_INVALIDPARAMS
, "Lock returned 0x%08x for rect [%d, %d]->[%d, %d]"
1909 ", expected DDERR_INVALIDPARAMS (0x%08x)\n", hr
, rect
->left
, rect
->top
,
1910 rect
->right
, rect
->bottom
, DDERR_INVALIDPARAMS
);
1911 ok(!locked_desc
.lpSurface
, "IDirectDrawSurface_Lock did not set lpSurface in the surface desc to zero.\n");
1914 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &locked_desc
, DDLOCK_WAIT
, NULL
);
1915 ok(hr
== DD_OK
, "IDirectDrawSurface_Lock(rect = NULL) failed (0x%08x)\n", hr
);
1916 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &locked_desc
, DDLOCK_WAIT
, NULL
);
1917 ok(hr
== DDERR_SURFACEBUSY
, "Double lock(rect = NULL) returned 0x%08x\n", hr
);
1919 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
1920 ok(SUCCEEDED(hr
), "Unlock failed (0x%08x)\n", hr
);
1922 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
1923 ok(SUCCEEDED(hr
), "Unlock failed (0x%08x)\n", hr
);
1925 memset(&locked_desc
, 0, sizeof(locked_desc
));
1926 locked_desc
.dwSize
= sizeof(locked_desc
);
1927 hr
= IDirectDrawSurface_Lock(surface
, &valid
[0], &locked_desc
, DDLOCK_WAIT
, NULL
);
1928 ok(hr
== DD_OK
, "IDirectDrawSurface_Lock(rect = [%d, %d]->[%d, %d]) failed (0x%08x)\n",
1929 valid
[0].left
, valid
[0].top
, valid
[0].right
, valid
[0].bottom
, hr
);
1930 hr
= IDirectDrawSurface_Lock(surface
, &valid
[0], &locked_desc
, DDLOCK_WAIT
, NULL
);
1931 ok(hr
== DDERR_SURFACEBUSY
, "Double lock(rect = [%d, %d]->[%d, %d]) failed (0x%08x)\n",
1932 valid
[0].left
, valid
[0].top
, valid
[0].right
, valid
[0].bottom
, hr
);
1934 /* Locking a different rectangle returns DD_OK, but it seems to break the surface.
1935 * Afterwards unlocking the surface fails(NULL rectangle, and both locked rectangles
1938 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
1939 ok(hr
== DD_OK
, "Unlock returned (0x%08x)\n", hr
);
1941 IDirectDrawSurface_Release(surface
);
1945 static void CompressedTest(void)
1948 IDirectDrawSurface7
*surface
;
1949 DDSURFACEDESC2 ddsd
, ddsd2
;
1950 IDirectDraw7
*dd7
= NULL
;
1951 RECT r
= { 0, 0, 128, 128 };
1952 RECT r2
= { 32, 32, 64, 64 };
1954 hr
= IDirectDraw_QueryInterface(lpDD
, &IID_IDirectDraw7
, (void **) &dd7
);
1955 ok(hr
== DD_OK
, "IDirectDraw::QueryInterface returned %08x\n", hr
);
1957 memset(&ddsd
, 0, sizeof(ddsd
));
1958 ddsd
.dwSize
= sizeof(ddsd
);
1959 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
1960 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CAPS
;
1962 ddsd
.dwHeight
= 128;
1963 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
;
1964 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_FOURCC
;
1965 U4(ddsd
).ddpfPixelFormat
.dwFourCC
= MAKEFOURCC('D','X','T','1');
1967 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd
, &surface
, NULL
);
1968 ok(hr
== DD_OK
, "CreateSurface returned %08x\n", hr
);
1971 skip("failed to create surface\n");
1975 memset(&ddsd2
, 0, sizeof(ddsd2
));
1976 ddsd2
.dwSize
= sizeof(ddsd2
);
1977 U4(ddsd2
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd2
).ddpfPixelFormat
);
1978 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd2
);
1979 ok(hr
== DD_OK
, "GetSurfaceDesc returned %08x\n", hr
);
1981 ok(ddsd2
.dwFlags
== (DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_LINEARSIZE
),
1982 "Surface desc flags: %08x\n", ddsd2
.dwFlags
);
1983 ok(U4(ddsd2
).ddpfPixelFormat
.dwFlags
== DDPF_FOURCC
, "Pixel format flags: %08x\n", U4(ddsd2
).ddpfPixelFormat
.dwFlags
);
1984 ok(U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
== 0, "RGB bitcount: %08x\n", U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
);
1985 ok(ddsd2
.ddsCaps
.dwCaps
== (DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
),
1986 "Surface caps flags: %08x\n", ddsd2
.ddsCaps
.dwCaps
);
1987 ok(U1(ddsd2
).dwLinearSize
== 8192, "Linear size is %d\n", U1(ddsd2
).dwLinearSize
);
1988 ok(ddsd2
.ddsCaps
.dwCaps2
== 0, "Caps2: %08x\n", ddsd2
.ddsCaps
.dwCaps2
);
1989 IDirectDrawSurface7_Release(surface
);
1991 U4(ddsd
).ddpfPixelFormat
.dwFourCC
= MAKEFOURCC('D','X','T','3');
1992 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd
, &surface
, NULL
);
1993 ok(hr
== DD_OK
, "CreateSurface returned %08x\n", hr
);
1996 skip("failed to create surface\n");
2000 memset(&ddsd2
, 0, sizeof(ddsd2
));
2001 ddsd2
.dwSize
= sizeof(ddsd2
);
2002 U4(ddsd2
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd2
).ddpfPixelFormat
);
2003 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd2
);
2004 ok(hr
== DD_OK
, "GetSurfaceDesc returned %08x\n", hr
);
2006 ok(ddsd2
.dwFlags
== (DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_LINEARSIZE
),
2007 "Surface desc flags: %08x\n", ddsd2
.dwFlags
);
2008 ok(U4(ddsd2
).ddpfPixelFormat
.dwFlags
== DDPF_FOURCC
, "Pixel format flags: %08x\n", U4(ddsd2
).ddpfPixelFormat
.dwFlags
);
2009 ok(U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
== 0, "RGB bitcount: %08x\n", U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
);
2010 ok(ddsd2
.ddsCaps
.dwCaps
== (DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
),
2011 "Surface caps flags: %08x\n", ddsd2
.ddsCaps
.dwCaps
);
2012 ok(U1(ddsd2
).dwLinearSize
== 16384, "Linear size is %d\n", U1(ddsd2
).dwLinearSize
);
2013 IDirectDrawSurface7_Release(surface
);
2015 U4(ddsd
).ddpfPixelFormat
.dwFourCC
= MAKEFOURCC('D','X','T','5');
2016 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd
, &surface
, NULL
);
2017 ok(hr
== DD_OK
, "CreateSurface returned %08x\n", hr
);
2020 skip("failed to create surface\n");
2024 memset(&ddsd2
, 0, sizeof(ddsd2
));
2025 ddsd2
.dwSize
= sizeof(ddsd2
);
2026 U4(ddsd2
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd2
).ddpfPixelFormat
);
2027 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd2
);
2028 ok(hr
== DD_OK
, "GetSurfaceDesc returned %08x\n", hr
);
2030 ok(ddsd2
.dwFlags
== (DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_LINEARSIZE
),
2031 "Surface desc flags: %08x\n", ddsd2
.dwFlags
);
2032 ok(U4(ddsd2
).ddpfPixelFormat
.dwFlags
== DDPF_FOURCC
, "Pixel format flags: %08x\n", U4(ddsd2
).ddpfPixelFormat
.dwFlags
);
2033 ok(U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
== 0, "RGB bitcount: %08x\n", U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
);
2034 ok(ddsd2
.ddsCaps
.dwCaps
== (DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
),
2035 "Surface caps flags: %08x\n", ddsd2
.ddsCaps
.dwCaps
);
2036 ok(U1(ddsd2
).dwLinearSize
== 16384, "Linear size is %d\n", U1(ddsd2
).dwLinearSize
);
2037 ok(ddsd2
.lpSurface
== 0, "Surface memory is at %p, expected NULL\n", ddsd2
.lpSurface
);
2039 memset(&ddsd2
, 0, sizeof(ddsd2
));
2040 ddsd2
.dwSize
= sizeof(ddsd2
);
2041 U4(ddsd2
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd2
).ddpfPixelFormat
);
2043 /* Show that the description is not changed when locking the surface. What is really interesting
2044 * about this is that DDSD_LPSURFACE isn't set.
2046 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &ddsd2
, DDLOCK_READONLY
, 0);
2047 ok(hr
== DD_OK
, "Lock returned %08x\n", hr
);
2049 ok(ddsd2
.dwFlags
== (DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_LINEARSIZE
),
2050 "Surface desc flags: %08x\n", ddsd2
.dwFlags
);
2051 ok(U4(ddsd2
).ddpfPixelFormat
.dwFlags
== DDPF_FOURCC
, "Pixel format flags: %08x\n", U4(ddsd2
).ddpfPixelFormat
.dwFlags
);
2052 ok(U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
== 0, "RGB bitcount: %08x\n", U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
);
2053 ok(ddsd2
.ddsCaps
.dwCaps
== (DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
),
2054 "Surface caps flags: %08x\n", ddsd2
.ddsCaps
.dwCaps
);
2055 ok(U1(ddsd2
).dwLinearSize
== 16384, "Linear size is %d\n", U1(ddsd2
).dwLinearSize
);
2056 ok(ddsd2
.lpSurface
!= 0, "Surface memory is at NULL\n");
2058 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
2059 ok(hr
== DD_OK
, "Unlock returned %08x\n", hr
);
2061 /* Now what about a locking rect? */
2062 hr
= IDirectDrawSurface7_Lock(surface
, &r
, &ddsd2
, DDLOCK_READONLY
, 0);
2063 ok(hr
== DD_OK
, "Lock returned %08x\n", hr
);
2065 ok(ddsd2
.dwFlags
== (DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_LINEARSIZE
),
2066 "Surface desc flags: %08x\n", ddsd2
.dwFlags
);
2067 ok(U4(ddsd2
).ddpfPixelFormat
.dwFlags
== DDPF_FOURCC
, "Pixel format flags: %08x\n", U4(ddsd2
).ddpfPixelFormat
.dwFlags
);
2068 ok(U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
== 0, "RGB bitcount: %08x\n", U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
);
2069 ok(ddsd2
.ddsCaps
.dwCaps
== (DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
),
2070 "Surface caps flags: %08x\n", ddsd2
.ddsCaps
.dwCaps
);
2071 ok(U1(ddsd2
).dwLinearSize
== 16384, "Linear size is %d\n", U1(ddsd2
).dwLinearSize
);
2072 ok(ddsd2
.lpSurface
!= 0, "Surface memory is at NULL\n");
2074 hr
= IDirectDrawSurface7_Unlock(surface
, &r
);
2075 ok(hr
== DD_OK
, "Unlock returned %08x\n", hr
);
2077 /* Now what about a different locking offset? */
2078 hr
= IDirectDrawSurface7_Lock(surface
, &r2
, &ddsd2
, DDLOCK_READONLY
, 0);
2079 ok(hr
== DD_OK
, "Lock returned %08x\n", hr
);
2081 ok(ddsd2
.dwFlags
== (DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_LINEARSIZE
),
2082 "Surface desc flags: %08x\n", ddsd2
.dwFlags
);
2083 ok(U4(ddsd2
).ddpfPixelFormat
.dwFlags
== DDPF_FOURCC
, "Pixel format flags: %08x\n", U4(ddsd2
).ddpfPixelFormat
.dwFlags
);
2084 ok(U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
== 0, "RGB bitcount: %08x\n", U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
);
2085 ok(ddsd2
.ddsCaps
.dwCaps
== (DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
),
2086 "Surface caps flags: %08x\n", ddsd2
.ddsCaps
.dwCaps
);
2087 ok(U1(ddsd2
).dwLinearSize
== 16384, "Linear size is %d\n", U1(ddsd2
).dwLinearSize
);
2088 ok(ddsd2
.lpSurface
!= 0, "Surface memory is at NULL\n");
2090 hr
= IDirectDrawSurface7_Unlock(surface
, &r2
);
2091 ok(hr
== DD_OK
, "Unlock returned %08x\n", hr
);
2092 IDirectDrawSurface7_Release(surface
);
2094 /* Try this with video memory. A kind of surprise. It still has the LINEARSIZE flag set,
2095 * but seems to have a pitch instead.
2097 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
;
2098 U4(ddsd
).ddpfPixelFormat
.dwFourCC
= MAKEFOURCC('D','X','T','1');
2100 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd
, &surface
, NULL
);
2101 ok(hr
== DD_OK
|| hr
== DDERR_NOTEXTUREHW
|| hr
== DDERR_INVALIDPARAMS
||
2102 broken(hr
== DDERR_NODIRECTDRAWHW
), "CreateSurface returned %08x\n", hr
);
2104 /* Not supported everywhere */
2107 memset(&ddsd2
, 0, sizeof(ddsd2
));
2108 ddsd2
.dwSize
= sizeof(ddsd2
);
2109 U4(ddsd2
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd2
).ddpfPixelFormat
);
2110 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd2
);
2111 ok(hr
== DD_OK
, "GetSurfaceDesc returned %08x\n", hr
);
2113 ok(ddsd2
.dwFlags
== (DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_LINEARSIZE
),
2114 "Surface desc flags: %08x\n", ddsd2
.dwFlags
);
2115 ok(U4(ddsd2
).ddpfPixelFormat
.dwFlags
== DDPF_FOURCC
, "Pixel format flags: %08x\n", U4(ddsd2
).ddpfPixelFormat
.dwFlags
);
2116 ok(U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
== 0, "RGB bitcount: %08x\n", U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
);
2117 ok(ddsd2
.ddsCaps
.dwCaps
== (DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
),
2118 "Surface caps flags: %08x\n", ddsd2
.ddsCaps
.dwCaps
);
2119 /* ATI drivers report a broken linear size, thus no need to clone the exact behaviour. nvidia reports the correct size */
2120 ok(ddsd2
.ddsCaps
.dwCaps2
== 0, "Caps2: %08x\n", ddsd2
.ddsCaps
.dwCaps2
);
2121 IDirectDrawSurface7_Release(surface
);
2123 U4(ddsd
).ddpfPixelFormat
.dwFourCC
= MAKEFOURCC('D','X','T','3');
2124 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd
, &surface
, NULL
);
2125 ok(hr
== DD_OK
, "CreateSurface returned %08x\n", hr
);
2127 memset(&ddsd2
, 0, sizeof(ddsd2
));
2128 ddsd2
.dwSize
= sizeof(ddsd2
);
2129 U4(ddsd2
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd2
).ddpfPixelFormat
);
2130 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd2
);
2131 ok(hr
== DD_OK
, "GetSurfaceDesc returned %08x\n", hr
);
2133 ok(ddsd2
.dwFlags
== (DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_LINEARSIZE
),
2134 "Surface desc flags: %08x\n", ddsd2
.dwFlags
);
2135 ok(U4(ddsd2
).ddpfPixelFormat
.dwFlags
== DDPF_FOURCC
, "Pixel format flags: %08x\n", U4(ddsd2
).ddpfPixelFormat
.dwFlags
);
2136 ok(U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
== 0, "RGB bitcount: %08x\n", U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
);
2137 ok(ddsd2
.ddsCaps
.dwCaps
== (DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
),
2138 "Surface caps flags: %08x\n", ddsd2
.ddsCaps
.dwCaps
);
2139 /* ATI drivers report a broken linear size, thus no need to clone the exact behaviour. nvidia reports the correct size */
2140 IDirectDrawSurface7_Release(surface
);
2142 U4(ddsd
).ddpfPixelFormat
.dwFourCC
= MAKEFOURCC('D','X','T','5');
2143 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd
, &surface
, NULL
);
2144 ok(hr
== DD_OK
, "CreateSurface returned %08x\n", hr
);
2146 memset(&ddsd2
, 0, sizeof(ddsd2
));
2147 ddsd2
.dwSize
= sizeof(ddsd2
);
2148 U4(ddsd2
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd2
).ddpfPixelFormat
);
2149 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd2
);
2150 ok(hr
== DD_OK
, "GetSurfaceDesc returned %08x\n", hr
);
2152 ok(ddsd2
.dwFlags
== (DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_LINEARSIZE
),
2153 "Surface desc flags: %08x\n", ddsd2
.dwFlags
);
2154 ok(U4(ddsd2
).ddpfPixelFormat
.dwFlags
== DDPF_FOURCC
, "Pixel format flags: %08x\n", U4(ddsd2
).ddpfPixelFormat
.dwFlags
);
2155 ok(U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
== 0, "RGB bitcount: %08x\n", U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
);
2156 ok(ddsd2
.ddsCaps
.dwCaps
== (DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
),
2157 "Surface caps flags: %08x\n", ddsd2
.ddsCaps
.dwCaps
);
2158 /* ATI drivers report a broken linear size, thus no need to clone the exact behaviour. nvidia reports the correct size */
2159 ok(ddsd2
.lpSurface
== 0, "Surface memory is at %p, expected NULL\n", ddsd2
.lpSurface
);
2161 memset(&ddsd2
, 0, sizeof(ddsd2
));
2162 ddsd2
.dwSize
= sizeof(ddsd2
);
2163 U4(ddsd2
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd2
).ddpfPixelFormat
);
2165 /* Show that the description is not changed when locking the surface. What is really interesting
2166 * about this is that DDSD_LPSURFACE isn't set.
2168 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &ddsd2
, DDLOCK_READONLY
, 0);
2169 ok(hr
== DD_OK
, "Lock returned %08x\n", hr
);
2171 ok(ddsd2
.dwFlags
== (DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_LINEARSIZE
),
2172 "Surface desc flags: %08x\n", ddsd2
.dwFlags
);
2173 ok(U4(ddsd2
).ddpfPixelFormat
.dwFlags
== DDPF_FOURCC
, "Pixel format flags: %08x\n", U4(ddsd2
).ddpfPixelFormat
.dwFlags
);
2174 ok(U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
== 0, "RGB bitcount: %08x\n", U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
);
2175 ok(ddsd2
.ddsCaps
.dwCaps
== (DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
),
2176 "Surface caps flags: %08x\n", ddsd2
.ddsCaps
.dwCaps
);
2177 /* ATI drivers report a broken linear size, thus no need to clone the exact behaviour. nvidia reports the correct size */
2178 ok(ddsd2
.lpSurface
!= 0, "Surface memory is at NULL\n");
2180 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
2181 ok(hr
== DD_OK
, "Unlock returned %08x\n", hr
);
2183 /* Now what about a locking rect? */
2184 hr
= IDirectDrawSurface7_Lock(surface
, &r
, &ddsd2
, DDLOCK_READONLY
, 0);
2185 ok(hr
== DD_OK
, "Lock returned %08x\n", hr
);
2187 ok(ddsd2
.dwFlags
== (DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_LINEARSIZE
),
2188 "Surface desc flags: %08x\n", ddsd2
.dwFlags
);
2189 ok(U4(ddsd2
).ddpfPixelFormat
.dwFlags
== DDPF_FOURCC
, "Pixel format flags: %08x\n", U4(ddsd2
).ddpfPixelFormat
.dwFlags
);
2190 ok(U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
== 0, "RGB bitcount: %08x\n", U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
);
2191 ok(ddsd2
.ddsCaps
.dwCaps
== (DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
),
2192 "Surface caps flags: %08x\n", ddsd2
.ddsCaps
.dwCaps
);
2193 /* ATI drivers report a broken linear size, thus no need to clone the exact behaviour. nvidia reports the correct size */
2194 ok(ddsd2
.lpSurface
!= 0, "Surface memory is at NULL\n");
2196 hr
= IDirectDrawSurface7_Unlock(surface
, &r
);
2197 ok(hr
== DD_OK
, "Unlock returned %08x\n", hr
);
2199 /* Now what about a different locking offset? */
2200 hr
= IDirectDrawSurface7_Lock(surface
, &r2
, &ddsd2
, DDLOCK_READONLY
, 0);
2201 ok(hr
== DD_OK
, "Lock returned %08x\n", hr
);
2203 ok(ddsd2
.dwFlags
== (DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_LINEARSIZE
),
2204 "Surface desc flags: %08x\n", ddsd2
.dwFlags
);
2205 ok(U4(ddsd2
).ddpfPixelFormat
.dwFlags
== DDPF_FOURCC
, "Pixel format flags: %08x\n", U4(ddsd2
).ddpfPixelFormat
.dwFlags
);
2206 ok(U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
== 0, "RGB bitcount: %08x\n", U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
);
2207 ok(ddsd2
.ddsCaps
.dwCaps
== (DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
),
2208 "Surface caps flags: %08x\n", ddsd2
.ddsCaps
.dwCaps
);
2209 /* ATI drivers report a broken linear size, thus no need to clone the exact behaviour. nvidia reports the correct size */
2210 ok(ddsd2
.lpSurface
!= 0, "Surface memory is at NULL\n");
2212 hr
= IDirectDrawSurface7_Unlock(surface
, &r2
);
2213 ok(hr
== DD_OK
, "Unlock returned %08x\n", hr
);
2215 IDirectDrawSurface7_Release(surface
);
2219 skip("Hardware DXTN textures not supported\n");
2222 /* What happens to managed textures? Interestingly, Windows reports them as being in system
2223 * memory. The linear size fits again.
2225 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
2226 ddsd
.ddsCaps
.dwCaps2
= DDSCAPS2_TEXTUREMANAGE
;
2227 U4(ddsd
).ddpfPixelFormat
.dwFourCC
= MAKEFOURCC('D','X','T','1');
2229 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd
, &surface
, NULL
);
2230 ok(hr
== DD_OK
|| hr
== DDERR_NOTEXTUREHW
, "CreateSurface returned %08x\n", hr
);
2232 /* Not supported everywhere */
2235 memset(&ddsd2
, 0, sizeof(ddsd2
));
2236 ddsd2
.dwSize
= sizeof(ddsd2
);
2237 U4(ddsd2
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd2
).ddpfPixelFormat
);
2238 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd2
);
2239 ok(hr
== DD_OK
, "GetSurfaceDesc returned %08x\n", hr
);
2241 ok(ddsd2
.dwFlags
== (DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_LINEARSIZE
),
2242 "Surface desc flags: %08x\n", ddsd2
.dwFlags
);
2243 ok(U4(ddsd2
).ddpfPixelFormat
.dwFlags
== DDPF_FOURCC
, "Pixel format flags: %08x\n", U4(ddsd2
).ddpfPixelFormat
.dwFlags
);
2244 ok(U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
== 0, "RGB bitcount: %08x\n", U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
);
2245 ok(ddsd2
.ddsCaps
.dwCaps
== (DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
),
2246 "Surface caps flags: %08x\n", ddsd2
.ddsCaps
.dwCaps
);
2247 ok(U1(ddsd2
).dwLinearSize
== 8192, "Linear size is %d\n", U1(ddsd2
).dwLinearSize
);
2248 ok(ddsd2
.ddsCaps
.dwCaps2
== DDSCAPS2_TEXTUREMANAGE
, "Caps2: %08x\n", ddsd2
.ddsCaps
.dwCaps2
);
2249 IDirectDrawSurface7_Release(surface
);
2251 U4(ddsd
).ddpfPixelFormat
.dwFourCC
= MAKEFOURCC('D','X','T','3');
2252 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd
, &surface
, NULL
);
2253 ok(hr
== DD_OK
, "CreateSurface returned %08x\n", hr
);
2255 memset(&ddsd2
, 0, sizeof(ddsd2
));
2256 ddsd2
.dwSize
= sizeof(ddsd2
);
2257 U4(ddsd2
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd2
).ddpfPixelFormat
);
2258 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd2
);
2259 ok(hr
== DD_OK
, "GetSurfaceDesc returned %08x\n", hr
);
2261 ok(ddsd2
.dwFlags
== (DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_LINEARSIZE
),
2262 "Surface desc flags: %08x\n", ddsd2
.dwFlags
);
2263 ok(U4(ddsd2
).ddpfPixelFormat
.dwFlags
== DDPF_FOURCC
, "Pixel format flags: %08x\n", U4(ddsd2
).ddpfPixelFormat
.dwFlags
);
2264 ok(U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
== 0, "RGB bitcount: %08x\n", U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
);
2265 ok(ddsd2
.ddsCaps
.dwCaps
== (DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
),
2266 "Surface caps flags: %08x\n", ddsd2
.ddsCaps
.dwCaps
);
2267 ok(U1(ddsd2
).dwLinearSize
== 16384, "Linear size is %d\n", U1(ddsd2
).dwLinearSize
);
2268 IDirectDrawSurface7_Release(surface
);
2270 U4(ddsd
).ddpfPixelFormat
.dwFourCC
= MAKEFOURCC('D','X','T','5');
2271 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd
, &surface
, NULL
);
2272 ok(hr
== DD_OK
, "CreateSurface returned %08x\n", hr
);
2274 memset(&ddsd2
, 0, sizeof(ddsd2
));
2275 ddsd2
.dwSize
= sizeof(ddsd2
);
2276 U4(ddsd2
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd2
).ddpfPixelFormat
);
2277 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd2
);
2278 ok(hr
== DD_OK
, "GetSurfaceDesc returned %08x\n", hr
);
2280 ok(ddsd2
.dwFlags
== (DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_LINEARSIZE
),
2281 "Surface desc flags: %08x\n", ddsd2
.dwFlags
);
2282 ok(U4(ddsd2
).ddpfPixelFormat
.dwFlags
== DDPF_FOURCC
, "Pixel format flags: %08x\n", U4(ddsd2
).ddpfPixelFormat
.dwFlags
);
2283 ok(U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
== 0, "RGB bitcount: %08x\n", U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
);
2284 ok(ddsd2
.ddsCaps
.dwCaps
== (DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
),
2285 "Surface caps flags: %08x\n", ddsd2
.ddsCaps
.dwCaps
);
2286 ok(U1(ddsd2
).dwLinearSize
== 16384, "Linear size is %d\n", U1(ddsd2
).dwLinearSize
);
2287 ok(ddsd2
.lpSurface
== 0, "Surface memory is at %p, expected NULL\n", ddsd2
.lpSurface
);
2289 memset(&ddsd2
, 0, sizeof(ddsd2
));
2290 ddsd2
.dwSize
= sizeof(ddsd2
);
2291 U4(ddsd2
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd2
).ddpfPixelFormat
);
2293 /* Show that the description is not changed when locking the surface. What is really interesting
2294 * about this is that DDSD_LPSURFACE isn't set.
2296 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &ddsd2
, DDLOCK_READONLY
, 0);
2297 ok(hr
== DD_OK
, "Lock returned %08x\n", hr
);
2299 ok(ddsd2
.dwFlags
== (DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_LINEARSIZE
),
2300 "Surface desc flags: %08x\n", ddsd2
.dwFlags
);
2301 ok(U4(ddsd2
).ddpfPixelFormat
.dwFlags
== DDPF_FOURCC
, "Pixel format flags: %08x\n", U4(ddsd2
).ddpfPixelFormat
.dwFlags
);
2302 ok(U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
== 0, "RGB bitcount: %08x\n", U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
);
2303 ok(ddsd2
.ddsCaps
.dwCaps
== (DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
),
2304 "Surface caps flags: %08x\n", ddsd2
.ddsCaps
.dwCaps
);
2305 ok(U1(ddsd2
).dwLinearSize
== 16384, "Linear size is %d\n", U1(ddsd2
).dwLinearSize
);
2306 ok(ddsd2
.lpSurface
!= 0, "Surface memory is at NULL\n");
2308 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
2309 ok(hr
== DD_OK
, "Unlock returned %08x\n", hr
);
2311 /* Now what about a locking rect? */
2312 hr
= IDirectDrawSurface7_Lock(surface
, &r
, &ddsd2
, DDLOCK_READONLY
, 0);
2313 ok(hr
== DD_OK
, "Lock returned %08x\n", hr
);
2315 ok(ddsd2
.dwFlags
== (DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_LINEARSIZE
),
2316 "Surface desc flags: %08x\n", ddsd2
.dwFlags
);
2317 ok(U4(ddsd2
).ddpfPixelFormat
.dwFlags
== DDPF_FOURCC
, "Pixel format flags: %08x\n", U4(ddsd2
).ddpfPixelFormat
.dwFlags
);
2318 ok(U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
== 0, "RGB bitcount: %08x\n", U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
);
2319 ok(ddsd2
.ddsCaps
.dwCaps
== (DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
),
2320 "Surface caps flags: %08x\n", ddsd2
.ddsCaps
.dwCaps
);
2321 ok(U1(ddsd2
).dwLinearSize
== 16384, "\"Linear\" size is %d\n", U1(ddsd2
).dwLinearSize
);
2322 ok(ddsd2
.lpSurface
!= 0, "Surface memory is at NULL\n");
2324 hr
= IDirectDrawSurface7_Unlock(surface
, &r
);
2325 ok(hr
== DD_OK
, "Unlock returned %08x\n", hr
);
2327 /* Now what about a different locking offset? */
2328 hr
= IDirectDrawSurface7_Lock(surface
, &r2
, &ddsd2
, DDLOCK_READONLY
, 0);
2329 ok(hr
== DD_OK
, "Lock returned %08x\n", hr
);
2331 ok(ddsd2
.dwFlags
== (DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_LINEARSIZE
),
2332 "Surface desc flags: %08x\n", ddsd2
.dwFlags
);
2333 ok(U4(ddsd2
).ddpfPixelFormat
.dwFlags
== DDPF_FOURCC
, "Pixel format flags: %08x\n", U4(ddsd2
).ddpfPixelFormat
.dwFlags
);
2334 ok(U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
== 0, "RGB bitcount: %08x\n", U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
);
2335 ok(ddsd2
.ddsCaps
.dwCaps
== (DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
),
2336 "Surface caps flags: %08x\n", ddsd2
.ddsCaps
.dwCaps
);
2337 ok(U1(ddsd2
).dwLinearSize
== 16384, "\"Linear\" size is %d\n", U1(ddsd2
).dwLinearSize
);
2338 ok(ddsd2
.lpSurface
!= 0, "Surface memory is at NULL\n");
2340 hr
= IDirectDrawSurface7_Unlock(surface
, &r2
);
2341 ok(hr
== DD_OK
, "Unlock returned %08x\n", hr
);
2343 IDirectDrawSurface7_Release(surface
);
2347 skip("Hardware DXTN textures not supported\n");
2350 IDirectDraw7_Release(dd7
);
2353 static void SizeTest(void)
2355 LPDIRECTDRAWSURFACE dsurface
= NULL
;
2358 HWND window
= CreateWindow( "static", "ddraw_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
2360 /* Create an offscreen surface surface without a size */
2361 ZeroMemory(&desc
, sizeof(desc
));
2362 desc
.dwSize
= sizeof(desc
);
2363 desc
.dwFlags
= DDSD_CAPS
;
2364 desc
.ddsCaps
.dwCaps
|= DDSCAPS_OFFSCREENPLAIN
;
2365 ret
= IDirectDraw_CreateSurface(lpDD
, &desc
, &dsurface
, NULL
);
2366 ok(ret
== DDERR_INVALIDPARAMS
, "Creating an offscreen plain surface without a size info returned %08x (dsurface=%p)\n", ret
, dsurface
);
2369 trace("Surface at %p\n", dsurface
);
2370 IDirectDrawSurface_Release(dsurface
);
2374 /* Create an offscreen surface surface with only a width parameter */
2375 ZeroMemory(&desc
, sizeof(desc
));
2376 desc
.dwSize
= sizeof(desc
);
2377 desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
;
2378 desc
.ddsCaps
.dwCaps
|= DDSCAPS_OFFSCREENPLAIN
;
2380 ret
= IDirectDraw_CreateSurface(lpDD
, &desc
, &dsurface
, NULL
);
2381 ok(ret
== DDERR_INVALIDPARAMS
, "Creating an offscreen plain surface without height info returned %08x\n", ret
);
2384 IDirectDrawSurface_Release(dsurface
);
2388 /* Create an offscreen surface surface with only a height parameter */
2389 ZeroMemory(&desc
, sizeof(desc
));
2390 desc
.dwSize
= sizeof(desc
);
2391 desc
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
;
2392 desc
.ddsCaps
.dwCaps
|= DDSCAPS_OFFSCREENPLAIN
;
2393 desc
.dwHeight
= 128;
2394 ret
= IDirectDraw_CreateSurface(lpDD
, &desc
, &dsurface
, NULL
);
2395 ok(ret
== DDERR_INVALIDPARAMS
, "Creating an offscreen plain surface without width info returned %08x\n", ret
);
2398 IDirectDrawSurface_Release(dsurface
);
2402 /* Test 0 height. */
2403 memset(&desc
, 0, sizeof(desc
));
2404 desc
.dwSize
= sizeof(desc
);
2405 desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
2406 desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
2409 ret
= IDirectDraw_CreateSurface(lpDD
, &desc
, &dsurface
, NULL
);
2410 ok(ret
== DDERR_INVALIDPARAMS
, "Creating a 0 height surface returned %#x, expected DDERR_INVALIDPARAMS.\n", ret
);
2411 if (SUCCEEDED(ret
)) IDirectDrawSurface_Release(dsurface
);
2415 memset(&desc
, 0, sizeof(desc
));
2416 desc
.dwSize
= sizeof(desc
);
2417 desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
2418 desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
2421 ret
= IDirectDraw_CreateSurface(lpDD
, &desc
, &dsurface
, NULL
);
2422 ok(ret
== DDERR_INVALIDPARAMS
, "Creating a 0 width surface returned %#x, expected DDERR_INVALIDPARAMS.\n", ret
);
2423 if (SUCCEEDED(ret
)) IDirectDrawSurface_Release(dsurface
);
2427 ZeroMemory(&desc
, sizeof(desc
));
2428 desc
.dwSize
= sizeof(desc
);
2429 desc
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
;
2430 desc
.ddsCaps
.dwCaps
|= DDSCAPS_OFFSCREENPLAIN
;
2431 desc
.dwHeight
= 128;
2433 ret
= IDirectDraw_CreateSurface(lpDD
, &desc
, &dsurface
, NULL
);
2434 ok(ret
== DD_OK
, "Creating an offscreen plain surface with width and height info returned %08x\n", ret
);
2437 IDirectDrawSurface_Release(dsurface
);
2441 /* Test a primary surface size */
2442 ret
= IDirectDraw_SetCooperativeLevel(lpDD
, window
, DDSCL_NORMAL
);
2443 ok(ret
== DD_OK
, "SetCooperativeLevel failed with %08x\n", ret
);
2445 ZeroMemory(&desc
, sizeof(desc
));
2446 desc
.dwSize
= sizeof(desc
);
2447 desc
.dwFlags
= DDSD_CAPS
;
2448 desc
.ddsCaps
.dwCaps
|= DDSCAPS_PRIMARYSURFACE
;
2449 desc
.dwHeight
= 128; /* Keep them set to check what happens */
2450 desc
.dwWidth
= 128; /* Keep them set to check what happens */
2451 ret
= IDirectDraw_CreateSurface(lpDD
, &desc
, &dsurface
, NULL
);
2452 ok(ret
== DD_OK
, "Creating a primary surface without width and height info returned %08x\n", ret
);
2455 ret
= IDirectDrawSurface_GetSurfaceDesc(dsurface
, &desc
);
2456 ok(ret
== DD_OK
, "GetSurfaceDesc returned %x\n", ret
);
2458 IDirectDrawSurface_Release(dsurface
);
2461 ok(desc
.dwFlags
& DDSD_WIDTH
, "Primary surface doesn't have width set\n");
2462 ok(desc
.dwFlags
& DDSD_HEIGHT
, "Primary surface doesn't have height set\n");
2463 ok(desc
.dwWidth
== GetSystemMetrics(SM_CXSCREEN
), "Surface width differs from screen width\n");
2464 ok(desc
.dwHeight
== GetSystemMetrics(SM_CYSCREEN
), "Surface height differs from screen height\n");
2466 ret
= IDirectDraw_SetCooperativeLevel(lpDD
, NULL
, DDSCL_NORMAL
);
2467 ok(ret
== DD_OK
, "SetCooperativeLevel failed with %08x\n", ret
);
2470 static void PrivateDataTest(void)
2473 IDirectDrawSurface7
*surface7
= NULL
;
2474 IDirectDrawSurface
*surface
= NULL
;
2478 DWORD size
= sizeof(IUnknown
*);
2480 ZeroMemory(&desc
, sizeof(desc
));
2481 desc
.dwSize
= sizeof(desc
);
2482 desc
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
;
2483 desc
.ddsCaps
.dwCaps
|= DDSCAPS_OFFSCREENPLAIN
;
2484 desc
.dwHeight
= 128;
2486 hr
= IDirectDraw_CreateSurface(lpDD
, &desc
, &surface
, NULL
);
2487 ok(hr
== DD_OK
, "Creating an offscreen plain surface failed with %08x\n", hr
);
2492 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirectDrawSurface7
, (void **) &surface7
);
2493 ok(hr
== DD_OK
, "IDirectDrawSurface_QueryInterface failed with %08x\n", hr
);
2496 IDirectDrawSurface_Release(surface
);
2501 hr
= IDirectDrawSurface7_SetPrivateData(surface7
, &IID_IDirectDrawSurface7
/* Abuse this tag */, lpDD
, 0, DDSPD_IUNKNOWNPOINTER
);
2502 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr
);
2503 hr
= IDirectDrawSurface7_SetPrivateData(surface7
, &IID_IDirectDrawSurface7
/* Abuse this tag */, lpDD
, 5, DDSPD_IUNKNOWNPOINTER
);
2504 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr
);
2505 hr
= IDirectDrawSurface7_SetPrivateData(surface7
, &IID_IDirectDrawSurface7
/* Abuse this tag */, lpDD
, sizeof(IUnknown
*) * 2, DDSPD_IUNKNOWNPOINTER
);
2506 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr
);
2508 ref
= getref((IUnknown
*) lpDD
);
2509 hr
= IDirectDrawSurface7_SetPrivateData(surface7
, &IID_IDirectDrawSurface7
/* Abuse this tag */, lpDD
, sizeof(IUnknown
*), DDSPD_IUNKNOWNPOINTER
);
2510 ok(hr
== DD_OK
, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr
);
2511 ref2
= getref((IUnknown
*) lpDD
);
2512 ok(ref2
== ref
+ 1, "Object reference is %d, expected %d\n", ref2
, ref
+ 1);
2513 hr
= IDirectDrawSurface7_FreePrivateData(surface7
, &IID_IDirectDrawSurface7
);
2514 ok(SUCCEEDED(hr
), "IDirectDrawSurface7_FreePrivateData returned %#x.\n", hr
);
2515 ref2
= getref((IUnknown
*) lpDD
);
2516 ok(ref2
== ref
, "Object reference is %d, expected %d\n", ref2
, ref
);
2518 hr
= IDirectDrawSurface7_SetPrivateData(surface7
, &IID_IDirectDrawSurface7
, lpDD
, sizeof(IUnknown
*), DDSPD_IUNKNOWNPOINTER
);
2519 ok(hr
== DD_OK
, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr
);
2520 hr
= IDirectDrawSurface7_SetPrivateData(surface7
, &IID_IDirectDrawSurface7
, surface7
, sizeof(IUnknown
*), DDSPD_IUNKNOWNPOINTER
);
2521 ok(hr
== DD_OK
, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr
);
2522 ref2
= getref((IUnknown
*) lpDD
);
2523 ok(ref2
== ref
, "Object reference is %d, expected %d\n", ref2
, ref
);
2525 hr
= IDirectDrawSurface7_SetPrivateData(surface7
, &IID_IDirectDrawSurface7
, lpDD
, sizeof(IUnknown
*), DDSPD_IUNKNOWNPOINTER
);
2526 ok(hr
== DD_OK
, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr
);
2527 hr
= IDirectDrawSurface7_GetPrivateData(surface7
, &IID_IDirectDrawSurface7
, &ptr
, &size
);
2528 ok(hr
== DD_OK
, "IDirectDrawSurface7_GetPrivateData failed with %08x\n", hr
);
2529 ref2
= getref((IUnknown
*) lpDD
);
2530 /* Object is NOT being addrefed */
2531 ok(ptr
== (IUnknown
*) lpDD
, "Returned interface pointer is %p, expected %p\n", ptr
, lpDD
);
2532 ok(ref2
== ref
+ 1, "Object reference is %d, expected %d. ptr at %p, orig at %p\n", ref2
, ref
+ 1, ptr
, lpDD
);
2534 IDirectDrawSurface_Release(surface
);
2535 IDirectDrawSurface7_Release(surface7
);
2537 /* Destroying the surface frees the held reference */
2538 ref2
= getref((IUnknown
*) lpDD
);
2539 ok(ref2
== ref
, "Object reference is %d, expected %d\n", ref2
, ref
);
2542 static void BltParamTest(void)
2544 IDirectDrawSurface
*surface1
= NULL
, *surface2
= NULL
;
2548 RECT valid
= {10, 10, 20, 20};
2549 RECT invalid1
= {20, 10, 10, 20};
2550 RECT invalid2
= {20, 20, 20, 20};
2551 RECT invalid3
= {-1, -1, 20, 20};
2552 RECT invalid4
= {60, 60, 70, 70};
2554 memset(&desc
, 0, sizeof(desc
));
2555 desc
.dwSize
= sizeof(desc
);
2556 desc
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
;
2557 desc
.ddsCaps
.dwCaps
|= DDSCAPS_OFFSCREENPLAIN
;
2558 desc
.dwHeight
= 128;
2560 hr
= IDirectDraw_CreateSurface(lpDD
, &desc
, &surface1
, NULL
);
2561 ok(hr
== DD_OK
, "Creating an offscreen plain surface failed with %08x\n", hr
);
2565 hr
= IDirectDraw_CreateSurface(lpDD
, &desc
, &surface2
, NULL
);
2566 ok(hr
== DD_OK
, "Creating an offscreen plain surface failed with %08x\n", hr
);
2571 hr
= IDirectDrawSurface_BltFast(surface1
, 0, 0, NULL
, NULL
, 0);
2572 ok(hr
== DD_OK
, "BltFast from NULL surface returned %08x\n", hr
);
2574 hr
= IDirectDrawSurface_BltFast(surface1
, 0, 0, surface2
, NULL
, 0);
2575 ok(hr
== DD_OK
, "BltFast from smaller to bigger surface returned %08x\n", hr
);
2576 hr
= IDirectDrawSurface_BltFast(surface2
, 0, 0, surface1
, NULL
, 0);
2577 ok(hr
== DDERR_INVALIDRECT
, "BltFast from bigger to smaller surface returned %08x\n", hr
);
2578 hr
= IDirectDrawSurface_BltFast(surface2
, 0, 0, surface1
, &valid
, 0);
2579 ok(hr
== DD_OK
, "BltFast from bigger to smaller surface using a valid rectangle returned %08x\n", hr
);
2580 hr
= IDirectDrawSurface_BltFast(surface2
, 60, 60, surface1
, &valid
, 0);
2581 ok(hr
== DDERR_INVALIDRECT
, "BltFast with a rectangle resulting in an off-surface write returned %08x\n", hr
);
2582 hr
= IDirectDrawSurface_BltFast(surface1
, 90, 90, surface2
, NULL
, 0);
2583 ok(hr
== DDERR_INVALIDRECT
, "BltFast with a rectangle resulting in an off-surface write returned %08x\n", hr
);
2585 hr
= IDirectDrawSurface_BltFast(surface1
, -10, 0, surface2
, NULL
, 0);
2586 ok(hr
== DDERR_INVALIDRECT
, "BltFast with an offset resulting in an off-surface write returned %08x\n", hr
);
2587 hr
= IDirectDrawSurface_BltFast(surface1
, 0, -10, surface2
, NULL
, 0);
2588 ok(hr
== DDERR_INVALIDRECT
, "BltFast with an offset resulting in an off-surface write returned %08x\n", hr
);
2589 hr
= IDirectDrawSurface_BltFast(surface2
, 20, 20, surface1
, &valid
, 0);
2590 ok(hr
== DD_OK
, "BltFast from bigger to smaller surface using a valid rectangle and offset returned %08x\n", hr
);
2592 hr
= IDirectDrawSurface_BltFast(surface2
, 0, 0, surface1
, &invalid1
, 0);
2593 ok(hr
== DDERR_INVALIDRECT
, "BltFast with invalid rectangle 1 returned %08x\n", hr
);
2594 hr
= IDirectDrawSurface_BltFast(surface2
, 0, 0, surface1
, &invalid2
, 0);
2595 ok(hr
== DDERR_INVALIDRECT
, "BltFast with invalid rectangle 2 returned %08x\n", hr
);
2596 hr
= IDirectDrawSurface_BltFast(surface2
, 0, 0, surface1
, &invalid3
, 0);
2597 ok(hr
== DDERR_INVALIDRECT
, "BltFast with invalid rectangle 3 returned %08x\n", hr
);
2598 hr
= IDirectDrawSurface_BltFast(surface1
, 0, 0, surface2
, &invalid4
, 0);
2599 ok(hr
== DDERR_INVALIDRECT
, "BltFast with invalid rectangle 3 returned %08x\n", hr
);
2600 hr
= IDirectDrawSurface_BltFast(surface1
, 0, 0, surface1
, NULL
, 0);
2601 ok(hr
== DD_OK
, "BltFast blitting a surface onto itself returned %08x\n", hr
);
2603 /* Blt(non-fast) tests */
2604 memset(&BltFx
, 0, sizeof(BltFx
));
2605 BltFx
.dwSize
= sizeof(BltFx
);
2606 U5(BltFx
).dwFillColor
= 0xaabbccdd;
2608 hr
= IDirectDrawSurface_Blt(surface1
, &valid
, NULL
, NULL
, DDBLT_COLORFILL
, &BltFx
);
2609 ok(hr
== DD_OK
, "IDirectDrawSurface_Blt with a valid rectangle for color fill returned %08x\n", hr
);
2610 hr
= IDirectDrawSurface_Blt(surface1
, &valid
, NULL
, &invalid3
, DDBLT_COLORFILL
, &BltFx
);
2611 ok(hr
== DD_OK
, "IDirectDrawSurface_Blt with a invalid, unused rectangle returned %08x\n", hr
);
2612 hr
= IDirectDrawSurface_Blt(surface2
, &invalid1
, NULL
, NULL
, DDBLT_COLORFILL
, &BltFx
);
2613 ok(hr
== DDERR_INVALIDRECT
, "IDirectDrawSurface_Blt with a with invalid rectangle 1 returned %08x\n", hr
);
2614 hr
= IDirectDrawSurface_Blt(surface2
, &invalid2
, NULL
, NULL
, DDBLT_COLORFILL
, &BltFx
);
2615 ok(hr
== DDERR_INVALIDRECT
, "IDirectDrawSurface_Blt with a with invalid rectangle 2 returned %08x\n", hr
);
2616 hr
= IDirectDrawSurface_Blt(surface2
, &invalid3
, NULL
, NULL
, DDBLT_COLORFILL
, &BltFx
);
2617 ok(hr
== DDERR_INVALIDRECT
, "IDirectDrawSurface_Blt with a with invalid rectangle 3 returned %08x\n", hr
);
2618 hr
= IDirectDrawSurface_Blt(surface2
, &invalid4
, NULL
, NULL
, DDBLT_COLORFILL
, &BltFx
);
2619 ok(hr
== DDERR_INVALIDRECT
, "IDirectDrawSurface_Blt with a with invalid rectangle 4 returned %08x\n", hr
);
2621 /* Valid on surface 1 */
2622 hr
= IDirectDrawSurface_Blt(surface1
, &invalid4
, NULL
, NULL
, DDBLT_COLORFILL
, &BltFx
);
2623 ok(hr
== DD_OK
, "IDirectDrawSurface_Blt with a subrectangle fill returned %08x\n", hr
);
2625 /* Works - stretched blit */
2626 hr
= IDirectDrawSurface_Blt(surface1
, NULL
, surface2
, NULL
, 0, NULL
);
2627 ok(hr
== DD_OK
, "IDirectDrawSurface_Blt from a smaller to a bigger surface returned %08x\n", hr
);
2628 hr
= IDirectDrawSurface_Blt(surface2
, NULL
, surface1
, NULL
, 0, NULL
);
2629 ok(hr
== DD_OK
, "IDirectDrawSurface_Blt from a bigger to a smaller surface %08x\n", hr
);
2631 /* Invalid dest rects in sourced blits */
2632 hr
= IDirectDrawSurface_Blt(surface2
, &invalid1
, surface1
, NULL
, 0, NULL
);
2633 ok(hr
== DDERR_INVALIDRECT
, "IDirectDrawSurface_Blt with a with invalid rectangle 1 returned %08x\n", hr
);
2634 hr
= IDirectDrawSurface_Blt(surface2
, &invalid2
, surface1
, NULL
, 0, NULL
);
2635 ok(hr
== DDERR_INVALIDRECT
, "IDirectDrawSurface_Blt with a with invalid rectangle 2 returned %08x\n", hr
);
2636 hr
= IDirectDrawSurface_Blt(surface2
, &invalid3
, surface1
, NULL
, 0, NULL
);
2637 ok(hr
== DDERR_INVALIDRECT
, "IDirectDrawSurface_Blt with a with invalid rectangle 3 returned %08x\n", hr
);
2638 hr
= IDirectDrawSurface_Blt(surface2
, &invalid4
, surface1
, NULL
, 0, NULL
);
2639 ok(hr
== DDERR_INVALIDRECT
, "IDirectDrawSurface_Blt with a with invalid rectangle 4 returned %08x\n", hr
);
2641 /* Invalid src rects */
2642 hr
= IDirectDrawSurface_Blt(surface2
, NULL
, surface1
, &invalid1
, 0, NULL
);
2643 ok(hr
== DDERR_INVALIDRECT
, "IDirectDrawSurface_Blt with a with invalid rectangle 1 returned %08x\n", hr
);
2644 hr
= IDirectDrawSurface_Blt(surface2
, NULL
, surface1
, &invalid2
, 0, NULL
);
2645 ok(hr
== DDERR_INVALIDRECT
, "IDirectDrawSurface_Blt with a with invalid rectangle 2 returned %08x\n", hr
);
2646 hr
= IDirectDrawSurface_Blt(surface2
, NULL
, surface1
, &invalid3
, 0, NULL
);
2647 ok(hr
== DDERR_INVALIDRECT
, "IDirectDrawSurface_Blt with a with invalid rectangle 3 returned %08x\n", hr
);
2648 hr
= IDirectDrawSurface_Blt(surface1
, NULL
, surface2
, &invalid4
, 0, NULL
);
2649 ok(hr
== DDERR_INVALIDRECT
, "IDirectDrawSurface_Blt with a with invalid rectangle 4 returned %08x\n", hr
);
2651 IDirectDrawSurface_Release(surface1
);
2652 IDirectDrawSurface_Release(surface2
);
2655 static void PaletteTest(void)
2658 LPDIRECTDRAWSURFACE lpSurf
= NULL
;
2660 IDirectDrawPalette
*palette
= NULL
;
2661 PALETTEENTRY Table
[256];
2662 PALETTEENTRY palEntries
[256];
2665 for(i
=0; i
<256; i
++)
2667 Table
[i
].peRed
= 0xff;
2668 Table
[i
].peGreen
= 0;
2669 Table
[i
].peBlue
= 0;
2670 Table
[i
].peFlags
= 0;
2673 /* Create a 8bit palette without DDPCAPS_ALLOW256 set */
2674 hr
= IDirectDraw_CreatePalette(lpDD
, DDPCAPS_8BIT
, Table
, &palette
, NULL
);
2675 ok(hr
== DD_OK
, "CreatePalette failed with %08x\n", hr
);
2676 if (FAILED(hr
)) goto err
;
2677 /* Read back the palette and verify the entries. Without DDPCAPS_ALLOW256 set
2678 / entry 0 and 255 should have been overwritten with black and white */
2679 IDirectDrawPalette_GetEntries(palette
, 0, 0, 256, &palEntries
[0]);
2680 ok(hr
== DD_OK
, "GetEntries failed with %08x\n", hr
);
2683 ok((palEntries
[0].peRed
== 0) && (palEntries
[0].peGreen
== 0) && (palEntries
[0].peBlue
== 0),
2684 "Palette entry 0 of a palette without DDPCAPS_ALLOW256 set should be (0,0,0) but it is (%d,%d,%d)\n",
2685 palEntries
[0].peRed
, palEntries
[0].peGreen
, palEntries
[0].peBlue
);
2686 ok((palEntries
[255].peRed
== 255) && (palEntries
[255].peGreen
== 255) && (palEntries
[255].peBlue
== 255),
2687 "Palette entry 255 of a palette without DDPCAPS_ALLOW256 set should be (255,255,255) but it is (%d,%d,%d)\n",
2688 palEntries
[255].peRed
, palEntries
[255].peGreen
, palEntries
[255].peBlue
);
2690 /* Entry 1-254 should contain red */
2691 for(i
=1; i
<255; i
++)
2692 ok((palEntries
[i
].peRed
== 255) && (palEntries
[i
].peGreen
== 0) && (palEntries
[i
].peBlue
== 0),
2693 "Palette entry %d should have contained (255,0,0) but was set to %d,%d,%d)\n",
2694 i
, palEntries
[i
].peRed
, palEntries
[i
].peGreen
, palEntries
[i
].peBlue
);
2697 /* CreatePalette without DDPCAPS_ALLOW256 ignores entry 0 and 255,
2698 / now check we are able to update the entries afterwards. */
2699 IDirectDrawPalette_SetEntries(palette
, 0, 0, 256, &Table
[0]);
2700 ok(hr
== DD_OK
, "SetEntries failed with %08x\n", hr
);
2701 IDirectDrawPalette_GetEntries(palette
, 0, 0, 256, &palEntries
[0]);
2702 ok(hr
== DD_OK
, "GetEntries failed with %08x\n", hr
);
2705 ok((palEntries
[0].peRed
== 0) && (palEntries
[0].peGreen
== 0) && (palEntries
[0].peBlue
== 0),
2706 "Palette entry 0 should have been set to (0,0,0) but it contains (%d,%d,%d)\n",
2707 palEntries
[0].peRed
, palEntries
[0].peGreen
, palEntries
[0].peBlue
);
2708 ok((palEntries
[255].peRed
== 255) && (palEntries
[255].peGreen
== 255) && (palEntries
[255].peBlue
== 255),
2709 "Palette entry 255 should have been set to (255,255,255) but it contains (%d,%d,%d)\n",
2710 palEntries
[255].peRed
, palEntries
[255].peGreen
, palEntries
[255].peBlue
);
2712 IDirectDrawPalette_Release(palette
);
2714 /* Create a 8bit palette with DDPCAPS_ALLOW256 set */
2715 hr
= IDirectDraw_CreatePalette(lpDD
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
, Table
, &palette
, NULL
);
2716 ok(hr
== DD_OK
, "CreatePalette failed with %08x\n", hr
);
2717 if (FAILED(hr
)) goto err
;
2719 IDirectDrawPalette_GetEntries(palette
, 0, 0, 256, &palEntries
[0]);
2720 ok(hr
== DD_OK
, "GetEntries failed with %08x\n", hr
);
2723 /* All entries should contain red */
2724 for(i
=0; i
<256; i
++)
2725 ok((palEntries
[i
].peRed
== 255) && (palEntries
[i
].peGreen
== 0) && (palEntries
[i
].peBlue
== 0),
2726 "Palette entry %d should have contained (255,0,0) but was set to %d,%d,%d)\n",
2727 i
, palEntries
[i
].peRed
, palEntries
[i
].peGreen
, palEntries
[i
].peBlue
);
2730 /* Try to set palette to a non-palettized surface */
2731 ddsd
.dwSize
= sizeof(ddsd
);
2732 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
2733 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
2734 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
2736 ddsd
.dwHeight
= 600;
2737 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
2738 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
2739 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0xFF0000;
2740 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x00FF00;
2741 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x0000FF;
2742 hr
= IDirectDraw_CreateSurface(lpDD
, &ddsd
, &lpSurf
, NULL
);
2743 ok(hr
==DD_OK
, "CreateSurface returned: %x\n",hr
);
2746 skip("failed to create surface\n");
2750 hr
= IDirectDrawSurface_SetPalette(lpSurf
, palette
);
2751 ok(hr
== DDERR_INVALIDPIXELFORMAT
, "CreateSurface returned: %x\n",hr
);
2753 IDirectDrawPalette_Release(palette
);
2756 hr
= IDirectDrawSurface_GetPalette(lpSurf
, &palette
);
2757 ok(hr
== DDERR_NOPALETTEATTACHED
, "CreateSurface returned: %x\n",hr
);
2761 if (lpSurf
) IDirectDrawSurface_Release(lpSurf
);
2762 if (palette
) IDirectDrawPalette_Release(palette
);
2765 static void StructSizeTest(void)
2767 IDirectDrawSurface
*surface1
;
2768 IDirectDrawSurface7
*surface7
;
2770 DDSURFACEDESC desc1
;
2771 DDSURFACEDESC2 desc2
;
2772 char blob
[1024]; /* To get a bunch of writable memory */
2774 DDSURFACEDESC create
;
2777 memset(&desc
, 0, sizeof(desc
));
2778 memset(&create
, 0, sizeof(create
));
2780 memset(&create
, 0, sizeof(create
));
2781 create
.dwSize
= sizeof(create
);
2782 create
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
;
2783 create
.ddsCaps
.dwCaps
|= DDSCAPS_OFFSCREENPLAIN
;
2784 create
.dwHeight
= 128;
2785 create
.dwWidth
= 128;
2786 hr
= IDirectDraw_CreateSurface(lpDD
, &create
, &surface1
, NULL
);
2787 ok(hr
== DD_OK
, "Creating an offscreen plain surface failed with %08x\n", hr
);
2788 hr
= IDirectDrawSurface_QueryInterface(surface1
, &IID_IDirectDrawSurface7
, (void **) &surface7
);
2789 ok(hr
== DD_OK
, "IDirectDrawSurface_QueryInterface failed with %08x\n", hr
);
2791 desc
.desc1
.dwSize
= sizeof(DDSURFACEDESC
);
2792 hr
= IDirectDrawSurface_GetSurfaceDesc(surface1
, &desc
.desc1
);
2793 ok(hr
== DD_OK
, "IDirectDrawSurface_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC) returned %08x\n", hr
);
2794 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface7
, &desc
.desc2
);
2795 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDrawSurface7_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC) returned %08x\n", hr
);
2797 desc
.desc2
.dwSize
= sizeof(DDSURFACEDESC2
);
2798 hr
= IDirectDrawSurface_GetSurfaceDesc(surface1
, &desc
.desc1
);
2799 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDrawSurface_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC2) returned %08x\n", hr
);
2800 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface7
, &desc
.desc2
);
2801 ok(hr
== DD_OK
, "IDirectDrawSurface7_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC2) returned %08x\n", hr
);
2803 desc
.desc2
.dwSize
= 0;
2804 hr
= IDirectDrawSurface_GetSurfaceDesc(surface1
, &desc
.desc1
);
2805 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDrawSurface_GetSurfaceDesc with desc size 0 returned %08x\n", hr
);
2806 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface7
, &desc
.desc2
);
2807 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDrawSurface7_GetSurfaceDesc with desc size 0 returned %08x\n", hr
);
2809 desc
.desc1
.dwSize
= sizeof(DDSURFACEDESC
) + 1;
2810 hr
= IDirectDrawSurface_GetSurfaceDesc(surface1
, &desc
.desc1
);
2811 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDrawSurface_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC) + 1 returned %08x\n", hr
);
2812 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface7
, &desc
.desc2
);
2813 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDrawSurface7_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC) + 1 returned %08x\n", hr
);
2815 desc
.desc2
.dwSize
= sizeof(DDSURFACEDESC2
) + 1;
2816 hr
= IDirectDrawSurface_GetSurfaceDesc(surface1
, &desc
.desc1
);
2817 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDrawSurface_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC2) + 1returned %08x\n", hr
);
2818 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface7
, &desc
.desc2
);
2819 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDrawSurface7_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC2) + 1returned %08x\n", hr
);
2821 /* Tests for Lock() */
2823 desc
.desc1
.dwSize
= sizeof(DDSURFACEDESC
);
2824 hr
= IDirectDrawSurface_Lock(surface1
, NULL
, &desc
.desc1
, 0, 0);
2825 ok(hr
== DD_OK
, "IDirectDrawSurface_Lock with desc size sizeof(DDSURFACEDESC) returned %08x\n", hr
);
2826 if(SUCCEEDED(hr
)) IDirectDrawSurface_Unlock(surface1
, NULL
);
2827 ok(desc
.desc1
.dwSize
== sizeof(DDSURFACEDESC
), "Destination size was changed to %d\n", desc
.desc1
.dwSize
);
2828 hr
= IDirectDrawSurface7_Lock(surface7
, NULL
, &desc
.desc2
, 0, 0);
2829 ok(hr
== DD_OK
, "IDirectDrawSurface7_Lock with desc size sizeof(DDSURFACEDESC) returned %08x\n", hr
);
2830 if(SUCCEEDED(hr
)) IDirectDrawSurface7_Unlock(surface7
, NULL
);
2831 ok(desc
.desc2
.dwSize
== sizeof(DDSURFACEDESC
), "Destination size was changed to %d\n", desc
.desc1
.dwSize
);
2833 desc
.desc2
.dwSize
= sizeof(DDSURFACEDESC2
);
2834 hr
= IDirectDrawSurface_Lock(surface1
, NULL
, &desc
.desc1
, 0, 0);
2835 ok(hr
== DD_OK
, "IDirectDrawSurface_Lock with desc size sizeof(DDSURFACEDESC2) returned %08x\n", hr
);
2836 ok(desc
.desc1
.dwSize
== sizeof(DDSURFACEDESC2
), "Destination size was changed to %d\n", desc
.desc1
.dwSize
);
2837 if(SUCCEEDED(hr
)) IDirectDrawSurface_Unlock(surface1
, NULL
);
2838 hr
= IDirectDrawSurface7_Lock(surface7
, NULL
, &desc
.desc2
, 0, 0);
2839 ok(hr
== DD_OK
, "IDirectDrawSurface7_Lock with desc size sizeof(DDSURFACEDESC2) returned %08x\n", hr
);
2840 if(SUCCEEDED(hr
)) IDirectDrawSurface7_Unlock(surface7
, NULL
);
2841 ok(desc
.desc2
.dwSize
== sizeof(DDSURFACEDESC2
), "Destination size was changed to %d\n", desc
.desc1
.dwSize
);
2843 desc
.desc2
.dwSize
= 0;
2844 hr
= IDirectDrawSurface_Lock(surface1
, NULL
, &desc
.desc1
, 0, 0);
2845 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDrawSurface_Lock with desc size 0 returned %08x\n", hr
);
2846 if(SUCCEEDED(hr
)) IDirectDrawSurface_Unlock(surface1
, NULL
);
2847 hr
= IDirectDrawSurface7_Lock(surface7
, NULL
, &desc
.desc2
, 0, 0);
2848 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDrawSurface7_Lock with desc size 0 returned %08x\n", hr
);
2849 if(SUCCEEDED(hr
)) IDirectDrawSurface7_Unlock(surface7
, NULL
);
2851 desc
.desc1
.dwSize
= sizeof(DDSURFACEDESC
) + 1;
2852 hr
= IDirectDrawSurface_Lock(surface1
, NULL
, &desc
.desc1
, 0, 0);
2853 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDrawSurface_Lock with desc size sizeof(DDSURFACEDESC) + 1 returned %08x\n", hr
);
2854 if(SUCCEEDED(hr
)) IDirectDrawSurface_Unlock(surface1
, NULL
);
2855 hr
= IDirectDrawSurface7_Lock(surface7
, NULL
, &desc
.desc2
, 0, 0);
2856 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDrawSurface7_Lock with desc size sizeof(DDSURFACEDESC) + 1 returned %08x\n", hr
);
2857 if(SUCCEEDED(hr
)) IDirectDrawSurface7_Unlock(surface7
, NULL
);
2859 desc
.desc2
.dwSize
= sizeof(DDSURFACEDESC2
) + 1;
2860 hr
= IDirectDrawSurface_Lock(surface1
, NULL
, &desc
.desc1
, 0, 0);
2861 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDrawSurface_Lock with desc size sizeof(DDSURFACEDESC2) + 1returned %08x\n", hr
);
2862 if(SUCCEEDED(hr
)) IDirectDrawSurface_Unlock(surface1
, NULL
);
2863 hr
= IDirectDrawSurface7_Lock(surface7
, NULL
, &desc
.desc2
, 0, 0);
2864 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDrawSurface7_Lock with desc size sizeof(DDSURFACEDESC2) + 1returned %08x\n", hr
);
2865 if(SUCCEEDED(hr
)) IDirectDrawSurface7_Unlock(surface7
, NULL
);
2867 IDirectDrawSurface7_Release(surface7
);
2868 IDirectDrawSurface_Release(surface1
);
2871 static void SurfaceCapsTest(void)
2873 DDSURFACEDESC create
;
2876 IDirectDrawSurface
*surface1
= NULL
;
2877 DDSURFACEDESC2 create2
, desc2
;
2878 IDirectDrawSurface7
*surface7
= NULL
;
2879 IDirectDraw7
*dd7
= NULL
;
2880 DWORD create_caps
[] = {
2881 DDSCAPS_OFFSCREENPLAIN
,
2883 DDSCAPS_TEXTURE
| DDSCAPS_ALLOCONLOAD
,
2885 DDSCAPS_TEXTURE
| DDSCAPS_ALLOCONLOAD
| DDSCAPS_SYSTEMMEMORY
,
2886 DDSCAPS_PRIMARYSURFACE
,
2887 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_SYSTEMMEMORY
,
2890 DDSCAPS_3DDEVICE
| DDSCAPS_OFFSCREENPLAIN
2892 DWORD expected_caps
[] = {
2893 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
2894 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
2895 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
| DDSCAPS_ALLOCONLOAD
,
2896 DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
2897 DDSCAPS_TEXTURE
| DDSCAPS_ALLOCONLOAD
| DDSCAPS_SYSTEMMEMORY
,
2898 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
| DDSCAPS_VISIBLE
,
2899 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_VISIBLE
,
2900 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
2901 DDSCAPS_ZBUFFER
| DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
,
2902 DDSCAPS_3DDEVICE
| DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
2906 /* Tests various surface flags, what changes do they undergo during surface creation. Forsaken
2907 * engine expects texture surfaces without memory flag to get a video memory flag right after
2908 * creation. Currently, Wine adds DDSCAPS_FRONTBUFFER to primary surface, but native doesn't do this
2909 * for single buffered primaries. Because of this primary surface creation tests are todo_wine. No real
2910 * app is known so far to care about this. */
2912 if (!(ddcaps
.ddsCaps
.dwCaps
& DDSCAPS_VIDEOMEMORY
))
2914 skip("DDraw reported no VIDEOMEMORY cap. Broken video driver? Skipping surface caps tests.\n");
2918 for (i
= 0; i
< sizeof(create_caps
) / sizeof(DWORD
); i
++)
2920 memset(&create
, 0, sizeof(create
));
2921 create
.dwSize
= sizeof(create
);
2922 create
.ddsCaps
.dwCaps
= create_caps
[i
];
2923 create
.dwFlags
= DDSD_CAPS
;
2925 if (!(create
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
))
2927 create
.dwFlags
|= DDSD_HEIGHT
| DDSD_WIDTH
;
2928 create
.dwHeight
= 128;
2929 create
.dwWidth
= 128;
2932 if (create
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
)
2934 create
.dwFlags
|= DDSD_PIXELFORMAT
;
2935 create
.ddpfPixelFormat
.dwSize
= sizeof(create
.ddpfPixelFormat
);
2936 create
.ddpfPixelFormat
.dwFlags
= DDPF_ZBUFFER
;
2937 U1(create
.ddpfPixelFormat
).dwZBufferBitDepth
= 16;
2938 U3(create
.ddpfPixelFormat
).dwZBitMask
= 0x0000FFFF;
2941 hr
= IDirectDraw_CreateSurface(lpDD
, &create
, &surface1
, NULL
);
2942 ok(hr
== DD_OK
, "IDirectDraw_CreateSurface failed with %08x\n", hr
);
2946 memset(&desc
, 0, sizeof(desc
));
2947 desc
.dwSize
= sizeof(DDSURFACEDESC
);
2948 hr
= IDirectDrawSurface_GetSurfaceDesc(surface1
, &desc
);
2949 ok(hr
== DD_OK
, "IDirectDrawSurface_GetSurfaceDesc failed with %08x\n", hr
);
2951 if (!(create_caps
[i
] & DDSCAPS_PRIMARYSURFACE
))
2952 ok(desc
.ddsCaps
.dwCaps
== expected_caps
[i
],
2953 "GetSurfaceDesc test %d returned caps %x, expected %x\n", i
,
2954 desc
.ddsCaps
.dwCaps
, expected_caps
[i
]);
2956 todo_wine
ok(desc
.ddsCaps
.dwCaps
== expected_caps
[i
],
2957 "GetSurfaceDesc test %d returned caps %x, expected %x\n", i
,
2958 desc
.ddsCaps
.dwCaps
, expected_caps
[i
]);
2960 IDirectDrawSurface_Release(surface1
);
2964 /* Test for differences in ddraw 7 */
2965 hr
= IDirectDraw_QueryInterface(lpDD
, &IID_IDirectDraw7
, (void **) &dd7
);
2966 ok(hr
== DD_OK
, "IDirectDraw_QueryInterface returned %08x\n", hr
);
2969 skip("Failed to get IDirectDraw7 interface, skipping tests\n");
2973 for (i
= 0; i
< sizeof(create_caps
) / sizeof(DWORD
); i
++)
2975 memset(&create2
, 0, sizeof(create2
));
2976 create2
.dwSize
= sizeof(create2
);
2977 create2
.ddsCaps
.dwCaps
= create_caps
[i
];
2978 create2
.dwFlags
= DDSD_CAPS
;
2980 if (!(create2
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
))
2982 create2
.dwFlags
|= DDSD_HEIGHT
| DDSD_WIDTH
;
2983 create2
.dwHeight
= 128;
2984 create2
.dwWidth
= 128;
2987 if (create2
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
)
2989 create2
.dwFlags
|= DDSD_PIXELFORMAT
;
2990 U4(create2
).ddpfPixelFormat
.dwSize
= sizeof(U4(create2
).ddpfPixelFormat
);
2991 U4(create2
).ddpfPixelFormat
.dwFlags
= DDPF_ZBUFFER
;
2992 U1(U4(create2
).ddpfPixelFormat
).dwZBufferBitDepth
= 16;
2993 U3(U4(create2
).ddpfPixelFormat
).dwZBitMask
= 0x0000FFFF;
2996 hr
= IDirectDraw7_CreateSurface(dd7
, &create2
, &surface7
, NULL
);
2997 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
3001 memset(&desc2
, 0, sizeof(desc2
));
3002 desc2
.dwSize
= sizeof(DDSURFACEDESC2
);
3003 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface7
, &desc2
);
3004 ok(hr
== DD_OK
, "IDirectDrawSurface_GetSurfaceDesc failed with %08x\n", hr
);
3006 if (!(create_caps
[i
] & DDSCAPS_PRIMARYSURFACE
))
3007 ok(desc2
.ddsCaps
.dwCaps
== expected_caps
[i
],
3008 "GetSurfaceDesc test %d returned caps %x, expected %x\n", i
,
3009 desc2
.ddsCaps
.dwCaps
, expected_caps
[i
]);
3011 todo_wine
ok(desc2
.ddsCaps
.dwCaps
== expected_caps
[i
],
3012 "GetSurfaceDesc test %d returned caps %x, expected %x\n", i
,
3013 desc2
.ddsCaps
.dwCaps
, expected_caps
[i
]);
3015 IDirectDrawSurface7_Release(surface7
);
3019 IDirectDraw7_Release(dd7
);
3022 memset(&create
, 0, sizeof(create
));
3023 create
.dwSize
= sizeof(create
);
3024 create
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
3025 create
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_VIDEOMEMORY
;
3026 create
.dwWidth
= 64;
3027 create
.dwHeight
= 64;
3028 hr
= IDirectDraw_CreateSurface(lpDD
, &create
, &surface1
, NULL
);
3029 ok(hr
== DDERR_INVALIDCAPS
, "Creating a SYSMEM | VIDMEM surface returned 0x%08x, expected DDERR_INVALIDCAPS\n", hr
);
3030 if(surface1
) IDirectDrawSurface_Release(surface1
);
3033 static BOOL
can_create_primary_surface(void)
3036 IDirectDrawSurface
*surface
;
3039 memset(&ddsd
, 0, sizeof(ddsd
));
3040 ddsd
.dwSize
= sizeof(ddsd
);
3041 ddsd
.dwFlags
= DDSD_CAPS
;
3042 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3043 hr
= IDirectDraw_CreateSurface(lpDD
, &ddsd
, &surface
, NULL
);
3044 if(FAILED(hr
)) return FALSE
;
3045 IDirectDrawSurface_Release(surface
);
3049 static void dctest_surf(IDirectDrawSurface
*surf
, int ddsdver
) {
3051 HDC dc
, dc2
= (HDC
) 0x1234;
3053 DDSURFACEDESC2 ddsd2
;
3055 memset(&ddsd
, 0, sizeof(ddsd
));
3056 ddsd
.dwSize
= sizeof(ddsd
);
3057 memset(&ddsd2
, 0, sizeof(ddsd2
));
3058 ddsd2
.dwSize
= sizeof(ddsd2
);
3060 hr
= IDirectDrawSurface_GetDC(surf
, &dc
);
3061 ok(hr
== DD_OK
, "IDirectDrawSurface_GetDC failed: 0x%08x\n", hr
);
3063 hr
= IDirectDrawSurface_GetDC(surf
, &dc2
);
3064 ok(hr
== DDERR_DCALREADYCREATED
, "IDirectDrawSurface_GetDC failed: 0x%08x\n", hr
);
3065 ok(dc2
== (HDC
) 0x1234, "The failed GetDC call changed the dc: %p\n", dc2
);
3067 hr
= IDirectDrawSurface_Lock(surf
, NULL
, ddsdver
== 1 ? &ddsd
: ((DDSURFACEDESC
*) &ddsd2
), 0, NULL
);
3068 ok(hr
== DDERR_SURFACEBUSY
, "IDirectDrawSurface_Lock returned 0x%08x, expected DDERR_ALREADYLOCKED\n", hr
);
3070 hr
= IDirectDrawSurface_ReleaseDC(surf
, dc
);
3071 ok(hr
== DD_OK
, "IDirectDrawSurface_ReleaseDC failed: 0x%08x\n", hr
);
3072 hr
= IDirectDrawSurface_ReleaseDC(surf
, dc
);
3073 ok(hr
== DDERR_NODC
, "IDirectDrawSurface_ReleaseDC returned 0x%08x, expected DDERR_NODC\n", hr
);
3076 static void GetDCTest(void)
3079 DDSURFACEDESC2 ddsd2
;
3080 IDirectDrawSurface
*surf
;
3081 IDirectDrawSurface2
*surf2
;
3082 IDirectDrawSurface4
*surf4
;
3083 IDirectDrawSurface7
*surf7
;
3084 IDirectDrawSurface
*tmp
;
3085 IDirectDrawSurface7
*tmp7
;
3093 memset(&ddsd
, 0, sizeof(ddsd
));
3094 ddsd
.dwSize
= sizeof(ddsd
);
3095 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
3098 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
3099 memset(&ddsd2
, 0, sizeof(ddsd2
));
3100 ddsd2
.dwSize
= sizeof(ddsd2
);
3101 ddsd2
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
3103 ddsd2
.dwHeight
= 64;
3104 ddsd2
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
3106 hr
= IDirectDraw_CreateSurface(lpDD
, &ddsd
, &surf
, NULL
);
3107 ok(hr
== DD_OK
, "IDirectDraw_CreateSurface failed: 0x%08x\n", hr
);
3108 dctest_surf(surf
, 1);
3109 IDirectDrawSurface_Release(surf
);
3111 hr
= IDirectDraw_QueryInterface(lpDD
, &IID_IDirectDraw2
, (void **) &dd2
);
3112 ok(hr
== DD_OK
, "IDirectDraw_QueryInterface failed: 0x%08x\n", hr
);
3114 hr
= IDirectDraw2_CreateSurface(dd2
, &ddsd
, &surf
, NULL
);
3115 ok(hr
== DD_OK
, "IDirectDraw2_CreateSurface failed: 0x%08x\n", hr
);
3116 dctest_surf(surf
, 1);
3118 hr
= IDirectDrawSurface_QueryInterface(surf
, &IID_IDirectDrawSurface2
, (void **) &surf2
);
3119 ok(hr
== DD_OK
, "IDirectDrawSurface_QueryInterface failed: 0x%08x\n", hr
);
3120 dctest_surf((IDirectDrawSurface
*) surf2
, 1);
3122 IDirectDrawSurface2_Release(surf2
);
3123 IDirectDrawSurface_Release(surf
);
3124 IDirectDraw2_Release(dd2
);
3126 hr
= IDirectDraw_QueryInterface(lpDD
, &IID_IDirectDraw4
, (void **) &dd4
);
3127 ok(hr
== DD_OK
, "IDirectDraw_QueryInterface failed: 0x%08x\n", hr
);
3130 hr
= IDirectDraw4_CreateSurface(dd4
, &ddsd2
, &surf4
, NULL
);
3131 ok(hr
== DD_OK
, "IDirectDraw4_CreateSurface failed: 0x%08x\n", hr
);
3132 dctest_surf((IDirectDrawSurface
*) surf4
, 2);
3134 hr
= IDirectDrawSurface4_QueryInterface(surf4
, &IID_IDirectDrawSurface
, (void **)&surf
);
3135 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
3137 ref
= getRefcount((IUnknown
*) surf
);
3138 ok(ref
== 1, "Refcount is %u, expected 1\n", ref
);
3139 ref
= getRefcount((IUnknown
*) surf4
);
3140 ok(ref
== 1, "Refcount is %u, expected 1\n", ref
);
3142 hr
= IDirectDrawSurface4_GetDC(surf4
, &dc
);
3143 ok(SUCCEEDED(hr
), "GetDC failed, hr %#x.\n", hr
);
3145 hr
= IDirectDraw4_GetSurfaceFromDC(dd4
, dc
, NULL
);
3146 ok(hr
== E_INVALIDARG
, "Expected hr E_INVALIDARG, got %#x.\n", hr
);
3148 hr
= IDirectDraw4_GetSurfaceFromDC(dd4
, dc
, (IDirectDrawSurface4
**)&tmp
);
3149 ok(SUCCEEDED(hr
), "GetSurfaceFromDC failed, hr %#x.\n", hr
);
3150 ok(tmp
== surf
, "Expected surface %p, got %p.\n\n", surf
, tmp
);
3152 ref
= getRefcount((IUnknown
*) surf
);
3153 ok(ref
== 2, "Refcount is %u, expected 2\n", ref
);
3154 ref
= getRefcount((IUnknown
*) tmp
);
3155 ok(ref
== 2, "Refcount is %u, expected 2\n", ref
);
3156 ref
= getRefcount((IUnknown
*) surf4
);
3157 ok(ref
== 1, "Refcount is %u, expected 1\n", ref
);
3159 hr
= IDirectDrawSurface4_ReleaseDC(surf4
, dc
);
3160 ok(SUCCEEDED(hr
), "ReleaseDC failed, hr %#x.\n", hr
);
3162 dc
= CreateCompatibleDC(NULL
);
3163 ok(!!dc
, "CreateCompatibleDC failed.\n");
3165 tmp
= (IDirectDrawSurface
*)0xdeadbeef;
3166 hr
= IDirectDraw4_GetSurfaceFromDC(dd4
, dc
, (IDirectDrawSurface4
**)&tmp
);
3167 ok(hr
== DDERR_NOTFOUND
, "GetSurfaceFromDC failed, hr %#x.\n", hr
);
3168 ok(!tmp
, "Expected surface NULL, got %p.\n", tmp
);
3170 ok(DeleteDC(dc
), "DeleteDC failed.\n");
3172 tmp
= (IDirectDrawSurface
*)0xdeadbeef;
3173 hr
= IDirectDraw4_GetSurfaceFromDC(dd4
, NULL
, (IDirectDrawSurface4
**)&tmp
);
3174 ok(hr
== DDERR_NOTFOUND
, "GetSurfaceFromDC failed, hr %#x.\n", hr
);
3175 ok(!tmp
, "Expected surface NULL, got %p.\n", tmp
);
3177 IDirectDrawSurface4_Release(surf4
);
3178 IDirectDraw4_Release(dd4
);
3180 hr
= IDirectDraw_QueryInterface(lpDD
, &IID_IDirectDraw7
, (void **) &dd7
);
3181 ok(hr
== DD_OK
, "IDirectDraw_QueryInterface failed: 0x%08x\n", hr
);
3183 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd2
, &surf7
, NULL
);
3184 ok(hr
== DD_OK
, "IDirectDraw7_CreateSurface failed: 0x%08x\n", hr
);
3185 dctest_surf((IDirectDrawSurface
*) surf7
, 2);
3187 hr
= IDirectDrawSurface7_GetDC(surf7
, &dc
);
3188 ok(SUCCEEDED(hr
), "GetDC failed, hr %#x.\n", hr
);
3190 hr
= IDirectDraw7_GetSurfaceFromDC(dd7
, dc
, NULL
);
3191 ok(hr
== E_INVALIDARG
, "Expected hr E_INVALIDARG, got %#x.\n", hr
);
3193 hr
= IDirectDraw7_GetSurfaceFromDC(dd7
, dc
, &tmp7
);
3194 ok(SUCCEEDED(hr
), "GetSurfaceFromDC failed, hr %#x.\n", hr
);
3195 ok(tmp7
== surf7
, "Expected surface %p, got %p.\n\n", surf7
, tmp7
);
3196 IDirectDrawSurface7_Release(tmp7
);
3198 hr
= IDirectDrawSurface7_ReleaseDC(surf7
, dc
);
3199 ok(SUCCEEDED(hr
), "ReleaseDC failed, hr %#x.\n", hr
);
3201 dc
= CreateCompatibleDC(NULL
);
3202 ok(!!dc
, "CreateCompatibleDC failed.\n");
3204 tmp7
= (IDirectDrawSurface7
*)0xdeadbeef;
3205 hr
= IDirectDraw7_GetSurfaceFromDC(dd7
, dc
, &tmp7
);
3206 ok(hr
== DDERR_NOTFOUND
, "GetSurfaceFromDC failed, hr %#x.\n", hr
);
3207 ok(!tmp7
, "Expected surface NULL, got %p.\n", tmp7
);
3209 ok(DeleteDC(dc
), "DeleteDC failed.\n");
3211 tmp7
= (IDirectDrawSurface7
*)0xdeadbeef;
3212 hr
= IDirectDraw7_GetSurfaceFromDC(dd7
, NULL
, (IDirectDrawSurface7
**)&tmp7
);
3213 ok(hr
== DDERR_NOTFOUND
, "GetSurfaceFromDC failed, hr %#x.\n", hr
);
3214 ok(!tmp7
, "Expected surface NULL, got %p.\n", tmp7
);
3216 IDirectDrawSurface7_Release(surf7
);
3217 IDirectDraw7_Release(dd7
);
3220 static void GetDCFormatTest(void)
3222 DDSURFACEDESC2 ddsd
;
3224 IDirectDrawSurface7
*surface
;
3239 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
3240 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
3247 sizeof(DDPIXELFORMAT
), DDPF_RGB
, 0,
3248 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0x00000000}
3255 sizeof(DDPIXELFORMAT
), DDPF_RGB
, 0,
3256 {32}, {0x000000ff}, {0x0000ff00}, {0x00ff0000}, {0x00000000}
3259 DDERR_CANTCREATEDC
/* Vista+ */
3264 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
3265 {32}, {0x000000ff}, {0x0000ff00}, {0x00ff0000}, {0xff000000}
3268 DDERR_CANTCREATEDC
/* Vista+ */
3273 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
3274 {16}, {0x00000f00}, {0x000000f0}, {0x0000000f}, {0x0000f000}
3277 DDERR_CANTCREATEDC
/* Vista+ */
3282 sizeof(DDPIXELFORMAT
), DDPF_RGB
, 0,
3283 {16}, {0x00000f00}, {0x000000f0}, {0x0000000f}, {0x00000000}
3286 DDERR_CANTCREATEDC
/* Vista+ */
3291 sizeof(DDPIXELFORMAT
), DDPF_RGB
, 0,
3292 {16}, {0x0000F800}, {0x000007E0}, {0x0000001F}, {0x00000000}
3299 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
3300 {16}, {0x00007C00}, {0x000003E0}, {0x0000001F}, {0x00008000}
3307 sizeof(DDPIXELFORMAT
), DDPF_RGB
, 0,
3308 {16}, {0x00007C00}, {0x000003E0}, {0x0000001F}, {0x00000000}
3315 sizeof(DDPIXELFORMAT
), DDPF_RGB
, 0,
3316 { 8}, {0x000000E0}, {0x0000001C}, {0x00000003}, {0x00000000}
3321 /* Untested, windows test machine didn't support this format */
3322 "D3DFMT_A2R10G10B10",
3324 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
3325 {32}, {0xC0000000}, {0x3FF00000}, {0x000FFC00}, {0x000003FF}
3330 * GetDC on a P8 surface fails unless the display mode is 8 bpp. This is not
3331 * implemented in wine yet, so disable the test for now. Succeeding P8 getDC
3332 * calls are tested in the ddraw.visual test.
3337 sizeof(DDPIXELFORMAT), DDPF_PALETTEINDEXED8 | DDPF_RGB, 0,
3338 {8 }, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}
3346 sizeof(DDPIXELFORMAT
), DDPF_LUMINANCE
, 0,
3347 {8 }, {0x000000ff}, {0x00000000}, {0x00000000}, {0x00000000}
3354 sizeof(DDPIXELFORMAT
), DDPF_ALPHAPIXELS
| DDPF_LUMINANCE
, 0,
3355 {16}, {0x000000ff}, {0x00000000}, {0x00000000}, {0x0000ff00}
3362 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('D','X','T','1'),
3363 {0 }, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}
3370 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('D','X','T','2'),
3371 {0 }, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}
3378 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('D','X','T','3'),
3379 {0 }, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}
3386 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('D','X','T','4'),
3387 {0 }, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}
3394 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('D','X','T','5'),
3395 {0 }, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}
3401 hr
= IDirectDraw_QueryInterface(lpDD
, &IID_IDirectDraw7
, (void **) &dd7
);
3402 ok(hr
== DD_OK
, "IDirectDraw_QueryInterface failed, hr = 0x%08x\n", hr
);
3404 for(i
= 0; i
< (sizeof(testdata
) / sizeof(testdata
[0])); i
++)
3406 memset(&ddsd
, 0, sizeof(ddsd
));
3407 ddsd
.dwSize
= sizeof(ddsd
);
3408 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
3411 U4(ddsd
).ddpfPixelFormat
= testdata
[i
].fmt
;
3412 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
3414 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd
, &surface
, NULL
);
3417 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
3418 ddsd
.ddsCaps
.dwCaps2
= DDSCAPS2_TEXTUREMANAGE
;
3419 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd
, &surface
, NULL
);
3422 skip("IDirectDraw7_CreateSurface failed, hr = 0x%08x, format %s\n", hr
, testdata
[i
].name
);
3427 dc
= (void *) 0x1234;
3428 hr
= IDirectDrawSurface7_GetDC(surface
, &dc
);
3429 if(testdata
[i
].getdc_capable
)
3432 (testdata
[i
].alt_result
&& hr
== testdata
[i
].alt_result
),
3433 "GetDC on a %s surface failed(0x%08x), expected it to work\n",
3434 testdata
[i
].name
, hr
);
3438 ok(FAILED(hr
), "GetDC on a %s surface succeeded(0x%08x), expected it to fail\n",
3439 testdata
[i
].name
, hr
);
3444 IDirectDrawSurface7_ReleaseDC(surface
, dc
);
3445 ok(hr
== DD_OK
, "IDirectDrawSurface7_ReleaseDC failed, hr = 0x%08x\n", hr
);
3450 ok(dc
== NULL
, "After failed GetDC dc is %p\n", dc
);
3453 IDirectDrawSurface7_Release(surface
);
3456 IDirectDraw7_Release(dd7
);
3459 static void BackBufferCreateSurfaceTest(void)
3462 DDSURFACEDESC created_ddsd
;
3463 DDSURFACEDESC2 ddsd2
;
3464 IDirectDrawSurface
*surf
;
3465 IDirectDrawSurface4
*surf4
;
3466 IDirectDrawSurface7
*surf7
;
3472 const DWORD caps
= DDSCAPS_BACKBUFFER
;
3473 const DWORD expected_caps
= DDSCAPS_BACKBUFFER
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
;
3475 if (!(ddcaps
.ddsCaps
.dwCaps
& DDSCAPS_VIDEOMEMORY
))
3477 skip("DDraw reported no VIDEOMEMORY cap. Broken video driver? Skipping surface caps tests.\n");
3481 memset(&ddsd
, 0, sizeof(ddsd
));
3482 ddsd
.dwSize
= sizeof(ddsd
);
3483 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
3486 ddsd
.ddsCaps
.dwCaps
= caps
;
3487 memset(&ddsd2
, 0, sizeof(ddsd2
));
3488 ddsd2
.dwSize
= sizeof(ddsd2
);
3489 ddsd2
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
3491 ddsd2
.dwHeight
= 64;
3492 ddsd2
.ddsCaps
.dwCaps
= caps
;
3493 memset(&created_ddsd
, 0, sizeof(created_ddsd
));
3494 created_ddsd
.dwSize
= sizeof(DDSURFACEDESC
);
3496 hr
= IDirectDraw_CreateSurface(lpDD
, &ddsd
, &surf
, NULL
);
3497 ok(SUCCEEDED(hr
), "IDirectDraw_CreateSurface failed: 0x%08x\n", hr
);
3500 hr
= IDirectDrawSurface_GetSurfaceDesc(surf
, &created_ddsd
);
3501 ok(SUCCEEDED(hr
), "IDirectDraw_GetSurfaceDesc failed: 0x%08x\n", hr
);
3502 ok(created_ddsd
.ddsCaps
.dwCaps
== expected_caps
,
3503 "GetSurfaceDesc returned caps %x, expected %x\n", created_ddsd
.ddsCaps
.dwCaps
,
3505 IDirectDrawSurface_Release(surf
);
3508 hr
= IDirectDraw_QueryInterface(lpDD
, &IID_IDirectDraw2
, (void **) &dd2
);
3509 ok(SUCCEEDED(hr
), "IDirectDraw_QueryInterface failed: 0x%08x\n", hr
);
3511 hr
= IDirectDraw2_CreateSurface(dd2
, &ddsd
, &surf
, NULL
);
3512 ok(hr
== DDERR_INVALIDCAPS
, "IDirectDraw2_CreateSurface didn't return %x08x, but %x08x\n",
3513 DDERR_INVALIDCAPS
, hr
);
3515 IDirectDraw2_Release(dd2
);
3517 hr
= IDirectDraw_QueryInterface(lpDD
, &IID_IDirectDraw4
, (void **) &dd4
);
3518 ok(SUCCEEDED(hr
), "IDirectDraw_QueryInterface failed: 0x%08x\n", hr
);
3520 hr
= IDirectDraw4_CreateSurface(dd4
, &ddsd2
, &surf4
, NULL
);
3521 ok(hr
== DDERR_INVALIDCAPS
, "IDirectDraw4_CreateSurface didn't return %x08x, but %x08x\n",
3522 DDERR_INVALIDCAPS
, hr
);
3524 IDirectDraw4_Release(dd4
);
3526 hr
= IDirectDraw_QueryInterface(lpDD
, &IID_IDirectDraw7
, (void **) &dd7
);
3527 ok(SUCCEEDED(hr
), "IDirectDraw_QueryInterface failed: 0x%08x\n", hr
);
3529 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd2
, &surf7
, NULL
);
3530 ok(hr
== DDERR_INVALIDCAPS
, "IDirectDraw7_CreateSurface didn't return %x08x, but %x08x\n",
3531 DDERR_INVALIDCAPS
, hr
);
3533 IDirectDraw7_Release(dd7
);
3536 static void BackBufferAttachmentFlipTest(void)
3539 IDirectDrawSurface
*surface1
, *surface2
, *surface3
, *surface4
;
3541 HWND window
= CreateWindow( "static", "ddraw_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
3543 hr
= IDirectDraw_SetCooperativeLevel(lpDD
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3544 ok(hr
== DD_OK
, "SetCooperativeLevel returned %08x\n", hr
);
3546 /* Perform attachment tests on a back-buffer */
3547 memset(&ddsd
, 0, sizeof(ddsd
));
3548 ddsd
.dwSize
= sizeof(ddsd
);
3549 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
3550 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_BACKBUFFER
;
3551 ddsd
.dwWidth
= GetSystemMetrics(SM_CXSCREEN
);
3552 ddsd
.dwHeight
= GetSystemMetrics(SM_CYSCREEN
);
3553 hr
= IDirectDraw_CreateSurface(lpDD
, &ddsd
, &surface2
, NULL
);
3554 ok(SUCCEEDED(hr
), "CreateSurface returned: %x\n",hr
);
3556 if (surface2
!= NULL
)
3558 /* Try a single primary and a two back buffers */
3559 memset(&ddsd
, 0, sizeof(ddsd
));
3560 ddsd
.dwSize
= sizeof(ddsd
);
3561 ddsd
.dwFlags
= DDSD_CAPS
;
3562 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3563 hr
= IDirectDraw_CreateSurface(lpDD
, &ddsd
, &surface1
, NULL
);
3564 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
3566 memset(&ddsd
, 0, sizeof(ddsd
));
3567 ddsd
.dwSize
= sizeof(ddsd
);
3568 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
3569 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_BACKBUFFER
;
3570 ddsd
.dwWidth
= GetSystemMetrics(SM_CXSCREEN
);
3571 ddsd
.dwHeight
= GetSystemMetrics(SM_CYSCREEN
);
3572 hr
= IDirectDraw_CreateSurface(lpDD
, &ddsd
, &surface3
, NULL
);
3573 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
3575 /* This one has a different size */
3576 memset(&ddsd
, 0, sizeof(ddsd
));
3577 ddsd
.dwSize
= sizeof(ddsd
);
3578 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
3579 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_BACKBUFFER
;
3581 ddsd
.dwHeight
= 128;
3582 hr
= IDirectDraw_CreateSurface(lpDD
, &ddsd
, &surface4
, NULL
);
3583 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
3585 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface2
);
3586 todo_wine
ok(hr
== DD_OK
|| broken(hr
== DDERR_CANNOTATTACHSURFACE
),
3587 "Attaching a back buffer to a front buffer returned %08x\n", hr
);
3590 /* Try flipping the surfaces */
3591 hr
= IDirectDrawSurface_Flip(surface1
, NULL
, DDFLIP_WAIT
);
3592 todo_wine
ok(hr
== DD_OK
, "IDirectDrawSurface_Flip returned 0x%08x\n", hr
);
3593 hr
= IDirectDrawSurface_Flip(surface2
, NULL
, DDFLIP_WAIT
);
3594 todo_wine
ok(hr
== DDERR_NOTFLIPPABLE
, "IDirectDrawSurface_Flip returned 0x%08x\n", hr
);
3596 /* Try the reverse without detaching first */
3597 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface1
);
3598 ok(hr
== DDERR_SURFACEALREADYATTACHED
, "Attaching an attached surface to its attachee returned %08x\n", hr
);
3599 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1
, 0, surface2
);
3600 ok(hr
== DD_OK
, "DeleteAttachedSurface failed with %08x\n", hr
);
3602 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface1
);
3603 todo_wine
ok(hr
== DD_OK
|| broken(hr
== DDERR_CANNOTATTACHSURFACE
),
3604 "Attaching a front buffer to a back buffer returned %08x\n", hr
);
3607 /* Try flipping the surfaces */
3608 hr
= IDirectDrawSurface_Flip(surface1
, NULL
, DDFLIP_WAIT
);
3609 todo_wine
ok(hr
== DD_OK
, "IDirectDrawSurface_Flip returned 0x%08x\n", hr
);
3610 hr
= IDirectDrawSurface_Flip(surface2
, NULL
, DDFLIP_WAIT
);
3611 todo_wine
ok(hr
== DDERR_NOTFLIPPABLE
, "IDirectDrawSurface_Flip returned 0x%08x\n", hr
);
3613 /* Try to detach reversed */
3614 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1
, 0, surface2
);
3615 ok(hr
== DDERR_CANNOTDETACHSURFACE
, "DeleteAttachedSurface returned %08x\n", hr
);
3616 /* Now the proper detach */
3617 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface2
, 0, surface1
);
3618 ok(hr
== DD_OK
, "DeleteAttachedSurface failed with %08x\n", hr
);
3620 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface3
);
3621 todo_wine
ok(hr
== DD_OK
|| broken(hr
== DDERR_CANNOTATTACHSURFACE
),
3622 "Attaching a back buffer to another back buffer returned %08x\n", hr
);
3625 /* Try flipping the surfaces */
3626 hr
= IDirectDrawSurface_Flip(surface3
, NULL
, DDFLIP_WAIT
);
3627 todo_wine
ok(hr
== DD_OK
, "IDirectDrawSurface_Flip returned 0x%08x\n", hr
);
3628 hr
= IDirectDrawSurface_Flip(surface2
, NULL
, DDFLIP_WAIT
);
3629 todo_wine
ok(hr
== DDERR_NOTFLIPPABLE
, "IDirectDrawSurface_Flip returned 0x%08x\n", hr
);
3630 hr
= IDirectDrawSurface_Flip(surface1
, NULL
, DDFLIP_WAIT
);
3631 ok(hr
== DDERR_NOTFLIPPABLE
, "IDirectDrawSurface_Flip returned 0x%08x\n", hr
);
3633 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface2
, 0, surface3
);
3634 ok(hr
== DD_OK
, "DeleteAttachedSurface failed with %08x\n", hr
);
3636 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface4
);
3637 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a back buffer to a front buffer of different size returned %08x\n", hr
);
3638 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface1
);
3639 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a front buffer to a back buffer of different size returned %08x\n", hr
);
3641 IDirectDrawSurface_Release(surface4
);
3642 IDirectDrawSurface_Release(surface3
);
3643 IDirectDrawSurface_Release(surface2
);
3644 IDirectDrawSurface_Release(surface1
);
3647 hr
=IDirectDraw_SetCooperativeLevel(lpDD
, NULL
, DDSCL_NORMAL
);
3648 ok(hr
== DD_OK
, "SetCooperativeLevel returned %08x\n", hr
);
3650 DestroyWindow(window
);
3653 static void CreateSurfaceBadCapsSizeTest(void)
3655 DDSURFACEDESC ddsd_ok
;
3656 DDSURFACEDESC ddsd_bad1
;
3657 DDSURFACEDESC ddsd_bad2
;
3658 DDSURFACEDESC ddsd_bad3
;
3659 DDSURFACEDESC ddsd_bad4
;
3660 DDSURFACEDESC2 ddsd2_ok
;
3661 DDSURFACEDESC2 ddsd2_bad1
;
3662 DDSURFACEDESC2 ddsd2_bad2
;
3663 DDSURFACEDESC2 ddsd2_bad3
;
3664 DDSURFACEDESC2 ddsd2_bad4
;
3665 IDirectDrawSurface
*surf
;
3666 IDirectDrawSurface4
*surf4
;
3667 IDirectDrawSurface7
*surf7
;
3673 const DWORD caps
= DDSCAPS_OFFSCREENPLAIN
;
3675 memset(&ddsd_ok
, 0, sizeof(ddsd_ok
));
3676 ddsd_ok
.dwSize
= sizeof(ddsd_ok
);
3677 ddsd_ok
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
3678 ddsd_ok
.dwWidth
= 64;
3679 ddsd_ok
.dwHeight
= 64;
3680 ddsd_ok
.ddsCaps
.dwCaps
= caps
;
3681 memcpy(&ddsd_bad1
, &ddsd_ok
, sizeof(ddsd_bad1
));
3683 memcpy(&ddsd_bad2
, &ddsd_ok
, sizeof(ddsd_bad2
));
3685 memcpy(&ddsd_bad3
, &ddsd_ok
, sizeof(ddsd_bad3
));
3686 ddsd_bad3
.dwSize
= 0;
3687 memcpy(&ddsd_bad4
, &ddsd_ok
, sizeof(ddsd_bad4
));
3688 ddsd_bad4
.dwSize
= sizeof(DDSURFACEDESC2
);
3690 memset(&ddsd2_ok
, 0, sizeof(ddsd2_ok
));
3691 ddsd2_ok
.dwSize
= sizeof(ddsd2_ok
);
3692 ddsd2_ok
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
3693 ddsd2_ok
.dwWidth
= 64;
3694 ddsd2_ok
.dwHeight
= 64;
3695 ddsd2_ok
.ddsCaps
.dwCaps
= caps
;
3696 memcpy(&ddsd2_bad1
, &ddsd2_ok
, sizeof(ddsd2_bad1
));
3697 ddsd2_bad1
.dwSize
--;
3698 memcpy(&ddsd2_bad2
, &ddsd2_ok
, sizeof(ddsd2_bad2
));
3699 ddsd2_bad2
.dwSize
++;
3700 memcpy(&ddsd2_bad3
, &ddsd2_ok
, sizeof(ddsd2_bad3
));
3701 ddsd2_bad3
.dwSize
= 0;
3702 memcpy(&ddsd2_bad4
, &ddsd2_ok
, sizeof(ddsd2_bad4
));
3703 ddsd2_bad4
.dwSize
= sizeof(DDSURFACEDESC
);
3705 hr
= IDirectDraw_CreateSurface(lpDD
, &ddsd_ok
, &surf
, NULL
);
3706 ok(SUCCEEDED(hr
), "IDirectDraw_CreateSurface failed: 0x%08x\n", hr
);
3707 IDirectDrawSurface_Release(surf
);
3709 hr
= IDirectDraw_CreateSurface(lpDD
, &ddsd_bad1
, &surf
, NULL
);
3710 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDraw_CreateSurface didn't return 0x%08x, but 0x%08x\n",
3711 DDERR_INVALIDPARAMS
, hr
);
3712 hr
= IDirectDraw_CreateSurface(lpDD
, &ddsd_bad2
, &surf
, NULL
);
3713 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDraw_CreateSurface didn't return 0x%08x, but 0x%08x\n",
3714 DDERR_INVALIDPARAMS
, hr
);
3715 hr
= IDirectDraw_CreateSurface(lpDD
, &ddsd_bad3
, &surf
, NULL
);
3716 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDraw_CreateSurface didn't return 0x%08x, but 0x%08x\n",
3717 DDERR_INVALIDPARAMS
, hr
);
3718 hr
= IDirectDraw_CreateSurface(lpDD
, &ddsd_bad4
, &surf
, NULL
);
3719 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDraw_CreateSurface didn't return 0x%08x, but 0x%08x\n",
3720 DDERR_INVALIDPARAMS
, hr
);
3721 hr
= IDirectDraw_CreateSurface(lpDD
, NULL
, &surf
, NULL
);
3722 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDraw_CreateSurface didn't return 0x%08x, but 0x%08x\n",
3723 DDERR_INVALIDPARAMS
, hr
);
3725 hr
= IDirectDraw_QueryInterface(lpDD
, &IID_IDirectDraw2
, (void **) &dd2
);
3726 ok(SUCCEEDED(hr
), "IDirectDraw_QueryInterface failed: 0x%08x\n", hr
);
3728 hr
= IDirectDraw2_CreateSurface(dd2
, &ddsd_ok
, &surf
, NULL
);
3729 ok(SUCCEEDED(hr
), "IDirectDraw2_CreateSurface failed: 0x%08x\n", hr
);
3730 IDirectDrawSurface_Release(surf
);
3732 hr
= IDirectDraw2_CreateSurface(dd2
, &ddsd_bad1
, &surf
, NULL
);
3733 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDraw2_CreateSurface didn't return 0x%08x, but 0x%08x\n",
3734 DDERR_INVALIDPARAMS
, hr
);
3735 hr
= IDirectDraw2_CreateSurface(dd2
, &ddsd_bad2
, &surf
, NULL
);
3736 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDraw2_CreateSurface didn't return 0x%08x, but 0x%08x\n",
3737 DDERR_INVALIDPARAMS
, hr
);
3738 hr
= IDirectDraw2_CreateSurface(dd2
, &ddsd_bad3
, &surf
, NULL
);
3739 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDraw2_CreateSurface didn't return 0x%08x, but 0x%08x\n",
3740 DDERR_INVALIDPARAMS
, hr
);
3741 hr
= IDirectDraw2_CreateSurface(dd2
, &ddsd_bad4
, &surf
, NULL
);
3742 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDraw2_CreateSurface didn't return 0x%08x, but 0x%08x\n",
3743 DDERR_INVALIDPARAMS
, hr
);
3744 hr
= IDirectDraw2_CreateSurface(dd2
, NULL
, &surf
, NULL
);
3745 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDraw2_CreateSurface didn't return 0x%08x, but 0x%08x\n",
3746 DDERR_INVALIDPARAMS
, hr
);
3748 IDirectDraw2_Release(dd2
);
3750 hr
= IDirectDraw_QueryInterface(lpDD
, &IID_IDirectDraw4
, (void **) &dd4
);
3751 ok(SUCCEEDED(hr
), "IDirectDraw_QueryInterface failed: 0x%08x\n", hr
);
3753 hr
= IDirectDraw4_CreateSurface(dd4
, &ddsd2_ok
, &surf4
, NULL
);
3754 ok(SUCCEEDED(hr
), "IDirectDraw4_CreateSurface failed: 0x%08x\n", hr
);
3755 IDirectDrawSurface4_Release(surf4
);
3757 hr
= IDirectDraw4_CreateSurface(dd4
, &ddsd2_bad1
, &surf4
, NULL
);
3758 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDraw4_CreateSurface didn't return 0x%08x, but 0x%08x\n",
3759 DDERR_INVALIDPARAMS
, hr
);
3760 hr
= IDirectDraw4_CreateSurface(dd4
, &ddsd2_bad2
, &surf4
, NULL
);
3761 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDraw4_CreateSurface didn't return 0x%08x, but 0x%08x\n",
3762 DDERR_INVALIDPARAMS
, hr
);
3763 hr
= IDirectDraw4_CreateSurface(dd4
, &ddsd2_bad3
, &surf4
, NULL
);
3764 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDraw4_CreateSurface didn't return 0x%08x, but 0x%08x\n",
3765 DDERR_INVALIDPARAMS
, hr
);
3766 hr
= IDirectDraw4_CreateSurface(dd4
, &ddsd2_bad4
, &surf4
, NULL
);
3767 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDraw4_CreateSurface didn't return 0x%08x, but 0x%08x\n",
3768 DDERR_INVALIDPARAMS
, hr
);
3769 hr
= IDirectDraw4_CreateSurface(dd4
, NULL
, &surf4
, NULL
);
3770 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDraw4_CreateSurface didn't return 0x%08x, but 0x%08x\n",
3771 DDERR_INVALIDPARAMS
, hr
);
3773 IDirectDraw4_Release(dd4
);
3775 hr
= IDirectDraw_QueryInterface(lpDD
, &IID_IDirectDraw7
, (void **) &dd7
);
3776 ok(SUCCEEDED(hr
), "IDirectDraw_QueryInterface failed: 0x%08x\n", hr
);
3778 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd2_ok
, &surf7
, NULL
);
3779 ok(SUCCEEDED(hr
), "IDirectDraw7_CreateSurface failed: 0x%08x\n", hr
);
3780 IDirectDrawSurface7_Release(surf7
);
3782 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd2_bad1
, &surf7
, NULL
);
3783 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDraw7_CreateSurface didn't return 0x%08x, but 0x%08x\n",
3784 DDERR_INVALIDPARAMS
, hr
);
3785 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd2_bad2
, &surf7
, NULL
);
3786 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDraw7_CreateSurface didn't return 0x%08x, but 0x%08x\n",
3787 DDERR_INVALIDPARAMS
, hr
);
3788 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd2_bad3
, &surf7
, NULL
);
3789 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDraw7_CreateSurface didn't return 0x%08x, but 0x%08x\n",
3790 DDERR_INVALIDPARAMS
, hr
);
3791 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd2_bad4
, &surf7
, NULL
);
3792 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDraw7_CreateSurface didn't return 0x%08x, but 0x%08x\n",
3793 DDERR_INVALIDPARAMS
, hr
);
3794 hr
= IDirectDraw7_CreateSurface(dd7
, NULL
, &surf7
, NULL
);
3795 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDraw7_CreateSurface didn't return 0x%08x, but 0x%08x\n",
3796 DDERR_INVALIDPARAMS
, hr
);
3798 IDirectDraw7_Release(dd7
);
3801 START_TEST(dsurface
)
3806 if (!CreateDirectDraw())
3809 ret
= IDirectDraw_QueryInterface(lpDD
, &IID_IDirectDraw4
, (void **) &dd4
);
3810 if (ret
== E_NOINTERFACE
)
3812 win_skip("DirectDraw4 and higher are not supported\n");
3813 ReleaseDirectDraw();
3816 IDirectDraw_Release(dd4
);
3818 if(!can_create_primary_surface())
3820 skip("Unable to create primary surface\n");
3824 ddcaps
.dwSize
= sizeof(DDCAPS
);
3825 ret
= IDirectDraw_GetCaps(lpDD
, &ddcaps
, NULL
);
3828 skip("IDirectDraw_GetCaps failed with %08x\n", ret
);
3832 MipMapCreationTest();
3833 SrcColorKey32BlitTest();
3844 test_lockrect_invalid();
3854 BackBufferCreateSurfaceTest();
3855 BackBufferAttachmentFlipTest();
3856 CreateSurfaceBadCapsSizeTest();
3857 ReleaseDirectDraw();