2 * Unit tests for (a few) ddraw surface functions
4 * Copyright (C) 2005 Antoine Chavasse (a.chavasse@gmail.com)
5 * Copyright (C) 2005 Christian Costa
6 * Copyright 2005 Ivan Leo Puoti
7 * Copyright (C) 2007 Stefan Dösinger
8 * Copyright (C) 2008 Alexander Dorofeyev
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/test.h"
27 #include "wine/exception.h"
32 static LPDIRECTDRAW lpDD = NULL;
35 static BOOL CreateDirectDraw(void)
39 rc = DirectDrawCreate(NULL, &lpDD, NULL);
40 ok(rc==DD_OK || rc==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreateEx returned: %x\n", rc);
42 trace("DirectDrawCreateEx() failed with an error %x\n", rc);
46 rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_NORMAL);
47 ok(rc==DD_OK,"SetCooperativeLevel returned: %x\n",rc);
53 static void ReleaseDirectDraw(void)
57 IDirectDraw_Release(lpDD);
62 static void MipMapCreationTest(void)
64 LPDIRECTDRAWSURFACE lpDDSMipMapTest;
68 /* First mipmap creation test: create a surface with DDSCAPS_COMPLEX,
69 DDSCAPS_MIPMAP, and DDSD_MIPMAPCOUNT. This create the number of
70 requested mipmap levels. */
71 ddsd.dwSize = sizeof(ddsd);
72 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_MIPMAPCOUNT;
73 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
74 U2(ddsd).dwMipMapCount = 3;
77 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpDDSMipMapTest, NULL);
78 ok(rc==DD_OK,"CreateSurface returned: %x\n",rc);
81 skip("failed to create surface\n");
85 /* Check the number of created mipmaps */
86 memset(&ddsd, 0, sizeof(DDSURFACEDESC));
87 ddsd.dwSize = sizeof(ddsd);
88 rc = IDirectDrawSurface_GetSurfaceDesc(lpDDSMipMapTest, &ddsd);
89 ok(rc==DD_OK,"GetSurfaceDesc returned: %x\n",rc);
90 ok(ddsd.dwFlags & DDSD_MIPMAPCOUNT,
91 "GetSurfaceDesc returned no mipmapcount.\n");
92 ok(U2(ddsd).dwMipMapCount == 3, "Incorrect mipmap count: %d.\n",
93 U2(ddsd).dwMipMapCount);
95 /* Destroy the surface. */
96 IDirectDrawSurface_Release(lpDDSMipMapTest);
99 /* Second mipmap creation test: create a surface without a mipmap
100 count, with DDSCAPS_MIPMAP and without DDSCAPS_COMPLEX.
101 This creates a single mipmap level. */
102 memset(&ddsd, 0, sizeof(DDSURFACEDESC));
103 ddsd.dwSize = sizeof(ddsd);
104 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
105 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_MIPMAP;
108 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpDDSMipMapTest, NULL);
109 ok(rc==DD_OK,"CreateSurface returned: %x\n",rc);
112 skip("failed to create surface\n");
115 /* Check the number of created mipmaps */
116 memset(&ddsd, 0, sizeof(DDSURFACEDESC));
117 ddsd.dwSize = sizeof(ddsd);
118 rc = IDirectDrawSurface_GetSurfaceDesc(lpDDSMipMapTest, &ddsd);
119 ok(rc==DD_OK,"GetSurfaceDesc returned: %x\n",rc);
120 ok(ddsd.dwFlags & DDSD_MIPMAPCOUNT,
121 "GetSurfaceDesc returned no mipmapcount.\n");
122 ok(U2(ddsd).dwMipMapCount == 1, "Incorrect mipmap count: %d.\n",
123 U2(ddsd).dwMipMapCount);
125 /* Destroy the surface. */
126 IDirectDrawSurface_Release(lpDDSMipMapTest);
129 /* Third mipmap creation test: create a surface with DDSCAPS_MIPMAP,
130 DDSCAPS_COMPLEX and without DDSD_MIPMAPCOUNT.
131 It's an undocumented features where a chain of mipmaps, starting from
132 he specified size and down to the smallest size, is automatically
134 Anarchy Online needs this feature to work. */
135 memset(&ddsd, 0, sizeof(DDSURFACEDESC));
136 ddsd.dwSize = sizeof(ddsd);
137 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
138 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
141 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpDDSMipMapTest, NULL);
142 ok(rc==DD_OK,"CreateSurface returned: %x\n",rc);
145 skip("failed to create surface\n");
149 /* Check the number of created mipmaps */
150 memset(&ddsd, 0, sizeof(DDSURFACEDESC));
151 ddsd.dwSize = sizeof(ddsd);
152 rc = IDirectDrawSurface_GetSurfaceDesc(lpDDSMipMapTest, &ddsd);
153 ok(rc==DD_OK,"GetSurfaceDesc returned: %x\n",rc);
154 ok(ddsd.dwFlags & DDSD_MIPMAPCOUNT,
155 "GetSurfaceDesc returned no mipmapcount.\n");
156 ok(U2(ddsd).dwMipMapCount == 6, "Incorrect mipmap count: %d.\n",
157 U2(ddsd).dwMipMapCount);
159 /* Destroy the surface. */
160 IDirectDrawSurface_Release(lpDDSMipMapTest);
163 /* Fourth mipmap creation test: same as above with a different texture
165 The purpose is to verify that the number of generated mipmaps is
166 dependent on the smallest dimension. */
167 memset(&ddsd, 0, sizeof(DDSURFACEDESC));
168 ddsd.dwSize = sizeof(ddsd);
169 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
170 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
173 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpDDSMipMapTest, NULL);
174 ok(rc==DD_OK,"CreateSurface returned: %x\n",rc);
177 skip("failed to create surface\n");
181 /* Check the number of created mipmaps */
182 memset(&ddsd, 0, sizeof(DDSURFACEDESC));
183 ddsd.dwSize = sizeof(ddsd);
184 rc = IDirectDrawSurface_GetSurfaceDesc(lpDDSMipMapTest, &ddsd);
185 ok(rc==DD_OK,"GetSurfaceDesc returned: %x\n",rc);
186 ok(ddsd.dwFlags & DDSD_MIPMAPCOUNT,
187 "GetSurfaceDesc returned no mipmapcount.\n");
188 ok(U2(ddsd).dwMipMapCount == 6, "Incorrect mipmap count: %d.\n",
189 U2(ddsd).dwMipMapCount);
191 /* Destroy the surface. */
192 IDirectDrawSurface_Release(lpDDSMipMapTest);
195 /* Fifth mipmap creation test: try to create a surface with
196 DDSCAPS_COMPLEX, DDSCAPS_MIPMAP, DDSD_MIPMAPCOUNT,
197 where dwMipMapCount = 0. This should fail. */
199 ddsd.dwSize = sizeof(ddsd);
200 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_MIPMAPCOUNT;
201 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
202 U2(ddsd).dwMipMapCount = 0;
205 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpDDSMipMapTest, NULL);
206 ok(rc==DDERR_INVALIDPARAMS,"CreateSurface returned: %x\n",rc);
208 /* Destroy the surface. */
210 IDirectDrawSurface_Release(lpDDSMipMapTest);
214 static void SrcColorKey32BlitTest(void)
216 LPDIRECTDRAWSURFACE lpSrc;
217 LPDIRECTDRAWSURFACE lpDst;
218 DDSURFACEDESC ddsd, ddsd2, ddsd3;
219 DDCOLORKEY DDColorKey;
224 ddsd2.dwSize = sizeof(ddsd2);
225 ddsd2.ddpfPixelFormat.dwSize = sizeof(ddsd2.ddpfPixelFormat);
227 ddsd.dwSize = sizeof(ddsd);
228 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
229 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
230 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
233 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
234 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 32;
235 U2(ddsd.ddpfPixelFormat).dwRBitMask = 0xFF0000;
236 U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x00FF00;
237 U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x0000FF;
238 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpDst, NULL);
239 ok(rc==DD_OK,"CreateSurface returned: %x\n",rc);
242 skip("failed to create surface\n");
246 ddsd.dwFlags |= DDSD_CKSRCBLT;
247 ddsd.ddckCKSrcBlt.dwColorSpaceLowValue = 0xFF00FF;
248 ddsd.ddckCKSrcBlt.dwColorSpaceHighValue = 0xFF00FF;
249 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpSrc, NULL);
250 ok(rc==DD_OK,"CreateSurface returned: %x\n",rc);
253 skip("failed to create surface\n");
257 rc = IDirectDrawSurface_Lock(lpDst, NULL, &ddsd2, DDLOCK_WAIT, NULL);
258 ok(rc==DD_OK,"Lock returned: %x\n",rc);
259 lpData = ddsd2.lpSurface;
260 lpData[0] = 0xCCCCCCCC;
261 lpData[1] = 0xCCCCCCCC;
262 lpData[2] = 0xCCCCCCCC;
263 lpData[3] = 0xCCCCCCCC;
265 memset(&ddsd3, 0, sizeof(ddsd3));
266 ddsd3.dwSize = sizeof(ddsd3);
267 ddsd3.ddpfPixelFormat.dwSize = sizeof(ddsd3.ddpfPixelFormat);
268 rc = IDirectDrawSurface_GetSurfaceDesc(lpDst, &ddsd3);
269 ok(rc == DD_OK, "IDirectDrawSurface_GetSurfaceDesc between a lock/unlock pair returned %08x\n", rc);
270 ok(ddsd3.lpSurface == ddsd3.lpSurface, "lpSurface from GetSurfaceDesc(%p) differs from the one returned by Lock(%p)\n", ddsd3.lpSurface, ddsd2.lpSurface);
272 rc = IDirectDrawSurface_Unlock(lpDst, NULL);
273 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
275 memset(&ddsd3, 0, sizeof(ddsd3));
276 ddsd3.dwSize = sizeof(ddsd3);
277 ddsd3.ddpfPixelFormat.dwSize = sizeof(ddsd3.ddpfPixelFormat);
278 rc = IDirectDrawSurface_GetSurfaceDesc(lpDst, &ddsd3);
279 ok(rc == DD_OK, "IDirectDrawSurface_GetSurfaceDesc between a lock/unlock pair returned %08x\n", rc);
280 ok(ddsd3.lpSurface == NULL, "lpSurface from GetSurfaceDesc(%p) is not NULL after unlock\n", ddsd3.lpSurface);
282 rc = IDirectDrawSurface_Lock(lpSrc, NULL, &ddsd2, DDLOCK_WAIT, NULL);
283 ok(rc==DD_OK,"Lock returned: %x\n",rc);
284 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
285 lpData = ddsd2.lpSurface;
286 lpData[0] = 0x77010203;
287 lpData[1] = 0x00010203;
288 lpData[2] = 0x77FF00FF;
289 lpData[3] = 0x00FF00FF;
290 rc = IDirectDrawSurface_Unlock(lpSrc, NULL);
291 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
293 IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYSRC, NULL);
295 rc = IDirectDrawSurface_Lock(lpDst, NULL, &ddsd2, DDLOCK_WAIT, NULL);
296 ok(rc==DD_OK,"Lock returned: %x\n",rc);
297 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
298 lpData = ddsd2.lpSurface;
299 /* Different behavior on some drivers / windows versions. Some versions ignore the X channel when
300 * color keying, but copy it to the destination surface. Others apply it for color keying, but
301 * do not copy it into the destination surface.
303 if(lpData[0]==0x00010203) {
304 trace("X channel was not copied into the destination surface\n");
305 ok((lpData[0]==0x00010203)&&(lpData[1]==0x00010203)&&(lpData[2]==0x00FF00FF)&&(lpData[3]==0xCCCCCCCC),
306 "Destination data after blitting is not correct\n");
308 ok((lpData[0]==0x77010203)&&(lpData[1]==0x00010203)&&(lpData[2]==0xCCCCCCCC)&&(lpData[3]==0xCCCCCCCC),
309 "Destination data after blitting is not correct\n");
311 rc = IDirectDrawSurface_Unlock(lpDst, NULL);
312 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
314 /* Below we repeat the same test as above but now using BltFast instead of Blt. Before
315 * we can carry out the test we need to restore the color of the destination surface.
317 rc = IDirectDrawSurface_Lock(lpDst, NULL, &ddsd2, DDLOCK_WAIT, NULL);
318 ok(rc==DD_OK,"Lock returned: %x\n",rc);
319 lpData = ddsd2.lpSurface;
320 lpData[0] = 0xCCCCCCCC;
321 lpData[1] = 0xCCCCCCCC;
322 lpData[2] = 0xCCCCCCCC;
323 lpData[3] = 0xCCCCCCCC;
324 rc = IDirectDrawSurface_Unlock(lpDst, NULL);
325 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
327 IDirectDrawSurface_BltFast(lpDst, 0, 0, lpSrc, NULL, DDBLTFAST_SRCCOLORKEY);
329 rc = IDirectDrawSurface_Lock(lpDst, NULL, &ddsd2, DDLOCK_WAIT, NULL);
330 ok(rc==DD_OK,"Lock returned: %x\n",rc);
331 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
332 lpData = ddsd2.lpSurface;
333 /* Different behavior on some drivers / windows versions. Some versions ignore the X channel when
334 * color keying, but copy it to the destination surface. Others apply it for color keying, but
335 * do not copy it into the destination surface.
337 if(lpData[0]==0x00010203) {
338 trace("X channel was not copied into the destination surface\n");
339 ok((lpData[0]==0x00010203)&&(lpData[1]==0x00010203)&&(lpData[2]==0x00FF00FF)&&(lpData[3]==0xCCCCCCCC),
340 "Destination data after blitting is not correct\n");
342 ok((lpData[0]==0x77010203)&&(lpData[1]==0x00010203)&&(lpData[2]==0xCCCCCCCC)&&(lpData[3]==0xCCCCCCCC),
343 "Destination data after blitting is not correct\n");
345 rc = IDirectDrawSurface_Unlock(lpDst, NULL);
346 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
348 /* Also test SetColorKey */
349 IDirectDrawSurface_GetColorKey(lpSrc, DDCKEY_SRCBLT, &DDColorKey);
350 ok(DDColorKey.dwColorSpaceLowValue == 0xFF00FF && DDColorKey.dwColorSpaceHighValue == 0xFF00FF,
351 "GetColorKey does not return the colorkey used at surface creation\n");
353 DDColorKey.dwColorSpaceLowValue = 0x00FF00;
354 DDColorKey.dwColorSpaceHighValue = 0x00FF00;
355 IDirectDrawSurface_SetColorKey(lpSrc, DDCKEY_SRCBLT, &DDColorKey);
357 DDColorKey.dwColorSpaceLowValue = 0;
358 DDColorKey.dwColorSpaceHighValue = 0;
359 IDirectDrawSurface_GetColorKey(lpSrc, DDCKEY_SRCBLT, &DDColorKey);
360 ok(DDColorKey.dwColorSpaceLowValue == 0x00FF00 && DDColorKey.dwColorSpaceHighValue == 0x00FF00,
361 "GetColorKey does not return the colorkey set with SetColorKey\n");
363 ddsd.ddckCKSrcBlt.dwColorSpaceLowValue = 0;
364 ddsd.ddckCKSrcBlt.dwColorSpaceHighValue = 0;
365 IDirectDrawSurface_GetSurfaceDesc(lpSrc, &ddsd);
366 ok(ddsd.ddckCKSrcBlt.dwColorSpaceLowValue == 0x00FF00 && ddsd.ddckCKSrcBlt.dwColorSpaceHighValue == 0x00FF00,
367 "GetSurfaceDesc does not return the colorkey set with SetColorKey\n");
369 /* Test SetColorKey with dwColorSpaceHighValue < dwColorSpaceLowValue */
370 DDColorKey.dwColorSpaceLowValue = 0x0000FF;
371 DDColorKey.dwColorSpaceHighValue = 0x000000;
372 IDirectDrawSurface_SetColorKey(lpSrc, DDCKEY_SRCBLT, &DDColorKey);
374 DDColorKey.dwColorSpaceLowValue = 0;
375 DDColorKey.dwColorSpaceHighValue = 0;
376 IDirectDrawSurface_GetColorKey(lpSrc, DDCKEY_SRCBLT, &DDColorKey);
377 ok(DDColorKey.dwColorSpaceLowValue == 0x0000FF && DDColorKey.dwColorSpaceHighValue == 0x0000FF,
378 "GetColorKey does not return the colorkey set with SetColorKey (%x %x)\n", DDColorKey.dwColorSpaceLowValue, DDColorKey.dwColorSpaceHighValue);
380 DDColorKey.dwColorSpaceLowValue = 0x0000FF;
381 DDColorKey.dwColorSpaceHighValue = 0x000001;
382 IDirectDrawSurface_SetColorKey(lpSrc, DDCKEY_SRCBLT, &DDColorKey);
384 DDColorKey.dwColorSpaceLowValue = 0;
385 DDColorKey.dwColorSpaceHighValue = 0;
386 IDirectDrawSurface_GetColorKey(lpSrc, DDCKEY_SRCBLT, &DDColorKey);
387 ok(DDColorKey.dwColorSpaceLowValue == 0x0000FF && DDColorKey.dwColorSpaceHighValue == 0x0000FF,
388 "GetColorKey does not return the colorkey set with SetColorKey (%x %x)\n", DDColorKey.dwColorSpaceLowValue, DDColorKey.dwColorSpaceHighValue);
390 DDColorKey.dwColorSpaceLowValue = 0x0000FF;
391 DDColorKey.dwColorSpaceHighValue = 0x0000FE;
392 IDirectDrawSurface_SetColorKey(lpSrc, DDCKEY_SRCBLT, &DDColorKey);
394 DDColorKey.dwColorSpaceLowValue = 0;
395 DDColorKey.dwColorSpaceHighValue = 0;
396 IDirectDrawSurface_GetColorKey(lpSrc, DDCKEY_SRCBLT, &DDColorKey);
397 ok(DDColorKey.dwColorSpaceLowValue == 0x0000FF && DDColorKey.dwColorSpaceHighValue == 0x0000FF,
398 "GetColorKey does not return the colorkey set with SetColorKey (%x %x)\n", DDColorKey.dwColorSpaceLowValue, DDColorKey.dwColorSpaceHighValue);
400 IDirectDrawSurface_Release(lpSrc);
401 IDirectDrawSurface_Release(lpDst);
403 /* start with a new set of surfaces to test the color keying parameters to blit */
404 memset(&ddsd, 0, sizeof(ddsd));
405 ddsd.dwSize = sizeof(ddsd);
406 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
407 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CKSRCBLT | DDSD_CKDESTBLT;
408 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
411 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
412 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 32;
413 U2(ddsd.ddpfPixelFormat).dwRBitMask = 0xFF0000;
414 U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x00FF00;
415 U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x0000FF;
416 ddsd.ddckCKDestBlt.dwColorSpaceLowValue = 0xFF0000;
417 ddsd.ddckCKDestBlt.dwColorSpaceHighValue = 0xFF0000;
418 ddsd.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00FF00;
419 ddsd.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00FF00;
420 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpDst, NULL);
421 ok(rc==DD_OK || rc == DDERR_NOCOLORKEYHW,"CreateSurface returned: %x\n",rc);
424 skip("Failed to create surface\n");
428 /* start with a new set of surfaces to test the color keying parameters to blit */
429 memset(&ddsd, 0, sizeof(ddsd));
430 ddsd.dwSize = sizeof(ddsd);
431 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
432 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CKSRCBLT | DDSD_CKDESTBLT;
433 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
436 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
437 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 32;
438 U2(ddsd.ddpfPixelFormat).dwRBitMask = 0xFF0000;
439 U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x00FF00;
440 U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x0000FF;
441 ddsd.ddckCKSrcBlt.dwColorSpaceLowValue = 0x0000FF;
442 ddsd.ddckCKSrcBlt.dwColorSpaceHighValue = 0x0000FF;
443 ddsd.ddckCKDestBlt.dwColorSpaceLowValue = 0x000000;
444 ddsd.ddckCKDestBlt.dwColorSpaceHighValue = 0x000000;
445 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpSrc, NULL);
446 ok(rc==DD_OK || rc == DDERR_NOCOLORKEYHW,"CreateSurface returned: %x\n",rc);
449 skip("Failed to create surface\n");
450 IDirectDrawSurface_Release(lpDst);
454 memset(&fx, 0, sizeof(fx));
455 fx.dwSize = sizeof(fx);
456 fx.ddckSrcColorkey.dwColorSpaceHighValue = 0x110000;
457 fx.ddckSrcColorkey.dwColorSpaceLowValue = 0x110000;
458 fx.ddckDestColorkey.dwColorSpaceHighValue = 0x001100;
459 fx.ddckDestColorkey.dwColorSpaceLowValue = 0x001100;
461 rc = IDirectDrawSurface_Lock(lpSrc, NULL, &ddsd2, DDLOCK_WAIT, NULL);
462 ok(rc==DD_OK,"Lock returned: %x\n",rc);
463 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
464 lpData = ddsd2.lpSurface;
465 lpData[0] = 0x000000FF; /* Applies to src blt key in src surface */
466 lpData[1] = 0x00000000; /* Applies to dst blt key in src surface */
467 lpData[2] = 0x00FF0000; /* Dst color key in dst surface */
468 lpData[3] = 0x0000FF00; /* Src color key in dst surface */
469 lpData[4] = 0x00001100; /* Src color key in ddbltfx */
470 lpData[5] = 0x00110000; /* Dst color key in ddbltfx */
471 rc = IDirectDrawSurface_Unlock(lpSrc, NULL);
472 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
474 rc = IDirectDrawSurface_Lock(lpDst, NULL, &ddsd2, DDLOCK_WAIT, NULL);
475 ok(rc==DD_OK,"Lock returned: %x\n",rc);
476 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
477 lpData = ddsd2.lpSurface;
478 lpData[0] = 0x55555555;
479 lpData[1] = 0x55555555;
480 lpData[2] = 0x55555555;
481 lpData[3] = 0x55555555;
482 lpData[4] = 0x55555555;
483 lpData[5] = 0x55555555;
484 rc = IDirectDrawSurface_Unlock(lpDst, NULL);
485 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
487 /* Test a blit without keying */
488 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, 0, &fx);
489 ok(rc == DD_OK, "IDirectDrawSurface_Blt returned %08x\n", rc);
491 rc = IDirectDrawSurface_Lock(lpDst, NULL, &ddsd2, DDLOCK_WAIT, NULL);
492 ok(rc==DD_OK,"Lock returned: %x\n",rc);
493 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
494 lpData = ddsd2.lpSurface;
495 /* Should have copied src data unmodified to dst */
496 ok(lpData[0] == 0x000000FF &&
497 lpData[1] == 0x00000000 &&
498 lpData[2] == 0x00FF0000 &&
499 lpData[3] == 0x0000FF00 &&
500 lpData[4] == 0x00001100 &&
501 lpData[5] == 0x00110000, "Surface data after unkeyed blit does not match\n");
503 lpData[0] = 0x55555555;
504 lpData[1] = 0x55555555;
505 lpData[2] = 0x55555555;
506 lpData[3] = 0x55555555;
507 lpData[4] = 0x55555555;
508 lpData[5] = 0x55555555;
509 rc = IDirectDrawSurface_Unlock(lpDst, NULL);
510 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
513 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYSRC, &fx);
514 ok(rc == DD_OK, "IDirectDrawSurface_Blt returned %08x\n", rc);
516 rc = IDirectDrawSurface_Lock(lpDst, NULL, &ddsd2, DDLOCK_WAIT, NULL);
517 ok(rc==DD_OK,"Lock returned: %x\n",rc);
518 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
519 lpData = ddsd2.lpSurface;
521 ok(lpData[0] == 0x55555555 && /* Here the src key applied */
522 lpData[1] == 0x00000000 &&
523 lpData[2] == 0x00FF0000 &&
524 lpData[3] == 0x0000FF00 &&
525 lpData[4] == 0x00001100 &&
526 lpData[5] == 0x00110000, "Surface data after srckey blit does not match\n");
528 lpData[0] = 0x55555555;
529 lpData[1] = 0x55555555;
530 lpData[2] = 0x55555555;
531 lpData[3] = 0x55555555;
532 lpData[4] = 0x55555555;
533 lpData[5] = 0x55555555;
534 rc = IDirectDrawSurface_Unlock(lpDst, NULL);
535 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
538 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYSRCOVERRIDE, &fx);
539 ok(rc == DD_OK, "IDirectDrawSurface_Blt returned %08x\n", rc);
541 rc = IDirectDrawSurface_Lock(lpDst, NULL, &ddsd2, DDLOCK_WAIT, NULL);
542 ok(rc==DD_OK,"Lock returned: %x\n",rc);
543 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
544 lpData = ddsd2.lpSurface;
546 ok(lpData[0] == 0x000000FF &&
547 lpData[1] == 0x00000000 &&
548 lpData[2] == 0x00FF0000 &&
549 lpData[3] == 0x0000FF00 &&
550 lpData[4] == 0x00001100 &&
551 lpData[5] == 0x55555555, /* Override key applies here */
552 "Surface data after src override key blit does not match\n");
554 lpData[0] = 0x55555555;
555 lpData[1] = 0x55555555;
556 lpData[2] = 0x55555555;
557 lpData[3] = 0x55555555;
558 lpData[4] = 0x55555555;
559 lpData[5] = 0x55555555;
560 rc = IDirectDrawSurface_Unlock(lpDst, NULL);
561 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
563 /* Src override AND src key. That is not supposed to work */
564 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYSRC | DDBLT_KEYSRCOVERRIDE, &fx);
565 ok(rc == DDERR_INVALIDPARAMS, "IDirectDrawSurface_Blt returned %08x\n", rc);
567 /* Verify that the destination is unchanged */
568 rc = IDirectDrawSurface_Lock(lpDst, NULL, &ddsd2, DDLOCK_WAIT, NULL);
569 ok(rc==DD_OK,"Lock returned: %x\n",rc);
570 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
571 lpData = ddsd2.lpSurface;
573 ok(lpData[0] == 0x55555555 &&
574 lpData[1] == 0x55555555 &&
575 lpData[2] == 0x55555555 &&
576 lpData[3] == 0x55555555 &&
577 lpData[4] == 0x55555555 &&
578 lpData[5] == 0x55555555, /* Override key applies here */
579 "Surface data after src key blit with override does not match\n");
581 lpData[0] = 0x00FF0000; /* Dest key in dst surface */
582 lpData[1] = 0x00FF0000; /* Dest key in dst surface */
583 lpData[2] = 0x00001100; /* Dest key in override */
584 lpData[3] = 0x00001100; /* Dest key in override */
585 lpData[4] = 0x00000000; /* Dest key in src surface */
586 lpData[5] = 0x00000000; /* Dest key in src surface */
587 rc = IDirectDrawSurface_Unlock(lpDst, NULL);
588 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
591 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYDEST, &fx);
592 ok(rc == DD_OK, "IDirectDrawSurface_Blt returned %08x\n", rc);
594 rc = IDirectDrawSurface_Lock(lpDst, NULL, &ddsd2, DDLOCK_WAIT, NULL);
595 ok(rc==DD_OK,"Lock returned: %x\n",rc);
596 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
597 lpData = ddsd2.lpSurface;
599 /* DirectDraw uses the dest blit key from the SOURCE surface ! */
600 ok(lpData[0] == 0x00ff0000 &&
601 lpData[1] == 0x00ff0000 &&
602 lpData[2] == 0x00001100 &&
603 lpData[3] == 0x00001100 &&
604 lpData[4] == 0x00001100 && /* Key applies here */
605 lpData[5] == 0x00110000, /* Key applies here */
606 "Surface data after dest key blit does not match\n");
608 lpData[0] = 0x00FF0000; /* Dest key in dst surface */
609 lpData[1] = 0x00FF0000; /* Dest key in dst surface */
610 lpData[2] = 0x00001100; /* Dest key in override */
611 lpData[3] = 0x00001100; /* Dest key in override */
612 lpData[4] = 0x00000000; /* Dest key in src surface */
613 lpData[5] = 0x00000000; /* Dest key in src surface */
614 rc = IDirectDrawSurface_Unlock(lpDst, NULL);
615 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
617 /* Dest override key blit */
618 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYDESTOVERRIDE, &fx);
619 ok(rc == DD_OK, "IDirectDrawSurface_Blt returned %08x\n", rc);
621 rc = IDirectDrawSurface_Lock(lpDst, NULL, &ddsd2, DDLOCK_WAIT, NULL);
622 ok(rc==DD_OK,"Lock returned: %x\n",rc);
623 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
624 lpData = ddsd2.lpSurface;
626 ok(lpData[0] == 0x00FF0000 &&
627 lpData[1] == 0x00FF0000 &&
628 lpData[2] == 0x00FF0000 && /* Key applies here */
629 lpData[3] == 0x0000FF00 && /* Key applies here */
630 lpData[4] == 0x00000000 &&
631 lpData[5] == 0x00000000,
632 "Surface data after dest key override blit does not match\n");
634 lpData[0] = 0x00FF0000; /* Dest key in dst surface */
635 lpData[1] = 0x00FF0000; /* Dest key in dst surface */
636 lpData[2] = 0x00001100; /* Dest key in override */
637 lpData[3] = 0x00001100; /* Dest key in override */
638 lpData[4] = 0x00000000; /* Dest key in src surface */
639 lpData[5] = 0x00000000; /* Dest key in src surface */
640 rc = IDirectDrawSurface_Unlock(lpDst, NULL);
641 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
643 /* Dest override key blit. Supposed to fail too */
644 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYDEST | DDBLT_KEYDESTOVERRIDE, &fx);
645 ok(rc == DDERR_INVALIDPARAMS, "IDirectDrawSurface_Blt returned %08x\n", rc);
647 /* Check for unchanged data */
648 rc = IDirectDrawSurface_Lock(lpDst, NULL, &ddsd2, DDLOCK_WAIT, NULL);
649 ok(rc==DD_OK,"Lock returned: %x\n",rc);
650 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
651 lpData = ddsd2.lpSurface;
653 ok(lpData[0] == 0x00FF0000 &&
654 lpData[1] == 0x00FF0000 &&
655 lpData[2] == 0x00001100 && /* Key applies here */
656 lpData[3] == 0x00001100 && /* Key applies here */
657 lpData[4] == 0x00000000 &&
658 lpData[5] == 0x00000000,
659 "Surface data with dest key and dest override does not match\n");
661 lpData[0] = 0x00FF0000; /* Dest key in dst surface */
662 lpData[1] = 0x00FF0000; /* Dest key in dst surface */
663 lpData[2] = 0x00001100; /* Dest key in override */
664 lpData[3] = 0x00001100; /* Dest key in override */
665 lpData[4] = 0x00000000; /* Dest key in src surface */
666 lpData[5] = 0x00000000; /* Dest key in src surface */
667 rc = IDirectDrawSurface_Unlock(lpDst, NULL);
668 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
670 /* Modify the source data a bit to give some more conclusive results */
671 rc = IDirectDrawSurface_Lock(lpSrc, NULL, &ddsd2, DDLOCK_WAIT, NULL);
672 ok(rc==DD_OK,"Lock returned: %x\n",rc);
673 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
674 lpData = ddsd2.lpSurface;
675 lpData[5] = 0x000000FF; /* Applies to src blt key in src surface */
676 rc = IDirectDrawSurface_Unlock(lpSrc, NULL);
677 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
679 /* Source and destination key */
680 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYDEST | DDBLT_KEYSRC, &fx);
681 ok(rc == DD_OK, "IDirectDrawSurface_Blt returned %08x\n", rc);
683 rc = IDirectDrawSurface_Lock(lpDst, NULL, &ddsd2, DDLOCK_WAIT, NULL);
684 ok(rc==DD_OK,"Lock returned: %x\n",rc);
685 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
686 lpData = ddsd2.lpSurface;
688 ok(lpData[0] == 0x00FF0000 && /* Masked by Destination key */
689 lpData[1] == 0x00FF0000 && /* Masked by Destination key */
690 lpData[2] == 0x00001100 && /* Masked by Destination key */
691 lpData[3] == 0x00001100 && /* Masked by Destination key */
692 lpData[4] == 0x00001100 && /* Allowed by destination key, not masked by source key */
693 lpData[5] == 0x00000000, /* Allowed by dst key, but masked by source key */
694 "Surface data with src key and dest key blit does not match\n");
696 lpData[0] = 0x00FF0000; /* Dest key in dst surface */
697 lpData[1] = 0x00FF0000; /* Dest key in dst surface */
698 lpData[2] = 0x00001100; /* Dest key in override */
699 lpData[3] = 0x00001100; /* Dest key in override */
700 lpData[4] = 0x00000000; /* Dest key in src surface */
701 lpData[5] = 0x00000000; /* Dest key in src surface */
702 rc = IDirectDrawSurface_Unlock(lpDst, NULL);
703 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
705 /* Override keys without ddbltfx parameter fail */
706 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYDESTOVERRIDE, NULL);
707 ok(rc == DDERR_INVALIDPARAMS, "IDirectDrawSurface_Blt returned %08x\n", rc);
708 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYSRCOVERRIDE, NULL);
709 ok(rc == DDERR_INVALIDPARAMS, "IDirectDrawSurface_Blt returned %08x\n", rc);
711 /* Try blitting without keys in the source surface*/
712 rc = IDirectDrawSurface_SetColorKey(lpSrc, DDCKEY_SRCBLT, NULL);
713 ok(rc == DD_OK, "SetColorKey returned %x\n", rc);
714 rc = IDirectDrawSurface_SetColorKey(lpSrc, DDCKEY_DESTBLT, NULL);
715 ok(rc == DD_OK, "SetColorKey returned %x\n", rc);
717 /* That fails now. Do not bother to check that the data is unmodified */
718 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYSRC, &fx);
719 ok(rc == DDERR_INVALIDPARAMS, "IDirectDrawSurface_Blt returned %08x\n", rc);
721 /* Dest key blit still works. Which key is used this time??? */
722 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYDEST, &fx);
723 ok(rc == DD_OK, "IDirectDrawSurface_Blt returned %08x\n", rc);
725 /* With correctly passed override keys no key in the surface is needed.
726 * Again, the result was checked before, no need to do that again
728 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYDESTOVERRIDE, &fx);
729 ok(rc == DD_OK, "IDirectDrawSurface_Blt returned %08x\n", rc);
730 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYSRCOVERRIDE, &fx);
731 ok(rc == DD_OK, "IDirectDrawSurface_Blt returned %08x\n", rc);
733 IDirectDrawSurface_Release(lpSrc);
734 IDirectDrawSurface_Release(lpDst);
737 static void QueryInterface(void)
739 LPDIRECTDRAWSURFACE dsurface;
740 DDSURFACEDESC surface;
744 /* Create a surface */
745 ZeroMemory(&surface, sizeof(surface));
746 surface.dwSize = sizeof(surface);
747 surface.dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
748 surface.dwHeight = 10;
749 surface.dwWidth = 10;
750 ret = IDirectDraw_CreateSurface(lpDD, &surface, &dsurface, NULL);
753 ok(FALSE, "IDirectDraw::CreateSurface failed with error %x\n", ret);
757 /* Call IUnknown::QueryInterface */
758 ret = IDirectDrawSurface_QueryInterface(dsurface, 0, &object);
759 ok(ret == DDERR_INVALIDPARAMS, "IDirectDrawSurface::QueryInterface returned %x\n", ret);
761 IDirectDrawSurface_Release(dsurface);
764 /* The following tests test which interface is returned by IDirectDrawSurfaceX::GetDDInterface.
765 * It uses refcounts to test that and compares the interface addresses. Partially fits here, and
766 * partially in the refcount test
769 static ULONG getref(IUnknown *iface)
771 IUnknown_AddRef(iface);
772 return IUnknown_Release(iface);
775 static void GetDDInterface_1(void)
777 LPDIRECTDRAWSURFACE dsurface;
778 LPDIRECTDRAWSURFACE2 dsurface2;
779 DDSURFACEDESC surface;
784 ULONG ref1, ref2, ref4, ref7;
787 /* Create a surface */
788 ZeroMemory(&surface, sizeof(surface));
789 surface.dwSize = sizeof(surface);
790 surface.dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
791 surface.dwHeight = 10;
792 surface.dwWidth = 10;
793 ret = IDirectDraw_CreateSurface(lpDD, &surface, &dsurface, NULL);
796 ok(FALSE, "IDirectDraw::CreateSurface failed with error %x\n", ret);
799 ret = IDirectDrawSurface_QueryInterface(dsurface, &IID_IDirectDrawSurface2, (void **) &dsurface2);
800 ok(ret == DD_OK, "IDirectDrawSurface_QueryInterface returned %08x\n", ret);
801 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw2, (void **) &dd2);
802 ok(ret == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", ret);
803 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw4, (void **) &dd4);
804 ok(ret == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", ret);
805 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
806 ok(ret == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", ret);
808 ref1 = getref((IUnknown *) lpDD);
809 ok(ref1 == 1, "IDirectDraw refcount is %d\n", ref1);
810 ref2 = getref((IUnknown *) dd2);
811 ok(ref2 == 1, "IDirectDraw2 refcount is %d\n", ref2);
812 ref4 = getref((IUnknown *) dd4);
813 ok(ref4 == 1, "IDirectDraw4 refcount is %d\n", ref4);
814 ref7 = getref((IUnknown *) dd7);
815 ok(ref7 == 1, "IDirectDraw7 refcount is %d\n", ref7);
818 ret = IDirectDrawSurface2_GetDDInterface(dsurface2, &dd);
819 ok(ret == DD_OK, "IDirectDrawSurface7_GetDDInterface returned %08x\n", ret);
820 ok(getref((IUnknown *) lpDD) == ref1 + 1, "IDirectDraw refcount was increased by %d\n", getref((IUnknown *) lpDD) - ref1);
821 ok(getref((IUnknown *) dd2) == ref2 + 0, "IDirectDraw2 refcount was increased by %d\n", getref((IUnknown *) dd2) - ref2);
822 ok(getref((IUnknown *) dd4) == ref4 + 0, "IDirectDraw4 refcount was increased by %d\n", getref((IUnknown *) dd4) - ref4);
823 ok(getref((IUnknown *) dd7) == ref7 + 0, "IDirectDraw7 refcount was increased by %d\n", getref((IUnknown *) dd7) - ref7);
825 ok(dd == lpDD, "Returned interface pointer is not equal to the creation interface\n");
826 IUnknown_Release((IUnknown *) dd);
828 /* try a NULL pointer */
829 ret = IDirectDrawSurface2_GetDDInterface(dsurface2, NULL);
830 ok(ret == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_GetDDInterface returned %08x\n", ret);
832 IDirectDraw_Release(dd2);
833 IDirectDraw_Release(dd4);
834 IDirectDraw_Release(dd7);
835 IDirectDrawSurface2_Release(dsurface2);
836 IDirectDrawSurface_Release(dsurface);
839 static void GetDDInterface_2(void)
841 LPDIRECTDRAWSURFACE dsurface;
842 LPDIRECTDRAWSURFACE2 dsurface2;
843 DDSURFACEDESC surface;
848 ULONG ref1, ref2, ref4, ref7;
851 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw2, (void **) &dd2);
852 ok(ret == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", ret);
853 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw4, (void **) &dd4);
854 ok(ret == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", ret);
855 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
856 ok(ret == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", ret);
858 /* Create a surface */
859 ZeroMemory(&surface, sizeof(surface));
860 surface.dwSize = sizeof(surface);
861 surface.dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
862 surface.dwHeight = 10;
863 surface.dwWidth = 10;
864 ret = IDirectDraw2_CreateSurface(dd2, &surface, &dsurface, NULL);
867 ok(FALSE, "IDirectDraw::CreateSurface failed with error %x\n", ret);
870 ret = IDirectDrawSurface_QueryInterface(dsurface, &IID_IDirectDrawSurface2, (void **) &dsurface2);
871 ok(ret == DD_OK, "IDirectDrawSurface_QueryInterface returned %08x\n", ret);
873 ref1 = getref((IUnknown *) lpDD);
874 ok(ref1 == 1, "IDirectDraw refcount is %d\n", ref1);
875 ref2 = getref((IUnknown *) dd2);
876 ok(ref2 == 1, "IDirectDraw2 refcount is %d\n", ref2);
877 ref4 = getref((IUnknown *) dd4);
878 ok(ref4 == 1, "IDirectDraw4 refcount is %d\n", ref4);
879 ref7 = getref((IUnknown *) dd7);
880 ok(ref7 == 1, "IDirectDraw7 refcount is %d\n", ref7);
883 ret = IDirectDrawSurface2_GetDDInterface(dsurface2, &dd);
884 ok(ret == DD_OK, "IDirectDrawSurface7_GetDDInterface returned %08x\n", ret);
885 ok(getref((IUnknown *) lpDD) == ref1 + 0, "IDirectDraw refcount was increased by %d\n", getref((IUnknown *) lpDD) - ref1);
886 ok(getref((IUnknown *) dd2) == ref2 + 1, "IDirectDraw2 refcount was increased by %d\n", getref((IUnknown *) dd2) - ref2);
887 ok(getref((IUnknown *) dd4) == ref4 + 0, "IDirectDraw4 refcount was increased by %d\n", getref((IUnknown *) dd4) - ref4);
888 ok(getref((IUnknown *) dd7) == ref7 + 0, "IDirectDraw7 refcount was increased by %d\n", getref((IUnknown *) dd7) - ref7);
890 ok(dd == dd2, "Returned interface pointer is not equal to the creation interface\n");
891 IUnknown_Release((IUnknown *) dd);
893 IDirectDraw_Release(dd2);
894 IDirectDraw_Release(dd4);
895 IDirectDraw_Release(dd7);
896 IDirectDrawSurface2_Release(dsurface2);
897 IDirectDrawSurface_Release(dsurface);
900 static void GetDDInterface_4(void)
902 LPDIRECTDRAWSURFACE2 dsurface2;
903 LPDIRECTDRAWSURFACE4 dsurface4;
904 DDSURFACEDESC2 surface;
909 ULONG ref1, ref2, ref4, ref7;
912 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw2, (void **) &dd2);
913 ok(ret == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", ret);
914 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw4, (void **) &dd4);
915 ok(ret == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", ret);
916 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
917 ok(ret == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", ret);
919 /* Create a surface */
920 ZeroMemory(&surface, sizeof(surface));
921 surface.dwSize = sizeof(surface);
922 surface.dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
923 surface.dwHeight = 10;
924 surface.dwWidth = 10;
925 ret = IDirectDraw4_CreateSurface(dd4, &surface, &dsurface4, NULL);
928 ok(FALSE, "IDirectDraw::CreateSurface failed with error %x\n", ret);
931 ret = IDirectDrawSurface4_QueryInterface(dsurface4, &IID_IDirectDrawSurface2, (void **) &dsurface2);
932 ok(ret == DD_OK, "IDirectDrawSurface_QueryInterface returned %08x\n", ret);
934 ref1 = getref((IUnknown *) lpDD);
935 ok(ref1 == 1, "IDirectDraw refcount is %d\n", ref1);
936 ref2 = getref((IUnknown *) dd2);
937 ok(ref2 == 1, "IDirectDraw2 refcount is %d\n", ref2);
938 ref4 = getref((IUnknown *) dd4);
939 ok(ref4 == 2, "IDirectDraw4 refcount is %d\n", ref4);
940 ref7 = getref((IUnknown *) dd7);
941 ok(ref7 == 1, "IDirectDraw7 refcount is %d\n", ref7);
943 ret = IDirectDrawSurface4_GetDDInterface(dsurface4, &dd);
944 ok(ret == DD_OK, "IDirectDrawSurface7_GetDDInterface returned %08x\n", ret);
945 ok(getref((IUnknown *) lpDD) == ref1 + 0, "IDirectDraw refcount was increased by %d\n", getref((IUnknown *) lpDD) - ref1);
946 ok(getref((IUnknown *) dd2) == ref2 + 0, "IDirectDraw2 refcount was increased by %d\n", getref((IUnknown *) dd2) - ref2);
947 ok(getref((IUnknown *) dd4) == ref4 + 1, "IDirectDraw4 refcount was increased by %d\n", getref((IUnknown *) dd4) - ref4);
948 ok(getref((IUnknown *) dd7) == ref7 + 0, "IDirectDraw7 refcount was increased by %d\n", getref((IUnknown *) dd7) - ref7);
950 ok(dd == dd4, "Returned interface pointer is not equal to the creation interface\n");
951 IUnknown_Release((IUnknown *) dd);
953 /* Now test what happens if we QI the surface for some other version - It should still return the creation interface */
954 ret = IDirectDrawSurface2_GetDDInterface(dsurface2, &dd);
955 ok(ret == DD_OK, "IDirectDrawSurface7_GetDDInterface returned %08x\n", ret);
956 ok(getref((IUnknown *) lpDD) == ref1 + 0, "IDirectDraw refcount was increased by %d\n", getref((IUnknown *) lpDD) - ref1);
957 ok(getref((IUnknown *) dd2) == ref2 + 0, "IDirectDraw2 refcount was increased by %d\n", getref((IUnknown *) dd2) - ref2);
958 ok(getref((IUnknown *) dd4) == ref4 + 1, "IDirectDraw4 refcount was increased by %d\n", getref((IUnknown *) dd4) - ref4);
959 ok(getref((IUnknown *) dd7) == ref7 + 0, "IDirectDraw7 refcount was increased by %d\n", getref((IUnknown *) dd7) - ref7);
961 ok(dd == dd4, "Returned interface pointer is not equal to the creation interface\n");
962 IUnknown_Release((IUnknown *) dd);
964 IDirectDraw_Release(dd2);
965 IDirectDraw_Release(dd4);
966 IDirectDraw_Release(dd7);
967 IDirectDrawSurface4_Release(dsurface4);
968 IDirectDrawSurface2_Release(dsurface2);
971 static void GetDDInterface_7(void)
973 LPDIRECTDRAWSURFACE4 dsurface4;
974 LPDIRECTDRAWSURFACE7 dsurface7;
975 DDSURFACEDESC2 surface;
980 ULONG ref1, ref2, ref4, ref7;
983 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw2, (void **) &dd2);
984 ok(ret == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", ret);
985 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw4, (void **) &dd4);
986 ok(ret == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", ret);
987 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
988 ok(ret == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", ret);
990 /* Create a surface */
991 ZeroMemory(&surface, sizeof(surface));
992 surface.dwSize = sizeof(surface);
993 surface.dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
994 surface.dwHeight = 10;
995 surface.dwWidth = 10;
996 ret = IDirectDraw7_CreateSurface(dd7, &surface, &dsurface7, NULL);
999 ok(FALSE, "IDirectDraw::CreateSurface failed with error %x\n", ret);
1002 ret = IDirectDrawSurface7_QueryInterface(dsurface7, &IID_IDirectDrawSurface4, (void **) &dsurface4);
1003 ok(ret == DD_OK, "IDirectDrawSurface_QueryInterface returned %08x\n", ret);
1005 ref1 = getref((IUnknown *) lpDD);
1006 ok(ref1 == 1, "IDirectDraw refcount is %d\n", ref1);
1007 ref2 = getref((IUnknown *) dd2);
1008 ok(ref2 == 1, "IDirectDraw2 refcount is %d\n", ref2);
1009 ref4 = getref((IUnknown *) dd4);
1010 ok(ref4 == 1, "IDirectDraw4 refcount is %d\n", ref4);
1011 ref7 = getref((IUnknown *) dd7);
1012 ok(ref7 == 2, "IDirectDraw7 refcount is %d\n", ref7);
1014 ret = IDirectDrawSurface7_GetDDInterface(dsurface7, &dd);
1015 ok(ret == DD_OK, "IDirectDrawSurface7_GetDDInterface returned %08x\n", ret);
1016 ok(getref((IUnknown *) lpDD) == ref1 + 0, "IDirectDraw refcount was increased by %d\n", getref((IUnknown *) lpDD) - ref1);
1017 ok(getref((IUnknown *) dd2) == ref2 + 0, "IDirectDraw2 refcount was increased by %d\n", getref((IUnknown *) dd2) - ref2);
1018 ok(getref((IUnknown *) dd4) == ref4 + 0, "IDirectDraw4 refcount was increased by %d\n", getref((IUnknown *) dd4) - ref4);
1019 ok(getref((IUnknown *) dd7) == ref7 + 1, "IDirectDraw7 refcount was increased by %d\n", getref((IUnknown *) dd7) - ref7);
1021 ok(dd == dd7, "Returned interface pointer is not equal to the creation interface\n");
1022 IUnknown_Release((IUnknown *) dd);
1024 /* Now test what happens if we QI the surface for some other version - It should still return the creation interface */
1025 ret = IDirectDrawSurface4_GetDDInterface(dsurface4, &dd);
1026 ok(ret == DD_OK, "IDirectDrawSurface7_GetDDInterface returned %08x\n", ret);
1027 ok(getref((IUnknown *) lpDD) == ref1 + 0, "IDirectDraw refcount was increased by %d\n", getref((IUnknown *) lpDD) - ref1);
1028 ok(getref((IUnknown *) dd2) == ref2 + 0, "IDirectDraw2 refcount was increased by %d\n", getref((IUnknown *) dd2) - ref2);
1029 ok(getref((IUnknown *) dd4) == ref4 + 0, "IDirectDraw4 refcount was increased by %d\n", getref((IUnknown *) dd4) - ref4);
1030 ok(getref((IUnknown *) dd7) == ref7 + 1, "IDirectDraw7 refcount was increased by %d\n", getref((IUnknown *) dd7) - ref7);
1032 ok(dd == dd7, "Returned interface pointer is not equal to the creation interface\n");
1033 IUnknown_Release((IUnknown *) dd);
1035 IDirectDraw_Release(dd2);
1036 IDirectDraw_Release(dd4);
1037 IDirectDraw_Release(dd7);
1038 IDirectDrawSurface4_Release(dsurface4);
1039 IDirectDrawSurface7_Release(dsurface7);
1042 static ULONG getRefcount(IUnknown *iface)
1044 IUnknown_AddRef(iface);
1045 return IUnknown_Release(iface);
1048 static void IFaceRefCount(void)
1050 LPDIRECTDRAWSURFACE surf;
1051 DDSURFACEDESC surface;
1053 IDirectDrawSurface2 *surf2;
1054 IDirectDrawSurface2 *surf2a;
1055 IDirectDrawSurface3 *surf3;
1056 IDirectDrawSurface4 *surf4;
1057 IDirectDrawSurface7 *surf7a;
1058 IDirectDrawSurface7 *surf7b;
1059 IDirect3DTexture* tex;
1060 IDirect3DTexture2* tex2;
1061 IDirectDrawGammaControl* gamma;
1064 /* Create a surface */
1065 ZeroMemory(&surface, sizeof(surface));
1066 surface.dwSize = sizeof(surface);
1067 surface.dwFlags = DDSD_CAPS;
1068 surface.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
1069 ret = IDirectDraw_CreateSurface(lpDD, &surface, &surf, NULL);
1073 ok(FALSE, "Could not create surface, skipping test\n");
1077 ref = getRefcount((IUnknown *) surf);
1078 ok(ref == 1, "Refcount is %u, expected 1\n", ref); /* Check the ref count is one */
1080 IDirectDrawSurface_QueryInterface(surf, &IID_IDirectDrawSurface2, (void **) &surf2);
1081 ref = getRefcount((IUnknown *) surf);
1082 ok(ref == 1, "Refcount is %u, expected 1\n", ref); /* Check the ref count is one */
1083 ref = getRefcount((IUnknown *) surf2);
1084 ok(ref == 1, "Refcount is %u, expected 1\n", ref); /* This should also be one */
1086 IDirectDrawSurface_QueryInterface(surf, &IID_IDirectDrawSurface2, (void **) &surf2a);
1087 ref = getRefcount((IUnknown *) surf2);
1088 ok(ref == 2, "Refcount is %u, expected 2\n", ref); /* Surf2's refcount should be 2 now, but surf should be 1 */
1089 ref = getRefcount((IUnknown *) surf);
1090 ok(ref == 1, "Refcount is %u, expected 1\n", ref);
1092 IDirectDrawSurface_QueryInterface(surf, &IID_IDirectDrawSurface3, (void **) &surf3);
1093 ref = getRefcount((IUnknown *) surf3);
1094 ok(ref == 1, "Refcount is %u, expected 1\n", ref);
1096 IDirectDrawSurface_QueryInterface(surf, &IID_IDirectDrawSurface4, (void **) &surf4);
1097 ref = getRefcount((IUnknown *) surf4);
1098 ok(ref == 1, "Refcount is %u, expected 1\n", ref);
1100 IDirectDrawSurface_QueryInterface(surf, &IID_IDirectDrawSurface7, (void **) &surf7a);
1101 ref = getRefcount((IUnknown *) surf7a);
1102 ok(ref == 1, "Refcount is %u, expected 1\n", ref);
1104 IDirectDrawSurface_QueryInterface(surf, &IID_IDirectDrawSurface7, (void **) &surf7b);
1105 ref = getRefcount((IUnknown *) surf7b);
1106 ok(ref == 2, "Refcount is %u, expected 2\n", ref);
1108 /* IDirect3DTexture interface (unlike the others) alters the original IDirectDrawSurface ref count */
1109 ret = IDirectDrawSurface_QueryInterface(surf, &IID_IDirect3DTexture, (void **) &tex);
1112 ref = getRefcount((IUnknown *) tex);
1113 ok(ref == 2, "Refcount is %u, expected 2\n", ref);
1114 ref = getRefcount((IUnknown *) surf);
1115 ok(ref == 2, "Refcount is %u, expected 2\n", ref);
1117 IDirectDrawSurface_QueryInterface(surf, &IID_IDirect3DTexture2, (void **) &tex2);
1118 ref = getRefcount((IUnknown *) tex);
1119 ok(ref == 3, "Refcount is %u, expected 3\n", ref);
1120 ref = getRefcount((IUnknown *) tex2);
1121 ok(ref == 3, "Refcount is %u, expected 3\n", ref);
1122 ref = getRefcount((IUnknown *) surf);
1123 ok(ref == 3, "Refcount is %u, expected 3\n", ref);
1125 IDirectDrawSurface_QueryInterface(surf, &IID_IDirectDrawGammaControl, (void **) &gamma);
1126 ref = getRefcount((IUnknown *) gamma);
1127 ok(ref == 1, "Refcount is %u, expected 1\n", ref);
1129 ref = IDirect3DTexture2_Release(tex2); /* Release the texture */
1130 ok(ref == 2, "Refcount is %u, expected 2\n", ref);
1131 ref = getRefcount((IUnknown *) surf);
1132 ok(ref == 2, "Refcount is %u, expected 2\n", ref);
1134 ref = IDirect3DTexture_Release(tex); /* Release the texture */
1135 ok(ref == 1, "Refcount is %u, expected 1\n", ref);
1136 ref = getRefcount((IUnknown *) surf);
1137 ok(ref == 1, "Refcount is %u, expected 1\n", ref);
1139 ref = IDirectDrawGammaControl_Release(gamma); /* Release the gamma control */
1140 ok(ref == 0, "Refcount is %u, expected 0\n", ref);
1143 ref = IDirectDrawSurface2_Release(surf2); /* Release one of the 2 surf2 interfaces */
1144 ok(ref == 1, "Refcount is %u, expected 1\n", ref);
1146 ref = IDirectDrawSurface2_Release(surf2a); /* Release the other */
1147 ok(ref == 0, "Refcount is %u, expected 0\n", ref);
1149 ref = IDirectDrawSurface3_Release(surf3);
1150 ok(ref == 0, "Refcount is %u, expected 0\n", ref);
1152 ref = IDirectDrawSurface4_Release(surf4);
1153 ok(ref == 0, "Refcount is %u, expected 0\n", ref);
1155 ref = IDirectDrawSurface7_Release(surf7a);
1156 ok(ref == 1, "Refcount is %u, expected 1\n", ref);
1158 ref = IDirectDrawSurface7_Release(surf7b);
1159 ok(ref == 0, "Refcount is %u, expected 0\n", ref);
1161 ref = IDirectDrawSurface_Release(surf);
1162 ok(ref == 0, "Refcount is %u, expected 0\n", ref);
1165 #define MAXEXPECTED 8 /* Can match up to 8 expected surfaces */
1168 IDirectDrawSurface *expected[MAXEXPECTED];
1172 static HRESULT WINAPI enumCB(IDirectDrawSurface *surf, DDSURFACEDESC *desc, void *ctx)
1177 for(i = 0; i < MAXEXPECTED; i++)
1179 if(((struct enumstruct *)ctx)->expected[i] == surf) found = TRUE;
1182 ok(found, "Unexpected surface %p enumerated\n", surf);
1183 ((struct enumstruct *)ctx)->count++;
1184 IDirectDrawSurface_Release(surf);
1185 return DDENUMRET_OK;
1188 static void EnumTest(void)
1192 IDirectDrawSurface *surface;
1193 struct enumstruct ctx;
1195 ddsd.dwSize = sizeof(ddsd);
1196 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_MIPMAPCOUNT;
1197 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
1198 U2(ddsd).dwMipMapCount = 3;
1201 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface, NULL);
1202 ok(rc==DD_OK,"CreateSurface returned: %x\n",rc);
1204 memset(&ctx, 0, sizeof(ctx));
1205 ctx.expected[0] = surface;
1206 rc = IDirectDrawSurface_GetAttachedSurface(ctx.expected[0], &ddsd.ddsCaps, &ctx.expected[1]);
1207 ok(rc == DD_OK, "GetAttachedSurface returned %08x\n", rc);
1208 rc = IDirectDrawSurface_GetAttachedSurface(ctx.expected[1], &ddsd.ddsCaps, &ctx.expected[2]);
1209 ok(rc == DD_OK, "GetAttachedSurface returned %08x\n", rc);
1210 rc = IDirectDrawSurface_GetAttachedSurface(ctx.expected[2], &ddsd.ddsCaps, &ctx.expected[3]);
1211 ok(rc == DDERR_NOTFOUND, "GetAttachedSurface returned %08x\n", rc);
1212 ok(!ctx.expected[3], "expected NULL pointer\n");
1215 rc = IDirectDraw_EnumSurfaces(lpDD, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_ALL, &ddsd, &ctx, enumCB);
1216 ok(rc == DD_OK, "IDirectDraw_EnumSurfaces returned %08x\n", rc);
1217 ok(ctx.count == 3, "%d surfaces enumerated, expected 3\n", ctx.count);
1220 rc = IDirectDraw_EnumSurfaces(lpDD, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_ALL, NULL, &ctx, enumCB);
1221 ok(rc == DD_OK, "IDirectDraw_EnumSurfaces returned %08x\n", rc);
1222 ok(ctx.count == 3, "%d surfaces enumerated, expected 3\n", ctx.count);
1224 IDirectDrawSurface_Release(ctx.expected[2]);
1225 IDirectDrawSurface_Release(ctx.expected[1]);
1226 IDirectDrawSurface_Release(surface);
1229 static HRESULT WINAPI SurfaceCounter(IDirectDrawSurface7 *surface, DDSURFACEDESC2 *desc, void *context)
1231 UINT *num = context;
1233 IDirectDrawSurface_Release(surface);
1234 return DDENUMRET_OK;
1237 static void AttachmentTest7(void)
1241 IDirectDrawSurface7 *surface1, *surface2, *surface3, *surface4;
1242 DDSURFACEDESC2 ddsd, ddsd2;
1244 DDSCAPS2 caps = {DDSCAPS_TEXTURE, 0, 0, 0}, caps2 = {DDSCAPS_BACKBUFFER,0,0,0};
1245 HWND window = CreateWindow( "static", "ddraw_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
1247 hr = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
1248 ok(hr == DD_OK, "IDirectDraw_QueryInterface returned %08x\n", hr);
1250 memset(&ddsd, 0, sizeof(ddsd));
1251 ddsd.dwSize = sizeof(ddsd);
1252 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_MIPMAPCOUNT;
1253 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
1254 U2(ddsd).dwMipMapCount = 3; /* Will create 128x128, 64x64, 32x32 */
1256 ddsd.dwHeight = 128;
1257 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface1, NULL);
1258 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1262 IDirectDrawSurface7_EnumAttachedSurfaces(surface1, &num, SurfaceCounter);
1263 ok(num == 1, "Mipmap root has %d surfaces attached, expected 1\n", num);
1267 hr = IDirectDrawSurface7_GetAttachedSurface(surface1, &caps, &surface2);
1268 ok(hr == DD_OK, "GetAttachedSurface returned %08x\n", hr);
1270 IDirectDrawSurface7_EnumAttachedSurfaces(surface2, &num, SurfaceCounter);
1271 ok(num == 1, "First mip level has %d surfaces attached, expected 1\n", num);
1275 hr = IDirectDrawSurface7_GetAttachedSurface(surface2, &caps, &surface3);
1276 ok(hr == DD_OK, "GetAttachedSurface returned %08x\n", hr);
1277 IDirectDrawSurface7_Release(surface2);
1279 IDirectDrawSurface7_EnumAttachedSurfaces(surface3, &num, SurfaceCounter);
1280 ok(num == 0, "Second mip level has %d surfaces attached, expected 1\n", num);
1282 /* Mip level 3 is still needed */
1283 hr = IDirectDrawSurface7_GetAttachedSurface(surface3, &caps, &surface4);
1284 ok(hr == DDERR_NOTFOUND, "GetAttachedSurface returned %08x\n", hr);
1285 ok(!surface4, "expected NULL pointer\n");
1287 /* Try to attach a 16x16 miplevel - Should not work as far I can see */
1288 memset(&ddsd, 0, sizeof(ddsd));
1289 ddsd.dwSize = sizeof(ddsd);
1290 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1291 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1294 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface2, NULL);
1295 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1297 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface2);
1298 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 16x16 surface to a 128x128 texture root returned %08x\n", hr);
1299 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface1);
1300 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 128x128 texture root to a 16x16 texture returned %08x\n", hr);
1301 hr = IDirectDrawSurface7_AddAttachedSurface(surface3, surface2);
1302 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 16x16 surface to a 32x32 texture mip level returned %08x\n", hr);
1303 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface3);
1304 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 32x32 texture mip level to a 16x16 surface returned %08x\n", hr);
1306 IDirectDrawSurface7_Release(surface2);
1308 memset(&ddsd, 0, sizeof(ddsd));
1309 ddsd.dwSize = sizeof(ddsd);
1310 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1311 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
1314 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface2, NULL);
1315 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1317 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface2);
1318 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 16x16 offscreen plain surface to a 128x128 texture root returned %08x\n", hr);
1319 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface1);
1320 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 128x128 texture root to a 16x16 offscreen plain surface returned %08x\n", hr);
1321 hr = IDirectDrawSurface7_AddAttachedSurface(surface3, surface2);
1322 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 16x16 offscreen plain surface to a 32x32 texture mip level returned %08x\n", hr);
1323 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface3);
1324 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 32x32 texture mip level to a 16x16 offscreen plain surface returned %08x\n", hr);
1326 IDirectDrawSurface7_Release(surface3);
1327 IDirectDrawSurface7_Release(surface2);
1328 IDirectDrawSurface7_Release(surface1);
1330 hr = IDirectDraw7_SetCooperativeLevel(dd7, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
1331 ok(hr == DD_OK, "SetCooperativeLevel returned %08x\n", hr);
1333 memset(&ddsd, 0, sizeof(ddsd));
1334 ddsd.dwSize = sizeof(ddsd);
1335 ddsd.dwFlags = DDSD_BACKBUFFERCOUNT | DDSD_CAPS;
1336 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
1337 ddsd.dwBackBufferCount = 2;
1338 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface1, NULL);
1339 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1341 /* backbuffer surfaces must not have dwBackBufferCount set */
1342 ddsd2.dwSize = sizeof(ddsd2);
1343 hr = IDirectDrawSurface7_GetAttachedSurface(surface1, &caps2, &surface2);
1344 ok(hr==DD_OK,"GetAttachedSurface returned: %x\n", hr);
1345 hr = IDirectDrawSurface7_GetSurfaceDesc(surface2, &ddsd2);
1346 ok(hr==DD_OK,"GetSurfaceDesc returned: %x\n", hr);
1347 ok(ddsd2.dwBackBufferCount==0,"backbuffer surface has dwBackBufferCount==%u\n", ddsd2.dwBackBufferCount);
1350 IDirectDrawSurface7_EnumAttachedSurfaces(surface1, &num, SurfaceCounter);
1351 ok(num == 1, "Primary surface has %d surfaces attached, expected 1\n", num);
1352 IDirectDrawSurface7_Release(surface1);
1354 /* Those are some invalid descriptions, no need to test attachments with them */
1355 memset(&ddsd, 0, sizeof(ddsd));
1356 ddsd.dwSize = sizeof(ddsd);
1357 ddsd.dwFlags = DDSD_CAPS;
1358 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FRONTBUFFER;
1359 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface1, NULL);
1360 ok(hr==DDERR_INVALIDCAPS,"CreateSurface returned: %x\n",hr);
1361 memset(&ddsd, 0, sizeof(ddsd));
1362 ddsd.dwSize = sizeof(ddsd);
1363 ddsd.dwFlags = DDSD_CAPS;
1364 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_BACKBUFFER;
1365 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface2, NULL);
1366 ok(hr==DDERR_INVALIDCAPS,"CreateSurface returned: %x\n",hr);
1368 /* Try a single primary and two offscreen plain surfaces */
1369 memset(&ddsd, 0, sizeof(ddsd));
1370 ddsd.dwSize = sizeof(ddsd);
1371 ddsd.dwFlags = DDSD_CAPS;
1372 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
1373 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface1, NULL);
1374 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1376 memset(&ddsd, 0, sizeof(ddsd));
1377 ddsd.dwSize = sizeof(ddsd);
1378 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1379 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
1380 ddsd.dwWidth = GetSystemMetrics(SM_CXSCREEN);
1381 ddsd.dwHeight = GetSystemMetrics(SM_CYSCREEN);
1382 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface2, NULL);
1383 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1385 memset(&ddsd, 0, sizeof(ddsd));
1386 ddsd.dwSize = sizeof(ddsd);
1387 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1388 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
1389 ddsd.dwWidth = GetSystemMetrics(SM_CXSCREEN);
1390 ddsd.dwHeight = GetSystemMetrics(SM_CYSCREEN);
1391 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface3, NULL);
1392 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1394 /* This one has a different size */
1395 memset(&ddsd, 0, sizeof(ddsd));
1396 ddsd.dwSize = sizeof(ddsd);
1397 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1398 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
1400 ddsd.dwHeight = 128;
1401 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface4, NULL);
1402 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1404 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface2);
1405 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching an offscreen plain surface to a front buffer returned %08x\n", hr);
1406 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface1);
1407 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a front buffer to an offscreen plain surface returned %08x\n", hr);
1408 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface3);
1409 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching an offscreen plain surface to another offscreen plain surface returned %08x\n", hr);
1410 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface4);
1411 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching an offscreen plain surface to a front buffer of different size returned %08x\n", hr);
1412 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface1);
1413 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a front buffer to an offscreen plain surface of different size returned %08x\n", hr);
1415 IDirectDrawSurface7_Release(surface4);
1416 IDirectDrawSurface7_Release(surface3);
1417 IDirectDrawSurface7_Release(surface2);
1418 IDirectDrawSurface7_Release(surface1);
1420 hr =IDirectDraw7_SetCooperativeLevel(dd7, NULL, DDSCL_NORMAL);
1421 ok(hr == DD_OK, "SetCooperativeLevel returned %08x\n", hr);
1422 IDirectDraw7_Release(dd7);
1425 static void AttachmentTest(void)
1428 IDirectDrawSurface *surface1, *surface2, *surface3, *surface4;
1430 DDSCAPS caps = {DDSCAPS_TEXTURE};
1431 BOOL refrast = FALSE;
1432 HWND window = CreateWindow( "static", "ddraw_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
1434 memset(&ddsd, 0, sizeof(ddsd));
1435 ddsd.dwSize = sizeof(ddsd);
1436 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_MIPMAPCOUNT;
1437 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
1438 U2(ddsd).dwMipMapCount = 3; /* Will create 128x128, 64x64, 32x32 */
1440 ddsd.dwHeight = 128;
1441 hr = IDirectDraw7_CreateSurface(lpDD, &ddsd, &surface1, NULL);
1442 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1444 hr = IDirectDrawSurface7_GetAttachedSurface(surface1, &caps, &surface2);
1445 ok(hr == DD_OK, "GetAttachedSurface returned %08x\n", hr);
1446 hr = IDirectDrawSurface7_GetAttachedSurface(surface2, &caps, &surface3);
1447 ok(hr == DD_OK, "GetAttachedSurface returned %08x\n", hr);
1449 /* Try to attach a 16x16 miplevel - Should not work as far I can see */
1450 memset(&ddsd, 0, sizeof(ddsd));
1451 ddsd.dwSize = sizeof(ddsd);
1452 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1453 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1456 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface4, NULL);
1457 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1459 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface4);
1460 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 16x16 surface to a 128x128 texture root returned %08x\n", hr);
1461 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface1);
1462 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 128x128 texture root to a 16x16 texture returned %08x\n", hr);
1463 hr = IDirectDrawSurface7_AddAttachedSurface(surface3, surface4);
1464 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 16x16 surface to a 32x32 texture mip level returned %08x\n", hr);
1465 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface3);
1466 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 32x32 texture mip level to a 16x16 surface returned %08x\n", hr);
1467 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface4);
1468 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 16x16 surface to a 64x64 texture sublevel returned %08x\n", hr);
1469 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface2);
1470 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 64x64 texture sublevel to a 16x16 texture returned %08x\n", hr);
1472 IDirectDrawSurface7_Release(surface4);
1474 memset(&ddsd, 0, sizeof(ddsd));
1475 ddsd.dwSize = sizeof(ddsd);
1476 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1477 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
1480 hr = IDirectDraw7_CreateSurface(lpDD, &ddsd, &surface4, NULL);
1481 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1483 if (SUCCEEDED(IDirectDrawSurface7_AddAttachedSurface(surface1, surface4)))
1485 IDirectDrawSurface7_DeleteAttachedSurface(surface1, 0, surface4);
1489 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface4); /* Succeeds on refrast */
1491 ok(hr == S_OK, "Attaching a 16x16 offscreen plain surface to a 128x128 texture root returned %08x\n", hr);
1493 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 16x16 offscreen plain surface to a 128x128 texture root returned %08x\n", hr);
1494 if(SUCCEEDED(hr)) IDirectDrawSurface7_DeleteAttachedSurface(surface1, 0, surface4);
1496 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface1); /* Succeeds on refrast */
1498 ok(hr == S_OK, "Attaching a 128x128 texture root to a 16x16 offscreen plain surface returned %08x\n", hr);
1500 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 128x128 texture root to a 16x16 offscreen plain surface returned %08x\n", hr);
1501 if(SUCCEEDED(hr)) IDirectDrawSurface7_DeleteAttachedSurface(surface1, 0, surface1);
1503 hr = IDirectDrawSurface7_AddAttachedSurface(surface3, surface4); /* Succeeds on refrast */
1505 ok(hr == S_OK, "Attaching a 16x16 offscreen plain surface to a 32x32 texture mip level returned %08x\n", hr);
1507 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 16x16 offscreen plain surface to a 32x32 texture mip level returned %08x\n", hr);
1508 if(SUCCEEDED(hr)) IDirectDrawSurface7_DeleteAttachedSurface(surface3, 0, surface4);
1510 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface3);
1511 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 32x32 texture mip level to a 16x16 offscreen plain surface returned %08x\n", hr);
1512 if(SUCCEEDED(hr)) IDirectDrawSurface7_DeleteAttachedSurface(surface4, 0, surface3);
1514 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface4); /* Succeeds on refrast */
1516 ok(hr == S_OK, "Attaching a 16x16 offscreen plain surface to a 64x64 texture sublevel returned %08x\n", hr);
1518 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 16x16 offscreen plain surface to a 64x64 texture sublevel returned %08x\n", hr);
1519 if(SUCCEEDED(hr)) IDirectDrawSurface7_DeleteAttachedSurface(surface2, 0, surface4);
1521 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface2);
1522 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 64x64 texture sublevel to a 16x16 offscreen plain surface returned %08x\n", hr);
1523 if(SUCCEEDED(hr)) IDirectDrawSurface7_DeleteAttachedSurface(surface4, 0, surface2);
1525 IDirectDrawSurface7_Release(surface4);
1526 IDirectDrawSurface7_Release(surface3);
1527 IDirectDrawSurface7_Release(surface2);
1528 IDirectDrawSurface7_Release(surface1);
1530 hr = IDirectDraw_SetCooperativeLevel(lpDD, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
1531 ok(hr == DD_OK, "SetCooperativeLevel returned %08x\n", hr);
1533 /* Creating a back buffer as-is, is not allowed. No need to perform attachment tests */
1534 memset(&ddsd, 0, sizeof(ddsd));
1535 ddsd.dwSize = sizeof(ddsd);
1536 ddsd.dwFlags = DDSD_CAPS;
1537 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_BACKBUFFER;
1538 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface2, NULL);
1539 ok(hr==DDERR_INVALIDCAPS,"CreateSurface returned: %x\n",hr);
1540 /* This old ddraw version happily creates explicit front buffers */
1541 memset(&ddsd, 0, sizeof(ddsd));
1542 ddsd.dwSize = sizeof(ddsd);
1543 ddsd.dwFlags = DDSD_CAPS;
1544 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FRONTBUFFER;
1545 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface1, NULL);
1546 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1547 IDirectDrawSurface_Release(surface1);
1549 /* Try a single primary and two offscreen plain surfaces */
1550 memset(&ddsd, 0, sizeof(ddsd));
1551 ddsd.dwSize = sizeof(ddsd);
1552 ddsd.dwFlags = DDSD_CAPS;
1553 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
1554 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface1, NULL);
1555 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1557 memset(&ddsd, 0, sizeof(ddsd));
1558 ddsd.dwSize = sizeof(ddsd);
1559 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1560 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
1561 ddsd.dwWidth = GetSystemMetrics(SM_CXSCREEN);
1562 ddsd.dwHeight = GetSystemMetrics(SM_CYSCREEN);
1563 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface2, NULL);
1564 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1566 memset(&ddsd, 0, sizeof(ddsd));
1567 ddsd.dwSize = sizeof(ddsd);
1568 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1569 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
1570 ddsd.dwWidth = GetSystemMetrics(SM_CXSCREEN);
1571 ddsd.dwHeight = GetSystemMetrics(SM_CYSCREEN);
1572 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface3, NULL);
1573 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1575 /* This one has a different size */
1576 memset(&ddsd, 0, sizeof(ddsd));
1577 ddsd.dwSize = sizeof(ddsd);
1578 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1579 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
1581 ddsd.dwHeight = 128;
1582 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface4, NULL);
1583 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1585 hr = IDirectDrawSurface_AddAttachedSurface(surface1, surface2);
1586 ok(hr == DD_OK || broken(hr == DDERR_CANNOTATTACHSURFACE),
1587 "Attaching an offscreen plain surface to a front buffer returned %08x\n", hr);
1590 /* Try the reverse without detaching first */
1591 hr = IDirectDrawSurface_AddAttachedSurface(surface2, surface1);
1592 ok(hr == DDERR_SURFACEALREADYATTACHED, "Attaching an attached surface to its attachee returned %08x\n", hr);
1593 hr = IDirectDrawSurface_DeleteAttachedSurface(surface1, 0, surface2);
1594 ok(hr == DD_OK, "DeleteAttachedSurface failed with %08x\n", hr);
1596 hr = IDirectDrawSurface_AddAttachedSurface(surface2, surface1);
1597 ok(hr == DD_OK || broken(hr == DDERR_CANNOTATTACHSURFACE),
1598 "Attaching a front buffer to an offscreen plain surface returned %08x\n", hr);
1601 /* Try to detach reversed */
1602 hr = IDirectDrawSurface_DeleteAttachedSurface(surface1, 0, surface2);
1603 ok(hr == DDERR_CANNOTDETACHSURFACE, "DeleteAttachedSurface returned %08x\n", hr);
1604 /* Now the proper detach */
1605 hr = IDirectDrawSurface_DeleteAttachedSurface(surface2, 0, surface1);
1606 ok(hr == DD_OK, "DeleteAttachedSurface failed with %08x\n", hr);
1608 hr = IDirectDrawSurface_AddAttachedSurface(surface2, surface3); /* Fails on refrast */
1609 ok(hr == DD_OK || broken(hr == DDERR_CANNOTATTACHSURFACE),
1610 "Attaching an offscreen plain surface to another offscreen plain surface returned %08x\n", hr);
1613 hr = IDirectDrawSurface_DeleteAttachedSurface(surface2, 0, surface3);
1614 ok(hr == DD_OK, "DeleteAttachedSurface failed with %08x\n", hr);
1616 hr = IDirectDrawSurface_AddAttachedSurface(surface1, surface4);
1617 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching an offscreen plain surface to a front buffer of different size returned %08x\n", hr);
1618 hr = IDirectDrawSurface_AddAttachedSurface(surface4, surface1);
1619 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a front buffer to an offscreen plain surface of different size returned %08x\n", hr);
1621 IDirectDrawSurface_Release(surface4);
1622 IDirectDrawSurface_Release(surface3);
1623 IDirectDrawSurface_Release(surface2);
1624 IDirectDrawSurface_Release(surface1);
1626 hr =IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_NORMAL);
1627 ok(hr == DD_OK, "SetCooperativeLevel returned %08x\n", hr);
1629 DestroyWindow(window);
1634 DWORD width, height;
1639 static HRESULT WINAPI CubeTestPaletteEnum(IDirectDrawSurface7 *surface, DDSURFACEDESC2 *desc, void *context)
1643 hr = IDirectDrawSurface7_SetPalette(surface, context);
1644 if (desc->dwWidth == 64) /* This is for first mimpmap */
1645 ok(hr == DDERR_NOTONMIPMAPSUBLEVEL, "SetPalette returned: %x\n",hr);
1647 ok(hr == DD_OK, "SetPalette returned: %x\n",hr);
1649 IDirectDrawSurface7_Release(surface);
1651 return DDENUMRET_OK;
1654 static HRESULT WINAPI CubeTestLvl2Enum(IDirectDrawSurface7 *surface, DDSURFACEDESC2 *desc, void *context)
1656 UINT *mips = context;
1659 IDirectDrawSurface7_EnumAttachedSurfaces(surface,
1663 return DDENUMRET_OK;
1666 static HRESULT WINAPI CubeTestLvl1Enum(IDirectDrawSurface7 *surface, DDSURFACEDESC2 *desc, void *context)
1669 UINT *num = context;
1670 static const struct compare expected[] =
1674 DDSCAPS_MIPMAP | DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_COMPLEX,
1675 DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEZ,
1680 DDSCAPS_MIPMAP | DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_COMPLEX,
1681 DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEZ,
1686 DDSCAPS_MIPMAP | DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_COMPLEX,
1687 DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEY,
1692 DDSCAPS_MIPMAP | DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_COMPLEX,
1693 DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEY,
1698 DDSCAPS_MIPMAP | DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_COMPLEX,
1699 DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEX,
1703 64, 64, /* This is the first mipmap */
1704 DDSCAPS_MIPMAP | DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_COMPLEX,
1705 DDSCAPS2_MIPMAPSUBLEVEL | DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEX,
1711 IDirectDrawSurface7_EnumAttachedSurfaces(surface,
1715 ok(desc->dwWidth == expected[*num].width, "Surface width is %d expected %d\n", desc->dwWidth, expected[*num].width);
1716 ok(desc->dwHeight == expected[*num].height, "Surface height is %d expected %d\n", desc->dwHeight, expected[*num].height);
1717 ok(desc->ddsCaps.dwCaps == expected[*num].caps, "Surface caps are %08x expected %08x\n", desc->ddsCaps.dwCaps, expected[*num].caps);
1718 ok(desc->ddsCaps.dwCaps2 == expected[*num].caps2, "Surface caps2 are %08x expected %08x\n", desc->ddsCaps.dwCaps2, expected[*num].caps2);
1719 ok(mips == expected[*num].mips, "Surface has %d mipmaps, expected %d\n", mips, expected[*num].mips);
1723 IDirectDrawSurface7_Release(surface);
1725 return DDENUMRET_OK;
1728 static void CubeMapTest(void)
1730 IDirectDraw7 *dd7 = NULL;
1731 IDirectDrawSurface7 *cubemap = NULL;
1732 IDirectDrawPalette *palette = NULL;
1733 DDSURFACEDESC2 ddsd;
1735 PALETTEENTRY Table[256];
1739 struct enumstruct ctx;
1741 for(i=0; i<256; i++)
1743 Table[i].peRed = 0xff;
1744 Table[i].peGreen = 0;
1745 Table[i].peBlue = 0;
1746 Table[i].peFlags = 0;
1749 hr = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
1750 ok(hr == DD_OK, "IDirectDraw::QueryInterface returned %08x\n", hr);
1751 if (FAILED(hr)) goto err;
1753 memset(&ddsd, 0, sizeof(ddsd));
1754 ddsd.dwSize = sizeof(ddsd);
1755 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
1756 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS;
1758 ddsd.dwHeight = 128;
1759 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP | DDSCAPS_SYSTEMMEMORY;
1760 ddsd.ddsCaps.dwCaps2 = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES;
1763 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
1764 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 16;
1765 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0xF800;
1766 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x07E0;
1767 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x001F;
1769 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &cubemap, NULL);
1772 skip("Can't create cubemap surface\n");
1776 hr = IDirectDrawSurface7_GetSurfaceDesc(cubemap, &ddsd);
1777 ok(hr == DD_OK, "IDirectDrawSurface7_GetSurfaceDesc returned %08x\n", hr);
1778 ok(ddsd.ddsCaps.dwCaps == (DDSCAPS_MIPMAP | DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_COMPLEX),
1779 "Root Caps are %08x\n", ddsd.ddsCaps.dwCaps);
1780 ok(ddsd.ddsCaps.dwCaps2 == (DDSCAPS2_CUBEMAP_POSITIVEX | DDSCAPS2_CUBEMAP),
1781 "Root Caps2 are %08x\n", ddsd.ddsCaps.dwCaps2);
1783 IDirectDrawSurface7_EnumAttachedSurfaces(cubemap,
1786 ok(num == 6, "Surface has %d attachments\n", num);
1787 IDirectDrawSurface7_Release(cubemap);
1789 /* What happens if I do not specify any faces? */
1790 memset(&ddsd, 0, sizeof(ddsd));
1791 ddsd.dwSize = sizeof(ddsd);
1792 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
1793 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS;
1795 ddsd.dwHeight = 128;
1796 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP | DDSCAPS_SYSTEMMEMORY;
1797 ddsd.ddsCaps.dwCaps2 = DDSCAPS2_CUBEMAP;
1800 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
1801 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 16;
1802 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0xF800;
1803 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x07E0;
1804 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x001F;
1806 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &cubemap, NULL);
1807 ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw7::CreateSurface asking for a cube map without faces returned %08x\n", hr);
1809 /* Cube map faces without a cube map? */
1810 memset(&ddsd, 0, sizeof(ddsd));
1811 ddsd.dwSize = sizeof(ddsd);
1812 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
1813 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS;
1815 ddsd.dwHeight = 128;
1816 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP | DDSCAPS_SYSTEMMEMORY;
1817 ddsd.ddsCaps.dwCaps2 = DDSCAPS2_CUBEMAP_ALLFACES;
1820 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
1821 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 16;
1822 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0xF800;
1823 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x07E0;
1824 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x001F;
1826 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &cubemap, NULL);
1827 ok(hr == DDERR_INVALIDCAPS, "IDirectDraw7::CreateSurface returned %08x\n", hr);
1829 memset(&ddsd, 0, sizeof(ddsd));
1830 ddsd.dwSize = sizeof(ddsd);
1831 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
1832 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS;
1834 ddsd.dwHeight = 128;
1835 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP | DDSCAPS_SYSTEMMEMORY;
1836 ddsd.ddsCaps.dwCaps2 = DDSCAPS2_CUBEMAP_POSITIVEX;
1839 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
1840 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 16;
1841 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0xF800;
1842 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x07E0;
1843 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x001F;
1845 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &cubemap, NULL);
1846 ok(hr == DDERR_INVALIDCAPS, "IDirectDraw7::CreateSurface returned %08x\n", hr);
1848 memset(&ddsd, 0, sizeof(ddsd));
1849 ddsd.dwSize = sizeof(ddsd);
1850 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
1851 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS;
1853 ddsd.dwHeight = 128;
1854 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP | DDSCAPS_SYSTEMMEMORY;
1855 ddsd.ddsCaps.dwCaps2 = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES;
1857 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_PALETTEINDEXED8;
1858 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 8;
1860 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &cubemap, NULL);
1863 skip("Can't create palletized cubemap surface\n");
1867 hr = IDirectDraw7_CreatePalette(dd7, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, Table, &palette, NULL);
1868 ok(hr == DD_OK, "CreatePalette failed with %08x\n", hr);
1870 hr = IDirectDrawSurface7_EnumAttachedSurfaces(cubemap, palette, CubeTestPaletteEnum);
1871 ok(hr == DD_OK, "EnumAttachedSurfaces failed\n");
1873 ref = getRefcount((IUnknown *) palette);
1874 ok(ref == 6, "Refcount is %u, expected 1\n", ref);
1876 IDirectDrawSurface7_Release(cubemap);
1878 ref = getRefcount((IUnknown *) palette);
1879 todo_wine ok(ref == 1, "Refcount is %u, expected 1\n", ref);
1881 IDirectDrawPalette_Release(palette);
1883 /* Make sure everything is cleaned up properly. Use the enumSurfaces test infrastructure */
1884 memset(&ctx, 0, sizeof(ctx));
1885 memset(&ddsd, 0, sizeof(ddsd));
1886 ddsd.dwSize = sizeof(DDSURFACEDESC);
1887 hr = IDirectDraw_EnumSurfaces(lpDD, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_ALL, (DDSURFACEDESC *) &ddsd, (void *) &ctx, enumCB);
1888 ok(hr == DD_OK, "IDirectDraw_EnumSurfaces returned %08x\n", hr);
1889 ok(ctx.count == 0, "%d surfaces enumerated, expected 0\n", ctx.count);
1892 if (dd7) IDirectDraw7_Release(dd7);
1895 static void test_lockrect_invalid(void)
1908 {68, 60, 60, 68}, /* left > right */
1909 {60, 68, 68, 60}, /* top > bottom */
1910 {-8, 60, 0, 68}, /* left < surface */
1911 {60, -8, 68, 0}, /* top < surface */
1912 {-16, 60, -8, 68}, /* right < surface */
1913 {60, -16, 68, -8}, /* bottom < surface */
1914 {60, 60, 136, 68}, /* right > surface */
1915 {60, 60, 68, 136}, /* bottom > surface */
1916 {136, 60, 144, 68}, /* left > surface */
1917 {60, 136, 68, 144}, /* top > surface */
1920 const DWORD dds_caps[] = {
1921 DDSCAPS_OFFSCREENPLAIN
1924 for (j = 0; j < (sizeof(dds_caps) / sizeof(*dds_caps)); ++j)
1926 IDirectDrawSurface *surface = 0;
1927 DDSURFACEDESC surface_desc = {0};
1928 DDSURFACEDESC locked_desc = {0};
1931 surface_desc.dwSize = sizeof(surface_desc);
1932 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
1933 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
1934 surface_desc.ddsCaps.dwCaps = dds_caps[j];
1935 surface_desc.dwWidth = 128;
1936 surface_desc.dwHeight = 128;
1937 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB;
1938 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount = 32;
1939 U2(surface_desc.ddpfPixelFormat).dwRBitMask = 0xFF0000;
1940 U3(surface_desc.ddpfPixelFormat).dwGBitMask = 0x00FF00;
1941 U4(surface_desc.ddpfPixelFormat).dwBBitMask = 0x0000FF;
1943 hr = IDirectDraw_CreateSurface(lpDD, &surface_desc, &surface, NULL);
1944 ok(SUCCEEDED(hr), "CreateSurface failed (0x%08x)\n", hr);
1947 skip("failed to create surface\n");
1951 hr = IDirectDrawSurface_Lock(surface, NULL, NULL, DDLOCK_WAIT, NULL);
1952 ok(hr == DDERR_INVALIDPARAMS, "Lock returned 0x%08x for NULL DDSURFACEDESC,"
1953 " expected DDERR_INVALIDPARAMS (0x%08x)\n", hr, DDERR_INVALIDPARAMS);
1955 for (i = 0; i < (sizeof(valid) / sizeof(*valid)); ++i)
1957 RECT *rect = &valid[i];
1959 memset(&locked_desc, 0, sizeof(locked_desc));
1960 locked_desc.dwSize = sizeof(locked_desc);
1962 hr = IDirectDrawSurface_Lock(surface, rect, &locked_desc, DDLOCK_WAIT, NULL);
1963 ok(SUCCEEDED(hr), "Lock failed (0x%08x) for rect [%d, %d]->[%d, %d]\n",
1964 hr, rect->left, rect->top, rect->right, rect->bottom);
1966 hr = IDirectDrawSurface_Unlock(surface, NULL);
1967 ok(SUCCEEDED(hr), "Unlock failed (0x%08x)\n", hr);
1970 for (i = 0; i < (sizeof(invalid) / sizeof(*invalid)); ++i)
1972 RECT *rect = &invalid[i];
1974 memset(&locked_desc, 1, sizeof(locked_desc));
1975 locked_desc.dwSize = sizeof(locked_desc);
1977 hr = IDirectDrawSurface_Lock(surface, rect, &locked_desc, DDLOCK_WAIT, NULL);
1978 ok(hr == DDERR_INVALIDPARAMS, "Lock returned 0x%08x for rect [%d, %d]->[%d, %d]"
1979 ", expected DDERR_INVALIDPARAMS (0x%08x)\n", hr, rect->left, rect->top,
1980 rect->right, rect->bottom, DDERR_INVALIDPARAMS);
1981 ok(!locked_desc.lpSurface, "IDirectDrawSurface_Lock did not set lpSurface in the surface desc to zero.\n");
1984 hr = IDirectDrawSurface_Lock(surface, NULL, &locked_desc, DDLOCK_WAIT, NULL);
1985 ok(hr == DD_OK, "IDirectDrawSurface_Lock(rect = NULL) failed (0x%08x)\n", hr);
1986 hr = IDirectDrawSurface_Lock(surface, NULL, &locked_desc, DDLOCK_WAIT, NULL);
1987 ok(hr == DDERR_SURFACEBUSY, "Double lock(rect = NULL) returned 0x%08x\n", hr);
1989 hr = IDirectDrawSurface_Unlock(surface, NULL);
1990 ok(SUCCEEDED(hr), "Unlock failed (0x%08x)\n", hr);
1992 hr = IDirectDrawSurface_Unlock(surface, NULL);
1993 ok(SUCCEEDED(hr), "Unlock failed (0x%08x)\n", hr);
1995 memset(&locked_desc, 0, sizeof(locked_desc));
1996 locked_desc.dwSize = sizeof(locked_desc);
1997 hr = IDirectDrawSurface_Lock(surface, &valid[0], &locked_desc, DDLOCK_WAIT, NULL);
1998 ok(hr == DD_OK, "IDirectDrawSurface_Lock(rect = [%d, %d]->[%d, %d]) failed (0x%08x)\n",
1999 valid[0].left, valid[0].top, valid[0].right, valid[0].bottom, hr);
2000 hr = IDirectDrawSurface_Lock(surface, &valid[0], &locked_desc, DDLOCK_WAIT, NULL);
2001 ok(hr == DDERR_SURFACEBUSY, "Double lock(rect = [%d, %d]->[%d, %d]) failed (0x%08x)\n",
2002 valid[0].left, valid[0].top, valid[0].right, valid[0].bottom, hr);
2004 /* Locking a different rectangle returns DD_OK, but it seems to break the surface.
2005 * Afterwards unlocking the surface fails(NULL rectangle, and both locked rectangles
2008 hr = IDirectDrawSurface_Unlock(surface, NULL);
2009 ok(hr == DD_OK, "Unlock returned (0x%08x)\n", hr);
2011 IDirectDrawSurface_Release(surface);
2015 static void CompressedTest(void)
2018 IDirectDrawSurface7 *surface;
2019 DDSURFACEDESC2 ddsd, ddsd2;
2020 IDirectDraw7 *dd7 = NULL;
2021 RECT r = { 0, 0, 128, 128 };
2022 RECT r2 = { 32, 32, 64, 64 };
2024 hr = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
2025 ok(hr == DD_OK, "IDirectDraw::QueryInterface returned %08x\n", hr);
2027 memset(&ddsd, 0, sizeof(ddsd));
2028 ddsd.dwSize = sizeof(ddsd);
2029 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
2030 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS;
2032 ddsd.dwHeight = 128;
2033 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY;
2034 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_FOURCC;
2035 U4(ddsd).ddpfPixelFormat.dwFourCC = MAKEFOURCC('D','X','T','1');
2037 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface, NULL);
2038 ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
2041 skip("failed to create surface\n");
2045 memset(&ddsd2, 0, sizeof(ddsd2));
2046 ddsd2.dwSize = sizeof(ddsd2);
2047 U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
2048 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd2);
2049 ok(hr == DD_OK, "GetSurfaceDesc returned %08x\n", hr);
2051 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
2052 "Surface desc flags: %08x\n", ddsd2.dwFlags);
2053 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
2054 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
2055 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
2056 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
2057 ok(U1(ddsd2).dwLinearSize == 8192, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
2058 ok(ddsd2.ddsCaps.dwCaps2 == 0, "Caps2: %08x\n", ddsd2.ddsCaps.dwCaps2);
2059 IDirectDrawSurface7_Release(surface);
2061 U4(ddsd).ddpfPixelFormat.dwFourCC = MAKEFOURCC('D','X','T','3');
2062 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface, NULL);
2063 ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
2066 skip("failed to create surface\n");
2070 memset(&ddsd2, 0, sizeof(ddsd2));
2071 ddsd2.dwSize = sizeof(ddsd2);
2072 U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
2073 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd2);
2074 ok(hr == DD_OK, "GetSurfaceDesc returned %08x\n", hr);
2076 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
2077 "Surface desc flags: %08x\n", ddsd2.dwFlags);
2078 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
2079 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
2080 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
2081 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
2082 ok(U1(ddsd2).dwLinearSize == 16384, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
2083 IDirectDrawSurface7_Release(surface);
2085 U4(ddsd).ddpfPixelFormat.dwFourCC = MAKEFOURCC('D','X','T','5');
2086 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface, NULL);
2087 ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
2090 skip("failed to create surface\n");
2094 memset(&ddsd2, 0, sizeof(ddsd2));
2095 ddsd2.dwSize = sizeof(ddsd2);
2096 U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
2097 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd2);
2098 ok(hr == DD_OK, "GetSurfaceDesc returned %08x\n", hr);
2100 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
2101 "Surface desc flags: %08x\n", ddsd2.dwFlags);
2102 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
2103 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
2104 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
2105 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
2106 ok(U1(ddsd2).dwLinearSize == 16384, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
2107 ok(ddsd2.lpSurface == 0, "Surface memory is at %p, expected NULL\n", ddsd2.lpSurface);
2109 memset(&ddsd2, 0, sizeof(ddsd2));
2110 ddsd2.dwSize = sizeof(ddsd2);
2111 U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
2113 /* Show that the description is not changed when locking the surface. What is really interesting
2114 * about this is that DDSD_LPSURFACE isn't set.
2116 hr = IDirectDrawSurface7_Lock(surface, NULL, &ddsd2, DDLOCK_READONLY, 0);
2117 ok(hr == DD_OK, "Lock returned %08x\n", hr);
2119 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
2120 "Surface desc flags: %08x\n", ddsd2.dwFlags);
2121 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
2122 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
2123 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
2124 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
2125 ok(U1(ddsd2).dwLinearSize == 16384, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
2126 ok(ddsd2.lpSurface != 0, "Surface memory is at NULL\n");
2128 hr = IDirectDrawSurface7_Unlock(surface, NULL);
2129 ok(hr == DD_OK, "Unlock returned %08x\n", hr);
2131 /* Now what about a locking rect? */
2132 hr = IDirectDrawSurface7_Lock(surface, &r, &ddsd2, DDLOCK_READONLY, 0);
2133 ok(hr == DD_OK, "Lock returned %08x\n", hr);
2135 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
2136 "Surface desc flags: %08x\n", ddsd2.dwFlags);
2137 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
2138 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
2139 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
2140 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
2141 ok(U1(ddsd2).dwLinearSize == 16384, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
2142 ok(ddsd2.lpSurface != 0, "Surface memory is at NULL\n");
2144 hr = IDirectDrawSurface7_Unlock(surface, &r);
2145 ok(hr == DD_OK, "Unlock returned %08x\n", hr);
2147 /* Now what about a different locking offset? */
2148 hr = IDirectDrawSurface7_Lock(surface, &r2, &ddsd2, DDLOCK_READONLY, 0);
2149 ok(hr == DD_OK, "Lock returned %08x\n", hr);
2151 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
2152 "Surface desc flags: %08x\n", ddsd2.dwFlags);
2153 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
2154 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
2155 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
2156 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
2157 ok(U1(ddsd2).dwLinearSize == 16384, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
2158 ok(ddsd2.lpSurface != 0, "Surface memory is at NULL\n");
2160 hr = IDirectDrawSurface7_Unlock(surface, &r2);
2161 ok(hr == DD_OK, "Unlock returned %08x\n", hr);
2162 IDirectDrawSurface7_Release(surface);
2164 /* Try this with video memory. A kind of surprise. It still has the LINEARSIZE flag set,
2165 * but seems to have a pitch instead.
2167 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY;
2168 U4(ddsd).ddpfPixelFormat.dwFourCC = MAKEFOURCC('D','X','T','1');
2170 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface, NULL);
2171 ok(hr == DD_OK || hr == DDERR_NOTEXTUREHW || hr == DDERR_INVALIDPARAMS ||
2172 broken(hr == DDERR_NODIRECTDRAWHW), "CreateSurface returned %08x\n", hr);
2174 /* Not supported everywhere */
2177 memset(&ddsd2, 0, sizeof(ddsd2));
2178 ddsd2.dwSize = sizeof(ddsd2);
2179 U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
2180 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd2);
2181 ok(hr == DD_OK, "GetSurfaceDesc returned %08x\n", hr);
2183 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
2184 "Surface desc flags: %08x\n", ddsd2.dwFlags);
2185 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
2186 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
2187 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM),
2188 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
2189 /* ATI drivers report a broken linear size, thus no need to clone the exact behaviour. nvidia reports the correct size */
2190 ok(ddsd2.ddsCaps.dwCaps2 == 0, "Caps2: %08x\n", ddsd2.ddsCaps.dwCaps2);
2191 IDirectDrawSurface7_Release(surface);
2193 U4(ddsd).ddpfPixelFormat.dwFourCC = MAKEFOURCC('D','X','T','3');
2194 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface, NULL);
2195 ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
2197 memset(&ddsd2, 0, sizeof(ddsd2));
2198 ddsd2.dwSize = sizeof(ddsd2);
2199 U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
2200 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd2);
2201 ok(hr == DD_OK, "GetSurfaceDesc returned %08x\n", hr);
2203 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
2204 "Surface desc flags: %08x\n", ddsd2.dwFlags);
2205 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
2206 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
2207 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM),
2208 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
2209 /* ATI drivers report a broken linear size, thus no need to clone the exact behaviour. nvidia reports the correct size */
2210 IDirectDrawSurface7_Release(surface);
2212 U4(ddsd).ddpfPixelFormat.dwFourCC = MAKEFOURCC('D','X','T','5');
2213 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface, NULL);
2214 ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
2216 memset(&ddsd2, 0, sizeof(ddsd2));
2217 ddsd2.dwSize = sizeof(ddsd2);
2218 U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
2219 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd2);
2220 ok(hr == DD_OK, "GetSurfaceDesc returned %08x\n", hr);
2222 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
2223 "Surface desc flags: %08x\n", ddsd2.dwFlags);
2224 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
2225 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
2226 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM),
2227 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
2228 /* ATI drivers report a broken linear size, thus no need to clone the exact behaviour. nvidia reports the correct size */
2229 ok(ddsd2.lpSurface == 0, "Surface memory is at %p, expected NULL\n", ddsd2.lpSurface);
2231 memset(&ddsd2, 0, sizeof(ddsd2));
2232 ddsd2.dwSize = sizeof(ddsd2);
2233 U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
2235 /* Show that the description is not changed when locking the surface. What is really interesting
2236 * about this is that DDSD_LPSURFACE isn't set.
2238 hr = IDirectDrawSurface7_Lock(surface, NULL, &ddsd2, DDLOCK_READONLY, 0);
2239 ok(hr == DD_OK, "Lock returned %08x\n", hr);
2241 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
2242 "Surface desc flags: %08x\n", ddsd2.dwFlags);
2243 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
2244 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
2245 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM),
2246 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
2247 /* ATI drivers report a broken linear size, thus no need to clone the exact behaviour. nvidia reports the correct size */
2248 ok(ddsd2.lpSurface != 0, "Surface memory is at NULL\n");
2250 hr = IDirectDrawSurface7_Unlock(surface, NULL);
2251 ok(hr == DD_OK, "Unlock returned %08x\n", hr);
2253 /* Now what about a locking rect? */
2254 hr = IDirectDrawSurface7_Lock(surface, &r, &ddsd2, DDLOCK_READONLY, 0);
2255 ok(hr == DD_OK, "Lock returned %08x\n", hr);
2257 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
2258 "Surface desc flags: %08x\n", ddsd2.dwFlags);
2259 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
2260 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
2261 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM),
2262 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
2263 /* ATI drivers report a broken linear size, thus no need to clone the exact behaviour. nvidia reports the correct size */
2264 ok(ddsd2.lpSurface != 0, "Surface memory is at NULL\n");
2266 hr = IDirectDrawSurface7_Unlock(surface, &r);
2267 ok(hr == DD_OK, "Unlock returned %08x\n", hr);
2269 /* Now what about a different locking offset? */
2270 hr = IDirectDrawSurface7_Lock(surface, &r2, &ddsd2, DDLOCK_READONLY, 0);
2271 ok(hr == DD_OK, "Lock returned %08x\n", hr);
2273 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
2274 "Surface desc flags: %08x\n", ddsd2.dwFlags);
2275 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
2276 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
2277 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM),
2278 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
2279 /* ATI drivers report a broken linear size, thus no need to clone the exact behaviour. nvidia reports the correct size */
2280 ok(ddsd2.lpSurface != 0, "Surface memory is at NULL\n");
2282 hr = IDirectDrawSurface7_Unlock(surface, &r2);
2283 ok(hr == DD_OK, "Unlock returned %08x\n", hr);
2285 IDirectDrawSurface7_Release(surface);
2289 skip("Hardware DXTN textures not supported\n");
2292 /* What happens to managed textures? Interestingly, Windows reports them as being in system
2293 * memory. The linear size fits again.
2295 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
2296 ddsd.ddsCaps.dwCaps2 = DDSCAPS2_TEXTUREMANAGE;
2297 U4(ddsd).ddpfPixelFormat.dwFourCC = MAKEFOURCC('D','X','T','1');
2299 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface, NULL);
2300 ok(hr == DD_OK || hr == DDERR_NOTEXTUREHW, "CreateSurface returned %08x\n", hr);
2302 /* Not supported everywhere */
2305 memset(&ddsd2, 0, sizeof(ddsd2));
2306 ddsd2.dwSize = sizeof(ddsd2);
2307 U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
2308 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd2);
2309 ok(hr == DD_OK, "GetSurfaceDesc returned %08x\n", hr);
2311 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
2312 "Surface desc flags: %08x\n", ddsd2.dwFlags);
2313 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
2314 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
2315 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
2316 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
2317 ok(U1(ddsd2).dwLinearSize == 8192, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
2318 ok(ddsd2.ddsCaps.dwCaps2 == DDSCAPS2_TEXTUREMANAGE, "Caps2: %08x\n", ddsd2.ddsCaps.dwCaps2);
2319 IDirectDrawSurface7_Release(surface);
2321 U4(ddsd).ddpfPixelFormat.dwFourCC = MAKEFOURCC('D','X','T','3');
2322 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface, NULL);
2323 ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
2325 memset(&ddsd2, 0, sizeof(ddsd2));
2326 ddsd2.dwSize = sizeof(ddsd2);
2327 U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
2328 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd2);
2329 ok(hr == DD_OK, "GetSurfaceDesc returned %08x\n", hr);
2331 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
2332 "Surface desc flags: %08x\n", ddsd2.dwFlags);
2333 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
2334 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
2335 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
2336 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
2337 ok(U1(ddsd2).dwLinearSize == 16384, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
2338 IDirectDrawSurface7_Release(surface);
2340 U4(ddsd).ddpfPixelFormat.dwFourCC = MAKEFOURCC('D','X','T','5');
2341 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface, NULL);
2342 ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
2344 memset(&ddsd2, 0, sizeof(ddsd2));
2345 ddsd2.dwSize = sizeof(ddsd2);
2346 U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
2347 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd2);
2348 ok(hr == DD_OK, "GetSurfaceDesc returned %08x\n", hr);
2350 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
2351 "Surface desc flags: %08x\n", ddsd2.dwFlags);
2352 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
2353 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
2354 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
2355 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
2356 ok(U1(ddsd2).dwLinearSize == 16384, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
2357 ok(ddsd2.lpSurface == 0, "Surface memory is at %p, expected NULL\n", ddsd2.lpSurface);
2359 memset(&ddsd2, 0, sizeof(ddsd2));
2360 ddsd2.dwSize = sizeof(ddsd2);
2361 U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
2363 /* Show that the description is not changed when locking the surface. What is really interesting
2364 * about this is that DDSD_LPSURFACE isn't set.
2366 hr = IDirectDrawSurface7_Lock(surface, NULL, &ddsd2, DDLOCK_READONLY, 0);
2367 ok(hr == DD_OK, "Lock returned %08x\n", hr);
2369 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
2370 "Surface desc flags: %08x\n", ddsd2.dwFlags);
2371 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
2372 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
2373 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
2374 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
2375 ok(U1(ddsd2).dwLinearSize == 16384, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
2376 ok(ddsd2.lpSurface != 0, "Surface memory is at NULL\n");
2378 hr = IDirectDrawSurface7_Unlock(surface, NULL);
2379 ok(hr == DD_OK, "Unlock returned %08x\n", hr);
2381 /* Now what about a locking rect? */
2382 hr = IDirectDrawSurface7_Lock(surface, &r, &ddsd2, DDLOCK_READONLY, 0);
2383 ok(hr == DD_OK, "Lock returned %08x\n", hr);
2385 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
2386 "Surface desc flags: %08x\n", ddsd2.dwFlags);
2387 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
2388 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
2389 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
2390 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
2391 ok(U1(ddsd2).dwLinearSize == 16384, "\"Linear\" size is %d\n", U1(ddsd2).dwLinearSize);
2392 ok(ddsd2.lpSurface != 0, "Surface memory is at NULL\n");
2394 hr = IDirectDrawSurface7_Unlock(surface, &r);
2395 ok(hr == DD_OK, "Unlock returned %08x\n", hr);
2397 /* Now what about a different locking offset? */
2398 hr = IDirectDrawSurface7_Lock(surface, &r2, &ddsd2, DDLOCK_READONLY, 0);
2399 ok(hr == DD_OK, "Lock returned %08x\n", hr);
2401 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
2402 "Surface desc flags: %08x\n", ddsd2.dwFlags);
2403 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
2404 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
2405 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
2406 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
2407 ok(U1(ddsd2).dwLinearSize == 16384, "\"Linear\" size is %d\n", U1(ddsd2).dwLinearSize);
2408 ok(ddsd2.lpSurface != 0, "Surface memory is at NULL\n");
2410 hr = IDirectDrawSurface7_Unlock(surface, &r2);
2411 ok(hr == DD_OK, "Unlock returned %08x\n", hr);
2413 IDirectDrawSurface7_Release(surface);
2417 skip("Hardware DXTN textures not supported\n");
2420 IDirectDraw7_Release(dd7);
2423 static void SizeTest(void)
2425 LPDIRECTDRAWSURFACE dsurface = NULL;
2428 HWND window = CreateWindow( "static", "ddraw_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
2430 /* Create an offscreen surface surface without a size */
2431 ZeroMemory(&desc, sizeof(desc));
2432 desc.dwSize = sizeof(desc);
2433 desc.dwFlags = DDSD_CAPS;
2434 desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
2435 ret = IDirectDraw_CreateSurface(lpDD, &desc, &dsurface, NULL);
2436 ok(ret == DDERR_INVALIDPARAMS, "Creating an offscreen plain surface without a size info returned %08x (dsurface=%p)\n", ret, dsurface);
2439 trace("Surface at %p\n", dsurface);
2440 IDirectDrawSurface_Release(dsurface);
2444 /* Create an offscreen surface surface with only a width parameter */
2445 ZeroMemory(&desc, sizeof(desc));
2446 desc.dwSize = sizeof(desc);
2447 desc.dwFlags = DDSD_CAPS | DDSD_WIDTH;
2448 desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
2450 ret = IDirectDraw_CreateSurface(lpDD, &desc, &dsurface, NULL);
2451 ok(ret == DDERR_INVALIDPARAMS, "Creating an offscreen plain surface without height info returned %08x\n", ret);
2454 IDirectDrawSurface_Release(dsurface);
2458 /* Create an offscreen surface surface with only a height parameter */
2459 ZeroMemory(&desc, sizeof(desc));
2460 desc.dwSize = sizeof(desc);
2461 desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT;
2462 desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
2463 desc.dwHeight = 128;
2464 ret = IDirectDraw_CreateSurface(lpDD, &desc, &dsurface, NULL);
2465 ok(ret == DDERR_INVALIDPARAMS, "Creating an offscreen plain surface without width info returned %08x\n", ret);
2468 IDirectDrawSurface_Release(dsurface);
2472 /* Test 0 height. */
2473 memset(&desc, 0, sizeof(desc));
2474 desc.dwSize = sizeof(desc);
2475 desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
2476 desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
2479 ret = IDirectDraw_CreateSurface(lpDD, &desc, &dsurface, NULL);
2480 ok(ret == DDERR_INVALIDPARAMS, "Creating a 0 height surface returned %#x, expected DDERR_INVALIDPARAMS.\n", ret);
2481 if (SUCCEEDED(ret)) IDirectDrawSurface_Release(dsurface);
2485 memset(&desc, 0, sizeof(desc));
2486 desc.dwSize = sizeof(desc);
2487 desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
2488 desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
2491 ret = IDirectDraw_CreateSurface(lpDD, &desc, &dsurface, NULL);
2492 ok(ret == DDERR_INVALIDPARAMS, "Creating a 0 width surface returned %#x, expected DDERR_INVALIDPARAMS.\n", ret);
2493 if (SUCCEEDED(ret)) IDirectDrawSurface_Release(dsurface);
2497 ZeroMemory(&desc, sizeof(desc));
2498 desc.dwSize = sizeof(desc);
2499 desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
2500 desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
2501 desc.dwHeight = 128;
2503 ret = IDirectDraw_CreateSurface(lpDD, &desc, &dsurface, NULL);
2504 ok(ret == DD_OK, "Creating an offscreen plain surface with width and height info returned %08x\n", ret);
2507 IDirectDrawSurface_Release(dsurface);
2511 /* Test a primary surface size */
2512 ret = IDirectDraw_SetCooperativeLevel(lpDD, window, DDSCL_NORMAL);
2513 ok(ret == DD_OK, "SetCooperativeLevel failed with %08x\n", ret);
2515 ZeroMemory(&desc, sizeof(desc));
2516 desc.dwSize = sizeof(desc);
2517 desc.dwFlags = DDSD_CAPS;
2518 desc.ddsCaps.dwCaps |= DDSCAPS_PRIMARYSURFACE;
2519 desc.dwHeight = 128; /* Keep them set to check what happens */
2520 desc.dwWidth = 128; /* Keep them set to check what happens */
2521 ret = IDirectDraw_CreateSurface(lpDD, &desc, &dsurface, NULL);
2522 ok(ret == DD_OK, "Creating a primary surface without width and height info returned %08x\n", ret);
2525 ret = IDirectDrawSurface_GetSurfaceDesc(dsurface, &desc);
2526 ok(ret == DD_OK, "GetSurfaceDesc returned %x\n", ret);
2528 IDirectDrawSurface_Release(dsurface);
2531 ok(desc.dwFlags & DDSD_WIDTH, "Primary surface doesn't have width set\n");
2532 ok(desc.dwFlags & DDSD_HEIGHT, "Primary surface doesn't have height set\n");
2533 ok(desc.dwWidth == GetSystemMetrics(SM_CXSCREEN), "Surface width differs from screen width\n");
2534 ok(desc.dwHeight == GetSystemMetrics(SM_CYSCREEN), "Surface height differs from screen height\n");
2536 ret = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_NORMAL);
2537 ok(ret == DD_OK, "SetCooperativeLevel failed with %08x\n", ret);
2540 static void PrivateDataTest(void)
2543 IDirectDrawSurface7 *surface7 = NULL;
2544 IDirectDrawSurface *surface = NULL;
2548 DWORD size = sizeof(IUnknown *);
2550 ZeroMemory(&desc, sizeof(desc));
2551 desc.dwSize = sizeof(desc);
2552 desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
2553 desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
2554 desc.dwHeight = 128;
2556 hr = IDirectDraw_CreateSurface(lpDD, &desc, &surface, NULL);
2557 ok(hr == DD_OK, "Creating an offscreen plain surface failed with %08x\n", hr);
2562 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirectDrawSurface7, (void **) &surface7);
2563 ok(hr == DD_OK, "IDirectDrawSurface_QueryInterface failed with %08x\n", hr);
2566 IDirectDrawSurface_Release(surface);
2571 hr = IDirectDrawSurface7_SetPrivateData(surface7, &IID_IDirectDrawSurface7 /* Abuse this tag */, lpDD, 0, DDSPD_IUNKNOWNPOINTER);
2572 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr);
2573 hr = IDirectDrawSurface7_SetPrivateData(surface7, &IID_IDirectDrawSurface7 /* Abuse this tag */, lpDD, 5, DDSPD_IUNKNOWNPOINTER);
2574 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr);
2575 hr = IDirectDrawSurface7_SetPrivateData(surface7, &IID_IDirectDrawSurface7 /* Abuse this tag */, lpDD, sizeof(IUnknown *) * 2, DDSPD_IUNKNOWNPOINTER);
2576 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr);
2578 ref = getref((IUnknown *) lpDD);
2579 hr = IDirectDrawSurface7_SetPrivateData(surface7, &IID_IDirectDrawSurface7 /* Abuse this tag */, lpDD, sizeof(IUnknown *), DDSPD_IUNKNOWNPOINTER);
2580 ok(hr == DD_OK, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr);
2581 ref2 = getref((IUnknown *) lpDD);
2582 ok(ref2 == ref + 1, "Object reference is %d, expected %d\n", ref2, ref + 1);
2583 hr = IDirectDrawSurface7_FreePrivateData(surface7, &IID_IDirectDrawSurface7);
2584 ok(SUCCEEDED(hr), "IDirectDrawSurface7_FreePrivateData returned %#x.\n", hr);
2585 ref2 = getref((IUnknown *) lpDD);
2586 ok(ref2 == ref, "Object reference is %d, expected %d\n", ref2, ref);
2588 hr = IDirectDrawSurface7_SetPrivateData(surface7, &IID_IDirectDrawSurface7, lpDD, sizeof(IUnknown *), DDSPD_IUNKNOWNPOINTER);
2589 ok(hr == DD_OK, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr);
2590 hr = IDirectDrawSurface7_SetPrivateData(surface7, &IID_IDirectDrawSurface7, surface7, sizeof(IUnknown *), DDSPD_IUNKNOWNPOINTER);
2591 ok(hr == DD_OK, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr);
2592 ref2 = getref((IUnknown *) lpDD);
2593 ok(ref2 == ref, "Object reference is %d, expected %d\n", ref2, ref);
2595 hr = IDirectDrawSurface7_SetPrivateData(surface7, &IID_IDirectDrawSurface7, lpDD, sizeof(IUnknown *), DDSPD_IUNKNOWNPOINTER);
2596 ok(hr == DD_OK, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr);
2597 hr = IDirectDrawSurface7_GetPrivateData(surface7, &IID_IDirectDrawSurface7, &ptr, &size);
2598 ok(hr == DD_OK, "IDirectDrawSurface7_GetPrivateData failed with %08x\n", hr);
2599 ref2 = getref((IUnknown *) lpDD);
2600 /* Object is NOT being addrefed */
2601 ok(ptr == (IUnknown *) lpDD, "Returned interface pointer is %p, expected %p\n", ptr, lpDD);
2602 ok(ref2 == ref + 1, "Object reference is %d, expected %d. ptr at %p, orig at %p\n", ref2, ref + 1, ptr, lpDD);
2604 IDirectDrawSurface_Release(surface);
2605 IDirectDrawSurface7_Release(surface7);
2607 /* Destroying the surface frees the held reference */
2608 ref2 = getref((IUnknown *) lpDD);
2609 ok(ref2 == ref, "Object reference is %d, expected %d\n", ref2, ref);
2612 static void BltParamTest(void)
2614 IDirectDrawSurface *surface1 = NULL, *surface2 = NULL;
2618 RECT valid = {10, 10, 20, 20};
2619 RECT invalid1 = {20, 10, 10, 20};
2620 RECT invalid2 = {20, 20, 20, 20};
2621 RECT invalid3 = {-1, -1, 20, 20};
2622 RECT invalid4 = {60, 60, 70, 70};
2624 memset(&desc, 0, sizeof(desc));
2625 desc.dwSize = sizeof(desc);
2626 desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
2627 desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
2628 desc.dwHeight = 128;
2630 hr = IDirectDraw_CreateSurface(lpDD, &desc, &surface1, NULL);
2631 ok(hr == DD_OK, "Creating an offscreen plain surface failed with %08x\n", hr);
2635 hr = IDirectDraw_CreateSurface(lpDD, &desc, &surface2, NULL);
2636 ok(hr == DD_OK, "Creating an offscreen plain surface failed with %08x\n", hr);
2641 hr = IDirectDrawSurface_BltFast(surface1, 0, 0, NULL, NULL, 0);
2642 ok(hr == DD_OK, "BltFast from NULL surface returned %08x\n", hr);
2644 hr = IDirectDrawSurface_BltFast(surface1, 0, 0, surface2, NULL, 0);
2645 ok(hr == DD_OK, "BltFast from smaller to bigger surface returned %08x\n", hr);
2646 hr = IDirectDrawSurface_BltFast(surface2, 0, 0, surface1, NULL, 0);
2647 ok(hr == DDERR_INVALIDRECT, "BltFast from bigger to smaller surface returned %08x\n", hr);
2648 hr = IDirectDrawSurface_BltFast(surface2, 0, 0, surface1, &valid, 0);
2649 ok(hr == DD_OK, "BltFast from bigger to smaller surface using a valid rectangle returned %08x\n", hr);
2650 hr = IDirectDrawSurface_BltFast(surface2, 60, 60, surface1, &valid, 0);
2651 ok(hr == DDERR_INVALIDRECT, "BltFast with a rectangle resulting in an off-surface write returned %08x\n", hr);
2652 hr = IDirectDrawSurface_BltFast(surface1, 90, 90, surface2, NULL, 0);
2653 ok(hr == DDERR_INVALIDRECT, "BltFast with a rectangle resulting in an off-surface write returned %08x\n", hr);
2655 hr = IDirectDrawSurface_BltFast(surface1, -10, 0, surface2, NULL, 0);
2656 ok(hr == DDERR_INVALIDRECT, "BltFast with an offset resulting in an off-surface write returned %08x\n", hr);
2657 hr = IDirectDrawSurface_BltFast(surface1, 0, -10, surface2, NULL, 0);
2658 ok(hr == DDERR_INVALIDRECT, "BltFast with an offset resulting in an off-surface write returned %08x\n", hr);
2659 hr = IDirectDrawSurface_BltFast(surface2, 20, 20, surface1, &valid, 0);
2660 ok(hr == DD_OK, "BltFast from bigger to smaller surface using a valid rectangle and offset returned %08x\n", hr);
2662 hr = IDirectDrawSurface_BltFast(surface2, 0, 0, surface1, &invalid1, 0);
2663 ok(hr == DDERR_INVALIDRECT, "BltFast with invalid rectangle 1 returned %08x\n", hr);
2664 hr = IDirectDrawSurface_BltFast(surface2, 0, 0, surface1, &invalid2, 0);
2665 ok(hr == DDERR_INVALIDRECT, "BltFast with invalid rectangle 2 returned %08x\n", hr);
2666 hr = IDirectDrawSurface_BltFast(surface2, 0, 0, surface1, &invalid3, 0);
2667 ok(hr == DDERR_INVALIDRECT, "BltFast with invalid rectangle 3 returned %08x\n", hr);
2668 hr = IDirectDrawSurface_BltFast(surface1, 0, 0, surface2, &invalid4, 0);
2669 ok(hr == DDERR_INVALIDRECT, "BltFast with invalid rectangle 3 returned %08x\n", hr);
2670 hr = IDirectDrawSurface_BltFast(surface1, 0, 0, surface1, NULL, 0);
2671 ok(hr == DD_OK, "BltFast blitting a surface onto itself returned %08x\n", hr);
2673 /* Blt(non-fast) tests */
2674 memset(&BltFx, 0, sizeof(BltFx));
2675 BltFx.dwSize = sizeof(BltFx);
2676 U5(BltFx).dwFillColor = 0xaabbccdd;
2678 hr = IDirectDrawSurface_Blt(surface1, &valid, NULL, NULL, DDBLT_COLORFILL, &BltFx);
2679 ok(hr == DD_OK, "IDirectDrawSurface_Blt with a valid rectangle for color fill returned %08x\n", hr);
2680 hr = IDirectDrawSurface_Blt(surface1, &valid, NULL, &invalid3, DDBLT_COLORFILL, &BltFx);
2681 ok(hr == DD_OK, "IDirectDrawSurface_Blt with a invalid, unused rectangle returned %08x\n", hr);
2682 hr = IDirectDrawSurface_Blt(surface2, &invalid1, NULL, NULL, DDBLT_COLORFILL, &BltFx);
2683 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 1 returned %08x\n", hr);
2684 hr = IDirectDrawSurface_Blt(surface2, &invalid2, NULL, NULL, DDBLT_COLORFILL, &BltFx);
2685 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 2 returned %08x\n", hr);
2686 hr = IDirectDrawSurface_Blt(surface2, &invalid3, NULL, NULL, DDBLT_COLORFILL, &BltFx);
2687 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 3 returned %08x\n", hr);
2688 hr = IDirectDrawSurface_Blt(surface2, &invalid4, NULL, NULL, DDBLT_COLORFILL, &BltFx);
2689 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 4 returned %08x\n", hr);
2691 /* Valid on surface 1 */
2692 hr = IDirectDrawSurface_Blt(surface1, &invalid4, NULL, NULL, DDBLT_COLORFILL, &BltFx);
2693 ok(hr == DD_OK, "IDirectDrawSurface_Blt with a subrectangle fill returned %08x\n", hr);
2695 /* Works - stretched blit */
2696 hr = IDirectDrawSurface_Blt(surface1, NULL, surface2, NULL, 0, NULL);
2697 ok(hr == DD_OK, "IDirectDrawSurface_Blt from a smaller to a bigger surface returned %08x\n", hr);
2698 hr = IDirectDrawSurface_Blt(surface2, NULL, surface1, NULL, 0, NULL);
2699 ok(hr == DD_OK, "IDirectDrawSurface_Blt from a bigger to a smaller surface %08x\n", hr);
2701 /* Invalid dest rects in sourced blits */
2702 hr = IDirectDrawSurface_Blt(surface2, &invalid1, surface1, NULL, 0, NULL);
2703 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 1 returned %08x\n", hr);
2704 hr = IDirectDrawSurface_Blt(surface2, &invalid2, surface1, NULL, 0, NULL);
2705 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 2 returned %08x\n", hr);
2706 hr = IDirectDrawSurface_Blt(surface2, &invalid3, surface1, NULL, 0, NULL);
2707 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 3 returned %08x\n", hr);
2708 hr = IDirectDrawSurface_Blt(surface2, &invalid4, surface1, NULL, 0, NULL);
2709 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 4 returned %08x\n", hr);
2711 /* Invalid src rects */
2712 hr = IDirectDrawSurface_Blt(surface2, NULL, surface1, &invalid1, 0, NULL);
2713 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 1 returned %08x\n", hr);
2714 hr = IDirectDrawSurface_Blt(surface2, NULL, surface1, &invalid2, 0, NULL);
2715 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 2 returned %08x\n", hr);
2716 hr = IDirectDrawSurface_Blt(surface2, NULL, surface1, &invalid3, 0, NULL);
2717 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 3 returned %08x\n", hr);
2718 hr = IDirectDrawSurface_Blt(surface1, NULL, surface2, &invalid4, 0, NULL);
2719 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 4 returned %08x\n", hr);
2721 IDirectDrawSurface_Release(surface1);
2722 IDirectDrawSurface_Release(surface2);
2725 static void PaletteTest(void)
2728 LPDIRECTDRAWSURFACE lpSurf = NULL;
2729 IDirectDrawSurface *backbuffer = NULL;
2732 IDirectDrawPalette *palette = NULL;
2733 PALETTEENTRY Table[256];
2734 PALETTEENTRY palEntries[256];
2737 for(i=0; i<256; i++)
2739 Table[i].peRed = 0xff;
2740 Table[i].peGreen = 0;
2741 Table[i].peBlue = 0;
2742 Table[i].peFlags = 0;
2745 /* Create a 8bit palette without DDPCAPS_ALLOW256 set */
2746 hr = IDirectDraw_CreatePalette(lpDD, DDPCAPS_8BIT, Table, &palette, NULL);
2747 ok(hr == DD_OK, "CreatePalette failed with %08x\n", hr);
2748 if (FAILED(hr)) goto err;
2749 /* Read back the palette and verify the entries. Without DDPCAPS_ALLOW256 set
2750 / entry 0 and 255 should have been overwritten with black and white */
2751 IDirectDrawPalette_GetEntries(palette , 0, 0, 256, &palEntries[0]);
2752 ok(hr == DD_OK, "GetEntries failed with %08x\n", hr);
2755 ok((palEntries[0].peRed == 0) && (palEntries[0].peGreen == 0) && (palEntries[0].peBlue == 0),
2756 "Palette entry 0 of a palette without DDPCAPS_ALLOW256 set should be (0,0,0) but it is (%d,%d,%d)\n",
2757 palEntries[0].peRed, palEntries[0].peGreen, palEntries[0].peBlue);
2758 ok((palEntries[255].peRed == 255) && (palEntries[255].peGreen == 255) && (palEntries[255].peBlue == 255),
2759 "Palette entry 255 of a palette without DDPCAPS_ALLOW256 set should be (255,255,255) but it is (%d,%d,%d)\n",
2760 palEntries[255].peRed, palEntries[255].peGreen, palEntries[255].peBlue);
2762 /* Entry 1-254 should contain red */
2763 for(i=1; i<255; i++)
2764 ok((palEntries[i].peRed == 255) && (palEntries[i].peGreen == 0) && (palEntries[i].peBlue == 0),
2765 "Palette entry %d should have contained (255,0,0) but was set to %d,%d,%d)\n",
2766 i, palEntries[i].peRed, palEntries[i].peGreen, palEntries[i].peBlue);
2769 /* CreatePalette without DDPCAPS_ALLOW256 ignores entry 0 and 255,
2770 / now check we are able to update the entries afterwards. */
2771 IDirectDrawPalette_SetEntries(palette , 0, 0, 256, &Table[0]);
2772 ok(hr == DD_OK, "SetEntries failed with %08x\n", hr);
2773 IDirectDrawPalette_GetEntries(palette , 0, 0, 256, &palEntries[0]);
2774 ok(hr == DD_OK, "GetEntries failed with %08x\n", hr);
2777 ok((palEntries[0].peRed == 0) && (palEntries[0].peGreen == 0) && (palEntries[0].peBlue == 0),
2778 "Palette entry 0 should have been set to (0,0,0) but it contains (%d,%d,%d)\n",
2779 palEntries[0].peRed, palEntries[0].peGreen, palEntries[0].peBlue);
2780 ok((palEntries[255].peRed == 255) && (palEntries[255].peGreen == 255) && (palEntries[255].peBlue == 255),
2781 "Palette entry 255 should have been set to (255,255,255) but it contains (%d,%d,%d)\n",
2782 palEntries[255].peRed, palEntries[255].peGreen, palEntries[255].peBlue);
2784 IDirectDrawPalette_Release(palette);
2786 /* Create a 8bit palette with DDPCAPS_ALLOW256 set */
2787 hr = IDirectDraw_CreatePalette(lpDD, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, Table, &palette, NULL);
2788 ok(hr == DD_OK, "CreatePalette failed with %08x\n", hr);
2789 if (FAILED(hr)) goto err;
2791 IDirectDrawPalette_GetEntries(palette , 0, 0, 256, &palEntries[0]);
2792 ok(hr == DD_OK, "GetEntries failed with %08x\n", hr);
2795 /* All entries should contain red */
2796 for(i=0; i<256; i++)
2797 ok((palEntries[i].peRed == 255) && (palEntries[i].peGreen == 0) && (palEntries[i].peBlue == 0),
2798 "Palette entry %d should have contained (255,0,0) but was set to %d,%d,%d)\n",
2799 i, palEntries[i].peRed, palEntries[i].peGreen, palEntries[i].peBlue);
2802 /* Try to set palette to a non-palettized surface */
2803 ddsd.dwSize = sizeof(ddsd);
2804 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
2805 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
2806 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
2808 ddsd.dwHeight = 600;
2809 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
2810 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 32;
2811 U2(ddsd.ddpfPixelFormat).dwRBitMask = 0xFF0000;
2812 U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x00FF00;
2813 U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x0000FF;
2814 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpSurf, NULL);
2815 ok(hr==DD_OK, "CreateSurface returned: %x\n",hr);
2818 skip("failed to create surface\n");
2822 hr = IDirectDrawSurface_SetPalette(lpSurf, palette);
2823 ok(hr == DDERR_INVALIDPIXELFORMAT, "CreateSurface returned: %x\n",hr);
2825 IDirectDrawPalette_Release(palette);
2828 hr = IDirectDrawSurface_GetPalette(lpSurf, &palette);
2829 ok(hr == DDERR_NOPALETTEATTACHED, "CreateSurface returned: %x\n",hr);
2833 if (lpSurf) IDirectDrawSurface_Release(lpSurf);
2834 if (palette) IDirectDrawPalette_Release(palette);
2836 hr = IDirectDraw_CreatePalette(lpDD, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, Table, &palette, NULL);
2837 ok(hr == DD_OK, "CreatePalette failed with %08x\n", hr);
2839 ddsd.dwSize = sizeof(ddsd);
2840 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
2841 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_BACKBUFFERCOUNT;
2842 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
2845 ddsd.dwBackBufferCount = 1;
2846 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_PALETTEINDEXED8;
2847 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 8;
2849 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpSurf, NULL);
2850 ok(hr==DD_OK, "CreateSurface returned: %x\n",hr);
2853 skip("failed to create surface\n");
2857 ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
2858 hr = IDirectDrawSurface_GetAttachedSurface(lpSurf, &ddscaps, &backbuffer);
2859 ok(hr == DD_OK, "GetAttachedSurface returned: %x\n",hr);
2861 hr = IDirectDrawSurface_SetPalette(backbuffer, palette);
2862 ok(hr == DD_OK, "SetPalette returned: %x\n",hr);
2864 IDirectDrawPalette_Release(palette);
2867 hr = IDirectDrawSurface_GetPalette(backbuffer, &palette);
2868 ok(hr == DD_OK, "CreateSurface returned: %x\n",hr);
2870 IDirectDrawSurface_Release(backbuffer);
2871 IDirectDrawSurface_Release(lpSurf);
2874 static void StructSizeTest(void)
2876 IDirectDrawSurface *surface1;
2877 IDirectDrawSurface7 *surface7;
2879 DDSURFACEDESC desc1;
2880 DDSURFACEDESC2 desc2;
2881 char blob[1024]; /* To get a bunch of writable memory */
2883 DDSURFACEDESC create;
2886 memset(&desc, 0, sizeof(desc));
2887 memset(&create, 0, sizeof(create));
2889 memset(&create, 0, sizeof(create));
2890 create.dwSize = sizeof(create);
2891 create.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
2892 create.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
2893 create.dwHeight = 128;
2894 create.dwWidth = 128;
2895 hr = IDirectDraw_CreateSurface(lpDD, &create, &surface1, NULL);
2896 ok(hr == DD_OK, "Creating an offscreen plain surface failed with %08x\n", hr);
2897 hr = IDirectDrawSurface_QueryInterface(surface1, &IID_IDirectDrawSurface7, (void **) &surface7);
2898 ok(hr == DD_OK, "IDirectDrawSurface_QueryInterface failed with %08x\n", hr);
2900 desc.desc1.dwSize = sizeof(DDSURFACEDESC);
2901 hr = IDirectDrawSurface_GetSurfaceDesc(surface1, &desc.desc1);
2902 ok(hr == DD_OK, "IDirectDrawSurface_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC) returned %08x\n", hr);
2903 hr = IDirectDrawSurface7_GetSurfaceDesc(surface7, &desc.desc2);
2904 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC) returned %08x\n", hr);
2906 desc.desc2.dwSize = sizeof(DDSURFACEDESC2);
2907 hr = IDirectDrawSurface_GetSurfaceDesc(surface1, &desc.desc1);
2908 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC2) returned %08x\n", hr);
2909 hr = IDirectDrawSurface7_GetSurfaceDesc(surface7, &desc.desc2);
2910 ok(hr == DD_OK, "IDirectDrawSurface7_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC2) returned %08x\n", hr);
2912 desc.desc2.dwSize = 0;
2913 hr = IDirectDrawSurface_GetSurfaceDesc(surface1, &desc.desc1);
2914 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface_GetSurfaceDesc with desc size 0 returned %08x\n", hr);
2915 hr = IDirectDrawSurface7_GetSurfaceDesc(surface7, &desc.desc2);
2916 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_GetSurfaceDesc with desc size 0 returned %08x\n", hr);
2918 desc.desc1.dwSize = sizeof(DDSURFACEDESC) + 1;
2919 hr = IDirectDrawSurface_GetSurfaceDesc(surface1, &desc.desc1);
2920 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC) + 1 returned %08x\n", hr);
2921 hr = IDirectDrawSurface7_GetSurfaceDesc(surface7, &desc.desc2);
2922 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC) + 1 returned %08x\n", hr);
2924 desc.desc2.dwSize = sizeof(DDSURFACEDESC2) + 1;
2925 hr = IDirectDrawSurface_GetSurfaceDesc(surface1, &desc.desc1);
2926 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC2) + 1returned %08x\n", hr);
2927 hr = IDirectDrawSurface7_GetSurfaceDesc(surface7, &desc.desc2);
2928 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC2) + 1returned %08x\n", hr);
2930 /* Tests for Lock() */
2932 desc.desc1.dwSize = sizeof(DDSURFACEDESC);
2933 hr = IDirectDrawSurface_Lock(surface1, NULL, &desc.desc1, 0, 0);
2934 ok(hr == DD_OK, "IDirectDrawSurface_Lock with desc size sizeof(DDSURFACEDESC) returned %08x\n", hr);
2935 if(SUCCEEDED(hr)) IDirectDrawSurface_Unlock(surface1, NULL);
2936 ok(desc.desc1.dwSize == sizeof(DDSURFACEDESC), "Destination size was changed to %d\n", desc.desc1.dwSize);
2937 hr = IDirectDrawSurface7_Lock(surface7, NULL, &desc.desc2, 0, 0);
2938 ok(hr == DD_OK, "IDirectDrawSurface7_Lock with desc size sizeof(DDSURFACEDESC) returned %08x\n", hr);
2939 if(SUCCEEDED(hr)) IDirectDrawSurface7_Unlock(surface7, NULL);
2940 ok(desc.desc2.dwSize == sizeof(DDSURFACEDESC), "Destination size was changed to %d\n", desc.desc1.dwSize);
2942 desc.desc2.dwSize = sizeof(DDSURFACEDESC2);
2943 hr = IDirectDrawSurface_Lock(surface1, NULL, &desc.desc1, 0, 0);
2944 ok(hr == DD_OK, "IDirectDrawSurface_Lock with desc size sizeof(DDSURFACEDESC2) returned %08x\n", hr);
2945 ok(desc.desc1.dwSize == sizeof(DDSURFACEDESC2), "Destination size was changed to %d\n", desc.desc1.dwSize);
2946 if(SUCCEEDED(hr)) IDirectDrawSurface_Unlock(surface1, NULL);
2947 hr = IDirectDrawSurface7_Lock(surface7, NULL, &desc.desc2, 0, 0);
2948 ok(hr == DD_OK, "IDirectDrawSurface7_Lock with desc size sizeof(DDSURFACEDESC2) returned %08x\n", hr);
2949 if(SUCCEEDED(hr)) IDirectDrawSurface7_Unlock(surface7, NULL);
2950 ok(desc.desc2.dwSize == sizeof(DDSURFACEDESC2), "Destination size was changed to %d\n", desc.desc1.dwSize);
2952 desc.desc2.dwSize = 0;
2953 hr = IDirectDrawSurface_Lock(surface1, NULL, &desc.desc1, 0, 0);
2954 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface_Lock with desc size 0 returned %08x\n", hr);
2955 if(SUCCEEDED(hr)) IDirectDrawSurface_Unlock(surface1, NULL);
2956 hr = IDirectDrawSurface7_Lock(surface7, NULL, &desc.desc2, 0, 0);
2957 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_Lock with desc size 0 returned %08x\n", hr);
2958 if(SUCCEEDED(hr)) IDirectDrawSurface7_Unlock(surface7, NULL);
2960 desc.desc1.dwSize = sizeof(DDSURFACEDESC) + 1;
2961 hr = IDirectDrawSurface_Lock(surface1, NULL, &desc.desc1, 0, 0);
2962 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface_Lock with desc size sizeof(DDSURFACEDESC) + 1 returned %08x\n", hr);
2963 if(SUCCEEDED(hr)) IDirectDrawSurface_Unlock(surface1, NULL);
2964 hr = IDirectDrawSurface7_Lock(surface7, NULL, &desc.desc2, 0, 0);
2965 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_Lock with desc size sizeof(DDSURFACEDESC) + 1 returned %08x\n", hr);
2966 if(SUCCEEDED(hr)) IDirectDrawSurface7_Unlock(surface7, NULL);
2968 desc.desc2.dwSize = sizeof(DDSURFACEDESC2) + 1;
2969 hr = IDirectDrawSurface_Lock(surface1, NULL, &desc.desc1, 0, 0);
2970 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface_Lock with desc size sizeof(DDSURFACEDESC2) + 1returned %08x\n", hr);
2971 if(SUCCEEDED(hr)) IDirectDrawSurface_Unlock(surface1, NULL);
2972 hr = IDirectDrawSurface7_Lock(surface7, NULL, &desc.desc2, 0, 0);
2973 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_Lock with desc size sizeof(DDSURFACEDESC2) + 1returned %08x\n", hr);
2974 if(SUCCEEDED(hr)) IDirectDrawSurface7_Unlock(surface7, NULL);
2976 IDirectDrawSurface7_Release(surface7);
2977 IDirectDrawSurface_Release(surface1);
2980 static void SurfaceCapsTest(void)
2982 DDSURFACEDESC create;
2985 IDirectDrawSurface *surface1 = NULL;
2986 DDSURFACEDESC2 create2, desc2;
2987 IDirectDrawSurface7 *surface7 = NULL;
2988 IDirectDraw7 *dd7 = NULL;
2989 DWORD create_caps[] = {
2990 DDSCAPS_OFFSCREENPLAIN,
2992 DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD,
2994 DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD | DDSCAPS_SYSTEMMEMORY,
2995 DDSCAPS_PRIMARYSURFACE,
2996 DDSCAPS_PRIMARYSURFACE | DDSCAPS_SYSTEMMEMORY,
2999 DDSCAPS_3DDEVICE | DDSCAPS_OFFSCREENPLAIN
3001 DWORD expected_caps[] = {
3002 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
3003 DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
3004 DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM | DDSCAPS_ALLOCONLOAD,
3005 DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
3006 DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD | DDSCAPS_SYSTEMMEMORY,
3007 DDSCAPS_PRIMARYSURFACE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM | DDSCAPS_VISIBLE,
3008 DDSCAPS_PRIMARYSURFACE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_VISIBLE,
3009 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
3010 DDSCAPS_ZBUFFER | DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY,
3011 DDSCAPS_3DDEVICE | DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM
3015 /* Tests various surface flags, what changes do they undergo during surface creation. Forsaken
3016 * engine expects texture surfaces without memory flag to get a video memory flag right after
3017 * creation. Currently, Wine adds DDSCAPS_FRONTBUFFER to primary surface, but native doesn't do this
3018 * for single buffered primaries. Because of this primary surface creation tests are todo_wine. No real
3019 * app is known so far to care about this. */
3021 if (!(ddcaps.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY))
3023 skip("DDraw reported no VIDEOMEMORY cap. Broken video driver? Skipping surface caps tests.\n");
3027 for (i = 0; i < sizeof(create_caps) / sizeof(DWORD); i++)
3029 memset(&create, 0, sizeof(create));
3030 create.dwSize = sizeof(create);
3031 create.ddsCaps.dwCaps = create_caps[i];
3032 create.dwFlags = DDSD_CAPS;
3034 if (!(create.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE))
3036 create.dwFlags |= DDSD_HEIGHT | DDSD_WIDTH;
3037 create.dwHeight = 128;
3038 create.dwWidth = 128;
3041 if (create.ddsCaps.dwCaps & DDSCAPS_ZBUFFER)
3043 create.dwFlags |= DDSD_PIXELFORMAT;
3044 create.ddpfPixelFormat.dwSize = sizeof(create.ddpfPixelFormat);
3045 create.ddpfPixelFormat.dwFlags = DDPF_ZBUFFER;
3046 U1(create.ddpfPixelFormat).dwZBufferBitDepth = 16;
3047 U3(create.ddpfPixelFormat).dwZBitMask = 0x0000FFFF;
3050 hr = IDirectDraw_CreateSurface(lpDD, &create, &surface1, NULL);
3051 ok(hr == DD_OK, "IDirectDraw_CreateSurface failed with %08x\n", hr);
3055 memset(&desc, 0, sizeof(desc));
3056 desc.dwSize = sizeof(DDSURFACEDESC);
3057 hr = IDirectDrawSurface_GetSurfaceDesc(surface1, &desc);
3058 ok(hr == DD_OK, "IDirectDrawSurface_GetSurfaceDesc failed with %08x\n", hr);
3060 if (!(create_caps[i] & DDSCAPS_PRIMARYSURFACE))
3061 ok(desc.ddsCaps.dwCaps == expected_caps[i],
3062 "GetSurfaceDesc test %d returned caps %x, expected %x\n", i,
3063 desc.ddsCaps.dwCaps, expected_caps[i]);
3065 todo_wine ok(desc.ddsCaps.dwCaps == expected_caps[i],
3066 "GetSurfaceDesc test %d returned caps %x, expected %x\n", i,
3067 desc.ddsCaps.dwCaps, expected_caps[i]);
3069 IDirectDrawSurface_Release(surface1);
3073 /* Test for differences in ddraw 7 */
3074 hr = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
3075 ok(hr == DD_OK, "IDirectDraw_QueryInterface returned %08x\n", hr);
3078 skip("Failed to get IDirectDraw7 interface, skipping tests\n");
3082 for (i = 0; i < sizeof(create_caps) / sizeof(DWORD); i++)
3084 memset(&create2, 0, sizeof(create2));
3085 create2.dwSize = sizeof(create2);
3086 create2.ddsCaps.dwCaps = create_caps[i];
3087 create2.dwFlags = DDSD_CAPS;
3089 if (!(create2.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE))
3091 create2.dwFlags |= DDSD_HEIGHT | DDSD_WIDTH;
3092 create2.dwHeight = 128;
3093 create2.dwWidth = 128;
3096 if (create2.ddsCaps.dwCaps & DDSCAPS_ZBUFFER)
3098 create2.dwFlags |= DDSD_PIXELFORMAT;
3099 U4(create2).ddpfPixelFormat.dwSize = sizeof(U4(create2).ddpfPixelFormat);
3100 U4(create2).ddpfPixelFormat.dwFlags = DDPF_ZBUFFER;
3101 U1(U4(create2).ddpfPixelFormat).dwZBufferBitDepth = 16;
3102 U3(U4(create2).ddpfPixelFormat).dwZBitMask = 0x0000FFFF;
3105 hr = IDirectDraw7_CreateSurface(dd7, &create2, &surface7, NULL);
3106 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
3110 memset(&desc2, 0, sizeof(desc2));
3111 desc2.dwSize = sizeof(DDSURFACEDESC2);
3112 hr = IDirectDrawSurface7_GetSurfaceDesc(surface7, &desc2);
3113 ok(hr == DD_OK, "IDirectDrawSurface_GetSurfaceDesc failed with %08x\n", hr);
3115 if (!(create_caps[i] & DDSCAPS_PRIMARYSURFACE))
3116 ok(desc2.ddsCaps.dwCaps == expected_caps[i],
3117 "GetSurfaceDesc test %d returned caps %x, expected %x\n", i,
3118 desc2.ddsCaps.dwCaps, expected_caps[i]);
3120 todo_wine ok(desc2.ddsCaps.dwCaps == expected_caps[i],
3121 "GetSurfaceDesc test %d returned caps %x, expected %x\n", i,
3122 desc2.ddsCaps.dwCaps, expected_caps[i]);
3124 IDirectDrawSurface7_Release(surface7);
3128 IDirectDraw7_Release(dd7);
3131 memset(&create, 0, sizeof(create));
3132 create.dwSize = sizeof(create);
3133 create.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
3134 create.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_VIDEOMEMORY;
3135 create.dwWidth = 64;
3136 create.dwHeight = 64;
3137 hr = IDirectDraw_CreateSurface(lpDD, &create, &surface1, NULL);
3138 ok(hr == DDERR_INVALIDCAPS, "Creating a SYSMEM | VIDMEM surface returned 0x%08x, expected DDERR_INVALIDCAPS\n", hr);
3139 if(surface1) IDirectDrawSurface_Release(surface1);
3142 static BOOL can_create_primary_surface(void)
3145 IDirectDrawSurface *surface;
3148 memset(&ddsd, 0, sizeof(ddsd));
3149 ddsd.dwSize = sizeof(ddsd);
3150 ddsd.dwFlags = DDSD_CAPS;
3151 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3152 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface, NULL);
3153 if(FAILED(hr)) return FALSE;
3154 IDirectDrawSurface_Release(surface);
3158 static void dctest_surf(IDirectDrawSurface *surf, int ddsdver) {
3160 HDC dc, dc2 = (HDC) 0x1234;
3162 DDSURFACEDESC2 ddsd2;
3164 memset(&ddsd, 0, sizeof(ddsd));
3165 ddsd.dwSize = sizeof(ddsd);
3166 memset(&ddsd2, 0, sizeof(ddsd2));
3167 ddsd2.dwSize = sizeof(ddsd2);
3169 hr = IDirectDrawSurface_GetDC(surf, &dc);
3170 ok(hr == DD_OK, "IDirectDrawSurface_GetDC failed: 0x%08x\n", hr);
3172 hr = IDirectDrawSurface_GetDC(surf, &dc2);
3173 ok(hr == DDERR_DCALREADYCREATED, "IDirectDrawSurface_GetDC failed: 0x%08x\n", hr);
3174 ok(dc2 == (HDC) 0x1234, "The failed GetDC call changed the dc: %p\n", dc2);
3176 hr = IDirectDrawSurface_Lock(surf, NULL, ddsdver == 1 ? &ddsd : ((DDSURFACEDESC *) &ddsd2), 0, NULL);
3177 ok(hr == DDERR_SURFACEBUSY, "IDirectDrawSurface_Lock returned 0x%08x, expected DDERR_ALREADYLOCKED\n", hr);
3179 hr = IDirectDrawSurface_ReleaseDC(surf, dc);
3180 ok(hr == DD_OK, "IDirectDrawSurface_ReleaseDC failed: 0x%08x\n", hr);
3181 hr = IDirectDrawSurface_ReleaseDC(surf, dc);
3182 ok(hr == DDERR_NODC, "IDirectDrawSurface_ReleaseDC returned 0x%08x, expected DDERR_NODC\n", hr);
3185 static void GetDCTest(void)
3188 DDSURFACEDESC2 ddsd2;
3189 IDirectDrawSurface *surf;
3190 IDirectDrawSurface2 *surf2;
3191 IDirectDrawSurface4 *surf4;
3192 IDirectDrawSurface7 *surf7;
3193 IDirectDrawSurface *tmp;
3194 IDirectDrawSurface7 *tmp7;
3202 memset(&ddsd, 0, sizeof(ddsd));
3203 ddsd.dwSize = sizeof(ddsd);
3204 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
3207 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
3208 memset(&ddsd2, 0, sizeof(ddsd2));
3209 ddsd2.dwSize = sizeof(ddsd2);
3210 ddsd2.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
3212 ddsd2.dwHeight = 64;
3213 ddsd2.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
3215 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &surf, NULL);
3216 ok(hr == DD_OK, "IDirectDraw_CreateSurface failed: 0x%08x\n", hr);
3217 dctest_surf(surf, 1);
3218 IDirectDrawSurface_Release(surf);
3220 hr = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw2, (void **) &dd2);
3221 ok(hr == DD_OK, "IDirectDraw_QueryInterface failed: 0x%08x\n", hr);
3223 hr = IDirectDraw2_CreateSurface(dd2, &ddsd, &surf, NULL);
3224 ok(hr == DD_OK, "IDirectDraw2_CreateSurface failed: 0x%08x\n", hr);
3225 dctest_surf(surf, 1);
3227 hr = IDirectDrawSurface_QueryInterface(surf, &IID_IDirectDrawSurface2, (void **) &surf2);
3228 ok(hr == DD_OK, "IDirectDrawSurface_QueryInterface failed: 0x%08x\n", hr);
3229 dctest_surf((IDirectDrawSurface *) surf2, 1);
3231 IDirectDrawSurface2_Release(surf2);
3232 IDirectDrawSurface_Release(surf);
3233 IDirectDraw2_Release(dd2);
3235 hr = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw4, (void **) &dd4);
3236 ok(hr == DD_OK, "IDirectDraw_QueryInterface failed: 0x%08x\n", hr);
3239 hr = IDirectDraw4_CreateSurface(dd4, &ddsd2, &surf4, NULL);
3240 ok(hr == DD_OK, "IDirectDraw4_CreateSurface failed: 0x%08x\n", hr);
3241 dctest_surf((IDirectDrawSurface *) surf4, 2);
3243 hr = IDirectDrawSurface4_QueryInterface(surf4, &IID_IDirectDrawSurface, (void **)&surf);
3244 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#x.\n", hr);
3246 ref = getRefcount((IUnknown *) surf);
3247 ok(ref == 1, "Refcount is %u, expected 1\n", ref);
3248 ref = getRefcount((IUnknown *) surf4);
3249 ok(ref == 1, "Refcount is %u, expected 1\n", ref);
3251 hr = IDirectDrawSurface4_GetDC(surf4, &dc);
3252 ok(SUCCEEDED(hr), "GetDC failed, hr %#x.\n", hr);
3254 hr = IDirectDraw4_GetSurfaceFromDC(dd4, dc, NULL);
3255 ok(hr == E_INVALIDARG, "Expected hr E_INVALIDARG, got %#x.\n", hr);
3257 hr = IDirectDraw4_GetSurfaceFromDC(dd4, dc, (IDirectDrawSurface4 **)&tmp);
3258 ok(SUCCEEDED(hr), "GetSurfaceFromDC failed, hr %#x.\n", hr);
3259 ok(tmp == surf, "Expected surface %p, got %p.\n\n", surf, tmp);
3261 ref = getRefcount((IUnknown *) surf);
3262 ok(ref == 2, "Refcount is %u, expected 2\n", ref);
3263 ref = getRefcount((IUnknown *) tmp);
3264 ok(ref == 2, "Refcount is %u, expected 2\n", ref);
3265 ref = getRefcount((IUnknown *) surf4);
3266 ok(ref == 1, "Refcount is %u, expected 1\n", ref);
3268 hr = IDirectDrawSurface4_ReleaseDC(surf4, dc);
3269 ok(SUCCEEDED(hr), "ReleaseDC failed, hr %#x.\n", hr);
3271 IDirectDrawSurface_Release(tmp);
3273 dc = CreateCompatibleDC(NULL);
3274 ok(!!dc, "CreateCompatibleDC failed.\n");
3276 tmp = (IDirectDrawSurface *)0xdeadbeef;
3277 hr = IDirectDraw4_GetSurfaceFromDC(dd4, dc, (IDirectDrawSurface4 **)&tmp);
3278 ok(hr == DDERR_NOTFOUND, "GetSurfaceFromDC failed, hr %#x.\n", hr);
3279 ok(!tmp, "Expected surface NULL, got %p.\n", tmp);
3281 ok(DeleteDC(dc), "DeleteDC failed.\n");
3283 tmp = (IDirectDrawSurface *)0xdeadbeef;
3284 hr = IDirectDraw4_GetSurfaceFromDC(dd4, NULL, (IDirectDrawSurface4 **)&tmp);
3285 ok(hr == DDERR_NOTFOUND, "GetSurfaceFromDC failed, hr %#x.\n", hr);
3286 ok(!tmp, "Expected surface NULL, got %p.\n", tmp);
3288 IDirectDrawSurface4_Release(surf4);
3289 IDirectDrawSurface_Release(surf);
3290 IDirectDraw4_Release(dd4);
3292 hr = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
3293 ok(hr == DD_OK, "IDirectDraw_QueryInterface failed: 0x%08x\n", hr);
3295 hr = IDirectDraw7_CreateSurface(dd7, &ddsd2, &surf7, NULL);
3296 ok(hr == DD_OK, "IDirectDraw7_CreateSurface failed: 0x%08x\n", hr);
3297 dctest_surf((IDirectDrawSurface *) surf7, 2);
3299 hr = IDirectDrawSurface7_GetDC(surf7, &dc);
3300 ok(SUCCEEDED(hr), "GetDC failed, hr %#x.\n", hr);
3302 hr = IDirectDraw7_GetSurfaceFromDC(dd7, dc, NULL);
3303 ok(hr == E_INVALIDARG, "Expected hr E_INVALIDARG, got %#x.\n", hr);
3305 hr = IDirectDraw7_GetSurfaceFromDC(dd7, dc, &tmp7);
3306 ok(SUCCEEDED(hr), "GetSurfaceFromDC failed, hr %#x.\n", hr);
3307 ok(tmp7 == surf7, "Expected surface %p, got %p.\n\n", surf7, tmp7);
3308 IDirectDrawSurface7_Release(tmp7);
3310 hr = IDirectDrawSurface7_ReleaseDC(surf7, dc);
3311 ok(SUCCEEDED(hr), "ReleaseDC failed, hr %#x.\n", hr);
3313 dc = CreateCompatibleDC(NULL);
3314 ok(!!dc, "CreateCompatibleDC failed.\n");
3316 tmp7 = (IDirectDrawSurface7 *)0xdeadbeef;
3317 hr = IDirectDraw7_GetSurfaceFromDC(dd7, dc, &tmp7);
3318 ok(hr == DDERR_NOTFOUND, "GetSurfaceFromDC failed, hr %#x.\n", hr);
3319 ok(!tmp7, "Expected surface NULL, got %p.\n", tmp7);
3321 ok(DeleteDC(dc), "DeleteDC failed.\n");
3323 tmp7 = (IDirectDrawSurface7 *)0xdeadbeef;
3324 hr = IDirectDraw7_GetSurfaceFromDC(dd7, NULL, (IDirectDrawSurface7 **)&tmp7);
3325 ok(hr == DDERR_NOTFOUND, "GetSurfaceFromDC failed, hr %#x.\n", hr);
3326 ok(!tmp7, "Expected surface NULL, got %p.\n", tmp7);
3328 IDirectDrawSurface7_Release(surf7);
3329 IDirectDraw7_Release(dd7);
3332 static void GetDCFormatTest(void)
3334 DDSURFACEDESC2 ddsd;
3336 IDirectDrawSurface7 *surface;
3351 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
3352 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
3359 sizeof(DDPIXELFORMAT), DDPF_RGB, 0,
3360 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0x00000000}
3367 sizeof(DDPIXELFORMAT), DDPF_RGB, 0,
3368 {32}, {0x000000ff}, {0x0000ff00}, {0x00ff0000}, {0x00000000}
3371 DDERR_CANTCREATEDC /* Vista+ */
3376 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
3377 {32}, {0x000000ff}, {0x0000ff00}, {0x00ff0000}, {0xff000000}
3380 DDERR_CANTCREATEDC /* Vista+ */
3385 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
3386 {16}, {0x00000f00}, {0x000000f0}, {0x0000000f}, {0x0000f000}
3389 DDERR_CANTCREATEDC /* Vista+ */
3394 sizeof(DDPIXELFORMAT), DDPF_RGB, 0,
3395 {16}, {0x00000f00}, {0x000000f0}, {0x0000000f}, {0x00000000}
3398 DDERR_CANTCREATEDC /* Vista+ */
3403 sizeof(DDPIXELFORMAT), DDPF_RGB, 0,
3404 {16}, {0x0000F800}, {0x000007E0}, {0x0000001F}, {0x00000000}
3411 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
3412 {16}, {0x00007C00}, {0x000003E0}, {0x0000001F}, {0x00008000}
3419 sizeof(DDPIXELFORMAT), DDPF_RGB, 0,
3420 {16}, {0x00007C00}, {0x000003E0}, {0x0000001F}, {0x00000000}
3427 sizeof(DDPIXELFORMAT), DDPF_RGB, 0,
3428 { 8}, {0x000000E0}, {0x0000001C}, {0x00000003}, {0x00000000}
3433 /* Untested, windows test machine didn't support this format */
3434 "D3DFMT_A2R10G10B10",
3436 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
3437 {32}, {0xC0000000}, {0x3FF00000}, {0x000FFC00}, {0x000003FF}
3442 * GetDC on a P8 surface fails unless the display mode is 8 bpp. This is not
3443 * implemented in wine yet, so disable the test for now. Succeeding P8 getDC
3444 * calls are tested in the ddraw.visual test.
3449 sizeof(DDPIXELFORMAT), DDPF_PALETTEINDEXED8 | DDPF_RGB, 0,
3450 {8 }, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}
3458 sizeof(DDPIXELFORMAT), DDPF_LUMINANCE, 0,
3459 {8 }, {0x000000ff}, {0x00000000}, {0x00000000}, {0x00000000}
3466 sizeof(DDPIXELFORMAT), DDPF_ALPHAPIXELS | DDPF_LUMINANCE, 0,
3467 {16}, {0x000000ff}, {0x00000000}, {0x00000000}, {0x0000ff00}
3474 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('D','X','T','1'),
3475 {0 }, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}
3482 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('D','X','T','2'),
3483 {0 }, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}
3490 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('D','X','T','3'),
3491 {0 }, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}
3498 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('D','X','T','4'),
3499 {0 }, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}
3506 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('D','X','T','5'),
3507 {0 }, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}
3513 hr = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
3514 ok(hr == DD_OK, "IDirectDraw_QueryInterface failed, hr = 0x%08x\n", hr);
3516 for(i = 0; i < (sizeof(testdata) / sizeof(testdata[0])); i++)
3518 memset(&ddsd, 0, sizeof(ddsd));
3519 ddsd.dwSize = sizeof(ddsd);
3520 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
3523 U4(ddsd).ddpfPixelFormat = testdata[i].fmt;
3524 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
3526 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface, NULL);
3529 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
3530 ddsd.ddsCaps.dwCaps2 = DDSCAPS2_TEXTUREMANAGE;
3531 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface, NULL);
3534 skip("IDirectDraw7_CreateSurface failed, hr = 0x%08x, format %s\n", hr, testdata[i].name);
3539 dc = (void *) 0x1234;
3540 hr = IDirectDrawSurface7_GetDC(surface, &dc);
3541 if(testdata[i].getdc_capable)
3544 (testdata[i].alt_result && hr == testdata[i].alt_result),
3545 "GetDC on a %s surface failed(0x%08x), expected it to work\n",
3546 testdata[i].name, hr);
3550 ok(FAILED(hr), "GetDC on a %s surface succeeded(0x%08x), expected it to fail\n",
3551 testdata[i].name, hr);
3556 IDirectDrawSurface7_ReleaseDC(surface, dc);
3557 ok(hr == DD_OK, "IDirectDrawSurface7_ReleaseDC failed, hr = 0x%08x\n", hr);
3562 ok(dc == NULL, "After failed GetDC dc is %p\n", dc);
3565 IDirectDrawSurface7_Release(surface);
3568 IDirectDraw7_Release(dd7);
3571 static void BackBufferCreateSurfaceTest(void)
3574 DDSURFACEDESC created_ddsd;
3575 DDSURFACEDESC2 ddsd2;
3576 IDirectDrawSurface *surf;
3577 IDirectDrawSurface4 *surf4;
3578 IDirectDrawSurface7 *surf7;
3584 const DWORD caps = DDSCAPS_BACKBUFFER;
3585 const DWORD expected_caps = DDSCAPS_BACKBUFFER | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM;
3587 if (!(ddcaps.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY))
3589 skip("DDraw reported no VIDEOMEMORY cap. Broken video driver? Skipping surface caps tests.\n");
3593 memset(&ddsd, 0, sizeof(ddsd));
3594 ddsd.dwSize = sizeof(ddsd);
3595 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
3598 ddsd.ddsCaps.dwCaps = caps;
3599 memset(&ddsd2, 0, sizeof(ddsd2));
3600 ddsd2.dwSize = sizeof(ddsd2);
3601 ddsd2.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
3603 ddsd2.dwHeight = 64;
3604 ddsd2.ddsCaps.dwCaps = caps;
3605 memset(&created_ddsd, 0, sizeof(created_ddsd));
3606 created_ddsd.dwSize = sizeof(DDSURFACEDESC);
3608 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &surf, NULL);
3609 ok(SUCCEEDED(hr), "IDirectDraw_CreateSurface failed: 0x%08x\n", hr);
3612 hr = IDirectDrawSurface_GetSurfaceDesc(surf, &created_ddsd);
3613 ok(SUCCEEDED(hr), "IDirectDraw_GetSurfaceDesc failed: 0x%08x\n", hr);
3614 ok(created_ddsd.ddsCaps.dwCaps == expected_caps,
3615 "GetSurfaceDesc returned caps %x, expected %x\n", created_ddsd.ddsCaps.dwCaps,
3617 IDirectDrawSurface_Release(surf);
3620 hr = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw2, (void **) &dd2);
3621 ok(SUCCEEDED(hr), "IDirectDraw_QueryInterface failed: 0x%08x\n", hr);
3623 hr = IDirectDraw2_CreateSurface(dd2, &ddsd, &surf, NULL);
3624 ok(hr == DDERR_INVALIDCAPS, "IDirectDraw2_CreateSurface didn't return %x08x, but %x08x\n",
3625 DDERR_INVALIDCAPS, hr);
3627 IDirectDraw2_Release(dd2);
3629 hr = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw4, (void **) &dd4);
3630 ok(SUCCEEDED(hr), "IDirectDraw_QueryInterface failed: 0x%08x\n", hr);
3632 hr = IDirectDraw4_CreateSurface(dd4, &ddsd2, &surf4, NULL);
3633 ok(hr == DDERR_INVALIDCAPS, "IDirectDraw4_CreateSurface didn't return %x08x, but %x08x\n",
3634 DDERR_INVALIDCAPS, hr);
3636 IDirectDraw4_Release(dd4);
3638 hr = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
3639 ok(SUCCEEDED(hr), "IDirectDraw_QueryInterface failed: 0x%08x\n", hr);
3641 hr = IDirectDraw7_CreateSurface(dd7, &ddsd2, &surf7, NULL);
3642 ok(hr == DDERR_INVALIDCAPS, "IDirectDraw7_CreateSurface didn't return %x08x, but %x08x\n",
3643 DDERR_INVALIDCAPS, hr);
3645 IDirectDraw7_Release(dd7);
3648 static void BackBufferAttachmentFlipTest(void)
3651 IDirectDrawSurface *surface1, *surface2, *surface3, *surface4;
3653 HWND window = CreateWindow( "static", "ddraw_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
3655 hr = IDirectDraw_SetCooperativeLevel(lpDD, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3656 ok(hr == DD_OK, "SetCooperativeLevel returned %08x\n", hr);
3658 /* Perform attachment tests on a back-buffer */
3659 memset(&ddsd, 0, sizeof(ddsd));
3660 ddsd.dwSize = sizeof(ddsd);
3661 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
3662 ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;
3663 ddsd.dwWidth = GetSystemMetrics(SM_CXSCREEN);
3664 ddsd.dwHeight = GetSystemMetrics(SM_CYSCREEN);
3665 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface2, NULL);
3666 ok(SUCCEEDED(hr), "CreateSurface returned: %x\n",hr);
3668 if (surface2 != NULL)
3670 /* Try a single primary and a two back buffers */
3671 memset(&ddsd, 0, sizeof(ddsd));
3672 ddsd.dwSize = sizeof(ddsd);
3673 ddsd.dwFlags = DDSD_CAPS;
3674 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3675 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface1, NULL);
3676 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
3678 memset(&ddsd, 0, sizeof(ddsd));
3679 ddsd.dwSize = sizeof(ddsd);
3680 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
3681 ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;
3682 ddsd.dwWidth = GetSystemMetrics(SM_CXSCREEN);
3683 ddsd.dwHeight = GetSystemMetrics(SM_CYSCREEN);
3684 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface3, NULL);
3685 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
3687 /* This one has a different size */
3688 memset(&ddsd, 0, sizeof(ddsd));
3689 ddsd.dwSize = sizeof(ddsd);
3690 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
3691 ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;
3693 ddsd.dwHeight = 128;
3694 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface4, NULL);
3695 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
3697 hr = IDirectDrawSurface_AddAttachedSurface(surface1, surface2);
3698 todo_wine ok(hr == DD_OK || broken(hr == DDERR_CANNOTATTACHSURFACE),
3699 "Attaching a back buffer to a front buffer returned %08x\n", hr);
3702 /* Try flipping the surfaces */
3703 hr = IDirectDrawSurface_Flip(surface1, NULL, DDFLIP_WAIT);
3704 todo_wine ok(hr == DD_OK, "IDirectDrawSurface_Flip returned 0x%08x\n", hr);
3705 hr = IDirectDrawSurface_Flip(surface2, NULL, DDFLIP_WAIT);
3706 todo_wine ok(hr == DDERR_NOTFLIPPABLE, "IDirectDrawSurface_Flip returned 0x%08x\n", hr);
3708 /* Try the reverse without detaching first */
3709 hr = IDirectDrawSurface_AddAttachedSurface(surface2, surface1);
3710 ok(hr == DDERR_SURFACEALREADYATTACHED, "Attaching an attached surface to its attachee returned %08x\n", hr);
3711 hr = IDirectDrawSurface_DeleteAttachedSurface(surface1, 0, surface2);
3712 ok(hr == DD_OK, "DeleteAttachedSurface failed with %08x\n", hr);
3714 hr = IDirectDrawSurface_AddAttachedSurface(surface2, surface1);
3715 todo_wine ok(hr == DD_OK || broken(hr == DDERR_CANNOTATTACHSURFACE),
3716 "Attaching a front buffer to a back buffer returned %08x\n", hr);
3719 /* Try flipping the surfaces */
3720 hr = IDirectDrawSurface_Flip(surface1, NULL, DDFLIP_WAIT);
3721 todo_wine ok(hr == DD_OK, "IDirectDrawSurface_Flip returned 0x%08x\n", hr);
3722 hr = IDirectDrawSurface_Flip(surface2, NULL, DDFLIP_WAIT);
3723 todo_wine ok(hr == DDERR_NOTFLIPPABLE, "IDirectDrawSurface_Flip returned 0x%08x\n", hr);
3725 /* Try to detach reversed */
3726 hr = IDirectDrawSurface_DeleteAttachedSurface(surface1, 0, surface2);
3727 ok(hr == DDERR_CANNOTDETACHSURFACE, "DeleteAttachedSurface returned %08x\n", hr);
3728 /* Now the proper detach */
3729 hr = IDirectDrawSurface_DeleteAttachedSurface(surface2, 0, surface1);
3730 ok(hr == DD_OK, "DeleteAttachedSurface failed with %08x\n", hr);
3732 hr = IDirectDrawSurface_AddAttachedSurface(surface2, surface3);
3733 todo_wine ok(hr == DD_OK || broken(hr == DDERR_CANNOTATTACHSURFACE),
3734 "Attaching a back buffer to another back buffer returned %08x\n", hr);
3737 /* Try flipping the surfaces */
3738 hr = IDirectDrawSurface_Flip(surface3, NULL, DDFLIP_WAIT);
3739 todo_wine ok(hr == DD_OK, "IDirectDrawSurface_Flip returned 0x%08x\n", hr);
3740 hr = IDirectDrawSurface_Flip(surface2, NULL, DDFLIP_WAIT);
3741 todo_wine ok(hr == DDERR_NOTFLIPPABLE, "IDirectDrawSurface_Flip returned 0x%08x\n", hr);
3742 hr = IDirectDrawSurface_Flip(surface1, NULL, DDFLIP_WAIT);
3743 ok(hr == DDERR_NOTFLIPPABLE, "IDirectDrawSurface_Flip returned 0x%08x\n", hr);
3745 hr = IDirectDrawSurface_DeleteAttachedSurface(surface2, 0, surface3);
3746 ok(hr == DD_OK, "DeleteAttachedSurface failed with %08x\n", hr);
3748 hr = IDirectDrawSurface_AddAttachedSurface(surface1, surface4);
3749 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a back buffer to a front buffer of different size returned %08x\n", hr);
3750 hr = IDirectDrawSurface_AddAttachedSurface(surface4, surface1);
3751 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a front buffer to a back buffer of different size returned %08x\n", hr);
3753 IDirectDrawSurface_Release(surface4);
3754 IDirectDrawSurface_Release(surface3);
3755 IDirectDrawSurface_Release(surface2);
3756 IDirectDrawSurface_Release(surface1);
3759 hr =IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_NORMAL);
3760 ok(hr == DD_OK, "SetCooperativeLevel returned %08x\n", hr);
3762 DestroyWindow(window);
3765 static void CreateSurfaceBadCapsSizeTest(void)
3767 DDSURFACEDESC ddsd_ok;
3768 DDSURFACEDESC ddsd_bad1;
3769 DDSURFACEDESC ddsd_bad2;
3770 DDSURFACEDESC ddsd_bad3;
3771 DDSURFACEDESC ddsd_bad4;
3772 DDSURFACEDESC2 ddsd2_ok;
3773 DDSURFACEDESC2 ddsd2_bad1;
3774 DDSURFACEDESC2 ddsd2_bad2;
3775 DDSURFACEDESC2 ddsd2_bad3;
3776 DDSURFACEDESC2 ddsd2_bad4;
3777 IDirectDrawSurface *surf;
3778 IDirectDrawSurface4 *surf4;
3779 IDirectDrawSurface7 *surf7;
3785 const DWORD caps = DDSCAPS_OFFSCREENPLAIN;
3787 memset(&ddsd_ok, 0, sizeof(ddsd_ok));
3788 ddsd_ok.dwSize = sizeof(ddsd_ok);
3789 ddsd_ok.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
3790 ddsd_ok.dwWidth = 64;
3791 ddsd_ok.dwHeight = 64;
3792 ddsd_ok.ddsCaps.dwCaps = caps;
3793 memcpy(&ddsd_bad1, &ddsd_ok, sizeof(ddsd_bad1));
3795 memcpy(&ddsd_bad2, &ddsd_ok, sizeof(ddsd_bad2));
3797 memcpy(&ddsd_bad3, &ddsd_ok, sizeof(ddsd_bad3));
3798 ddsd_bad3.dwSize = 0;
3799 memcpy(&ddsd_bad4, &ddsd_ok, sizeof(ddsd_bad4));
3800 ddsd_bad4.dwSize = sizeof(DDSURFACEDESC2);
3802 memset(&ddsd2_ok, 0, sizeof(ddsd2_ok));
3803 ddsd2_ok.dwSize = sizeof(ddsd2_ok);
3804 ddsd2_ok.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
3805 ddsd2_ok.dwWidth = 64;
3806 ddsd2_ok.dwHeight = 64;
3807 ddsd2_ok.ddsCaps.dwCaps = caps;
3808 memcpy(&ddsd2_bad1, &ddsd2_ok, sizeof(ddsd2_bad1));
3809 ddsd2_bad1.dwSize--;
3810 memcpy(&ddsd2_bad2, &ddsd2_ok, sizeof(ddsd2_bad2));
3811 ddsd2_bad2.dwSize++;
3812 memcpy(&ddsd2_bad3, &ddsd2_ok, sizeof(ddsd2_bad3));
3813 ddsd2_bad3.dwSize = 0;
3814 memcpy(&ddsd2_bad4, &ddsd2_ok, sizeof(ddsd2_bad4));
3815 ddsd2_bad4.dwSize = sizeof(DDSURFACEDESC);
3817 hr = IDirectDraw_CreateSurface(lpDD, &ddsd_ok, &surf, NULL);
3818 ok(SUCCEEDED(hr), "IDirectDraw_CreateSurface failed: 0x%08x\n", hr);
3819 IDirectDrawSurface_Release(surf);
3821 hr = IDirectDraw_CreateSurface(lpDD, &ddsd_bad1, &surf, NULL);
3822 ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw_CreateSurface didn't return 0x%08x, but 0x%08x\n",
3823 DDERR_INVALIDPARAMS, hr);
3824 hr = IDirectDraw_CreateSurface(lpDD, &ddsd_bad2, &surf, NULL);
3825 ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw_CreateSurface didn't return 0x%08x, but 0x%08x\n",
3826 DDERR_INVALIDPARAMS, hr);
3827 hr = IDirectDraw_CreateSurface(lpDD, &ddsd_bad3, &surf, NULL);
3828 ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw_CreateSurface didn't return 0x%08x, but 0x%08x\n",
3829 DDERR_INVALIDPARAMS, hr);
3830 hr = IDirectDraw_CreateSurface(lpDD, &ddsd_bad4, &surf, NULL);
3831 ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw_CreateSurface didn't return 0x%08x, but 0x%08x\n",
3832 DDERR_INVALIDPARAMS, hr);
3833 hr = IDirectDraw_CreateSurface(lpDD, NULL, &surf, NULL);
3834 ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw_CreateSurface didn't return 0x%08x, but 0x%08x\n",
3835 DDERR_INVALIDPARAMS, hr);
3837 hr = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw2, (void **) &dd2);
3838 ok(SUCCEEDED(hr), "IDirectDraw_QueryInterface failed: 0x%08x\n", hr);
3840 hr = IDirectDraw2_CreateSurface(dd2, &ddsd_ok, &surf, NULL);
3841 ok(SUCCEEDED(hr), "IDirectDraw2_CreateSurface failed: 0x%08x\n", hr);
3842 IDirectDrawSurface_Release(surf);
3844 hr = IDirectDraw2_CreateSurface(dd2, &ddsd_bad1, &surf, NULL);
3845 ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw2_CreateSurface didn't return 0x%08x, but 0x%08x\n",
3846 DDERR_INVALIDPARAMS, hr);
3847 hr = IDirectDraw2_CreateSurface(dd2, &ddsd_bad2, &surf, NULL);
3848 ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw2_CreateSurface didn't return 0x%08x, but 0x%08x\n",
3849 DDERR_INVALIDPARAMS, hr);
3850 hr = IDirectDraw2_CreateSurface(dd2, &ddsd_bad3, &surf, NULL);
3851 ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw2_CreateSurface didn't return 0x%08x, but 0x%08x\n",
3852 DDERR_INVALIDPARAMS, hr);
3853 hr = IDirectDraw2_CreateSurface(dd2, &ddsd_bad4, &surf, NULL);
3854 ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw2_CreateSurface didn't return 0x%08x, but 0x%08x\n",
3855 DDERR_INVALIDPARAMS, hr);
3856 hr = IDirectDraw2_CreateSurface(dd2, NULL, &surf, NULL);
3857 ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw2_CreateSurface didn't return 0x%08x, but 0x%08x\n",
3858 DDERR_INVALIDPARAMS, hr);
3860 IDirectDraw2_Release(dd2);
3862 hr = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw4, (void **) &dd4);
3863 ok(SUCCEEDED(hr), "IDirectDraw_QueryInterface failed: 0x%08x\n", hr);
3865 hr = IDirectDraw4_CreateSurface(dd4, &ddsd2_ok, &surf4, NULL);
3866 ok(SUCCEEDED(hr), "IDirectDraw4_CreateSurface failed: 0x%08x\n", hr);
3867 IDirectDrawSurface4_Release(surf4);
3869 hr = IDirectDraw4_CreateSurface(dd4, &ddsd2_bad1, &surf4, NULL);
3870 ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw4_CreateSurface didn't return 0x%08x, but 0x%08x\n",
3871 DDERR_INVALIDPARAMS, hr);
3872 hr = IDirectDraw4_CreateSurface(dd4, &ddsd2_bad2, &surf4, NULL);
3873 ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw4_CreateSurface didn't return 0x%08x, but 0x%08x\n",
3874 DDERR_INVALIDPARAMS, hr);
3875 hr = IDirectDraw4_CreateSurface(dd4, &ddsd2_bad3, &surf4, NULL);
3876 ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw4_CreateSurface didn't return 0x%08x, but 0x%08x\n",
3877 DDERR_INVALIDPARAMS, hr);
3878 hr = IDirectDraw4_CreateSurface(dd4, &ddsd2_bad4, &surf4, NULL);
3879 ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw4_CreateSurface didn't return 0x%08x, but 0x%08x\n",
3880 DDERR_INVALIDPARAMS, hr);
3881 hr = IDirectDraw4_CreateSurface(dd4, NULL, &surf4, NULL);
3882 ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw4_CreateSurface didn't return 0x%08x, but 0x%08x\n",
3883 DDERR_INVALIDPARAMS, hr);
3885 IDirectDraw4_Release(dd4);
3887 hr = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
3888 ok(SUCCEEDED(hr), "IDirectDraw_QueryInterface failed: 0x%08x\n", hr);
3890 hr = IDirectDraw7_CreateSurface(dd7, &ddsd2_ok, &surf7, NULL);
3891 ok(SUCCEEDED(hr), "IDirectDraw7_CreateSurface failed: 0x%08x\n", hr);
3892 IDirectDrawSurface7_Release(surf7);
3894 hr = IDirectDraw7_CreateSurface(dd7, &ddsd2_bad1, &surf7, NULL);
3895 ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw7_CreateSurface didn't return 0x%08x, but 0x%08x\n",
3896 DDERR_INVALIDPARAMS, hr);
3897 hr = IDirectDraw7_CreateSurface(dd7, &ddsd2_bad2, &surf7, NULL);
3898 ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw7_CreateSurface didn't return 0x%08x, but 0x%08x\n",
3899 DDERR_INVALIDPARAMS, hr);
3900 hr = IDirectDraw7_CreateSurface(dd7, &ddsd2_bad3, &surf7, NULL);
3901 ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw7_CreateSurface didn't return 0x%08x, but 0x%08x\n",
3902 DDERR_INVALIDPARAMS, hr);
3903 hr = IDirectDraw7_CreateSurface(dd7, &ddsd2_bad4, &surf7, NULL);
3904 ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw7_CreateSurface didn't return 0x%08x, but 0x%08x\n",
3905 DDERR_INVALIDPARAMS, hr);
3906 hr = IDirectDraw7_CreateSurface(dd7, NULL, &surf7, NULL);
3907 ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw7_CreateSurface didn't return 0x%08x, but 0x%08x\n",
3908 DDERR_INVALIDPARAMS, hr);
3910 IDirectDraw7_Release(dd7);
3913 static void reset_ddsd(DDSURFACEDESC *ddsd)
3915 memset(ddsd, 0, sizeof(*ddsd));
3916 ddsd->dwSize = sizeof(*ddsd);
3919 static void no_ddsd_caps_test(void)
3923 IDirectDrawSurface *surface;
3926 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
3928 ddsd.dwHeight = 128;
3929 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
3930 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface, NULL);
3931 ok(SUCCEEDED(hr), "IDirectDraw_CreateSurface failed, hr %#x.\n", hr);
3933 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &ddsd);
3934 IDirectDrawSurface_Release(surface);
3935 ok(ddsd.dwFlags & DDSD_CAPS, "DDSD_CAPS is not set\n");
3936 ok(ddsd.ddsCaps.dwCaps & DDSCAPS_OFFSCREENPLAIN, "DDSCAPS_OFFSCREENPLAIN is not set\n");
3939 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3940 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface, NULL);
3941 ok(SUCCEEDED(hr), "IDirectDraw_CreateSurface failed, hr %#x.\n", hr);
3943 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &ddsd);
3944 IDirectDrawSurface_Release(surface);
3945 ok(ddsd.dwFlags & DDSD_CAPS, "DDSD_CAPS is not set\n");
3946 ok(ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE, "DDSCAPS_OFFSCREENPLAIN is not set\n");
3949 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
3951 ddsd.dwHeight = 128;
3952 ddsd.ddsCaps.dwCaps = DDSCAPS_VIDEOMEMORY | DDSCAPS_SYSTEMMEMORY;
3953 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface, NULL);
3954 ok(hr == DDERR_INVALIDCAPS, "IDirectDraw_CreateSurface returned %#x, expected DDERR_INVALIDCAPS.\n", hr);
3957 static void dump_format(const DDPIXELFORMAT *fmt)
3959 trace("dwFlags %08x, FourCC %08x, dwZBufferBitDepth %u, stencil %u\n", fmt->dwFlags, fmt->dwFourCC,
3960 U1(*fmt).dwZBufferBitDepth, U2(*fmt).dwStencilBitDepth);
3961 trace("dwZBitMask %08x, dwStencilBitMask %08x, dwRGBZBitMask %08x\n", U3(*fmt).dwZBitMask,
3962 U4(*fmt).dwStencilBitMask, U5(*fmt).dwRGBZBitMask);
3965 static void zbufferbitdepth_test(void)
3969 ZFMT_SUPPORTED_ALWAYS,
3970 ZFMT_SUPPORTED_NEVER,
3971 ZFMT_SUPPORTED_HWDEPENDENT
3976 enum zfmt_succeed supported;
3982 16, ZFMT_SUPPORTED_ALWAYS,
3984 sizeof(DDPIXELFORMAT), DDPF_ZBUFFER, 0,
3985 {16}, {0}, {0x0000ffff}, {0x00000000}, {0x00000000}
3989 24, ZFMT_SUPPORTED_HWDEPENDENT,
3991 sizeof(DDPIXELFORMAT), DDPF_ZBUFFER, 0,
3992 {24}, {0}, {0x00ffffff}, {0x00000000}, {0x00000000}
3996 32, ZFMT_SUPPORTED_HWDEPENDENT,
3998 sizeof(DDPIXELFORMAT), DDPF_ZBUFFER, 0,
3999 {32}, {0}, {0xffffffff}, {0x00000000}, {0x00000000}
4002 /* Returns DDERR_INVALIDPARAMS instead of DDERR_INVALIDPIXELFORMAT.
4005 0, ZFMT_SUPPORTED_NEVER
4009 15, ZFMT_SUPPORTED_NEVER
4012 28, ZFMT_SUPPORTED_NEVER
4015 40, ZFMT_SUPPORTED_NEVER
4020 IDirectDrawSurface *surface;
4025 memset(&caps, 0, sizeof(caps));
4026 caps.dwSize = sizeof(caps);
4027 hr = IDirectDraw_GetCaps(lpDD, &caps, NULL);
4028 ok(SUCCEEDED(hr), "IDirectDraw_GetCaps failed, hr %#x.\n", hr);
4029 if (!(caps.ddsCaps.dwCaps & DDSCAPS_ZBUFFER))
4031 skip("Z buffers not supported, skipping DDSD_ZBUFFERBITDEPTH test\n");
4035 for (i = 0; i < (sizeof(test_data) / sizeof(*test_data)); i++)
4038 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_ZBUFFERBITDEPTH;
4039 ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
4041 ddsd.dwHeight = 256;
4042 U2(ddsd).dwZBufferBitDepth = test_data[i].depth;
4044 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface, NULL);
4045 if (test_data[i].supported == ZFMT_SUPPORTED_ALWAYS)
4047 ok(SUCCEEDED(hr), "IDirectDraw_CreateSurface failed, hr %#x.\n", hr);
4049 else if (test_data[i].supported == ZFMT_SUPPORTED_NEVER)
4051 ok(hr == DDERR_INVALIDPIXELFORMAT, "IDirectDraw_CreateSurface returned %#x, expected %x.\n",
4052 hr, DDERR_INVALIDPIXELFORMAT);
4054 if (!surface) continue;
4057 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &ddsd);
4058 ok(SUCCEEDED(hr), "IDirectDrawSurface_GetSurfaceDesc failed, hr %#x.\n", hr);
4059 IDirectDrawSurface_Release(surface);
4061 ok(ddsd.dwFlags & DDSD_ZBUFFERBITDEPTH, "DDSD_ZBUFFERBITDEPTH is not set\n");
4062 ok(!(ddsd.dwFlags & DDSD_PIXELFORMAT), "DDSD_PIXELFORMAT is set\n");
4063 /* Yet the ddpfPixelFormat member contains valid data */
4064 if (memcmp(&ddsd.ddpfPixelFormat, &test_data[i].pf, ddsd.ddpfPixelFormat.dwSize))
4066 ok(0, "Unexpected format for depth %u\n", test_data[i].depth);
4067 dump_format(&ddsd.ddpfPixelFormat);
4071 /* DDSD_ZBUFFERBITDEPTH vs DDSD_PIXELFORMAT? */
4073 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_ZBUFFERBITDEPTH;
4074 ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
4076 ddsd.dwHeight = 256;
4077 U2(ddsd).dwZBufferBitDepth = 24;
4078 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
4079 ddsd.ddpfPixelFormat.dwFlags = DDPF_ZBUFFER;
4080 U1(ddsd.ddpfPixelFormat).dwZBufferBitDepth = 16;
4081 U3(ddsd.ddpfPixelFormat).dwZBitMask = 0x0000ffff;
4084 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface, NULL);
4085 ok(SUCCEEDED(hr), "IDirectDraw_CreateSurface failed, hr %#x.\n", hr);
4086 if (!surface) return;
4088 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &ddsd);
4089 ok(SUCCEEDED(hr), "IDirectDrawSurface_GetSurfaceDesc failed, hr %#x.\n", hr);
4090 IDirectDrawSurface_Release(surface);
4091 ok(U1(ddsd.ddpfPixelFormat).dwZBufferBitDepth == 16, "Expected a 16bpp depth buffer, got %ubpp\n",
4092 U1(ddsd.ddpfPixelFormat).dwZBufferBitDepth);
4093 ok(ddsd.dwFlags & DDSD_ZBUFFERBITDEPTH, "DDSD_ZBUFFERBITDEPTH is not set\n");
4094 ok(!(ddsd.dwFlags & DDSD_PIXELFORMAT), "DDSD_PIXELFORMAT is set\n");
4095 ok(U2(ddsd).dwZBufferBitDepth == 16, "Expected dwZBufferBitDepth=16, got %u\n",
4096 U2(ddsd).dwZBufferBitDepth);
4098 /* DDSD_PIXELFORMAT vs invalid ZBUFFERBITDEPTH */
4100 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_PIXELFORMAT;
4101 ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
4103 ddsd.dwHeight = 256;
4104 U2(ddsd).dwZBufferBitDepth = 40;
4105 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
4106 ddsd.ddpfPixelFormat.dwFlags = DDPF_ZBUFFER;
4107 U1(ddsd.ddpfPixelFormat).dwZBufferBitDepth = 16;
4108 U3(ddsd.ddpfPixelFormat).dwZBitMask = 0x0000ffff;
4110 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface, NULL);
4111 ok(SUCCEEDED(hr), "IDirectDraw_CreateSurface failed, hr %#x.\n", hr);
4112 if (surface) IDirectDrawSurface_Release(surface);
4114 /* Create a PIXELFORMAT-only surface, see if ZBUFFERBITDEPTH is set */
4116 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_PIXELFORMAT;
4117 ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
4119 ddsd.dwHeight = 256;
4120 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
4121 ddsd.ddpfPixelFormat.dwFlags = DDPF_ZBUFFER;
4122 U1(ddsd.ddpfPixelFormat).dwZBufferBitDepth = 16;
4123 U3(ddsd.ddpfPixelFormat).dwZBitMask = 0x0000ffff;
4125 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface, NULL);
4126 ok(SUCCEEDED(hr), "IDirectDrawSurface_GetSurfaceDesc failed, hr %#x.\n", hr);
4128 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &ddsd);
4129 ok(SUCCEEDED(hr), "IDirectDrawSurface_GetSurfaceDesc failed, hr %#x.\n", hr);
4130 IDirectDrawSurface_Release(surface);
4131 ok(U1(ddsd.ddpfPixelFormat).dwZBufferBitDepth == 16, "Expected a 16bpp depth buffer, got %ubpp\n",
4132 U1(ddsd.ddpfPixelFormat).dwZBufferBitDepth);
4133 ok(ddsd.dwFlags & DDSD_ZBUFFERBITDEPTH, "DDSD_ZBUFFERBITDEPTH is not set\n");
4134 ok(!(ddsd.dwFlags & DDSD_PIXELFORMAT), "DDSD_PIXELFORMAT is set\n");
4135 ok(U2(ddsd).dwZBufferBitDepth == 16, "Expected dwZBufferBitDepth=16, got %u\n",
4136 U2(ddsd).dwZBufferBitDepth);
4139 static void test_ddsd(DDSURFACEDESC *ddsd, BOOL expect_pf, BOOL expect_zd, const char *name, DWORD z_bit_depth)
4141 IDirectDrawSurface *surface;
4142 IDirectDrawSurface7 *surface7;
4145 DDSURFACEDESC2 out2;
4147 hr = IDirectDraw_CreateSurface(lpDD, ddsd, &surface, NULL);
4148 if (hr == DDERR_NOZBUFFERHW)
4150 skip("Z buffers not supported, skipping Z flag test\n");
4153 ok(SUCCEEDED(hr), "IDirectDraw_CreateSurface failed, hr %#x.\n", hr);
4154 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirectDrawSurface7, (void **) &surface7);
4155 ok(SUCCEEDED(hr), "IDirectDrawSurface_QueryInterface failed, hr %#x.\n", hr);
4158 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &out);
4159 ok(SUCCEEDED(hr), "IDirectDrawSurface_GetSurfaceDesc failed, hr %#x.\n", hr);
4160 memset(&out2, 0, sizeof(out2));
4161 out2.dwSize = sizeof(out2);
4162 hr = IDirectDrawSurface7_GetSurfaceDesc(surface7, &out2);
4163 ok(SUCCEEDED(hr), "IDirectDrawSurface_GetSurfaceDesc failed, hr %#x.\n", hr);
4167 ok(out.dwFlags & DDSD_PIXELFORMAT, "%s surface: Expected DDSD_PIXELFORMAT to be set\n", name);
4168 ok(out2.dwFlags & DDSD_PIXELFORMAT,
4169 "%s surface: Expected DDSD_PIXELFORMAT to be set in DDSURFACEDESC2\n", name);
4173 ok(!(out.dwFlags & DDSD_PIXELFORMAT), "%s surface: Expected DDSD_PIXELFORMAT not to be set\n", name);
4174 ok(out2.dwFlags & DDSD_PIXELFORMAT,
4175 "%s surface: Expected DDSD_PIXELFORMAT to be set in DDSURFACEDESC2\n", name);
4179 ok(out.dwFlags & DDSD_ZBUFFERBITDEPTH, "%s surface: Expected DDSD_ZBUFFERBITDEPTH to be set\n", name);
4180 ok(U2(out).dwZBufferBitDepth == z_bit_depth, "ZBufferBitDepth is %u, expected %u\n",
4181 U2(out).dwZBufferBitDepth, z_bit_depth);
4182 ok(!(out2.dwFlags & DDSD_ZBUFFERBITDEPTH),
4183 "%s surface: Did not expect DDSD_ZBUFFERBITDEPTH to be set in DDSURFACEDESC2\n", name);
4184 /* dwMipMapCount and dwZBufferBitDepth share the same union */
4185 ok(U2(out2).dwMipMapCount == 0, "dwMipMapCount is %u, expected 0\n", U2(out2).dwMipMapCount);
4189 ok(!(out.dwFlags & DDSD_ZBUFFERBITDEPTH), "%s surface: Expected DDSD_ZBUFFERBITDEPTH not to be set\n", name);
4190 ok(U2(out).dwZBufferBitDepth == 0, "ZBufferBitDepth is %u, expected 0\n", U2(out).dwZBufferBitDepth);
4191 ok(!(out2.dwFlags & DDSD_ZBUFFERBITDEPTH),
4192 "%s surface: Did not expect DDSD_ZBUFFERBITDEPTH to be set in DDSURFACEDESC2\n", name);
4193 ok(U2(out2).dwMipMapCount == 0, "dwMipMapCount is %u, expected 0\n", U2(out2).dwMipMapCount);
4197 hr = IDirectDrawSurface_Lock(surface, NULL, &out, 0, NULL);
4200 hr = IDirectDrawSurface_Unlock(surface, NULL);
4201 ok(SUCCEEDED(hr), "IDirectDrawSurface_GetSurfaceDesc failed, hr %#x.\n", hr);
4203 /* DDSD_ZBUFFERBITDEPTH is never set on Nvidia, but follows GetSurfaceDesc rules on AMD */
4206 ok(!(out.dwFlags & DDSD_ZBUFFERBITDEPTH),
4207 "Lock %s surface: Expected DDSD_ZBUFFERBITDEPTH not to be set\n", name);
4210 /* DDSD_PIXELFORMAT follows GetSurfaceDesc rules */
4213 ok(out.dwFlags & DDSD_PIXELFORMAT, "%s surface: Expected DDSD_PIXELFORMAT to be set\n", name);
4217 ok(!(out.dwFlags & DDSD_PIXELFORMAT),
4218 "Lock %s surface: Expected DDSD_PIXELFORMAT not to be set\n", name);
4220 if (out.dwFlags & DDSD_ZBUFFERBITDEPTH)
4221 ok(U2(out).dwZBufferBitDepth == z_bit_depth, "ZBufferBitDepth is %u, expected %u\n",
4222 U2(out).dwZBufferBitDepth, z_bit_depth);
4224 ok(U2(out).dwZBufferBitDepth == 0, "ZBufferBitDepth is %u, expected 0\n", U2(out).dwZBufferBitDepth);
4227 hr = IDirectDrawSurface7_Lock(surface7, NULL, &out2, 0, NULL);
4228 ok(SUCCEEDED(hr), "IDirectDrawSurface7_Lock failed, hr %#x.\n", hr);
4231 hr = IDirectDrawSurface7_Unlock(surface7, NULL);
4232 ok(SUCCEEDED(hr), "IDirectDrawSurface7_Unlock failed, hr %#x.\n", hr);
4233 /* DDSD_PIXELFORMAT is always set, DDSD_ZBUFFERBITDEPTH never */
4234 ok(out2.dwFlags & DDSD_PIXELFORMAT,
4235 "Lock %s surface: Expected DDSD_PIXELFORMAT to be set in DDSURFACEDESC2\n", name);
4236 ok(!(out2.dwFlags & DDSD_ZBUFFERBITDEPTH),
4237 "Lock %s surface: Did not expect DDSD_ZBUFFERBITDEPTH to be set in DDSURFACEDESC2\n", name);
4238 ok(U2(out2).dwMipMapCount == 0, "dwMipMapCount is %u, expected 0\n", U2(out2).dwMipMapCount);
4241 IDirectDrawSurface7_Release(surface7);
4242 IDirectDrawSurface_Release(surface);
4245 static void pixelformat_flag_test(void)
4251 memset(&caps, 0, sizeof(caps));
4252 caps.dwSize = sizeof(caps);
4253 hr = IDirectDraw_GetCaps(lpDD, &caps, NULL);
4254 ok(SUCCEEDED(hr), "IDirectDraw_GetCaps failed, hr %#x.\n", hr);
4255 if (!(caps.ddsCaps.dwCaps & DDSCAPS_ZBUFFER))
4257 skip("Z buffers not supported, skipping DDSD_PIXELFORMAT test\n");
4262 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4265 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
4266 test_ddsd(&ddsd, TRUE, FALSE, "offscreen plain", ~0U);
4269 ddsd.dwFlags = DDSD_CAPS;
4270 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
4271 test_ddsd(&ddsd, TRUE, FALSE, "primary", ~0U);
4274 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_ZBUFFERBITDEPTH;
4277 U2(ddsd).dwZBufferBitDepth = 16;
4278 ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
4279 test_ddsd(&ddsd, FALSE, TRUE, "Z buffer", 16);
4282 static void set_surface_desc_test(void)
4286 IDirectDrawSurface *surface;
4287 IDirectDrawSurface3 *surface3;
4290 hr = IDirectDraw_CreateSurface(lpDD, NULL, &surface, NULL);
4291 ok(hr == DDERR_INVALIDPARAMS, "CreateSurface with a NULL DDSD returned %#x,"
4292 " expected DDERR_INVALIDPARAMS(%#x)\n", hr, DDERR_INVALIDPARAMS);
4295 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_PIXELFORMAT;
4298 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
4299 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
4300 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 32;
4301 U2(ddsd.ddpfPixelFormat).dwRBitMask = 0x00ff0000;
4302 U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x0000ff00;
4303 U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x000000ff;
4304 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY;
4306 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface, NULL);
4307 ok(SUCCEEDED(hr), "IDirectDraw_CreateSurface failed, hr %#x.\n", hr);
4309 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirectDrawSurface3, (void **) &surface3);
4310 ok(SUCCEEDED(hr), "IDirectDrawSurface_QueryInterface failed, hr %#x.\n", hr);
4311 IDirectDrawSurface_Release(surface);
4314 ddsd.dwFlags = DDSD_LPSURFACE;
4315 ddsd.lpSurface = data;
4316 hr = IDirectDrawSurface3_SetSurfaceDesc(surface3, &ddsd, 0);
4317 ok(SUCCEEDED(hr), "IDirectDrawSurface3_SetSurfaceDesc failed, hr %#x.\n", hr);
4319 /* Redundantly setting the same lpSurface is not an error */
4320 hr = IDirectDrawSurface3_SetSurfaceDesc(surface3, &ddsd, 0);
4321 ok(SUCCEEDED(hr), "IDirectDrawSurface3_SetSurfaceDesc failed, hr %#x.\n", hr);
4323 hr = IDirectDrawSurface3_SetSurfaceDesc(surface3, &ddsd, 1);
4324 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface3_SetSurfaceDesc returned %#x, expected"
4325 " DDERR_INVALIDPARAMS(%#x)\n", hr, DDERR_INVALIDPARAMS);
4327 hr = IDirectDrawSurface3_SetSurfaceDesc(surface3, NULL, 0);
4328 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface3_SetSurfaceDesc returned %#x, expected"
4329 " DDERR_INVALIDPARAMS(%#x)\n", hr, DDERR_INVALIDPARAMS);
4331 IDirectDrawSurface_Release(surface3);
4334 START_TEST(dsurface)
4339 if (!CreateDirectDraw())
4342 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw4, (void **) &dd4);
4343 if (ret == E_NOINTERFACE)
4345 win_skip("DirectDraw4 and higher are not supported\n");
4346 ReleaseDirectDraw();
4349 IDirectDraw_Release(dd4);
4351 if(!can_create_primary_surface())
4353 skip("Unable to create primary surface\n");
4357 ddcaps.dwSize = sizeof(DDCAPS);
4358 ret = IDirectDraw_GetCaps(lpDD, &ddcaps, NULL);
4361 skip("IDirectDraw_GetCaps failed with %08x\n", ret);
4365 MipMapCreationTest();
4366 SrcColorKey32BlitTest();
4377 test_lockrect_invalid();
4387 BackBufferCreateSurfaceTest();
4388 BackBufferAttachmentFlipTest();
4389 CreateSurfaceBadCapsSizeTest();
4390 no_ddsd_caps_test();
4391 zbufferbitdepth_test();
4392 pixelformat_flag_test();
4393 set_surface_desc_test();
4394 ReleaseDirectDraw();