2 * Unit tests for (a few) ddraw surface functions
4 * Copyright (C) 2005 Antoine Chavasse (a.chavasse@gmail.com)
5 * Copyright (C) 2005 Christian Costa
6 * Copyright 2005 Ivan Leo Puoti
7 * Copyright (C) 2007 Stefan Dösinger
8 * Copyright (C) 2008 Alexander Dorofeyev
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "wine/test.h"
32 static LPDIRECTDRAW lpDD = NULL;
34 static BOOL CreateDirectDraw(void)
38 rc = DirectDrawCreate(NULL, &lpDD, NULL);
39 ok(rc==DD_OK || rc==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreateEx returned: %x\n", rc);
41 trace("DirectDrawCreateEx() failed with an error %x\n", rc);
45 rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_NORMAL);
46 ok(rc==DD_OK,"SetCooperativeLevel returned: %x\n",rc);
52 static void ReleaseDirectDraw(void)
56 IDirectDraw_Release(lpDD);
61 static void MipMapCreationTest(void)
63 LPDIRECTDRAWSURFACE lpDDSMipMapTest;
67 /* First mipmap creation test: create a surface with DDSCAPS_COMPLEX,
68 DDSCAPS_MIPMAP, and DDSD_MIPMAPCOUNT. This create the number of
69 requested mipmap levels. */
70 ddsd.dwSize = sizeof(ddsd);
71 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_MIPMAPCOUNT;
72 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
73 U2(ddsd).dwMipMapCount = 3;
76 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpDDSMipMapTest, NULL);
77 ok(rc==DD_OK,"CreateSurface returned: %x\n",rc);
79 skip("failed to create surface\n");
83 /* Check the number of created mipmaps */
84 memset(&ddsd, 0, sizeof(DDSURFACEDESC));
85 ddsd.dwSize = sizeof(ddsd);
86 rc = IDirectDrawSurface_GetSurfaceDesc(lpDDSMipMapTest, &ddsd);
87 ok(rc==DD_OK,"GetSurfaceDesc returned: %x\n",rc);
88 ok(ddsd.dwFlags & DDSD_MIPMAPCOUNT,
89 "GetSurfaceDesc returned no mipmapcount.\n");
90 ok(U2(ddsd).dwMipMapCount == 3, "Incorrect mipmap count: %d.\n",
91 U2(ddsd).dwMipMapCount);
93 /* Destroy the surface. */
94 IDirectDrawSurface_Release(lpDDSMipMapTest);
97 /* Second mipmap creation test: create a surface without a mipmap
98 count, with DDSCAPS_MIPMAP and without DDSCAPS_COMPLEX.
99 This creates a single mipmap level. */
100 memset(&ddsd, 0, sizeof(DDSURFACEDESC));
101 ddsd.dwSize = sizeof(ddsd);
102 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
103 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_MIPMAP;
106 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpDDSMipMapTest, NULL);
107 ok(rc==DD_OK,"CreateSurface returned: %x\n",rc);
109 skip("failed to create surface\n");
112 /* Check the number of created mipmaps */
113 memset(&ddsd, 0, sizeof(DDSURFACEDESC));
114 ddsd.dwSize = sizeof(ddsd);
115 rc = IDirectDrawSurface_GetSurfaceDesc(lpDDSMipMapTest, &ddsd);
116 ok(rc==DD_OK,"GetSurfaceDesc returned: %x\n",rc);
117 ok(ddsd.dwFlags & DDSD_MIPMAPCOUNT,
118 "GetSurfaceDesc returned no mipmapcount.\n");
119 ok(U2(ddsd).dwMipMapCount == 1, "Incorrect mipmap count: %d.\n",
120 U2(ddsd).dwMipMapCount);
122 /* Destroy the surface. */
123 IDirectDrawSurface_Release(lpDDSMipMapTest);
126 /* Third mipmap creation test: create a surface with DDSCAPS_MIPMAP,
127 DDSCAPS_COMPLEX and without DDSD_MIPMAPCOUNT.
128 It's an undocumented features where a chain of mipmaps, starting from
129 he specified size and down to the smallest size, is automatically
131 Anarchy Online needs this feature to work. */
132 memset(&ddsd, 0, sizeof(DDSURFACEDESC));
133 ddsd.dwSize = sizeof(ddsd);
134 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
135 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
138 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpDDSMipMapTest, NULL);
139 ok(rc==DD_OK,"CreateSurface returned: %x\n",rc);
141 skip("failed to create surface\n");
145 /* Check the number of created mipmaps */
146 memset(&ddsd, 0, sizeof(DDSURFACEDESC));
147 ddsd.dwSize = sizeof(ddsd);
148 rc = IDirectDrawSurface_GetSurfaceDesc(lpDDSMipMapTest, &ddsd);
149 ok(rc==DD_OK,"GetSurfaceDesc returned: %x\n",rc);
150 ok(ddsd.dwFlags & DDSD_MIPMAPCOUNT,
151 "GetSurfaceDesc returned no mipmapcount.\n");
152 ok(U2(ddsd).dwMipMapCount == 6, "Incorrect mipmap count: %d.\n",
153 U2(ddsd).dwMipMapCount);
155 /* Destroy the surface. */
156 IDirectDrawSurface_Release(lpDDSMipMapTest);
159 /* Fourth mipmap creation test: same as above with a different texture
161 The purpose is to verify that the number of generated mipmaps is
162 dependent on the smallest dimension. */
163 memset(&ddsd, 0, sizeof(DDSURFACEDESC));
164 ddsd.dwSize = sizeof(ddsd);
165 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
166 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
169 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpDDSMipMapTest, NULL);
170 ok(rc==DD_OK,"CreateSurface returned: %x\n",rc);
172 skip("failed to create surface\n");
176 /* Check the number of created mipmaps */
177 memset(&ddsd, 0, sizeof(DDSURFACEDESC));
178 ddsd.dwSize = sizeof(ddsd);
179 rc = IDirectDrawSurface_GetSurfaceDesc(lpDDSMipMapTest, &ddsd);
180 ok(rc==DD_OK,"GetSurfaceDesc returned: %x\n",rc);
181 ok(ddsd.dwFlags & DDSD_MIPMAPCOUNT,
182 "GetSurfaceDesc returned no mipmapcount.\n");
183 ok(U2(ddsd).dwMipMapCount == 6, "Incorrect mipmap count: %d.\n",
184 U2(ddsd).dwMipMapCount);
186 /* Destroy the surface. */
187 IDirectDrawSurface_Release(lpDDSMipMapTest);
190 /* Fifth mipmap creation test: try to create a surface with
191 DDSCAPS_COMPLEX, DDSCAPS_MIPMAP, DDSD_MIPMAPCOUNT,
192 where dwMipMapCount = 0. This should fail. */
194 ddsd.dwSize = sizeof(ddsd);
195 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_MIPMAPCOUNT;
196 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
197 U2(ddsd).dwMipMapCount = 0;
200 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpDDSMipMapTest, NULL);
201 ok(rc==DDERR_INVALIDPARAMS,"CreateSurface returned: %x\n",rc);
203 /* Destroy the surface. */
205 IDirectDrawSurface_Release(lpDDSMipMapTest);
209 static void SrcColorKey32BlitTest(void)
211 LPDIRECTDRAWSURFACE lpSrc;
212 LPDIRECTDRAWSURFACE lpDst;
213 DDSURFACEDESC ddsd, ddsd2, ddsd3;
214 DDCOLORKEY DDColorKey;
219 ddsd2.dwSize = sizeof(ddsd2);
220 ddsd2.ddpfPixelFormat.dwSize = sizeof(ddsd2.ddpfPixelFormat);
222 ddsd.dwSize = sizeof(ddsd);
223 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
224 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
225 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
228 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
229 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 32;
230 U2(ddsd.ddpfPixelFormat).dwRBitMask = 0xFF0000;
231 U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x00FF00;
232 U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x0000FF;
233 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpDst, NULL);
234 ok(rc==DD_OK,"CreateSurface returned: %x\n",rc);
236 skip("failed to create surface\n");
240 ddsd.dwFlags |= DDSD_CKSRCBLT;
241 ddsd.ddckCKSrcBlt.dwColorSpaceLowValue = 0xFF00FF;
242 ddsd.ddckCKSrcBlt.dwColorSpaceHighValue = 0xFF00FF;
243 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpSrc, NULL);
244 ok(rc==DD_OK,"CreateSurface returned: %x\n",rc);
246 skip("failed to create surface\n");
250 rc = IDirectDrawSurface_Lock(lpDst, NULL, &ddsd2, DDLOCK_WAIT, NULL);
251 ok(rc==DD_OK,"Lock returned: %x\n",rc);
252 lpData = ddsd2.lpSurface;
253 lpData[0] = 0xCCCCCCCC;
254 lpData[1] = 0xCCCCCCCC;
255 lpData[2] = 0xCCCCCCCC;
256 lpData[3] = 0xCCCCCCCC;
258 memset(&ddsd3, 0, sizeof(ddsd3));
259 ddsd3.dwSize = sizeof(ddsd3);
260 ddsd3.ddpfPixelFormat.dwSize = sizeof(ddsd3.ddpfPixelFormat);
261 rc = IDirectDrawSurface_GetSurfaceDesc(lpDst, &ddsd3);
262 ok(rc == DD_OK, "IDirectDrawSurface_GetSurfaceDesc between a lock/unlock pair returned %08x\n", rc);
263 ok(ddsd3.lpSurface == ddsd3.lpSurface, "lpSurface from GetSurfaceDesc(%p) differs from the one returned by Lock(%p)\n", ddsd3.lpSurface, ddsd2.lpSurface);
265 rc = IDirectDrawSurface_Unlock(lpDst, NULL);
266 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
268 memset(&ddsd3, 0, sizeof(ddsd3));
269 ddsd3.dwSize = sizeof(ddsd3);
270 ddsd3.ddpfPixelFormat.dwSize = sizeof(ddsd3.ddpfPixelFormat);
271 rc = IDirectDrawSurface_GetSurfaceDesc(lpDst, &ddsd3);
272 ok(rc == DD_OK, "IDirectDrawSurface_GetSurfaceDesc between a lock/unlock pair returned %08x\n", rc);
273 ok(ddsd3.lpSurface == NULL, "lpSurface from GetSurfaceDesc(%p) is not NULL after unlock\n", ddsd3.lpSurface);
275 rc = IDirectDrawSurface_Lock(lpSrc, NULL, &ddsd2, DDLOCK_WAIT, NULL);
276 ok(rc==DD_OK,"Lock returned: %x\n",rc);
277 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
278 lpData = ddsd2.lpSurface;
279 lpData[0] = 0x77010203;
280 lpData[1] = 0x00010203;
281 lpData[2] = 0x77FF00FF;
282 lpData[3] = 0x00FF00FF;
283 rc = IDirectDrawSurface_Unlock(lpSrc, NULL);
284 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
286 IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYSRC, NULL);
288 rc = IDirectDrawSurface_Lock(lpDst, NULL, &ddsd2, DDLOCK_WAIT, NULL);
289 ok(rc==DD_OK,"Lock returned: %x\n",rc);
290 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
291 lpData = ddsd2.lpSurface;
292 /* Different behavior on some drivers / windows versions. Some versions ignore the X channel when
293 * color keying, but copy it to the destination surface. Others apply it for color keying, but
294 * do not copy it into the destination surface.
296 if(lpData[0]==0x00010203) {
297 trace("X channel was not copied into the destination surface\n");
298 ok((lpData[0]==0x00010203)&&(lpData[1]==0x00010203)&&(lpData[2]==0x00FF00FF)&&(lpData[3]==0xCCCCCCCC),
299 "Destination data after blitting is not correct\n");
301 ok((lpData[0]==0x77010203)&&(lpData[1]==0x00010203)&&(lpData[2]==0xCCCCCCCC)&&(lpData[3]==0xCCCCCCCC),
302 "Destination data after blitting is not correct\n");
304 rc = IDirectDrawSurface_Unlock(lpDst, NULL);
305 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
307 /* Also test SetColorKey */
308 IDirectDrawSurface_GetColorKey(lpSrc, DDCKEY_SRCBLT, &DDColorKey);
309 ok(DDColorKey.dwColorSpaceLowValue == 0xFF00FF && DDColorKey.dwColorSpaceHighValue == 0xFF00FF,
310 "GetColorKey does not return the colorkey used at surface creation\n");
312 DDColorKey.dwColorSpaceLowValue = 0x00FF00;
313 DDColorKey.dwColorSpaceHighValue = 0x00FF00;
314 IDirectDrawSurface_SetColorKey(lpSrc, DDCKEY_SRCBLT, &DDColorKey);
316 DDColorKey.dwColorSpaceLowValue = 0;
317 DDColorKey.dwColorSpaceHighValue = 0;
318 IDirectDrawSurface_GetColorKey(lpSrc, DDCKEY_SRCBLT, &DDColorKey);
319 ok(DDColorKey.dwColorSpaceLowValue == 0x00FF00 && DDColorKey.dwColorSpaceHighValue == 0x00FF00,
320 "GetColorKey does not return the colorkey set with SetColorKey\n");
322 ddsd.ddckCKSrcBlt.dwColorSpaceLowValue = 0;
323 ddsd.ddckCKSrcBlt.dwColorSpaceHighValue = 0;
324 IDirectDrawSurface_GetSurfaceDesc(lpSrc, &ddsd);
325 ok(ddsd.ddckCKSrcBlt.dwColorSpaceLowValue == 0x00FF00 && ddsd.ddckCKSrcBlt.dwColorSpaceHighValue == 0x00FF00,
326 "GetSurfaceDesc does not return the colorkey set with SetColorKey\n");
328 IDirectDrawSurface_Release(lpSrc);
329 IDirectDrawSurface_Release(lpDst);
331 /* start with a new set of surfaces to test the color keying parameters to blit */
332 memset(&ddsd, 0, sizeof(ddsd));
333 ddsd.dwSize = sizeof(ddsd);
334 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
335 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CKSRCBLT | DDSD_CKDESTBLT;
336 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
339 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
340 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 32;
341 U2(ddsd.ddpfPixelFormat).dwRBitMask = 0xFF0000;
342 U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x00FF00;
343 U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x0000FF;
344 ddsd.ddckCKDestBlt.dwColorSpaceLowValue = 0xFF0000;
345 ddsd.ddckCKDestBlt.dwColorSpaceHighValue = 0xFF0000;
346 ddsd.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00FF00;
347 ddsd.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00FF00;
348 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpDst, NULL);
349 ok(rc==DD_OK || rc == DDERR_NOCOLORKEYHW,"CreateSurface returned: %x\n",rc);
352 skip("Failed to create surface\n");
356 /* start with a new set of surfaces to test the color keying parameters to blit */
357 memset(&ddsd, 0, sizeof(ddsd));
358 ddsd.dwSize = sizeof(ddsd);
359 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
360 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CKSRCBLT | DDSD_CKDESTBLT;
361 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
364 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
365 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 32;
366 U2(ddsd.ddpfPixelFormat).dwRBitMask = 0xFF0000;
367 U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x00FF00;
368 U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x0000FF;
369 ddsd.ddckCKSrcBlt.dwColorSpaceLowValue = 0x0000FF;
370 ddsd.ddckCKSrcBlt.dwColorSpaceHighValue = 0x0000FF;
371 ddsd.ddckCKDestBlt.dwColorSpaceLowValue = 0x000000;
372 ddsd.ddckCKDestBlt.dwColorSpaceHighValue = 0x000000;
373 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpSrc, NULL);
374 ok(rc==DD_OK || rc == DDERR_NOCOLORKEYHW,"CreateSurface returned: %x\n",rc);
377 skip("Failed to create surface\n");
378 IDirectDrawSurface_Release(lpDst);
382 memset(&fx, 0, sizeof(fx));
383 fx.dwSize = sizeof(fx);
384 fx.ddckSrcColorkey.dwColorSpaceHighValue = 0x110000;
385 fx.ddckSrcColorkey.dwColorSpaceLowValue = 0x110000;
386 fx.ddckDestColorkey.dwColorSpaceHighValue = 0x001100;
387 fx.ddckDestColorkey.dwColorSpaceLowValue = 0x001100;
389 rc = IDirectDrawSurface_Lock(lpSrc, NULL, &ddsd2, DDLOCK_WAIT, NULL);
390 ok(rc==DD_OK,"Lock returned: %x\n",rc);
391 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
392 lpData = ddsd2.lpSurface;
393 lpData[0] = 0x000000FF; /* Applies to src blt key in src surface */
394 lpData[1] = 0x00000000; /* Applies to dst blt key in src surface */
395 lpData[2] = 0x00FF0000; /* Dst color key in dst surface */
396 lpData[3] = 0x0000FF00; /* Src color key in dst surface */
397 lpData[4] = 0x00001100; /* Src color key in ddbltfx */
398 lpData[5] = 0x00110000; /* Dst color key in ddbltfx */
399 rc = IDirectDrawSurface_Unlock(lpSrc, NULL);
400 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
402 rc = IDirectDrawSurface_Lock(lpDst, NULL, &ddsd2, DDLOCK_WAIT, NULL);
403 ok(rc==DD_OK,"Lock returned: %x\n",rc);
404 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
405 lpData = ddsd2.lpSurface;
406 lpData[0] = 0x55555555;
407 lpData[1] = 0x55555555;
408 lpData[2] = 0x55555555;
409 lpData[3] = 0x55555555;
410 lpData[4] = 0x55555555;
411 lpData[5] = 0x55555555;
412 rc = IDirectDrawSurface_Unlock(lpDst, NULL);
413 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
415 /* Test a blit without keying */
416 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, 0, &fx);
417 ok(rc == DD_OK, "IDirectDrawSurface_Blt returned %08x\n", rc);
419 rc = IDirectDrawSurface_Lock(lpDst, NULL, &ddsd2, DDLOCK_WAIT, NULL);
420 ok(rc==DD_OK,"Lock returned: %x\n",rc);
421 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
422 lpData = ddsd2.lpSurface;
423 /* Should have copied src data unmodified to dst */
424 ok(lpData[0] == 0x000000FF &&
425 lpData[1] == 0x00000000 &&
426 lpData[2] == 0x00FF0000 &&
427 lpData[3] == 0x0000FF00 &&
428 lpData[4] == 0x00001100 &&
429 lpData[5] == 0x00110000, "Surface data after unkeyed blit does not match\n");
431 lpData[0] = 0x55555555;
432 lpData[1] = 0x55555555;
433 lpData[2] = 0x55555555;
434 lpData[3] = 0x55555555;
435 lpData[4] = 0x55555555;
436 lpData[5] = 0x55555555;
437 rc = IDirectDrawSurface_Unlock(lpDst, NULL);
438 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
441 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYSRC, &fx);
442 ok(rc == DD_OK, "IDirectDrawSurface_Blt returned %08x\n", rc);
444 rc = IDirectDrawSurface_Lock(lpDst, NULL, &ddsd2, DDLOCK_WAIT, NULL);
445 ok(rc==DD_OK,"Lock returned: %x\n",rc);
446 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
447 lpData = ddsd2.lpSurface;
449 ok(lpData[0] == 0x55555555 && /* Here the src key applied */
450 lpData[1] == 0x00000000 &&
451 lpData[2] == 0x00FF0000 &&
452 lpData[3] == 0x0000FF00 &&
453 lpData[4] == 0x00001100 &&
454 lpData[5] == 0x00110000, "Surface data after srckey blit does not match\n");
456 lpData[0] = 0x55555555;
457 lpData[1] = 0x55555555;
458 lpData[2] = 0x55555555;
459 lpData[3] = 0x55555555;
460 lpData[4] = 0x55555555;
461 lpData[5] = 0x55555555;
462 rc = IDirectDrawSurface_Unlock(lpDst, NULL);
463 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
466 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYSRCOVERRIDE, &fx);
467 ok(rc == DD_OK, "IDirectDrawSurface_Blt returned %08x\n", rc);
469 rc = IDirectDrawSurface_Lock(lpDst, NULL, &ddsd2, DDLOCK_WAIT, NULL);
470 ok(rc==DD_OK,"Lock returned: %x\n",rc);
471 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
472 lpData = ddsd2.lpSurface;
474 ok(lpData[0] == 0x000000FF &&
475 lpData[1] == 0x00000000 &&
476 lpData[2] == 0x00FF0000 &&
477 lpData[3] == 0x0000FF00 &&
478 lpData[4] == 0x00001100 &&
479 lpData[5] == 0x55555555, /* Override key applies here */
480 "Surface data after src override key blit does not match\n");
482 lpData[0] = 0x55555555;
483 lpData[1] = 0x55555555;
484 lpData[2] = 0x55555555;
485 lpData[3] = 0x55555555;
486 lpData[4] = 0x55555555;
487 lpData[5] = 0x55555555;
488 rc = IDirectDrawSurface_Unlock(lpDst, NULL);
489 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
491 /* Src override AND src key. That is not supposed to work */
492 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYSRC | DDBLT_KEYSRCOVERRIDE, &fx);
493 ok(rc == DDERR_INVALIDPARAMS, "IDirectDrawSurface_Blt returned %08x\n", rc);
495 /* Verify that the destination is unchanged */
496 rc = IDirectDrawSurface_Lock(lpDst, NULL, &ddsd2, DDLOCK_WAIT, NULL);
497 ok(rc==DD_OK,"Lock returned: %x\n",rc);
498 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
499 lpData = ddsd2.lpSurface;
501 ok(lpData[0] == 0x55555555 &&
502 lpData[1] == 0x55555555 &&
503 lpData[2] == 0x55555555 &&
504 lpData[3] == 0x55555555 &&
505 lpData[4] == 0x55555555 &&
506 lpData[5] == 0x55555555, /* Override key applies here */
507 "Surface data after src key blit with override does not match\n");
509 lpData[0] = 0x00FF0000; /* Dest key in dst surface */
510 lpData[1] = 0x00FF0000; /* Dest key in dst surface */
511 lpData[2] = 0x00001100; /* Dest key in override */
512 lpData[3] = 0x00001100; /* Dest key in override */
513 lpData[4] = 0x00000000; /* Dest key in src surface */
514 lpData[5] = 0x00000000; /* Dest key in src surface */
515 rc = IDirectDrawSurface_Unlock(lpDst, NULL);
516 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
519 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYDEST, &fx);
520 ok(rc == DD_OK, "IDirectDrawSurface_Blt returned %08x\n", rc);
522 rc = IDirectDrawSurface_Lock(lpDst, NULL, &ddsd2, DDLOCK_WAIT, NULL);
523 ok(rc==DD_OK,"Lock returned: %x\n",rc);
524 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
525 lpData = ddsd2.lpSurface;
527 /* DirectDraw uses the dest blit key from the SOURCE surface ! */
528 ok(lpData[0] == 0x00ff0000 &&
529 lpData[1] == 0x00ff0000 &&
530 lpData[2] == 0x00001100 &&
531 lpData[3] == 0x00001100 &&
532 lpData[4] == 0x00001100 && /* Key applies here */
533 lpData[5] == 0x00110000, /* Key applies here */
534 "Surface data after dest key blit does not match\n");
536 lpData[0] = 0x00FF0000; /* Dest key in dst surface */
537 lpData[1] = 0x00FF0000; /* Dest key in dst surface */
538 lpData[2] = 0x00001100; /* Dest key in override */
539 lpData[3] = 0x00001100; /* Dest key in override */
540 lpData[4] = 0x00000000; /* Dest key in src surface */
541 lpData[5] = 0x00000000; /* Dest key in src surface */
542 rc = IDirectDrawSurface_Unlock(lpDst, NULL);
543 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
545 /* Dest override key blit */
546 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYDESTOVERRIDE, &fx);
547 ok(rc == DD_OK, "IDirectDrawSurface_Blt returned %08x\n", rc);
549 rc = IDirectDrawSurface_Lock(lpDst, NULL, &ddsd2, DDLOCK_WAIT, NULL);
550 ok(rc==DD_OK,"Lock returned: %x\n",rc);
551 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
552 lpData = ddsd2.lpSurface;
554 ok(lpData[0] == 0x00FF0000 &&
555 lpData[1] == 0x00FF0000 &&
556 lpData[2] == 0x00FF0000 && /* Key applies here */
557 lpData[3] == 0x0000FF00 && /* Key applies here */
558 lpData[4] == 0x00000000 &&
559 lpData[5] == 0x00000000,
560 "Surface data after dest key override blit does not match\n");
562 lpData[0] = 0x00FF0000; /* Dest key in dst surface */
563 lpData[1] = 0x00FF0000; /* Dest key in dst surface */
564 lpData[2] = 0x00001100; /* Dest key in override */
565 lpData[3] = 0x00001100; /* Dest key in override */
566 lpData[4] = 0x00000000; /* Dest key in src surface */
567 lpData[5] = 0x00000000; /* Dest key in src surface */
568 rc = IDirectDrawSurface_Unlock(lpDst, NULL);
569 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
571 /* Dest override key blit. Supposed to fail too */
572 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYDEST | DDBLT_KEYDESTOVERRIDE, &fx);
573 ok(rc == DDERR_INVALIDPARAMS, "IDirectDrawSurface_Blt returned %08x\n", rc);
575 /* Check for unchanged data */
576 rc = IDirectDrawSurface_Lock(lpDst, NULL, &ddsd2, DDLOCK_WAIT, NULL);
577 ok(rc==DD_OK,"Lock returned: %x\n",rc);
578 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
579 lpData = ddsd2.lpSurface;
581 ok(lpData[0] == 0x00FF0000 &&
582 lpData[1] == 0x00FF0000 &&
583 lpData[2] == 0x00001100 && /* Key applies here */
584 lpData[3] == 0x00001100 && /* Key applies here */
585 lpData[4] == 0x00000000 &&
586 lpData[5] == 0x00000000,
587 "Surface data with dest key and dest override does not match\n");
589 lpData[0] = 0x00FF0000; /* Dest key in dst surface */
590 lpData[1] = 0x00FF0000; /* Dest key in dst surface */
591 lpData[2] = 0x00001100; /* Dest key in override */
592 lpData[3] = 0x00001100; /* Dest key in override */
593 lpData[4] = 0x00000000; /* Dest key in src surface */
594 lpData[5] = 0x00000000; /* Dest key in src surface */
595 rc = IDirectDrawSurface_Unlock(lpDst, NULL);
596 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
598 /* Modify the source data a bit to give some more conclusive results */
599 rc = IDirectDrawSurface_Lock(lpSrc, NULL, &ddsd2, DDLOCK_WAIT, NULL);
600 ok(rc==DD_OK,"Lock returned: %x\n",rc);
601 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
602 lpData = ddsd2.lpSurface;
603 lpData[5] = 0x000000FF; /* Applies to src blt key in src surface */
604 rc = IDirectDrawSurface_Unlock(lpSrc, NULL);
605 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
607 /* Source and destination key */
608 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYDEST | DDBLT_KEYSRC, &fx);
609 ok(rc == DD_OK, "IDirectDrawSurface_Blt returned %08x\n", rc);
611 rc = IDirectDrawSurface_Lock(lpDst, NULL, &ddsd2, DDLOCK_WAIT, NULL);
612 ok(rc==DD_OK,"Lock returned: %x\n",rc);
613 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
614 lpData = ddsd2.lpSurface;
616 ok(lpData[0] == 0x00FF0000 && /* Masked by Destination key */
617 lpData[1] == 0x00FF0000 && /* Masked by Destination key */
618 lpData[2] == 0x00001100 && /* Masked by Destination key */
619 lpData[3] == 0x00001100 && /* Masked by Destination key */
620 lpData[4] == 0x00001100 && /* Allowed by destination key, not masked by source key */
621 lpData[5] == 0x00000000, /* Allowed by dst key, but masked by source key */
622 "Surface data with src key and dest key blit does not match\n");
624 lpData[0] = 0x00FF0000; /* Dest key in dst surface */
625 lpData[1] = 0x00FF0000; /* Dest key in dst surface */
626 lpData[2] = 0x00001100; /* Dest key in override */
627 lpData[3] = 0x00001100; /* Dest key in override */
628 lpData[4] = 0x00000000; /* Dest key in src surface */
629 lpData[5] = 0x00000000; /* Dest key in src surface */
630 rc = IDirectDrawSurface_Unlock(lpDst, NULL);
631 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
633 /* Override keys without ddbltfx parameter fail */
634 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYDESTOVERRIDE, NULL);
635 ok(rc == DDERR_INVALIDPARAMS, "IDirectDrawSurface_Blt returned %08x\n", rc);
636 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYSRCOVERRIDE, NULL);
637 ok(rc == DDERR_INVALIDPARAMS, "IDirectDrawSurface_Blt returned %08x\n", rc);
639 /* Try blitting without keys in the source surface*/
640 rc = IDirectDrawSurface_SetColorKey(lpSrc, DDCKEY_SRCBLT, NULL);
641 ok(rc == DD_OK, "SetColorKey returned %x\n", rc);
642 rc = IDirectDrawSurface_SetColorKey(lpSrc, DDCKEY_DESTBLT, NULL);
643 ok(rc == DD_OK, "SetColorKey returned %x\n", rc);
645 /* That fails now. Do not bother to check that the data is unmodified */
646 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYSRC, &fx);
647 ok(rc == DDERR_INVALIDPARAMS, "IDirectDrawSurface_Blt returned %08x\n", rc);
649 /* Dest key blit still works. Which key is used this time??? */
650 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYDEST, &fx);
651 ok(rc == DD_OK, "IDirectDrawSurface_Blt returned %08x\n", rc);
653 /* With correctly passed override keys no key in the surface is needed.
654 * Again, the result was checked before, no need to do that again
656 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYDESTOVERRIDE, &fx);
657 ok(rc == DD_OK, "IDirectDrawSurface_Blt returned %08x\n", rc);
658 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYSRCOVERRIDE, &fx);
659 ok(rc == DD_OK, "IDirectDrawSurface_Blt returned %08x\n", rc);
661 IDirectDrawSurface_Release(lpSrc);
662 IDirectDrawSurface_Release(lpDst);
665 static void QueryInterface(void)
667 LPDIRECTDRAWSURFACE dsurface;
668 DDSURFACEDESC surface;
672 /* Create a surface */
673 ZeroMemory(&surface, sizeof(surface));
674 surface.dwSize = sizeof(surface);
675 surface.dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
676 surface.dwHeight = 10;
677 surface.dwWidth = 10;
678 ret = IDirectDraw_CreateSurface(lpDD, &surface, &dsurface, NULL);
681 ok(FALSE, "IDirectDraw::CreateSurface failed with error %x\n", ret);
685 /* Call IUnknown::QueryInterface */
686 ret = IDirectDrawSurface_QueryInterface(dsurface, 0, &object);
687 ok(ret == DDERR_INVALIDPARAMS, "IDirectDrawSurface::QueryInterface returned %x\n", ret);
689 IDirectDrawSurface_Release(dsurface);
692 /* The following tests test which interface is returned by IDirectDrawSurfaceX::GetDDInterface.
693 * It uses refcounts to test that and compares the interface addresses. Partially fits here, and
694 * partially in the refcount test
697 static ULONG getref(IUnknown *iface)
699 IUnknown_AddRef(iface);
700 return IUnknown_Release(iface);
703 static void GetDDInterface_1(void)
705 LPDIRECTDRAWSURFACE dsurface;
706 LPDIRECTDRAWSURFACE2 dsurface2;
707 DDSURFACEDESC surface;
712 ULONG ref1, ref2, ref4, ref7;
715 /* Create a surface */
716 ZeroMemory(&surface, sizeof(surface));
717 surface.dwSize = sizeof(surface);
718 surface.dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
719 surface.dwHeight = 10;
720 surface.dwWidth = 10;
721 ret = IDirectDraw_CreateSurface(lpDD, &surface, &dsurface, NULL);
724 ok(FALSE, "IDirectDraw::CreateSurface failed with error %x\n", ret);
727 ret = IDirectDrawSurface_QueryInterface(dsurface, &IID_IDirectDrawSurface2, (void **) &dsurface2);
728 ok(ret == DD_OK, "IDirectDrawSurface_QueryInterface returned %08x\n", ret);
729 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw2, (void **) &dd2);
730 ok(ret == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", ret);
731 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw4, (void **) &dd4);
732 ok(ret == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", ret);
733 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
734 ok(ret == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", ret);
736 ref1 = getref((IUnknown *) lpDD);
737 ok(ref1 == 1, "IDirectDraw refcount is %d\n", ref1);
738 ref2 = getref((IUnknown *) dd2);
739 ok(ref2 == 1, "IDirectDraw2 refcount is %d\n", ref2);
740 ref4 = getref((IUnknown *) dd4);
741 ok(ref4 == 1, "IDirectDraw4 refcount is %d\n", ref4);
742 ref7 = getref((IUnknown *) dd7);
743 ok(ref7 == 1, "IDirectDraw7 refcount is %d\n", ref7);
746 ret = IDirectDrawSurface2_GetDDInterface(dsurface2, &dd);
747 ok(ret == DD_OK, "IDirectDrawSurface7_GetDDInterface returned %08x\n", ret);
748 ok(getref((IUnknown *) lpDD) == ref1 + 1, "IDirectDraw refcount was increased by %d\n", getref((IUnknown *) lpDD) - ref1);
749 ok(getref((IUnknown *) dd2) == ref2 + 0, "IDirectDraw2 refcount was increased by %d\n", getref((IUnknown *) dd2) - ref2);
750 ok(getref((IUnknown *) dd4) == ref4 + 0, "IDirectDraw4 refcount was increased by %d\n", getref((IUnknown *) dd4) - ref4);
751 ok(getref((IUnknown *) dd7) == ref7 + 0, "IDirectDraw7 refcount was increased by %d\n", getref((IUnknown *) dd7) - ref7);
753 ok(dd == lpDD, "Returned interface pointer is not equal to the creation interface\n");
754 IUnknown_Release((IUnknown *) dd);
756 /* try a NULL pointer */
757 ret = IDirectDrawSurface2_GetDDInterface(dsurface2, NULL);
758 ok(ret == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_GetDDInterface returned %08x\n", ret);
760 IDirectDraw_Release(dd2);
761 IDirectDraw_Release(dd4);
762 IDirectDraw_Release(dd7);
763 IDirectDrawSurface2_Release(dsurface2);
764 IDirectDrawSurface_Release(dsurface);
767 static void GetDDInterface_2(void)
769 LPDIRECTDRAWSURFACE dsurface;
770 LPDIRECTDRAWSURFACE2 dsurface2;
771 DDSURFACEDESC surface;
776 ULONG ref1, ref2, ref4, ref7;
779 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw2, (void **) &dd2);
780 ok(ret == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", ret);
781 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw4, (void **) &dd4);
782 ok(ret == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", ret);
783 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
784 ok(ret == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", ret);
786 /* Create a surface */
787 ZeroMemory(&surface, sizeof(surface));
788 surface.dwSize = sizeof(surface);
789 surface.dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
790 surface.dwHeight = 10;
791 surface.dwWidth = 10;
792 ret = IDirectDraw2_CreateSurface(dd2, &surface, &dsurface, NULL);
795 ok(FALSE, "IDirectDraw::CreateSurface failed with error %x\n", ret);
798 ret = IDirectDrawSurface_QueryInterface(dsurface, &IID_IDirectDrawSurface2, (void **) &dsurface2);
799 ok(ret == DD_OK, "IDirectDrawSurface_QueryInterface returned %08x\n", ret);
801 ref1 = getref((IUnknown *) lpDD);
802 ok(ref1 == 1, "IDirectDraw refcount is %d\n", ref1);
803 ref2 = getref((IUnknown *) dd2);
804 ok(ref2 == 1, "IDirectDraw2 refcount is %d\n", ref2);
805 ref4 = getref((IUnknown *) dd4);
806 ok(ref4 == 1, "IDirectDraw4 refcount is %d\n", ref4);
807 ref7 = getref((IUnknown *) dd7);
808 ok(ref7 == 1, "IDirectDraw7 refcount is %d\n", ref7);
811 ret = IDirectDrawSurface2_GetDDInterface(dsurface2, &dd);
812 ok(ret == DD_OK, "IDirectDrawSurface7_GetDDInterface returned %08x\n", ret);
813 ok(getref((IUnknown *) lpDD) == ref1 + 0, "IDirectDraw refcount was increased by %d\n", getref((IUnknown *) lpDD) - ref1);
814 ok(getref((IUnknown *) dd2) == ref2 + 1, "IDirectDraw2 refcount was increased by %d\n", getref((IUnknown *) dd2) - ref2);
815 ok(getref((IUnknown *) dd4) == ref4 + 0, "IDirectDraw4 refcount was increased by %d\n", getref((IUnknown *) dd4) - ref4);
816 ok(getref((IUnknown *) dd7) == ref7 + 0, "IDirectDraw7 refcount was increased by %d\n", getref((IUnknown *) dd7) - ref7);
818 ok(dd == dd2, "Returned interface pointer is not equal to the creation interface\n");
819 IUnknown_Release((IUnknown *) dd);
821 IDirectDraw_Release(dd2);
822 IDirectDraw_Release(dd4);
823 IDirectDraw_Release(dd7);
824 IDirectDrawSurface2_Release(dsurface2);
825 IDirectDrawSurface_Release(dsurface);
828 static void GetDDInterface_4(void)
830 LPDIRECTDRAWSURFACE2 dsurface2;
831 LPDIRECTDRAWSURFACE4 dsurface4;
832 DDSURFACEDESC2 surface;
837 ULONG ref1, ref2, ref4, ref7;
840 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw2, (void **) &dd2);
841 ok(ret == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", ret);
842 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw4, (void **) &dd4);
843 ok(ret == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", ret);
844 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
845 ok(ret == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", ret);
847 /* Create a surface */
848 ZeroMemory(&surface, sizeof(surface));
849 surface.dwSize = sizeof(surface);
850 surface.dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
851 surface.dwHeight = 10;
852 surface.dwWidth = 10;
853 ret = IDirectDraw4_CreateSurface(dd4, &surface, &dsurface4, NULL);
856 ok(FALSE, "IDirectDraw::CreateSurface failed with error %x\n", ret);
859 ret = IDirectDrawSurface4_QueryInterface(dsurface4, &IID_IDirectDrawSurface2, (void **) &dsurface2);
860 ok(ret == DD_OK, "IDirectDrawSurface_QueryInterface returned %08x\n", ret);
862 ref1 = getref((IUnknown *) lpDD);
863 ok(ref1 == 1, "IDirectDraw refcount is %d\n", ref1);
864 ref2 = getref((IUnknown *) dd2);
865 ok(ref2 == 1, "IDirectDraw2 refcount is %d\n", ref2);
866 ref4 = getref((IUnknown *) dd4);
867 ok(ref4 == 2, "IDirectDraw4 refcount is %d\n", ref4);
868 ref7 = getref((IUnknown *) dd7);
869 ok(ref7 == 1, "IDirectDraw7 refcount is %d\n", ref7);
871 ret = IDirectDrawSurface4_GetDDInterface(dsurface4, &dd);
872 ok(ret == DD_OK, "IDirectDrawSurface7_GetDDInterface returned %08x\n", ret);
873 ok(getref((IUnknown *) lpDD) == ref1 + 0, "IDirectDraw refcount was increased by %d\n", getref((IUnknown *) lpDD) - ref1);
874 ok(getref((IUnknown *) dd2) == ref2 + 0, "IDirectDraw2 refcount was increased by %d\n", getref((IUnknown *) dd2) - ref2);
875 ok(getref((IUnknown *) dd4) == ref4 + 1, "IDirectDraw4 refcount was increased by %d\n", getref((IUnknown *) dd4) - ref4);
876 ok(getref((IUnknown *) dd7) == ref7 + 0, "IDirectDraw7 refcount was increased by %d\n", getref((IUnknown *) dd7) - ref7);
878 ok(dd == dd4, "Returned interface pointer is not equal to the creation interface\n");
879 IUnknown_Release((IUnknown *) dd);
881 /* Now test what happens if we QI the surface for some other version - It should still return the creation interface */
882 ret = IDirectDrawSurface2_GetDDInterface(dsurface2, &dd);
883 ok(ret == DD_OK, "IDirectDrawSurface7_GetDDInterface returned %08x\n", ret);
884 ok(getref((IUnknown *) lpDD) == ref1 + 0, "IDirectDraw refcount was increased by %d\n", getref((IUnknown *) lpDD) - ref1);
885 ok(getref((IUnknown *) dd2) == ref2 + 0, "IDirectDraw2 refcount was increased by %d\n", getref((IUnknown *) dd2) - ref2);
886 ok(getref((IUnknown *) dd4) == ref4 + 1, "IDirectDraw4 refcount was increased by %d\n", getref((IUnknown *) dd4) - ref4);
887 ok(getref((IUnknown *) dd7) == ref7 + 0, "IDirectDraw7 refcount was increased by %d\n", getref((IUnknown *) dd7) - ref7);
889 ok(dd == dd4, "Returned interface pointer is not equal to the creation interface\n");
890 IUnknown_Release((IUnknown *) dd);
892 IDirectDraw_Release(dd2);
893 IDirectDraw_Release(dd4);
894 IDirectDraw_Release(dd7);
895 IDirectDrawSurface4_Release(dsurface4);
896 IDirectDrawSurface2_Release(dsurface2);
899 static void GetDDInterface_7(void)
901 LPDIRECTDRAWSURFACE4 dsurface4;
902 LPDIRECTDRAWSURFACE7 dsurface7;
903 DDSURFACEDESC2 surface;
908 ULONG ref1, ref2, ref4, ref7;
911 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw2, (void **) &dd2);
912 ok(ret == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", ret);
913 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw4, (void **) &dd4);
914 ok(ret == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", ret);
915 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
916 ok(ret == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", ret);
918 /* Create a surface */
919 ZeroMemory(&surface, sizeof(surface));
920 surface.dwSize = sizeof(surface);
921 surface.dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
922 surface.dwHeight = 10;
923 surface.dwWidth = 10;
924 ret = IDirectDraw7_CreateSurface(dd7, &surface, &dsurface7, NULL);
927 ok(FALSE, "IDirectDraw::CreateSurface failed with error %x\n", ret);
930 ret = IDirectDrawSurface7_QueryInterface(dsurface7, &IID_IDirectDrawSurface4, (void **) &dsurface4);
931 ok(ret == DD_OK, "IDirectDrawSurface_QueryInterface returned %08x\n", ret);
933 ref1 = getref((IUnknown *) lpDD);
934 ok(ref1 == 1, "IDirectDraw refcount is %d\n", ref1);
935 ref2 = getref((IUnknown *) dd2);
936 ok(ref2 == 1, "IDirectDraw2 refcount is %d\n", ref2);
937 ref4 = getref((IUnknown *) dd4);
938 ok(ref4 == 1, "IDirectDraw4 refcount is %d\n", ref4);
939 ref7 = getref((IUnknown *) dd7);
940 ok(ref7 == 2, "IDirectDraw7 refcount is %d\n", ref7);
942 ret = IDirectDrawSurface7_GetDDInterface(dsurface7, &dd);
943 ok(ret == DD_OK, "IDirectDrawSurface7_GetDDInterface returned %08x\n", ret);
944 ok(getref((IUnknown *) lpDD) == ref1 + 0, "IDirectDraw refcount was increased by %d\n", getref((IUnknown *) lpDD) - ref1);
945 ok(getref((IUnknown *) dd2) == ref2 + 0, "IDirectDraw2 refcount was increased by %d\n", getref((IUnknown *) dd2) - ref2);
946 ok(getref((IUnknown *) dd4) == ref4 + 0, "IDirectDraw4 refcount was increased by %d\n", getref((IUnknown *) dd4) - ref4);
947 ok(getref((IUnknown *) dd7) == ref7 + 1, "IDirectDraw7 refcount was increased by %d\n", getref((IUnknown *) dd7) - ref7);
949 ok(dd == dd7, "Returned interface pointer is not equal to the creation interface\n");
950 IUnknown_Release((IUnknown *) dd);
952 /* Now test what happens if we QI the surface for some other version - It should still return the creation interface */
953 ret = IDirectDrawSurface4_GetDDInterface(dsurface4, &dd);
954 ok(ret == DD_OK, "IDirectDrawSurface7_GetDDInterface returned %08x\n", ret);
955 ok(getref((IUnknown *) lpDD) == ref1 + 0, "IDirectDraw refcount was increased by %d\n", getref((IUnknown *) lpDD) - ref1);
956 ok(getref((IUnknown *) dd2) == ref2 + 0, "IDirectDraw2 refcount was increased by %d\n", getref((IUnknown *) dd2) - ref2);
957 ok(getref((IUnknown *) dd4) == ref4 + 0, "IDirectDraw4 refcount was increased by %d\n", getref((IUnknown *) dd4) - ref4);
958 ok(getref((IUnknown *) dd7) == ref7 + 1, "IDirectDraw7 refcount was increased by %d\n", getref((IUnknown *) dd7) - ref7);
960 ok(dd == dd7, "Returned interface pointer is not equal to the creation interface\n");
961 IUnknown_Release((IUnknown *) dd);
963 IDirectDraw_Release(dd2);
964 IDirectDraw_Release(dd4);
965 IDirectDraw_Release(dd7);
966 IDirectDrawSurface4_Release(dsurface4);
967 IDirectDrawSurface7_Release(dsurface7);
970 static ULONG getRefcount(IUnknown *iface)
972 IUnknown_AddRef(iface);
973 return IUnknown_Release(iface);
976 static void IFaceRefCount(void)
978 LPDIRECTDRAWSURFACE surf;
979 DDSURFACEDESC surface;
981 IDirectDrawSurface2 *surf2;
982 IDirectDrawSurface2 *surf2a;
983 IDirectDrawSurface4 *surf4;
984 IDirectDrawSurface7 *surf7a;
985 IDirectDrawSurface7 *surf7b;
986 IDirect3DTexture* tex;
987 IDirect3DTexture2* tex2;
988 IDirectDrawGammaControl* gamma;
991 /* Create a surface */
992 ZeroMemory(&surface, sizeof(surface));
993 surface.dwSize = sizeof(surface);
994 surface.dwFlags = DDSD_CAPS;
995 surface.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
996 ret = IDirectDraw_CreateSurface(lpDD, &surface, &surf, NULL);
1000 ok(FALSE, "Could not create surface, skipping test\n");
1004 ref = getRefcount((IUnknown *) surf);
1005 ok(ref == 1, "Refcount is %u, expected 1\n", ref); /* Check the ref count is one */
1007 IDirectDrawSurface_QueryInterface(surf, &IID_IDirectDrawSurface2, (void **) &surf2);
1008 ref = getRefcount((IUnknown *) surf);
1009 todo_wine ok(ref == 1, "Refcount is %u, expected 1\n", ref); /* Check the ref count is one */
1010 ref = getRefcount((IUnknown *) surf2);
1011 todo_wine ok(ref == 1, "Refcount is %u, expected 1\n", ref); /* This should also be one */
1013 IDirectDrawSurface_QueryInterface(surf, &IID_IDirectDrawSurface2, (void **) &surf2a);
1014 ref = getRefcount((IUnknown *) surf2);
1015 todo_wine ok(ref == 2, "Refcount is %u, expected 2\n", ref); /* Surf2's refcount should be 2 now, but surf should be 1 */
1016 ref = getRefcount((IUnknown *) surf);
1017 todo_wine ok(ref == 1, "Refcount is %u, expected 1\n", ref);
1019 IDirectDrawSurface_QueryInterface(surf, &IID_IDirectDrawSurface4, (void **) &surf4);
1020 ref = getRefcount((IUnknown *) surf4);
1021 todo_wine ok(ref == 1, "Refcount is %u, expected 1\n", ref);
1023 IDirectDrawSurface_QueryInterface(surf, &IID_IDirectDrawSurface7, (void **) &surf7a);
1024 ref = getRefcount((IUnknown *) surf7a);
1025 todo_wine ok(ref == 1, "Refcount is %u, expected 1\n", ref);
1027 IDirectDrawSurface_QueryInterface(surf, &IID_IDirectDrawSurface7, (void **) &surf7b);
1028 ref = getRefcount((IUnknown *) surf7b);
1029 todo_wine ok(ref == 2, "Refcount is %u, expected 2\n", ref);
1031 /* IDirect3DTexture interface (unlike the others) alters the original IDirectDrawSurface ref count */
1032 ret = IDirectDrawSurface_QueryInterface(surf, &IID_IDirect3DTexture, (void **) &tex);
1035 ref = getRefcount((IUnknown *) tex);
1036 todo_wine ok(ref == 2, "Refcount is %u, expected 2\n", ref);
1037 ref = getRefcount((IUnknown *) surf);
1038 todo_wine ok(ref == 2, "Refcount is %u, expected 2\n", ref);
1040 IDirectDrawSurface_QueryInterface(surf, &IID_IDirect3DTexture2, (void **) &tex2);
1041 ref = getRefcount((IUnknown *) tex);
1042 todo_wine ok(ref == 3, "Refcount is %u, expected 3\n", ref);
1043 ref = getRefcount((IUnknown *) tex2);
1044 todo_wine ok(ref == 3, "Refcount is %u, expected 3\n", ref);
1045 ref = getRefcount((IUnknown *) surf);
1046 todo_wine ok(ref == 3, "Refcount is %u, expected 3\n", ref);
1048 IDirectDrawSurface_QueryInterface(surf, &IID_IDirectDrawGammaControl, (void **) &gamma);
1049 ref = getRefcount((IUnknown *) gamma);
1050 todo_wine ok(ref == 1, "Refcount is %u, expected 1\n", ref);
1052 ref = IDirect3DTexture2_Release(tex2); /* Release the texture */
1053 todo_wine ok(ref == 2, "Refcount is %u, expected 2\n", ref);
1054 ref = getRefcount((IUnknown *) surf);
1055 todo_wine ok(ref == 2, "Refcount is %u, expected 2\n", ref);
1057 ref = IDirect3DTexture_Release(tex); /* Release the texture */
1058 todo_wine ok(ref == 1, "Refcount is %u, expected 1\n", ref);
1059 ref = getRefcount((IUnknown *) surf);
1060 todo_wine ok(ref == 1, "Refcount is %u, expected 1\n", ref);
1062 ref = IDirectDrawGammaControl_Release(gamma); /* Release the gamma control */
1063 todo_wine ok(ref == 0, "Refcount is %u, expected 0\n", ref);
1066 ref = IDirectDrawSurface2_Release(surf2); /* Release one of the 2 surf2 interfaces */
1067 todo_wine ok(ref == 1, "Refcount is %u, expected 1\n", ref);
1069 ref = IDirectDrawSurface2_Release(surf2a); /* Release the other */
1070 todo_wine ok(ref == 0, "Refcount is %u, expected 0\n", ref);
1072 ref = IDirectDrawSurface4_Release(surf4);
1073 todo_wine ok(ref == 0, "Refcount is %u, expected 0\n", ref);
1075 ref = IDirectDrawSurface7_Release(surf7a);
1076 todo_wine ok(ref == 1, "Refcount is %u, expected 1\n", ref);
1078 ref = IDirectDrawSurface7_Release(surf7b);
1079 todo_wine ok(ref == 0, "Refcount is %u, expected 0\n", ref);
1081 ref = IDirectDrawSurface_Release(surf);
1082 ok(ref == 0, "Refcount is %u, expected 0\n", ref);
1085 #define MAXEXPECTED 8 /* Can match up to 8 expected surfaces */
1088 IDirectDrawSurface *expected[MAXEXPECTED];
1092 static HRESULT WINAPI enumCB(IDirectDrawSurface *surf, DDSURFACEDESC *desc, void *ctx)
1097 for(i = 0; i < MAXEXPECTED; i++)
1099 if(((struct enumstruct *)ctx)->expected[i] == surf) found = TRUE;
1102 ok(found, "Unexpected surface %p enumerated\n", surf);
1103 ((struct enumstruct *)ctx)->count++;
1104 IDirectDrawSurface_Release(surf);
1105 return DDENUMRET_OK;
1108 static void EnumTest(void)
1112 IDirectDrawSurface *surface;
1113 struct enumstruct ctx;
1115 ddsd.dwSize = sizeof(ddsd);
1116 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_MIPMAPCOUNT;
1117 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
1118 U2(ddsd).dwMipMapCount = 3;
1121 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface, NULL);
1122 ok(rc==DD_OK,"CreateSurface returned: %x\n",rc);
1124 memset(&ctx, 0, sizeof(ctx));
1125 ctx.expected[0] = surface;
1126 rc = IDirectDrawSurface_GetAttachedSurface(ctx.expected[0], &ddsd.ddsCaps, &ctx.expected[1]);
1127 ok(rc == DD_OK, "GetAttachedSurface returned %08x\n", rc);
1128 rc = IDirectDrawSurface_GetAttachedSurface(ctx.expected[1], &ddsd.ddsCaps, &ctx.expected[2]);
1129 ok(rc == DD_OK, "GetAttachedSurface returned %08x\n", rc);
1130 rc = IDirectDrawSurface_GetAttachedSurface(ctx.expected[2], &ddsd.ddsCaps, &ctx.expected[3]);
1131 ok(rc == DDERR_NOTFOUND, "GetAttachedSurface returned %08x\n", rc);
1132 ok(!ctx.expected[3], "expected NULL pointer\n");
1135 rc = IDirectDraw_EnumSurfaces(lpDD, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_ALL, &ddsd, &ctx, enumCB);
1136 ok(rc == DD_OK, "IDirectDraw_EnumSurfaces returned %08x\n", rc);
1137 ok(ctx.count == 3, "%d surfaces enumerated, expected 3\n", ctx.count);
1139 IDirectDrawSurface_Release(ctx.expected[2]);
1140 IDirectDrawSurface_Release(ctx.expected[1]);
1141 IDirectDrawSurface_Release(surface);
1144 static HRESULT WINAPI SurfaceCounter(IDirectDrawSurface7 *surface, DDSURFACEDESC2 *desc, void *context)
1146 UINT *num = context;
1148 IDirectDrawSurface_Release(surface);
1149 return DDENUMRET_OK;
1152 static void AttachmentTest7(void)
1156 IDirectDrawSurface7 *surface1, *surface2, *surface3, *surface4;
1157 DDSURFACEDESC2 ddsd;
1159 DDSCAPS2 caps = {DDSCAPS_TEXTURE, 0, 0, 0};
1160 HWND window = CreateWindow( "static", "ddraw_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
1162 hr = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
1163 ok(hr == DD_OK, "IDirectDraw_QueryInterface returned %08x\n", hr);
1165 memset(&ddsd, 0, sizeof(ddsd));
1166 ddsd.dwSize = sizeof(ddsd);
1167 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_MIPMAPCOUNT;
1168 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
1169 U2(ddsd).dwMipMapCount = 3; /* Will create 128x128, 64x64, 32x32 */
1171 ddsd.dwHeight = 128;
1172 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface1, NULL);
1173 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1177 IDirectDrawSurface7_EnumAttachedSurfaces(surface1, &num, SurfaceCounter);
1178 ok(num == 1, "Mipmap root has %d surfaces attached, expected 1\n", num);
1182 hr = IDirectDrawSurface7_GetAttachedSurface(surface1, &caps, &surface2);
1183 ok(hr == DD_OK, "GetAttachedSurface returned %08x\n", hr);
1185 IDirectDrawSurface7_EnumAttachedSurfaces(surface2, &num, SurfaceCounter);
1186 ok(num == 1, "First mip level has %d surfaces attached, expected 1\n", num);
1190 hr = IDirectDrawSurface7_GetAttachedSurface(surface2, &caps, &surface3);
1191 ok(hr == DD_OK, "GetAttachedSurface returned %08x\n", hr);
1192 IDirectDrawSurface7_Release(surface2);
1194 IDirectDrawSurface7_EnumAttachedSurfaces(surface3, &num, SurfaceCounter);
1195 ok(num == 0, "Second mip level has %d surfaces attached, expected 1\n", num);
1197 /* Mip level 3 is still needed */
1198 hr = IDirectDrawSurface7_GetAttachedSurface(surface3, &caps, &surface4);
1199 ok(hr == DDERR_NOTFOUND, "GetAttachedSurface returned %08x\n", hr);
1200 ok(!surface4, "expected NULL pointer\n");
1202 /* Try to attach a 16x16 miplevel - Should not work as far I can see */
1203 memset(&ddsd, 0, sizeof(ddsd));
1204 ddsd.dwSize = sizeof(ddsd);
1205 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1206 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1209 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface2, NULL);
1210 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1212 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface2);
1213 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 16x16 surface to a 128x128 texture root returned %08x\n", hr);
1214 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface1);
1215 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 128x128 texture root to a 16x16 texture returned %08x\n", hr);
1216 hr = IDirectDrawSurface7_AddAttachedSurface(surface3, surface2);
1217 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 16x16 surface to a 32x32 texture mip level returned %08x\n", hr);
1218 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface3);
1219 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 32x32 texture mip level to a 16x16 surface returned %08x\n", hr);
1221 IDirectDrawSurface7_Release(surface2);
1223 memset(&ddsd, 0, sizeof(ddsd));
1224 ddsd.dwSize = sizeof(ddsd);
1225 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1226 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
1229 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface2, NULL);
1230 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1232 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface2);
1233 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 16x16 offscreen plain surface to a 128x128 texture root returned %08x\n", hr);
1234 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface1);
1235 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 128x128 texture root to a 16x16 offscreen plain surface returned %08x\n", hr);
1236 hr = IDirectDrawSurface7_AddAttachedSurface(surface3, surface2);
1237 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 16x16 offscreen plain surface to a 32x32 texture mip level returned %08x\n", hr);
1238 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface3);
1239 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 32x32 texture mip level to a 16x16 offscreen plain surface returned %08x\n", hr);
1241 IDirectDrawSurface7_Release(surface3);
1242 IDirectDrawSurface7_Release(surface2);
1243 IDirectDrawSurface7_Release(surface1);
1245 hr = IDirectDraw7_SetCooperativeLevel(dd7, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
1246 ok(hr == DD_OK, "SetCooperativeLevel returned %08x\n", hr);
1248 memset(&ddsd, 0, sizeof(ddsd));
1249 ddsd.dwSize = sizeof(ddsd);
1250 ddsd.dwFlags = DDSD_BACKBUFFERCOUNT | DDSD_CAPS;
1251 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
1252 ddsd.dwBackBufferCount = 2;
1253 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface1, NULL);
1254 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1257 IDirectDrawSurface7_EnumAttachedSurfaces(surface1, &num, SurfaceCounter);
1258 ok(num == 1, "Primary surface has %d surfaces attached, expected 1\n", num);
1259 IDirectDrawSurface7_Release(surface1);
1261 /* Those are some invalid descriptions, no need to test attachments with them */
1262 memset(&ddsd, 0, sizeof(ddsd));
1263 ddsd.dwSize = sizeof(ddsd);
1264 ddsd.dwFlags = DDSD_CAPS;
1265 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FRONTBUFFER;
1266 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface1, NULL);
1267 ok(hr==DDERR_INVALIDCAPS,"CreateSurface returned: %x\n",hr);
1268 memset(&ddsd, 0, sizeof(ddsd));
1269 ddsd.dwSize = sizeof(ddsd);
1270 ddsd.dwFlags = DDSD_CAPS;
1271 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_BACKBUFFER;
1272 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface2, NULL);
1273 ok(hr==DDERR_INVALIDCAPS,"CreateSurface returned: %x\n",hr);
1275 /* Try a single primary and two offscreen plain surfaces */
1276 memset(&ddsd, 0, sizeof(ddsd));
1277 ddsd.dwSize = sizeof(ddsd);
1278 ddsd.dwFlags = DDSD_CAPS;
1279 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
1280 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface1, NULL);
1281 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1283 memset(&ddsd, 0, sizeof(ddsd));
1284 ddsd.dwSize = sizeof(ddsd);
1285 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1286 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
1287 ddsd.dwWidth = GetSystemMetrics(SM_CXSCREEN);
1288 ddsd.dwHeight = GetSystemMetrics(SM_CYSCREEN);
1289 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface2, NULL);
1290 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1292 memset(&ddsd, 0, sizeof(ddsd));
1293 ddsd.dwSize = sizeof(ddsd);
1294 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1295 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
1296 ddsd.dwWidth = GetSystemMetrics(SM_CXSCREEN);
1297 ddsd.dwHeight = GetSystemMetrics(SM_CYSCREEN);
1298 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface3, NULL);
1299 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1301 /* This one has a different size */
1302 memset(&ddsd, 0, sizeof(ddsd));
1303 ddsd.dwSize = sizeof(ddsd);
1304 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1305 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
1307 ddsd.dwHeight = 128;
1308 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface4, NULL);
1309 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1311 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface2);
1312 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching an offscreen plain surface to a front buffer returned %08x\n", hr);
1313 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface1);
1314 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a front buffer to an offscreen plain surface returned %08x\n", hr);
1315 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface3);
1316 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching an offscreen plain surface to another offscreen plain surface returned %08x\n", hr);
1317 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface4);
1318 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching an offscreen plain surface to a front buffer of different size returned %08x\n", hr);
1319 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface1);
1320 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a front buffer to an offscreen plain surface of different size returned %08x\n", hr);
1322 IDirectDrawSurface7_Release(surface4);
1323 IDirectDrawSurface7_Release(surface3);
1324 IDirectDrawSurface7_Release(surface2);
1325 IDirectDrawSurface7_Release(surface1);
1327 hr =IDirectDraw7_SetCooperativeLevel(dd7, NULL, DDSCL_NORMAL);
1328 ok(hr == DD_OK, "SetCooperativeLevel returned %08x\n", hr);
1329 IDirectDraw7_Release(dd7);
1332 static void AttachmentTest(void)
1335 IDirectDrawSurface *surface1, *surface2, *surface3, *surface4;
1337 DDSCAPS caps = {DDSCAPS_TEXTURE};
1338 BOOL refrast = FALSE;
1339 HWND window = CreateWindow( "static", "ddraw_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
1341 memset(&ddsd, 0, sizeof(ddsd));
1342 ddsd.dwSize = sizeof(ddsd);
1343 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_MIPMAPCOUNT;
1344 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
1345 U2(ddsd).dwMipMapCount = 3; /* Will create 128x128, 64x64, 32x32 */
1347 ddsd.dwHeight = 128;
1348 hr = IDirectDraw7_CreateSurface(lpDD, &ddsd, &surface1, NULL);
1349 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1351 hr = IDirectDrawSurface7_GetAttachedSurface(surface1, &caps, &surface2);
1352 ok(hr == DD_OK, "GetAttachedSurface returned %08x\n", hr);
1353 hr = IDirectDrawSurface7_GetAttachedSurface(surface2, &caps, &surface3);
1354 ok(hr == DD_OK, "GetAttachedSurface returned %08x\n", hr);
1356 /* Try to attach a 16x16 miplevel - Should not work as far I can see */
1357 memset(&ddsd, 0, sizeof(ddsd));
1358 ddsd.dwSize = sizeof(ddsd);
1359 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1360 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1363 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface4, NULL);
1364 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1366 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface4);
1367 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 16x16 surface to a 128x128 texture root returned %08x\n", hr);
1368 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface1);
1369 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 128x128 texture root to a 16x16 texture returned %08x\n", hr);
1370 hr = IDirectDrawSurface7_AddAttachedSurface(surface3, surface4);
1371 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 16x16 surface to a 32x32 texture mip level returned %08x\n", hr);
1372 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface3);
1373 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 32x32 texture mip level to a 16x16 surface returned %08x\n", hr);
1374 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface4);
1375 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 16x16 surface to a 64x64 texture sublevel returned %08x\n", hr);
1376 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface2);
1377 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 64x64 texture sublevel to a 16x16 texture returned %08x\n", hr);
1379 IDirectDrawSurface7_Release(surface4);
1381 memset(&ddsd, 0, sizeof(ddsd));
1382 ddsd.dwSize = sizeof(ddsd);
1383 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1384 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
1387 hr = IDirectDraw7_CreateSurface(lpDD, &ddsd, &surface4, NULL);
1388 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1390 if (SUCCEEDED(IDirectDrawSurface7_AddAttachedSurface(surface1, surface4)))
1392 IDirectDrawSurface7_DeleteAttachedSurface(surface1, 0, surface4);
1396 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface4); /* Succeeds on refrast */
1398 ok(hr == S_OK, "Attaching a 16x16 offscreen plain surface to a 128x128 texture root returned %08x\n", hr);
1400 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 16x16 offscreen plain surface to a 128x128 texture root returned %08x\n", hr);
1401 if(SUCCEEDED(hr)) IDirectDrawSurface7_DeleteAttachedSurface(surface1, 0, surface4);
1403 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface1); /* Succeeds on refrast */
1405 ok(hr == S_OK, "Attaching a 128x128 texture root to a 16x16 offscreen plain surface returned %08x\n", hr);
1407 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 128x128 texture root to a 16x16 offscreen plain surface returned %08x\n", hr);
1408 if(SUCCEEDED(hr)) IDirectDrawSurface7_DeleteAttachedSurface(surface1, 0, surface1);
1410 hr = IDirectDrawSurface7_AddAttachedSurface(surface3, surface4); /* Succeeds on refrast */
1412 ok(hr == S_OK, "Attaching a 16x16 offscreen plain surface to a 32x32 texture mip level returned %08x\n", hr);
1414 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 16x16 offscreen plain surface to a 32x32 texture mip level returned %08x\n", hr);
1415 if(SUCCEEDED(hr)) IDirectDrawSurface7_DeleteAttachedSurface(surface3, 0, surface4);
1417 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface3);
1418 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 32x32 texture mip level to a 16x16 offscreen plain surface returned %08x\n", hr);
1419 if(SUCCEEDED(hr)) IDirectDrawSurface7_DeleteAttachedSurface(surface4, 0, surface3);
1421 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface4); /* Succeeds on refrast */
1423 ok(hr == S_OK, "Attaching a 16x16 offscreen plain surface to a 64x64 texture sublevel returned %08x\n", hr);
1425 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 16x16 offscreen plain surface to a 64x64 texture sublevel returned %08x\n", hr);
1426 if(SUCCEEDED(hr)) IDirectDrawSurface7_DeleteAttachedSurface(surface2, 0, surface4);
1428 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface2);
1429 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 64x64 texture sublevel to a 16x16 offscreen plain surface returned %08x\n", hr);
1430 if(SUCCEEDED(hr)) IDirectDrawSurface7_DeleteAttachedSurface(surface4, 0, surface2);
1432 IDirectDrawSurface7_Release(surface4);
1433 IDirectDrawSurface7_Release(surface3);
1434 IDirectDrawSurface7_Release(surface2);
1435 IDirectDrawSurface7_Release(surface1);
1437 hr = IDirectDraw_SetCooperativeLevel(lpDD, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
1438 ok(hr == DD_OK, "SetCooperativeLevel returned %08x\n", hr);
1440 /* Creating a back buffer as-is, is not allowed. No need to perform attachment tests */
1441 memset(&ddsd, 0, sizeof(ddsd));
1442 ddsd.dwSize = sizeof(ddsd);
1443 ddsd.dwFlags = DDSD_CAPS;
1444 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_BACKBUFFER;
1445 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface2, NULL);
1446 ok(hr==DDERR_INVALIDCAPS,"CreateSurface returned: %x\n",hr);
1447 /* This old ddraw version happily creates explicit front buffers */
1448 memset(&ddsd, 0, sizeof(ddsd));
1449 ddsd.dwSize = sizeof(ddsd);
1450 ddsd.dwFlags = DDSD_CAPS;
1451 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FRONTBUFFER;
1452 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface1, NULL);
1453 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1454 IDirectDrawSurface_Release(surface1);
1456 /* Try a single primary and two offscreen plain surfaces */
1457 memset(&ddsd, 0, sizeof(ddsd));
1458 ddsd.dwSize = sizeof(ddsd);
1459 ddsd.dwFlags = DDSD_CAPS;
1460 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
1461 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface1, NULL);
1462 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1464 memset(&ddsd, 0, sizeof(ddsd));
1465 ddsd.dwSize = sizeof(ddsd);
1466 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1467 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
1468 ddsd.dwWidth = GetSystemMetrics(SM_CXSCREEN);
1469 ddsd.dwHeight = GetSystemMetrics(SM_CYSCREEN);
1470 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface2, NULL);
1471 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1473 memset(&ddsd, 0, sizeof(ddsd));
1474 ddsd.dwSize = sizeof(ddsd);
1475 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1476 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
1477 ddsd.dwWidth = GetSystemMetrics(SM_CXSCREEN);
1478 ddsd.dwHeight = GetSystemMetrics(SM_CYSCREEN);
1479 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface3, NULL);
1480 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1482 /* This one has a different size */
1483 memset(&ddsd, 0, sizeof(ddsd));
1484 ddsd.dwSize = sizeof(ddsd);
1485 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1486 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
1488 ddsd.dwHeight = 128;
1489 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface4, NULL);
1490 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1492 hr = IDirectDrawSurface_AddAttachedSurface(surface1, surface2);
1493 ok(hr == DD_OK || broken(hr == DDERR_CANNOTATTACHSURFACE),
1494 "Attaching an offscreen plain surface to a front buffer returned %08x\n", hr);
1497 /* Try the reverse without detaching first */
1498 hr = IDirectDrawSurface_AddAttachedSurface(surface2, surface1);
1499 ok(hr == DDERR_SURFACEALREADYATTACHED, "Attaching an attached surface to its attachee returned %08x\n", hr);
1500 hr = IDirectDrawSurface_DeleteAttachedSurface(surface1, 0, surface2);
1501 ok(hr == DD_OK, "DeleteAttachedSurface failed with %08x\n", hr);
1503 hr = IDirectDrawSurface_AddAttachedSurface(surface2, surface1);
1504 ok(hr == DD_OK || broken(hr == DDERR_CANNOTATTACHSURFACE),
1505 "Attaching a front buffer to an offscreen plain surface returned %08x\n", hr);
1508 /* Try to detach reversed */
1509 hr = IDirectDrawSurface_DeleteAttachedSurface(surface1, 0, surface2);
1510 ok(hr == DDERR_CANNOTDETACHSURFACE, "DeleteAttachedSurface returned %08x\n", hr);
1511 /* Now the proper detach */
1512 hr = IDirectDrawSurface_DeleteAttachedSurface(surface2, 0, surface1);
1513 ok(hr == DD_OK, "DeleteAttachedSurface failed with %08x\n", hr);
1515 hr = IDirectDrawSurface_AddAttachedSurface(surface2, surface3); /* Fails on refrast */
1516 ok(hr == DD_OK || broken(hr == DDERR_CANNOTATTACHSURFACE),
1517 "Attaching an offscreen plain surface to another offscreen plain surface returned %08x\n", hr);
1520 hr = IDirectDrawSurface_DeleteAttachedSurface(surface2, 0, surface3);
1521 ok(hr == DD_OK, "DeleteAttachedSurface failed with %08x\n", hr);
1523 hr = IDirectDrawSurface_AddAttachedSurface(surface1, surface4);
1524 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching an offscreen plain surface to a front buffer of different size returned %08x\n", hr);
1525 hr = IDirectDrawSurface_AddAttachedSurface(surface4, surface1);
1526 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a front buffer to an offscreen plain surface of different size returned %08x\n", hr);
1528 IDirectDrawSurface_Release(surface4);
1529 IDirectDrawSurface_Release(surface3);
1530 IDirectDrawSurface_Release(surface2);
1531 IDirectDrawSurface_Release(surface1);
1533 hr =IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_NORMAL);
1534 ok(hr == DD_OK, "SetCooperativeLevel returned %08x\n", hr);
1536 DestroyWindow(window);
1541 DWORD width, height;
1546 static HRESULT WINAPI CubeTestLvl2Enum(IDirectDrawSurface7 *surface, DDSURFACEDESC2 *desc, void *context)
1548 UINT *mips = context;
1551 IDirectDrawSurface7_EnumAttachedSurfaces(surface,
1555 return DDENUMRET_OK;
1558 static HRESULT WINAPI CubeTestLvl1Enum(IDirectDrawSurface7 *surface, DDSURFACEDESC2 *desc, void *context)
1561 UINT *num = context;
1562 static const struct compare expected[] =
1566 DDSCAPS_MIPMAP | DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_COMPLEX,
1567 DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEZ,
1572 DDSCAPS_MIPMAP | DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_COMPLEX,
1573 DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEZ,
1578 DDSCAPS_MIPMAP | DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_COMPLEX,
1579 DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEY,
1584 DDSCAPS_MIPMAP | DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_COMPLEX,
1585 DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEY,
1590 DDSCAPS_MIPMAP | DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_COMPLEX,
1591 DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEX,
1595 64, 64, /* This is the first mipmap */
1596 DDSCAPS_MIPMAP | DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_COMPLEX,
1597 DDSCAPS2_MIPMAPSUBLEVEL | DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEX,
1603 IDirectDrawSurface7_EnumAttachedSurfaces(surface,
1607 ok(desc->dwWidth == expected[*num].width, "Surface width is %d expected %d\n", desc->dwWidth, expected[*num].width);
1608 ok(desc->dwHeight == expected[*num].height, "Surface height is %d expected %d\n", desc->dwHeight, expected[*num].height);
1609 ok(desc->ddsCaps.dwCaps == expected[*num].caps, "Surface caps are %08x expected %08x\n", desc->ddsCaps.dwCaps, expected[*num].caps);
1610 ok(desc->ddsCaps.dwCaps2 == expected[*num].caps2, "Surface caps2 are %08x expected %08x\n", desc->ddsCaps.dwCaps2, expected[*num].caps2);
1611 ok(mips == expected[*num].mips, "Surface has %d mipmaps, expected %d\n", mips, expected[*num].mips);
1615 IDirectDrawSurface7_Release(surface);
1617 return DDENUMRET_OK;
1620 static void CubeMapTest(void)
1622 IDirectDraw7 *dd7 = NULL;
1623 IDirectDrawSurface7 *cubemap = NULL;
1624 DDSURFACEDESC2 ddsd;
1627 struct enumstruct ctx;
1629 hr = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
1630 ok(hr == DD_OK, "IDirectDraw::QueryInterface returned %08x\n", hr);
1631 if (FAILED(hr)) goto err;
1633 memset(&ddsd, 0, sizeof(ddsd));
1634 ddsd.dwSize = sizeof(ddsd);
1635 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
1636 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS;
1638 ddsd.dwHeight = 128;
1639 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP | DDSCAPS_SYSTEMMEMORY;
1640 ddsd.ddsCaps.dwCaps2 = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES;
1643 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
1644 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 16;
1645 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0xF800;
1646 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x07E0;
1647 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x001F;
1649 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &cubemap, NULL);
1652 skip("Can't create cubemap surface\n");
1656 hr = IDirectDrawSurface7_GetSurfaceDesc(cubemap, &ddsd);
1657 ok(hr == DD_OK, "IDirectDrawSurface7_GetSurfaceDesc returned %08x\n", hr);
1658 ok(ddsd.ddsCaps.dwCaps == (DDSCAPS_MIPMAP | DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_COMPLEX),
1659 "Root Caps are %08x\n", ddsd.ddsCaps.dwCaps);
1660 ok(ddsd.ddsCaps.dwCaps2 == (DDSCAPS2_CUBEMAP_POSITIVEX | DDSCAPS2_CUBEMAP),
1661 "Root Caps2 are %08x\n", ddsd.ddsCaps.dwCaps2);
1663 IDirectDrawSurface7_EnumAttachedSurfaces(cubemap,
1666 ok(num == 6, "Surface has %d attachments\n", num);
1667 IDirectDrawSurface7_Release(cubemap);
1669 /* What happens if I do not specify any faces? */
1670 memset(&ddsd, 0, sizeof(ddsd));
1671 ddsd.dwSize = sizeof(ddsd);
1672 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
1673 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS;
1675 ddsd.dwHeight = 128;
1676 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP | DDSCAPS_SYSTEMMEMORY;
1677 ddsd.ddsCaps.dwCaps2 = DDSCAPS2_CUBEMAP;
1680 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
1681 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 16;
1682 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0xF800;
1683 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x07E0;
1684 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x001F;
1686 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &cubemap, NULL);
1687 ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw7::CreateSurface asking for a cube map without faces returned %08x\n", hr);
1689 /* Cube map faces without a cube map? */
1690 memset(&ddsd, 0, sizeof(ddsd));
1691 ddsd.dwSize = sizeof(ddsd);
1692 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
1693 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS;
1695 ddsd.dwHeight = 128;
1696 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP | DDSCAPS_SYSTEMMEMORY;
1697 ddsd.ddsCaps.dwCaps2 = DDSCAPS2_CUBEMAP_ALLFACES;
1700 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
1701 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 16;
1702 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0xF800;
1703 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x07E0;
1704 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x001F;
1706 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &cubemap, NULL);
1707 ok(hr == DDERR_INVALIDCAPS, "IDirectDraw7::CreateSurface returned %08x\n", hr);
1709 memset(&ddsd, 0, sizeof(ddsd));
1710 ddsd.dwSize = sizeof(ddsd);
1711 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
1712 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS;
1714 ddsd.dwHeight = 128;
1715 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP | DDSCAPS_SYSTEMMEMORY;
1716 ddsd.ddsCaps.dwCaps2 = DDSCAPS2_CUBEMAP_POSITIVEX;
1719 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
1720 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 16;
1721 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0xF800;
1722 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x07E0;
1723 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x001F;
1725 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &cubemap, NULL);
1726 ok(hr == DDERR_INVALIDCAPS, "IDirectDraw7::CreateSurface returned %08x\n", hr);
1728 /* Make sure everything is cleaned up properly. Use the enumSurfaces test infrastructure */
1729 memset(&ctx, 0, sizeof(ctx));
1730 memset(&ddsd, 0, sizeof(ddsd));
1731 ddsd.dwSize = sizeof(DDSURFACEDESC);
1732 hr = IDirectDraw_EnumSurfaces(lpDD, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_ALL, (DDSURFACEDESC *) &ddsd, (void *) &ctx, enumCB);
1733 ok(hr == DD_OK, "IDirectDraw_EnumSurfaces returned %08x\n", hr);
1734 ok(ctx.count == 0, "%d surfaces enumerated, expected 0\n", ctx.count);
1737 if (dd7) IDirectDraw7_Release(dd7);
1740 static void test_lockrect_invalid(void)
1753 {68, 60, 60, 68}, /* left > right */
1754 {60, 68, 68, 60}, /* top > bottom */
1755 {-8, 60, 0, 68}, /* left < surface */
1756 {60, -8, 68, 0}, /* top < surface */
1757 {-16, 60, -8, 68}, /* right < surface */
1758 {60, -16, 68, -8}, /* bottom < surface */
1759 {60, 60, 136, 68}, /* right > surface */
1760 {60, 60, 68, 136}, /* bottom > surface */
1761 {136, 60, 144, 68}, /* left > surface */
1762 {60, 136, 68, 144}, /* top > surface */
1765 const DWORD dds_caps[] = {
1766 DDSCAPS_OFFSCREENPLAIN
1769 for (j = 0; j < (sizeof(dds_caps) / sizeof(*dds_caps)); ++j)
1771 IDirectDrawSurface *surface = 0;
1772 DDSURFACEDESC surface_desc = {0};
1773 DDSURFACEDESC locked_desc = {0};
1776 surface_desc.dwSize = sizeof(surface_desc);
1777 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
1778 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
1779 surface_desc.ddsCaps.dwCaps = dds_caps[j];
1780 surface_desc.dwWidth = 128;
1781 surface_desc.dwHeight = 128;
1782 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB;
1783 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount = 32;
1784 U2(surface_desc.ddpfPixelFormat).dwRBitMask = 0xFF0000;
1785 U3(surface_desc.ddpfPixelFormat).dwGBitMask = 0x00FF00;
1786 U4(surface_desc.ddpfPixelFormat).dwBBitMask = 0x0000FF;
1788 hr = IDirectDraw_CreateSurface(lpDD, &surface_desc, &surface, NULL);
1789 ok(SUCCEEDED(hr), "CreateSurface failed (0x%08x)\n", hr);
1791 skip("failed to create surface\n");
1795 for (i = 0; i < (sizeof(valid) / sizeof(*valid)); ++i)
1797 RECT *rect = &valid[i];
1799 memset(&locked_desc, 0, sizeof(locked_desc));
1800 locked_desc.dwSize = sizeof(locked_desc);
1802 hr = IDirectDrawSurface_Lock(surface, rect, &locked_desc, DDLOCK_WAIT, NULL);
1803 ok(SUCCEEDED(hr), "Lock failed (0x%08x) for rect [%d, %d]->[%d, %d]\n",
1804 hr, rect->left, rect->top, rect->right, rect->bottom);
1806 hr = IDirectDrawSurface_Unlock(surface, NULL);
1807 ok(SUCCEEDED(hr), "Unlock failed (0x%08x)\n", hr);
1810 for (i = 0; i < (sizeof(invalid) / sizeof(*invalid)); ++i)
1812 RECT *rect = &invalid[i];
1814 memset(&locked_desc, 1, sizeof(locked_desc));
1815 locked_desc.dwSize = sizeof(locked_desc);
1817 hr = IDirectDrawSurface_Lock(surface, rect, &locked_desc, DDLOCK_WAIT, NULL);
1818 ok(hr == DDERR_INVALIDPARAMS, "Lock returned 0x%08x for rect [%d, %d]->[%d, %d]"
1819 ", expected DDERR_INVALIDPARAMS (0x%08x)\n", hr, rect->left, rect->top,
1820 rect->right, rect->bottom, DDERR_INVALIDPARAMS);
1821 ok(!locked_desc.lpSurface, "IDirectDrawSurface_Lock did not set lpSurface in the surface desc to zero.\n");
1824 hr = IDirectDrawSurface_Lock(surface, NULL, &locked_desc, DDLOCK_WAIT, NULL);
1825 ok(hr == DD_OK, "IDirectDrawSurface_Lock(rect = NULL) failed (0x%08x)\n", hr);
1826 hr = IDirectDrawSurface_Lock(surface, NULL, &locked_desc, DDLOCK_WAIT, NULL);
1827 ok(hr == DDERR_SURFACEBUSY, "Double lock(rect = NULL) returned 0x%08x\n", hr);
1829 hr = IDirectDrawSurface_Unlock(surface, NULL);
1830 ok(SUCCEEDED(hr), "Unlock failed (0x%08x)\n", hr);
1832 hr = IDirectDrawSurface_Unlock(surface, NULL);
1833 ok(SUCCEEDED(hr), "Unlock failed (0x%08x)\n", hr);
1835 memset(&locked_desc, 0, sizeof(locked_desc));
1836 locked_desc.dwSize = sizeof(locked_desc);
1837 hr = IDirectDrawSurface_Lock(surface, &valid[0], &locked_desc, DDLOCK_WAIT, NULL);
1838 ok(hr == DD_OK, "IDirectDrawSurface_Lock(rect = [%d, %d]->[%d, %d]) failed (0x%08x)\n",
1839 valid[0].left, valid[0].top, valid[0].right, valid[0].bottom, hr);
1840 hr = IDirectDrawSurface_Lock(surface, &valid[0], &locked_desc, DDLOCK_WAIT, NULL);
1841 ok(hr == DDERR_SURFACEBUSY, "Double lock(rect = [%d, %d]->[%d, %d]) failed (0x%08x)\n",
1842 valid[0].left, valid[0].top, valid[0].right, valid[0].bottom, hr);
1844 /* Locking a different rectangle returns DD_OK, but it seems to break the surface.
1845 * Afterwards unlocking the surface fails(NULL rectangle, and both locked rectangles
1848 hr = IDirectDrawSurface_Unlock(surface, NULL);
1849 ok(hr == DD_OK, "Unlock returned (0x%08x)\n", hr);
1851 IDirectDrawSurface_Release(surface);
1855 static void CompressedTest(void)
1858 IDirectDrawSurface7 *surface;
1859 DDSURFACEDESC2 ddsd, ddsd2;
1860 IDirectDraw7 *dd7 = NULL;
1861 RECT r = { 0, 0, 128, 128 };
1862 RECT r2 = { 32, 32, 64, 64 };
1864 hr = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
1865 ok(hr == DD_OK, "IDirectDraw::QueryInterface returned %08x\n", hr);
1867 memset(&ddsd, 0, sizeof(ddsd));
1868 ddsd.dwSize = sizeof(ddsd);
1869 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
1870 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS;
1872 ddsd.dwHeight = 128;
1873 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY;
1874 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_FOURCC;
1875 U4(ddsd).ddpfPixelFormat.dwFourCC = MAKEFOURCC('D','X','T','1');
1877 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface, NULL);
1878 ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
1880 skip("failed to create surface\n");
1884 memset(&ddsd2, 0, sizeof(ddsd2));
1885 ddsd2.dwSize = sizeof(ddsd2);
1886 U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
1887 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd2);
1888 ok(hr == DD_OK, "GetSurfaceDesc returned %08x\n", hr);
1890 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
1891 "Surface desc flags: %08x\n", ddsd2.dwFlags);
1892 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
1893 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
1894 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
1895 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
1896 ok(U1(ddsd2).dwLinearSize == 8192, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
1897 ok(ddsd2.ddsCaps.dwCaps2 == 0, "Caps2: %08x\n", ddsd2.ddsCaps.dwCaps2);
1898 IDirectDrawSurface7_Release(surface);
1900 U4(ddsd).ddpfPixelFormat.dwFourCC = MAKEFOURCC('D','X','T','3');
1901 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface, NULL);
1902 ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
1904 skip("failed to create surface\n");
1908 memset(&ddsd2, 0, sizeof(ddsd2));
1909 ddsd2.dwSize = sizeof(ddsd2);
1910 U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
1911 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd2);
1912 ok(hr == DD_OK, "GetSurfaceDesc returned %08x\n", hr);
1914 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
1915 "Surface desc flags: %08x\n", ddsd2.dwFlags);
1916 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
1917 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
1918 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
1919 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
1920 ok(U1(ddsd2).dwLinearSize == 16384, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
1921 IDirectDrawSurface7_Release(surface);
1923 U4(ddsd).ddpfPixelFormat.dwFourCC = MAKEFOURCC('D','X','T','5');
1924 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface, NULL);
1925 ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
1927 skip("failed to create surface\n");
1931 memset(&ddsd2, 0, sizeof(ddsd2));
1932 ddsd2.dwSize = sizeof(ddsd2);
1933 U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
1934 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd2);
1935 ok(hr == DD_OK, "GetSurfaceDesc returned %08x\n", hr);
1937 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
1938 "Surface desc flags: %08x\n", ddsd2.dwFlags);
1939 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
1940 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
1941 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
1942 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
1943 ok(U1(ddsd2).dwLinearSize == 16384, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
1944 ok(ddsd2.lpSurface == 0, "Surface memory is at %p, expected NULL\n", ddsd2.lpSurface);
1946 memset(&ddsd2, 0, sizeof(ddsd2));
1947 ddsd2.dwSize = sizeof(ddsd2);
1948 U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
1950 /* Show that the description is not changed when locking the surface. What is really interesting
1951 * about this is that DDSD_LPSURFACE isn't set.
1953 hr = IDirectDrawSurface7_Lock(surface, NULL, &ddsd2, DDLOCK_READONLY, 0);
1954 ok(hr == DD_OK, "Lock returned %08x\n", hr);
1956 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
1957 "Surface desc flags: %08x\n", ddsd2.dwFlags);
1958 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
1959 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
1960 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
1961 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
1962 ok(U1(ddsd2).dwLinearSize == 16384, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
1963 ok(ddsd2.lpSurface != 0, "Surface memory is at NULL\n");
1965 hr = IDirectDrawSurface7_Unlock(surface, NULL);
1966 ok(hr == DD_OK, "Unlock returned %08x\n", hr);
1968 /* Now what about a locking rect? */
1969 hr = IDirectDrawSurface7_Lock(surface, &r, &ddsd2, DDLOCK_READONLY, 0);
1970 ok(hr == DD_OK, "Lock returned %08x\n", hr);
1972 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
1973 "Surface desc flags: %08x\n", ddsd2.dwFlags);
1974 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
1975 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
1976 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
1977 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
1978 ok(U1(ddsd2).dwLinearSize == 16384, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
1979 ok(ddsd2.lpSurface != 0, "Surface memory is at NULL\n");
1981 hr = IDirectDrawSurface7_Unlock(surface, &r);
1982 ok(hr == DD_OK, "Unlock returned %08x\n", hr);
1984 /* Now what about a different locking offset? */
1985 hr = IDirectDrawSurface7_Lock(surface, &r2, &ddsd2, DDLOCK_READONLY, 0);
1986 ok(hr == DD_OK, "Lock returned %08x\n", hr);
1988 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
1989 "Surface desc flags: %08x\n", ddsd2.dwFlags);
1990 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
1991 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
1992 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
1993 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
1994 ok(U1(ddsd2).dwLinearSize == 16384, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
1995 ok(ddsd2.lpSurface != 0, "Surface memory is at NULL\n");
1997 hr = IDirectDrawSurface7_Unlock(surface, &r2);
1998 ok(hr == DD_OK, "Unlock returned %08x\n", hr);
1999 IDirectDrawSurface7_Release(surface);
2001 /* Try this with video memory. A kind of surprise. It still has the LINEARSIZE flag set,
2002 * but seems to have a pitch instead.
2004 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY;
2005 U4(ddsd).ddpfPixelFormat.dwFourCC = MAKEFOURCC('D','X','T','1');
2007 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface, NULL);
2008 ok(hr == DD_OK || hr == DDERR_NOTEXTUREHW || hr == DDERR_INVALIDPARAMS ||
2009 broken(hr == DDERR_NODIRECTDRAWHW), "CreateSurface returned %08x\n", hr);
2011 /* Not supported everywhere */
2014 memset(&ddsd2, 0, sizeof(ddsd2));
2015 ddsd2.dwSize = sizeof(ddsd2);
2016 U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
2017 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd2);
2018 ok(hr == DD_OK, "GetSurfaceDesc returned %08x\n", hr);
2020 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
2021 "Surface desc flags: %08x\n", ddsd2.dwFlags);
2022 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
2023 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
2024 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM),
2025 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
2026 /* ATI drivers report a broken linear size, thus no need to clone the exact behaviour. nvidia reports the correct size */
2027 ok(ddsd2.ddsCaps.dwCaps2 == 0, "Caps2: %08x\n", ddsd2.ddsCaps.dwCaps2);
2028 IDirectDrawSurface7_Release(surface);
2030 U4(ddsd).ddpfPixelFormat.dwFourCC = MAKEFOURCC('D','X','T','3');
2031 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface, NULL);
2032 ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
2034 memset(&ddsd2, 0, sizeof(ddsd2));
2035 ddsd2.dwSize = sizeof(ddsd2);
2036 U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
2037 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd2);
2038 ok(hr == DD_OK, "GetSurfaceDesc returned %08x\n", hr);
2040 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
2041 "Surface desc flags: %08x\n", ddsd2.dwFlags);
2042 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
2043 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
2044 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM),
2045 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
2046 /* ATI drivers report a broken linear size, thus no need to clone the exact behaviour. nvidia reports the correct size */
2047 IDirectDrawSurface7_Release(surface);
2049 U4(ddsd).ddpfPixelFormat.dwFourCC = MAKEFOURCC('D','X','T','5');
2050 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface, NULL);
2051 ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
2053 memset(&ddsd2, 0, sizeof(ddsd2));
2054 ddsd2.dwSize = sizeof(ddsd2);
2055 U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
2056 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd2);
2057 ok(hr == DD_OK, "GetSurfaceDesc returned %08x\n", hr);
2059 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
2060 "Surface desc flags: %08x\n", ddsd2.dwFlags);
2061 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
2062 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
2063 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM),
2064 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
2065 /* ATI drivers report a broken linear size, thus no need to clone the exact behaviour. nvidia reports the correct size */
2066 ok(ddsd2.lpSurface == 0, "Surface memory is at %p, expected NULL\n", ddsd2.lpSurface);
2068 memset(&ddsd2, 0, sizeof(ddsd2));
2069 ddsd2.dwSize = sizeof(ddsd2);
2070 U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
2072 /* Show that the description is not changed when locking the surface. What is really interesting
2073 * about this is that DDSD_LPSURFACE isn't set.
2075 hr = IDirectDrawSurface7_Lock(surface, NULL, &ddsd2, DDLOCK_READONLY, 0);
2076 ok(hr == DD_OK, "Lock returned %08x\n", hr);
2078 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
2079 "Surface desc flags: %08x\n", ddsd2.dwFlags);
2080 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
2081 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
2082 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM),
2083 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
2084 /* ATI drivers report a broken linear size, thus no need to clone the exact behaviour. nvidia reports the correct size */
2085 ok(ddsd2.lpSurface != 0, "Surface memory is at NULL\n");
2087 hr = IDirectDrawSurface7_Unlock(surface, NULL);
2088 ok(hr == DD_OK, "Unlock returned %08x\n", hr);
2090 /* Now what about a locking rect? */
2091 hr = IDirectDrawSurface7_Lock(surface, &r, &ddsd2, DDLOCK_READONLY, 0);
2092 ok(hr == DD_OK, "Lock returned %08x\n", hr);
2094 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
2095 "Surface desc flags: %08x\n", ddsd2.dwFlags);
2096 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
2097 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
2098 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM),
2099 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
2100 /* ATI drivers report a broken linear size, thus no need to clone the exact behaviour. nvidia reports the correct size */
2101 ok(ddsd2.lpSurface != 0, "Surface memory is at NULL\n");
2103 hr = IDirectDrawSurface7_Unlock(surface, &r);
2104 ok(hr == DD_OK, "Unlock returned %08x\n", hr);
2106 /* Now what about a different locking offset? */
2107 hr = IDirectDrawSurface7_Lock(surface, &r2, &ddsd2, DDLOCK_READONLY, 0);
2108 ok(hr == DD_OK, "Lock returned %08x\n", hr);
2110 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
2111 "Surface desc flags: %08x\n", ddsd2.dwFlags);
2112 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
2113 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
2114 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM),
2115 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
2116 /* ATI drivers report a broken linear size, thus no need to clone the exact behaviour. nvidia reports the correct size */
2117 ok(ddsd2.lpSurface != 0, "Surface memory is at NULL\n");
2119 hr = IDirectDrawSurface7_Unlock(surface, &r2);
2120 ok(hr == DD_OK, "Unlock returned %08x\n", hr);
2122 IDirectDrawSurface7_Release(surface);
2126 skip("Hardware DXTN textures not supported\n");
2129 /* What happens to managed textures? Interestingly, Windows reports them as being in system
2130 * memory. The linear size fits again.
2132 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
2133 ddsd.ddsCaps.dwCaps2 = DDSCAPS2_TEXTUREMANAGE;
2134 U4(ddsd).ddpfPixelFormat.dwFourCC = MAKEFOURCC('D','X','T','1');
2136 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface, NULL);
2137 ok(hr == DD_OK || hr == DDERR_NOTEXTUREHW, "CreateSurface returned %08x\n", hr);
2139 /* Not supported everywhere */
2142 memset(&ddsd2, 0, sizeof(ddsd2));
2143 ddsd2.dwSize = sizeof(ddsd2);
2144 U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
2145 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd2);
2146 ok(hr == DD_OK, "GetSurfaceDesc returned %08x\n", hr);
2148 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
2149 "Surface desc flags: %08x\n", ddsd2.dwFlags);
2150 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
2151 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
2152 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
2153 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
2154 ok(U1(ddsd2).dwLinearSize == 8192, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
2155 ok(ddsd2.ddsCaps.dwCaps2 == DDSCAPS2_TEXTUREMANAGE, "Caps2: %08x\n", ddsd2.ddsCaps.dwCaps2);
2156 IDirectDrawSurface7_Release(surface);
2158 U4(ddsd).ddpfPixelFormat.dwFourCC = MAKEFOURCC('D','X','T','3');
2159 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface, NULL);
2160 ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
2162 memset(&ddsd2, 0, sizeof(ddsd2));
2163 ddsd2.dwSize = sizeof(ddsd2);
2164 U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
2165 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd2);
2166 ok(hr == DD_OK, "GetSurfaceDesc returned %08x\n", hr);
2168 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
2169 "Surface desc flags: %08x\n", ddsd2.dwFlags);
2170 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
2171 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
2172 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
2173 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
2174 ok(U1(ddsd2).dwLinearSize == 16384, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
2175 IDirectDrawSurface7_Release(surface);
2177 U4(ddsd).ddpfPixelFormat.dwFourCC = MAKEFOURCC('D','X','T','5');
2178 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface, NULL);
2179 ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
2181 memset(&ddsd2, 0, sizeof(ddsd2));
2182 ddsd2.dwSize = sizeof(ddsd2);
2183 U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
2184 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd2);
2185 ok(hr == DD_OK, "GetSurfaceDesc returned %08x\n", hr);
2187 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
2188 "Surface desc flags: %08x\n", ddsd2.dwFlags);
2189 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
2190 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
2191 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
2192 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
2193 ok(U1(ddsd2).dwLinearSize == 16384, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
2194 ok(ddsd2.lpSurface == 0, "Surface memory is at %p, expected NULL\n", ddsd2.lpSurface);
2196 memset(&ddsd2, 0, sizeof(ddsd2));
2197 ddsd2.dwSize = sizeof(ddsd2);
2198 U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
2200 /* Show that the description is not changed when locking the surface. What is really interesting
2201 * about this is that DDSD_LPSURFACE isn't set.
2203 hr = IDirectDrawSurface7_Lock(surface, NULL, &ddsd2, DDLOCK_READONLY, 0);
2204 ok(hr == DD_OK, "Lock returned %08x\n", hr);
2206 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
2207 "Surface desc flags: %08x\n", ddsd2.dwFlags);
2208 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
2209 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
2210 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
2211 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
2212 ok(U1(ddsd2).dwLinearSize == 16384, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
2213 ok(ddsd2.lpSurface != 0, "Surface memory is at NULL\n");
2215 hr = IDirectDrawSurface7_Unlock(surface, NULL);
2216 ok(hr == DD_OK, "Unlock returned %08x\n", hr);
2218 /* Now what about a locking rect? */
2219 hr = IDirectDrawSurface7_Lock(surface, &r, &ddsd2, DDLOCK_READONLY, 0);
2220 ok(hr == DD_OK, "Lock 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_SYSTEMMEMORY),
2227 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
2228 ok(U1(ddsd2).dwLinearSize == 16384, "\"Linear\" size is %d\n", U1(ddsd2).dwLinearSize);
2229 ok(ddsd2.lpSurface != 0, "Surface memory is at NULL\n");
2231 hr = IDirectDrawSurface7_Unlock(surface, &r);
2232 ok(hr == DD_OK, "Unlock returned %08x\n", hr);
2234 /* Now what about a different locking offset? */
2235 hr = IDirectDrawSurface7_Lock(surface, &r2, &ddsd2, DDLOCK_READONLY, 0);
2236 ok(hr == DD_OK, "Lock returned %08x\n", hr);
2238 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
2239 "Surface desc flags: %08x\n", ddsd2.dwFlags);
2240 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
2241 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
2242 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
2243 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
2244 ok(U1(ddsd2).dwLinearSize == 16384, "\"Linear\" size is %d\n", U1(ddsd2).dwLinearSize);
2245 ok(ddsd2.lpSurface != 0, "Surface memory is at NULL\n");
2247 hr = IDirectDrawSurface7_Unlock(surface, &r2);
2248 ok(hr == DD_OK, "Unlock returned %08x\n", hr);
2250 IDirectDrawSurface7_Release(surface);
2254 skip("Hardware DXTN textures not supported\n");
2257 IDirectDraw7_Release(dd7);
2260 static void SizeTest(void)
2262 LPDIRECTDRAWSURFACE dsurface = NULL;
2265 HWND window = CreateWindow( "static", "ddraw_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
2267 /* Create an offscreen surface surface without a size */
2268 ZeroMemory(&desc, sizeof(desc));
2269 desc.dwSize = sizeof(desc);
2270 desc.dwFlags = DDSD_CAPS;
2271 desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
2272 ret = IDirectDraw_CreateSurface(lpDD, &desc, &dsurface, NULL);
2273 ok(ret == DDERR_INVALIDPARAMS, "Creating an offscreen plain surface without a size info returned %08x (dsurface=%p)\n", ret, dsurface);
2276 trace("Surface at %p\n", dsurface);
2277 IDirectDrawSurface_Release(dsurface);
2281 /* Create an offscreen surface surface with only a width parameter */
2282 ZeroMemory(&desc, sizeof(desc));
2283 desc.dwSize = sizeof(desc);
2284 desc.dwFlags = DDSD_CAPS | DDSD_WIDTH;
2285 desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
2287 ret = IDirectDraw_CreateSurface(lpDD, &desc, &dsurface, NULL);
2288 ok(ret == DDERR_INVALIDPARAMS, "Creating an offscreen plain surface without hight info returned %08x\n", ret);
2291 IDirectDrawSurface_Release(dsurface);
2295 /* Create an offscreen surface surface with only a height parameter */
2296 ZeroMemory(&desc, sizeof(desc));
2297 desc.dwSize = sizeof(desc);
2298 desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT;
2299 desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
2300 desc.dwHeight = 128;
2301 ret = IDirectDraw_CreateSurface(lpDD, &desc, &dsurface, NULL);
2302 ok(ret == DDERR_INVALIDPARAMS, "Creating an offscreen plain surface without width info returned %08x\n", ret);
2305 IDirectDrawSurface_Release(dsurface);
2310 ZeroMemory(&desc, sizeof(desc));
2311 desc.dwSize = sizeof(desc);
2312 desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
2313 desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
2314 desc.dwHeight = 128;
2316 ret = IDirectDraw_CreateSurface(lpDD, &desc, &dsurface, NULL);
2317 ok(ret == DD_OK, "Creating an offscreen plain surface with width and height info returned %08x\n", ret);
2320 IDirectDrawSurface_Release(dsurface);
2324 /* Test a primary surface size */
2325 ret = IDirectDraw_SetCooperativeLevel(lpDD, window, DDSCL_NORMAL);
2326 ok(ret == DD_OK, "SetCooperativeLevel failed with %08x\n", ret);
2328 ZeroMemory(&desc, sizeof(desc));
2329 desc.dwSize = sizeof(desc);
2330 desc.dwFlags = DDSD_CAPS;
2331 desc.ddsCaps.dwCaps |= DDSCAPS_PRIMARYSURFACE;
2332 desc.dwHeight = 128; /* Keep them set to check what happens */
2333 desc.dwWidth = 128; /* Keep them set to check what happens */
2334 ret = IDirectDraw_CreateSurface(lpDD, &desc, &dsurface, NULL);
2335 ok(ret == DD_OK, "Creating a primary surface without width and height info returned %08x\n", ret);
2338 ret = IDirectDrawSurface_GetSurfaceDesc(dsurface, &desc);
2339 ok(ret == DD_OK, "GetSurfaceDesc returned %x\n", ret);
2341 IDirectDrawSurface_Release(dsurface);
2344 ok(desc.dwFlags & DDSD_WIDTH, "Primary surface doesn't have width set\n");
2345 ok(desc.dwFlags & DDSD_HEIGHT, "Primary surface doesn't have height set\n");
2346 ok(desc.dwWidth == GetSystemMetrics(SM_CXSCREEN), "Surface width differs from screen width\n");
2347 ok(desc.dwHeight == GetSystemMetrics(SM_CYSCREEN), "Surface height differs from screen height\n");
2349 ret = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_NORMAL);
2350 ok(ret == DD_OK, "SetCooperativeLevel failed with %08x\n", ret);
2353 static void PrivateDataTest(void)
2356 IDirectDrawSurface7 *surface7 = NULL;
2357 IDirectDrawSurface *surface = NULL;
2361 DWORD size = sizeof(IUnknown *);
2363 ZeroMemory(&desc, sizeof(desc));
2364 desc.dwSize = sizeof(desc);
2365 desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
2366 desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
2367 desc.dwHeight = 128;
2369 hr = IDirectDraw_CreateSurface(lpDD, &desc, &surface, NULL);
2370 ok(hr == DD_OK, "Creating an offscreen plain surface failed with %08x\n", hr);
2375 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirectDrawSurface7, (void **) &surface7);
2376 ok(hr == DD_OK, "IDirectDrawSurface_QueryInterface failed with %08x\n", hr);
2379 IDirectDrawSurface_Release(surface);
2384 hr = IDirectDrawSurface7_SetPrivateData(surface7, &IID_IDirectDrawSurface7 /* Abuse this tag */, lpDD, 0, DDSPD_IUNKNOWNPOINTER);
2385 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr);
2386 hr = IDirectDrawSurface7_SetPrivateData(surface7, &IID_IDirectDrawSurface7 /* Abuse this tag */, lpDD, 5, DDSPD_IUNKNOWNPOINTER);
2387 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr);
2388 hr = IDirectDrawSurface7_SetPrivateData(surface7, &IID_IDirectDrawSurface7 /* Abuse this tag */, lpDD, sizeof(IUnknown *) * 2, DDSPD_IUNKNOWNPOINTER);
2389 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr);
2391 ref = getref((IUnknown *) lpDD);
2392 hr = IDirectDrawSurface7_SetPrivateData(surface7, &IID_IDirectDrawSurface7 /* Abuse this tag */, lpDD, sizeof(IUnknown *), DDSPD_IUNKNOWNPOINTER);
2393 ok(hr == DD_OK, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr);
2394 ref2 = getref((IUnknown *) lpDD);
2395 ok(ref2 == ref + 1, "Object reference is %d, expected %d\n", ref2, ref + 1);
2396 hr = IDirectDrawSurface7_FreePrivateData(surface7, &IID_IDirectDrawSurface7);
2397 ref2 = getref((IUnknown *) lpDD);
2398 ok(ref2 == ref, "Object reference is %d, expected %d\n", ref2, ref);
2400 hr = IDirectDrawSurface7_SetPrivateData(surface7, &IID_IDirectDrawSurface7, lpDD, sizeof(IUnknown *), DDSPD_IUNKNOWNPOINTER);
2401 ok(hr == DD_OK, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr);
2402 hr = IDirectDrawSurface7_SetPrivateData(surface7, &IID_IDirectDrawSurface7, surface7, sizeof(IUnknown *), DDSPD_IUNKNOWNPOINTER);
2403 ok(hr == DD_OK, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr);
2404 ref2 = getref((IUnknown *) lpDD);
2405 ok(ref2 == ref, "Object reference is %d, expected %d\n", ref2, ref);
2407 hr = IDirectDrawSurface7_SetPrivateData(surface7, &IID_IDirectDrawSurface7, lpDD, sizeof(IUnknown *), DDSPD_IUNKNOWNPOINTER);
2408 ok(hr == DD_OK, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr);
2409 hr = IDirectDrawSurface7_GetPrivateData(surface7, &IID_IDirectDrawSurface7, &ptr, &size);
2410 ok(hr == DD_OK, "IDirectDrawSurface7_GetPrivateData failed with %08x\n", hr);
2411 ref2 = getref((IUnknown *) lpDD);
2412 /* Object is NOT being addrefed */
2413 ok(ptr == (IUnknown *) lpDD, "Returned interface pointer is %p, expected %p\n", ptr, lpDD);
2414 ok(ref2 == ref + 1, "Object reference is %d, expected %d. ptr at %p, orig at %p\n", ref2, ref + 1, ptr, lpDD);
2416 IDirectDrawSurface_Release(surface);
2417 IDirectDrawSurface7_Release(surface7);
2419 /* Destroying the surface frees the held reference */
2420 ref2 = getref((IUnknown *) lpDD);
2421 ok(ref2 == ref, "Object reference is %d, expected %d\n", ref2, ref);
2424 static void BltParamTest(void)
2426 IDirectDrawSurface *surface1 = NULL, *surface2 = NULL;
2430 RECT valid = {10, 10, 20, 20};
2431 RECT invalid1 = {20, 10, 10, 20};
2432 RECT invalid2 = {20, 20, 20, 20};
2433 RECT invalid3 = {-1, -1, 20, 20};
2434 RECT invalid4 = {60, 60, 70, 70};
2436 memset(&desc, 0, sizeof(desc));
2437 desc.dwSize = sizeof(desc);
2438 desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
2439 desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
2440 desc.dwHeight = 128;
2442 hr = IDirectDraw_CreateSurface(lpDD, &desc, &surface1, NULL);
2443 ok(hr == DD_OK, "Creating an offscreen plain surface failed with %08x\n", hr);
2447 hr = IDirectDraw_CreateSurface(lpDD, &desc, &surface2, NULL);
2448 ok(hr == DD_OK, "Creating an offscreen plain surface failed with %08x\n", hr);
2453 hr = IDirectDrawSurface_BltFast(surface1, 0, 0, NULL, NULL, 0);
2454 ok(hr == DD_OK, "BltFast from NULL surface returned %08x\n", hr);
2456 hr = IDirectDrawSurface_BltFast(surface1, 0, 0, surface2, NULL, 0);
2457 ok(hr == DD_OK, "BltFast from smaller to bigger surface returned %08x\n", hr);
2458 hr = IDirectDrawSurface_BltFast(surface2, 0, 0, surface1, NULL, 0);
2459 ok(hr == DDERR_INVALIDRECT, "BltFast from bigger to smaller surface returned %08x\n", hr);
2460 hr = IDirectDrawSurface_BltFast(surface2, 0, 0, surface1, &valid, 0);
2461 ok(hr == DD_OK, "BltFast from bigger to smaller surface using a valid rectangle returned %08x\n", hr);
2462 hr = IDirectDrawSurface_BltFast(surface2, 60, 60, surface1, &valid, 0);
2463 ok(hr == DDERR_INVALIDRECT, "BltFast with a rectangle resulting in an off-surface write returned %08x\n", hr);
2464 hr = IDirectDrawSurface_BltFast(surface1, 90, 90, surface2, NULL, 0);
2465 ok(hr == DDERR_INVALIDRECT, "BltFast with a rectangle resulting in an off-surface write returned %08x\n", hr);
2466 hr = IDirectDrawSurface_BltFast(surface2, 0, 0, surface1, &invalid1, 0);
2467 ok(hr == DDERR_INVALIDRECT, "BltFast with invalid rectangle 1 returned %08x\n", hr);
2468 hr = IDirectDrawSurface_BltFast(surface2, 0, 0, surface1, &invalid2, 0);
2469 ok(hr == DDERR_INVALIDRECT, "BltFast with invalid rectangle 2 returned %08x\n", hr);
2470 hr = IDirectDrawSurface_BltFast(surface2, 0, 0, surface1, &invalid3, 0);
2471 ok(hr == DDERR_INVALIDRECT, "BltFast with invalid rectangle 3 returned %08x\n", hr);
2472 hr = IDirectDrawSurface_BltFast(surface1, 0, 0, surface2, &invalid4, 0);
2473 ok(hr == DDERR_INVALIDRECT, "BltFast with invalid rectangle 3 returned %08x\n", hr);
2474 hr = IDirectDrawSurface_BltFast(surface1, 0, 0, surface1, NULL, 0);
2475 ok(hr == DD_OK, "BltFast blitting a surface onto itself returned %08x\n", hr);
2477 /* Blt(non-fast) tests */
2478 memset(&BltFx, 0, sizeof(BltFx));
2479 BltFx.dwSize = sizeof(BltFx);
2480 U5(BltFx).dwFillColor = 0xaabbccdd;
2482 hr = IDirectDrawSurface_Blt(surface1, &valid, NULL, NULL, DDBLT_COLORFILL, &BltFx);
2483 ok(hr == DD_OK, "IDirectDrawSurface_Blt with a valid rectangle for color fill returned %08x\n", hr);
2484 hr = IDirectDrawSurface_Blt(surface1, &valid, NULL, &invalid3, DDBLT_COLORFILL, &BltFx);
2485 ok(hr == DD_OK, "IDirectDrawSurface_Blt with a invalid, unused rectangle returned %08x\n", hr);
2486 hr = IDirectDrawSurface_Blt(surface2, &invalid1, NULL, NULL, DDBLT_COLORFILL, &BltFx);
2487 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 1 returned %08x\n", hr);
2488 hr = IDirectDrawSurface_Blt(surface2, &invalid2, NULL, NULL, DDBLT_COLORFILL, &BltFx);
2489 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 2 returned %08x\n", hr);
2490 hr = IDirectDrawSurface_Blt(surface2, &invalid3, NULL, NULL, DDBLT_COLORFILL, &BltFx);
2491 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 3 returned %08x\n", hr);
2492 hr = IDirectDrawSurface_Blt(surface2, &invalid4, NULL, NULL, DDBLT_COLORFILL, &BltFx);
2493 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 4 returned %08x\n", hr);
2495 /* Valid on surface 1 */
2496 hr = IDirectDrawSurface_Blt(surface1, &invalid4, NULL, NULL, DDBLT_COLORFILL, &BltFx);
2497 ok(hr == DD_OK, "IDirectDrawSurface_Blt with a subrectangle fill returned %08x\n", hr);
2499 /* Works - stretched blit */
2500 hr = IDirectDrawSurface_Blt(surface1, NULL, surface2, NULL, 0, NULL);
2501 ok(hr == DD_OK, "IDirectDrawSurface_Blt from a smaller to a bigger surface returned %08x\n", hr);
2502 hr = IDirectDrawSurface_Blt(surface2, NULL, surface1, NULL, 0, NULL);
2503 ok(hr == DD_OK, "IDirectDrawSurface_Blt from a bigger to a smaller surface %08x\n", hr);
2505 /* Invalid dest rects in sourced blits */
2506 hr = IDirectDrawSurface_Blt(surface2, &invalid1, surface1, NULL, 0, NULL);
2507 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 1 returned %08x\n", hr);
2508 hr = IDirectDrawSurface_Blt(surface2, &invalid2, surface1, NULL, 0, NULL);
2509 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 2 returned %08x\n", hr);
2510 hr = IDirectDrawSurface_Blt(surface2, &invalid3, surface1, NULL, 0, NULL);
2511 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 3 returned %08x\n", hr);
2512 hr = IDirectDrawSurface_Blt(surface2, &invalid4, surface1, NULL, 0, NULL);
2513 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 4 returned %08x\n", hr);
2515 /* Invalid src rects */
2516 hr = IDirectDrawSurface_Blt(surface2, NULL, surface1, &invalid1, 0, NULL);
2517 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 1 returned %08x\n", hr);
2518 hr = IDirectDrawSurface_Blt(surface2, NULL, surface1, &invalid2, 0, NULL);
2519 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 2 returned %08x\n", hr);
2520 hr = IDirectDrawSurface_Blt(surface2, NULL, surface1, &invalid3, 0, NULL);
2521 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 3 returned %08x\n", hr);
2522 hr = IDirectDrawSurface_Blt(surface1, NULL, surface2, &invalid4, 0, NULL);
2523 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 4 returned %08x\n", hr);
2525 IDirectDrawSurface_Release(surface1);
2526 IDirectDrawSurface_Release(surface2);
2529 static void PaletteTest(void)
2532 LPDIRECTDRAWSURFACE lpSurf = NULL;
2534 IDirectDrawPalette *palette = NULL;
2535 PALETTEENTRY Table[256];
2536 PALETTEENTRY palEntries[256];
2539 for(i=0; i<256; i++)
2541 Table[i].peRed = 0xff;
2542 Table[i].peGreen = 0;
2543 Table[i].peBlue = 0;
2544 Table[i].peFlags = 0;
2547 /* Create a 8bit palette without DDPCAPS_ALLOW256 set */
2548 hr = IDirectDraw_CreatePalette(lpDD, DDPCAPS_8BIT, Table, &palette, NULL);
2549 ok(hr == DD_OK, "CreatePalette failed with %08x\n", hr);
2550 if (FAILED(hr)) goto err;
2551 /* Read back the palette and verify the entries. Without DDPCAPS_ALLOW256 set
2552 / entry 0 and 255 should have been overwritten with black and white */
2553 IDirectDrawPalette_GetEntries(palette , 0, 0, 256, &palEntries[0]);
2554 ok(hr == DD_OK, "GetEntries failed with %08x\n", hr);
2557 ok((palEntries[0].peRed == 0) && (palEntries[0].peGreen == 0) && (palEntries[0].peBlue == 0),
2558 "Palette entry 0 of a palette without DDPCAPS_ALLOW256 set should be (0,0,0) but it is (%d,%d,%d)\n",
2559 palEntries[0].peRed, palEntries[0].peGreen, palEntries[0].peBlue);
2560 ok((palEntries[255].peRed == 255) && (palEntries[255].peGreen == 255) && (palEntries[255].peBlue == 255),
2561 "Palette entry 255 of a palette without DDPCAPS_ALLOW256 set should be (255,255,255) but it is (%d,%d,%d)\n",
2562 palEntries[255].peRed, palEntries[255].peGreen, palEntries[255].peBlue);
2564 /* Entry 1-254 should contain red */
2565 for(i=1; i<255; i++)
2566 ok((palEntries[i].peRed == 255) && (palEntries[i].peGreen == 0) && (palEntries[i].peBlue == 0),
2567 "Palette entry %d should have contained (255,0,0) but was set to %d,%d,%d)\n",
2568 i, palEntries[i].peRed, palEntries[i].peGreen, palEntries[i].peBlue);
2571 /* CreatePalette without DDPCAPS_ALLOW256 ignores entry 0 and 255,
2572 / now check we are able to update the entries afterwards. */
2573 IDirectDrawPalette_SetEntries(palette , 0, 0, 256, &Table[0]);
2574 ok(hr == DD_OK, "SetEntries failed with %08x\n", hr);
2575 IDirectDrawPalette_GetEntries(palette , 0, 0, 256, &palEntries[0]);
2576 ok(hr == DD_OK, "GetEntries failed with %08x\n", hr);
2579 ok((palEntries[0].peRed == 0) && (palEntries[0].peGreen == 0) && (palEntries[0].peBlue == 0),
2580 "Palette entry 0 should have been set to (0,0,0) but it contains (%d,%d,%d)\n",
2581 palEntries[0].peRed, palEntries[0].peGreen, palEntries[0].peBlue);
2582 ok((palEntries[255].peRed == 255) && (palEntries[255].peGreen == 255) && (palEntries[255].peBlue == 255),
2583 "Palette entry 255 should have been set to (255,255,255) but it contains (%d,%d,%d)\n",
2584 palEntries[255].peRed, palEntries[255].peGreen, palEntries[255].peBlue);
2586 IDirectDrawPalette_Release(palette);
2588 /* Create a 8bit palette with DDPCAPS_ALLOW256 set */
2589 hr = IDirectDraw_CreatePalette(lpDD, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, Table, &palette, NULL);
2590 ok(hr == DD_OK, "CreatePalette failed with %08x\n", hr);
2591 if (FAILED(hr)) goto err;
2593 IDirectDrawPalette_GetEntries(palette , 0, 0, 256, &palEntries[0]);
2594 ok(hr == DD_OK, "GetEntries failed with %08x\n", hr);
2597 /* All entries should contain red */
2598 for(i=0; i<256; i++)
2599 ok((palEntries[i].peRed == 255) && (palEntries[i].peGreen == 0) && (palEntries[i].peBlue == 0),
2600 "Palette entry %d should have contained (255,0,0) but was set to %d,%d,%d)\n",
2601 i, palEntries[i].peRed, palEntries[i].peGreen, palEntries[i].peBlue);
2604 /* Try to set palette to a non-palettized surface */
2605 ddsd.dwSize = sizeof(ddsd);
2606 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
2607 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
2608 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
2610 ddsd.dwHeight = 600;
2611 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
2612 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 32;
2613 U2(ddsd.ddpfPixelFormat).dwRBitMask = 0xFF0000;
2614 U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x00FF00;
2615 U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x0000FF;
2616 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpSurf, NULL);
2617 ok(hr==DD_OK, "CreateSurface returned: %x\n",hr);
2619 skip("failed to create surface\n");
2623 hr = IDirectDrawSurface_SetPalette(lpSurf, palette);
2624 ok(hr == DDERR_INVALIDPIXELFORMAT, "CreateSurface returned: %x\n",hr);
2626 IDirectDrawPalette_Release(palette);
2629 hr = IDirectDrawSurface_GetPalette(lpSurf, &palette);
2630 ok(hr == DDERR_NOPALETTEATTACHED, "CreateSurface returned: %x\n",hr);
2634 if (lpSurf) IDirectDrawSurface_Release(lpSurf);
2635 if (palette) IDirectDrawPalette_Release(palette);
2638 static void StructSizeTest(void)
2640 IDirectDrawSurface *surface1;
2641 IDirectDrawSurface7 *surface7;
2643 DDSURFACEDESC desc1;
2644 DDSURFACEDESC2 desc2;
2645 char blob[1024]; /* To get a bunch of writable memory */
2647 DDSURFACEDESC create;
2650 memset(&desc, 0, sizeof(desc));
2651 memset(&create, 0, sizeof(create));
2653 memset(&create, 0, sizeof(create));
2654 create.dwSize = sizeof(create);
2655 create.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
2656 create.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
2657 create.dwHeight = 128;
2658 create.dwWidth = 128;
2659 hr = IDirectDraw_CreateSurface(lpDD, &create, &surface1, NULL);
2660 ok(hr == DD_OK, "Creating an offscreen plain surface failed with %08x\n", hr);
2661 hr = IDirectDrawSurface_QueryInterface(surface1, &IID_IDirectDrawSurface7, (void **) &surface7);
2662 ok(hr == DD_OK, "IDirectDrawSurface_QueryInterface failed with %08x\n", hr);
2664 desc.desc1.dwSize = sizeof(DDSURFACEDESC);
2665 hr = IDirectDrawSurface_GetSurfaceDesc(surface1, &desc.desc1);
2666 ok(hr == DD_OK, "IDirectDrawSurface_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC) returned %08x\n", hr);
2667 hr = IDirectDrawSurface7_GetSurfaceDesc(surface7, &desc.desc2);
2668 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC) returned %08x\n", hr);
2670 desc.desc2.dwSize = sizeof(DDSURFACEDESC2);
2671 hr = IDirectDrawSurface_GetSurfaceDesc(surface1, &desc.desc1);
2672 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC2) returned %08x\n", hr);
2673 hr = IDirectDrawSurface7_GetSurfaceDesc(surface7, &desc.desc2);
2674 ok(hr == DD_OK, "IDirectDrawSurface7_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC2) returned %08x\n", hr);
2676 desc.desc2.dwSize = 0;
2677 hr = IDirectDrawSurface_GetSurfaceDesc(surface1, &desc.desc1);
2678 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface_GetSurfaceDesc with desc size 0 returned %08x\n", hr);
2679 hr = IDirectDrawSurface7_GetSurfaceDesc(surface7, &desc.desc2);
2680 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_GetSurfaceDesc with desc size 0 returned %08x\n", hr);
2682 desc.desc1.dwSize = sizeof(DDSURFACEDESC) + 1;
2683 hr = IDirectDrawSurface_GetSurfaceDesc(surface1, &desc.desc1);
2684 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC) + 1 returned %08x\n", hr);
2685 hr = IDirectDrawSurface7_GetSurfaceDesc(surface7, &desc.desc2);
2686 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC) + 1 returned %08x\n", hr);
2688 desc.desc2.dwSize = sizeof(DDSURFACEDESC2) + 1;
2689 hr = IDirectDrawSurface_GetSurfaceDesc(surface1, &desc.desc1);
2690 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC2) + 1returned %08x\n", hr);
2691 hr = IDirectDrawSurface7_GetSurfaceDesc(surface7, &desc.desc2);
2692 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC2) + 1returned %08x\n", hr);
2694 /* Tests for Lock() */
2696 desc.desc1.dwSize = sizeof(DDSURFACEDESC);
2697 hr = IDirectDrawSurface_Lock(surface1, NULL, &desc.desc1, 0, 0);
2698 ok(hr == DD_OK, "IDirectDrawSurface_Lock with desc size sizeof(DDSURFACEDESC) returned %08x\n", hr);
2699 if(SUCCEEDED(hr)) IDirectDrawSurface_Unlock(surface1, NULL);
2700 ok(desc.desc1.dwSize == sizeof(DDSURFACEDESC), "Destination size was changed to %d\n", desc.desc1.dwSize);
2701 hr = IDirectDrawSurface7_Lock(surface7, NULL, &desc.desc2, 0, 0);
2702 ok(hr == DD_OK, "IDirectDrawSurface7_Lock with desc size sizeof(DDSURFACEDESC) returned %08x\n", hr);
2703 if(SUCCEEDED(hr)) IDirectDrawSurface7_Unlock(surface7, NULL);
2704 ok(desc.desc2.dwSize == sizeof(DDSURFACEDESC), "Destination size was changed to %d\n", desc.desc1.dwSize);
2706 desc.desc2.dwSize = sizeof(DDSURFACEDESC2);
2707 hr = IDirectDrawSurface_Lock(surface1, NULL, &desc.desc1, 0, 0);
2708 ok(hr == DD_OK, "IDirectDrawSurface_Lock with desc size sizeof(DDSURFACEDESC2) returned %08x\n", hr);
2709 ok(desc.desc1.dwSize == sizeof(DDSURFACEDESC2), "Destination size was changed to %d\n", desc.desc1.dwSize);
2710 if(SUCCEEDED(hr)) IDirectDrawSurface_Unlock(surface1, NULL);
2711 hr = IDirectDrawSurface7_Lock(surface7, NULL, &desc.desc2, 0, 0);
2712 ok(hr == DD_OK, "IDirectDrawSurface7_Lock with desc size sizeof(DDSURFACEDESC2) returned %08x\n", hr);
2713 if(SUCCEEDED(hr)) IDirectDrawSurface7_Unlock(surface7, NULL);
2714 ok(desc.desc2.dwSize == sizeof(DDSURFACEDESC2), "Destination size was changed to %d\n", desc.desc1.dwSize);
2716 desc.desc2.dwSize = 0;
2717 hr = IDirectDrawSurface_Lock(surface1, NULL, &desc.desc1, 0, 0);
2718 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface_Lock with desc size 0 returned %08x\n", hr);
2719 if(SUCCEEDED(hr)) IDirectDrawSurface_Unlock(surface1, NULL);
2720 hr = IDirectDrawSurface7_Lock(surface7, NULL, &desc.desc2, 0, 0);
2721 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_Lock with desc size 0 returned %08x\n", hr);
2722 if(SUCCEEDED(hr)) IDirectDrawSurface7_Unlock(surface7, NULL);
2724 desc.desc1.dwSize = sizeof(DDSURFACEDESC) + 1;
2725 hr = IDirectDrawSurface_Lock(surface1, NULL, &desc.desc1, 0, 0);
2726 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface_Lock with desc size sizeof(DDSURFACEDESC) + 1 returned %08x\n", hr);
2727 if(SUCCEEDED(hr)) IDirectDrawSurface_Unlock(surface1, NULL);
2728 hr = IDirectDrawSurface7_Lock(surface7, NULL, &desc.desc2, 0, 0);
2729 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_Lock with desc size sizeof(DDSURFACEDESC) + 1 returned %08x\n", hr);
2730 if(SUCCEEDED(hr)) IDirectDrawSurface7_Unlock(surface7, NULL);
2732 desc.desc2.dwSize = sizeof(DDSURFACEDESC2) + 1;
2733 hr = IDirectDrawSurface_Lock(surface1, NULL, &desc.desc1, 0, 0);
2734 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface_Lock with desc size sizeof(DDSURFACEDESC2) + 1returned %08x\n", hr);
2735 if(SUCCEEDED(hr)) IDirectDrawSurface_Unlock(surface1, NULL);
2736 hr = IDirectDrawSurface7_Lock(surface7, NULL, &desc.desc2, 0, 0);
2737 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_Lock with desc size sizeof(DDSURFACEDESC2) + 1returned %08x\n", hr);
2738 if(SUCCEEDED(hr)) IDirectDrawSurface7_Unlock(surface7, NULL);
2740 IDirectDrawSurface7_Release(surface7);
2741 IDirectDrawSurface_Release(surface1);
2744 static void SurfaceCapsTest(void)
2746 DDSURFACEDESC create;
2749 IDirectDrawSurface *surface1 = NULL;
2750 DDSURFACEDESC2 create2, desc2;
2751 IDirectDrawSurface7 *surface7 = NULL;
2752 IDirectDraw7 *dd7 = NULL;
2753 DWORD create_caps[] = {
2754 DDSCAPS_OFFSCREENPLAIN,
2756 DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD,
2758 DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD | DDSCAPS_SYSTEMMEMORY,
2759 DDSCAPS_PRIMARYSURFACE,
2760 DDSCAPS_PRIMARYSURFACE | DDSCAPS_SYSTEMMEMORY
2762 DWORD expected_caps[] = {
2763 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
2764 DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
2765 DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM | DDSCAPS_ALLOCONLOAD,
2766 DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
2767 DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD | DDSCAPS_SYSTEMMEMORY,
2768 DDSCAPS_PRIMARYSURFACE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM | DDSCAPS_VISIBLE,
2769 DDSCAPS_PRIMARYSURFACE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_VISIBLE
2774 /* Tests various surface flags, what changes do they undergo during surface creation. Forsaken
2775 * engine expects texture surfaces without memory flag to get a video memory flag right after
2776 * creation. Currently, Wine adds DDSCAPS_FRONTBUFFER to primary surface, but native doesn't do this
2777 * for single buffered primaries. Because of this primary surface creation tests are todo_wine. No real
2778 * app is known so far to care about this. */
2779 ddcaps.dwSize = sizeof(DDCAPS);
2780 hr = IDirectDraw_GetCaps(lpDD, &ddcaps, NULL);
2781 ok(hr == DD_OK, "IDirectDraw_GetCaps failed with %08x\n", hr);
2783 if (!(ddcaps.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY))
2785 skip("DDraw reported no VIDEOMEMORY cap. Broken video driver? Skipping surface caps tests.\n");
2789 for (i = 0; i < sizeof(create_caps) / sizeof(DWORD); i++)
2791 memset(&create, 0, sizeof(create));
2792 create.dwSize = sizeof(create);
2793 create.ddsCaps.dwCaps = create_caps[i];
2794 create.dwFlags = DDSD_CAPS;
2796 if (!(create.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE))
2798 create.dwFlags |= DDSD_HEIGHT | DDSD_WIDTH;
2799 create.dwHeight = 128;
2800 create.dwWidth = 128;
2803 hr = IDirectDraw_CreateSurface(lpDD, &create, &surface1, NULL);
2804 ok(hr == DD_OK, "IDirectDraw_CreateSurface failed with %08x\n", hr);
2808 memset(&desc, 0, sizeof(desc));
2809 desc.dwSize = sizeof(DDSURFACEDESC);
2810 hr = IDirectDrawSurface_GetSurfaceDesc(surface1, &desc);
2811 ok(hr == DD_OK, "IDirectDrawSurface_GetSurfaceDesc failed with %08x\n", hr);
2813 if (!(create_caps[i] & DDSCAPS_PRIMARYSURFACE))
2814 ok(desc.ddsCaps.dwCaps == expected_caps[i],
2815 "GetSurfaceDesc returned caps %x, expected %x\n", desc.ddsCaps.dwCaps,
2818 todo_wine ok(desc.ddsCaps.dwCaps == expected_caps[i],
2819 "GetSurfaceDesc returned caps %x, expected %x\n", desc.ddsCaps.dwCaps,
2822 IDirectDrawSurface_Release(surface1);
2826 /* Test for differences in ddraw 7 */
2827 hr = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
2828 ok(hr == DD_OK, "IDirectDraw_QueryInterface returned %08x\n", hr);
2831 skip("Failed to get IDirectDraw7 interface, skipping tests\n");
2835 for (i = 0; i < sizeof(create_caps) / sizeof(DWORD); i++)
2837 memset(&create2, 0, sizeof(create2));
2838 create2.dwSize = sizeof(create2);
2839 create2.ddsCaps.dwCaps = create_caps[i];
2840 create2.dwFlags = DDSD_CAPS;
2842 if (!(create2.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE))
2844 create2.dwFlags |= DDSD_HEIGHT | DDSD_WIDTH;
2845 create2.dwHeight = 128;
2846 create2.dwWidth = 128;
2849 hr = IDirectDraw7_CreateSurface(dd7, &create2, &surface7, NULL);
2850 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
2854 memset(&desc2, 0, sizeof(desc2));
2855 desc2.dwSize = sizeof(DDSURFACEDESC2);
2856 hr = IDirectDrawSurface7_GetSurfaceDesc(surface7, &desc2);
2857 ok(hr == DD_OK, "IDirectDrawSurface_GetSurfaceDesc failed with %08x\n", hr);
2859 if (!(create_caps[i] & DDSCAPS_PRIMARYSURFACE))
2860 ok(desc2.ddsCaps.dwCaps == expected_caps[i],
2861 "GetSurfaceDesc returned caps %x, expected %x\n", desc2.ddsCaps.dwCaps,
2864 todo_wine ok(desc2.ddsCaps.dwCaps == expected_caps[i],
2865 "GetSurfaceDesc returned caps %x, expected %x\n", desc2.ddsCaps.dwCaps,
2868 IDirectDrawSurface7_Release(surface7);
2872 IDirectDraw7_Release(dd7);
2875 memset(&create, 0, sizeof(create));
2876 create.dwSize = sizeof(create);
2877 create.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
2878 create.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_VIDEOMEMORY;
2879 create.dwWidth = 64;
2880 create.dwHeight = 64;
2881 hr = IDirectDraw_CreateSurface(lpDD, &create, &surface1, NULL);
2882 ok(hr == DDERR_INVALIDCAPS, "Creating a SYSMEM | VIDMEM surface returned 0x%08x, expected DDERR_INVALIDCAPS\n", hr);
2883 if(surface1) IDirectDrawSurface_Release(surface1);
2886 static BOOL can_create_primary_surface(void)
2889 IDirectDrawSurface *surface;
2892 memset(&ddsd, 0, sizeof(ddsd));
2893 ddsd.dwSize = sizeof(ddsd);
2894 ddsd.dwFlags = DDSD_CAPS;
2895 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2896 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface, NULL);
2897 if(FAILED(hr)) return FALSE;
2898 IDirectDrawSurface_Release(surface);
2902 static void dctest_surf(IDirectDrawSurface *surf, int ddsdver) {
2904 HDC dc, dc2 = (HDC) 0x1234;
2906 DDSURFACEDESC2 ddsd2;
2908 memset(&ddsd, 0, sizeof(ddsd));
2909 ddsd.dwSize = sizeof(ddsd);
2910 memset(&ddsd2, 0, sizeof(ddsd2));
2911 ddsd2.dwSize = sizeof(ddsd2);
2913 hr = IDirectDrawSurface_GetDC(surf, &dc);
2914 ok(hr == DD_OK, "IDirectDrawSurface_GetDC failed: 0x%08x\n", hr);
2916 hr = IDirectDrawSurface_GetDC(surf, &dc2);
2917 ok(hr == DDERR_DCALREADYCREATED, "IDirectDrawSurface_GetDC failed: 0x%08x\n", hr);
2918 ok(dc2 == (HDC) 0x1234, "The failed GetDC call changed the dc: %p\n", dc2);
2920 hr = IDirectDrawSurface_Lock(surf, NULL, ddsdver == 1 ? &ddsd : ((DDSURFACEDESC *) &ddsd2), 0, NULL);
2921 ok(hr == DDERR_SURFACEBUSY, "IDirectDrawSurface_Lock returned 0x%08x, expected DDERR_ALREADYLOCKED\n", hr);
2923 hr = IDirectDrawSurface_ReleaseDC(surf, dc);
2924 ok(hr == DD_OK, "IDirectDrawSurface_ReleaseDC failed: 0x%08x\n", hr);
2925 hr = IDirectDrawSurface_ReleaseDC(surf, dc);
2926 ok(hr == DDERR_NODC, "IDirectDrawSurface_ReleaseDC returned 0x%08x, expected DDERR_NODC\n", hr);
2929 static void GetDCTest(void)
2932 DDSURFACEDESC2 ddsd2;
2933 IDirectDrawSurface *surf;
2934 IDirectDrawSurface2 *surf2;
2935 IDirectDrawSurface4 *surf4;
2936 IDirectDrawSurface7 *surf7;
2942 memset(&ddsd, 0, sizeof(ddsd));
2943 ddsd.dwSize = sizeof(ddsd);
2944 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
2947 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
2948 memset(&ddsd2, 0, sizeof(ddsd2));
2949 ddsd2.dwSize = sizeof(ddsd2);
2950 ddsd2.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
2952 ddsd2.dwHeight = 64;
2953 ddsd2.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
2955 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &surf, NULL);
2956 ok(hr == DD_OK, "IDirectDraw_CreateSurface failed: 0x%08x\n", hr);
2957 dctest_surf(surf, 1);
2958 IDirectDrawSurface_Release(surf);
2960 hr = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw2, (void **) &dd2);
2961 ok(hr == DD_OK, "IDirectDraw_QueryInterface failed: 0x%08x\n", hr);
2963 hr = IDirectDraw2_CreateSurface(dd2, &ddsd, &surf, NULL);
2964 ok(hr == DD_OK, "IDirectDraw2_CreateSurface failed: 0x%08x\n", hr);
2965 dctest_surf(surf, 1);
2967 hr = IDirectDrawSurface_QueryInterface(surf, &IID_IDirectDrawSurface2, (void **) &surf2);
2968 ok(hr == DD_OK, "IDirectDrawSurface_QueryInterface failed: 0x%08x\n", hr);
2969 dctest_surf((IDirectDrawSurface *) surf2, 1);
2971 IDirectDrawSurface2_Release(surf2);
2972 IDirectDrawSurface_Release(surf);
2973 IDirectDraw2_Release(dd2);
2975 hr = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw4, (void **) &dd4);
2976 ok(hr == DD_OK, "IDirectDraw_QueryInterface failed: 0x%08x\n", hr);
2979 hr = IDirectDraw4_CreateSurface(dd4, &ddsd2, &surf4, NULL);
2980 ok(hr == DD_OK, "IDirectDraw4_CreateSurface failed: 0x%08x\n", hr);
2981 dctest_surf((IDirectDrawSurface *) surf4, 2);
2983 IDirectDrawSurface4_Release(surf4);
2984 IDirectDraw4_Release(dd4);
2986 hr = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
2987 ok(hr == DD_OK, "IDirectDraw_QueryInterface failed: 0x%08x\n", hr);
2989 hr = IDirectDraw7_CreateSurface(dd7, &ddsd2, &surf7, NULL);
2990 ok(hr == DD_OK, "IDirectDraw7_CreateSurface failed: 0x%08x\n", hr);
2991 dctest_surf((IDirectDrawSurface *) surf7, 2);
2993 IDirectDrawSurface7_Release(surf7);
2994 IDirectDraw7_Release(dd7);
2997 START_TEST(dsurface)
3002 if (!CreateDirectDraw())
3005 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw4, (void **) &dd4);
3006 if (ret == E_NOINTERFACE)
3008 win_skip("DirectDraw4 and higher are not supported\n");
3009 ReleaseDirectDraw();
3012 IDirectDraw_Release(dd4);
3014 if(!can_create_primary_surface())
3016 skip("Unable to create primary surface\n");
3020 MipMapCreationTest();
3021 SrcColorKey32BlitTest();
3032 test_lockrect_invalid();
3041 ReleaseDirectDraw();