push 3600ceb9798742c4473b49518e0ae238427fc4b7
[wine/hacks.git] / dlls / ddraw / tests / dsurface.c
blob80cf9b13417289793e17439b672923179c472e1f
1 /*
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
24 #define COBJMACROS
26 #include <assert.h>
27 #include "wine/test.h"
28 #include "ddraw.h"
29 #include "unknwn.h"
31 static LPDIRECTDRAW lpDD = NULL;
33 static BOOL CreateDirectDraw(void)
35 HRESULT rc;
37 rc = DirectDrawCreate(NULL, &lpDD, NULL);
38 ok(rc==DD_OK || rc==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreateEx returned: %x\n", rc);
39 if (!lpDD) {
40 trace("DirectDrawCreateEx() failed with an error %x\n", rc);
41 return FALSE;
44 rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_NORMAL);
45 ok(rc==DD_OK,"SetCooperativeLevel returned: %x\n",rc);
47 return TRUE;
51 static void ReleaseDirectDraw(void)
53 if( lpDD != NULL )
55 IDirectDraw_Release(lpDD);
56 lpDD = NULL;
60 static void MipMapCreationTest(void)
62 LPDIRECTDRAWSURFACE lpDDSMipMapTest;
63 DDSURFACEDESC ddsd;
64 HRESULT rc;
66 /* First mipmap creation test: create a surface with DDSCAPS_COMPLEX,
67 DDSCAPS_MIPMAP, and DDSD_MIPMAPCOUNT. This create the number of
68 requested mipmap levels. */
69 ddsd.dwSize = sizeof(ddsd);
70 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_MIPMAPCOUNT;
71 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
72 U2(ddsd).dwMipMapCount = 3;
73 ddsd.dwWidth = 128;
74 ddsd.dwHeight = 32;
75 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpDDSMipMapTest, NULL);
76 ok(rc==DD_OK,"CreateSurface returned: %x\n",rc);
77 if (FAILED(rc)) {
78 skip("failed to create surface\n");
79 return;
82 /* Check the number of created mipmaps */
83 memset(&ddsd, 0, sizeof(DDSURFACEDESC));
84 ddsd.dwSize = sizeof(ddsd);
85 rc = IDirectDrawSurface_GetSurfaceDesc(lpDDSMipMapTest, &ddsd);
86 ok(rc==DD_OK,"GetSurfaceDesc returned: %x\n",rc);
87 ok(ddsd.dwFlags & DDSD_MIPMAPCOUNT,
88 "GetSurfaceDesc returned no mipmapcount.\n");
89 ok(U2(ddsd).dwMipMapCount == 3, "Incorrect mipmap count: %d.\n",
90 U2(ddsd).dwMipMapCount);
92 /* Destroy the surface. */
93 IDirectDrawSurface_Release(lpDDSMipMapTest);
96 /* Second mipmap creation test: create a surface without a mipmap
97 count, with DDSCAPS_MIPMAP and without DDSCAPS_COMPLEX.
98 This creates a single mipmap level. */
99 memset(&ddsd, 0, sizeof(DDSURFACEDESC));
100 ddsd.dwSize = sizeof(ddsd);
101 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
102 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_MIPMAP;
103 ddsd.dwWidth = 128;
104 ddsd.dwHeight = 32;
105 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpDDSMipMapTest, NULL);
106 ok(rc==DD_OK,"CreateSurface returned: %x\n",rc);
107 if (FAILED(rc)) {
108 skip("failed to create surface\n");
109 return;
111 /* Check the number of created mipmaps */
112 memset(&ddsd, 0, sizeof(DDSURFACEDESC));
113 ddsd.dwSize = sizeof(ddsd);
114 rc = IDirectDrawSurface_GetSurfaceDesc(lpDDSMipMapTest, &ddsd);
115 ok(rc==DD_OK,"GetSurfaceDesc returned: %x\n",rc);
116 ok(ddsd.dwFlags & DDSD_MIPMAPCOUNT,
117 "GetSurfaceDesc returned no mipmapcount.\n");
118 ok(U2(ddsd).dwMipMapCount == 1, "Incorrect mipmap count: %d.\n",
119 U2(ddsd).dwMipMapCount);
121 /* Destroy the surface. */
122 IDirectDrawSurface_Release(lpDDSMipMapTest);
125 /* Third mipmap creation test: create a surface with DDSCAPS_MIPMAP,
126 DDSCAPS_COMPLEX and without DDSD_MIPMAPCOUNT.
127 It's an undocumented features where a chain of mipmaps, starting from
128 he specified size and down to the smallest size, is automatically
129 created.
130 Anarchy Online needs this feature to work. */
131 memset(&ddsd, 0, sizeof(DDSURFACEDESC));
132 ddsd.dwSize = sizeof(ddsd);
133 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
134 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
135 ddsd.dwWidth = 128;
136 ddsd.dwHeight = 32;
137 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpDDSMipMapTest, NULL);
138 ok(rc==DD_OK,"CreateSurface returned: %x\n",rc);
139 if (FAILED(rc)) {
140 skip("failed to create surface\n");
141 return;
144 /* Check the number of created mipmaps */
145 memset(&ddsd, 0, sizeof(DDSURFACEDESC));
146 ddsd.dwSize = sizeof(ddsd);
147 rc = IDirectDrawSurface_GetSurfaceDesc(lpDDSMipMapTest, &ddsd);
148 ok(rc==DD_OK,"GetSurfaceDesc returned: %x\n",rc);
149 ok(ddsd.dwFlags & DDSD_MIPMAPCOUNT,
150 "GetSurfaceDesc returned no mipmapcount.\n");
151 ok(U2(ddsd).dwMipMapCount == 6, "Incorrect mipmap count: %d.\n",
152 U2(ddsd).dwMipMapCount);
154 /* Destroy the surface. */
155 IDirectDrawSurface_Release(lpDDSMipMapTest);
158 /* Fourth mipmap creation test: same as above with a different texture
159 size.
160 The purpose is to verify that the number of generated mipmaps is
161 dependent on the smallest dimension. */
162 memset(&ddsd, 0, sizeof(DDSURFACEDESC));
163 ddsd.dwSize = sizeof(ddsd);
164 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
165 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
166 ddsd.dwWidth = 32;
167 ddsd.dwHeight = 64;
168 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpDDSMipMapTest, NULL);
169 ok(rc==DD_OK,"CreateSurface returned: %x\n",rc);
170 if (FAILED(rc)) {
171 skip("failed to create surface\n");
172 return;
175 /* Check the number of created mipmaps */
176 memset(&ddsd, 0, sizeof(DDSURFACEDESC));
177 ddsd.dwSize = sizeof(ddsd);
178 rc = IDirectDrawSurface_GetSurfaceDesc(lpDDSMipMapTest, &ddsd);
179 ok(rc==DD_OK,"GetSurfaceDesc returned: %x\n",rc);
180 ok(ddsd.dwFlags & DDSD_MIPMAPCOUNT,
181 "GetSurfaceDesc returned no mipmapcount.\n");
182 ok(U2(ddsd).dwMipMapCount == 6, "Incorrect mipmap count: %d.\n",
183 U2(ddsd).dwMipMapCount);
185 /* Destroy the surface. */
186 IDirectDrawSurface_Release(lpDDSMipMapTest);
189 /* Fifth mipmap creation test: try to create a surface with
190 DDSCAPS_COMPLEX, DDSCAPS_MIPMAP, DDSD_MIPMAPCOUNT,
191 where dwMipMapCount = 0. This should fail. */
193 ddsd.dwSize = sizeof(ddsd);
194 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_MIPMAPCOUNT;
195 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
196 U2(ddsd).dwMipMapCount = 0;
197 ddsd.dwWidth = 128;
198 ddsd.dwHeight = 32;
199 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpDDSMipMapTest, NULL);
200 ok(rc==DDERR_INVALIDPARAMS,"CreateSurface returned: %x\n",rc);
202 /* Destroy the surface. */
203 if( rc == DD_OK )
204 IDirectDrawSurface_Release(lpDDSMipMapTest);
208 static void SrcColorKey32BlitTest(void)
210 LPDIRECTDRAWSURFACE lpSrc;
211 LPDIRECTDRAWSURFACE lpDst;
212 DDSURFACEDESC ddsd, ddsd2, ddsd3;
213 DDCOLORKEY DDColorKey;
214 LPDWORD lpData;
215 HRESULT rc;
216 DDBLTFX fx;
218 ddsd2.dwSize = sizeof(ddsd2);
219 ddsd2.ddpfPixelFormat.dwSize = sizeof(ddsd2.ddpfPixelFormat);
221 ddsd.dwSize = sizeof(ddsd);
222 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
223 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
224 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
225 ddsd.dwWidth = 800;
226 ddsd.dwHeight = 600;
227 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
228 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 32;
229 U2(ddsd.ddpfPixelFormat).dwRBitMask = 0xFF0000;
230 U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x00FF00;
231 U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x0000FF;
232 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpDst, NULL);
233 ok(rc==DD_OK,"CreateSurface returned: %x\n",rc);
234 if (FAILED(rc)) {
235 skip("failed to create surface\n");
236 return;
239 ddsd.dwFlags |= DDSD_CKSRCBLT;
240 ddsd.ddckCKSrcBlt.dwColorSpaceLowValue = 0xFF00FF;
241 ddsd.ddckCKSrcBlt.dwColorSpaceHighValue = 0xFF00FF;
242 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpSrc, NULL);
243 ok(rc==DD_OK,"CreateSurface returned: %x\n",rc);
244 if (FAILED(rc)) {
245 skip("failed to create surface\n");
246 return;
249 rc = IDirectDrawSurface_Lock(lpDst, NULL, &ddsd2, DDLOCK_WAIT, NULL);
250 ok(rc==DD_OK,"Lock returned: %x\n",rc);
251 lpData = (LPDWORD)ddsd2.lpSurface;
252 lpData[0] = 0xCCCCCCCC;
253 lpData[1] = 0xCCCCCCCC;
254 lpData[2] = 0xCCCCCCCC;
255 lpData[3] = 0xCCCCCCCC;
257 memset(&ddsd3, 0, sizeof(ddsd3));
258 ddsd3.dwSize = sizeof(ddsd3);
259 ddsd3.ddpfPixelFormat.dwSize = sizeof(ddsd3.ddpfPixelFormat);
260 rc = IDirectDrawSurface_GetSurfaceDesc(lpDst, &ddsd3);
261 ok(rc == DD_OK, "IDirectDrawSurface_GetSurfaceDesc between a lock/unlock pair returned %08x\n", rc);
262 ok(ddsd3.lpSurface == ddsd3.lpSurface, "lpSurface from GetSurfaceDesc(%p) differs from the one returned by Lock(%p)\n", ddsd3.lpSurface, ddsd2.lpSurface);
264 rc = IDirectDrawSurface_Unlock(lpDst, NULL);
265 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
267 memset(&ddsd3, 0, sizeof(ddsd3));
268 ddsd3.dwSize = sizeof(ddsd3);
269 ddsd3.ddpfPixelFormat.dwSize = sizeof(ddsd3.ddpfPixelFormat);
270 rc = IDirectDrawSurface_GetSurfaceDesc(lpDst, &ddsd3);
271 ok(rc == DD_OK, "IDirectDrawSurface_GetSurfaceDesc between a lock/unlock pair returned %08x\n", rc);
272 ok(ddsd3.lpSurface == NULL, "lpSurface from GetSurfaceDesc(%p) is not NULL after unlock\n", ddsd3.lpSurface);
274 rc = IDirectDrawSurface_Lock(lpSrc, NULL, &ddsd2, DDLOCK_WAIT, NULL);
275 ok(rc==DD_OK,"Lock returned: %x\n",rc);
276 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
277 lpData = (LPDWORD)ddsd2.lpSurface;
278 lpData[0] = 0x77010203;
279 lpData[1] = 0x00010203;
280 lpData[2] = 0x77FF00FF;
281 lpData[3] = 0x00FF00FF;
282 rc = IDirectDrawSurface_Unlock(lpSrc, NULL);
283 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
285 IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYSRC, NULL);
287 rc = IDirectDrawSurface_Lock(lpDst, NULL, &ddsd2, DDLOCK_WAIT, NULL);
288 ok(rc==DD_OK,"Lock returned: %x\n",rc);
289 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
290 lpData = (LPDWORD)ddsd2.lpSurface;
291 /* Different behavior on some drivers / windows versions. Some versions ignore the X channel when
292 * color keying, but copy it to the destination surface. Others apply it for color keying, but
293 * do not copy it into the destination surface.
295 if(lpData[0]==0x00010203) {
296 trace("X channel was not copied into the destination surface\n");
297 ok((lpData[0]==0x00010203)&&(lpData[1]==0x00010203)&&(lpData[2]==0x00FF00FF)&&(lpData[3]==0xCCCCCCCC),
298 "Destination data after blitting is not correct\n");
299 } else {
300 ok((lpData[0]==0x77010203)&&(lpData[1]==0x00010203)&&(lpData[2]==0xCCCCCCCC)&&(lpData[3]==0xCCCCCCCC),
301 "Destination data after blitting is not correct\n");
303 rc = IDirectDrawSurface_Unlock(lpDst, NULL);
304 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
306 /* Also test SetColorKey */
307 IDirectDrawSurface_GetColorKey(lpSrc, DDCKEY_SRCBLT, &DDColorKey);
308 ok(DDColorKey.dwColorSpaceLowValue == 0xFF00FF && DDColorKey.dwColorSpaceHighValue == 0xFF00FF,
309 "GetColorKey does not return the colorkey used at surface creation\n");
311 DDColorKey.dwColorSpaceLowValue = 0x00FF00;
312 DDColorKey.dwColorSpaceHighValue = 0x00FF00;
313 IDirectDrawSurface_SetColorKey(lpSrc, DDCKEY_SRCBLT, &DDColorKey);
315 DDColorKey.dwColorSpaceLowValue = 0;
316 DDColorKey.dwColorSpaceHighValue = 0;
317 IDirectDrawSurface_GetColorKey(lpSrc, DDCKEY_SRCBLT, &DDColorKey);
318 ok(DDColorKey.dwColorSpaceLowValue == 0x00FF00 && DDColorKey.dwColorSpaceHighValue == 0x00FF00,
319 "GetColorKey does not return the colorkey set with SetColorKey\n");
321 ddsd.ddckCKSrcBlt.dwColorSpaceLowValue = 0;
322 ddsd.ddckCKSrcBlt.dwColorSpaceHighValue = 0;
323 IDirectDrawSurface_GetSurfaceDesc(lpSrc, &ddsd);
324 ok(ddsd.ddckCKSrcBlt.dwColorSpaceLowValue == 0x00FF00 && ddsd.ddckCKSrcBlt.dwColorSpaceHighValue == 0x00FF00,
325 "GetSurfaceDesc does not return the colorkey set with SetColorKey\n");
327 IDirectDrawSurface_Release(lpSrc);
328 IDirectDrawSurface_Release(lpDst);
330 /* start with a new set of surfaces to test the color keying parameters to blit */
331 memset(&ddsd, 0, sizeof(ddsd));
332 ddsd.dwSize = sizeof(ddsd);
333 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
334 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CKSRCBLT | DDSD_CKDESTBLT;
335 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
336 ddsd.dwWidth = 800;
337 ddsd.dwHeight = 600;
338 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
339 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 32;
340 U2(ddsd.ddpfPixelFormat).dwRBitMask = 0xFF0000;
341 U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x00FF00;
342 U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x0000FF;
343 ddsd.ddckCKDestBlt.dwColorSpaceLowValue = 0xFF0000;
344 ddsd.ddckCKDestBlt.dwColorSpaceHighValue = 0xFF0000;
345 ddsd.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00FF00;
346 ddsd.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00FF00;
347 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpDst, NULL);
348 ok(rc==DD_OK || rc == DDERR_NOCOLORKEYHW,"CreateSurface returned: %x\n",rc);
349 if(FAILED(rc))
351 skip("Failed to create surface\n");
352 return;
355 /* start with a new set of surfaces to test the color keying parameters to blit */
356 memset(&ddsd, 0, sizeof(ddsd));
357 ddsd.dwSize = sizeof(ddsd);
358 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
359 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CKSRCBLT | DDSD_CKDESTBLT;
360 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
361 ddsd.dwWidth = 800;
362 ddsd.dwHeight = 600;
363 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
364 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 32;
365 U2(ddsd.ddpfPixelFormat).dwRBitMask = 0xFF0000;
366 U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x00FF00;
367 U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x0000FF;
368 ddsd.ddckCKSrcBlt.dwColorSpaceLowValue = 0x0000FF;
369 ddsd.ddckCKSrcBlt.dwColorSpaceHighValue = 0x0000FF;
370 ddsd.ddckCKDestBlt.dwColorSpaceLowValue = 0x000000;
371 ddsd.ddckCKDestBlt.dwColorSpaceHighValue = 0x000000;
372 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpSrc, NULL);
373 ok(rc==DD_OK || rc == DDERR_NOCOLORKEYHW,"CreateSurface returned: %x\n",rc);
374 if(FAILED(rc))
376 skip("Failed to create surface\n");
377 IDirectDrawSurface_Release(lpDst);
378 return;
381 memset(&fx, 0, sizeof(fx));
382 fx.dwSize = sizeof(fx);
383 fx.ddckSrcColorkey.dwColorSpaceHighValue = 0x110000;
384 fx.ddckSrcColorkey.dwColorSpaceLowValue = 0x110000;
385 fx.ddckDestColorkey.dwColorSpaceHighValue = 0x001100;
386 fx.ddckDestColorkey.dwColorSpaceLowValue = 0x001100;
388 rc = IDirectDrawSurface_Lock(lpSrc, NULL, &ddsd2, DDLOCK_WAIT, NULL);
389 ok(rc==DD_OK,"Lock returned: %x\n",rc);
390 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
391 lpData = (LPDWORD)ddsd2.lpSurface;
392 lpData[0] = 0x000000FF; /* Applies to src blt key in src surface */
393 lpData[1] = 0x00000000; /* Applies to dst blt key in src surface */
394 lpData[2] = 0x00FF0000; /* Dst color key in dst surface */
395 lpData[3] = 0x0000FF00; /* Src color key in dst surface */
396 lpData[4] = 0x00001100; /* Src color key in ddbltfx */
397 lpData[5] = 0x00110000; /* Dst color key in ddbltfx */
398 rc = IDirectDrawSurface_Unlock(lpSrc, NULL);
399 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
401 rc = IDirectDrawSurface_Lock(lpDst, NULL, &ddsd2, DDLOCK_WAIT, NULL);
402 ok(rc==DD_OK,"Lock returned: %x\n",rc);
403 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
404 lpData = (LPDWORD)ddsd2.lpSurface;
405 lpData[0] = 0x55555555;
406 lpData[1] = 0x55555555;
407 lpData[2] = 0x55555555;
408 lpData[3] = 0x55555555;
409 lpData[4] = 0x55555555;
410 lpData[5] = 0x55555555;
411 rc = IDirectDrawSurface_Unlock(lpDst, NULL);
412 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
414 /* Test a blit without keying */
415 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, 0, &fx);
416 ok(rc == DD_OK, "IDirectDrawSurface_Blt returned %08x\n", rc);
418 rc = IDirectDrawSurface_Lock(lpDst, NULL, &ddsd2, DDLOCK_WAIT, NULL);
419 ok(rc==DD_OK,"Lock returned: %x\n",rc);
420 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
421 lpData = (LPDWORD)ddsd2.lpSurface;
422 /* Should have copied src data unmodified to dst */
423 ok(lpData[0] == 0x000000FF &&
424 lpData[1] == 0x00000000 &&
425 lpData[2] == 0x00FF0000 &&
426 lpData[3] == 0x0000FF00 &&
427 lpData[4] == 0x00001100 &&
428 lpData[5] == 0x00110000, "Surface data after unkeyed blit does not match\n");
430 lpData[0] = 0x55555555;
431 lpData[1] = 0x55555555;
432 lpData[2] = 0x55555555;
433 lpData[3] = 0x55555555;
434 lpData[4] = 0x55555555;
435 lpData[5] = 0x55555555;
436 rc = IDirectDrawSurface_Unlock(lpDst, NULL);
437 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
439 /* Src key */
440 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYSRC, &fx);
441 ok(rc == DD_OK, "IDirectDrawSurface_Blt returned %08x\n", rc);
443 rc = IDirectDrawSurface_Lock(lpDst, NULL, &ddsd2, DDLOCK_WAIT, NULL);
444 ok(rc==DD_OK,"Lock returned: %x\n",rc);
445 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
446 lpData = (LPDWORD)ddsd2.lpSurface;
448 ok(lpData[0] == 0x55555555 && /* Here the src key applied */
449 lpData[1] == 0x00000000 &&
450 lpData[2] == 0x00FF0000 &&
451 lpData[3] == 0x0000FF00 &&
452 lpData[4] == 0x00001100 &&
453 lpData[5] == 0x00110000, "Surface data after srckey blit does not match\n");
455 lpData[0] = 0x55555555;
456 lpData[1] = 0x55555555;
457 lpData[2] = 0x55555555;
458 lpData[3] = 0x55555555;
459 lpData[4] = 0x55555555;
460 lpData[5] = 0x55555555;
461 rc = IDirectDrawSurface_Unlock(lpDst, NULL);
462 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
464 /* Src override */
465 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYSRCOVERRIDE, &fx);
466 ok(rc == DD_OK, "IDirectDrawSurface_Blt returned %08x\n", rc);
468 rc = IDirectDrawSurface_Lock(lpDst, NULL, &ddsd2, DDLOCK_WAIT, NULL);
469 ok(rc==DD_OK,"Lock returned: %x\n",rc);
470 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
471 lpData = (LPDWORD)ddsd2.lpSurface;
473 ok(lpData[0] == 0x000000FF &&
474 lpData[1] == 0x00000000 &&
475 lpData[2] == 0x00FF0000 &&
476 lpData[3] == 0x0000FF00 &&
477 lpData[4] == 0x00001100 &&
478 lpData[5] == 0x55555555, /* Override key applies here */
479 "Surface data after src override key blit does not match\n");
481 lpData[0] = 0x55555555;
482 lpData[1] = 0x55555555;
483 lpData[2] = 0x55555555;
484 lpData[3] = 0x55555555;
485 lpData[4] = 0x55555555;
486 lpData[5] = 0x55555555;
487 rc = IDirectDrawSurface_Unlock(lpDst, NULL);
488 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
490 /* Src override AND src key. That is not supposed to work */
491 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYSRC | DDBLT_KEYSRCOVERRIDE, &fx);
492 ok(rc == DDERR_INVALIDPARAMS, "IDirectDrawSurface_Blt returned %08x\n", rc);
494 /* Verify that the destination is unchanged */
495 rc = IDirectDrawSurface_Lock(lpDst, NULL, &ddsd2, DDLOCK_WAIT, NULL);
496 ok(rc==DD_OK,"Lock returned: %x\n",rc);
497 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
498 lpData = (LPDWORD)ddsd2.lpSurface;
500 ok(lpData[0] == 0x55555555 &&
501 lpData[1] == 0x55555555 &&
502 lpData[2] == 0x55555555 &&
503 lpData[3] == 0x55555555 &&
504 lpData[4] == 0x55555555 &&
505 lpData[5] == 0x55555555, /* Override key applies here */
506 "Surface data after src key blit with override does not match\n");
508 lpData[0] = 0x00FF0000; /* Dest key in dst surface */
509 lpData[1] = 0x00FF0000; /* Dest key in dst surface */
510 lpData[2] = 0x00001100; /* Dest key in override */
511 lpData[3] = 0x00001100; /* Dest key in override */
512 lpData[4] = 0x00000000; /* Dest key in src surface */
513 lpData[5] = 0x00000000; /* Dest key in src surface */
514 rc = IDirectDrawSurface_Unlock(lpDst, NULL);
515 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
517 /* Dest key blit */
518 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYDEST, &fx);
519 ok(rc == DD_OK, "IDirectDrawSurface_Blt returned %08x\n", rc);
521 rc = IDirectDrawSurface_Lock(lpDst, NULL, &ddsd2, DDLOCK_WAIT, NULL);
522 ok(rc==DD_OK,"Lock returned: %x\n",rc);
523 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
524 lpData = (LPDWORD)ddsd2.lpSurface;
526 /* DirectDraw uses the dest blit key from the SOURCE surface ! */
527 ok(lpData[0] == 0x00ff0000 &&
528 lpData[1] == 0x00ff0000 &&
529 lpData[2] == 0x00001100 &&
530 lpData[3] == 0x00001100 &&
531 lpData[4] == 0x00001100 && /* Key applies here */
532 lpData[5] == 0x00110000, /* Key applies here */
533 "Surface data after dest key blit does not match\n");
535 lpData[0] = 0x00FF0000; /* Dest key in dst surface */
536 lpData[1] = 0x00FF0000; /* Dest key in dst surface */
537 lpData[2] = 0x00001100; /* Dest key in override */
538 lpData[3] = 0x00001100; /* Dest key in override */
539 lpData[4] = 0x00000000; /* Dest key in src surface */
540 lpData[5] = 0x00000000; /* Dest key in src surface */
541 rc = IDirectDrawSurface_Unlock(lpDst, NULL);
542 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
544 /* Dest override key blit */
545 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYDESTOVERRIDE, &fx);
546 ok(rc == DD_OK, "IDirectDrawSurface_Blt returned %08x\n", rc);
548 rc = IDirectDrawSurface_Lock(lpDst, NULL, &ddsd2, DDLOCK_WAIT, NULL);
549 ok(rc==DD_OK,"Lock returned: %x\n",rc);
550 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
551 lpData = (LPDWORD)ddsd2.lpSurface;
553 ok(lpData[0] == 0x00FF0000 &&
554 lpData[1] == 0x00FF0000 &&
555 lpData[2] == 0x00FF0000 && /* Key applies here */
556 lpData[3] == 0x0000FF00 && /* Key applies here */
557 lpData[4] == 0x00000000 &&
558 lpData[5] == 0x00000000,
559 "Surface data after dest key override blit does not match\n");
561 lpData[0] = 0x00FF0000; /* Dest key in dst surface */
562 lpData[1] = 0x00FF0000; /* Dest key in dst surface */
563 lpData[2] = 0x00001100; /* Dest key in override */
564 lpData[3] = 0x00001100; /* Dest key in override */
565 lpData[4] = 0x00000000; /* Dest key in src surface */
566 lpData[5] = 0x00000000; /* Dest key in src surface */
567 rc = IDirectDrawSurface_Unlock(lpDst, NULL);
568 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
570 /* Dest override key blit. Supposed to fail too */
571 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYDEST | DDBLT_KEYDESTOVERRIDE, &fx);
572 ok(rc == DDERR_INVALIDPARAMS, "IDirectDrawSurface_Blt returned %08x\n", rc);
574 /* Check for unchanged data */
575 rc = IDirectDrawSurface_Lock(lpDst, NULL, &ddsd2, DDLOCK_WAIT, NULL);
576 ok(rc==DD_OK,"Lock returned: %x\n",rc);
577 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
578 lpData = (LPDWORD)ddsd2.lpSurface;
580 ok(lpData[0] == 0x00FF0000 &&
581 lpData[1] == 0x00FF0000 &&
582 lpData[2] == 0x00001100 && /* Key applies here */
583 lpData[3] == 0x00001100 && /* Key applies here */
584 lpData[4] == 0x00000000 &&
585 lpData[5] == 0x00000000,
586 "Surface data with dest key and dest override does not match\n");
588 lpData[0] = 0x00FF0000; /* Dest key in dst surface */
589 lpData[1] = 0x00FF0000; /* Dest key in dst surface */
590 lpData[2] = 0x00001100; /* Dest key in override */
591 lpData[3] = 0x00001100; /* Dest key in override */
592 lpData[4] = 0x00000000; /* Dest key in src surface */
593 lpData[5] = 0x00000000; /* Dest key in src surface */
594 rc = IDirectDrawSurface_Unlock(lpDst, NULL);
595 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
597 /* Modify the source data a bit to give some more conclusive results */
598 rc = IDirectDrawSurface_Lock(lpSrc, NULL, &ddsd2, DDLOCK_WAIT, NULL);
599 ok(rc==DD_OK,"Lock returned: %x\n",rc);
600 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
601 lpData = (LPDWORD)ddsd2.lpSurface;
602 lpData[5] = 0x000000FF; /* Applies to src blt key in src surface */
603 rc = IDirectDrawSurface_Unlock(lpSrc, NULL);
604 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
606 /* Source and destination key */
607 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYDEST | DDBLT_KEYSRC, &fx);
608 ok(rc == DD_OK, "IDirectDrawSurface_Blt returned %08x\n", rc);
610 rc = IDirectDrawSurface_Lock(lpDst, NULL, &ddsd2, DDLOCK_WAIT, NULL);
611 ok(rc==DD_OK,"Lock returned: %x\n",rc);
612 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
613 lpData = (LPDWORD)ddsd2.lpSurface;
615 ok(lpData[0] == 0x00FF0000 && /* Masked by Destination key */
616 lpData[1] == 0x00FF0000 && /* Masked by Destination key */
617 lpData[2] == 0x00001100 && /* Masked by Destination key */
618 lpData[3] == 0x00001100 && /* Masked by Destination key */
619 lpData[4] == 0x00001100 && /* Allowed by destination key, not masked by source key */
620 lpData[5] == 0x00000000, /* Allowed by dst key, but masked by source key */
621 "Surface data with src key and dest key blit does not match\n");
623 lpData[0] = 0x00FF0000; /* Dest key in dst surface */
624 lpData[1] = 0x00FF0000; /* Dest key in dst surface */
625 lpData[2] = 0x00001100; /* Dest key in override */
626 lpData[3] = 0x00001100; /* Dest key in override */
627 lpData[4] = 0x00000000; /* Dest key in src surface */
628 lpData[5] = 0x00000000; /* Dest key in src surface */
629 rc = IDirectDrawSurface_Unlock(lpDst, NULL);
630 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
632 /* Override keys without ddbltfx parameter fail */
633 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYDESTOVERRIDE, NULL);
634 ok(rc == DDERR_INVALIDPARAMS, "IDirectDrawSurface_Blt returned %08x\n", rc);
635 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYSRCOVERRIDE, NULL);
636 ok(rc == DDERR_INVALIDPARAMS, "IDirectDrawSurface_Blt returned %08x\n", rc);
638 /* Try blitting without keys in the source surface*/
639 rc = IDirectDrawSurface_SetColorKey(lpSrc, DDCKEY_SRCBLT, NULL);
640 ok(rc == DD_OK, "SetColorKey returned %x\n", rc);
641 rc = IDirectDrawSurface_SetColorKey(lpSrc, DDCKEY_DESTBLT, NULL);
642 ok(rc == DD_OK, "SetColorKey returned %x\n", rc);
644 /* That fails now. Do not bother to check that the data is unmodified */
645 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYSRC, &fx);
646 ok(rc == DDERR_INVALIDPARAMS, "IDirectDrawSurface_Blt returned %08x\n", rc);
648 /* Dest key blit still works. Which key is used this time??? */
649 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYDEST, &fx);
650 ok(rc == DD_OK, "IDirectDrawSurface_Blt returned %08x\n", rc);
652 /* With correctly passed override keys no key in the surface is needed.
653 * Again, the result was checked before, no need to do that again
655 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYDESTOVERRIDE, &fx);
656 ok(rc == DD_OK, "IDirectDrawSurface_Blt returned %08x\n", rc);
657 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYSRCOVERRIDE, &fx);
658 ok(rc == DD_OK, "IDirectDrawSurface_Blt returned %08x\n", rc);
660 IDirectDrawSurface_Release(lpSrc);
661 IDirectDrawSurface_Release(lpDst);
664 static void QueryInterface(void)
666 LPDIRECTDRAWSURFACE dsurface;
667 DDSURFACEDESC surface;
668 LPVOID object;
669 HRESULT ret;
671 /* Create a surface */
672 ZeroMemory(&surface, sizeof(surface));
673 surface.dwSize = sizeof(surface);
674 surface.dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
675 surface.dwHeight = 10;
676 surface.dwWidth = 10;
677 ret = IDirectDraw_CreateSurface(lpDD, &surface, &dsurface, NULL);
678 if(ret != DD_OK)
680 ok(FALSE, "IDirectDraw::CreateSurface failed with error %x\n", ret);
681 return;
684 /* Call IUnknown::QueryInterface */
685 ret = IDirectDrawSurface_QueryInterface(dsurface, 0, &object);
686 ok(ret == DDERR_INVALIDPARAMS, "IDirectDrawSurface::QueryInterface returned %x\n", ret);
688 IDirectDrawSurface_Release(dsurface);
691 /* The following tests test which interface is returned by IDirectDrawSurfaceX::GetDDInterface.
692 * It uses refcounts to test that and compares the interface addresses. Partially fits here, and
693 * partially in the refcount test
696 static unsigned long getref(IUnknown *iface)
698 IUnknown_AddRef(iface);
699 return IUnknown_Release(iface);
702 static void GetDDInterface_1(void)
704 LPDIRECTDRAWSURFACE dsurface;
705 LPDIRECTDRAWSURFACE2 dsurface2;
706 DDSURFACEDESC surface;
707 HRESULT ret;
708 IDirectDraw2 *dd2;
709 IDirectDraw4 *dd4;
710 IDirectDraw7 *dd7;
711 unsigned long ref1, ref2, ref4, ref7;
712 void *dd;
714 /* Create a surface */
715 ZeroMemory(&surface, sizeof(surface));
716 surface.dwSize = sizeof(surface);
717 surface.dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
718 surface.dwHeight = 10;
719 surface.dwWidth = 10;
720 ret = IDirectDraw_CreateSurface(lpDD, &surface, &dsurface, NULL);
721 if(ret != DD_OK)
723 ok(FALSE, "IDirectDraw::CreateSurface failed with error %x\n", ret);
724 return;
726 ret = IDirectDrawSurface_QueryInterface(dsurface, &IID_IDirectDrawSurface2, (void **) &dsurface2);
727 ok(ret == DD_OK, "IDirectDrawSurface_QueryInterface returned %08x\n", ret);
728 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw2, (void **) &dd2);
729 ok(ret == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", ret);
730 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw4, (void **) &dd4);
731 ok(ret == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", ret);
732 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
733 ok(ret == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", ret);
735 ref1 = getref((IUnknown *) lpDD);
736 ok(ref1 == 1, "IDirectDraw refcount is %ld\n", ref1);
737 ref2 = getref((IUnknown *) dd2);
738 ok(ref2 == 1, "IDirectDraw2 refcount is %ld\n", ref2);
739 ref4 = getref((IUnknown *) dd4);
740 ok(ref4 == 1, "IDirectDraw4 refcount is %ld\n", ref4);
741 ref7 = getref((IUnknown *) dd7);
742 ok(ref7 == 1, "IDirectDraw7 refcount is %ld\n", ref7);
745 ret = IDirectDrawSurface2_GetDDInterface(dsurface2, &dd);
746 ok(ret == DD_OK, "IDirectDrawSurface7_GetDDInterface returned %08x\n", ret);
747 ok(getref((IUnknown *) lpDD) == ref1 + 1, "IDirectDraw refcount was increased by %ld\n", getref((IUnknown *) lpDD) - ref1);
748 ok(getref((IUnknown *) dd2) == ref2 + 0, "IDirectDraw2 refcount was increased by %ld\n", getref((IUnknown *) dd2) - ref2);
749 ok(getref((IUnknown *) dd4) == ref4 + 0, "IDirectDraw4 refcount was increased by %ld\n", getref((IUnknown *) dd4) - ref4);
750 ok(getref((IUnknown *) dd7) == ref7 + 0, "IDirectDraw7 refcount was increased by %ld\n", getref((IUnknown *) dd7) - ref7);
752 ok(dd == lpDD, "Returned interface pointer is not equal to the creation interface\n");
753 IUnknown_Release((IUnknown *) dd);
755 /* try a NULL pointer */
756 ret = IDirectDrawSurface2_GetDDInterface(dsurface2, NULL);
757 ok(ret == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_GetDDInterface returned %08x\n", ret);
759 IDirectDraw_Release(dd2);
760 IDirectDraw_Release(dd4);
761 IDirectDraw_Release(dd7);
762 IDirectDrawSurface2_Release(dsurface2);
763 IDirectDrawSurface_Release(dsurface);
766 static void GetDDInterface_2(void)
768 LPDIRECTDRAWSURFACE dsurface;
769 LPDIRECTDRAWSURFACE2 dsurface2;
770 DDSURFACEDESC surface;
771 HRESULT ret;
772 IDirectDraw2 *dd2;
773 IDirectDraw4 *dd4;
774 IDirectDraw7 *dd7;
775 unsigned long ref1, ref2, ref4, ref7;
776 void *dd;
778 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw2, (void **) &dd2);
779 ok(ret == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", ret);
780 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw4, (void **) &dd4);
781 ok(ret == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", ret);
782 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
783 ok(ret == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", ret);
785 /* Create a surface */
786 ZeroMemory(&surface, sizeof(surface));
787 surface.dwSize = sizeof(surface);
788 surface.dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
789 surface.dwHeight = 10;
790 surface.dwWidth = 10;
791 ret = IDirectDraw2_CreateSurface(dd2, &surface, &dsurface, NULL);
792 if(ret != DD_OK)
794 ok(FALSE, "IDirectDraw::CreateSurface failed with error %x\n", ret);
795 return;
797 ret = IDirectDrawSurface_QueryInterface(dsurface, &IID_IDirectDrawSurface2, (void **) &dsurface2);
798 ok(ret == DD_OK, "IDirectDrawSurface_QueryInterface returned %08x\n", ret);
800 ref1 = getref((IUnknown *) lpDD);
801 ok(ref1 == 1, "IDirectDraw refcount is %ld\n", ref1);
802 ref2 = getref((IUnknown *) dd2);
803 ok(ref2 == 1, "IDirectDraw2 refcount is %ld\n", ref2);
804 ref4 = getref((IUnknown *) dd4);
805 ok(ref4 == 1, "IDirectDraw4 refcount is %ld\n", ref4);
806 ref7 = getref((IUnknown *) dd7);
807 ok(ref7 == 1, "IDirectDraw7 refcount is %ld\n", ref7);
810 ret = IDirectDrawSurface2_GetDDInterface(dsurface2, &dd);
811 ok(ret == DD_OK, "IDirectDrawSurface7_GetDDInterface returned %08x\n", ret);
812 ok(getref((IUnknown *) lpDD) == ref1 + 0, "IDirectDraw refcount was increased by %ld\n", getref((IUnknown *) lpDD) - ref1);
813 ok(getref((IUnknown *) dd2) == ref2 + 1, "IDirectDraw2 refcount was increased by %ld\n", getref((IUnknown *) dd2) - ref2);
814 ok(getref((IUnknown *) dd4) == ref4 + 0, "IDirectDraw4 refcount was increased by %ld\n", getref((IUnknown *) dd4) - ref4);
815 ok(getref((IUnknown *) dd7) == ref7 + 0, "IDirectDraw7 refcount was increased by %ld\n", getref((IUnknown *) dd7) - ref7);
817 ok(dd == dd2, "Returned interface pointer is not equal to the creation interface\n");
818 IUnknown_Release((IUnknown *) dd);
820 IDirectDraw_Release(dd2);
821 IDirectDraw_Release(dd4);
822 IDirectDraw_Release(dd7);
823 IDirectDrawSurface2_Release(dsurface2);
824 IDirectDrawSurface_Release(dsurface);
827 static void GetDDInterface_4(void)
829 LPDIRECTDRAWSURFACE2 dsurface2;
830 LPDIRECTDRAWSURFACE4 dsurface4;
831 DDSURFACEDESC2 surface;
832 HRESULT ret;
833 IDirectDraw2 *dd2;
834 IDirectDraw4 *dd4;
835 IDirectDraw7 *dd7;
836 unsigned long ref1, ref2, ref4, ref7;
837 void *dd;
839 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw2, (void **) &dd2);
840 ok(ret == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", ret);
841 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw4, (void **) &dd4);
842 ok(ret == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", ret);
843 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
844 ok(ret == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", ret);
846 /* Create a surface */
847 ZeroMemory(&surface, sizeof(surface));
848 surface.dwSize = sizeof(surface);
849 surface.dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
850 surface.dwHeight = 10;
851 surface.dwWidth = 10;
852 ret = IDirectDraw4_CreateSurface(dd4, &surface, &dsurface4, NULL);
853 if(ret != DD_OK)
855 ok(FALSE, "IDirectDraw::CreateSurface failed with error %x\n", ret);
856 return;
858 ret = IDirectDrawSurface4_QueryInterface(dsurface4, &IID_IDirectDrawSurface2, (void **) &dsurface2);
859 ok(ret == DD_OK, "IDirectDrawSurface_QueryInterface returned %08x\n", ret);
861 ref1 = getref((IUnknown *) lpDD);
862 ok(ref1 == 1, "IDirectDraw refcount is %ld\n", ref1);
863 ref2 = getref((IUnknown *) dd2);
864 ok(ref2 == 1, "IDirectDraw2 refcount is %ld\n", ref2);
865 ref4 = getref((IUnknown *) dd4);
866 ok(ref4 == 2, "IDirectDraw4 refcount is %ld\n", ref4);
867 ref7 = getref((IUnknown *) dd7);
868 ok(ref7 == 1, "IDirectDraw7 refcount is %ld\n", ref7);
870 ret = IDirectDrawSurface4_GetDDInterface(dsurface4, &dd);
871 ok(ret == DD_OK, "IDirectDrawSurface7_GetDDInterface returned %08x\n", ret);
872 ok(getref((IUnknown *) lpDD) == ref1 + 0, "IDirectDraw refcount was increased by %ld\n", getref((IUnknown *) lpDD) - ref1);
873 ok(getref((IUnknown *) dd2) == ref2 + 0, "IDirectDraw2 refcount was increased by %ld\n", getref((IUnknown *) dd2) - ref2);
874 ok(getref((IUnknown *) dd4) == ref4 + 1, "IDirectDraw4 refcount was increased by %ld\n", getref((IUnknown *) dd4) - ref4);
875 ok(getref((IUnknown *) dd7) == ref7 + 0, "IDirectDraw7 refcount was increased by %ld\n", getref((IUnknown *) dd7) - ref7);
877 ok(dd == dd4, "Returned interface pointer is not equal to the creation interface\n");
878 IUnknown_Release((IUnknown *) dd);
880 /* Now test what happens if we QI the surface for some other version - It should still return the creation interface */
881 ret = IDirectDrawSurface2_GetDDInterface(dsurface2, &dd);
882 ok(ret == DD_OK, "IDirectDrawSurface7_GetDDInterface returned %08x\n", ret);
883 ok(getref((IUnknown *) lpDD) == ref1 + 0, "IDirectDraw refcount was increased by %ld\n", getref((IUnknown *) lpDD) - ref1);
884 ok(getref((IUnknown *) dd2) == ref2 + 0, "IDirectDraw2 refcount was increased by %ld\n", getref((IUnknown *) dd2) - ref2);
885 ok(getref((IUnknown *) dd4) == ref4 + 1, "IDirectDraw4 refcount was increased by %ld\n", getref((IUnknown *) dd4) - ref4);
886 ok(getref((IUnknown *) dd7) == ref7 + 0, "IDirectDraw7 refcount was increased by %ld\n", getref((IUnknown *) dd7) - ref7);
888 ok(dd == dd4, "Returned interface pointer is not equal to the creation interface\n");
889 IUnknown_Release((IUnknown *) dd);
891 IDirectDraw_Release(dd2);
892 IDirectDraw_Release(dd4);
893 IDirectDraw_Release(dd7);
894 IDirectDrawSurface4_Release(dsurface4);
895 IDirectDrawSurface2_Release(dsurface2);
898 static void GetDDInterface_7(void)
900 LPDIRECTDRAWSURFACE4 dsurface4;
901 LPDIRECTDRAWSURFACE7 dsurface7;
902 DDSURFACEDESC2 surface;
903 HRESULT ret;
904 IDirectDraw2 *dd2;
905 IDirectDraw4 *dd4;
906 IDirectDraw7 *dd7;
907 unsigned long ref1, ref2, ref4, ref7;
908 void *dd;
910 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw2, (void **) &dd2);
911 ok(ret == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", ret);
912 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw4, (void **) &dd4);
913 ok(ret == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", ret);
914 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
915 ok(ret == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", ret);
917 /* Create a surface */
918 ZeroMemory(&surface, sizeof(surface));
919 surface.dwSize = sizeof(surface);
920 surface.dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
921 surface.dwHeight = 10;
922 surface.dwWidth = 10;
923 ret = IDirectDraw7_CreateSurface(dd7, &surface, &dsurface7, NULL);
924 if(ret != DD_OK)
926 ok(FALSE, "IDirectDraw::CreateSurface failed with error %x\n", ret);
927 return;
929 ret = IDirectDrawSurface7_QueryInterface(dsurface7, &IID_IDirectDrawSurface4, (void **) &dsurface4);
930 ok(ret == DD_OK, "IDirectDrawSurface_QueryInterface returned %08x\n", ret);
932 ref1 = getref((IUnknown *) lpDD);
933 ok(ref1 == 1, "IDirectDraw refcount is %ld\n", ref1);
934 ref2 = getref((IUnknown *) dd2);
935 ok(ref2 == 1, "IDirectDraw2 refcount is %ld\n", ref2);
936 ref4 = getref((IUnknown *) dd4);
937 ok(ref4 == 1, "IDirectDraw4 refcount is %ld\n", ref4);
938 ref7 = getref((IUnknown *) dd7);
939 ok(ref7 == 2, "IDirectDraw7 refcount is %ld\n", ref7);
941 ret = IDirectDrawSurface7_GetDDInterface(dsurface7, &dd);
942 ok(ret == DD_OK, "IDirectDrawSurface7_GetDDInterface returned %08x\n", ret);
943 ok(getref((IUnknown *) lpDD) == ref1 + 0, "IDirectDraw refcount was increased by %ld\n", getref((IUnknown *) lpDD) - ref1);
944 ok(getref((IUnknown *) dd2) == ref2 + 0, "IDirectDraw2 refcount was increased by %ld\n", getref((IUnknown *) dd2) - ref2);
945 ok(getref((IUnknown *) dd4) == ref4 + 0, "IDirectDraw4 refcount was increased by %ld\n", getref((IUnknown *) dd4) - ref4);
946 ok(getref((IUnknown *) dd7) == ref7 + 1, "IDirectDraw7 refcount was increased by %ld\n", getref((IUnknown *) dd7) - ref7);
948 ok(dd == dd7, "Returned interface pointer is not equal to the creation interface\n");
949 IUnknown_Release((IUnknown *) dd);
951 /* Now test what happens if we QI the surface for some other version - It should still return the creation interface */
952 ret = IDirectDrawSurface4_GetDDInterface(dsurface4, &dd);
953 ok(ret == DD_OK, "IDirectDrawSurface7_GetDDInterface returned %08x\n", ret);
954 ok(getref((IUnknown *) lpDD) == ref1 + 0, "IDirectDraw refcount was increased by %ld\n", getref((IUnknown *) lpDD) - ref1);
955 ok(getref((IUnknown *) dd2) == ref2 + 0, "IDirectDraw2 refcount was increased by %ld\n", getref((IUnknown *) dd2) - ref2);
956 ok(getref((IUnknown *) dd4) == ref4 + 0, "IDirectDraw4 refcount was increased by %ld\n", getref((IUnknown *) dd4) - ref4);
957 ok(getref((IUnknown *) dd7) == ref7 + 1, "IDirectDraw7 refcount was increased by %ld\n", getref((IUnknown *) dd7) - ref7);
959 ok(dd == dd7, "Returned interface pointer is not equal to the creation interface\n");
960 IUnknown_Release((IUnknown *) dd);
962 IDirectDraw_Release(dd2);
963 IDirectDraw_Release(dd4);
964 IDirectDraw_Release(dd7);
965 IDirectDrawSurface4_Release(dsurface4);
966 IDirectDrawSurface7_Release(dsurface7);
969 #define MAXEXPECTED 8 /* Can match up to 8 expected surfaces */
970 struct enumstruct
972 IDirectDrawSurface *expected[MAXEXPECTED];
973 UINT count;
976 static HRESULT WINAPI enumCB(IDirectDrawSurface *surf, DDSURFACEDESC *desc, void *ctx)
978 int i;
979 BOOL found = FALSE;
981 for(i = 0; i < MAXEXPECTED; i++)
983 if(((struct enumstruct *)ctx)->expected[i] == surf) found = TRUE;
986 ok(found, "Unexpected surface %p enumerated\n", surf);
987 ((struct enumstruct *)ctx)->count++;
988 IDirectDrawSurface_Release(surf);
989 return DDENUMRET_OK;
992 static void EnumTest(void)
994 HRESULT rc;
995 DDSURFACEDESC ddsd;
996 IDirectDrawSurface *surface;
997 struct enumstruct ctx;
999 ddsd.dwSize = sizeof(ddsd);
1000 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_MIPMAPCOUNT;
1001 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
1002 U2(ddsd).dwMipMapCount = 3;
1003 ddsd.dwWidth = 32;
1004 ddsd.dwHeight = 32;
1005 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface, NULL);
1006 ok(rc==DD_OK,"CreateSurface returned: %x\n",rc);
1008 memset(&ctx, 0, sizeof(ctx));
1009 ctx.expected[0] = surface;
1010 rc = IDirectDrawSurface_GetAttachedSurface(ctx.expected[0], &ddsd.ddsCaps, &ctx.expected[1]);
1011 ok(rc == DD_OK, "GetAttachedSurface returned %08x\n", rc);
1012 rc = IDirectDrawSurface_GetAttachedSurface(ctx.expected[1], &ddsd.ddsCaps, &ctx.expected[2]);
1013 ok(rc == DD_OK, "GetAttachedSurface returned %08x\n", rc);
1014 rc = IDirectDrawSurface_GetAttachedSurface(ctx.expected[2], &ddsd.ddsCaps, &ctx.expected[3]);
1015 ok(rc == DDERR_NOTFOUND, "GetAttachedSurface returned %08x\n", rc);
1016 ok(!ctx.expected[3], "expected NULL pointer\n");
1017 ctx.count = 0;
1019 rc = IDirectDraw_EnumSurfaces(lpDD, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_ALL, &ddsd, (void *) &ctx, enumCB);
1020 ok(rc == DD_OK, "IDirectDraw_EnumSurfaces returned %08x\n", rc);
1021 ok(ctx.count == 3, "%d surfaces enumerated, expected 3\n", ctx.count);
1023 IDirectDrawSurface_Release(ctx.expected[2]);
1024 IDirectDrawSurface_Release(ctx.expected[1]);
1025 IDirectDrawSurface_Release(surface);
1028 HRESULT WINAPI SurfaceCounter(IDirectDrawSurface7 *surface, DDSURFACEDESC2 *desc, void *context)
1030 UINT *num = context;
1031 (*num)++;
1032 IDirectDrawSurface_Release(surface);
1033 return DDENUMRET_OK;
1036 static void AttachmentTest7(void)
1038 HRESULT hr;
1039 IDirectDraw7 *dd7;
1040 IDirectDrawSurface7 *surface1, *surface2, *surface3, *surface4;
1041 DDSURFACEDESC2 ddsd;
1042 UINT num;
1043 DDSCAPS2 caps = {DDSCAPS_TEXTURE, 0, 0, 0};
1044 HWND window = CreateWindow( "static", "ddraw_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
1046 hr = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
1047 ok(hr == DD_OK, "IDirectDraw_QueryInterface returned %08x\n", hr);
1049 memset(&ddsd, 0, sizeof(ddsd));
1050 ddsd.dwSize = sizeof(ddsd);
1051 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_MIPMAPCOUNT;
1052 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
1053 U2(ddsd).dwMipMapCount = 3; /* Will create 128x128, 64x64, 32x32 */
1054 ddsd.dwWidth = 128;
1055 ddsd.dwHeight = 128;
1056 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface1, NULL);
1057 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1059 /* ROOT */
1060 num = 0;
1061 IDirectDrawSurface7_EnumAttachedSurfaces(surface1, &num, SurfaceCounter);
1062 ok(num == 1, "Mipmap root has %d surfaces attached, expected 1\n", num);
1063 /* DONE ROOT */
1065 /* LEVEL 1 */
1066 hr = IDirectDrawSurface7_GetAttachedSurface(surface1, &caps, &surface2);
1067 ok(hr == DD_OK, "GetAttachedSurface returned %08x\n", hr);
1068 num = 0;
1069 IDirectDrawSurface7_EnumAttachedSurfaces(surface2, &num, SurfaceCounter);
1070 ok(num == 1, "First mip level has %d surfaces attached, expected 1\n", num);
1071 /* DONE LEVEL 1 */
1073 /* LEVEL 2 */
1074 hr = IDirectDrawSurface7_GetAttachedSurface(surface2, &caps, &surface3);
1075 ok(hr == DD_OK, "GetAttachedSurface returned %08x\n", hr);
1076 IDirectDrawSurface7_Release(surface2);
1077 num = 0;
1078 IDirectDrawSurface7_EnumAttachedSurfaces(surface3, &num, SurfaceCounter);
1079 ok(num == 0, "Second mip level has %d surfaces attached, expected 1\n", num);
1080 /* Done level 2 */
1081 /* Mip level 3 is still needed */
1082 hr = IDirectDrawSurface7_GetAttachedSurface(surface3, &caps, &surface4);
1083 ok(hr == DDERR_NOTFOUND, "GetAttachedSurface returned %08x\n", hr);
1084 ok(!surface4, "expected NULL pointer\n");
1086 /* Try to attach a 16x16 miplevel - Should not work as far I can see */
1087 memset(&ddsd, 0, sizeof(ddsd));
1088 ddsd.dwSize = sizeof(ddsd);
1089 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1090 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1091 ddsd.dwWidth = 16;
1092 ddsd.dwHeight = 16;
1093 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface2, NULL);
1094 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1096 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface2);
1097 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 16x16 surface to a 128x128 texture root returned %08x\n", hr);
1098 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface1);
1099 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 128x128 texture root to a 16x16 texture returned %08x\n", hr);
1100 hr = IDirectDrawSurface7_AddAttachedSurface(surface3, surface2);
1101 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 16x16 surface to a 32x32 texture mip level returned %08x\n", hr);
1102 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface3);
1103 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 32x32 texture mip level to a 16x16 surface returned %08x\n", hr);
1105 IDirectDrawSurface7_Release(surface2);
1107 memset(&ddsd, 0, sizeof(ddsd));
1108 ddsd.dwSize = sizeof(ddsd);
1109 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1110 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
1111 ddsd.dwWidth = 16;
1112 ddsd.dwHeight = 16;
1113 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface2, NULL);
1114 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1116 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface2);
1117 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 16x16 offscreen plain surface to a 128x128 texture root returned %08x\n", hr);
1118 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface1);
1119 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 128x128 texture root to a 16x16 offscreen plain surface returned %08x\n", hr);
1120 hr = IDirectDrawSurface7_AddAttachedSurface(surface3, surface2);
1121 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 16x16 offscreen plain surface to a 32x32 texture mip level returned %08x\n", hr);
1122 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface3);
1123 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 32x32 texture mip level to a 16x16 offscreen plain surface returned %08x\n", hr);
1125 IDirectDrawSurface7_Release(surface3);
1126 IDirectDrawSurface7_Release(surface2);
1127 IDirectDrawSurface7_Release(surface1);
1129 hr = IDirectDraw7_SetCooperativeLevel(dd7, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
1130 ok(hr == DD_OK, "SetCooperativeLevel returned %08x\n", hr);
1132 memset(&ddsd, 0, sizeof(ddsd));
1133 ddsd.dwSize = sizeof(ddsd);
1134 ddsd.dwFlags = DDSD_BACKBUFFERCOUNT | DDSD_CAPS;
1135 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
1136 ddsd.dwBackBufferCount = 2;
1137 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface1, NULL);
1138 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1140 num = 0;
1141 IDirectDrawSurface7_EnumAttachedSurfaces(surface1, &num, SurfaceCounter);
1142 ok(num == 1, "Primary surface has %d surfaces attached, expected 1\n", num);
1143 IDirectDrawSurface7_Release(surface1);
1145 /* Those are some invalid descriptions, no need to test attachments with them */
1146 memset(&ddsd, 0, sizeof(ddsd));
1147 ddsd.dwSize = sizeof(ddsd);
1148 ddsd.dwFlags = DDSD_CAPS;
1149 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FRONTBUFFER;
1150 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface1, NULL);
1151 ok(hr==DDERR_INVALIDCAPS,"CreateSurface returned: %x\n",hr);
1152 memset(&ddsd, 0, sizeof(ddsd));
1153 ddsd.dwSize = sizeof(ddsd);
1154 ddsd.dwFlags = DDSD_CAPS;
1155 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_BACKBUFFER;
1156 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface2, NULL);
1157 ok(hr==DDERR_INVALIDCAPS,"CreateSurface returned: %x\n",hr);
1159 /* Try a single primary and two offscreen plain surfaces */
1160 memset(&ddsd, 0, sizeof(ddsd));
1161 ddsd.dwSize = sizeof(ddsd);
1162 ddsd.dwFlags = DDSD_CAPS;
1163 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
1164 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface1, NULL);
1165 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1167 memset(&ddsd, 0, sizeof(ddsd));
1168 ddsd.dwSize = sizeof(ddsd);
1169 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1170 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
1171 ddsd.dwWidth = GetSystemMetrics(SM_CXSCREEN);
1172 ddsd.dwHeight = GetSystemMetrics(SM_CYSCREEN);
1173 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface2, NULL);
1174 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1176 memset(&ddsd, 0, sizeof(ddsd));
1177 ddsd.dwSize = sizeof(ddsd);
1178 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1179 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
1180 ddsd.dwWidth = GetSystemMetrics(SM_CXSCREEN);
1181 ddsd.dwHeight = GetSystemMetrics(SM_CYSCREEN);
1182 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface3, NULL);
1183 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1185 /* This one has a different size */
1186 memset(&ddsd, 0, sizeof(ddsd));
1187 ddsd.dwSize = sizeof(ddsd);
1188 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1189 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
1190 ddsd.dwWidth = 128;
1191 ddsd.dwHeight = 128;
1192 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface4, NULL);
1193 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1195 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface2);
1196 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching an offscreen plain surface to a front buffer returned %08x\n", hr);
1197 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface1);
1198 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a front buffer to an offscreen plain surface returned %08x\n", hr);
1199 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface3);
1200 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching an offscreen plain surface to another offscreen plain surface returned %08x\n", hr);
1201 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface4);
1202 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching an offscreen plain surface to a front buffer of different size returned %08x\n", hr);
1203 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface1);
1204 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a front buffer to an offscreen plain surface of different size returned %08x\n", hr);
1206 IDirectDrawSurface7_Release(surface4);
1207 IDirectDrawSurface7_Release(surface3);
1208 IDirectDrawSurface7_Release(surface2);
1209 IDirectDrawSurface7_Release(surface1);
1211 hr =IDirectDraw7_SetCooperativeLevel(dd7, NULL, DDSCL_NORMAL);
1212 ok(hr == DD_OK, "SetCooperativeLevel returned %08x\n", hr);
1213 IDirectDraw7_Release(dd7);
1216 static void AttachmentTest(void)
1218 HRESULT hr;
1219 IDirectDrawSurface *surface1, *surface2, *surface3, *surface4;
1220 DDSURFACEDESC ddsd;
1221 DDSCAPS caps = {DDSCAPS_TEXTURE};
1222 BOOL refrast = FALSE;
1223 HWND window = CreateWindow( "static", "ddraw_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
1225 memset(&ddsd, 0, sizeof(ddsd));
1226 ddsd.dwSize = sizeof(ddsd);
1227 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_MIPMAPCOUNT;
1228 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
1229 U2(ddsd).dwMipMapCount = 3; /* Will create 128x128, 64x64, 32x32 */
1230 ddsd.dwWidth = 128;
1231 ddsd.dwHeight = 128;
1232 hr = IDirectDraw7_CreateSurface(lpDD, &ddsd, &surface1, NULL);
1233 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1235 hr = IDirectDrawSurface7_GetAttachedSurface(surface1, &caps, &surface2);
1236 ok(hr == DD_OK, "GetAttachedSurface returned %08x\n", hr);
1237 hr = IDirectDrawSurface7_GetAttachedSurface(surface2, &caps, &surface3);
1238 ok(hr == DD_OK, "GetAttachedSurface returned %08x\n", hr);
1240 /* Try to attach a 16x16 miplevel - Should not work as far I can see */
1241 memset(&ddsd, 0, sizeof(ddsd));
1242 ddsd.dwSize = sizeof(ddsd);
1243 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1244 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1245 ddsd.dwWidth = 16;
1246 ddsd.dwHeight = 16;
1247 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface4, NULL);
1248 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1250 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface4);
1251 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 16x16 surface to a 128x128 texture root returned %08x\n", hr);
1252 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface1);
1253 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 128x128 texture root to a 16x16 texture returned %08x\n", hr);
1254 hr = IDirectDrawSurface7_AddAttachedSurface(surface3, surface4);
1255 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 16x16 surface to a 32x32 texture mip level returned %08x\n", hr);
1256 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface3);
1257 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 32x32 texture mip level to a 16x16 surface returned %08x\n", hr);
1258 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface4);
1259 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 16x16 surface to a 64x64 texture sublevel returned %08x\n", hr);
1260 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface2);
1261 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 64x64 texture sublevel to a 16x16 texture returned %08x\n", hr);
1263 IDirectDrawSurface7_Release(surface4);
1265 memset(&ddsd, 0, sizeof(ddsd));
1266 ddsd.dwSize = sizeof(ddsd);
1267 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1268 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
1269 ddsd.dwWidth = 16;
1270 ddsd.dwHeight = 16;
1271 hr = IDirectDraw7_CreateSurface(lpDD, &ddsd, &surface4, NULL);
1272 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1274 if (SUCCEEDED(IDirectDrawSurface7_AddAttachedSurface(surface1, surface4)))
1276 IDirectDrawSurface7_DeleteAttachedSurface(surface1, 0, surface4);
1277 refrast = TRUE;
1280 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface4); /* Succeeds on refrast */
1281 if (refrast)
1282 ok(hr == S_OK, "Attaching a 16x16 offscreen plain surface to a 128x128 texture root returned %08x\n", hr);
1283 else
1284 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 16x16 offscreen plain surface to a 128x128 texture root returned %08x\n", hr);
1285 if(SUCCEEDED(hr)) IDirectDrawSurface7_DeleteAttachedSurface(surface1, 0, surface4);
1287 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface1); /* Succeeds on refrast */
1288 if (refrast)
1289 ok(hr == S_OK, "Attaching a 128x128 texture root to a 16x16 offscreen plain surface returned %08x\n", hr);
1290 else
1291 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 128x128 texture root to a 16x16 offscreen plain surface returned %08x\n", hr);
1292 if(SUCCEEDED(hr)) IDirectDrawSurface7_DeleteAttachedSurface(surface1, 0, surface1);
1294 hr = IDirectDrawSurface7_AddAttachedSurface(surface3, surface4); /* Succeeds on refrast */
1295 if (refrast)
1296 ok(hr == S_OK, "Attaching a 16x16 offscreen plain surface to a 32x32 texture mip level returned %08x\n", hr);
1297 else
1298 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 16x16 offscreen plain surface to a 32x32 texture mip level returned %08x\n", hr);
1299 if(SUCCEEDED(hr)) IDirectDrawSurface7_DeleteAttachedSurface(surface3, 0, surface4);
1301 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface3);
1302 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 32x32 texture mip level to a 16x16 offscreen plain surface returned %08x\n", hr);
1303 if(SUCCEEDED(hr)) IDirectDrawSurface7_DeleteAttachedSurface(surface4, 0, surface3);
1305 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface4); /* Succeeds on refrast */
1306 if (refrast)
1307 ok(hr == S_OK, "Attaching a 16x16 offscreen plain surface to a 64x64 texture sublevel returned %08x\n", hr);
1308 else
1309 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 16x16 offscreen plain surface to a 64x64 texture sublevel returned %08x\n", hr);
1310 if(SUCCEEDED(hr)) IDirectDrawSurface7_DeleteAttachedSurface(surface2, 0, surface4);
1312 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface2);
1313 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 64x64 texture sublevel to a 16x16 offscreen plain surface returned %08x\n", hr);
1314 if(SUCCEEDED(hr)) IDirectDrawSurface7_DeleteAttachedSurface(surface4, 0, surface2);
1316 IDirectDrawSurface7_Release(surface4);
1317 IDirectDrawSurface7_Release(surface3);
1318 IDirectDrawSurface7_Release(surface2);
1319 IDirectDrawSurface7_Release(surface1);
1321 hr = IDirectDraw_SetCooperativeLevel(lpDD, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
1322 ok(hr == DD_OK, "SetCooperativeLevel returned %08x\n", hr);
1324 /* Creating a back buffer as-is, is not allowed. No need to perform attachment tests */
1325 memset(&ddsd, 0, sizeof(ddsd));
1326 ddsd.dwSize = sizeof(ddsd);
1327 ddsd.dwFlags = DDSD_CAPS;
1328 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_BACKBUFFER;
1329 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface2, NULL);
1330 ok(hr==DDERR_INVALIDCAPS,"CreateSurface returned: %x\n",hr);
1331 /* This old ddraw version happily creates explicit front buffers */
1332 memset(&ddsd, 0, sizeof(ddsd));
1333 ddsd.dwSize = sizeof(ddsd);
1334 ddsd.dwFlags = DDSD_CAPS;
1335 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FRONTBUFFER;
1336 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface1, NULL);
1337 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1338 IDirectDrawSurface_Release(surface1);
1340 /* Try a single primary and two offscreen plain surfaces */
1341 memset(&ddsd, 0, sizeof(ddsd));
1342 ddsd.dwSize = sizeof(ddsd);
1343 ddsd.dwFlags = DDSD_CAPS;
1344 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
1345 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface1, NULL);
1346 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1348 memset(&ddsd, 0, sizeof(ddsd));
1349 ddsd.dwSize = sizeof(ddsd);
1350 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1351 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
1352 ddsd.dwWidth = GetSystemMetrics(SM_CXSCREEN);
1353 ddsd.dwHeight = GetSystemMetrics(SM_CYSCREEN);
1354 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface2, NULL);
1355 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
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_OFFSCREENPLAIN;
1361 ddsd.dwWidth = GetSystemMetrics(SM_CXSCREEN);
1362 ddsd.dwHeight = GetSystemMetrics(SM_CYSCREEN);
1363 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface3, NULL);
1364 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1366 /* This one has a different size */
1367 memset(&ddsd, 0, sizeof(ddsd));
1368 ddsd.dwSize = sizeof(ddsd);
1369 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1370 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
1371 ddsd.dwWidth = 128;
1372 ddsd.dwHeight = 128;
1373 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface4, NULL);
1374 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1376 hr = IDirectDrawSurface_AddAttachedSurface(surface1, surface2);
1377 ok(hr == DD_OK, "Attaching an offscreen plain surface to a front buffer returned %08x\n", hr);
1378 /* Try the reverse without detaching first */
1379 hr = IDirectDrawSurface_AddAttachedSurface(surface2, surface1);
1380 ok(hr == DDERR_SURFACEALREADYATTACHED, "Attaching an attached surface to its attachee returned %08x\n", hr);
1381 hr = IDirectDrawSurface_DeleteAttachedSurface(surface1, 0, surface2);
1382 ok(hr == DD_OK, "DeleteAttachedSurface failed with %08x\n", hr);
1383 hr = IDirectDrawSurface_AddAttachedSurface(surface2, surface1);
1384 ok(hr == DD_OK, "Attaching a front buffer to an offscreen plain surface returned %08x\n", hr);
1385 /* Try to detach reversed */
1386 hr = IDirectDrawSurface_DeleteAttachedSurface(surface1, 0, surface2);
1387 ok(hr == DDERR_CANNOTDETACHSURFACE, "DeleteAttachedSurface returned %08x\n", hr);
1388 /* Now the proper detach */
1389 hr = IDirectDrawSurface_DeleteAttachedSurface(surface2, 0, surface1);
1390 ok(hr == DD_OK, "DeleteAttachedSurface failed with %08x\n", hr);
1391 hr = IDirectDrawSurface_AddAttachedSurface(surface2, surface3); /* Fails on refrast */
1392 ok(hr == DD_OK, "Attaching an offscreen plain surface to another offscreen plain surface returned %08x\n", hr);
1393 if(SUCCEEDED(hr))
1395 hr = IDirectDrawSurface_DeleteAttachedSurface(surface2, 0, surface3);
1396 ok(hr == DD_OK, "DeleteAttachedSurface failed with %08x\n", hr);
1398 hr = IDirectDrawSurface_AddAttachedSurface(surface1, surface4);
1399 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching an offscreen plain surface to a front buffer of different size returned %08x\n", hr);
1400 hr = IDirectDrawSurface_AddAttachedSurface(surface4, surface1);
1401 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a front buffer to an offscreen plain surface of different size returned %08x\n", hr);
1403 IDirectDrawSurface_Release(surface4);
1404 IDirectDrawSurface_Release(surface3);
1405 IDirectDrawSurface_Release(surface2);
1406 IDirectDrawSurface_Release(surface1);
1408 hr =IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_NORMAL);
1409 ok(hr == DD_OK, "SetCooperativeLevel returned %08x\n", hr);
1411 DestroyWindow(window);
1414 struct compare
1416 DWORD width, height;
1417 DWORD caps, caps2;
1418 UINT mips;
1421 HRESULT WINAPI CubeTestLvl2Enum(IDirectDrawSurface7 *surface, DDSURFACEDESC2 *desc, void *context)
1423 UINT *mips = context;
1425 (*mips)++;
1426 IDirectDrawSurface7_EnumAttachedSurfaces(surface,
1427 context,
1428 CubeTestLvl2Enum);
1430 return DDENUMRET_OK;
1433 HRESULT WINAPI CubeTestLvl1Enum(IDirectDrawSurface7 *surface, DDSURFACEDESC2 *desc, void *context)
1435 UINT mips = 0;
1436 UINT *num = (UINT *) context;
1437 static const struct compare expected[] =
1440 128, 128,
1441 DDSCAPS_MIPMAP | DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_COMPLEX,
1442 DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEZ,
1446 128, 128,
1447 DDSCAPS_MIPMAP | DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_COMPLEX,
1448 DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEZ,
1452 128, 128,
1453 DDSCAPS_MIPMAP | DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_COMPLEX,
1454 DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEY,
1458 128, 128,
1459 DDSCAPS_MIPMAP | DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_COMPLEX,
1460 DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEY,
1464 128, 128,
1465 DDSCAPS_MIPMAP | DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_COMPLEX,
1466 DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEX,
1470 64, 64, /* This is the first mipmap */
1471 DDSCAPS_MIPMAP | DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_COMPLEX,
1472 DDSCAPS2_MIPMAPSUBLEVEL | DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEX,
1477 mips = 0;
1478 IDirectDrawSurface7_EnumAttachedSurfaces(surface,
1479 &mips,
1480 CubeTestLvl2Enum);
1482 ok(desc->dwWidth == expected[*num].width, "Surface width is %d expected %d\n", desc->dwWidth, expected[*num].width);
1483 ok(desc->dwHeight == expected[*num].height, "Surface height is %d expected %d\n", desc->dwHeight, expected[*num].height);
1484 ok(desc->ddsCaps.dwCaps == expected[*num].caps, "Surface caps are %08x expected %08x\n", desc->ddsCaps.dwCaps, expected[*num].caps);
1485 ok(desc->ddsCaps.dwCaps2 == expected[*num].caps2, "Surface caps2 are %08x expected %08x\n", desc->ddsCaps.dwCaps2, expected[*num].caps2);
1486 ok(mips == expected[*num].mips, "Surface has %d mipmaps, expected %d\n", mips, expected[*num].mips);
1488 (*num)++;
1490 IDirectDrawSurface7_Release(surface);
1492 return DDENUMRET_OK;
1495 static void CubeMapTest(void)
1497 IDirectDraw7 *dd7 = NULL;
1498 IDirectDrawSurface7 *cubemap = NULL;
1499 DDSURFACEDESC2 ddsd;
1500 HRESULT hr;
1501 UINT num = 0;
1502 struct enumstruct ctx;
1504 hr = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
1505 ok(hr == DD_OK, "IDirectDraw::QueryInterface returned %08x\n", hr);
1506 if (FAILED(hr)) goto err;
1508 memset(&ddsd, 0, sizeof(ddsd));
1509 ddsd.dwSize = sizeof(ddsd);
1510 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
1511 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS;
1512 ddsd.dwWidth = 128;
1513 ddsd.dwHeight = 128;
1514 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP | DDSCAPS_SYSTEMMEMORY;
1515 ddsd.ddsCaps.dwCaps2 = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES;
1517 /* D3DFMT_R5G6B5 */
1518 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
1519 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 16;
1520 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0xF800;
1521 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x07E0;
1522 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x001F;
1524 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &cubemap, NULL);
1525 if (FAILED(hr))
1527 skip("Can't create cubemap surface\n");
1528 goto err;
1531 hr = IDirectDrawSurface7_GetSurfaceDesc(cubemap, &ddsd);
1532 ok(hr == DD_OK, "IDirectDrawSurface7_GetSurfaceDesc returned %08x\n", hr);
1533 ok(ddsd.ddsCaps.dwCaps == (DDSCAPS_MIPMAP | DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_COMPLEX),
1534 "Root Caps are %08x\n", ddsd.ddsCaps.dwCaps);
1535 ok(ddsd.ddsCaps.dwCaps2 == (DDSCAPS2_CUBEMAP_POSITIVEX | DDSCAPS2_CUBEMAP),
1536 "Root Caps2 are %08x\n", ddsd.ddsCaps.dwCaps2);
1538 IDirectDrawSurface7_EnumAttachedSurfaces(cubemap,
1539 &num,
1540 CubeTestLvl1Enum);
1541 ok(num == 6, "Surface has %d attachments\n", num);
1542 IDirectDrawSurface7_Release(cubemap);
1544 /* What happens if I do not specify any faces? */
1545 memset(&ddsd, 0, sizeof(ddsd));
1546 ddsd.dwSize = sizeof(ddsd);
1547 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
1548 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS;
1549 ddsd.dwWidth = 128;
1550 ddsd.dwHeight = 128;
1551 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP | DDSCAPS_SYSTEMMEMORY;
1552 ddsd.ddsCaps.dwCaps2 = DDSCAPS2_CUBEMAP;
1554 /* D3DFMT_R5G6B5 */
1555 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
1556 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 16;
1557 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0xF800;
1558 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x07E0;
1559 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x001F;
1561 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &cubemap, NULL);
1562 ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw7::CreateSurface asking for a cube map without faces returned %08x\n", hr);
1564 /* Cube map faces without a cube map? */
1565 memset(&ddsd, 0, sizeof(ddsd));
1566 ddsd.dwSize = sizeof(ddsd);
1567 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
1568 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS;
1569 ddsd.dwWidth = 128;
1570 ddsd.dwHeight = 128;
1571 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP | DDSCAPS_SYSTEMMEMORY;
1572 ddsd.ddsCaps.dwCaps2 = DDSCAPS2_CUBEMAP_ALLFACES;
1574 /* D3DFMT_R5G6B5 */
1575 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
1576 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 16;
1577 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0xF800;
1578 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x07E0;
1579 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x001F;
1581 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &cubemap, NULL);
1582 ok(hr == DDERR_INVALIDCAPS, "IDirectDraw7::CreateSurface returned %08x\n", hr);
1584 memset(&ddsd, 0, sizeof(ddsd));
1585 ddsd.dwSize = sizeof(ddsd);
1586 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
1587 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS;
1588 ddsd.dwWidth = 128;
1589 ddsd.dwHeight = 128;
1590 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP | DDSCAPS_SYSTEMMEMORY;
1591 ddsd.ddsCaps.dwCaps2 = DDSCAPS2_CUBEMAP_POSITIVEX;
1593 /* D3DFMT_R5G6B5 */
1594 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
1595 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 16;
1596 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0xF800;
1597 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x07E0;
1598 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x001F;
1600 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &cubemap, NULL);
1601 ok(hr == DDERR_INVALIDCAPS, "IDirectDraw7::CreateSurface returned %08x\n", hr);
1603 /* Make sure everything is cleaned up properly. Use the enumSurfaces test infrastructure */
1604 memset(&ctx, 0, sizeof(ctx));
1605 memset(&ddsd, 0, sizeof(ddsd));
1606 ddsd.dwSize = sizeof(DDSURFACEDESC);
1607 hr = IDirectDraw_EnumSurfaces(lpDD, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_ALL, (DDSURFACEDESC *) &ddsd, (void *) &ctx, enumCB);
1608 ok(hr == DD_OK, "IDirectDraw_EnumSurfaces returned %08x\n", hr);
1609 ok(ctx.count == 0, "%d surfaces enumerated, expected 0\n", ctx.count);
1611 err:
1612 if (dd7) IDirectDraw7_Release(dd7);
1615 static void test_lockrect_invalid(void)
1617 unsigned int i, j;
1619 RECT valid[] = {
1620 {60, 60, 68, 68},
1621 {60, 60, 60, 68},
1622 {60, 60, 68, 60},
1623 {120, 60, 128, 68},
1624 {60, 120, 68, 128},
1627 RECT invalid[] = {
1628 {68, 60, 60, 68}, /* left > right */
1629 {60, 68, 68, 60}, /* top > bottom */
1630 {-8, 60, 0, 68}, /* left < surface */
1631 {60, -8, 68, 0}, /* top < surface */
1632 {-16, 60, -8, 68}, /* right < surface */
1633 {60, -16, 68, -8}, /* bottom < surface */
1634 {60, 60, 136, 68}, /* right > surface */
1635 {60, 60, 68, 136}, /* bottom > surface */
1636 {136, 60, 144, 68}, /* left > surface */
1637 {60, 136, 68, 144}, /* top > surface */
1640 const DWORD dds_caps[] = {
1641 DDSCAPS_OFFSCREENPLAIN
1644 for (j = 0; j < (sizeof(dds_caps) / sizeof(*dds_caps)); ++j)
1646 IDirectDrawSurface *surface = 0;
1647 DDSURFACEDESC surface_desc = {0};
1648 DDSURFACEDESC locked_desc = {0};
1649 HRESULT hr;
1651 surface_desc.dwSize = sizeof(surface_desc);
1652 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
1653 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
1654 surface_desc.ddsCaps.dwCaps = dds_caps[j];
1655 surface_desc.dwWidth = 128;
1656 surface_desc.dwHeight = 128;
1657 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB;
1658 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount = 32;
1659 U2(surface_desc.ddpfPixelFormat).dwRBitMask = 0xFF0000;
1660 U3(surface_desc.ddpfPixelFormat).dwGBitMask = 0x00FF00;
1661 U4(surface_desc.ddpfPixelFormat).dwBBitMask = 0x0000FF;
1663 hr = IDirectDraw_CreateSurface(lpDD, &surface_desc, &surface, NULL);
1664 ok(SUCCEEDED(hr), "CreateSurface failed (0x%08x)\n", hr);
1665 if (FAILED(hr)) {
1666 skip("failed to create surface\n");
1667 continue;
1670 for (i = 0; i < (sizeof(valid) / sizeof(*valid)); ++i)
1672 RECT *rect = &valid[i];
1674 memset(&locked_desc, 0, sizeof(locked_desc));
1675 locked_desc.dwSize = sizeof(locked_desc);
1677 hr = IDirectDrawSurface_Lock(surface, rect, &locked_desc, DDLOCK_WAIT, NULL);
1678 ok(SUCCEEDED(hr), "Lock failed (0x%08x) for rect [%d, %d]->[%d, %d]\n",
1679 hr, rect->left, rect->top, rect->right, rect->bottom);
1681 hr = IDirectDrawSurface_Unlock(surface, NULL);
1682 ok(SUCCEEDED(hr), "Unlock failed (0x%08x)\n", hr);
1685 for (i = 0; i < (sizeof(invalid) / sizeof(*invalid)); ++i)
1687 RECT *rect = &invalid[i];
1689 memset(&locked_desc, 1, sizeof(locked_desc));
1690 locked_desc.dwSize = sizeof(locked_desc);
1692 hr = IDirectDrawSurface_Lock(surface, rect, &locked_desc, DDLOCK_WAIT, NULL);
1693 ok(hr == DDERR_INVALIDPARAMS, "Lock returned 0x%08x for rect [%d, %d]->[%d, %d]"
1694 ", expected DDERR_INVALIDPARAMS (0x%08x)\n", hr, rect->left, rect->top,
1695 rect->right, rect->bottom, DDERR_INVALIDPARAMS);
1696 ok(!locked_desc.lpSurface, "IDirectDrawSurface_Lock did not set lpSurface in the surface desc to zero.\n");
1699 hr = IDirectDrawSurface_Lock(surface, NULL, &locked_desc, DDLOCK_WAIT, NULL);
1700 ok(hr == DD_OK, "IDirectDrawSurface_Lock(rect = NULL) failed (0x%08x)\n", hr);
1701 hr = IDirectDrawSurface_Lock(surface, NULL, &locked_desc, DDLOCK_WAIT, NULL);
1702 ok(hr == DDERR_SURFACEBUSY, "Double lock(rect = NULL) returned 0x%08x\n", hr);
1703 if(SUCCEEDED(hr)) {
1704 hr = IDirectDrawSurface_Unlock(surface, NULL);
1705 ok(SUCCEEDED(hr), "Unlock failed (0x%08x)\n", hr);
1707 hr = IDirectDrawSurface_Unlock(surface, NULL);
1708 ok(SUCCEEDED(hr), "Unlock failed (0x%08x)\n", hr);
1710 memset(&locked_desc, 0, sizeof(locked_desc));
1711 locked_desc.dwSize = sizeof(locked_desc);
1712 hr = IDirectDrawSurface_Lock(surface, &valid[0], &locked_desc, DDLOCK_WAIT, NULL);
1713 ok(hr == DD_OK, "IDirectDrawSurface_Lock(rect = [%d, %d]->[%d, %d]) failed (0x%08x)\n",
1714 valid[0].left, valid[0].top, valid[0].right, valid[0].bottom, hr);
1715 hr = IDirectDrawSurface_Lock(surface, &valid[0], &locked_desc, DDLOCK_WAIT, NULL);
1716 ok(hr == DDERR_SURFACEBUSY, "Double lock(rect = [%d, %d]->[%d, %d]) failed (0x%08x)\n",
1717 valid[0].left, valid[0].top, valid[0].right, valid[0].bottom, hr);
1719 /* Locking a different rectangle returns DD_OK, but it seems to break the surface.
1720 * Afterwards unlocking the surface fails(NULL rectangle, and both locked rectangles
1723 hr = IDirectDrawSurface_Unlock(surface, NULL);
1724 ok(hr == DD_OK, "Unlock returned (0x%08x)\n", hr);
1726 IDirectDrawSurface_Release(surface);
1730 static void CompressedTest(void)
1732 HRESULT hr;
1733 IDirectDrawSurface7 *surface;
1734 DDSURFACEDESC2 ddsd, ddsd2;
1735 IDirectDraw7 *dd7 = NULL;
1736 RECT r = { 0, 0, 128, 128 };
1737 RECT r2 = { 32, 32, 64, 64 };
1739 hr = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
1740 ok(hr == DD_OK, "IDirectDraw::QueryInterface returned %08x\n", hr);
1742 memset(&ddsd, 0, sizeof(ddsd));
1743 ddsd.dwSize = sizeof(ddsd);
1744 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
1745 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS;
1746 ddsd.dwWidth = 128;
1747 ddsd.dwHeight = 128;
1748 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY;
1749 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_FOURCC;
1750 U4(ddsd).ddpfPixelFormat.dwFourCC = MAKEFOURCC('D','X','T','1');
1752 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface, NULL);
1753 ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
1754 if (FAILED(hr)) {
1755 skip("failed to create surface\n");
1756 return;
1759 memset(&ddsd2, 0, sizeof(ddsd2));
1760 ddsd2.dwSize = sizeof(ddsd2);
1761 U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
1762 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd2);
1763 ok(hr == DD_OK, "GetSurfaceDesc returned %08x\n", hr);
1765 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
1766 "Surface desc flags: %08x\n", ddsd2.dwFlags);
1767 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
1768 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
1769 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
1770 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
1771 ok(U1(ddsd2).dwLinearSize == 8192, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
1772 ok(ddsd2.ddsCaps.dwCaps2 == 0, "Caps2: %08x\n", ddsd2.ddsCaps.dwCaps2);
1773 IDirectDrawSurface7_Release(surface);
1775 U4(ddsd).ddpfPixelFormat.dwFourCC = MAKEFOURCC('D','X','T','3');
1776 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface, NULL);
1777 ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
1778 if (FAILED(hr)) {
1779 skip("failed to create surface\n");
1780 return;
1783 memset(&ddsd2, 0, sizeof(ddsd2));
1784 ddsd2.dwSize = sizeof(ddsd2);
1785 U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
1786 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd2);
1787 ok(hr == DD_OK, "GetSurfaceDesc returned %08x\n", hr);
1789 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
1790 "Surface desc flags: %08x\n", ddsd2.dwFlags);
1791 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
1792 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
1793 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
1794 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
1795 ok(U1(ddsd2).dwLinearSize == 16384, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
1796 IDirectDrawSurface7_Release(surface);
1798 U4(ddsd).ddpfPixelFormat.dwFourCC = MAKEFOURCC('D','X','T','5');
1799 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface, NULL);
1800 ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
1801 if (FAILED(hr)) {
1802 skip("failed to create surface\n");
1803 return;
1806 memset(&ddsd2, 0, sizeof(ddsd2));
1807 ddsd2.dwSize = sizeof(ddsd2);
1808 U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
1809 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd2);
1810 ok(hr == DD_OK, "GetSurfaceDesc returned %08x\n", hr);
1812 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
1813 "Surface desc flags: %08x\n", ddsd2.dwFlags);
1814 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
1815 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
1816 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
1817 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
1818 ok(U1(ddsd2).dwLinearSize == 16384, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
1819 ok(ddsd2.lpSurface == 0, "Surface memory is at %p, expected NULL\n", ddsd2.lpSurface);
1821 memset(&ddsd2, 0, sizeof(ddsd2));
1822 ddsd2.dwSize = sizeof(ddsd2);
1823 U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
1825 /* Show that the description is not changed when locking the surface. What is really interesting
1826 * about this is that DDSD_LPSURFACE isn't set.
1828 hr = IDirectDrawSurface7_Lock(surface, NULL, &ddsd2, DDLOCK_READONLY, 0);
1829 ok(hr == DD_OK, "Lock returned %08x\n", hr);
1831 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
1832 "Surface desc flags: %08x\n", ddsd2.dwFlags);
1833 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
1834 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
1835 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
1836 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
1837 ok(U1(ddsd2).dwLinearSize == 16384, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
1838 ok(ddsd2.lpSurface != 0, "Surface memory is at NULL\n");
1840 hr = IDirectDrawSurface7_Unlock(surface, NULL);
1841 ok(hr == DD_OK, "Unlock returned %08x\n", hr);
1843 /* Now what about a locking rect? */
1844 hr = IDirectDrawSurface7_Lock(surface, &r, &ddsd2, DDLOCK_READONLY, 0);
1845 ok(hr == DD_OK, "Lock returned %08x\n", hr);
1847 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
1848 "Surface desc flags: %08x\n", ddsd2.dwFlags);
1849 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
1850 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
1851 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
1852 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
1853 ok(U1(ddsd2).dwLinearSize == 16384, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
1854 ok(ddsd2.lpSurface != 0, "Surface memory is at NULL\n");
1856 hr = IDirectDrawSurface7_Unlock(surface, &r);
1857 ok(hr == DD_OK, "Unlock returned %08x\n", hr);
1859 /* Now what about a different locking offset? */
1860 hr = IDirectDrawSurface7_Lock(surface, &r2, &ddsd2, DDLOCK_READONLY, 0);
1861 ok(hr == DD_OK, "Lock returned %08x\n", hr);
1863 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
1864 "Surface desc flags: %08x\n", ddsd2.dwFlags);
1865 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
1866 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
1867 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
1868 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
1869 ok(U1(ddsd2).dwLinearSize == 16384, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
1870 ok(ddsd2.lpSurface != 0, "Surface memory is at NULL\n");
1872 hr = IDirectDrawSurface7_Unlock(surface, &r2);
1873 ok(hr == DD_OK, "Unlock returned %08x\n", hr);
1874 IDirectDrawSurface7_Release(surface);
1876 /* Try this with video memory. A kind of surprise. It still has the LINEARSIZE flag set,
1877 * but seems to have a pitch instead.
1879 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY;
1880 U4(ddsd).ddpfPixelFormat.dwFourCC = MAKEFOURCC('D','X','T','1');
1882 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface, NULL);
1883 ok(hr == DD_OK || hr == DDERR_NOTEXTUREHW || hr == DDERR_INVALIDPARAMS ||
1884 broken(hr == DDERR_NODIRECTDRAWHW), "CreateSurface returned %08x\n", hr);
1886 /* Not supported everywhere */
1887 if(SUCCEEDED(hr))
1889 memset(&ddsd2, 0, sizeof(ddsd2));
1890 ddsd2.dwSize = sizeof(ddsd2);
1891 U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
1892 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd2);
1893 ok(hr == DD_OK, "GetSurfaceDesc returned %08x\n", hr);
1895 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
1896 "Surface desc flags: %08x\n", ddsd2.dwFlags);
1897 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
1898 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
1899 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM),
1900 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
1901 /* ATI drivers report a broken linear size, thus no need to clone the exact behaviour. nvidia reports the correct size */
1902 ok(ddsd2.ddsCaps.dwCaps2 == 0, "Caps2: %08x\n", ddsd2.ddsCaps.dwCaps2);
1903 IDirectDrawSurface7_Release(surface);
1905 U4(ddsd).ddpfPixelFormat.dwFourCC = MAKEFOURCC('D','X','T','3');
1906 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface, NULL);
1907 ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
1909 memset(&ddsd2, 0, sizeof(ddsd2));
1910 ddsd2.dwSize = sizeof(ddsd2);
1911 U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
1912 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd2);
1913 ok(hr == DD_OK, "GetSurfaceDesc returned %08x\n", hr);
1915 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
1916 "Surface desc flags: %08x\n", ddsd2.dwFlags);
1917 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
1918 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
1919 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM),
1920 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
1921 /* ATI drivers report a broken linear size, thus no need to clone the exact behaviour. nvidia reports the correct size */
1922 IDirectDrawSurface7_Release(surface);
1924 U4(ddsd).ddpfPixelFormat.dwFourCC = MAKEFOURCC('D','X','T','5');
1925 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface, NULL);
1926 ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
1928 memset(&ddsd2, 0, sizeof(ddsd2));
1929 ddsd2.dwSize = sizeof(ddsd2);
1930 U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
1931 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd2);
1932 ok(hr == DD_OK, "GetSurfaceDesc returned %08x\n", hr);
1934 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
1935 "Surface desc flags: %08x\n", ddsd2.dwFlags);
1936 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
1937 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
1938 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM),
1939 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
1940 /* ATI drivers report a broken linear size, thus no need to clone the exact behaviour. nvidia reports the correct size */
1941 ok(ddsd2.lpSurface == 0, "Surface memory is at %p, expected NULL\n", ddsd2.lpSurface);
1943 memset(&ddsd2, 0, sizeof(ddsd2));
1944 ddsd2.dwSize = sizeof(ddsd2);
1945 U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
1947 /* Show that the description is not changed when locking the surface. What is really interesting
1948 * about this is that DDSD_LPSURFACE isn't set.
1950 hr = IDirectDrawSurface7_Lock(surface, NULL, &ddsd2, DDLOCK_READONLY, 0);
1951 ok(hr == DD_OK, "Lock returned %08x\n", hr);
1953 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
1954 "Surface desc flags: %08x\n", ddsd2.dwFlags);
1955 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
1956 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
1957 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM),
1958 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
1959 /* ATI drivers report a broken linear size, thus no need to clone the exact behaviour. nvidia reports the correct size */
1960 ok(ddsd2.lpSurface != 0, "Surface memory is at NULL\n");
1962 hr = IDirectDrawSurface7_Unlock(surface, NULL);
1963 ok(hr == DD_OK, "Unlock returned %08x\n", hr);
1965 /* Now what about a locking rect? */
1966 hr = IDirectDrawSurface7_Lock(surface, &r, &ddsd2, DDLOCK_READONLY, 0);
1967 ok(hr == DD_OK, "Lock returned %08x\n", hr);
1969 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
1970 "Surface desc flags: %08x\n", ddsd2.dwFlags);
1971 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
1972 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
1973 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM),
1974 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
1975 /* ATI drivers report a broken linear size, thus no need to clone the exact behaviour. nvidia reports the correct size */
1976 ok(ddsd2.lpSurface != 0, "Surface memory is at NULL\n");
1978 hr = IDirectDrawSurface7_Unlock(surface, &r);
1979 ok(hr == DD_OK, "Unlock returned %08x\n", hr);
1981 /* Now what about a different locking offset? */
1982 hr = IDirectDrawSurface7_Lock(surface, &r2, &ddsd2, DDLOCK_READONLY, 0);
1983 ok(hr == DD_OK, "Lock returned %08x\n", hr);
1985 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
1986 "Surface desc flags: %08x\n", ddsd2.dwFlags);
1987 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
1988 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
1989 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM),
1990 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
1991 /* ATI drivers report a broken linear size, thus no need to clone the exact behaviour. nvidia reports the correct size */
1992 ok(ddsd2.lpSurface != 0, "Surface memory is at NULL\n");
1994 hr = IDirectDrawSurface7_Unlock(surface, &r2);
1995 ok(hr == DD_OK, "Unlock returned %08x\n", hr);
1997 IDirectDrawSurface7_Release(surface);
1999 else
2001 skip("Hardware DXTN textures not supported\n");
2004 /* What happens to managed textures? Interestingly, Windows reports them as being in system
2005 * memory. The linear size fits again.
2007 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
2008 ddsd.ddsCaps.dwCaps2 = DDSCAPS2_TEXTUREMANAGE;
2009 U4(ddsd).ddpfPixelFormat.dwFourCC = MAKEFOURCC('D','X','T','1');
2011 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface, NULL);
2012 ok(hr == DD_OK || hr == DDERR_NOTEXTUREHW, "CreateSurface returned %08x\n", hr);
2014 /* Not supported everywhere */
2015 if(SUCCEEDED(hr))
2017 memset(&ddsd2, 0, sizeof(ddsd2));
2018 ddsd2.dwSize = sizeof(ddsd2);
2019 U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
2020 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd2);
2021 ok(hr == DD_OK, "GetSurfaceDesc returned %08x\n", hr);
2023 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
2024 "Surface desc flags: %08x\n", ddsd2.dwFlags);
2025 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
2026 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
2027 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
2028 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
2029 ok(U1(ddsd2).dwLinearSize == 8192, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
2030 ok(ddsd2.ddsCaps.dwCaps2 == DDSCAPS2_TEXTUREMANAGE, "Caps2: %08x\n", ddsd2.ddsCaps.dwCaps2);
2031 IDirectDrawSurface7_Release(surface);
2033 U4(ddsd).ddpfPixelFormat.dwFourCC = MAKEFOURCC('D','X','T','3');
2034 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface, NULL);
2035 ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
2037 memset(&ddsd2, 0, sizeof(ddsd2));
2038 ddsd2.dwSize = sizeof(ddsd2);
2039 U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
2040 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd2);
2041 ok(hr == DD_OK, "GetSurfaceDesc returned %08x\n", hr);
2043 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
2044 "Surface desc flags: %08x\n", ddsd2.dwFlags);
2045 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
2046 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
2047 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
2048 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
2049 ok(U1(ddsd2).dwLinearSize == 16384, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
2050 IDirectDrawSurface7_Release(surface);
2052 U4(ddsd).ddpfPixelFormat.dwFourCC = MAKEFOURCC('D','X','T','5');
2053 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface, NULL);
2054 ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
2056 memset(&ddsd2, 0, sizeof(ddsd2));
2057 ddsd2.dwSize = sizeof(ddsd2);
2058 U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
2059 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd2);
2060 ok(hr == DD_OK, "GetSurfaceDesc returned %08x\n", hr);
2062 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
2063 "Surface desc flags: %08x\n", ddsd2.dwFlags);
2064 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
2065 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
2066 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
2067 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
2068 ok(U1(ddsd2).dwLinearSize == 16384, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
2069 ok(ddsd2.lpSurface == 0, "Surface memory is at %p, expected NULL\n", ddsd2.lpSurface);
2071 memset(&ddsd2, 0, sizeof(ddsd2));
2072 ddsd2.dwSize = sizeof(ddsd2);
2073 U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
2075 /* Show that the description is not changed when locking the surface. What is really interesting
2076 * about this is that DDSD_LPSURFACE isn't set.
2078 hr = IDirectDrawSurface7_Lock(surface, NULL, &ddsd2, DDLOCK_READONLY, 0);
2079 ok(hr == DD_OK, "Lock returned %08x\n", hr);
2081 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
2082 "Surface desc flags: %08x\n", ddsd2.dwFlags);
2083 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
2084 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
2085 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
2086 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
2087 ok(U1(ddsd2).dwLinearSize == 16384, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
2088 ok(ddsd2.lpSurface != 0, "Surface memory is at NULL\n");
2090 hr = IDirectDrawSurface7_Unlock(surface, NULL);
2091 ok(hr == DD_OK, "Unlock returned %08x\n", hr);
2093 /* Now what about a locking rect? */
2094 hr = IDirectDrawSurface7_Lock(surface, &r, &ddsd2, DDLOCK_READONLY, 0);
2095 ok(hr == DD_OK, "Lock returned %08x\n", hr);
2097 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
2098 "Surface desc flags: %08x\n", ddsd2.dwFlags);
2099 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
2100 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
2101 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
2102 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
2103 ok(U1(ddsd2).dwLinearSize == 16384, "\"Linear\" size is %d\n", U1(ddsd2).dwLinearSize);
2104 ok(ddsd2.lpSurface != 0, "Surface memory is at NULL\n");
2106 hr = IDirectDrawSurface7_Unlock(surface, &r);
2107 ok(hr == DD_OK, "Unlock returned %08x\n", hr);
2109 /* Now what about a different locking offset? */
2110 hr = IDirectDrawSurface7_Lock(surface, &r2, &ddsd2, DDLOCK_READONLY, 0);
2111 ok(hr == DD_OK, "Lock returned %08x\n", hr);
2113 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
2114 "Surface desc flags: %08x\n", ddsd2.dwFlags);
2115 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
2116 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
2117 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
2118 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
2119 ok(U1(ddsd2).dwLinearSize == 16384, "\"Linear\" size is %d\n", U1(ddsd2).dwLinearSize);
2120 ok(ddsd2.lpSurface != 0, "Surface memory is at NULL\n");
2122 hr = IDirectDrawSurface7_Unlock(surface, &r2);
2123 ok(hr == DD_OK, "Unlock returned %08x\n", hr);
2125 IDirectDrawSurface7_Release(surface);
2127 else
2129 skip("Hardware DXTN textures not supported\n");
2132 IDirectDraw7_Release(dd7);
2135 static void SizeTest(void)
2137 LPDIRECTDRAWSURFACE dsurface = NULL;
2138 DDSURFACEDESC desc;
2139 HRESULT ret;
2140 HWND window = CreateWindow( "static", "ddraw_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
2142 /* Create an offscreen surface surface without a size */
2143 ZeroMemory(&desc, sizeof(desc));
2144 desc.dwSize = sizeof(desc);
2145 desc.dwFlags = DDSD_CAPS;
2146 desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
2147 ret = IDirectDraw_CreateSurface(lpDD, &desc, &dsurface, NULL);
2148 ok(ret == DDERR_INVALIDPARAMS, "Creating an offscreen plain surface without a size info returned %08x (dsurface=%p)\n", ret, dsurface);
2149 if(dsurface)
2151 trace("Surface at %p\n", dsurface);
2152 IDirectDrawSurface_Release(dsurface);
2153 dsurface = NULL;
2156 /* Create an offscreen surface surface with only a width parameter */
2157 ZeroMemory(&desc, sizeof(desc));
2158 desc.dwSize = sizeof(desc);
2159 desc.dwFlags = DDSD_CAPS | DDSD_WIDTH;
2160 desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
2161 desc.dwWidth = 128;
2162 ret = IDirectDraw_CreateSurface(lpDD, &desc, &dsurface, NULL);
2163 ok(ret == DDERR_INVALIDPARAMS, "Creating an offscreen plain surface without hight info returned %08x\n", ret);
2164 if(dsurface)
2166 IDirectDrawSurface_Release(dsurface);
2167 dsurface = NULL;
2170 /* Create an offscreen surface surface with only a height parameter */
2171 ZeroMemory(&desc, sizeof(desc));
2172 desc.dwSize = sizeof(desc);
2173 desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT;
2174 desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
2175 desc.dwHeight = 128;
2176 ret = IDirectDraw_CreateSurface(lpDD, &desc, &dsurface, NULL);
2177 ok(ret == DDERR_INVALIDPARAMS, "Creating an offscreen plain surface without width info returned %08x\n", ret);
2178 if(dsurface)
2180 IDirectDrawSurface_Release(dsurface);
2181 dsurface = NULL;
2184 /* Sanity check */
2185 ZeroMemory(&desc, sizeof(desc));
2186 desc.dwSize = sizeof(desc);
2187 desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
2188 desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
2189 desc.dwHeight = 128;
2190 desc.dwWidth = 128;
2191 ret = IDirectDraw_CreateSurface(lpDD, &desc, &dsurface, NULL);
2192 ok(ret == DD_OK, "Creating an offscreen plain surface with width and height info returned %08x\n", ret);
2193 if(dsurface)
2195 IDirectDrawSurface_Release(dsurface);
2196 dsurface = NULL;
2199 /* Test a primary surface size */
2200 ret = IDirectDraw_SetCooperativeLevel(lpDD, window, DDSCL_NORMAL);
2201 ok(ret == DD_OK, "SetCooperativeLevel failed with %08x\n", ret);
2203 ZeroMemory(&desc, sizeof(desc));
2204 desc.dwSize = sizeof(desc);
2205 desc.dwFlags = DDSD_CAPS;
2206 desc.ddsCaps.dwCaps |= DDSCAPS_PRIMARYSURFACE;
2207 desc.dwHeight = 128; /* Keep them set to check what happens */
2208 desc.dwWidth = 128; /* Keep them set to check what happens */
2209 ret = IDirectDraw_CreateSurface(lpDD, &desc, &dsurface, NULL);
2210 ok(ret == DD_OK, "Creating a primary surface without width and height info returned %08x\n", ret);
2211 if(dsurface)
2213 ret = IDirectDrawSurface_GetSurfaceDesc(dsurface, &desc);
2214 ok(ret == DD_OK, "GetSurfaceDesc returned %x\n", ret);
2216 IDirectDrawSurface_Release(dsurface);
2217 dsurface = NULL;
2219 ok(desc.dwFlags & DDSD_WIDTH, "Primary surface doesn't have width set\n");
2220 ok(desc.dwFlags & DDSD_HEIGHT, "Primary surface doesn't have height set\n");
2221 ok(desc.dwWidth == GetSystemMetrics(SM_CXSCREEN), "Surface width differs from screen width\n");
2222 ok(desc.dwHeight == GetSystemMetrics(SM_CYSCREEN), "Surface height differs from screen height\n");
2224 ret = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_NORMAL);
2225 ok(ret == DD_OK, "SetCooperativeLevel failed with %08x\n", ret);
2228 static void PrivateDataTest(void)
2230 HRESULT hr;
2231 IDirectDrawSurface7 *surface7 = NULL;
2232 IDirectDrawSurface *surface = NULL;
2233 DDSURFACEDESC desc;
2234 ULONG ref, ref2;
2235 IUnknown *ptr;
2236 DWORD size = sizeof(IUnknown *);
2238 ZeroMemory(&desc, sizeof(desc));
2239 desc.dwSize = sizeof(desc);
2240 desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
2241 desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
2242 desc.dwHeight = 128;
2243 desc.dwWidth = 128;
2244 hr = IDirectDraw_CreateSurface(lpDD, &desc, &surface, NULL);
2245 ok(hr == DD_OK, "Creating an offscreen plain surface failed with %08x\n", hr);
2246 if(!surface)
2248 return;
2250 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirectDrawSurface7, (void **) &surface7);
2251 ok(hr == DD_OK, "IDirectDrawSurface_QueryInterface failed with %08x\n", hr);
2252 if(!surface7)
2254 IDirectDrawSurface_Release(surface);
2255 return;
2258 /* This fails */
2259 hr = IDirectDrawSurface7_SetPrivateData(surface7, &IID_IDirectDrawSurface7 /* Abuse this tag */, lpDD, 0, DDSPD_IUNKNOWNPOINTER);
2260 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr);
2261 hr = IDirectDrawSurface7_SetPrivateData(surface7, &IID_IDirectDrawSurface7 /* Abuse this tag */, lpDD, 5, DDSPD_IUNKNOWNPOINTER);
2262 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr);
2263 hr = IDirectDrawSurface7_SetPrivateData(surface7, &IID_IDirectDrawSurface7 /* Abuse this tag */, lpDD, sizeof(IUnknown *) * 2, DDSPD_IUNKNOWNPOINTER);
2264 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr);
2266 ref = getref((IUnknown *) lpDD);
2267 hr = IDirectDrawSurface7_SetPrivateData(surface7, &IID_IDirectDrawSurface7 /* Abuse this tag */, lpDD, sizeof(IUnknown *), DDSPD_IUNKNOWNPOINTER);
2268 ok(hr == DD_OK, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr);
2269 ref2 = getref((IUnknown *) lpDD);
2270 ok(ref2 == ref + 1, "Object reference is %d, expected %d\n", ref2, ref + 1);
2271 hr = IDirectDrawSurface7_FreePrivateData(surface7, &IID_IDirectDrawSurface7);
2272 ref2 = getref((IUnknown *) lpDD);
2273 ok(ref2 == ref, "Object reference is %d, expected %d\n", ref2, ref);
2275 hr = IDirectDrawSurface7_SetPrivateData(surface7, &IID_IDirectDrawSurface7, lpDD, sizeof(IUnknown *), DDSPD_IUNKNOWNPOINTER);
2276 ok(hr == DD_OK, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr);
2277 hr = IDirectDrawSurface7_SetPrivateData(surface7, &IID_IDirectDrawSurface7, surface7, sizeof(IUnknown *), DDSPD_IUNKNOWNPOINTER);
2278 ok(hr == DD_OK, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr);
2279 ref2 = getref((IUnknown *) lpDD);
2280 ok(ref2 == ref, "Object reference is %d, expected %d\n", ref2, ref);
2282 hr = IDirectDrawSurface7_SetPrivateData(surface7, &IID_IDirectDrawSurface7, lpDD, sizeof(IUnknown *), DDSPD_IUNKNOWNPOINTER);
2283 ok(hr == DD_OK, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr);
2284 hr = IDirectDrawSurface7_GetPrivateData(surface7, &IID_IDirectDrawSurface7, &ptr, &size);
2285 ok(hr == DD_OK, "IDirectDrawSurface7_GetPrivateData failed with %08x\n", hr);
2286 ref2 = getref((IUnknown *) lpDD);
2287 /* Object is NOT being addrefed */
2288 ok(ptr == (IUnknown *) lpDD, "Returned interface pointer is %p, expected %p\n", ptr, lpDD);
2289 ok(ref2 == ref + 1, "Object reference is %d, expected %d. ptr at %p, orig at %p\n", ref2, ref + 1, ptr, lpDD);
2291 IDirectDrawSurface_Release(surface);
2292 IDirectDrawSurface7_Release(surface7);
2294 /* Destroying the surface frees the held reference */
2295 ref2 = getref((IUnknown *) lpDD);
2296 ok(ref2 == ref, "Object reference is %d, expected %d\n", ref2, ref);
2299 static void BltParamTest(void)
2301 IDirectDrawSurface *surface1 = NULL, *surface2 = NULL;
2302 DDSURFACEDESC desc;
2303 HRESULT hr;
2304 DDBLTFX BltFx;
2305 RECT valid = {10, 10, 20, 20};
2306 RECT invalid1 = {20, 10, 10, 20};
2307 RECT invalid2 = {20, 20, 20, 20};
2308 RECT invalid3 = {-1, -1, 20, 20};
2309 RECT invalid4 = {60, 60, 70, 70};
2311 memset(&desc, 0, sizeof(desc));
2312 desc.dwSize = sizeof(desc);
2313 desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
2314 desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
2315 desc.dwHeight = 128;
2316 desc.dwWidth = 128;
2317 hr = IDirectDraw_CreateSurface(lpDD, &desc, &surface1, NULL);
2318 ok(hr == DD_OK, "Creating an offscreen plain surface failed with %08x\n", hr);
2320 desc.dwHeight = 64;
2321 desc.dwWidth = 64;
2322 hr = IDirectDraw_CreateSurface(lpDD, &desc, &surface2, NULL);
2323 ok(hr == DD_OK, "Creating an offscreen plain surface failed with %08x\n", hr);
2325 if(0)
2327 /* This crashes */
2328 hr = IDirectDrawSurface_BltFast(surface1, 0, 0, NULL, NULL, 0);
2329 ok(hr == DD_OK, "BltFast from NULL surface returned %08x\n", hr);
2331 hr = IDirectDrawSurface_BltFast(surface1, 0, 0, surface2, NULL, 0);
2332 ok(hr == DD_OK, "BltFast from smaller to bigger surface returned %08x\n", hr);
2333 hr = IDirectDrawSurface_BltFast(surface2, 0, 0, surface1, NULL, 0);
2334 ok(hr == DDERR_INVALIDRECT, "BltFast from bigger to smaller surface returned %08x\n", hr);
2335 hr = IDirectDrawSurface_BltFast(surface2, 0, 0, surface1, &valid, 0);
2336 ok(hr == DD_OK, "BltFast from bigger to smaller surface using a valid rectangle returned %08x\n", hr);
2337 hr = IDirectDrawSurface_BltFast(surface2, 60, 60, surface1, &valid, 0);
2338 ok(hr == DDERR_INVALIDRECT, "BltFast with a rectangle resulting in an off-surface write returned %08x\n", hr);
2339 hr = IDirectDrawSurface_BltFast(surface1, 90, 90, surface2, NULL, 0);
2340 ok(hr == DDERR_INVALIDRECT, "BltFast with a rectangle resulting in an off-surface write returned %08x\n", hr);
2341 hr = IDirectDrawSurface_BltFast(surface2, 0, 0, surface1, &invalid1, 0);
2342 ok(hr == DDERR_INVALIDRECT, "BltFast with invalid rectangle 1 returned %08x\n", hr);
2343 hr = IDirectDrawSurface_BltFast(surface2, 0, 0, surface1, &invalid2, 0);
2344 ok(hr == DDERR_INVALIDRECT, "BltFast with invalid rectangle 2 returned %08x\n", hr);
2345 hr = IDirectDrawSurface_BltFast(surface2, 0, 0, surface1, &invalid3, 0);
2346 ok(hr == DDERR_INVALIDRECT, "BltFast with invalid rectangle 3 returned %08x\n", hr);
2347 hr = IDirectDrawSurface_BltFast(surface1, 0, 0, surface2, &invalid4, 0);
2348 ok(hr == DDERR_INVALIDRECT, "BltFast with invalid rectangle 3 returned %08x\n", hr);
2349 hr = IDirectDrawSurface_BltFast(surface1, 0, 0, surface1, NULL, 0);
2350 ok(hr == DD_OK, "BltFast blitting a surface onto itself returned %08x\n", hr);
2352 /* Blt(non-fast) tests */
2353 memset(&BltFx, 0, sizeof(BltFx));
2354 BltFx.dwSize = sizeof(BltFx);
2355 U5(BltFx).dwFillColor = 0xaabbccdd;
2357 hr = IDirectDrawSurface_Blt(surface1, &valid, NULL, NULL, DDBLT_COLORFILL, &BltFx);
2358 ok(hr == DD_OK, "IDirectDrawSurface_Blt with a valid rectangle for color fill returned %08x\n", hr);
2359 hr = IDirectDrawSurface_Blt(surface1, &valid, NULL, &invalid3, DDBLT_COLORFILL, &BltFx);
2360 ok(hr == DD_OK, "IDirectDrawSurface_Blt with a invalid, unused rectangle returned %08x\n", hr);
2361 hr = IDirectDrawSurface_Blt(surface2, &invalid1, NULL, NULL, DDBLT_COLORFILL, &BltFx);
2362 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 1 returned %08x\n", hr);
2363 hr = IDirectDrawSurface_Blt(surface2, &invalid2, NULL, NULL, DDBLT_COLORFILL, &BltFx);
2364 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 2 returned %08x\n", hr);
2365 hr = IDirectDrawSurface_Blt(surface2, &invalid3, NULL, NULL, DDBLT_COLORFILL, &BltFx);
2366 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 3 returned %08x\n", hr);
2367 hr = IDirectDrawSurface_Blt(surface2, &invalid4, NULL, NULL, DDBLT_COLORFILL, &BltFx);
2368 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 4 returned %08x\n", hr);
2370 /* Valid on surface 1 */
2371 hr = IDirectDrawSurface_Blt(surface1, &invalid4, NULL, NULL, DDBLT_COLORFILL, &BltFx);
2372 ok(hr == DD_OK, "IDirectDrawSurface_Blt with a subrectangle fill returned %08x\n", hr);
2374 /* Works - stretched blit */
2375 hr = IDirectDrawSurface_Blt(surface1, NULL, surface2, NULL, 0, NULL);
2376 ok(hr == DD_OK, "IDirectDrawSurface_Blt from a smaller to a bigger surface returned %08x\n", hr);
2377 hr = IDirectDrawSurface_Blt(surface2, NULL, surface1, NULL, 0, NULL);
2378 ok(hr == DD_OK, "IDirectDrawSurface_Blt from a bigger to a smaller surface %08x\n", hr);
2380 /* Invalid dest rects in sourced blits */
2381 hr = IDirectDrawSurface_Blt(surface2, &invalid1, surface1, NULL, 0, NULL);
2382 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 1 returned %08x\n", hr);
2383 hr = IDirectDrawSurface_Blt(surface2, &invalid2, surface1, NULL, 0, NULL);
2384 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 2 returned %08x\n", hr);
2385 hr = IDirectDrawSurface_Blt(surface2, &invalid3, surface1, NULL, 0, NULL);
2386 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 3 returned %08x\n", hr);
2387 hr = IDirectDrawSurface_Blt(surface2, &invalid4, surface1, NULL, 0, NULL);
2388 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 4 returned %08x\n", hr);
2390 /* Invalid src rects */
2391 hr = IDirectDrawSurface_Blt(surface2, NULL, surface1, &invalid1, 0, NULL);
2392 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 1 returned %08x\n", hr);
2393 hr = IDirectDrawSurface_Blt(surface2, NULL, surface1, &invalid2, 0, NULL);
2394 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 2 returned %08x\n", hr);
2395 hr = IDirectDrawSurface_Blt(surface2, NULL, surface1, &invalid3, 0, NULL);
2396 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 3 returned %08x\n", hr);
2397 hr = IDirectDrawSurface_Blt(surface1, NULL, surface2, &invalid4, 0, NULL);
2398 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 4 returned %08x\n", hr);
2400 IDirectDrawSurface_Release(surface1);
2401 IDirectDrawSurface_Release(surface2);
2404 static void PaletteTest(void)
2406 HRESULT hr;
2407 LPDIRECTDRAWSURFACE lpSurf = NULL;
2408 DDSURFACEDESC ddsd;
2409 IDirectDrawPalette *palette = NULL;
2410 PALETTEENTRY Table[256];
2411 PALETTEENTRY palEntries[256];
2412 int i;
2414 for(i=0; i<256; i++)
2416 Table[i].peRed = 0xff;
2417 Table[i].peGreen = 0;
2418 Table[i].peBlue = 0;
2419 Table[i].peFlags = 0;
2422 /* Create a 8bit palette without DDPCAPS_ALLOW256 set */
2423 hr = IDirectDraw_CreatePalette(lpDD, DDPCAPS_8BIT, Table, &palette, NULL);
2424 ok(hr == DD_OK, "CreatePalette failed with %08x\n", hr);
2425 if (FAILED(hr)) goto err;
2426 /* Read back the palette and verify the entries. Without DDPCAPS_ALLOW256 set
2427 / entry 0 and 255 should have been overwritten with black and white */
2428 IDirectDrawPalette_GetEntries(palette , 0, 0, 256, &palEntries[0]);
2429 ok(hr == DD_OK, "GetEntries failed with %08x\n", hr);
2430 if(hr == DD_OK)
2432 ok((palEntries[0].peRed == 0) && (palEntries[0].peGreen == 0) && (palEntries[0].peBlue == 0),
2433 "Palette entry 0 of a palette without DDPCAPS_ALLOW256 set should be (0,0,0) but it is (%d,%d,%d)\n",
2434 palEntries[0].peRed, palEntries[0].peGreen, palEntries[0].peBlue);
2435 ok((palEntries[255].peRed == 255) && (palEntries[255].peGreen == 255) && (palEntries[255].peBlue == 255),
2436 "Palette entry 255 of a palette without DDPCAPS_ALLOW256 set should be (255,255,255) but it is (%d,%d,%d)\n",
2437 palEntries[255].peRed, palEntries[255].peGreen, palEntries[255].peBlue);
2439 /* Entry 1-254 should contain red */
2440 for(i=1; i<255; i++)
2441 ok((palEntries[i].peRed == 255) && (palEntries[i].peGreen == 0) && (palEntries[i].peBlue == 0),
2442 "Palette entry %d should have contained (255,0,0) but was set to %d,%d,%d)\n",
2443 i, palEntries[i].peRed, palEntries[i].peGreen, palEntries[i].peBlue);
2446 /* CreatePalette without DDPCAPS_ALLOW256 ignores entry 0 and 255,
2447 / now check we are able to update the entries afterwards. */
2448 IDirectDrawPalette_SetEntries(palette , 0, 0, 256, &Table[0]);
2449 ok(hr == DD_OK, "SetEntries failed with %08x\n", hr);
2450 IDirectDrawPalette_GetEntries(palette , 0, 0, 256, &palEntries[0]);
2451 ok(hr == DD_OK, "GetEntries failed with %08x\n", hr);
2452 if(hr == DD_OK)
2454 ok((palEntries[0].peRed == 0) && (palEntries[0].peGreen == 0) && (palEntries[0].peBlue == 0),
2455 "Palette entry 0 should have been set to (0,0,0) but it contains (%d,%d,%d)\n",
2456 palEntries[0].peRed, palEntries[0].peGreen, palEntries[0].peBlue);
2457 ok((palEntries[255].peRed == 255) && (palEntries[255].peGreen == 255) && (palEntries[255].peBlue == 255),
2458 "Palette entry 255 should have been set to (255,255,255) but it contains (%d,%d,%d)\n",
2459 palEntries[255].peRed, palEntries[255].peGreen, palEntries[255].peBlue);
2461 IDirectDrawPalette_Release(palette);
2463 /* Create a 8bit palette with DDPCAPS_ALLOW256 set */
2464 hr = IDirectDraw_CreatePalette(lpDD, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, Table, &palette, NULL);
2465 ok(hr == DD_OK, "CreatePalette failed with %08x\n", hr);
2466 if (FAILED(hr)) goto err;
2468 IDirectDrawPalette_GetEntries(palette , 0, 0, 256, &palEntries[0]);
2469 ok(hr == DD_OK, "GetEntries failed with %08x\n", hr);
2470 if(hr == DD_OK)
2472 /* All entries should contain red */
2473 for(i=0; i<256; i++)
2474 ok((palEntries[i].peRed == 255) && (palEntries[i].peGreen == 0) && (palEntries[i].peBlue == 0),
2475 "Palette entry %d should have contained (255,0,0) but was set to %d,%d,%d)\n",
2476 i, palEntries[i].peRed, palEntries[i].peGreen, palEntries[i].peBlue);
2479 /* Try to set palette to a non-palettized surface */
2480 ddsd.dwSize = sizeof(ddsd);
2481 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
2482 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
2483 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
2484 ddsd.dwWidth = 800;
2485 ddsd.dwHeight = 600;
2486 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
2487 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 32;
2488 U2(ddsd.ddpfPixelFormat).dwRBitMask = 0xFF0000;
2489 U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x00FF00;
2490 U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x0000FF;
2491 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpSurf, NULL);
2492 ok(hr==DD_OK, "CreateSurface returned: %x\n",hr);
2493 if (FAILED(hr)) {
2494 skip("failed to create surface\n");
2495 goto err;
2498 hr = IDirectDrawSurface_SetPalette(lpSurf, palette);
2499 ok(hr == DDERR_INVALIDPIXELFORMAT, "CreateSurface returned: %x\n",hr);
2501 IDirectDrawPalette_Release(palette);
2502 palette = NULL;
2504 hr = IDirectDrawSurface_GetPalette(lpSurf, &palette);
2505 ok(hr == DDERR_NOPALETTEATTACHED, "CreateSurface returned: %x\n",hr);
2507 err:
2509 if (lpSurf) IDirectDrawSurface_Release(lpSurf);
2510 if (palette) IDirectDrawPalette_Release(palette);
2513 static void StructSizeTest(void)
2515 IDirectDrawSurface *surface1;
2516 IDirectDrawSurface7 *surface7;
2517 union {
2518 DDSURFACEDESC desc1;
2519 DDSURFACEDESC2 desc2;
2520 char blob[1024]; /* To get a bunch of writable memory */
2521 } desc;
2522 DDSURFACEDESC create;
2523 HRESULT hr;
2525 memset(&desc, 0, sizeof(desc));
2526 memset(&create, 0, sizeof(create));
2528 memset(&create, 0, sizeof(create));
2529 create.dwSize = sizeof(create);
2530 create.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
2531 create.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
2532 create.dwHeight = 128;
2533 create.dwWidth = 128;
2534 hr = IDirectDraw_CreateSurface(lpDD, &create, &surface1, NULL);
2535 ok(hr == DD_OK, "Creating an offscreen plain surface failed with %08x\n", hr);
2536 hr = IDirectDrawSurface_QueryInterface(surface1, &IID_IDirectDrawSurface7, (void **) &surface7);
2537 ok(hr == DD_OK, "IDirectDrawSurface_QueryInterface failed with %08x\n", hr);
2539 desc.desc1.dwSize = sizeof(DDSURFACEDESC);
2540 hr = IDirectDrawSurface_GetSurfaceDesc(surface1, &desc.desc1);
2541 ok(hr == DD_OK, "IDirectDrawSurface_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC) returned %08x\n", hr);
2542 hr = IDirectDrawSurface7_GetSurfaceDesc(surface7, &desc.desc2);
2543 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC) returned %08x\n", hr);
2545 desc.desc2.dwSize = sizeof(DDSURFACEDESC2);
2546 hr = IDirectDrawSurface_GetSurfaceDesc(surface1, &desc.desc1);
2547 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC2) returned %08x\n", hr);
2548 hr = IDirectDrawSurface7_GetSurfaceDesc(surface7, &desc.desc2);
2549 ok(hr == DD_OK, "IDirectDrawSurface7_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC2) returned %08x\n", hr);
2551 desc.desc2.dwSize = 0;
2552 hr = IDirectDrawSurface_GetSurfaceDesc(surface1, &desc.desc1);
2553 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface_GetSurfaceDesc with desc size 0 returned %08x\n", hr);
2554 hr = IDirectDrawSurface7_GetSurfaceDesc(surface7, &desc.desc2);
2555 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_GetSurfaceDesc with desc size 0 returned %08x\n", hr);
2557 desc.desc1.dwSize = sizeof(DDSURFACEDESC) + 1;
2558 hr = IDirectDrawSurface_GetSurfaceDesc(surface1, &desc.desc1);
2559 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC) + 1 returned %08x\n", hr);
2560 hr = IDirectDrawSurface7_GetSurfaceDesc(surface7, &desc.desc2);
2561 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC) + 1 returned %08x\n", hr);
2563 desc.desc2.dwSize = sizeof(DDSURFACEDESC2) + 1;
2564 hr = IDirectDrawSurface_GetSurfaceDesc(surface1, &desc.desc1);
2565 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC2) + 1returned %08x\n", hr);
2566 hr = IDirectDrawSurface7_GetSurfaceDesc(surface7, &desc.desc2);
2567 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC2) + 1returned %08x\n", hr);
2569 /* Tests for Lock() */
2571 desc.desc1.dwSize = sizeof(DDSURFACEDESC);
2572 hr = IDirectDrawSurface_Lock(surface1, NULL, &desc.desc1, 0, 0);
2573 ok(hr == DD_OK, "IDirectDrawSurface_Lock with desc size sizeof(DDSURFACEDESC) returned %08x\n", hr);
2574 if(SUCCEEDED(hr)) IDirectDrawSurface_Unlock(surface1, NULL);
2575 ok(desc.desc1.dwSize == sizeof(DDSURFACEDESC), "Destination size was changed to %d\n", desc.desc1.dwSize);
2576 hr = IDirectDrawSurface7_Lock(surface7, NULL, &desc.desc2, 0, 0);
2577 ok(hr == DD_OK, "IDirectDrawSurface7_Lock with desc size sizeof(DDSURFACEDESC) returned %08x\n", hr);
2578 if(SUCCEEDED(hr)) IDirectDrawSurface7_Unlock(surface7, NULL);
2579 ok(desc.desc2.dwSize == sizeof(DDSURFACEDESC), "Destination size was changed to %d\n", desc.desc1.dwSize);
2581 desc.desc2.dwSize = sizeof(DDSURFACEDESC2);
2582 hr = IDirectDrawSurface_Lock(surface1, NULL, &desc.desc1, 0, 0);
2583 ok(hr == DD_OK, "IDirectDrawSurface_Lock with desc size sizeof(DDSURFACEDESC2) returned %08x\n", hr);
2584 ok(desc.desc1.dwSize == sizeof(DDSURFACEDESC2), "Destination size was changed to %d\n", desc.desc1.dwSize);
2585 if(SUCCEEDED(hr)) IDirectDrawSurface_Unlock(surface1, NULL);
2586 hr = IDirectDrawSurface7_Lock(surface7, NULL, &desc.desc2, 0, 0);
2587 ok(hr == DD_OK, "IDirectDrawSurface7_Lock with desc size sizeof(DDSURFACEDESC2) returned %08x\n", hr);
2588 if(SUCCEEDED(hr)) IDirectDrawSurface7_Unlock(surface7, NULL);
2589 ok(desc.desc2.dwSize == sizeof(DDSURFACEDESC2), "Destination size was changed to %d\n", desc.desc1.dwSize);
2591 desc.desc2.dwSize = 0;
2592 hr = IDirectDrawSurface_Lock(surface1, NULL, &desc.desc1, 0, 0);
2593 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface_Lock with desc size 0 returned %08x\n", hr);
2594 if(SUCCEEDED(hr)) IDirectDrawSurface_Unlock(surface1, NULL);
2595 hr = IDirectDrawSurface7_Lock(surface7, NULL, &desc.desc2, 0, 0);
2596 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_Lock with desc size 0 returned %08x\n", hr);
2597 if(SUCCEEDED(hr)) IDirectDrawSurface7_Unlock(surface7, NULL);
2599 desc.desc1.dwSize = sizeof(DDSURFACEDESC) + 1;
2600 hr = IDirectDrawSurface_Lock(surface1, NULL, &desc.desc1, 0, 0);
2601 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface_Lock with desc size sizeof(DDSURFACEDESC) + 1 returned %08x\n", hr);
2602 if(SUCCEEDED(hr)) IDirectDrawSurface_Unlock(surface1, NULL);
2603 hr = IDirectDrawSurface7_Lock(surface7, NULL, &desc.desc2, 0, 0);
2604 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_Lock with desc size sizeof(DDSURFACEDESC) + 1 returned %08x\n", hr);
2605 if(SUCCEEDED(hr)) IDirectDrawSurface7_Unlock(surface7, NULL);
2607 desc.desc2.dwSize = sizeof(DDSURFACEDESC2) + 1;
2608 hr = IDirectDrawSurface_Lock(surface1, NULL, &desc.desc1, 0, 0);
2609 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface_Lock with desc size sizeof(DDSURFACEDESC2) + 1returned %08x\n", hr);
2610 if(SUCCEEDED(hr)) IDirectDrawSurface_Unlock(surface1, NULL);
2611 hr = IDirectDrawSurface7_Lock(surface7, NULL, &desc.desc2, 0, 0);
2612 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_Lock with desc size sizeof(DDSURFACEDESC2) + 1returned %08x\n", hr);
2613 if(SUCCEEDED(hr)) IDirectDrawSurface7_Unlock(surface7, NULL);
2615 IDirectDrawSurface7_Release(surface7);
2616 IDirectDrawSurface_Release(surface1);
2619 static void SurfaceCapsTest(void)
2621 DDSURFACEDESC create;
2622 DDSURFACEDESC desc;
2623 HRESULT hr;
2624 IDirectDrawSurface *surface1 = NULL;
2625 DDSURFACEDESC2 create2, desc2;
2626 IDirectDrawSurface7 *surface7 = NULL;
2627 IDirectDraw7 *dd7 = NULL;
2628 DWORD create_caps[] = {
2629 DDSCAPS_OFFSCREENPLAIN,
2630 DDSCAPS_TEXTURE,
2631 DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD,
2633 DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD | DDSCAPS_SYSTEMMEMORY,
2634 DDSCAPS_PRIMARYSURFACE,
2635 DDSCAPS_PRIMARYSURFACE | DDSCAPS_SYSTEMMEMORY
2637 DWORD expected_caps[] = {
2638 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
2639 DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
2640 DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM | DDSCAPS_ALLOCONLOAD,
2641 DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
2642 DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD | DDSCAPS_SYSTEMMEMORY,
2643 DDSCAPS_PRIMARYSURFACE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM | DDSCAPS_VISIBLE,
2644 DDSCAPS_PRIMARYSURFACE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_VISIBLE
2646 UINT i;
2647 DDCAPS ddcaps;
2649 /* Tests various surface flags, what changes do they undergo during surface creation. Forsaken
2650 * engine expects texture surfaces without memory flag to get a video memory flag right after
2651 * creation. Currently, Wine adds DDSCAPS_FRONTBUFFER to primary surface, but native doesn't do this
2652 * for single buffered primaries. Because of this primary surface creation tests are todo_wine. No real
2653 * app is known so far to care about this. */
2654 ddcaps.dwSize = sizeof(DDCAPS);
2655 hr = IDirectDraw_GetCaps(lpDD, &ddcaps, NULL);
2656 ok(hr == DD_OK, "IDirectDraw_GetCaps failed with %08x\n", hr);
2658 if (!(ddcaps.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY))
2660 skip("DDraw reported no VIDEOMEMORY cap. Broken video driver? Skipping surface caps tests.\n");
2661 return ;
2664 for (i = 0; i < sizeof(create_caps) / sizeof(DWORD); i++)
2666 memset(&create, 0, sizeof(create));
2667 create.dwSize = sizeof(create);
2668 create.ddsCaps.dwCaps = create_caps[i];
2669 create.dwFlags = DDSD_CAPS;
2671 if (!(create.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE))
2673 create.dwFlags |= DDSD_HEIGHT | DDSD_WIDTH;
2674 create.dwHeight = 128;
2675 create.dwWidth = 128;
2678 hr = IDirectDraw_CreateSurface(lpDD, &create, &surface1, NULL);
2679 ok(hr == DD_OK, "IDirectDraw_CreateSurface failed with %08x\n", hr);
2681 if (SUCCEEDED(hr))
2683 memset(&desc, 0, sizeof(desc));
2684 desc.dwSize = sizeof(DDSURFACEDESC);
2685 hr = IDirectDrawSurface_GetSurfaceDesc(surface1, &desc);
2686 ok(hr == DD_OK, "IDirectDrawSurface_GetSurfaceDesc failed with %08x\n", hr);
2688 if (!(create_caps[i] & DDSCAPS_PRIMARYSURFACE))
2689 ok(desc.ddsCaps.dwCaps == expected_caps[i],
2690 "GetSurfaceDesc returned caps %x, expected %x\n", desc.ddsCaps.dwCaps,
2691 expected_caps[i]);
2692 else
2693 todo_wine ok(desc.ddsCaps.dwCaps == expected_caps[i],
2694 "GetSurfaceDesc returned caps %x, expected %x\n", desc.ddsCaps.dwCaps,
2695 expected_caps[i]);
2697 IDirectDrawSurface_Release(surface1);
2701 /* Test for differences in ddraw 7 */
2702 hr = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
2703 ok(hr == DD_OK, "IDirectDraw_QueryInterface returned %08x\n", hr);
2704 if (FAILED(hr))
2706 skip("Failed to get IDirectDraw7 interface, skipping tests\n");
2708 else
2710 for (i = 0; i < sizeof(create_caps) / sizeof(DWORD); i++)
2712 memset(&create2, 0, sizeof(create2));
2713 create2.dwSize = sizeof(create2);
2714 create2.ddsCaps.dwCaps = create_caps[i];
2715 create2.dwFlags = DDSD_CAPS;
2717 if (!(create2.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE))
2719 create2.dwFlags |= DDSD_HEIGHT | DDSD_WIDTH;
2720 create2.dwHeight = 128;
2721 create2.dwWidth = 128;
2724 hr = IDirectDraw7_CreateSurface(dd7, &create2, &surface7, NULL);
2725 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
2727 if (SUCCEEDED(hr))
2729 memset(&desc2, 0, sizeof(desc2));
2730 desc2.dwSize = sizeof(DDSURFACEDESC2);
2731 hr = IDirectDrawSurface7_GetSurfaceDesc(surface7, &desc2);
2732 ok(hr == DD_OK, "IDirectDrawSurface_GetSurfaceDesc failed with %08x\n", hr);
2734 if (!(create_caps[i] & DDSCAPS_PRIMARYSURFACE))
2735 ok(desc2.ddsCaps.dwCaps == expected_caps[i],
2736 "GetSurfaceDesc returned caps %x, expected %x\n", desc2.ddsCaps.dwCaps,
2737 expected_caps[i]);
2738 else
2739 todo_wine ok(desc2.ddsCaps.dwCaps == expected_caps[i],
2740 "GetSurfaceDesc returned caps %x, expected %x\n", desc2.ddsCaps.dwCaps,
2741 expected_caps[i]);
2743 IDirectDrawSurface7_Release(surface7);
2747 IDirectDraw7_Release(dd7);
2751 static BOOL can_create_primary_surface(void)
2753 DDSURFACEDESC ddsd;
2754 IDirectDrawSurface *surface;
2755 HRESULT hr;
2757 memset(&ddsd, 0, sizeof(ddsd));
2758 ddsd.dwSize = sizeof(ddsd);
2759 ddsd.dwFlags = DDSD_CAPS;
2760 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2761 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface, NULL);
2762 if(FAILED(hr)) return FALSE;
2763 IDirectDrawSurface_Release(surface);
2764 return TRUE;
2767 START_TEST(dsurface)
2769 HRESULT ret;
2770 IDirectDraw4 *dd4;
2772 if (!CreateDirectDraw())
2773 return;
2775 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw4, (void **) &dd4);
2776 if (ret == E_NOINTERFACE)
2778 win_skip("DirectDraw4 and higher are not supported\n");
2779 ReleaseDirectDraw();
2780 return;
2782 IDirectDraw_Release(dd4);
2784 if(!can_create_primary_surface())
2786 skip("Unable to create primary surface\n");
2787 return;
2790 MipMapCreationTest();
2791 SrcColorKey32BlitTest();
2792 QueryInterface();
2793 GetDDInterface_1();
2794 GetDDInterface_2();
2795 GetDDInterface_4();
2796 GetDDInterface_7();
2797 EnumTest();
2798 AttachmentTest();
2799 AttachmentTest7();
2800 CubeMapTest();
2801 test_lockrect_invalid();
2802 CompressedTest();
2803 SizeTest();
2804 PrivateDataTest();
2805 BltParamTest();
2806 StructSizeTest();
2807 PaletteTest();
2808 SurfaceCapsTest();
2809 ReleaseDirectDraw();