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
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/test.h"
30 static LPDIRECTDRAW lpDD
= NULL
;
32 static BOOL
CreateDirectDraw(void)
36 rc
= DirectDrawCreate(NULL
, &lpDD
, NULL
);
37 ok(rc
==DD_OK
|| rc
==DDERR_NODIRECTDRAWSUPPORT
, "DirectDrawCreateEx returned: %x\n", rc
);
39 trace("DirectDrawCreateEx() failed with an error %x\n", rc
);
43 rc
= IDirectDraw_SetCooperativeLevel(lpDD
, NULL
, DDSCL_NORMAL
);
44 ok(rc
==DD_OK
,"SetCooperativeLevel returned: %x\n",rc
);
50 static void ReleaseDirectDraw(void)
54 IDirectDraw_Release(lpDD
);
59 static void MipMapCreationTest(void)
61 LPDIRECTDRAWSURFACE lpDDSMipMapTest
;
65 /* First mipmap creation test: create a surface with DDSCAPS_COMPLEX,
66 DDSCAPS_MIPMAP, and DDSD_MIPMAPCOUNT. This create the number of
67 requested mipmap levels. */
68 ddsd
.dwSize
= sizeof(ddsd
);
69 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_MIPMAPCOUNT
;
70 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
71 U2(ddsd
).dwMipMapCount
= 3;
74 rc
= IDirectDraw_CreateSurface(lpDD
, &ddsd
, &lpDDSMipMapTest
, NULL
);
75 ok(rc
==DD_OK
,"CreateSurface returned: %x\n",rc
);
77 skip("failed to create surface\n");
81 /* Check the number of created mipmaps */
82 memset(&ddsd
, 0, sizeof(DDSURFACEDESC
));
83 ddsd
.dwSize
= sizeof(ddsd
);
84 rc
= IDirectDrawSurface_GetSurfaceDesc(lpDDSMipMapTest
, &ddsd
);
85 ok(rc
==DD_OK
,"GetSurfaceDesc returned: %x\n",rc
);
86 ok(ddsd
.dwFlags
& DDSD_MIPMAPCOUNT
,
87 "GetSurfaceDesc returned no mipmapcount.\n");
88 ok(U2(ddsd
).dwMipMapCount
== 3, "Incorrect mipmap count: %d.\n",
89 U2(ddsd
).dwMipMapCount
);
91 /* Destroy the surface. */
92 IDirectDrawSurface_Release(lpDDSMipMapTest
);
95 /* Second mipmap creation test: create a surface without a mipmap
96 count, with DDSCAPS_MIPMAP and without DDSCAPS_COMPLEX.
97 This creates a single mipmap level. */
98 memset(&ddsd
, 0, sizeof(DDSURFACEDESC
));
99 ddsd
.dwSize
= sizeof(ddsd
);
100 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
101 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
;
104 rc
= IDirectDraw_CreateSurface(lpDD
, &ddsd
, &lpDDSMipMapTest
, NULL
);
105 ok(rc
==DD_OK
,"CreateSurface returned: %x\n",rc
);
107 skip("failed to create surface\n");
110 /* Check the number of created mipmaps */
111 memset(&ddsd
, 0, sizeof(DDSURFACEDESC
));
112 ddsd
.dwSize
= sizeof(ddsd
);
113 rc
= IDirectDrawSurface_GetSurfaceDesc(lpDDSMipMapTest
, &ddsd
);
114 ok(rc
==DD_OK
,"GetSurfaceDesc returned: %x\n",rc
);
115 ok(ddsd
.dwFlags
& DDSD_MIPMAPCOUNT
,
116 "GetSurfaceDesc returned no mipmapcount.\n");
117 ok(U2(ddsd
).dwMipMapCount
== 1, "Incorrect mipmap count: %d.\n",
118 U2(ddsd
).dwMipMapCount
);
120 /* Destroy the surface. */
121 IDirectDrawSurface_Release(lpDDSMipMapTest
);
124 /* Third mipmap creation test: create a surface with DDSCAPS_MIPMAP,
125 DDSCAPS_COMPLEX and without DDSD_MIPMAPCOUNT.
126 It's an undocumented features where a chain of mipmaps, starting from
127 he specified size and down to the smallest size, is automatically
129 Anarchy Online needs this feature to work. */
130 memset(&ddsd
, 0, sizeof(DDSURFACEDESC
));
131 ddsd
.dwSize
= sizeof(ddsd
);
132 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
133 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
136 rc
= IDirectDraw_CreateSurface(lpDD
, &ddsd
, &lpDDSMipMapTest
, NULL
);
137 ok(rc
==DD_OK
,"CreateSurface returned: %x\n",rc
);
139 skip("failed to create surface\n");
143 /* Check the number of created mipmaps */
144 memset(&ddsd
, 0, sizeof(DDSURFACEDESC
));
145 ddsd
.dwSize
= sizeof(ddsd
);
146 rc
= IDirectDrawSurface_GetSurfaceDesc(lpDDSMipMapTest
, &ddsd
);
147 ok(rc
==DD_OK
,"GetSurfaceDesc returned: %x\n",rc
);
148 ok(ddsd
.dwFlags
& DDSD_MIPMAPCOUNT
,
149 "GetSurfaceDesc returned no mipmapcount.\n");
150 ok(U2(ddsd
).dwMipMapCount
== 6, "Incorrect mipmap count: %d.\n",
151 U2(ddsd
).dwMipMapCount
);
153 /* Destroy the surface. */
154 IDirectDrawSurface_Release(lpDDSMipMapTest
);
157 /* Fourth mipmap creation test: same as above with a different texture
159 The purpose is to verify that the number of generated mipmaps is
160 dependent on the smallest dimension. */
161 memset(&ddsd
, 0, sizeof(DDSURFACEDESC
));
162 ddsd
.dwSize
= sizeof(ddsd
);
163 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
164 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
167 rc
= IDirectDraw_CreateSurface(lpDD
, &ddsd
, &lpDDSMipMapTest
, NULL
);
168 ok(rc
==DD_OK
,"CreateSurface returned: %x\n",rc
);
170 skip("failed to create surface\n");
174 /* Check the number of created mipmaps */
175 memset(&ddsd
, 0, sizeof(DDSURFACEDESC
));
176 ddsd
.dwSize
= sizeof(ddsd
);
177 rc
= IDirectDrawSurface_GetSurfaceDesc(lpDDSMipMapTest
, &ddsd
);
178 ok(rc
==DD_OK
,"GetSurfaceDesc returned: %x\n",rc
);
179 ok(ddsd
.dwFlags
& DDSD_MIPMAPCOUNT
,
180 "GetSurfaceDesc returned no mipmapcount.\n");
181 ok(U2(ddsd
).dwMipMapCount
== 6, "Incorrect mipmap count: %d.\n",
182 U2(ddsd
).dwMipMapCount
);
184 /* Destroy the surface. */
185 IDirectDrawSurface_Release(lpDDSMipMapTest
);
188 /* Fifth mipmap creation test: try to create a surface with
189 DDSCAPS_COMPLEX, DDSCAPS_MIPMAP, DDSD_MIPMAPCOUNT,
190 where dwMipMapCount = 0. This should fail. */
192 ddsd
.dwSize
= sizeof(ddsd
);
193 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_MIPMAPCOUNT
;
194 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
195 U2(ddsd
).dwMipMapCount
= 0;
198 rc
= IDirectDraw_CreateSurface(lpDD
, &ddsd
, &lpDDSMipMapTest
, NULL
);
199 ok(rc
==DDERR_INVALIDPARAMS
,"CreateSurface returned: %x\n",rc
);
201 /* Destroy the surface. */
203 IDirectDrawSurface_Release(lpDDSMipMapTest
);
207 static void SrcColorKey32BlitTest(void)
209 LPDIRECTDRAWSURFACE lpSrc
;
210 LPDIRECTDRAWSURFACE lpDst
;
211 DDSURFACEDESC ddsd
, ddsd2
, ddsd3
;
212 DDCOLORKEY DDColorKey
;
217 ddsd2
.dwSize
= sizeof(ddsd2
);
218 ddsd2
.ddpfPixelFormat
.dwSize
= sizeof(ddsd2
.ddpfPixelFormat
);
220 ddsd
.dwSize
= sizeof(ddsd
);
221 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
222 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
223 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
226 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
227 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
228 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0xFF0000;
229 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x00FF00;
230 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x0000FF;
231 rc
= IDirectDraw_CreateSurface(lpDD
, &ddsd
, &lpDst
, NULL
);
232 ok(rc
==DD_OK
,"CreateSurface returned: %x\n",rc
);
234 skip("failed to create surface\n");
238 ddsd
.dwFlags
|= DDSD_CKSRCBLT
;
239 ddsd
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0xFF00FF;
240 ddsd
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0xFF00FF;
241 rc
= IDirectDraw_CreateSurface(lpDD
, &ddsd
, &lpSrc
, NULL
);
242 ok(rc
==DD_OK
,"CreateSurface returned: %x\n",rc
);
244 skip("failed to create surface\n");
248 rc
= IDirectDrawSurface_Lock(lpDst
, NULL
, &ddsd2
, DDLOCK_WAIT
, NULL
);
249 ok(rc
==DD_OK
,"Lock returned: %x\n",rc
);
250 lpData
= (LPDWORD
)ddsd2
.lpSurface
;
251 lpData
[0] = 0xCCCCCCCC;
252 lpData
[1] = 0xCCCCCCCC;
253 lpData
[2] = 0xCCCCCCCC;
254 lpData
[3] = 0xCCCCCCCC;
256 memset(&ddsd3
, 0, sizeof(ddsd3
));
257 ddsd3
.dwSize
= sizeof(ddsd3
);
258 ddsd3
.ddpfPixelFormat
.dwSize
= sizeof(ddsd3
.ddpfPixelFormat
);
259 rc
= IDirectDrawSurface_GetSurfaceDesc(lpDst
, &ddsd3
);
260 ok(rc
== DD_OK
, "IDirectDrawSurface_GetSurfaceDesc between a lock/unlock pair returned %08x\n", rc
);
261 ok(ddsd3
.lpSurface
== ddsd3
.lpSurface
, "lpSurface from GetSurfaceDesc(%p) differs from the one returned by Lock(%p)\n", ddsd3
.lpSurface
, ddsd2
.lpSurface
);
263 rc
= IDirectDrawSurface_Unlock(lpDst
, NULL
);
264 ok(rc
==DD_OK
,"Unlock returned: %x\n",rc
);
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
== NULL
, "lpSurface from GetSurfaceDesc(%p) is not NULL after unlock\n", ddsd3
.lpSurface
);
273 rc
= IDirectDrawSurface_Lock(lpSrc
, NULL
, &ddsd2
, DDLOCK_WAIT
, NULL
);
274 ok(rc
==DD_OK
,"Lock returned: %x\n",rc
);
275 ok((ddsd2
.dwFlags
& DDSD_LPSURFACE
) == 0, "Surface desc has LPSURFACE Flags set\n");
276 lpData
= (LPDWORD
)ddsd2
.lpSurface
;
277 lpData
[0] = 0x77010203;
278 lpData
[1] = 0x00010203;
279 lpData
[2] = 0x77FF00FF;
280 lpData
[3] = 0x00FF00FF;
281 rc
= IDirectDrawSurface_Unlock(lpSrc
, NULL
);
282 ok(rc
==DD_OK
,"Unlock returned: %x\n",rc
);
284 IDirectDrawSurface_Blt(lpDst
, NULL
, lpSrc
, NULL
, DDBLT_KEYSRC
, NULL
);
286 rc
= IDirectDrawSurface_Lock(lpDst
, NULL
, &ddsd2
, DDLOCK_WAIT
, NULL
);
287 ok(rc
==DD_OK
,"Lock returned: %x\n",rc
);
288 ok((ddsd2
.dwFlags
& DDSD_LPSURFACE
) == 0, "Surface desc has LPSURFACE Flags set\n");
289 lpData
= (LPDWORD
)ddsd2
.lpSurface
;
290 /* Different behavior on some drivers / windows versions. Some versions ignore the X channel when
291 * color keying, but copy it to the destination surface. Others apply it for color keying, but
292 * do not copy it into the destination surface.
294 if(lpData
[0]==0x00010203) {
295 trace("X channel was not copied into the destination surface\n");
296 ok((lpData
[0]==0x00010203)&&(lpData
[1]==0x00010203)&&(lpData
[2]==0x00FF00FF)&&(lpData
[3]==0xCCCCCCCC),
297 "Destination data after blitting is not correct\n");
299 ok((lpData
[0]==0x77010203)&&(lpData
[1]==0x00010203)&&(lpData
[2]==0xCCCCCCCC)&&(lpData
[3]==0xCCCCCCCC),
300 "Destination data after blitting is not correct\n");
302 rc
= IDirectDrawSurface_Unlock(lpDst
, NULL
);
303 ok(rc
==DD_OK
,"Unlock returned: %x\n",rc
);
305 /* Also test SetColorKey */
306 IDirectDrawSurface_GetColorKey(lpSrc
, DDCKEY_SRCBLT
, &DDColorKey
);
307 ok(DDColorKey
.dwColorSpaceLowValue
== 0xFF00FF && DDColorKey
.dwColorSpaceHighValue
== 0xFF00FF,
308 "GetColorKey does not return the colorkey used at surface creation\n");
310 DDColorKey
.dwColorSpaceLowValue
= 0x00FF00;
311 DDColorKey
.dwColorSpaceHighValue
= 0x00FF00;
312 IDirectDrawSurface_SetColorKey(lpSrc
, DDCKEY_SRCBLT
, &DDColorKey
);
314 DDColorKey
.dwColorSpaceLowValue
= 0;
315 DDColorKey
.dwColorSpaceHighValue
= 0;
316 IDirectDrawSurface_GetColorKey(lpSrc
, DDCKEY_SRCBLT
, &DDColorKey
);
317 ok(DDColorKey
.dwColorSpaceLowValue
== 0x00FF00 && DDColorKey
.dwColorSpaceHighValue
== 0x00FF00,
318 "GetColorKey does not return the colorkey set with SetColorKey\n");
320 ddsd
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0;
321 ddsd
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0;
322 IDirectDrawSurface_GetSurfaceDesc(lpSrc
, &ddsd
);
323 ok(ddsd
.ddckCKSrcBlt
.dwColorSpaceLowValue
== 0x00FF00 && ddsd
.ddckCKSrcBlt
.dwColorSpaceHighValue
== 0x00FF00,
324 "GetSurfaceDesc does not return the colorkey set with SetColorKey\n");
326 IDirectDrawSurface_Release(lpSrc
);
327 IDirectDrawSurface_Release(lpDst
);
329 /* start with a new set of surfaces to test the color keying parameters to blit */
330 memset(&ddsd
, 0, sizeof(ddsd
));
331 ddsd
.dwSize
= sizeof(ddsd
);
332 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
333 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CKSRCBLT
| DDSD_CKDESTBLT
;
334 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
337 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
338 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
339 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0xFF0000;
340 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x00FF00;
341 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x0000FF;
342 ddsd
.ddckCKDestBlt
.dwColorSpaceLowValue
= 0xFF0000;
343 ddsd
.ddckCKDestBlt
.dwColorSpaceHighValue
= 0xFF0000;
344 ddsd
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00FF00;
345 ddsd
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00FF00;
346 rc
= IDirectDraw_CreateSurface(lpDD
, &ddsd
, &lpDst
, NULL
);
347 ok(rc
==DD_OK
|| rc
== DDERR_NOCOLORKEYHW
,"CreateSurface returned: %x\n",rc
);
350 skip("Failed to create surface\n");
354 /* start with a new set of surfaces to test the color keying parameters to blit */
355 memset(&ddsd
, 0, sizeof(ddsd
));
356 ddsd
.dwSize
= sizeof(ddsd
);
357 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
358 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CKSRCBLT
| DDSD_CKDESTBLT
;
359 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
362 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
363 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
364 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0xFF0000;
365 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x00FF00;
366 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x0000FF;
367 ddsd
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x0000FF;
368 ddsd
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x0000FF;
369 ddsd
.ddckCKDestBlt
.dwColorSpaceLowValue
= 0x000000;
370 ddsd
.ddckCKDestBlt
.dwColorSpaceHighValue
= 0x000000;
371 rc
= IDirectDraw_CreateSurface(lpDD
, &ddsd
, &lpSrc
, NULL
);
372 ok(rc
==DD_OK
|| rc
== DDERR_NOCOLORKEYHW
,"CreateSurface returned: %x\n",rc
);
375 skip("Failed to create surface\n");
376 IDirectDrawSurface_Release(lpDst
);
380 memset(&fx
, 0, sizeof(fx
));
381 fx
.dwSize
= sizeof(fx
);
382 fx
.ddckSrcColorkey
.dwColorSpaceHighValue
= 0x110000;
383 fx
.ddckSrcColorkey
.dwColorSpaceLowValue
= 0x110000;
384 fx
.ddckDestColorkey
.dwColorSpaceHighValue
= 0x001100;
385 fx
.ddckDestColorkey
.dwColorSpaceLowValue
= 0x001100;
387 rc
= IDirectDrawSurface_Lock(lpSrc
, NULL
, &ddsd2
, DDLOCK_WAIT
, NULL
);
388 ok(rc
==DD_OK
,"Lock returned: %x\n",rc
);
389 ok((ddsd2
.dwFlags
& DDSD_LPSURFACE
) == 0, "Surface desc has LPSURFACE Flags set\n");
390 lpData
= (LPDWORD
)ddsd2
.lpSurface
;
391 lpData
[0] = 0x000000FF; /* Applies to src blt key in src surface */
392 lpData
[1] = 0x00000000; /* Applies to dst blt key in src surface */
393 lpData
[2] = 0x00FF0000; /* Dst color key in dst surface */
394 lpData
[3] = 0x0000FF00; /* Src color key in dst surface */
395 lpData
[4] = 0x00001100; /* Src color key in ddbltfx */
396 lpData
[5] = 0x00110000; /* Dst color key in ddbltfx */
397 rc
= IDirectDrawSurface_Unlock(lpSrc
, NULL
);
398 ok(rc
==DD_OK
,"Unlock returned: %x\n",rc
);
400 rc
= IDirectDrawSurface_Lock(lpDst
, NULL
, &ddsd2
, DDLOCK_WAIT
, NULL
);
401 ok(rc
==DD_OK
,"Lock returned: %x\n",rc
);
402 ok((ddsd2
.dwFlags
& DDSD_LPSURFACE
) == 0, "Surface desc has LPSURFACE Flags set\n");
403 lpData
= (LPDWORD
)ddsd2
.lpSurface
;
404 lpData
[0] = 0x55555555;
405 lpData
[1] = 0x55555555;
406 lpData
[2] = 0x55555555;
407 lpData
[3] = 0x55555555;
408 lpData
[4] = 0x55555555;
409 lpData
[5] = 0x55555555;
410 rc
= IDirectDrawSurface_Unlock(lpDst
, NULL
);
411 ok(rc
==DD_OK
,"Unlock returned: %x\n",rc
);
413 /* Test a blit without keying */
414 rc
= IDirectDrawSurface_Blt(lpDst
, NULL
, lpSrc
, NULL
, 0, &fx
);
415 ok(rc
== DD_OK
, "IDirectDrawSurface_Blt returned %08x\n", rc
);
417 rc
= IDirectDrawSurface_Lock(lpDst
, NULL
, &ddsd2
, DDLOCK_WAIT
, NULL
);
418 ok(rc
==DD_OK
,"Lock returned: %x\n",rc
);
419 ok((ddsd2
.dwFlags
& DDSD_LPSURFACE
) == 0, "Surface desc has LPSURFACE Flags set\n");
420 lpData
= (LPDWORD
)ddsd2
.lpSurface
;
421 /* Should have copied src data unmodified to dst */
422 ok(lpData
[0] == 0x000000FF &&
423 lpData
[1] == 0x00000000 &&
424 lpData
[2] == 0x00FF0000 &&
425 lpData
[3] == 0x0000FF00 &&
426 lpData
[4] == 0x00001100 &&
427 lpData
[5] == 0x00110000, "Surface data after unkeyed blit does not match\n");
429 lpData
[0] = 0x55555555;
430 lpData
[1] = 0x55555555;
431 lpData
[2] = 0x55555555;
432 lpData
[3] = 0x55555555;
433 lpData
[4] = 0x55555555;
434 lpData
[5] = 0x55555555;
435 rc
= IDirectDrawSurface_Unlock(lpDst
, NULL
);
436 ok(rc
==DD_OK
,"Unlock returned: %x\n",rc
);
439 rc
= IDirectDrawSurface_Blt(lpDst
, NULL
, lpSrc
, NULL
, DDBLT_KEYSRC
, &fx
);
440 ok(rc
== DD_OK
, "IDirectDrawSurface_Blt returned %08x\n", rc
);
442 rc
= IDirectDrawSurface_Lock(lpDst
, NULL
, &ddsd2
, DDLOCK_WAIT
, NULL
);
443 ok(rc
==DD_OK
,"Lock returned: %x\n",rc
);
444 ok((ddsd2
.dwFlags
& DDSD_LPSURFACE
) == 0, "Surface desc has LPSURFACE Flags set\n");
445 lpData
= (LPDWORD
)ddsd2
.lpSurface
;
447 ok(lpData
[0] == 0x55555555 && /* Here the src key applied */
448 lpData
[1] == 0x00000000 &&
449 lpData
[2] == 0x00FF0000 &&
450 lpData
[3] == 0x0000FF00 &&
451 lpData
[4] == 0x00001100 &&
452 lpData
[5] == 0x00110000, "Surface data after srckey blit does not match\n");
454 lpData
[0] = 0x55555555;
455 lpData
[1] = 0x55555555;
456 lpData
[2] = 0x55555555;
457 lpData
[3] = 0x55555555;
458 lpData
[4] = 0x55555555;
459 lpData
[5] = 0x55555555;
460 rc
= IDirectDrawSurface_Unlock(lpDst
, NULL
);
461 ok(rc
==DD_OK
,"Unlock returned: %x\n",rc
);
464 rc
= IDirectDrawSurface_Blt(lpDst
, NULL
, lpSrc
, NULL
, DDBLT_KEYSRCOVERRIDE
, &fx
);
465 ok(rc
== DD_OK
, "IDirectDrawSurface_Blt returned %08x\n", rc
);
467 rc
= IDirectDrawSurface_Lock(lpDst
, NULL
, &ddsd2
, DDLOCK_WAIT
, NULL
);
468 ok(rc
==DD_OK
,"Lock returned: %x\n",rc
);
469 ok((ddsd2
.dwFlags
& DDSD_LPSURFACE
) == 0, "Surface desc has LPSURFACE Flags set\n");
470 lpData
= (LPDWORD
)ddsd2
.lpSurface
;
472 ok(lpData
[0] == 0x000000FF &&
473 lpData
[1] == 0x00000000 &&
474 lpData
[2] == 0x00FF0000 &&
475 lpData
[3] == 0x0000FF00 &&
476 lpData
[4] == 0x00001100 &&
477 lpData
[5] == 0x55555555, /* Override key applies here */
478 "Surface data after src override key blit does not match\n");
480 lpData
[0] = 0x55555555;
481 lpData
[1] = 0x55555555;
482 lpData
[2] = 0x55555555;
483 lpData
[3] = 0x55555555;
484 lpData
[4] = 0x55555555;
485 lpData
[5] = 0x55555555;
486 rc
= IDirectDrawSurface_Unlock(lpDst
, NULL
);
487 ok(rc
==DD_OK
,"Unlock returned: %x\n",rc
);
489 /* Src override AND src key. That is not supposed to work */
490 rc
= IDirectDrawSurface_Blt(lpDst
, NULL
, lpSrc
, NULL
, DDBLT_KEYSRC
| DDBLT_KEYSRCOVERRIDE
, &fx
);
491 ok(rc
== DDERR_INVALIDPARAMS
, "IDirectDrawSurface_Blt returned %08x\n", rc
);
493 /* Verify that the destination is unchanged */
494 rc
= IDirectDrawSurface_Lock(lpDst
, NULL
, &ddsd2
, DDLOCK_WAIT
, NULL
);
495 ok(rc
==DD_OK
,"Lock returned: %x\n",rc
);
496 ok((ddsd2
.dwFlags
& DDSD_LPSURFACE
) == 0, "Surface desc has LPSURFACE Flags set\n");
497 lpData
= (LPDWORD
)ddsd2
.lpSurface
;
499 ok(lpData
[0] == 0x55555555 &&
500 lpData
[1] == 0x55555555 &&
501 lpData
[2] == 0x55555555 &&
502 lpData
[3] == 0x55555555 &&
503 lpData
[4] == 0x55555555 &&
504 lpData
[5] == 0x55555555, /* Override key applies here */
505 "Surface data after src key blit with override does not match\n");
507 lpData
[0] = 0x00FF0000; /* Dest key in dst surface */
508 lpData
[1] = 0x00FF0000; /* Dest key in dst surface */
509 lpData
[2] = 0x00001100; /* Dest key in override */
510 lpData
[3] = 0x00001100; /* Dest key in override */
511 lpData
[4] = 0x00000000; /* Dest key in src surface */
512 lpData
[5] = 0x00000000; /* Dest key in src surface */
513 rc
= IDirectDrawSurface_Unlock(lpDst
, NULL
);
514 ok(rc
==DD_OK
,"Unlock returned: %x\n",rc
);
517 rc
= IDirectDrawSurface_Blt(lpDst
, NULL
, lpSrc
, NULL
, DDBLT_KEYDEST
, &fx
);
518 ok(rc
== DD_OK
, "IDirectDrawSurface_Blt returned %08x\n", rc
);
520 rc
= IDirectDrawSurface_Lock(lpDst
, NULL
, &ddsd2
, DDLOCK_WAIT
, NULL
);
521 ok(rc
==DD_OK
,"Lock returned: %x\n",rc
);
522 ok((ddsd2
.dwFlags
& DDSD_LPSURFACE
) == 0, "Surface desc has LPSURFACE Flags set\n");
523 lpData
= (LPDWORD
)ddsd2
.lpSurface
;
525 /* DirectDraw uses the dest blit key from the SOURCE surface ! */
526 ok(lpData
[0] == 0x00ff0000 &&
527 lpData
[1] == 0x00ff0000 &&
528 lpData
[2] == 0x00001100 &&
529 lpData
[3] == 0x00001100 &&
530 lpData
[4] == 0x00001100 && /* Key applies here */
531 lpData
[5] == 0x00110000, /* Key applies here */
532 "Surface data after dest key blit does not match\n");
534 lpData
[0] = 0x00FF0000; /* Dest key in dst surface */
535 lpData
[1] = 0x00FF0000; /* Dest key in dst surface */
536 lpData
[2] = 0x00001100; /* Dest key in override */
537 lpData
[3] = 0x00001100; /* Dest key in override */
538 lpData
[4] = 0x00000000; /* Dest key in src surface */
539 lpData
[5] = 0x00000000; /* Dest key in src surface */
540 rc
= IDirectDrawSurface_Unlock(lpDst
, NULL
);
541 ok(rc
==DD_OK
,"Unlock returned: %x\n",rc
);
543 /* Dest override key blit */
544 rc
= IDirectDrawSurface_Blt(lpDst
, NULL
, lpSrc
, NULL
, DDBLT_KEYDESTOVERRIDE
, &fx
);
545 ok(rc
== DD_OK
, "IDirectDrawSurface_Blt returned %08x\n", rc
);
547 rc
= IDirectDrawSurface_Lock(lpDst
, NULL
, &ddsd2
, DDLOCK_WAIT
, NULL
);
548 ok(rc
==DD_OK
,"Lock returned: %x\n",rc
);
549 ok((ddsd2
.dwFlags
& DDSD_LPSURFACE
) == 0, "Surface desc has LPSURFACE Flags set\n");
550 lpData
= (LPDWORD
)ddsd2
.lpSurface
;
552 ok(lpData
[0] == 0x00FF0000 &&
553 lpData
[1] == 0x00FF0000 &&
554 lpData
[2] == 0x00FF0000 && /* Key applies here */
555 lpData
[3] == 0x0000FF00 && /* Key applies here */
556 lpData
[4] == 0x00000000 &&
557 lpData
[5] == 0x00000000,
558 "Surface data after dest key override blit does not match\n");
560 lpData
[0] = 0x00FF0000; /* Dest key in dst surface */
561 lpData
[1] = 0x00FF0000; /* Dest key in dst surface */
562 lpData
[2] = 0x00001100; /* Dest key in override */
563 lpData
[3] = 0x00001100; /* Dest key in override */
564 lpData
[4] = 0x00000000; /* Dest key in src surface */
565 lpData
[5] = 0x00000000; /* Dest key in src surface */
566 rc
= IDirectDrawSurface_Unlock(lpDst
, NULL
);
567 ok(rc
==DD_OK
,"Unlock returned: %x\n",rc
);
569 /* Dest override key blit. Supposed to fail too */
570 rc
= IDirectDrawSurface_Blt(lpDst
, NULL
, lpSrc
, NULL
, DDBLT_KEYDEST
| DDBLT_KEYDESTOVERRIDE
, &fx
);
571 ok(rc
== DDERR_INVALIDPARAMS
, "IDirectDrawSurface_Blt returned %08x\n", rc
);
573 /* Check for unchanged data */
574 rc
= IDirectDrawSurface_Lock(lpDst
, NULL
, &ddsd2
, DDLOCK_WAIT
, NULL
);
575 ok(rc
==DD_OK
,"Lock returned: %x\n",rc
);
576 ok((ddsd2
.dwFlags
& DDSD_LPSURFACE
) == 0, "Surface desc has LPSURFACE Flags set\n");
577 lpData
= (LPDWORD
)ddsd2
.lpSurface
;
579 ok(lpData
[0] == 0x00FF0000 &&
580 lpData
[1] == 0x00FF0000 &&
581 lpData
[2] == 0x00001100 && /* Key applies here */
582 lpData
[3] == 0x00001100 && /* Key applies here */
583 lpData
[4] == 0x00000000 &&
584 lpData
[5] == 0x00000000,
585 "Surface data with dest key and dest override does not match\n");
587 lpData
[0] = 0x00FF0000; /* Dest key in dst surface */
588 lpData
[1] = 0x00FF0000; /* Dest key in dst surface */
589 lpData
[2] = 0x00001100; /* Dest key in override */
590 lpData
[3] = 0x00001100; /* Dest key in override */
591 lpData
[4] = 0x00000000; /* Dest key in src surface */
592 lpData
[5] = 0x00000000; /* Dest key in src surface */
593 rc
= IDirectDrawSurface_Unlock(lpDst
, NULL
);
594 ok(rc
==DD_OK
,"Unlock returned: %x\n",rc
);
596 /* Modify the source data a bit to give some more conclusive results */
597 rc
= IDirectDrawSurface_Lock(lpSrc
, NULL
, &ddsd2
, DDLOCK_WAIT
, NULL
);
598 ok(rc
==DD_OK
,"Lock returned: %x\n",rc
);
599 ok((ddsd2
.dwFlags
& DDSD_LPSURFACE
) == 0, "Surface desc has LPSURFACE Flags set\n");
600 lpData
= (LPDWORD
)ddsd2
.lpSurface
;
601 lpData
[5] = 0x000000FF; /* Applies to src blt key in src surface */
602 rc
= IDirectDrawSurface_Unlock(lpSrc
, NULL
);
603 ok(rc
==DD_OK
,"Unlock returned: %x\n",rc
);
605 /* Source and destination key */
606 rc
= IDirectDrawSurface_Blt(lpDst
, NULL
, lpSrc
, NULL
, DDBLT_KEYDEST
| DDBLT_KEYSRC
, &fx
);
607 ok(rc
== DD_OK
, "IDirectDrawSurface_Blt returned %08x\n", rc
);
609 rc
= IDirectDrawSurface_Lock(lpDst
, NULL
, &ddsd2
, DDLOCK_WAIT
, NULL
);
610 ok(rc
==DD_OK
,"Lock returned: %x\n",rc
);
611 ok((ddsd2
.dwFlags
& DDSD_LPSURFACE
) == 0, "Surface desc has LPSURFACE Flags set\n");
612 lpData
= (LPDWORD
)ddsd2
.lpSurface
;
614 ok(lpData
[0] == 0x00FF0000 && /* Masked by Destination key */
615 lpData
[1] == 0x00FF0000 && /* Masked by Destination key */
616 lpData
[2] == 0x00001100 && /* Masked by Destination key */
617 lpData
[3] == 0x00001100 && /* Masked by Destination key */
618 lpData
[4] == 0x00001100 && /* Allowed by destination key, not masked by source key */
619 lpData
[5] == 0x00000000, /* Allowed by dst key, but masked by source key */
620 "Surface data with src key and dest key blit does not match\n");
622 lpData
[0] = 0x00FF0000; /* Dest key in dst surface */
623 lpData
[1] = 0x00FF0000; /* Dest key in dst surface */
624 lpData
[2] = 0x00001100; /* Dest key in override */
625 lpData
[3] = 0x00001100; /* Dest key in override */
626 lpData
[4] = 0x00000000; /* Dest key in src surface */
627 lpData
[5] = 0x00000000; /* Dest key in src surface */
628 rc
= IDirectDrawSurface_Unlock(lpDst
, NULL
);
629 ok(rc
==DD_OK
,"Unlock returned: %x\n",rc
);
631 /* Override keys without ddbltfx parameter fail */
632 rc
= IDirectDrawSurface_Blt(lpDst
, NULL
, lpSrc
, NULL
, DDBLT_KEYDESTOVERRIDE
, NULL
);
633 ok(rc
== DDERR_INVALIDPARAMS
, "IDirectDrawSurface_Blt returned %08x\n", rc
);
634 rc
= IDirectDrawSurface_Blt(lpDst
, NULL
, lpSrc
, NULL
, DDBLT_KEYSRCOVERRIDE
, NULL
);
635 ok(rc
== DDERR_INVALIDPARAMS
, "IDirectDrawSurface_Blt returned %08x\n", rc
);
637 /* Try blitting without keys in the source surface*/
638 rc
= IDirectDrawSurface_SetColorKey(lpSrc
, DDCKEY_SRCBLT
, NULL
);
639 ok(rc
== DD_OK
, "SetColorKey returned %x\n", rc
);
640 rc
= IDirectDrawSurface_SetColorKey(lpSrc
, DDCKEY_DESTBLT
, NULL
);
641 ok(rc
== DD_OK
, "SetColorKey returned %x\n", rc
);
643 /* That fails now. Do not bother to check that the data is unmodified */
644 rc
= IDirectDrawSurface_Blt(lpDst
, NULL
, lpSrc
, NULL
, DDBLT_KEYSRC
, &fx
);
645 ok(rc
== DDERR_INVALIDPARAMS
, "IDirectDrawSurface_Blt returned %08x\n", rc
);
647 /* Dest key blit still works. Which key is used this time??? */
648 rc
= IDirectDrawSurface_Blt(lpDst
, NULL
, lpSrc
, NULL
, DDBLT_KEYDEST
, &fx
);
649 ok(rc
== DD_OK
, "IDirectDrawSurface_Blt returned %08x\n", rc
);
651 /* With correctly passed override keys no key in the surface is needed.
652 * Again, the result was checked before, no need to do that again
654 rc
= IDirectDrawSurface_Blt(lpDst
, NULL
, lpSrc
, NULL
, DDBLT_KEYDESTOVERRIDE
, &fx
);
655 ok(rc
== DD_OK
, "IDirectDrawSurface_Blt returned %08x\n", rc
);
656 rc
= IDirectDrawSurface_Blt(lpDst
, NULL
, lpSrc
, NULL
, DDBLT_KEYSRCOVERRIDE
, &fx
);
657 ok(rc
== DD_OK
, "IDirectDrawSurface_Blt returned %08x\n", rc
);
659 IDirectDrawSurface_Release(lpSrc
);
660 IDirectDrawSurface_Release(lpDst
);
663 static void QueryInterface(void)
665 LPDIRECTDRAWSURFACE dsurface
;
666 DDSURFACEDESC surface
;
670 /* Create a surface */
671 ZeroMemory(&surface
, sizeof(surface
));
672 surface
.dwSize
= sizeof(surface
);
673 surface
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
;
674 surface
.dwHeight
= 10;
675 surface
.dwWidth
= 10;
676 ret
= IDirectDraw_CreateSurface(lpDD
, &surface
, &dsurface
, NULL
);
679 ok(FALSE
, "IDirectDraw::CreateSurface failed with error %x\n", ret
);
683 /* Call IUnknown::QueryInterface */
684 ret
= IDirectDrawSurface_QueryInterface(dsurface
, 0, &object
);
685 ok(ret
== DDERR_INVALIDPARAMS
, "IDirectDrawSurface::QueryInterface returned %x\n", ret
);
687 IDirectDrawSurface_Release(dsurface
);
690 /* The following tests test which interface is returned by IDirectDrawSurfaceX::GetDDInterface.
691 * It uses refcounts to test that and compares the interface addresses. Partially fits here, and
692 * partially in the refcount test
695 static unsigned long getref(IUnknown
*iface
)
697 IUnknown_AddRef(iface
);
698 return IUnknown_Release(iface
);
701 static void GetDDInterface_1(void)
703 LPDIRECTDRAWSURFACE dsurface
;
704 LPDIRECTDRAWSURFACE2 dsurface2
;
705 DDSURFACEDESC surface
;
710 unsigned long ref1
, ref2
, ref4
, ref7
;
713 /* Create a surface */
714 ZeroMemory(&surface
, sizeof(surface
));
715 surface
.dwSize
= sizeof(surface
);
716 surface
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
;
717 surface
.dwHeight
= 10;
718 surface
.dwWidth
= 10;
719 ret
= IDirectDraw_CreateSurface(lpDD
, &surface
, &dsurface
, NULL
);
722 ok(FALSE
, "IDirectDraw::CreateSurface failed with error %x\n", ret
);
725 ret
= IDirectDrawSurface_QueryInterface(dsurface
, &IID_IDirectDrawSurface2
, (void **) &dsurface2
);
726 ok(ret
== DD_OK
, "IDirectDrawSurface_QueryInterface returned %08x\n", ret
);
727 ret
= IDirectDraw_QueryInterface(lpDD
, &IID_IDirectDraw2
, (void **) &dd2
);
728 ok(ret
== DD_OK
, "IDirectDraw7_QueryInterface returned %08x\n", ret
);
729 ret
= IDirectDraw_QueryInterface(lpDD
, &IID_IDirectDraw4
, (void **) &dd4
);
730 ok(ret
== DD_OK
, "IDirectDraw7_QueryInterface returned %08x\n", ret
);
731 ret
= IDirectDraw_QueryInterface(lpDD
, &IID_IDirectDraw7
, (void **) &dd7
);
732 ok(ret
== DD_OK
, "IDirectDraw7_QueryInterface returned %08x\n", ret
);
734 ref1
= getref((IUnknown
*) lpDD
);
735 ok(ref1
== 1, "IDirectDraw refcount is %ld\n", ref1
);
736 ref2
= getref((IUnknown
*) dd2
);
737 ok(ref2
== 1, "IDirectDraw2 refcount is %ld\n", ref2
);
738 ref4
= getref((IUnknown
*) dd4
);
739 ok(ref4
== 1, "IDirectDraw4 refcount is %ld\n", ref4
);
740 ref7
= getref((IUnknown
*) dd7
);
741 ok(ref7
== 1, "IDirectDraw7 refcount is %ld\n", ref7
);
744 ret
= IDirectDrawSurface2_GetDDInterface(dsurface2
, &dd
);
745 ok(ret
== DD_OK
, "IDirectDrawSurface7_GetDDInterface returned %08x\n", ret
);
746 ok(getref((IUnknown
*) lpDD
) == ref1
+ 1, "IDirectDraw refcount was increased by %ld\n", getref((IUnknown
*) lpDD
) - ref1
);
747 ok(getref((IUnknown
*) dd2
) == ref2
+ 0, "IDirectDraw2 refcount was increased by %ld\n", getref((IUnknown
*) dd2
) - ref2
);
748 ok(getref((IUnknown
*) dd4
) == ref4
+ 0, "IDirectDraw4 refcount was increased by %ld\n", getref((IUnknown
*) dd4
) - ref4
);
749 ok(getref((IUnknown
*) dd7
) == ref7
+ 0, "IDirectDraw7 refcount was increased by %ld\n", getref((IUnknown
*) dd7
) - ref7
);
751 ok(dd
== lpDD
, "Returned interface pointer is not equal to the creation interface\n");
752 IUnknown_Release((IUnknown
*) dd
);
754 /* try a NULL pointer */
755 ret
= IDirectDrawSurface2_GetDDInterface(dsurface2
, NULL
);
756 ok(ret
== DDERR_INVALIDPARAMS
, "IDirectDrawSurface7_GetDDInterface returned %08x\n", ret
);
758 IDirectDraw_Release(dd2
);
759 IDirectDraw_Release(dd4
);
760 IDirectDraw_Release(dd7
);
761 IDirectDrawSurface2_Release(dsurface2
);
762 IDirectDrawSurface_Release(dsurface
);
765 static void GetDDInterface_2(void)
767 LPDIRECTDRAWSURFACE dsurface
;
768 LPDIRECTDRAWSURFACE2 dsurface2
;
769 DDSURFACEDESC surface
;
774 unsigned long ref1
, ref2
, ref4
, ref7
;
777 ret
= IDirectDraw_QueryInterface(lpDD
, &IID_IDirectDraw2
, (void **) &dd2
);
778 ok(ret
== DD_OK
, "IDirectDraw7_QueryInterface returned %08x\n", ret
);
779 ret
= IDirectDraw_QueryInterface(lpDD
, &IID_IDirectDraw4
, (void **) &dd4
);
780 ok(ret
== DD_OK
, "IDirectDraw7_QueryInterface returned %08x\n", ret
);
781 ret
= IDirectDraw_QueryInterface(lpDD
, &IID_IDirectDraw7
, (void **) &dd7
);
782 ok(ret
== DD_OK
, "IDirectDraw7_QueryInterface returned %08x\n", ret
);
784 /* Create a surface */
785 ZeroMemory(&surface
, sizeof(surface
));
786 surface
.dwSize
= sizeof(surface
);
787 surface
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
;
788 surface
.dwHeight
= 10;
789 surface
.dwWidth
= 10;
790 ret
= IDirectDraw2_CreateSurface(dd2
, &surface
, &dsurface
, NULL
);
793 ok(FALSE
, "IDirectDraw::CreateSurface failed with error %x\n", ret
);
796 ret
= IDirectDrawSurface_QueryInterface(dsurface
, &IID_IDirectDrawSurface2
, (void **) &dsurface2
);
797 ok(ret
== DD_OK
, "IDirectDrawSurface_QueryInterface returned %08x\n", ret
);
799 ref1
= getref((IUnknown
*) lpDD
);
800 ok(ref1
== 1, "IDirectDraw refcount is %ld\n", ref1
);
801 ref2
= getref((IUnknown
*) dd2
);
802 ok(ref2
== 1, "IDirectDraw2 refcount is %ld\n", ref2
);
803 ref4
= getref((IUnknown
*) dd4
);
804 ok(ref4
== 1, "IDirectDraw4 refcount is %ld\n", ref4
);
805 ref7
= getref((IUnknown
*) dd7
);
806 ok(ref7
== 1, "IDirectDraw7 refcount is %ld\n", ref7
);
809 ret
= IDirectDrawSurface2_GetDDInterface(dsurface2
, &dd
);
810 ok(ret
== DD_OK
, "IDirectDrawSurface7_GetDDInterface returned %08x\n", ret
);
811 ok(getref((IUnknown
*) lpDD
) == ref1
+ 0, "IDirectDraw refcount was increased by %ld\n", getref((IUnknown
*) lpDD
) - ref1
);
812 ok(getref((IUnknown
*) dd2
) == ref2
+ 1, "IDirectDraw2 refcount was increased by %ld\n", getref((IUnknown
*) dd2
) - ref2
);
813 ok(getref((IUnknown
*) dd4
) == ref4
+ 0, "IDirectDraw4 refcount was increased by %ld\n", getref((IUnknown
*) dd4
) - ref4
);
814 ok(getref((IUnknown
*) dd7
) == ref7
+ 0, "IDirectDraw7 refcount was increased by %ld\n", getref((IUnknown
*) dd7
) - ref7
);
816 ok(dd
== dd2
, "Returned interface pointer is not equal to the creation interface\n");
817 IUnknown_Release((IUnknown
*) dd
);
819 IDirectDraw_Release(dd2
);
820 IDirectDraw_Release(dd4
);
821 IDirectDraw_Release(dd7
);
822 IDirectDrawSurface2_Release(dsurface2
);
823 IDirectDrawSurface_Release(dsurface
);
826 static void GetDDInterface_4(void)
828 LPDIRECTDRAWSURFACE2 dsurface2
;
829 LPDIRECTDRAWSURFACE4 dsurface4
;
830 DDSURFACEDESC2 surface
;
835 unsigned long ref1
, ref2
, ref4
, ref7
;
838 ret
= IDirectDraw_QueryInterface(lpDD
, &IID_IDirectDraw2
, (void **) &dd2
);
839 ok(ret
== DD_OK
, "IDirectDraw7_QueryInterface returned %08x\n", ret
);
840 ret
= IDirectDraw_QueryInterface(lpDD
, &IID_IDirectDraw4
, (void **) &dd4
);
841 ok(ret
== DD_OK
, "IDirectDraw7_QueryInterface returned %08x\n", ret
);
842 ret
= IDirectDraw_QueryInterface(lpDD
, &IID_IDirectDraw7
, (void **) &dd7
);
843 ok(ret
== DD_OK
, "IDirectDraw7_QueryInterface returned %08x\n", ret
);
845 /* Create a surface */
846 ZeroMemory(&surface
, sizeof(surface
));
847 surface
.dwSize
= sizeof(surface
);
848 surface
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
;
849 surface
.dwHeight
= 10;
850 surface
.dwWidth
= 10;
851 ret
= IDirectDraw4_CreateSurface(dd4
, &surface
, &dsurface4
, NULL
);
854 ok(FALSE
, "IDirectDraw::CreateSurface failed with error %x\n", ret
);
857 ret
= IDirectDrawSurface4_QueryInterface(dsurface4
, &IID_IDirectDrawSurface2
, (void **) &dsurface2
);
858 ok(ret
== DD_OK
, "IDirectDrawSurface_QueryInterface returned %08x\n", ret
);
860 ref1
= getref((IUnknown
*) lpDD
);
861 ok(ref1
== 1, "IDirectDraw refcount is %ld\n", ref1
);
862 ref2
= getref((IUnknown
*) dd2
);
863 ok(ref2
== 1, "IDirectDraw2 refcount is %ld\n", ref2
);
864 ref4
= getref((IUnknown
*) dd4
);
865 ok(ref4
== 2, "IDirectDraw4 refcount is %ld\n", ref4
);
866 ref7
= getref((IUnknown
*) dd7
);
867 ok(ref7
== 1, "IDirectDraw7 refcount is %ld\n", ref7
);
869 ret
= IDirectDrawSurface4_GetDDInterface(dsurface4
, &dd
);
870 ok(ret
== DD_OK
, "IDirectDrawSurface7_GetDDInterface returned %08x\n", ret
);
871 ok(getref((IUnknown
*) lpDD
) == ref1
+ 0, "IDirectDraw refcount was increased by %ld\n", getref((IUnknown
*) lpDD
) - ref1
);
872 ok(getref((IUnknown
*) dd2
) == ref2
+ 0, "IDirectDraw2 refcount was increased by %ld\n", getref((IUnknown
*) dd2
) - ref2
);
873 ok(getref((IUnknown
*) dd4
) == ref4
+ 1, "IDirectDraw4 refcount was increased by %ld\n", getref((IUnknown
*) dd4
) - ref4
);
874 ok(getref((IUnknown
*) dd7
) == ref7
+ 0, "IDirectDraw7 refcount was increased by %ld\n", getref((IUnknown
*) dd7
) - ref7
);
876 ok(dd
== dd4
, "Returned interface pointer is not equal to the creation interface\n");
877 IUnknown_Release((IUnknown
*) dd
);
879 /* Now test what happens if we QI the surface for some other version - It should still return the creation interface */
880 ret
= IDirectDrawSurface2_GetDDInterface(dsurface2
, &dd
);
881 ok(ret
== DD_OK
, "IDirectDrawSurface7_GetDDInterface returned %08x\n", ret
);
882 ok(getref((IUnknown
*) lpDD
) == ref1
+ 0, "IDirectDraw refcount was increased by %ld\n", getref((IUnknown
*) lpDD
) - ref1
);
883 ok(getref((IUnknown
*) dd2
) == ref2
+ 0, "IDirectDraw2 refcount was increased by %ld\n", getref((IUnknown
*) dd2
) - ref2
);
884 ok(getref((IUnknown
*) dd4
) == ref4
+ 1, "IDirectDraw4 refcount was increased by %ld\n", getref((IUnknown
*) dd4
) - ref4
);
885 ok(getref((IUnknown
*) dd7
) == ref7
+ 0, "IDirectDraw7 refcount was increased by %ld\n", getref((IUnknown
*) dd7
) - ref7
);
887 ok(dd
== dd4
, "Returned interface pointer is not equal to the creation interface\n");
888 IUnknown_Release((IUnknown
*) dd
);
890 IDirectDraw_Release(dd2
);
891 IDirectDraw_Release(dd4
);
892 IDirectDraw_Release(dd7
);
893 IDirectDrawSurface4_Release(dsurface4
);
894 IDirectDrawSurface2_Release(dsurface2
);
897 static void GetDDInterface_7(void)
899 LPDIRECTDRAWSURFACE4 dsurface4
;
900 LPDIRECTDRAWSURFACE7 dsurface7
;
901 DDSURFACEDESC2 surface
;
906 unsigned long ref1
, ref2
, ref4
, ref7
;
909 ret
= IDirectDraw_QueryInterface(lpDD
, &IID_IDirectDraw2
, (void **) &dd2
);
910 ok(ret
== DD_OK
, "IDirectDraw7_QueryInterface returned %08x\n", ret
);
911 ret
= IDirectDraw_QueryInterface(lpDD
, &IID_IDirectDraw4
, (void **) &dd4
);
912 ok(ret
== DD_OK
, "IDirectDraw7_QueryInterface returned %08x\n", ret
);
913 ret
= IDirectDraw_QueryInterface(lpDD
, &IID_IDirectDraw7
, (void **) &dd7
);
914 ok(ret
== DD_OK
, "IDirectDraw7_QueryInterface returned %08x\n", ret
);
916 /* Create a surface */
917 ZeroMemory(&surface
, sizeof(surface
));
918 surface
.dwSize
= sizeof(surface
);
919 surface
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
;
920 surface
.dwHeight
= 10;
921 surface
.dwWidth
= 10;
922 ret
= IDirectDraw7_CreateSurface(dd7
, &surface
, &dsurface7
, NULL
);
925 ok(FALSE
, "IDirectDraw::CreateSurface failed with error %x\n", ret
);
928 ret
= IDirectDrawSurface7_QueryInterface(dsurface7
, &IID_IDirectDrawSurface4
, (void **) &dsurface4
);
929 ok(ret
== DD_OK
, "IDirectDrawSurface_QueryInterface returned %08x\n", ret
);
931 ref1
= getref((IUnknown
*) lpDD
);
932 ok(ref1
== 1, "IDirectDraw refcount is %ld\n", ref1
);
933 ref2
= getref((IUnknown
*) dd2
);
934 ok(ref2
== 1, "IDirectDraw2 refcount is %ld\n", ref2
);
935 ref4
= getref((IUnknown
*) dd4
);
936 ok(ref4
== 1, "IDirectDraw4 refcount is %ld\n", ref4
);
937 ref7
= getref((IUnknown
*) dd7
);
938 ok(ref7
== 2, "IDirectDraw7 refcount is %ld\n", ref7
);
940 ret
= IDirectDrawSurface7_GetDDInterface(dsurface7
, &dd
);
941 ok(ret
== DD_OK
, "IDirectDrawSurface7_GetDDInterface returned %08x\n", ret
);
942 ok(getref((IUnknown
*) lpDD
) == ref1
+ 0, "IDirectDraw refcount was increased by %ld\n", getref((IUnknown
*) lpDD
) - ref1
);
943 ok(getref((IUnknown
*) dd2
) == ref2
+ 0, "IDirectDraw2 refcount was increased by %ld\n", getref((IUnknown
*) dd2
) - ref2
);
944 ok(getref((IUnknown
*) dd4
) == ref4
+ 0, "IDirectDraw4 refcount was increased by %ld\n", getref((IUnknown
*) dd4
) - ref4
);
945 ok(getref((IUnknown
*) dd7
) == ref7
+ 1, "IDirectDraw7 refcount was increased by %ld\n", getref((IUnknown
*) dd7
) - ref7
);
947 ok(dd
== dd7
, "Returned interface pointer is not equal to the creation interface\n");
948 IUnknown_Release((IUnknown
*) dd
);
950 /* Now test what happens if we QI the surface for some other version - It should still return the creation interface */
951 ret
= IDirectDrawSurface4_GetDDInterface(dsurface4
, &dd
);
952 ok(ret
== DD_OK
, "IDirectDrawSurface7_GetDDInterface returned %08x\n", ret
);
953 ok(getref((IUnknown
*) lpDD
) == ref1
+ 0, "IDirectDraw refcount was increased by %ld\n", getref((IUnknown
*) lpDD
) - ref1
);
954 ok(getref((IUnknown
*) dd2
) == ref2
+ 0, "IDirectDraw2 refcount was increased by %ld\n", getref((IUnknown
*) dd2
) - ref2
);
955 ok(getref((IUnknown
*) dd4
) == ref4
+ 0, "IDirectDraw4 refcount was increased by %ld\n", getref((IUnknown
*) dd4
) - ref4
);
956 ok(getref((IUnknown
*) dd7
) == ref7
+ 1, "IDirectDraw7 refcount was increased by %ld\n", getref((IUnknown
*) dd7
) - ref7
);
958 ok(dd
== dd7
, "Returned interface pointer is not equal to the creation interface\n");
959 IUnknown_Release((IUnknown
*) dd
);
961 IDirectDraw_Release(dd2
);
962 IDirectDraw_Release(dd4
);
963 IDirectDraw_Release(dd7
);
964 IDirectDrawSurface4_Release(dsurface4
);
965 IDirectDrawSurface7_Release(dsurface7
);
968 #define MAXEXPECTED 8 /* Can match up to 8 expected surfaces */
971 IDirectDrawSurface
*expected
[MAXEXPECTED
];
975 static HRESULT WINAPI
enumCB(IDirectDrawSurface
*surf
, DDSURFACEDESC
*desc
, void *ctx
)
980 for(i
= 0; i
< MAXEXPECTED
; i
++)
982 if(((struct enumstruct
*)ctx
)->expected
[i
] == surf
) found
= TRUE
;
985 ok(found
, "Unexpected surface %p enumerated\n", surf
);
986 ((struct enumstruct
*)ctx
)->count
++;
987 IDirectDrawSurface_Release(surf
);
991 static void EnumTest(void)
995 IDirectDrawSurface
*surface
;
996 struct enumstruct ctx
;
998 ddsd
.dwSize
= sizeof(ddsd
);
999 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_MIPMAPCOUNT
;
1000 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
1001 U2(ddsd
).dwMipMapCount
= 3;
1004 rc
= IDirectDraw_CreateSurface(lpDD
, &ddsd
, &surface
, NULL
);
1005 ok(rc
==DD_OK
,"CreateSurface returned: %x\n",rc
);
1007 memset(&ctx
, 0, sizeof(ctx
));
1008 ctx
.expected
[0] = surface
;
1009 rc
= IDirectDrawSurface_GetAttachedSurface(ctx
.expected
[0], &ddsd
.ddsCaps
, &ctx
.expected
[1]);
1010 ok(rc
== DD_OK
, "GetAttachedSurface returned %08x\n", rc
);
1011 rc
= IDirectDrawSurface_GetAttachedSurface(ctx
.expected
[1], &ddsd
.ddsCaps
, &ctx
.expected
[2]);
1012 ok(rc
== DD_OK
, "GetAttachedSurface returned %08x\n", rc
);
1013 rc
= IDirectDrawSurface_GetAttachedSurface(ctx
.expected
[2], &ddsd
.ddsCaps
, &ctx
.expected
[3]);
1014 ok(rc
== DDERR_NOTFOUND
, "GetAttachedSurface returned %08x\n", rc
);
1015 ok(!ctx
.expected
[3], "expected NULL pointer\n");
1018 rc
= IDirectDraw_EnumSurfaces(lpDD
, DDENUMSURFACES_DOESEXIST
| DDENUMSURFACES_ALL
, &ddsd
, (void *) &ctx
, enumCB
);
1019 ok(rc
== DD_OK
, "IDirectDraw_EnumSurfaces returned %08x\n", rc
);
1020 ok(ctx
.count
== 3, "%d surfaces enumerated, expected 3\n", ctx
.count
);
1022 IDirectDrawSurface_Release(ctx
.expected
[2]);
1023 IDirectDrawSurface_Release(ctx
.expected
[1]);
1024 IDirectDrawSurface_Release(surface
);
1027 HRESULT WINAPI
SurfaceCounter(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*desc
, void *context
)
1029 UINT
*num
= context
;
1031 IDirectDrawSurface_Release(surface
);
1032 return DDENUMRET_OK
;
1035 static void AttachmentTest7(void)
1039 IDirectDrawSurface7
*surface1
, *surface2
, *surface3
, *surface4
;
1040 DDSURFACEDESC2 ddsd
;
1042 DDSCAPS2 caps
= {DDSCAPS_TEXTURE
, 0, 0, 0};
1043 HWND window
= CreateWindow( "static", "ddraw_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
1045 hr
= IDirectDraw_QueryInterface(lpDD
, &IID_IDirectDraw7
, (void **) &dd7
);
1046 ok(hr
== DD_OK
, "IDirectDraw_QueryInterface returned %08x\n", hr
);
1048 memset(&ddsd
, 0, sizeof(ddsd
));
1049 ddsd
.dwSize
= sizeof(ddsd
);
1050 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_MIPMAPCOUNT
;
1051 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
1052 U2(ddsd
).dwMipMapCount
= 3; /* Will create 128x128, 64x64, 32x32 */
1054 ddsd
.dwHeight
= 128;
1055 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd
, &surface1
, NULL
);
1056 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
1060 IDirectDrawSurface7_EnumAttachedSurfaces(surface1
, &num
, SurfaceCounter
);
1061 ok(num
== 1, "Mipmap root has %d surfaces attached, expected 1\n", num
);
1065 hr
= IDirectDrawSurface7_GetAttachedSurface(surface1
, &caps
, &surface2
);
1066 ok(hr
== DD_OK
, "GetAttachedSurface returned %08x\n", hr
);
1068 IDirectDrawSurface7_EnumAttachedSurfaces(surface2
, &num
, SurfaceCounter
);
1069 ok(num
== 1, "First mip level has %d surfaces attached, expected 1\n", num
);
1073 hr
= IDirectDrawSurface7_GetAttachedSurface(surface2
, &caps
, &surface3
);
1074 ok(hr
== DD_OK
, "GetAttachedSurface returned %08x\n", hr
);
1075 IDirectDrawSurface7_Release(surface2
);
1077 IDirectDrawSurface7_EnumAttachedSurfaces(surface3
, &num
, SurfaceCounter
);
1078 ok(num
== 0, "Second mip level has %d surfaces attached, expected 1\n", num
);
1080 /* Mip level 3 is still needed */
1081 hr
= IDirectDrawSurface7_GetAttachedSurface(surface3
, &caps
, &surface4
);
1082 ok(hr
== DDERR_NOTFOUND
, "GetAttachedSurface returned %08x\n", hr
);
1083 ok(!surface4
, "expected NULL pointer\n");
1085 /* Try to attach a 16x16 miplevel - Should not work as far I can see */
1086 memset(&ddsd
, 0, sizeof(ddsd
));
1087 ddsd
.dwSize
= sizeof(ddsd
);
1088 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1089 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1092 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd
, &surface2
, NULL
);
1093 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
1095 hr
= IDirectDrawSurface7_AddAttachedSurface(surface1
, surface2
);
1096 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a 16x16 surface to a 128x128 texture root returned %08x\n", hr
);
1097 hr
= IDirectDrawSurface7_AddAttachedSurface(surface2
, surface1
);
1098 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a 128x128 texture root to a 16x16 texture returned %08x\n", hr
);
1099 hr
= IDirectDrawSurface7_AddAttachedSurface(surface3
, surface2
);
1100 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a 16x16 surface to a 32x32 texture mip level returned %08x\n", hr
);
1101 hr
= IDirectDrawSurface7_AddAttachedSurface(surface2
, surface3
);
1102 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a 32x32 texture mip level to a 16x16 surface returned %08x\n", hr
);
1104 IDirectDrawSurface7_Release(surface2
);
1106 memset(&ddsd
, 0, sizeof(ddsd
));
1107 ddsd
.dwSize
= sizeof(ddsd
);
1108 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1109 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
1112 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd
, &surface2
, NULL
);
1113 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
1115 hr
= IDirectDrawSurface7_AddAttachedSurface(surface1
, surface2
);
1116 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a 16x16 offscreen plain surface to a 128x128 texture root returned %08x\n", hr
);
1117 hr
= IDirectDrawSurface7_AddAttachedSurface(surface2
, surface1
);
1118 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a 128x128 texture root to a 16x16 offscreen plain surface returned %08x\n", hr
);
1119 hr
= IDirectDrawSurface7_AddAttachedSurface(surface3
, surface2
);
1120 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a 16x16 offscreen plain surface to a 32x32 texture mip level returned %08x\n", hr
);
1121 hr
= IDirectDrawSurface7_AddAttachedSurface(surface2
, surface3
);
1122 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a 32x32 texture mip level to a 16x16 offscreen plain surface returned %08x\n", hr
);
1124 IDirectDrawSurface7_Release(surface3
);
1125 IDirectDrawSurface7_Release(surface2
);
1126 IDirectDrawSurface7_Release(surface1
);
1128 hr
= IDirectDraw7_SetCooperativeLevel(dd7
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
1129 ok(hr
== DD_OK
, "SetCooperativeLevel returned %08x\n", hr
);
1131 memset(&ddsd
, 0, sizeof(ddsd
));
1132 ddsd
.dwSize
= sizeof(ddsd
);
1133 ddsd
.dwFlags
= DDSD_BACKBUFFERCOUNT
| DDSD_CAPS
;
1134 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
1135 ddsd
.dwBackBufferCount
= 2;
1136 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd
, &surface1
, NULL
);
1137 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
1140 IDirectDrawSurface7_EnumAttachedSurfaces(surface1
, &num
, SurfaceCounter
);
1141 ok(num
== 1, "Primary surface has %d surfaces attached, expected 1\n", num
);
1142 IDirectDrawSurface7_Release(surface1
);
1144 /* Those are some invalid descriptions, no need to test attachments with them */
1145 memset(&ddsd
, 0, sizeof(ddsd
));
1146 ddsd
.dwSize
= sizeof(ddsd
);
1147 ddsd
.dwFlags
= DDSD_CAPS
;
1148 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
;
1149 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd
, &surface1
, NULL
);
1150 ok(hr
==DDERR_INVALIDCAPS
,"CreateSurface returned: %x\n",hr
);
1151 memset(&ddsd
, 0, sizeof(ddsd
));
1152 ddsd
.dwSize
= sizeof(ddsd
);
1153 ddsd
.dwFlags
= DDSD_CAPS
;
1154 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_BACKBUFFER
;
1155 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd
, &surface2
, NULL
);
1156 ok(hr
==DDERR_INVALIDCAPS
,"CreateSurface returned: %x\n",hr
);
1158 /* Try a single primary and two offscreen plain surfaces */
1159 memset(&ddsd
, 0, sizeof(ddsd
));
1160 ddsd
.dwSize
= sizeof(ddsd
);
1161 ddsd
.dwFlags
= DDSD_CAPS
;
1162 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
1163 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd
, &surface1
, NULL
);
1164 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
1166 memset(&ddsd
, 0, sizeof(ddsd
));
1167 ddsd
.dwSize
= sizeof(ddsd
);
1168 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1169 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
1170 ddsd
.dwWidth
= GetSystemMetrics(SM_CXSCREEN
);
1171 ddsd
.dwHeight
= GetSystemMetrics(SM_CYSCREEN
);
1172 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd
, &surface2
, NULL
);
1173 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
1175 memset(&ddsd
, 0, sizeof(ddsd
));
1176 ddsd
.dwSize
= sizeof(ddsd
);
1177 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1178 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
1179 ddsd
.dwWidth
= GetSystemMetrics(SM_CXSCREEN
);
1180 ddsd
.dwHeight
= GetSystemMetrics(SM_CYSCREEN
);
1181 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd
, &surface3
, NULL
);
1182 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
1184 /* This one has a different size */
1185 memset(&ddsd
, 0, sizeof(ddsd
));
1186 ddsd
.dwSize
= sizeof(ddsd
);
1187 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1188 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
1190 ddsd
.dwHeight
= 128;
1191 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd
, &surface4
, NULL
);
1192 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
1194 hr
= IDirectDrawSurface7_AddAttachedSurface(surface1
, surface2
);
1195 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching an offscreen plain surface to a front buffer returned %08x\n", hr
);
1196 hr
= IDirectDrawSurface7_AddAttachedSurface(surface2
, surface1
);
1197 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a front buffer to an offscreen plain surface returned %08x\n", hr
);
1198 hr
= IDirectDrawSurface7_AddAttachedSurface(surface2
, surface3
);
1199 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching an offscreen plain surface to another offscreen plain surface returned %08x\n", hr
);
1200 hr
= IDirectDrawSurface7_AddAttachedSurface(surface1
, surface4
);
1201 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching an offscreen plain surface to a front buffer of different size returned %08x\n", hr
);
1202 hr
= IDirectDrawSurface7_AddAttachedSurface(surface4
, surface1
);
1203 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a front buffer to an offscreen plain surface of different size returned %08x\n", hr
);
1205 IDirectDrawSurface7_Release(surface4
);
1206 IDirectDrawSurface7_Release(surface3
);
1207 IDirectDrawSurface7_Release(surface2
);
1208 IDirectDrawSurface7_Release(surface1
);
1210 hr
=IDirectDraw7_SetCooperativeLevel(dd7
, NULL
, DDSCL_NORMAL
);
1211 ok(hr
== DD_OK
, "SetCooperativeLevel returned %08x\n", hr
);
1212 IDirectDraw7_Release(dd7
);
1215 static void AttachmentTest(void)
1218 IDirectDrawSurface
*surface1
, *surface2
, *surface3
, *surface4
;
1220 DDSCAPS caps
= {DDSCAPS_TEXTURE
};
1221 BOOL refrast
= FALSE
;
1222 HWND window
= CreateWindow( "static", "ddraw_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
1224 memset(&ddsd
, 0, sizeof(ddsd
));
1225 ddsd
.dwSize
= sizeof(ddsd
);
1226 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_MIPMAPCOUNT
;
1227 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
1228 U2(ddsd
).dwMipMapCount
= 3; /* Will create 128x128, 64x64, 32x32 */
1230 ddsd
.dwHeight
= 128;
1231 hr
= IDirectDraw7_CreateSurface(lpDD
, &ddsd
, &surface1
, NULL
);
1232 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
1234 hr
= IDirectDrawSurface7_GetAttachedSurface(surface1
, &caps
, &surface2
);
1235 ok(hr
== DD_OK
, "GetAttachedSurface returned %08x\n", hr
);
1236 hr
= IDirectDrawSurface7_GetAttachedSurface(surface2
, &caps
, &surface3
);
1237 ok(hr
== DD_OK
, "GetAttachedSurface returned %08x\n", hr
);
1239 /* Try to attach a 16x16 miplevel - Should not work as far I can see */
1240 memset(&ddsd
, 0, sizeof(ddsd
));
1241 ddsd
.dwSize
= sizeof(ddsd
);
1242 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1243 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1246 hr
= IDirectDraw_CreateSurface(lpDD
, &ddsd
, &surface4
, NULL
);
1247 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
1249 hr
= IDirectDrawSurface7_AddAttachedSurface(surface1
, surface4
);
1250 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a 16x16 surface to a 128x128 texture root returned %08x\n", hr
);
1251 hr
= IDirectDrawSurface7_AddAttachedSurface(surface4
, surface1
);
1252 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a 128x128 texture root to a 16x16 texture returned %08x\n", hr
);
1253 hr
= IDirectDrawSurface7_AddAttachedSurface(surface3
, surface4
);
1254 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a 16x16 surface to a 32x32 texture mip level returned %08x\n", hr
);
1255 hr
= IDirectDrawSurface7_AddAttachedSurface(surface4
, surface3
);
1256 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a 32x32 texture mip level to a 16x16 surface returned %08x\n", hr
);
1257 hr
= IDirectDrawSurface7_AddAttachedSurface(surface2
, surface4
);
1258 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a 16x16 surface to a 64x64 texture sublevel returned %08x\n", hr
);
1259 hr
= IDirectDrawSurface7_AddAttachedSurface(surface4
, surface2
);
1260 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a 64x64 texture sublevel to a 16x16 texture returned %08x\n", hr
);
1262 IDirectDrawSurface7_Release(surface4
);
1264 memset(&ddsd
, 0, sizeof(ddsd
));
1265 ddsd
.dwSize
= sizeof(ddsd
);
1266 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1267 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
1270 hr
= IDirectDraw7_CreateSurface(lpDD
, &ddsd
, &surface4
, NULL
);
1271 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
1273 if (SUCCEEDED(IDirectDrawSurface7_AddAttachedSurface(surface1
, surface4
)))
1275 IDirectDrawSurface7_DeleteAttachedSurface(surface1
, 0, surface4
);
1279 hr
= IDirectDrawSurface7_AddAttachedSurface(surface1
, surface4
); /* Succeeds on refrast */
1281 ok(hr
== S_OK
, "Attaching a 16x16 offscreen plain surface to a 128x128 texture root returned %08x\n", hr
);
1283 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a 16x16 offscreen plain surface to a 128x128 texture root returned %08x\n", hr
);
1284 if(SUCCEEDED(hr
)) IDirectDrawSurface7_DeleteAttachedSurface(surface1
, 0, surface4
);
1286 hr
= IDirectDrawSurface7_AddAttachedSurface(surface4
, surface1
); /* Succeeds on refrast */
1288 ok(hr
== S_OK
, "Attaching a 128x128 texture root to a 16x16 offscreen plain surface returned %08x\n", hr
);
1290 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a 128x128 texture root to a 16x16 offscreen plain surface returned %08x\n", hr
);
1291 if(SUCCEEDED(hr
)) IDirectDrawSurface7_DeleteAttachedSurface(surface1
, 0, surface1
);
1293 hr
= IDirectDrawSurface7_AddAttachedSurface(surface3
, surface4
); /* Succeeds on refrast */
1295 ok(hr
== S_OK
, "Attaching a 16x16 offscreen plain surface to a 32x32 texture mip level returned %08x\n", hr
);
1297 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a 16x16 offscreen plain surface to a 32x32 texture mip level returned %08x\n", hr
);
1298 if(SUCCEEDED(hr
)) IDirectDrawSurface7_DeleteAttachedSurface(surface3
, 0, surface4
);
1300 hr
= IDirectDrawSurface7_AddAttachedSurface(surface4
, surface3
);
1301 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a 32x32 texture mip level to a 16x16 offscreen plain surface returned %08x\n", hr
);
1302 if(SUCCEEDED(hr
)) IDirectDrawSurface7_DeleteAttachedSurface(surface4
, 0, surface3
);
1304 hr
= IDirectDrawSurface7_AddAttachedSurface(surface2
, surface4
); /* Succeeds on refrast */
1306 ok(hr
== S_OK
, "Attaching a 16x16 offscreen plain surface to a 64x64 texture sublevel returned %08x\n", hr
);
1308 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a 16x16 offscreen plain surface to a 64x64 texture sublevel returned %08x\n", hr
);
1309 if(SUCCEEDED(hr
)) IDirectDrawSurface7_DeleteAttachedSurface(surface2
, 0, surface4
);
1311 hr
= IDirectDrawSurface7_AddAttachedSurface(surface4
, surface2
);
1312 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a 64x64 texture sublevel to a 16x16 offscreen plain surface returned %08x\n", hr
);
1313 if(SUCCEEDED(hr
)) IDirectDrawSurface7_DeleteAttachedSurface(surface4
, 0, surface2
);
1315 IDirectDrawSurface7_Release(surface4
);
1316 IDirectDrawSurface7_Release(surface3
);
1317 IDirectDrawSurface7_Release(surface2
);
1318 IDirectDrawSurface7_Release(surface1
);
1320 hr
= IDirectDraw_SetCooperativeLevel(lpDD
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
1321 ok(hr
== DD_OK
, "SetCooperativeLevel returned %08x\n", hr
);
1323 /* Creating a back buffer as-is, is not allowed. No need to perform attachment tests */
1324 memset(&ddsd
, 0, sizeof(ddsd
));
1325 ddsd
.dwSize
= sizeof(ddsd
);
1326 ddsd
.dwFlags
= DDSD_CAPS
;
1327 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_BACKBUFFER
;
1328 hr
= IDirectDraw_CreateSurface(lpDD
, &ddsd
, &surface2
, NULL
);
1329 ok(hr
==DDERR_INVALIDCAPS
,"CreateSurface returned: %x\n",hr
);
1330 /* This old ddraw version happily creates explicit front buffers */
1331 memset(&ddsd
, 0, sizeof(ddsd
));
1332 ddsd
.dwSize
= sizeof(ddsd
);
1333 ddsd
.dwFlags
= DDSD_CAPS
;
1334 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
;
1335 hr
= IDirectDraw_CreateSurface(lpDD
, &ddsd
, &surface1
, NULL
);
1336 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
1337 IDirectDrawSurface_Release(surface1
);
1339 /* Try a single primary and two offscreen plain surfaces */
1340 memset(&ddsd
, 0, sizeof(ddsd
));
1341 ddsd
.dwSize
= sizeof(ddsd
);
1342 ddsd
.dwFlags
= DDSD_CAPS
;
1343 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
1344 hr
= IDirectDraw_CreateSurface(lpDD
, &ddsd
, &surface1
, NULL
);
1345 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
1347 memset(&ddsd
, 0, sizeof(ddsd
));
1348 ddsd
.dwSize
= sizeof(ddsd
);
1349 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1350 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
1351 ddsd
.dwWidth
= GetSystemMetrics(SM_CXSCREEN
);
1352 ddsd
.dwHeight
= GetSystemMetrics(SM_CYSCREEN
);
1353 hr
= IDirectDraw_CreateSurface(lpDD
, &ddsd
, &surface2
, NULL
);
1354 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
1356 memset(&ddsd
, 0, sizeof(ddsd
));
1357 ddsd
.dwSize
= sizeof(ddsd
);
1358 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1359 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
1360 ddsd
.dwWidth
= GetSystemMetrics(SM_CXSCREEN
);
1361 ddsd
.dwHeight
= GetSystemMetrics(SM_CYSCREEN
);
1362 hr
= IDirectDraw_CreateSurface(lpDD
, &ddsd
, &surface3
, NULL
);
1363 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
1365 /* This one has a different size */
1366 memset(&ddsd
, 0, sizeof(ddsd
));
1367 ddsd
.dwSize
= sizeof(ddsd
);
1368 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1369 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
1371 ddsd
.dwHeight
= 128;
1372 hr
= IDirectDraw_CreateSurface(lpDD
, &ddsd
, &surface4
, NULL
);
1373 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
1375 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface2
);
1376 ok(hr
== DD_OK
, "Attaching an offscreen plain surface to a front buffer returned %08x\n", hr
);
1377 /* Try the reverse without detaching first */
1378 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface1
);
1379 ok(hr
== DDERR_SURFACEALREADYATTACHED
, "Attaching an attached surface to its attachee returned %08x\n", hr
);
1380 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1
, 0, surface2
);
1381 ok(hr
== DD_OK
, "DeleteAttachedSurface failed with %08x\n", hr
);
1382 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface1
);
1383 ok(hr
== DD_OK
, "Attaching a front buffer to an offscreen plain surface returned %08x\n", hr
);
1384 /* Try to detach reversed */
1385 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1
, 0, surface2
);
1386 ok(hr
== DDERR_CANNOTDETACHSURFACE
, "DeleteAttachedSurface returned %08x\n", hr
);
1387 /* Now the proper detach */
1388 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface2
, 0, surface1
);
1389 ok(hr
== DD_OK
, "DeleteAttachedSurface failed with %08x\n", hr
);
1390 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface3
); /* Fails on refrast */
1391 ok(hr
== DD_OK
, "Attaching an offscreen plain surface to another offscreen plain surface returned %08x\n", hr
);
1394 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface2
, 0, surface3
);
1395 ok(hr
== DD_OK
, "DeleteAttachedSurface failed with %08x\n", hr
);
1397 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface4
);
1398 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching an offscreen plain surface to a front buffer of different size returned %08x\n", hr
);
1399 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface1
);
1400 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a front buffer to an offscreen plain surface of different size returned %08x\n", hr
);
1402 IDirectDrawSurface_Release(surface4
);
1403 IDirectDrawSurface_Release(surface3
);
1404 IDirectDrawSurface_Release(surface2
);
1405 IDirectDrawSurface_Release(surface1
);
1407 hr
=IDirectDraw_SetCooperativeLevel(lpDD
, NULL
, DDSCL_NORMAL
);
1408 ok(hr
== DD_OK
, "SetCooperativeLevel returned %08x\n", hr
);
1410 DestroyWindow(window
);
1415 DWORD width
, height
;
1420 HRESULT WINAPI
CubeTestLvl2Enum(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*desc
, void *context
)
1422 UINT
*mips
= context
;
1425 IDirectDrawSurface7_EnumAttachedSurfaces(surface
,
1429 return DDENUMRET_OK
;
1432 HRESULT WINAPI
CubeTestLvl1Enum(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*desc
, void *context
)
1435 UINT
*num
= (UINT
*) context
;
1436 static const struct compare expected
[] =
1440 DDSCAPS_MIPMAP
| DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_COMPLEX
,
1441 DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_NEGATIVEZ
,
1446 DDSCAPS_MIPMAP
| DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_COMPLEX
,
1447 DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_POSITIVEZ
,
1452 DDSCAPS_MIPMAP
| DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_COMPLEX
,
1453 DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_NEGATIVEY
,
1458 DDSCAPS_MIPMAP
| DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_COMPLEX
,
1459 DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_POSITIVEY
,
1464 DDSCAPS_MIPMAP
| DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_COMPLEX
,
1465 DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_NEGATIVEX
,
1469 64, 64, /* This is the first mipmap */
1470 DDSCAPS_MIPMAP
| DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_COMPLEX
,
1471 DDSCAPS2_MIPMAPSUBLEVEL
| DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_POSITIVEX
,
1477 IDirectDrawSurface7_EnumAttachedSurfaces(surface
,
1481 ok(desc
->dwWidth
== expected
[*num
].width
, "Surface width is %d expected %d\n", desc
->dwWidth
, expected
[*num
].width
);
1482 ok(desc
->dwHeight
== expected
[*num
].height
, "Surface height is %d expected %d\n", desc
->dwHeight
, expected
[*num
].height
);
1483 ok(desc
->ddsCaps
.dwCaps
== expected
[*num
].caps
, "Surface caps are %08x expected %08x\n", desc
->ddsCaps
.dwCaps
, expected
[*num
].caps
);
1484 ok(desc
->ddsCaps
.dwCaps2
== expected
[*num
].caps2
, "Surface caps2 are %08x expected %08x\n", desc
->ddsCaps
.dwCaps2
, expected
[*num
].caps2
);
1485 ok(mips
== expected
[*num
].mips
, "Surface has %d mipmaps, expected %d\n", mips
, expected
[*num
].mips
);
1489 IDirectDrawSurface7_Release(surface
);
1491 return DDENUMRET_OK
;
1494 static void CubeMapTest(void)
1496 IDirectDraw7
*dd7
= NULL
;
1497 IDirectDrawSurface7
*cubemap
;
1498 DDSURFACEDESC2 ddsd
;
1501 struct enumstruct ctx
;
1503 hr
= IDirectDraw_QueryInterface(lpDD
, &IID_IDirectDraw7
, (void **) &dd7
);
1504 ok(hr
== DD_OK
, "IDirectDraw::QueryInterface returned %08x\n", hr
);
1506 memset(&ddsd
, 0, sizeof(ddsd
));
1507 ddsd
.dwSize
= sizeof(ddsd
);
1508 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
1509 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CAPS
;
1511 ddsd
.dwHeight
= 128;
1512 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
| DDSCAPS_SYSTEMMEMORY
;
1513 ddsd
.ddsCaps
.dwCaps2
= DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_ALLFACES
;
1516 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
1517 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 16;
1518 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0xF800;
1519 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x07E0;
1520 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x001F;
1522 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd
, &cubemap
, NULL
);
1523 ok(hr
== DD_OK
, "IDirectDraw7::CreateSurface returned %08x\n", hr
);
1525 hr
= IDirectDrawSurface7_GetSurfaceDesc(cubemap
, &ddsd
);
1526 ok(hr
== DD_OK
, "IDirectDrawSurface7_GetSurfaceDesc returned %08x\n", hr
);
1527 ok(ddsd
.ddsCaps
.dwCaps
== (DDSCAPS_MIPMAP
| DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_COMPLEX
),
1528 "Root Caps are %08x\n", ddsd
.ddsCaps
.dwCaps
);
1529 ok(ddsd
.ddsCaps
.dwCaps2
== (DDSCAPS2_CUBEMAP_POSITIVEX
| DDSCAPS2_CUBEMAP
),
1530 "Root Caps2 are %08x\n", ddsd
.ddsCaps
.dwCaps2
);
1532 IDirectDrawSurface7_EnumAttachedSurfaces(cubemap
,
1535 ok(num
== 6, "Surface has %d attachments\n", num
);
1536 IDirectDrawSurface7_Release(cubemap
);
1538 /* What happens if I do not specify any faces? */
1539 memset(&ddsd
, 0, sizeof(ddsd
));
1540 ddsd
.dwSize
= sizeof(ddsd
);
1541 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
1542 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CAPS
;
1544 ddsd
.dwHeight
= 128;
1545 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
| DDSCAPS_SYSTEMMEMORY
;
1546 ddsd
.ddsCaps
.dwCaps2
= DDSCAPS2_CUBEMAP
;
1549 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
1550 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 16;
1551 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0xF800;
1552 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x07E0;
1553 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x001F;
1555 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd
, &cubemap
, NULL
);
1556 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDraw7::CreateSurface asking for a cube map without faces returned %08x\n", hr
);
1558 /* Cube map faces without a cube map? */
1559 memset(&ddsd
, 0, sizeof(ddsd
));
1560 ddsd
.dwSize
= sizeof(ddsd
);
1561 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
1562 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CAPS
;
1564 ddsd
.dwHeight
= 128;
1565 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
| DDSCAPS_SYSTEMMEMORY
;
1566 ddsd
.ddsCaps
.dwCaps2
= DDSCAPS2_CUBEMAP_ALLFACES
;
1569 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
1570 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 16;
1571 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0xF800;
1572 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x07E0;
1573 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x001F;
1575 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd
, &cubemap
, NULL
);
1576 ok(hr
== DDERR_INVALIDCAPS
, "IDirectDraw7::CreateSurface returned %08x\n", hr
);
1578 memset(&ddsd
, 0, sizeof(ddsd
));
1579 ddsd
.dwSize
= sizeof(ddsd
);
1580 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
1581 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CAPS
;
1583 ddsd
.dwHeight
= 128;
1584 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
| DDSCAPS_SYSTEMMEMORY
;
1585 ddsd
.ddsCaps
.dwCaps2
= DDSCAPS2_CUBEMAP_POSITIVEX
;
1588 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
1589 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 16;
1590 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0xF800;
1591 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x07E0;
1592 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x001F;
1594 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd
, &cubemap
, NULL
);
1595 ok(hr
== DDERR_INVALIDCAPS
, "IDirectDraw7::CreateSurface returned %08x\n", hr
);
1597 /* Make sure everything is cleaned up properly. Use the enumSurfaces test infrastructure */
1598 memset(&ctx
, 0, sizeof(ctx
));
1599 memset(&ddsd
, 0, sizeof(ddsd
));
1600 ddsd
.dwSize
= sizeof(DDSURFACEDESC
);
1601 hr
= IDirectDraw_EnumSurfaces(lpDD
, DDENUMSURFACES_DOESEXIST
| DDENUMSURFACES_ALL
, (DDSURFACEDESC
*) &ddsd
, (void *) &ctx
, enumCB
);
1602 ok(hr
== DD_OK
, "IDirectDraw_EnumSurfaces returned %08x\n", hr
);
1603 ok(ctx
.count
== 0, "%d surfaces enumerated, expected 0\n", ctx
.count
);
1605 IDirectDraw7_Release(dd7
);
1608 static void test_lockrect_invalid(void)
1621 {68, 60, 60, 68}, /* left > right */
1622 {60, 68, 68, 60}, /* top > bottom */
1623 {-8, 60, 0, 68}, /* left < surface */
1624 {60, -8, 68, 0}, /* top < surface */
1625 {-16, 60, -8, 68}, /* right < surface */
1626 {60, -16, 68, -8}, /* bottom < surface */
1627 {60, 60, 136, 68}, /* right > surface */
1628 {60, 60, 68, 136}, /* bottom > surface */
1629 {136, 60, 144, 68}, /* left > surface */
1630 {60, 136, 68, 144}, /* top > surface */
1633 const DWORD dds_caps
[] = {
1634 DDSCAPS_OFFSCREENPLAIN
1637 for (j
= 0; j
< (sizeof(dds_caps
) / sizeof(*dds_caps
)); ++j
)
1639 IDirectDrawSurface
*surface
= 0;
1640 DDSURFACEDESC surface_desc
= {0};
1641 DDSURFACEDESC locked_desc
= {0};
1644 surface_desc
.dwSize
= sizeof(surface_desc
);
1645 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
1646 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
1647 surface_desc
.ddsCaps
.dwCaps
= dds_caps
[j
];
1648 surface_desc
.dwWidth
= 128;
1649 surface_desc
.dwHeight
= 128;
1650 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
1651 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
1652 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0xFF0000;
1653 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x00FF00;
1654 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x0000FF;
1656 hr
= IDirectDraw_CreateSurface(lpDD
, &surface_desc
, &surface
, NULL
);
1657 ok(SUCCEEDED(hr
), "CreateSurface failed (0x%08x)\n", hr
);
1659 skip("failed to create surface\n");
1663 for (i
= 0; i
< (sizeof(valid
) / sizeof(*valid
)); ++i
)
1665 RECT
*rect
= &valid
[i
];
1667 memset(&locked_desc
, 0, sizeof(locked_desc
));
1668 locked_desc
.dwSize
= sizeof(locked_desc
);
1670 hr
= IDirectDrawSurface_Lock(surface
, rect
, &locked_desc
, DDLOCK_WAIT
, NULL
);
1671 ok(SUCCEEDED(hr
), "Lock failed (0x%08x) for rect [%d, %d]->[%d, %d]\n",
1672 hr
, rect
->left
, rect
->top
, rect
->right
, rect
->bottom
);
1674 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
1675 ok(SUCCEEDED(hr
), "Unlock failed (0x%08x)\n", hr
);
1678 for (i
= 0; i
< (sizeof(invalid
) / sizeof(*invalid
)); ++i
)
1680 RECT
*rect
= &invalid
[i
];
1682 memset(&locked_desc
, 1, sizeof(locked_desc
));
1683 locked_desc
.dwSize
= sizeof(locked_desc
);
1685 hr
= IDirectDrawSurface_Lock(surface
, rect
, &locked_desc
, DDLOCK_WAIT
, NULL
);
1686 ok(hr
== DDERR_INVALIDPARAMS
, "Lock returned 0x%08x for rect [%d, %d]->[%d, %d]"
1687 ", expected DDERR_INVALIDPARAMS (0x%08x)\n", hr
, rect
->left
, rect
->top
,
1688 rect
->right
, rect
->bottom
, DDERR_INVALIDPARAMS
);
1689 ok(!locked_desc
.lpSurface
, "IDirectDrawSurface_Lock did not set lpSurface in the surface desc to zero.\n");
1692 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &locked_desc
, DDLOCK_WAIT
, NULL
);
1693 ok(hr
== DD_OK
, "IDirectDrawSurface_Lock(rect = NULL) failed (0x%08x)\n", hr
);
1694 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &locked_desc
, DDLOCK_WAIT
, NULL
);
1695 ok(hr
== DDERR_SURFACEBUSY
, "Double lock(rect = NULL) returned 0x%08x\n", hr
);
1697 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
1698 ok(SUCCEEDED(hr
), "Unlock failed (0x%08x)\n", hr
);
1700 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
1701 ok(SUCCEEDED(hr
), "Unlock failed (0x%08x)\n", hr
);
1703 memset(&locked_desc
, 0, sizeof(locked_desc
));
1704 locked_desc
.dwSize
= sizeof(locked_desc
);
1705 hr
= IDirectDrawSurface_Lock(surface
, &valid
[0], &locked_desc
, DDLOCK_WAIT
, NULL
);
1706 ok(hr
== DD_OK
, "IDirectDrawSurface_Lock(rect = [%d, %d]->[%d, %d]) failed (0x%08x)\n",
1707 valid
[0].left
, valid
[0].top
, valid
[0].right
, valid
[0].bottom
, hr
);
1708 hr
= IDirectDrawSurface_Lock(surface
, &valid
[0], &locked_desc
, DDLOCK_WAIT
, NULL
);
1709 ok(hr
== DDERR_SURFACEBUSY
, "Double lock(rect = [%d, %d]->[%d, %d]) failed (0x%08x)\n",
1710 valid
[0].left
, valid
[0].top
, valid
[0].right
, valid
[0].bottom
, hr
);
1712 /* Locking a different rectangle returns DD_OK, but it seems to break the surface.
1713 * Afterwards unlocking the surface fails(NULL rectangle, and both locked rectangles
1716 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
1717 ok(hr
== DD_OK
, "Unlock returned (0x%08x)\n", hr
);
1719 IDirectDrawSurface_Release(surface
);
1723 static void CompressedTest(void)
1726 IDirectDrawSurface7
*surface
;
1727 DDSURFACEDESC2 ddsd
, ddsd2
;
1728 IDirectDraw7
*dd7
= NULL
;
1729 RECT r
= { 0, 0, 128, 128 };
1730 RECT r2
= { 32, 32, 64, 64 };
1732 hr
= IDirectDraw_QueryInterface(lpDD
, &IID_IDirectDraw7
, (void **) &dd7
);
1733 ok(hr
== DD_OK
, "IDirectDraw::QueryInterface returned %08x\n", hr
);
1735 memset(&ddsd
, 0, sizeof(ddsd
));
1736 ddsd
.dwSize
= sizeof(ddsd
);
1737 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
1738 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CAPS
;
1740 ddsd
.dwHeight
= 128;
1741 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
;
1742 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_FOURCC
;
1743 U4(ddsd
).ddpfPixelFormat
.dwFourCC
= MAKEFOURCC('D','X','T','1');
1745 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd
, &surface
, NULL
);
1746 ok(hr
== DD_OK
, "CreateSurface returned %08x\n", hr
);
1748 skip("failed to create surface\n");
1752 memset(&ddsd2
, 0, sizeof(ddsd2
));
1753 ddsd2
.dwSize
= sizeof(ddsd2
);
1754 U4(ddsd2
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd2
).ddpfPixelFormat
);
1755 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd2
);
1756 ok(hr
== DD_OK
, "GetSurfaceDesc returned %08x\n", hr
);
1758 ok(ddsd2
.dwFlags
== (DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_LINEARSIZE
),
1759 "Surface desc flags: %08x\n", ddsd2
.dwFlags
);
1760 ok(U4(ddsd2
).ddpfPixelFormat
.dwFlags
== DDPF_FOURCC
, "Pixel format flags: %08x\n", U4(ddsd2
).ddpfPixelFormat
.dwFlags
);
1761 ok(U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
== 0, "RGB bitcount: %08x\n", U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
);
1762 ok(ddsd2
.ddsCaps
.dwCaps
== (DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
),
1763 "Surface caps flags: %08x\n", ddsd2
.ddsCaps
.dwCaps
);
1764 ok(U1(ddsd2
).dwLinearSize
== 8192, "Linear size is %d\n", U1(ddsd2
).dwLinearSize
);
1765 ok(ddsd2
.ddsCaps
.dwCaps2
== 0, "Caps2: %08x\n", ddsd2
.ddsCaps
.dwCaps2
);
1766 IDirectDrawSurface7_Release(surface
);
1768 U4(ddsd
).ddpfPixelFormat
.dwFourCC
= MAKEFOURCC('D','X','T','3');
1769 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd
, &surface
, NULL
);
1770 ok(hr
== DD_OK
, "CreateSurface returned %08x\n", hr
);
1772 skip("failed to create surface\n");
1776 memset(&ddsd2
, 0, sizeof(ddsd2
));
1777 ddsd2
.dwSize
= sizeof(ddsd2
);
1778 U4(ddsd2
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd2
).ddpfPixelFormat
);
1779 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd2
);
1780 ok(hr
== DD_OK
, "GetSurfaceDesc returned %08x\n", hr
);
1782 ok(ddsd2
.dwFlags
== (DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_LINEARSIZE
),
1783 "Surface desc flags: %08x\n", ddsd2
.dwFlags
);
1784 ok(U4(ddsd2
).ddpfPixelFormat
.dwFlags
== DDPF_FOURCC
, "Pixel format flags: %08x\n", U4(ddsd2
).ddpfPixelFormat
.dwFlags
);
1785 ok(U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
== 0, "RGB bitcount: %08x\n", U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
);
1786 ok(ddsd2
.ddsCaps
.dwCaps
== (DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
),
1787 "Surface caps flags: %08x\n", ddsd2
.ddsCaps
.dwCaps
);
1788 ok(U1(ddsd2
).dwLinearSize
== 16384, "Linear size is %d\n", U1(ddsd2
).dwLinearSize
);
1789 IDirectDrawSurface7_Release(surface
);
1791 U4(ddsd
).ddpfPixelFormat
.dwFourCC
= MAKEFOURCC('D','X','T','5');
1792 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd
, &surface
, NULL
);
1793 ok(hr
== DD_OK
, "CreateSurface returned %08x\n", hr
);
1795 skip("failed to create surface\n");
1799 memset(&ddsd2
, 0, sizeof(ddsd2
));
1800 ddsd2
.dwSize
= sizeof(ddsd2
);
1801 U4(ddsd2
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd2
).ddpfPixelFormat
);
1802 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd2
);
1803 ok(hr
== DD_OK
, "GetSurfaceDesc returned %08x\n", hr
);
1805 ok(ddsd2
.dwFlags
== (DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_LINEARSIZE
),
1806 "Surface desc flags: %08x\n", ddsd2
.dwFlags
);
1807 ok(U4(ddsd2
).ddpfPixelFormat
.dwFlags
== DDPF_FOURCC
, "Pixel format flags: %08x\n", U4(ddsd2
).ddpfPixelFormat
.dwFlags
);
1808 ok(U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
== 0, "RGB bitcount: %08x\n", U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
);
1809 ok(ddsd2
.ddsCaps
.dwCaps
== (DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
),
1810 "Surface caps flags: %08x\n", ddsd2
.ddsCaps
.dwCaps
);
1811 ok(U1(ddsd2
).dwLinearSize
== 16384, "Linear size is %d\n", U1(ddsd2
).dwLinearSize
);
1812 ok(ddsd2
.lpSurface
== 0, "Surface memory is at %p, expected NULL\n", ddsd2
.lpSurface
);
1814 memset(&ddsd2
, 0, sizeof(ddsd2
));
1815 ddsd2
.dwSize
= sizeof(ddsd2
);
1816 U4(ddsd2
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd2
).ddpfPixelFormat
);
1818 /* Show that the description is not changed when locking the surface. What is really interesting
1819 * about this is that DDSD_LPSURFACE isn't set.
1821 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &ddsd2
, DDLOCK_READONLY
, 0);
1822 ok(hr
== DD_OK
, "Lock returned %08x\n", hr
);
1824 ok(ddsd2
.dwFlags
== (DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_LINEARSIZE
),
1825 "Surface desc flags: %08x\n", ddsd2
.dwFlags
);
1826 ok(U4(ddsd2
).ddpfPixelFormat
.dwFlags
== DDPF_FOURCC
, "Pixel format flags: %08x\n", U4(ddsd2
).ddpfPixelFormat
.dwFlags
);
1827 ok(U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
== 0, "RGB bitcount: %08x\n", U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
);
1828 ok(ddsd2
.ddsCaps
.dwCaps
== (DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
),
1829 "Surface caps flags: %08x\n", ddsd2
.ddsCaps
.dwCaps
);
1830 ok(U1(ddsd2
).dwLinearSize
== 16384, "Linear size is %d\n", U1(ddsd2
).dwLinearSize
);
1831 ok(ddsd2
.lpSurface
!= 0, "Surface memory is at NULL\n");
1833 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
1834 ok(hr
== DD_OK
, "Unlock returned %08x\n", hr
);
1836 /* Now what about a locking rect? */
1837 hr
= IDirectDrawSurface7_Lock(surface
, &r
, &ddsd2
, DDLOCK_READONLY
, 0);
1838 ok(hr
== DD_OK
, "Lock returned %08x\n", hr
);
1840 ok(ddsd2
.dwFlags
== (DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_LINEARSIZE
),
1841 "Surface desc flags: %08x\n", ddsd2
.dwFlags
);
1842 ok(U4(ddsd2
).ddpfPixelFormat
.dwFlags
== DDPF_FOURCC
, "Pixel format flags: %08x\n", U4(ddsd2
).ddpfPixelFormat
.dwFlags
);
1843 ok(U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
== 0, "RGB bitcount: %08x\n", U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
);
1844 ok(ddsd2
.ddsCaps
.dwCaps
== (DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
),
1845 "Surface caps flags: %08x\n", ddsd2
.ddsCaps
.dwCaps
);
1846 ok(U1(ddsd2
).dwLinearSize
== 16384, "Linear size is %d\n", U1(ddsd2
).dwLinearSize
);
1847 ok(ddsd2
.lpSurface
!= 0, "Surface memory is at NULL\n");
1849 hr
= IDirectDrawSurface7_Unlock(surface
, &r
);
1850 ok(hr
== DD_OK
, "Unlock returned %08x\n", hr
);
1852 /* Now what about a different locking offset? */
1853 hr
= IDirectDrawSurface7_Lock(surface
, &r2
, &ddsd2
, DDLOCK_READONLY
, 0);
1854 ok(hr
== DD_OK
, "Lock returned %08x\n", hr
);
1856 ok(ddsd2
.dwFlags
== (DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_LINEARSIZE
),
1857 "Surface desc flags: %08x\n", ddsd2
.dwFlags
);
1858 ok(U4(ddsd2
).ddpfPixelFormat
.dwFlags
== DDPF_FOURCC
, "Pixel format flags: %08x\n", U4(ddsd2
).ddpfPixelFormat
.dwFlags
);
1859 ok(U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
== 0, "RGB bitcount: %08x\n", U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
);
1860 ok(ddsd2
.ddsCaps
.dwCaps
== (DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
),
1861 "Surface caps flags: %08x\n", ddsd2
.ddsCaps
.dwCaps
);
1862 ok(U1(ddsd2
).dwLinearSize
== 16384, "Linear size is %d\n", U1(ddsd2
).dwLinearSize
);
1863 ok(ddsd2
.lpSurface
!= 0, "Surface memory is at NULL\n");
1865 hr
= IDirectDrawSurface7_Unlock(surface
, &r2
);
1866 ok(hr
== DD_OK
, "Unlock returned %08x\n", hr
);
1867 IDirectDrawSurface7_Release(surface
);
1869 /* Try this with video memory. A kind of surprise. It still has the LINEARSIZE flag set,
1870 * but seems to have a pitch instead.
1872 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
;
1873 U4(ddsd
).ddpfPixelFormat
.dwFourCC
= MAKEFOURCC('D','X','T','1');
1875 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd
, &surface
, NULL
);
1876 ok(hr
== DD_OK
|| hr
== DDERR_NOTEXTUREHW
|| hr
== DDERR_INVALIDPARAMS
||
1877 broken(hr
== DDERR_NODIRECTDRAWHW
), "CreateSurface returned %08x\n", hr
);
1879 /* Not supported everywhere */
1882 memset(&ddsd2
, 0, sizeof(ddsd2
));
1883 ddsd2
.dwSize
= sizeof(ddsd2
);
1884 U4(ddsd2
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd2
).ddpfPixelFormat
);
1885 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd2
);
1886 ok(hr
== DD_OK
, "GetSurfaceDesc returned %08x\n", hr
);
1888 ok(ddsd2
.dwFlags
== (DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_LINEARSIZE
),
1889 "Surface desc flags: %08x\n", ddsd2
.dwFlags
);
1890 ok(U4(ddsd2
).ddpfPixelFormat
.dwFlags
== DDPF_FOURCC
, "Pixel format flags: %08x\n", U4(ddsd2
).ddpfPixelFormat
.dwFlags
);
1891 ok(U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
== 0, "RGB bitcount: %08x\n", U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
);
1892 ok(ddsd2
.ddsCaps
.dwCaps
== (DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
),
1893 "Surface caps flags: %08x\n", ddsd2
.ddsCaps
.dwCaps
);
1894 /* ATI drivers report a broken linear size, thus no need to clone the exact behaviour. nvidia reports the correct size */
1895 ok(ddsd2
.ddsCaps
.dwCaps2
== 0, "Caps2: %08x\n", ddsd2
.ddsCaps
.dwCaps2
);
1896 IDirectDrawSurface7_Release(surface
);
1898 U4(ddsd
).ddpfPixelFormat
.dwFourCC
= MAKEFOURCC('D','X','T','3');
1899 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd
, &surface
, NULL
);
1900 ok(hr
== DD_OK
, "CreateSurface returned %08x\n", hr
);
1902 memset(&ddsd2
, 0, sizeof(ddsd2
));
1903 ddsd2
.dwSize
= sizeof(ddsd2
);
1904 U4(ddsd2
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd2
).ddpfPixelFormat
);
1905 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd2
);
1906 ok(hr
== DD_OK
, "GetSurfaceDesc returned %08x\n", hr
);
1908 ok(ddsd2
.dwFlags
== (DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_LINEARSIZE
),
1909 "Surface desc flags: %08x\n", ddsd2
.dwFlags
);
1910 ok(U4(ddsd2
).ddpfPixelFormat
.dwFlags
== DDPF_FOURCC
, "Pixel format flags: %08x\n", U4(ddsd2
).ddpfPixelFormat
.dwFlags
);
1911 ok(U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
== 0, "RGB bitcount: %08x\n", U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
);
1912 ok(ddsd2
.ddsCaps
.dwCaps
== (DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
),
1913 "Surface caps flags: %08x\n", ddsd2
.ddsCaps
.dwCaps
);
1914 /* ATI drivers report a broken linear size, thus no need to clone the exact behaviour. nvidia reports the correct size */
1915 IDirectDrawSurface7_Release(surface
);
1917 U4(ddsd
).ddpfPixelFormat
.dwFourCC
= MAKEFOURCC('D','X','T','5');
1918 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd
, &surface
, NULL
);
1919 ok(hr
== DD_OK
, "CreateSurface returned %08x\n", hr
);
1921 memset(&ddsd2
, 0, sizeof(ddsd2
));
1922 ddsd2
.dwSize
= sizeof(ddsd2
);
1923 U4(ddsd2
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd2
).ddpfPixelFormat
);
1924 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd2
);
1925 ok(hr
== DD_OK
, "GetSurfaceDesc returned %08x\n", hr
);
1927 ok(ddsd2
.dwFlags
== (DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_LINEARSIZE
),
1928 "Surface desc flags: %08x\n", ddsd2
.dwFlags
);
1929 ok(U4(ddsd2
).ddpfPixelFormat
.dwFlags
== DDPF_FOURCC
, "Pixel format flags: %08x\n", U4(ddsd2
).ddpfPixelFormat
.dwFlags
);
1930 ok(U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
== 0, "RGB bitcount: %08x\n", U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
);
1931 ok(ddsd2
.ddsCaps
.dwCaps
== (DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
),
1932 "Surface caps flags: %08x\n", ddsd2
.ddsCaps
.dwCaps
);
1933 /* ATI drivers report a broken linear size, thus no need to clone the exact behaviour. nvidia reports the correct size */
1934 ok(ddsd2
.lpSurface
== 0, "Surface memory is at %p, expected NULL\n", ddsd2
.lpSurface
);
1936 memset(&ddsd2
, 0, sizeof(ddsd2
));
1937 ddsd2
.dwSize
= sizeof(ddsd2
);
1938 U4(ddsd2
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd2
).ddpfPixelFormat
);
1940 /* Show that the description is not changed when locking the surface. What is really interesting
1941 * about this is that DDSD_LPSURFACE isn't set.
1943 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &ddsd2
, DDLOCK_READONLY
, 0);
1944 ok(hr
== DD_OK
, "Lock returned %08x\n", hr
);
1946 ok(ddsd2
.dwFlags
== (DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_LINEARSIZE
),
1947 "Surface desc flags: %08x\n", ddsd2
.dwFlags
);
1948 ok(U4(ddsd2
).ddpfPixelFormat
.dwFlags
== DDPF_FOURCC
, "Pixel format flags: %08x\n", U4(ddsd2
).ddpfPixelFormat
.dwFlags
);
1949 ok(U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
== 0, "RGB bitcount: %08x\n", U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
);
1950 ok(ddsd2
.ddsCaps
.dwCaps
== (DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
),
1951 "Surface caps flags: %08x\n", ddsd2
.ddsCaps
.dwCaps
);
1952 /* ATI drivers report a broken linear size, thus no need to clone the exact behaviour. nvidia reports the correct size */
1953 ok(ddsd2
.lpSurface
!= 0, "Surface memory is at NULL\n");
1955 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
1956 ok(hr
== DD_OK
, "Unlock returned %08x\n", hr
);
1958 /* Now what about a locking rect? */
1959 hr
= IDirectDrawSurface7_Lock(surface
, &r
, &ddsd2
, DDLOCK_READONLY
, 0);
1960 ok(hr
== DD_OK
, "Lock returned %08x\n", hr
);
1962 ok(ddsd2
.dwFlags
== (DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_LINEARSIZE
),
1963 "Surface desc flags: %08x\n", ddsd2
.dwFlags
);
1964 ok(U4(ddsd2
).ddpfPixelFormat
.dwFlags
== DDPF_FOURCC
, "Pixel format flags: %08x\n", U4(ddsd2
).ddpfPixelFormat
.dwFlags
);
1965 ok(U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
== 0, "RGB bitcount: %08x\n", U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
);
1966 ok(ddsd2
.ddsCaps
.dwCaps
== (DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
),
1967 "Surface caps flags: %08x\n", ddsd2
.ddsCaps
.dwCaps
);
1968 /* ATI drivers report a broken linear size, thus no need to clone the exact behaviour. nvidia reports the correct size */
1969 ok(ddsd2
.lpSurface
!= 0, "Surface memory is at NULL\n");
1971 hr
= IDirectDrawSurface7_Unlock(surface
, &r
);
1972 ok(hr
== DD_OK
, "Unlock returned %08x\n", hr
);
1974 /* Now what about a different locking offset? */
1975 hr
= IDirectDrawSurface7_Lock(surface
, &r2
, &ddsd2
, DDLOCK_READONLY
, 0);
1976 ok(hr
== DD_OK
, "Lock returned %08x\n", hr
);
1978 ok(ddsd2
.dwFlags
== (DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_LINEARSIZE
),
1979 "Surface desc flags: %08x\n", ddsd2
.dwFlags
);
1980 ok(U4(ddsd2
).ddpfPixelFormat
.dwFlags
== DDPF_FOURCC
, "Pixel format flags: %08x\n", U4(ddsd2
).ddpfPixelFormat
.dwFlags
);
1981 ok(U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
== 0, "RGB bitcount: %08x\n", U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
);
1982 ok(ddsd2
.ddsCaps
.dwCaps
== (DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
),
1983 "Surface caps flags: %08x\n", ddsd2
.ddsCaps
.dwCaps
);
1984 /* ATI drivers report a broken linear size, thus no need to clone the exact behaviour. nvidia reports the correct size */
1985 ok(ddsd2
.lpSurface
!= 0, "Surface memory is at NULL\n");
1987 hr
= IDirectDrawSurface7_Unlock(surface
, &r2
);
1988 ok(hr
== DD_OK
, "Unlock returned %08x\n", hr
);
1990 IDirectDrawSurface7_Release(surface
);
1994 skip("Hardware DXTN textures not supported\n");
1997 /* What happens to managed textures? Interestingly, Windows reports them as being in system
1998 * memory. The linear size fits again.
2000 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
2001 ddsd
.ddsCaps
.dwCaps2
= DDSCAPS2_TEXTUREMANAGE
;
2002 U4(ddsd
).ddpfPixelFormat
.dwFourCC
= MAKEFOURCC('D','X','T','1');
2004 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd
, &surface
, NULL
);
2005 ok(hr
== DD_OK
|| hr
== DDERR_NOTEXTUREHW
, "CreateSurface returned %08x\n", hr
);
2007 /* Not supported everywhere */
2010 memset(&ddsd2
, 0, sizeof(ddsd2
));
2011 ddsd2
.dwSize
= sizeof(ddsd2
);
2012 U4(ddsd2
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd2
).ddpfPixelFormat
);
2013 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd2
);
2014 ok(hr
== DD_OK
, "GetSurfaceDesc returned %08x\n", hr
);
2016 ok(ddsd2
.dwFlags
== (DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_LINEARSIZE
),
2017 "Surface desc flags: %08x\n", ddsd2
.dwFlags
);
2018 ok(U4(ddsd2
).ddpfPixelFormat
.dwFlags
== DDPF_FOURCC
, "Pixel format flags: %08x\n", U4(ddsd2
).ddpfPixelFormat
.dwFlags
);
2019 ok(U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
== 0, "RGB bitcount: %08x\n", U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
);
2020 ok(ddsd2
.ddsCaps
.dwCaps
== (DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
),
2021 "Surface caps flags: %08x\n", ddsd2
.ddsCaps
.dwCaps
);
2022 ok(U1(ddsd2
).dwLinearSize
== 8192, "Linear size is %d\n", U1(ddsd2
).dwLinearSize
);
2023 ok(ddsd2
.ddsCaps
.dwCaps2
== DDSCAPS2_TEXTUREMANAGE
, "Caps2: %08x\n", ddsd2
.ddsCaps
.dwCaps2
);
2024 IDirectDrawSurface7_Release(surface
);
2026 U4(ddsd
).ddpfPixelFormat
.dwFourCC
= MAKEFOURCC('D','X','T','3');
2027 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd
, &surface
, NULL
);
2028 ok(hr
== DD_OK
, "CreateSurface returned %08x\n", hr
);
2030 memset(&ddsd2
, 0, sizeof(ddsd2
));
2031 ddsd2
.dwSize
= sizeof(ddsd2
);
2032 U4(ddsd2
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd2
).ddpfPixelFormat
);
2033 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd2
);
2034 ok(hr
== DD_OK
, "GetSurfaceDesc returned %08x\n", hr
);
2036 ok(ddsd2
.dwFlags
== (DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_LINEARSIZE
),
2037 "Surface desc flags: %08x\n", ddsd2
.dwFlags
);
2038 ok(U4(ddsd2
).ddpfPixelFormat
.dwFlags
== DDPF_FOURCC
, "Pixel format flags: %08x\n", U4(ddsd2
).ddpfPixelFormat
.dwFlags
);
2039 ok(U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
== 0, "RGB bitcount: %08x\n", U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
);
2040 ok(ddsd2
.ddsCaps
.dwCaps
== (DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
),
2041 "Surface caps flags: %08x\n", ddsd2
.ddsCaps
.dwCaps
);
2042 ok(U1(ddsd2
).dwLinearSize
== 16384, "Linear size is %d\n", U1(ddsd2
).dwLinearSize
);
2043 IDirectDrawSurface7_Release(surface
);
2045 U4(ddsd
).ddpfPixelFormat
.dwFourCC
= MAKEFOURCC('D','X','T','5');
2046 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd
, &surface
, NULL
);
2047 ok(hr
== DD_OK
, "CreateSurface returned %08x\n", hr
);
2049 memset(&ddsd2
, 0, sizeof(ddsd2
));
2050 ddsd2
.dwSize
= sizeof(ddsd2
);
2051 U4(ddsd2
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd2
).ddpfPixelFormat
);
2052 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd2
);
2053 ok(hr
== DD_OK
, "GetSurfaceDesc returned %08x\n", hr
);
2055 ok(ddsd2
.dwFlags
== (DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_LINEARSIZE
),
2056 "Surface desc flags: %08x\n", ddsd2
.dwFlags
);
2057 ok(U4(ddsd2
).ddpfPixelFormat
.dwFlags
== DDPF_FOURCC
, "Pixel format flags: %08x\n", U4(ddsd2
).ddpfPixelFormat
.dwFlags
);
2058 ok(U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
== 0, "RGB bitcount: %08x\n", U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
);
2059 ok(ddsd2
.ddsCaps
.dwCaps
== (DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
),
2060 "Surface caps flags: %08x\n", ddsd2
.ddsCaps
.dwCaps
);
2061 ok(U1(ddsd2
).dwLinearSize
== 16384, "Linear size is %d\n", U1(ddsd2
).dwLinearSize
);
2062 ok(ddsd2
.lpSurface
== 0, "Surface memory is at %p, expected NULL\n", ddsd2
.lpSurface
);
2064 memset(&ddsd2
, 0, sizeof(ddsd2
));
2065 ddsd2
.dwSize
= sizeof(ddsd2
);
2066 U4(ddsd2
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd2
).ddpfPixelFormat
);
2068 /* Show that the description is not changed when locking the surface. What is really interesting
2069 * about this is that DDSD_LPSURFACE isn't set.
2071 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &ddsd2
, DDLOCK_READONLY
, 0);
2072 ok(hr
== DD_OK
, "Lock returned %08x\n", hr
);
2074 ok(ddsd2
.dwFlags
== (DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_LINEARSIZE
),
2075 "Surface desc flags: %08x\n", ddsd2
.dwFlags
);
2076 ok(U4(ddsd2
).ddpfPixelFormat
.dwFlags
== DDPF_FOURCC
, "Pixel format flags: %08x\n", U4(ddsd2
).ddpfPixelFormat
.dwFlags
);
2077 ok(U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
== 0, "RGB bitcount: %08x\n", U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
);
2078 ok(ddsd2
.ddsCaps
.dwCaps
== (DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
),
2079 "Surface caps flags: %08x\n", ddsd2
.ddsCaps
.dwCaps
);
2080 ok(U1(ddsd2
).dwLinearSize
== 16384, "Linear size is %d\n", U1(ddsd2
).dwLinearSize
);
2081 ok(ddsd2
.lpSurface
!= 0, "Surface memory is at NULL\n");
2083 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
2084 ok(hr
== DD_OK
, "Unlock returned %08x\n", hr
);
2086 /* Now what about a locking rect? */
2087 hr
= IDirectDrawSurface7_Lock(surface
, &r
, &ddsd2
, DDLOCK_READONLY
, 0);
2088 ok(hr
== DD_OK
, "Lock returned %08x\n", hr
);
2090 ok(ddsd2
.dwFlags
== (DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_LINEARSIZE
),
2091 "Surface desc flags: %08x\n", ddsd2
.dwFlags
);
2092 ok(U4(ddsd2
).ddpfPixelFormat
.dwFlags
== DDPF_FOURCC
, "Pixel format flags: %08x\n", U4(ddsd2
).ddpfPixelFormat
.dwFlags
);
2093 ok(U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
== 0, "RGB bitcount: %08x\n", U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
);
2094 ok(ddsd2
.ddsCaps
.dwCaps
== (DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
),
2095 "Surface caps flags: %08x\n", ddsd2
.ddsCaps
.dwCaps
);
2096 ok(U1(ddsd2
).dwLinearSize
== 16384, "\"Linear\" size is %d\n", U1(ddsd2
).dwLinearSize
);
2097 ok(ddsd2
.lpSurface
!= 0, "Surface memory is at NULL\n");
2099 hr
= IDirectDrawSurface7_Unlock(surface
, &r
);
2100 ok(hr
== DD_OK
, "Unlock returned %08x\n", hr
);
2102 /* Now what about a different locking offset? */
2103 hr
= IDirectDrawSurface7_Lock(surface
, &r2
, &ddsd2
, DDLOCK_READONLY
, 0);
2104 ok(hr
== DD_OK
, "Lock returned %08x\n", hr
);
2106 ok(ddsd2
.dwFlags
== (DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_LINEARSIZE
),
2107 "Surface desc flags: %08x\n", ddsd2
.dwFlags
);
2108 ok(U4(ddsd2
).ddpfPixelFormat
.dwFlags
== DDPF_FOURCC
, "Pixel format flags: %08x\n", U4(ddsd2
).ddpfPixelFormat
.dwFlags
);
2109 ok(U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
== 0, "RGB bitcount: %08x\n", U1(U4(ddsd2
).ddpfPixelFormat
).dwRGBBitCount
);
2110 ok(ddsd2
.ddsCaps
.dwCaps
== (DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
),
2111 "Surface caps flags: %08x\n", ddsd2
.ddsCaps
.dwCaps
);
2112 ok(U1(ddsd2
).dwLinearSize
== 16384, "\"Linear\" size is %d\n", U1(ddsd2
).dwLinearSize
);
2113 ok(ddsd2
.lpSurface
!= 0, "Surface memory is at NULL\n");
2115 hr
= IDirectDrawSurface7_Unlock(surface
, &r2
);
2116 ok(hr
== DD_OK
, "Unlock returned %08x\n", hr
);
2118 IDirectDrawSurface7_Release(surface
);
2122 skip("Hardware DXTN textures not supported\n");
2125 IDirectDraw7_Release(dd7
);
2128 static void SizeTest(void)
2130 LPDIRECTDRAWSURFACE dsurface
= NULL
;
2133 HWND window
= CreateWindow( "static", "ddraw_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
2135 /* Create an offscreen surface surface without a size */
2136 ZeroMemory(&desc
, sizeof(desc
));
2137 desc
.dwSize
= sizeof(desc
);
2138 desc
.dwFlags
= DDSD_CAPS
;
2139 desc
.ddsCaps
.dwCaps
|= DDSCAPS_OFFSCREENPLAIN
;
2140 ret
= IDirectDraw_CreateSurface(lpDD
, &desc
, &dsurface
, NULL
);
2141 ok(ret
== DDERR_INVALIDPARAMS
, "Creating an offscreen plain surface without a size info returned %08x (dsurface=%p)\n", ret
, dsurface
);
2144 trace("Surface at %p\n", dsurface
);
2145 IDirectDrawSurface_Release(dsurface
);
2149 /* Create an offscreen surface surface with only a width parameter */
2150 ZeroMemory(&desc
, sizeof(desc
));
2151 desc
.dwSize
= sizeof(desc
);
2152 desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
;
2153 desc
.ddsCaps
.dwCaps
|= DDSCAPS_OFFSCREENPLAIN
;
2155 ret
= IDirectDraw_CreateSurface(lpDD
, &desc
, &dsurface
, NULL
);
2156 ok(ret
== DDERR_INVALIDPARAMS
, "Creating an offscreen plain surface without hight info returned %08x\n", ret
);
2159 IDirectDrawSurface_Release(dsurface
);
2163 /* Create an offscreen surface surface with only a height parameter */
2164 ZeroMemory(&desc
, sizeof(desc
));
2165 desc
.dwSize
= sizeof(desc
);
2166 desc
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
;
2167 desc
.ddsCaps
.dwCaps
|= DDSCAPS_OFFSCREENPLAIN
;
2168 desc
.dwHeight
= 128;
2169 ret
= IDirectDraw_CreateSurface(lpDD
, &desc
, &dsurface
, NULL
);
2170 ok(ret
== DDERR_INVALIDPARAMS
, "Creating an offscreen plain surface without width info returned %08x\n", ret
);
2173 IDirectDrawSurface_Release(dsurface
);
2178 ZeroMemory(&desc
, sizeof(desc
));
2179 desc
.dwSize
= sizeof(desc
);
2180 desc
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
;
2181 desc
.ddsCaps
.dwCaps
|= DDSCAPS_OFFSCREENPLAIN
;
2182 desc
.dwHeight
= 128;
2184 ret
= IDirectDraw_CreateSurface(lpDD
, &desc
, &dsurface
, NULL
);
2185 ok(ret
== DD_OK
, "Creating an offscreen plain surface with width and height info returned %08x\n", ret
);
2188 IDirectDrawSurface_Release(dsurface
);
2192 /* Test a primary surface size */
2193 ret
= IDirectDraw_SetCooperativeLevel(lpDD
, window
, DDSCL_NORMAL
);
2194 ok(ret
== DD_OK
, "SetCooperativeLevel failed with %08x\n", ret
);
2196 ZeroMemory(&desc
, sizeof(desc
));
2197 desc
.dwSize
= sizeof(desc
);
2198 desc
.dwFlags
= DDSD_CAPS
;
2199 desc
.ddsCaps
.dwCaps
|= DDSCAPS_PRIMARYSURFACE
;
2200 desc
.dwHeight
= 128; /* Keep them set to check what happens */
2201 desc
.dwWidth
= 128; /* Keep them set to check what happens */
2202 ret
= IDirectDraw_CreateSurface(lpDD
, &desc
, &dsurface
, NULL
);
2203 ok(ret
== DD_OK
, "Creating a primary surface without width and height info returned %08x\n", ret
);
2206 ret
= IDirectDrawSurface_GetSurfaceDesc(dsurface
, &desc
);
2207 ok(ret
== DD_OK
, "GetSurfaceDesc returned %x\n", ret
);
2209 IDirectDrawSurface_Release(dsurface
);
2212 ok(desc
.dwFlags
& DDSD_WIDTH
, "Primary surface doesn't have width set\n");
2213 ok(desc
.dwFlags
& DDSD_HEIGHT
, "Primary surface doesn't have height set\n");
2214 ok(desc
.dwWidth
== GetSystemMetrics(SM_CXSCREEN
), "Surface width differs from screen width\n");
2215 ok(desc
.dwHeight
== GetSystemMetrics(SM_CYSCREEN
), "Surface height differs from screen height\n");
2217 ret
= IDirectDraw_SetCooperativeLevel(lpDD
, NULL
, DDSCL_NORMAL
);
2218 ok(ret
== DD_OK
, "SetCooperativeLevel failed with %08x\n", ret
);
2221 static void PrivateDataTest(void)
2224 IDirectDrawSurface7
*surface7
= NULL
;
2225 IDirectDrawSurface
*surface
= NULL
;
2229 DWORD size
= sizeof(IUnknown
*);
2231 ZeroMemory(&desc
, sizeof(desc
));
2232 desc
.dwSize
= sizeof(desc
);
2233 desc
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
;
2234 desc
.ddsCaps
.dwCaps
|= DDSCAPS_OFFSCREENPLAIN
;
2235 desc
.dwHeight
= 128;
2237 hr
= IDirectDraw_CreateSurface(lpDD
, &desc
, &surface
, NULL
);
2238 ok(hr
== DD_OK
, "Creating an offscreen plain surface failed with %08x\n", hr
);
2243 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirectDrawSurface7
, (void **) &surface7
);
2244 ok(hr
== DD_OK
, "IDirectDrawSurface_QueryInterface failed with %08x\n", hr
);
2247 IDirectDrawSurface_Release(surface
);
2252 hr
= IDirectDrawSurface7_SetPrivateData(surface7
, &IID_IDirectDrawSurface7
/* Abuse this tag */, lpDD
, 0, DDSPD_IUNKNOWNPOINTER
);
2253 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr
);
2254 hr
= IDirectDrawSurface7_SetPrivateData(surface7
, &IID_IDirectDrawSurface7
/* Abuse this tag */, lpDD
, 5, DDSPD_IUNKNOWNPOINTER
);
2255 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr
);
2256 hr
= IDirectDrawSurface7_SetPrivateData(surface7
, &IID_IDirectDrawSurface7
/* Abuse this tag */, lpDD
, sizeof(IUnknown
*) * 2, DDSPD_IUNKNOWNPOINTER
);
2257 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr
);
2259 ref
= getref((IUnknown
*) lpDD
);
2260 hr
= IDirectDrawSurface7_SetPrivateData(surface7
, &IID_IDirectDrawSurface7
/* Abuse this tag */, lpDD
, sizeof(IUnknown
*), DDSPD_IUNKNOWNPOINTER
);
2261 ok(hr
== DD_OK
, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr
);
2262 ref2
= getref((IUnknown
*) lpDD
);
2263 ok(ref2
== ref
+ 1, "Object reference is %d, expected %d\n", ref2
, ref
+ 1);
2264 hr
= IDirectDrawSurface7_FreePrivateData(surface7
, &IID_IDirectDrawSurface7
);
2265 ref2
= getref((IUnknown
*) lpDD
);
2266 ok(ref2
== ref
, "Object reference is %d, expected %d\n", ref2
, ref
);
2268 hr
= IDirectDrawSurface7_SetPrivateData(surface7
, &IID_IDirectDrawSurface7
, lpDD
, sizeof(IUnknown
*), DDSPD_IUNKNOWNPOINTER
);
2269 ok(hr
== DD_OK
, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr
);
2270 hr
= IDirectDrawSurface7_SetPrivateData(surface7
, &IID_IDirectDrawSurface7
, surface7
, sizeof(IUnknown
*), DDSPD_IUNKNOWNPOINTER
);
2271 ok(hr
== DD_OK
, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr
);
2272 ref2
= getref((IUnknown
*) lpDD
);
2273 ok(ref2
== ref
, "Object reference is %d, expected %d\n", ref2
, ref
);
2275 hr
= IDirectDrawSurface7_SetPrivateData(surface7
, &IID_IDirectDrawSurface7
, lpDD
, sizeof(IUnknown
*), DDSPD_IUNKNOWNPOINTER
);
2276 ok(hr
== DD_OK
, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr
);
2277 hr
= IDirectDrawSurface7_GetPrivateData(surface7
, &IID_IDirectDrawSurface7
, &ptr
, &size
);
2278 ok(hr
== DD_OK
, "IDirectDrawSurface7_GetPrivateData failed with %08x\n", hr
);
2279 ref2
= getref((IUnknown
*) lpDD
);
2280 /* Object is NOT being addrefed */
2281 ok(ptr
== (IUnknown
*) lpDD
, "Returned interface pointer is %p, expected %p\n", ptr
, lpDD
);
2282 ok(ref2
== ref
+ 1, "Object reference is %d, expected %d. ptr at %p, orig at %p\n", ref2
, ref
+ 1, ptr
, lpDD
);
2284 IDirectDrawSurface_Release(surface
);
2285 IDirectDrawSurface7_Release(surface7
);
2287 /* Destroying the surface frees the held reference */
2288 ref2
= getref((IUnknown
*) lpDD
);
2289 ok(ref2
== ref
, "Object reference is %d, expected %d\n", ref2
, ref
);
2292 static void BltParamTest(void)
2294 IDirectDrawSurface
*surface1
= NULL
, *surface2
= NULL
;
2298 RECT valid
= {10, 10, 20, 20};
2299 RECT invalid1
= {20, 10, 10, 20};
2300 RECT invalid2
= {20, 20, 20, 20};
2301 RECT invalid3
= {-1, -1, 20, 20};
2302 RECT invalid4
= {60, 60, 70, 70};
2304 memset(&desc
, 0, sizeof(desc
));
2305 desc
.dwSize
= sizeof(desc
);
2306 desc
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
;
2307 desc
.ddsCaps
.dwCaps
|= DDSCAPS_OFFSCREENPLAIN
;
2308 desc
.dwHeight
= 128;
2310 hr
= IDirectDraw_CreateSurface(lpDD
, &desc
, &surface1
, NULL
);
2311 ok(hr
== DD_OK
, "Creating an offscreen plain surface failed with %08x\n", hr
);
2315 hr
= IDirectDraw_CreateSurface(lpDD
, &desc
, &surface2
, NULL
);
2316 ok(hr
== DD_OK
, "Creating an offscreen plain surface failed with %08x\n", hr
);
2321 hr
= IDirectDrawSurface_BltFast(surface1
, 0, 0, NULL
, NULL
, 0);
2322 ok(hr
== DD_OK
, "BltFast from NULL surface returned %08x\n", hr
);
2324 hr
= IDirectDrawSurface_BltFast(surface1
, 0, 0, surface2
, NULL
, 0);
2325 ok(hr
== DD_OK
, "BltFast from smaller to bigger surface returned %08x\n", hr
);
2326 hr
= IDirectDrawSurface_BltFast(surface2
, 0, 0, surface1
, NULL
, 0);
2327 ok(hr
== DDERR_INVALIDRECT
, "BltFast from bigger to smaller surface returned %08x\n", hr
);
2328 hr
= IDirectDrawSurface_BltFast(surface2
, 0, 0, surface1
, &valid
, 0);
2329 ok(hr
== DD_OK
, "BltFast from bigger to smaller surface using a valid rectangle returned %08x\n", hr
);
2330 hr
= IDirectDrawSurface_BltFast(surface2
, 60, 60, surface1
, &valid
, 0);
2331 ok(hr
== DDERR_INVALIDRECT
, "BltFast with a rectangle resulting in an off-surface write returned %08x\n", hr
);
2332 hr
= IDirectDrawSurface_BltFast(surface1
, 90, 90, surface2
, NULL
, 0);
2333 ok(hr
== DDERR_INVALIDRECT
, "BltFast with a rectangle resulting in an off-surface write returned %08x\n", hr
);
2334 hr
= IDirectDrawSurface_BltFast(surface2
, 0, 0, surface1
, &invalid1
, 0);
2335 ok(hr
== DDERR_INVALIDRECT
, "BltFast with invalid rectangle 1 returned %08x\n", hr
);
2336 hr
= IDirectDrawSurface_BltFast(surface2
, 0, 0, surface1
, &invalid2
, 0);
2337 ok(hr
== DDERR_INVALIDRECT
, "BltFast with invalid rectangle 2 returned %08x\n", hr
);
2338 hr
= IDirectDrawSurface_BltFast(surface2
, 0, 0, surface1
, &invalid3
, 0);
2339 ok(hr
== DDERR_INVALIDRECT
, "BltFast with invalid rectangle 3 returned %08x\n", hr
);
2340 hr
= IDirectDrawSurface_BltFast(surface1
, 0, 0, surface2
, &invalid4
, 0);
2341 ok(hr
== DDERR_INVALIDRECT
, "BltFast with invalid rectangle 3 returned %08x\n", hr
);
2342 hr
= IDirectDrawSurface_BltFast(surface1
, 0, 0, surface1
, NULL
, 0);
2343 ok(hr
== DD_OK
, "BltFast blitting a surface onto itself returned %08x\n", hr
);
2345 /* Blt(non-fast) tests */
2346 memset(&BltFx
, 0, sizeof(BltFx
));
2347 BltFx
.dwSize
= sizeof(BltFx
);
2348 U5(BltFx
).dwFillColor
= 0xaabbccdd;
2350 hr
= IDirectDrawSurface_Blt(surface1
, &valid
, NULL
, NULL
, DDBLT_COLORFILL
, &BltFx
);
2351 ok(hr
== DD_OK
, "IDirectDrawSurface_Blt with a valid rectangle for color fill returned %08x\n", hr
);
2352 hr
= IDirectDrawSurface_Blt(surface1
, &valid
, NULL
, &invalid3
, DDBLT_COLORFILL
, &BltFx
);
2353 ok(hr
== DD_OK
, "IDirectDrawSurface_Blt with a invalid, unused rectangle returned %08x\n", hr
);
2354 hr
= IDirectDrawSurface_Blt(surface2
, &invalid1
, NULL
, NULL
, DDBLT_COLORFILL
, &BltFx
);
2355 ok(hr
== DDERR_INVALIDRECT
, "IDirectDrawSurface_Blt with a with invalid rectangle 1 returned %08x\n", hr
);
2356 hr
= IDirectDrawSurface_Blt(surface2
, &invalid2
, NULL
, NULL
, DDBLT_COLORFILL
, &BltFx
);
2357 ok(hr
== DDERR_INVALIDRECT
, "IDirectDrawSurface_Blt with a with invalid rectangle 2 returned %08x\n", hr
);
2358 hr
= IDirectDrawSurface_Blt(surface2
, &invalid3
, NULL
, NULL
, DDBLT_COLORFILL
, &BltFx
);
2359 ok(hr
== DDERR_INVALIDRECT
, "IDirectDrawSurface_Blt with a with invalid rectangle 3 returned %08x\n", hr
);
2360 hr
= IDirectDrawSurface_Blt(surface2
, &invalid4
, NULL
, NULL
, DDBLT_COLORFILL
, &BltFx
);
2361 ok(hr
== DDERR_INVALIDRECT
, "IDirectDrawSurface_Blt with a with invalid rectangle 4 returned %08x\n", hr
);
2363 /* Valid on surface 1 */
2364 hr
= IDirectDrawSurface_Blt(surface1
, &invalid4
, NULL
, NULL
, DDBLT_COLORFILL
, &BltFx
);
2365 ok(hr
== DD_OK
, "IDirectDrawSurface_Blt with a subrectangle fill returned %08x\n", hr
);
2367 /* Works - stretched blit */
2368 hr
= IDirectDrawSurface_Blt(surface1
, NULL
, surface2
, NULL
, 0, NULL
);
2369 ok(hr
== DD_OK
, "IDirectDrawSurface_Blt from a smaller to a bigger surface returned %08x\n", hr
);
2370 hr
= IDirectDrawSurface_Blt(surface2
, NULL
, surface1
, NULL
, 0, NULL
);
2371 ok(hr
== DD_OK
, "IDirectDrawSurface_Blt from a bigger to a smaller surface %08x\n", hr
);
2373 /* Invalid dest rects in sourced blits */
2374 hr
= IDirectDrawSurface_Blt(surface2
, &invalid1
, surface1
, NULL
, 0, NULL
);
2375 ok(hr
== DDERR_INVALIDRECT
, "IDirectDrawSurface_Blt with a with invalid rectangle 1 returned %08x\n", hr
);
2376 hr
= IDirectDrawSurface_Blt(surface2
, &invalid2
, surface1
, NULL
, 0, NULL
);
2377 ok(hr
== DDERR_INVALIDRECT
, "IDirectDrawSurface_Blt with a with invalid rectangle 2 returned %08x\n", hr
);
2378 hr
= IDirectDrawSurface_Blt(surface2
, &invalid3
, surface1
, NULL
, 0, NULL
);
2379 ok(hr
== DDERR_INVALIDRECT
, "IDirectDrawSurface_Blt with a with invalid rectangle 3 returned %08x\n", hr
);
2380 hr
= IDirectDrawSurface_Blt(surface2
, &invalid4
, surface1
, NULL
, 0, NULL
);
2381 ok(hr
== DDERR_INVALIDRECT
, "IDirectDrawSurface_Blt with a with invalid rectangle 4 returned %08x\n", hr
);
2383 /* Invalid src rects */
2384 hr
= IDirectDrawSurface_Blt(surface2
, NULL
, surface1
, &invalid1
, 0, NULL
);
2385 ok(hr
== DDERR_INVALIDRECT
, "IDirectDrawSurface_Blt with a with invalid rectangle 1 returned %08x\n", hr
);
2386 hr
= IDirectDrawSurface_Blt(surface2
, NULL
, surface1
, &invalid2
, 0, NULL
);
2387 ok(hr
== DDERR_INVALIDRECT
, "IDirectDrawSurface_Blt with a with invalid rectangle 2 returned %08x\n", hr
);
2388 hr
= IDirectDrawSurface_Blt(surface2
, NULL
, surface1
, &invalid3
, 0, NULL
);
2389 ok(hr
== DDERR_INVALIDRECT
, "IDirectDrawSurface_Blt with a with invalid rectangle 3 returned %08x\n", hr
);
2390 hr
= IDirectDrawSurface_Blt(surface1
, NULL
, surface2
, &invalid4
, 0, NULL
);
2391 ok(hr
== DDERR_INVALIDRECT
, "IDirectDrawSurface_Blt with a with invalid rectangle 4 returned %08x\n", hr
);
2393 IDirectDrawSurface_Release(surface1
);
2394 IDirectDrawSurface_Release(surface2
);
2397 static void PaletteTest(void)
2400 LPDIRECTDRAWSURFACE lpSurf
= NULL
;
2402 IDirectDrawPalette
*palette
= NULL
;
2403 PALETTEENTRY Table
[256];
2404 PALETTEENTRY palEntries
[256];
2407 for(i
=0; i
<256; i
++)
2409 Table
[i
].peRed
= 0xff;
2410 Table
[i
].peGreen
= 0;
2411 Table
[i
].peBlue
= 0;
2412 Table
[i
].peFlags
= 0;
2415 /* Create a 8bit palette without DDPCAPS_ALLOW256 set */
2416 hr
= IDirectDraw_CreatePalette(lpDD
, DDPCAPS_8BIT
, Table
, &palette
, NULL
);
2417 ok(hr
== DD_OK
, "CreatePalette failed with %08x\n", hr
);
2418 if (FAILED(hr
)) goto err
;
2419 /* Read back the palette and verify the entries. Without DDPCAPS_ALLOW256 set
2420 / entry 0 and 255 should have been overwritten with black and white */
2421 IDirectDrawPalette_GetEntries(palette
, 0, 0, 256, &palEntries
[0]);
2422 ok(hr
== DD_OK
, "GetEntries failed with %08x\n", hr
);
2425 ok((palEntries
[0].peRed
== 0) && (palEntries
[0].peGreen
== 0) && (palEntries
[0].peBlue
== 0),
2426 "Palette entry 0 of a palette without DDPCAPS_ALLOW256 set should be (0,0,0) but it is (%d,%d,%d)\n",
2427 palEntries
[0].peRed
, palEntries
[0].peGreen
, palEntries
[0].peBlue
);
2428 ok((palEntries
[255].peRed
== 255) && (palEntries
[255].peGreen
== 255) && (palEntries
[255].peBlue
== 255),
2429 "Palette entry 255 of a palette without DDPCAPS_ALLOW256 set should be (255,255,255) but it is (%d,%d,%d)\n",
2430 palEntries
[255].peRed
, palEntries
[255].peGreen
, palEntries
[255].peBlue
);
2432 /* Entry 1-254 should contain red */
2433 for(i
=1; i
<255; i
++)
2434 ok((palEntries
[i
].peRed
== 255) && (palEntries
[i
].peGreen
== 0) && (palEntries
[i
].peBlue
== 0),
2435 "Palette entry %d should have contained (255,0,0) but was set to %d,%d,%d)\n",
2436 i
, palEntries
[i
].peRed
, palEntries
[i
].peGreen
, palEntries
[i
].peBlue
);
2439 /* CreatePalette without DDPCAPS_ALLOW256 ignores entry 0 and 255,
2440 / now check we are able to update the entries afterwards. */
2441 IDirectDrawPalette_SetEntries(palette
, 0, 0, 256, &Table
[0]);
2442 ok(hr
== DD_OK
, "SetEntries failed with %08x\n", hr
);
2443 IDirectDrawPalette_GetEntries(palette
, 0, 0, 256, &palEntries
[0]);
2444 ok(hr
== DD_OK
, "GetEntries failed with %08x\n", hr
);
2447 ok((palEntries
[0].peRed
== 0) && (palEntries
[0].peGreen
== 0) && (palEntries
[0].peBlue
== 0),
2448 "Palette entry 0 should have been set to (0,0,0) but it contains (%d,%d,%d)\n",
2449 palEntries
[0].peRed
, palEntries
[0].peGreen
, palEntries
[0].peBlue
);
2450 ok((palEntries
[255].peRed
== 255) && (palEntries
[255].peGreen
== 255) && (palEntries
[255].peBlue
== 255),
2451 "Palette entry 255 should have been set to (255,255,255) but it contains (%d,%d,%d)\n",
2452 palEntries
[255].peRed
, palEntries
[255].peGreen
, palEntries
[255].peBlue
);
2454 IDirectDrawPalette_Release(palette
);
2456 /* Create a 8bit palette with DDPCAPS_ALLOW256 set */
2457 hr
= IDirectDraw_CreatePalette(lpDD
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
, Table
, &palette
, NULL
);
2458 ok(hr
== DD_OK
, "CreatePalette failed with %08x\n", hr
);
2459 if (FAILED(hr
)) goto err
;
2461 IDirectDrawPalette_GetEntries(palette
, 0, 0, 256, &palEntries
[0]);
2462 ok(hr
== DD_OK
, "GetEntries failed with %08x\n", hr
);
2465 /* All entries should contain red */
2466 for(i
=0; i
<256; i
++)
2467 ok((palEntries
[i
].peRed
== 255) && (palEntries
[i
].peGreen
== 0) && (palEntries
[i
].peBlue
== 0),
2468 "Palette entry %d should have contained (255,0,0) but was set to %d,%d,%d)\n",
2469 i
, palEntries
[i
].peRed
, palEntries
[i
].peGreen
, palEntries
[i
].peBlue
);
2472 /* Try to set palette to a non-palettized surface */
2473 ddsd
.dwSize
= sizeof(ddsd
);
2474 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
2475 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
2476 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
2478 ddsd
.dwHeight
= 600;
2479 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
2480 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
2481 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0xFF0000;
2482 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x00FF00;
2483 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x0000FF;
2484 hr
= IDirectDraw_CreateSurface(lpDD
, &ddsd
, &lpSurf
, NULL
);
2485 ok(hr
==DD_OK
, "CreateSurface returned: %x\n",hr
);
2487 skip("failed to create surface\n");
2491 hr
= IDirectDrawSurface_SetPalette(lpSurf
, palette
);
2492 ok(hr
== DDERR_INVALIDPIXELFORMAT
, "CreateSurface returned: %x\n",hr
);
2494 IDirectDrawPalette_Release(palette
);
2497 hr
= IDirectDrawSurface_GetPalette(lpSurf
, &palette
);
2498 ok(hr
== DDERR_NOPALETTEATTACHED
, "CreateSurface returned: %x\n",hr
);
2502 if (lpSurf
) IDirectDrawSurface_Release(lpSurf
);
2503 if (palette
) IDirectDrawPalette_Release(palette
);
2506 static void StructSizeTest(void)
2508 IDirectDrawSurface
*surface1
;
2509 IDirectDrawSurface7
*surface7
;
2511 DDSURFACEDESC desc1
;
2512 DDSURFACEDESC2 desc2
;
2513 char blob
[1024]; /* To get a bunch of writable memory */
2515 DDSURFACEDESC create
;
2518 memset(&desc
, 0, sizeof(desc
));
2519 memset(&create
, 0, sizeof(create
));
2521 memset(&create
, 0, sizeof(create
));
2522 create
.dwSize
= sizeof(create
);
2523 create
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
;
2524 create
.ddsCaps
.dwCaps
|= DDSCAPS_OFFSCREENPLAIN
;
2525 create
.dwHeight
= 128;
2526 create
.dwWidth
= 128;
2527 hr
= IDirectDraw_CreateSurface(lpDD
, &create
, &surface1
, NULL
);
2528 ok(hr
== DD_OK
, "Creating an offscreen plain surface failed with %08x\n", hr
);
2529 hr
= IDirectDrawSurface_QueryInterface(surface1
, &IID_IDirectDrawSurface7
, (void **) &surface7
);
2530 ok(hr
== DD_OK
, "IDirectDrawSurface_QueryInterface failed with %08x\n", hr
);
2532 desc
.desc1
.dwSize
= sizeof(DDSURFACEDESC
);
2533 hr
= IDirectDrawSurface_GetSurfaceDesc(surface1
, &desc
.desc1
);
2534 ok(hr
== DD_OK
, "IDirectDrawSurface_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC) returned %08x\n", hr
);
2535 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface7
, &desc
.desc2
);
2536 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDrawSurface7_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC) returned %08x\n", hr
);
2538 desc
.desc2
.dwSize
= sizeof(DDSURFACEDESC2
);
2539 hr
= IDirectDrawSurface_GetSurfaceDesc(surface1
, &desc
.desc1
);
2540 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDrawSurface_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC2) returned %08x\n", hr
);
2541 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface7
, &desc
.desc2
);
2542 ok(hr
== DD_OK
, "IDirectDrawSurface7_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC2) returned %08x\n", hr
);
2544 desc
.desc2
.dwSize
= 0;
2545 hr
= IDirectDrawSurface_GetSurfaceDesc(surface1
, &desc
.desc1
);
2546 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDrawSurface_GetSurfaceDesc with desc size 0 returned %08x\n", hr
);
2547 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface7
, &desc
.desc2
);
2548 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDrawSurface7_GetSurfaceDesc with desc size 0 returned %08x\n", hr
);
2550 desc
.desc1
.dwSize
= sizeof(DDSURFACEDESC
) + 1;
2551 hr
= IDirectDrawSurface_GetSurfaceDesc(surface1
, &desc
.desc1
);
2552 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDrawSurface_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC) + 1 returned %08x\n", hr
);
2553 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface7
, &desc
.desc2
);
2554 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDrawSurface7_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC) + 1 returned %08x\n", hr
);
2556 desc
.desc2
.dwSize
= sizeof(DDSURFACEDESC2
) + 1;
2557 hr
= IDirectDrawSurface_GetSurfaceDesc(surface1
, &desc
.desc1
);
2558 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDrawSurface_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC2) + 1returned %08x\n", hr
);
2559 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface7
, &desc
.desc2
);
2560 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDrawSurface7_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC2) + 1returned %08x\n", hr
);
2562 /* Tests for Lock() */
2564 desc
.desc1
.dwSize
= sizeof(DDSURFACEDESC
);
2565 hr
= IDirectDrawSurface_Lock(surface1
, NULL
, &desc
.desc1
, 0, 0);
2566 ok(hr
== DD_OK
, "IDirectDrawSurface_Lock with desc size sizeof(DDSURFACEDESC) returned %08x\n", hr
);
2567 if(SUCCEEDED(hr
)) IDirectDrawSurface_Unlock(surface1
, NULL
);
2568 ok(desc
.desc1
.dwSize
== sizeof(DDSURFACEDESC
), "Destination size was changed to %d\n", desc
.desc1
.dwSize
);
2569 hr
= IDirectDrawSurface7_Lock(surface7
, NULL
, &desc
.desc2
, 0, 0);
2570 ok(hr
== DD_OK
, "IDirectDrawSurface7_Lock with desc size sizeof(DDSURFACEDESC) returned %08x\n", hr
);
2571 if(SUCCEEDED(hr
)) IDirectDrawSurface7_Unlock(surface7
, NULL
);
2572 ok(desc
.desc2
.dwSize
== sizeof(DDSURFACEDESC
), "Destination size was changed to %d\n", desc
.desc1
.dwSize
);
2574 desc
.desc2
.dwSize
= sizeof(DDSURFACEDESC2
);
2575 hr
= IDirectDrawSurface_Lock(surface1
, NULL
, &desc
.desc1
, 0, 0);
2576 ok(hr
== DD_OK
, "IDirectDrawSurface_Lock with desc size sizeof(DDSURFACEDESC2) returned %08x\n", hr
);
2577 ok(desc
.desc1
.dwSize
== sizeof(DDSURFACEDESC2
), "Destination size was changed to %d\n", desc
.desc1
.dwSize
);
2578 if(SUCCEEDED(hr
)) IDirectDrawSurface_Unlock(surface1
, NULL
);
2579 hr
= IDirectDrawSurface7_Lock(surface7
, NULL
, &desc
.desc2
, 0, 0);
2580 ok(hr
== DD_OK
, "IDirectDrawSurface7_Lock with desc size sizeof(DDSURFACEDESC2) returned %08x\n", hr
);
2581 if(SUCCEEDED(hr
)) IDirectDrawSurface7_Unlock(surface7
, NULL
);
2582 ok(desc
.desc2
.dwSize
== sizeof(DDSURFACEDESC2
), "Destination size was changed to %d\n", desc
.desc1
.dwSize
);
2584 desc
.desc2
.dwSize
= 0;
2585 hr
= IDirectDrawSurface_Lock(surface1
, NULL
, &desc
.desc1
, 0, 0);
2586 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDrawSurface_Lock with desc size 0 returned %08x\n", hr
);
2587 if(SUCCEEDED(hr
)) IDirectDrawSurface_Unlock(surface1
, NULL
);
2588 hr
= IDirectDrawSurface7_Lock(surface7
, NULL
, &desc
.desc2
, 0, 0);
2589 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDrawSurface7_Lock with desc size 0 returned %08x\n", hr
);
2590 if(SUCCEEDED(hr
)) IDirectDrawSurface7_Unlock(surface7
, NULL
);
2592 desc
.desc1
.dwSize
= sizeof(DDSURFACEDESC
) + 1;
2593 hr
= IDirectDrawSurface_Lock(surface1
, NULL
, &desc
.desc1
, 0, 0);
2594 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDrawSurface_Lock with desc size sizeof(DDSURFACEDESC) + 1 returned %08x\n", hr
);
2595 if(SUCCEEDED(hr
)) IDirectDrawSurface_Unlock(surface1
, NULL
);
2596 hr
= IDirectDrawSurface7_Lock(surface7
, NULL
, &desc
.desc2
, 0, 0);
2597 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDrawSurface7_Lock with desc size sizeof(DDSURFACEDESC) + 1 returned %08x\n", hr
);
2598 if(SUCCEEDED(hr
)) IDirectDrawSurface7_Unlock(surface7
, NULL
);
2600 desc
.desc2
.dwSize
= sizeof(DDSURFACEDESC2
) + 1;
2601 hr
= IDirectDrawSurface_Lock(surface1
, NULL
, &desc
.desc1
, 0, 0);
2602 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDrawSurface_Lock with desc size sizeof(DDSURFACEDESC2) + 1returned %08x\n", hr
);
2603 if(SUCCEEDED(hr
)) IDirectDrawSurface_Unlock(surface1
, NULL
);
2604 hr
= IDirectDrawSurface7_Lock(surface7
, NULL
, &desc
.desc2
, 0, 0);
2605 ok(hr
== DDERR_INVALIDPARAMS
, "IDirectDrawSurface7_Lock with desc size sizeof(DDSURFACEDESC2) + 1returned %08x\n", hr
);
2606 if(SUCCEEDED(hr
)) IDirectDrawSurface7_Unlock(surface7
, NULL
);
2608 IDirectDrawSurface7_Release(surface7
);
2609 IDirectDrawSurface_Release(surface1
);
2612 START_TEST(dsurface
)
2614 if (!CreateDirectDraw())
2616 MipMapCreationTest();
2617 SrcColorKey32BlitTest();
2627 test_lockrect_invalid();
2634 ReleaseDirectDraw();