d3d: Add a test for double surface locking.
[wine/wine64.git] / dlls / ddraw / tests / dsurface.c
blob6c223f4e85446ab8246e1e9bdc6511c16e0fd36f
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
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #define COBJMACROS
25 #include <assert.h>
26 #include "wine/test.h"
27 #include "ddraw.h"
28 #include "unknwn.h"
30 static LPDIRECTDRAW lpDD = NULL;
32 static BOOL CreateDirectDraw(void)
34 HRESULT rc;
36 rc = DirectDrawCreate(NULL, &lpDD, NULL);
37 ok(rc==DD_OK || rc==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreateEx returned: %x\n", rc);
38 if (!lpDD) {
39 trace("DirectDrawCreateEx() failed with an error %x\n", rc);
40 return FALSE;
43 rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_NORMAL);
44 ok(rc==DD_OK,"SetCooperativeLevel returned: %x\n",rc);
46 return TRUE;
50 static void ReleaseDirectDraw(void)
52 if( lpDD != NULL )
54 IDirectDraw_Release(lpDD);
55 lpDD = NULL;
59 static void MipMapCreationTest(void)
61 LPDIRECTDRAWSURFACE lpDDSMipMapTest;
62 DDSURFACEDESC ddsd;
63 HRESULT rc;
65 /* First mipmap creation test: create a surface with DDSCAPS_COMPLEX,
66 DDSCAPS_MIPMAP, and DDSD_MIPMAPCOUNT. This create the number of
67 requested mipmap levels. */
68 ddsd.dwSize = sizeof(ddsd);
69 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_MIPMAPCOUNT;
70 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
71 U2(ddsd).dwMipMapCount = 3;
72 ddsd.dwWidth = 128;
73 ddsd.dwHeight = 32;
74 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpDDSMipMapTest, NULL);
75 ok(rc==DD_OK,"CreateSurface returned: %x\n",rc);
76 if (FAILED(rc)) {
77 skip("failed to create surface\n");
78 return;
81 /* Check the number of created mipmaps */
82 memset(&ddsd, 0, sizeof(DDSURFACEDESC));
83 ddsd.dwSize = sizeof(ddsd);
84 rc = IDirectDrawSurface_GetSurfaceDesc(lpDDSMipMapTest, &ddsd);
85 ok(rc==DD_OK,"GetSurfaceDesc returned: %x\n",rc);
86 ok(ddsd.dwFlags & DDSD_MIPMAPCOUNT,
87 "GetSurfaceDesc returned no mipmapcount.\n");
88 ok(U2(ddsd).dwMipMapCount == 3, "Incorrect mipmap count: %d.\n",
89 U2(ddsd).dwMipMapCount);
91 /* Destroy the surface. */
92 IDirectDrawSurface_Release(lpDDSMipMapTest);
95 /* Second mipmap creation test: create a surface without a mipmap
96 count, with DDSCAPS_MIPMAP and without DDSCAPS_COMPLEX.
97 This creates a single mipmap level. */
98 memset(&ddsd, 0, sizeof(DDSURFACEDESC));
99 ddsd.dwSize = sizeof(ddsd);
100 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
101 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_MIPMAP;
102 ddsd.dwWidth = 128;
103 ddsd.dwHeight = 32;
104 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpDDSMipMapTest, NULL);
105 ok(rc==DD_OK,"CreateSurface returned: %x\n",rc);
106 if (FAILED(rc)) {
107 skip("failed to create surface\n");
108 return;
110 /* Check the number of created mipmaps */
111 memset(&ddsd, 0, sizeof(DDSURFACEDESC));
112 ddsd.dwSize = sizeof(ddsd);
113 rc = IDirectDrawSurface_GetSurfaceDesc(lpDDSMipMapTest, &ddsd);
114 ok(rc==DD_OK,"GetSurfaceDesc returned: %x\n",rc);
115 ok(ddsd.dwFlags & DDSD_MIPMAPCOUNT,
116 "GetSurfaceDesc returned no mipmapcount.\n");
117 ok(U2(ddsd).dwMipMapCount == 1, "Incorrect mipmap count: %d.\n",
118 U2(ddsd).dwMipMapCount);
120 /* Destroy the surface. */
121 IDirectDrawSurface_Release(lpDDSMipMapTest);
124 /* Third mipmap creation test: create a surface with DDSCAPS_MIPMAP,
125 DDSCAPS_COMPLEX and without DDSD_MIPMAPCOUNT.
126 It's an undocumented features where a chain of mipmaps, starting from
127 he specified size and down to the smallest size, is automatically
128 created.
129 Anarchy Online needs this feature to work. */
130 memset(&ddsd, 0, sizeof(DDSURFACEDESC));
131 ddsd.dwSize = sizeof(ddsd);
132 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
133 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
134 ddsd.dwWidth = 128;
135 ddsd.dwHeight = 32;
136 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpDDSMipMapTest, NULL);
137 ok(rc==DD_OK,"CreateSurface returned: %x\n",rc);
138 if (FAILED(rc)) {
139 skip("failed to create surface\n");
140 return;
143 /* Check the number of created mipmaps */
144 memset(&ddsd, 0, sizeof(DDSURFACEDESC));
145 ddsd.dwSize = sizeof(ddsd);
146 rc = IDirectDrawSurface_GetSurfaceDesc(lpDDSMipMapTest, &ddsd);
147 ok(rc==DD_OK,"GetSurfaceDesc returned: %x\n",rc);
148 ok(ddsd.dwFlags & DDSD_MIPMAPCOUNT,
149 "GetSurfaceDesc returned no mipmapcount.\n");
150 ok(U2(ddsd).dwMipMapCount == 6, "Incorrect mipmap count: %d.\n",
151 U2(ddsd).dwMipMapCount);
153 /* Destroy the surface. */
154 IDirectDrawSurface_Release(lpDDSMipMapTest);
157 /* Fourth mipmap creation test: same as above with a different texture
158 size.
159 The purpose is to verify that the number of generated mipmaps is
160 dependent on the smallest dimension. */
161 memset(&ddsd, 0, sizeof(DDSURFACEDESC));
162 ddsd.dwSize = sizeof(ddsd);
163 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
164 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
165 ddsd.dwWidth = 32;
166 ddsd.dwHeight = 64;
167 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpDDSMipMapTest, NULL);
168 ok(rc==DD_OK,"CreateSurface returned: %x\n",rc);
169 if (FAILED(rc)) {
170 skip("failed to create surface\n");
171 return;
174 /* Check the number of created mipmaps */
175 memset(&ddsd, 0, sizeof(DDSURFACEDESC));
176 ddsd.dwSize = sizeof(ddsd);
177 rc = IDirectDrawSurface_GetSurfaceDesc(lpDDSMipMapTest, &ddsd);
178 ok(rc==DD_OK,"GetSurfaceDesc returned: %x\n",rc);
179 ok(ddsd.dwFlags & DDSD_MIPMAPCOUNT,
180 "GetSurfaceDesc returned no mipmapcount.\n");
181 ok(U2(ddsd).dwMipMapCount == 6, "Incorrect mipmap count: %d.\n",
182 U2(ddsd).dwMipMapCount);
184 /* Destroy the surface. */
185 IDirectDrawSurface_Release(lpDDSMipMapTest);
188 static void SrcColorKey32BlitTest(void)
190 LPDIRECTDRAWSURFACE lpSrc;
191 LPDIRECTDRAWSURFACE lpDst;
192 DDSURFACEDESC ddsd, ddsd2, ddsd3;
193 DDCOLORKEY DDColorKey;
194 LPDWORD lpData;
195 HRESULT rc;
196 DDBLTFX fx;
198 ddsd2.dwSize = sizeof(ddsd2);
199 ddsd2.ddpfPixelFormat.dwSize = sizeof(ddsd2.ddpfPixelFormat);
201 ddsd.dwSize = sizeof(ddsd);
202 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
203 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
204 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
205 ddsd.dwWidth = 800;
206 ddsd.dwHeight = 600;
207 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
208 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 32;
209 U2(ddsd.ddpfPixelFormat).dwRBitMask = 0xFF0000;
210 U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x00FF00;
211 U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x0000FF;
212 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpDst, NULL);
213 ok(rc==DD_OK,"CreateSurface returned: %x\n",rc);
214 if (FAILED(rc)) {
215 skip("failed to create surface\n");
216 return;
219 ddsd.dwFlags |= DDSD_CKSRCBLT;
220 ddsd.ddckCKSrcBlt.dwColorSpaceLowValue = 0xFF00FF;
221 ddsd.ddckCKSrcBlt.dwColorSpaceHighValue = 0xFF00FF;
222 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpSrc, NULL);
223 ok(rc==DD_OK,"CreateSurface returned: %x\n",rc);
224 if (FAILED(rc)) {
225 skip("failed to create surface\n");
226 return;
229 rc = IDirectDrawSurface_Lock(lpDst, NULL, &ddsd2, DDLOCK_WAIT, NULL);
230 ok(rc==DD_OK,"Lock returned: %x\n",rc);
231 lpData = (LPDWORD)ddsd2.lpSurface;
232 lpData[0] = 0xCCCCCCCC;
233 lpData[1] = 0xCCCCCCCC;
234 lpData[2] = 0xCCCCCCCC;
235 lpData[3] = 0xCCCCCCCC;
237 memset(&ddsd3, 0, sizeof(ddsd3));
238 ddsd3.dwSize = sizeof(ddsd3);
239 ddsd3.ddpfPixelFormat.dwSize = sizeof(ddsd3.ddpfPixelFormat);
240 rc = IDirectDrawSurface_GetSurfaceDesc(lpDst, &ddsd3);
241 ok(rc == DD_OK, "IDirectDrawSurface_GetSurfaceDesc between a lock/unlock pair returned %08x\n", rc);
242 ok(ddsd3.lpSurface == ddsd3.lpSurface, "lpSurface from GetSurfaceDesc(%p) differs from the one returned by Lock(%p)\n", ddsd3.lpSurface, ddsd2.lpSurface);
244 rc = IDirectDrawSurface_Unlock(lpDst, NULL);
245 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
247 memset(&ddsd3, 0, sizeof(ddsd3));
248 ddsd3.dwSize = sizeof(ddsd3);
249 ddsd3.ddpfPixelFormat.dwSize = sizeof(ddsd3.ddpfPixelFormat);
250 rc = IDirectDrawSurface_GetSurfaceDesc(lpDst, &ddsd3);
251 ok(rc == DD_OK, "IDirectDrawSurface_GetSurfaceDesc between a lock/unlock pair returned %08x\n", rc);
252 ok(ddsd3.lpSurface == NULL, "lpSurface from GetSurfaceDesc(%p) is not NULL after unlock\n", ddsd3.lpSurface);
254 rc = IDirectDrawSurface_Lock(lpSrc, NULL, &ddsd2, DDLOCK_WAIT, NULL);
255 ok(rc==DD_OK,"Lock returned: %x\n",rc);
256 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
257 lpData = (LPDWORD)ddsd2.lpSurface;
258 lpData[0] = 0x77010203;
259 lpData[1] = 0x00010203;
260 lpData[2] = 0x77FF00FF;
261 lpData[3] = 0x00FF00FF;
262 rc = IDirectDrawSurface_Unlock(lpSrc, NULL);
263 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
265 IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYSRC, NULL);
267 rc = IDirectDrawSurface_Lock(lpDst, NULL, &ddsd2, DDLOCK_WAIT, NULL);
268 ok(rc==DD_OK,"Lock returned: %x\n",rc);
269 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
270 lpData = (LPDWORD)ddsd2.lpSurface;
271 ok((lpData[0]==0x77010203)&&(lpData[1]==0x00010203)&&(lpData[2]==0xCCCCCCCC)&&(lpData[3]==0xCCCCCCCC),
272 "Destination data after blitting is not correct\n");
273 rc = IDirectDrawSurface_Unlock(lpDst, NULL);
274 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
276 /* Also test SetColorKey */
277 IDirectDrawSurface_GetColorKey(lpSrc, DDCKEY_SRCBLT, &DDColorKey);
278 ok(DDColorKey.dwColorSpaceLowValue == 0xFF00FF && DDColorKey.dwColorSpaceHighValue == 0xFF00FF,
279 "GetColorKey does not return the colorkey used at surface creation\n");
281 DDColorKey.dwColorSpaceLowValue = 0x00FF00;
282 DDColorKey.dwColorSpaceHighValue = 0x00FF00;
283 IDirectDrawSurface_SetColorKey(lpSrc, DDCKEY_SRCBLT, &DDColorKey);
285 DDColorKey.dwColorSpaceLowValue = 0;
286 DDColorKey.dwColorSpaceHighValue = 0;
287 IDirectDrawSurface_GetColorKey(lpSrc, DDCKEY_SRCBLT, &DDColorKey);
288 ok(DDColorKey.dwColorSpaceLowValue == 0x00FF00 && DDColorKey.dwColorSpaceHighValue == 0x00FF00,
289 "GetColorKey does not return the colorkey set with SetColorKey\n");
291 ddsd.ddckCKSrcBlt.dwColorSpaceLowValue = 0;
292 ddsd.ddckCKSrcBlt.dwColorSpaceHighValue = 0;
293 IDirectDrawSurface_GetSurfaceDesc(lpSrc, &ddsd);
294 ok(ddsd.ddckCKSrcBlt.dwColorSpaceLowValue == 0x00FF00 && ddsd.ddckCKSrcBlt.dwColorSpaceHighValue == 0x00FF00,
295 "GetSurfaceDesc does not return the colorkey set with SetColorKey\n");
297 IDirectDrawSurface_Release(lpSrc);
298 IDirectDrawSurface_Release(lpDst);
300 /* start with a new set of surfaces to test the color keying parameters to blit */
301 memset(&ddsd, 0, sizeof(ddsd));
302 ddsd.dwSize = sizeof(ddsd);
303 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
304 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CKSRCBLT | DDSD_CKDESTBLT;
305 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
306 ddsd.dwWidth = 800;
307 ddsd.dwHeight = 600;
308 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
309 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 32;
310 U2(ddsd.ddpfPixelFormat).dwRBitMask = 0xFF0000;
311 U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x00FF00;
312 U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x0000FF;
313 ddsd.ddckCKDestBlt.dwColorSpaceLowValue = 0xFF0000;
314 ddsd.ddckCKDestBlt.dwColorSpaceHighValue = 0xFF0000;
315 ddsd.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00FF00;
316 ddsd.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00FF00;
317 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpDst, NULL);
318 ok(rc==DD_OK || rc == DDERR_NOCOLORKEYHW,"CreateSurface returned: %x\n",rc);
319 if(FAILED(rc))
321 skip("Failed to create surface\n");
322 return;
325 /* start with a new set of surfaces to test the color keying parameters to blit */
326 memset(&ddsd, 0, sizeof(ddsd));
327 ddsd.dwSize = sizeof(ddsd);
328 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
329 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CKSRCBLT | DDSD_CKDESTBLT;
330 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
331 ddsd.dwWidth = 800;
332 ddsd.dwHeight = 600;
333 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
334 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 32;
335 U2(ddsd.ddpfPixelFormat).dwRBitMask = 0xFF0000;
336 U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x00FF00;
337 U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x0000FF;
338 ddsd.ddckCKSrcBlt.dwColorSpaceLowValue = 0x0000FF;
339 ddsd.ddckCKSrcBlt.dwColorSpaceHighValue = 0x0000FF;
340 ddsd.ddckCKDestBlt.dwColorSpaceLowValue = 0x000000;
341 ddsd.ddckCKDestBlt.dwColorSpaceHighValue = 0x000000;
342 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpSrc, NULL);
343 ok(rc==DD_OK || rc == DDERR_NOCOLORKEYHW,"CreateSurface returned: %x\n",rc);
344 if(FAILED(rc))
346 skip("Failed to create surface\n");
347 IDirectDrawSurface_Release(lpDst);
348 return;
351 memset(&fx, 0, sizeof(fx));
352 fx.dwSize = sizeof(fx);
353 fx.ddckSrcColorkey.dwColorSpaceHighValue = 0x110000;
354 fx.ddckSrcColorkey.dwColorSpaceLowValue = 0x110000;
355 fx.ddckDestColorkey.dwColorSpaceHighValue = 0x001100;
356 fx.ddckDestColorkey.dwColorSpaceLowValue = 0x001100;
358 rc = IDirectDrawSurface_Lock(lpSrc, NULL, &ddsd2, DDLOCK_WAIT, NULL);
359 ok(rc==DD_OK,"Lock returned: %x\n",rc);
360 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
361 lpData = (LPDWORD)ddsd2.lpSurface;
362 lpData[0] = 0x000000FF; /* Applies to src blt key in src surface */
363 lpData[1] = 0x00000000; /* Applies to dst blt key in src surface */
364 lpData[2] = 0x00FF0000; /* Dst color key in dst surface */
365 lpData[3] = 0x0000FF00; /* Src color key in dst surface */
366 lpData[4] = 0x00001100; /* Src color key in ddbltfx */
367 lpData[5] = 0x00110000; /* Dst color key in ddbltfx */
368 rc = IDirectDrawSurface_Unlock(lpSrc, NULL);
369 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
371 rc = IDirectDrawSurface_Lock(lpDst, NULL, &ddsd2, DDLOCK_WAIT, NULL);
372 ok(rc==DD_OK,"Lock returned: %x\n",rc);
373 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
374 lpData = (LPDWORD)ddsd2.lpSurface;
375 lpData[0] = 0x55555555;
376 lpData[1] = 0x55555555;
377 lpData[2] = 0x55555555;
378 lpData[3] = 0x55555555;
379 lpData[4] = 0x55555555;
380 lpData[5] = 0x55555555;
381 rc = IDirectDrawSurface_Unlock(lpDst, NULL);
382 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
384 /* Test a blit without keying */
385 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, 0, &fx);
386 ok(rc == DD_OK, "IDirectDrawSurface_Blt returned %08x\n", rc);
388 rc = IDirectDrawSurface_Lock(lpDst, 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 /* Should have copied src data unmodified to dst */
393 ok(lpData[0] == 0x000000FF &&
394 lpData[1] == 0x00000000 &&
395 lpData[2] == 0x00FF0000 &&
396 lpData[3] == 0x0000FF00 &&
397 lpData[4] == 0x00001100 &&
398 lpData[5] == 0x00110000, "Surface data after unkeyed blit does not match\n");
400 lpData[0] = 0x55555555;
401 lpData[1] = 0x55555555;
402 lpData[2] = 0x55555555;
403 lpData[3] = 0x55555555;
404 lpData[4] = 0x55555555;
405 lpData[5] = 0x55555555;
406 rc = IDirectDrawSurface_Unlock(lpDst, NULL);
407 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
409 /* Src key */
410 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYSRC, &fx);
411 ok(rc == DD_OK, "IDirectDrawSurface_Blt returned %08x\n", rc);
413 rc = IDirectDrawSurface_Lock(lpDst, NULL, &ddsd2, DDLOCK_WAIT, NULL);
414 ok(rc==DD_OK,"Lock returned: %x\n",rc);
415 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
416 lpData = (LPDWORD)ddsd2.lpSurface;
418 ok(lpData[0] == 0x55555555 && /* Here the src key applied */
419 lpData[1] == 0x00000000 &&
420 lpData[2] == 0x00FF0000 &&
421 lpData[3] == 0x0000FF00 &&
422 lpData[4] == 0x00001100 &&
423 lpData[5] == 0x00110000, "Surface data after srckey blit does not match\n");
425 lpData[0] = 0x55555555;
426 lpData[1] = 0x55555555;
427 lpData[2] = 0x55555555;
428 lpData[3] = 0x55555555;
429 lpData[4] = 0x55555555;
430 lpData[5] = 0x55555555;
431 rc = IDirectDrawSurface_Unlock(lpDst, NULL);
432 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
434 /* Src override */
435 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYSRCOVERRIDE, &fx);
436 ok(rc == DD_OK, "IDirectDrawSurface_Blt returned %08x\n", rc);
438 rc = IDirectDrawSurface_Lock(lpDst, NULL, &ddsd2, DDLOCK_WAIT, NULL);
439 ok(rc==DD_OK,"Lock returned: %x\n",rc);
440 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
441 lpData = (LPDWORD)ddsd2.lpSurface;
443 ok(lpData[0] == 0x000000FF &&
444 lpData[1] == 0x00000000 &&
445 lpData[2] == 0x00FF0000 &&
446 lpData[3] == 0x0000FF00 &&
447 lpData[4] == 0x00001100 &&
448 lpData[5] == 0x55555555, /* Override key applies here */
449 "Surface data after src override key blit does not match\n");
451 lpData[0] = 0x55555555;
452 lpData[1] = 0x55555555;
453 lpData[2] = 0x55555555;
454 lpData[3] = 0x55555555;
455 lpData[4] = 0x55555555;
456 lpData[5] = 0x55555555;
457 rc = IDirectDrawSurface_Unlock(lpDst, NULL);
458 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
460 /* Src override AND src key. That is not supposed to work */
461 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYSRC | DDBLT_KEYSRCOVERRIDE, &fx);
462 ok(rc == DDERR_INVALIDPARAMS, "IDirectDrawSurface_Blt returned %08x\n", rc);
464 /* Verify that the destination is unchanged */
465 rc = IDirectDrawSurface_Lock(lpDst, NULL, &ddsd2, DDLOCK_WAIT, NULL);
466 ok(rc==DD_OK,"Lock returned: %x\n",rc);
467 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
468 lpData = (LPDWORD)ddsd2.lpSurface;
470 ok(lpData[0] == 0x55555555 &&
471 lpData[1] == 0x55555555 &&
472 lpData[2] == 0x55555555 &&
473 lpData[3] == 0x55555555 &&
474 lpData[4] == 0x55555555 &&
475 lpData[5] == 0x55555555, /* Override key applies here */
476 "Surface data after src key blit with override does not match\n");
478 lpData[0] = 0x00FF0000; /* Dest key in dst surface */
479 lpData[1] = 0x00FF0000; /* Dest key in dst surface */
480 lpData[2] = 0x00001100; /* Dest key in override */
481 lpData[3] = 0x00001100; /* Dest key in override */
482 lpData[4] = 0x00000000; /* Dest key in src surface */
483 lpData[5] = 0x00000000; /* Dest key in src surface */
484 rc = IDirectDrawSurface_Unlock(lpDst, NULL);
485 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
487 /* Dest key blit */
488 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYDEST, &fx);
489 ok(rc == DD_OK, "IDirectDrawSurface_Blt returned %08x\n", rc);
491 rc = IDirectDrawSurface_Lock(lpDst, NULL, &ddsd2, DDLOCK_WAIT, NULL);
492 ok(rc==DD_OK,"Lock returned: %x\n",rc);
493 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
494 lpData = (LPDWORD)ddsd2.lpSurface;
496 /* DirectDraw uses the dest blit key from the SOURCE surface ! */
497 ok(lpData[0] == 0x00ff0000 &&
498 lpData[1] == 0x00ff0000 &&
499 lpData[2] == 0x00001100 &&
500 lpData[3] == 0x00001100 &&
501 lpData[4] == 0x00001100 && /* Key applies here */
502 lpData[5] == 0x00110000, /* Key applies here */
503 "Surface data after dest key blit does not match\n");
505 lpData[0] = 0x00FF0000; /* Dest key in dst surface */
506 lpData[1] = 0x00FF0000; /* Dest key in dst surface */
507 lpData[2] = 0x00001100; /* Dest key in override */
508 lpData[3] = 0x00001100; /* Dest key in override */
509 lpData[4] = 0x00000000; /* Dest key in src surface */
510 lpData[5] = 0x00000000; /* Dest key in src surface */
511 rc = IDirectDrawSurface_Unlock(lpDst, NULL);
512 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
514 /* Dest override key blit */
515 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYDESTOVERRIDE, &fx);
516 ok(rc == DD_OK, "IDirectDrawSurface_Blt returned %08x\n", rc);
518 rc = IDirectDrawSurface_Lock(lpDst, NULL, &ddsd2, DDLOCK_WAIT, NULL);
519 ok(rc==DD_OK,"Lock returned: %x\n",rc);
520 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
521 lpData = (LPDWORD)ddsd2.lpSurface;
523 ok(lpData[0] == 0x00FF0000 &&
524 lpData[1] == 0x00FF0000 &&
525 lpData[2] == 0x00FF0000 && /* Key applies here */
526 lpData[3] == 0x0000FF00 && /* Key applies here */
527 lpData[4] == 0x00000000 &&
528 lpData[5] == 0x00000000,
529 "Surface data after dest key override blit does not match\n");
531 lpData[0] = 0x00FF0000; /* Dest key in dst surface */
532 lpData[1] = 0x00FF0000; /* Dest key in dst surface */
533 lpData[2] = 0x00001100; /* Dest key in override */
534 lpData[3] = 0x00001100; /* Dest key in override */
535 lpData[4] = 0x00000000; /* Dest key in src surface */
536 lpData[5] = 0x00000000; /* Dest key in src surface */
537 rc = IDirectDrawSurface_Unlock(lpDst, NULL);
538 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
540 /* Dest override key blit. Supposed to fail too */
541 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYDEST | DDBLT_KEYDESTOVERRIDE, &fx);
542 ok(rc == DDERR_INVALIDPARAMS, "IDirectDrawSurface_Blt returned %08x\n", rc);
544 /* Check for unchanged data */
545 rc = IDirectDrawSurface_Lock(lpDst, NULL, &ddsd2, DDLOCK_WAIT, NULL);
546 ok(rc==DD_OK,"Lock returned: %x\n",rc);
547 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
548 lpData = (LPDWORD)ddsd2.lpSurface;
550 ok(lpData[0] == 0x00FF0000 &&
551 lpData[1] == 0x00FF0000 &&
552 lpData[2] == 0x00001100 && /* Key applies here */
553 lpData[3] == 0x00001100 && /* Key applies here */
554 lpData[4] == 0x00000000 &&
555 lpData[5] == 0x00000000,
556 "Surface data with dest key and dest override does not match\n");
558 lpData[0] = 0x00FF0000; /* Dest key in dst surface */
559 lpData[1] = 0x00FF0000; /* Dest key in dst surface */
560 lpData[2] = 0x00001100; /* Dest key in override */
561 lpData[3] = 0x00001100; /* Dest key in override */
562 lpData[4] = 0x00000000; /* Dest key in src surface */
563 lpData[5] = 0x00000000; /* Dest key in src surface */
564 rc = IDirectDrawSurface_Unlock(lpDst, NULL);
565 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
567 /* Modify the source data a bit to give some more conclusive results */
568 rc = IDirectDrawSurface_Lock(lpSrc, NULL, &ddsd2, DDLOCK_WAIT, NULL);
569 ok(rc==DD_OK,"Lock returned: %x\n",rc);
570 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
571 lpData = (LPDWORD)ddsd2.lpSurface;
572 lpData[5] = 0x000000FF; /* Applies to src blt key in src surface */
573 rc = IDirectDrawSurface_Unlock(lpSrc, NULL);
574 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
576 /* Source and destination key */
577 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYDEST | DDBLT_KEYSRC, &fx);
578 ok(rc == DD_OK, "IDirectDrawSurface_Blt returned %08x\n", rc);
580 rc = IDirectDrawSurface_Lock(lpDst, NULL, &ddsd2, DDLOCK_WAIT, NULL);
581 ok(rc==DD_OK,"Lock returned: %x\n",rc);
582 ok((ddsd2.dwFlags & DDSD_LPSURFACE) == 0, "Surface desc has LPSURFACE Flags set\n");
583 lpData = (LPDWORD)ddsd2.lpSurface;
585 ok(lpData[0] == 0x00FF0000 && /* Masked by Destination key */
586 lpData[1] == 0x00FF0000 && /* Masked by Destination key */
587 lpData[2] == 0x00001100 && /* Masked by Destination key */
588 lpData[3] == 0x00001100 && /* Masked by Destination key */
589 lpData[4] == 0x00001100 && /* Allowed by destination key, not masked by source key */
590 lpData[5] == 0x00000000, /* Allowed by dst key, but masked by source key */
591 "Surface data with src key and dest key blit does not match\n");
593 lpData[0] = 0x00FF0000; /* Dest key in dst surface */
594 lpData[1] = 0x00FF0000; /* Dest key in dst surface */
595 lpData[2] = 0x00001100; /* Dest key in override */
596 lpData[3] = 0x00001100; /* Dest key in override */
597 lpData[4] = 0x00000000; /* Dest key in src surface */
598 lpData[5] = 0x00000000; /* Dest key in src surface */
599 rc = IDirectDrawSurface_Unlock(lpDst, NULL);
600 ok(rc==DD_OK,"Unlock returned: %x\n",rc);
602 /* Override keys without ddbltfx parameter fail */
603 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYDESTOVERRIDE, NULL);
604 ok(rc == DDERR_INVALIDPARAMS, "IDirectDrawSurface_Blt returned %08x\n", rc);
605 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYSRCOVERRIDE, NULL);
606 ok(rc == DDERR_INVALIDPARAMS, "IDirectDrawSurface_Blt returned %08x\n", rc);
608 /* Try blitting without keys in the source surface*/
609 rc = IDirectDrawSurface_SetColorKey(lpSrc, DDCKEY_SRCBLT, NULL);
610 ok(rc == DD_OK, "SetColorKey returned %x\n", rc);
611 rc = IDirectDrawSurface_SetColorKey(lpSrc, DDCKEY_DESTBLT, NULL);
612 ok(rc == DD_OK, "SetColorKey returned %x\n", rc);
614 /* That fails now. Do not bother to check that the data is unmodified */
615 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYSRC, &fx);
616 ok(rc == DDERR_INVALIDPARAMS, "IDirectDrawSurface_Blt returned %08x\n", rc);
618 /* Dest key blit still works. Which key is used this time??? */
619 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYDEST, &fx);
620 ok(rc == DD_OK, "IDirectDrawSurface_Blt returned %08x\n", rc);
622 /* With korrectly passed override keys no key in the surface is needed.
623 * Again, the result was checked before, no need to do that again
625 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYDESTOVERRIDE, &fx);
626 ok(rc == DD_OK, "IDirectDrawSurface_Blt returned %08x\n", rc);
627 rc = IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYSRCOVERRIDE, &fx);
628 ok(rc == DD_OK, "IDirectDrawSurface_Blt returned %08x\n", rc);
630 IDirectDrawSurface_Release(lpSrc);
631 IDirectDrawSurface_Release(lpDst);
634 static void QueryInterface(void)
636 LPDIRECTDRAWSURFACE dsurface;
637 DDSURFACEDESC surface;
638 LPVOID object;
639 HRESULT ret;
641 /* Create a surface */
642 ZeroMemory(&surface, sizeof(surface));
643 surface.dwSize = sizeof(surface);
644 surface.dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
645 surface.dwHeight = 10;
646 surface.dwWidth = 10;
647 ret = IDirectDraw_CreateSurface(lpDD, &surface, &dsurface, NULL);
648 if(ret != DD_OK)
650 ok(FALSE, "IDirectDraw::CreateSurface failed with error %x\n", ret);
651 return;
654 /* Call IUnknown::QueryInterface */
655 ret = IDirectDrawSurface_QueryInterface(dsurface, 0, &object);
656 ok(ret == DDERR_INVALIDPARAMS, "IDirectDrawSurface::QueryInterface returned %x\n", ret);
658 IDirectDrawSurface_Release(dsurface);
661 /* The following tests test which interface is returned by IDirectDrawSurfaceX::GetDDInterface.
662 * It uses refcounts to test that and compares the interface addresses. Partially fits here, and
663 * partially in the refcount test
666 static unsigned long getref(IUnknown *iface)
668 IUnknown_AddRef(iface);
669 return IUnknown_Release(iface);
672 static void GetDDInterface_1(void)
674 LPDIRECTDRAWSURFACE dsurface;
675 LPDIRECTDRAWSURFACE2 dsurface2;
676 DDSURFACEDESC surface;
677 HRESULT ret;
678 IDirectDraw2 *dd2;
679 IDirectDraw4 *dd4;
680 IDirectDraw7 *dd7;
681 unsigned long ref1, ref2, ref4, ref7;
682 void *dd;
684 /* Create a surface */
685 ZeroMemory(&surface, sizeof(surface));
686 surface.dwSize = sizeof(surface);
687 surface.dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
688 surface.dwHeight = 10;
689 surface.dwWidth = 10;
690 ret = IDirectDraw_CreateSurface(lpDD, &surface, &dsurface, NULL);
691 if(ret != DD_OK)
693 ok(FALSE, "IDirectDraw::CreateSurface failed with error %x\n", ret);
694 return;
696 ret = IDirectDrawSurface_QueryInterface(dsurface, &IID_IDirectDrawSurface2, (void **) &dsurface2);
697 ok(ret == DD_OK, "IDirectDrawSurface_QueryInterface returned %08x\n", ret);
698 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw2, (void **) &dd2);
699 ok(ret == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", ret);
700 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw4, (void **) &dd4);
701 ok(ret == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", ret);
702 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
703 ok(ret == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", ret);
705 ref1 = getref((IUnknown *) lpDD);
706 ok(ref1 == 1, "IDirectDraw refcount is %ld\n", ref1);
707 ref2 = getref((IUnknown *) dd2);
708 ok(ref2 == 1, "IDirectDraw2 refcount is %ld\n", ref2);
709 ref4 = getref((IUnknown *) dd4);
710 ok(ref4 == 1, "IDirectDraw4 refcount is %ld\n", ref4);
711 ref7 = getref((IUnknown *) dd7);
712 ok(ref7 == 1, "IDirectDraw7 refcount is %ld\n", ref7);
715 ret = IDirectDrawSurface2_GetDDInterface(dsurface2, &dd);
716 ok(ret == DD_OK, "IDirectDrawSurface7_GetDDInterface returned %08x\n", ret);
717 ok(getref((IUnknown *) lpDD) == ref1 + 1, "IDirectDraw refcount was increased by %ld\n", getref((IUnknown *) lpDD) - ref1);
718 ok(getref((IUnknown *) dd2) == ref2 + 0, "IDirectDraw2 refcount was increased by %ld\n", getref((IUnknown *) dd2) - ref2);
719 ok(getref((IUnknown *) dd4) == ref4 + 0, "IDirectDraw4 refcount was increased by %ld\n", getref((IUnknown *) dd4) - ref4);
720 ok(getref((IUnknown *) dd7) == ref7 + 0, "IDirectDraw7 refcount was increased by %ld\n", getref((IUnknown *) dd7) - ref7);
722 ok(dd == lpDD, "Returned interface pointer is not equal to the creation interface\n");
723 IUnknown_Release((IUnknown *) dd);
725 /* try a NULL pointer */
726 ret = IDirectDrawSurface2_GetDDInterface(dsurface2, NULL);
727 ok(ret == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_GetDDInterface returned %08x\n", ret);
729 IDirectDraw_Release(dd2);
730 IDirectDraw_Release(dd4);
731 IDirectDraw_Release(dd7);
732 IDirectDrawSurface2_Release(dsurface2);
733 IDirectDrawSurface_Release(dsurface);
736 static void GetDDInterface_2(void)
738 LPDIRECTDRAWSURFACE dsurface;
739 LPDIRECTDRAWSURFACE2 dsurface2;
740 DDSURFACEDESC surface;
741 HRESULT ret;
742 IDirectDraw2 *dd2;
743 IDirectDraw4 *dd4;
744 IDirectDraw7 *dd7;
745 unsigned long ref1, ref2, ref4, ref7;
746 void *dd;
748 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw2, (void **) &dd2);
749 ok(ret == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", ret);
750 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw4, (void **) &dd4);
751 ok(ret == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", ret);
752 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
753 ok(ret == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", ret);
755 /* Create a surface */
756 ZeroMemory(&surface, sizeof(surface));
757 surface.dwSize = sizeof(surface);
758 surface.dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
759 surface.dwHeight = 10;
760 surface.dwWidth = 10;
761 ret = IDirectDraw2_CreateSurface(dd2, &surface, &dsurface, NULL);
762 if(ret != DD_OK)
764 ok(FALSE, "IDirectDraw::CreateSurface failed with error %x\n", ret);
765 return;
767 ret = IDirectDrawSurface_QueryInterface(dsurface, &IID_IDirectDrawSurface2, (void **) &dsurface2);
768 ok(ret == DD_OK, "IDirectDrawSurface_QueryInterface returned %08x\n", ret);
770 ref1 = getref((IUnknown *) lpDD);
771 ok(ref1 == 1, "IDirectDraw refcount is %ld\n", ref1);
772 ref2 = getref((IUnknown *) dd2);
773 ok(ref2 == 1, "IDirectDraw2 refcount is %ld\n", ref2);
774 ref4 = getref((IUnknown *) dd4);
775 ok(ref4 == 1, "IDirectDraw4 refcount is %ld\n", ref4);
776 ref7 = getref((IUnknown *) dd7);
777 ok(ref7 == 1, "IDirectDraw7 refcount is %ld\n", ref7);
780 ret = IDirectDrawSurface2_GetDDInterface(dsurface2, &dd);
781 ok(ret == DD_OK, "IDirectDrawSurface7_GetDDInterface returned %08x\n", ret);
782 ok(getref((IUnknown *) lpDD) == ref1 + 0, "IDirectDraw refcount was increased by %ld\n", getref((IUnknown *) lpDD) - ref1);
783 ok(getref((IUnknown *) dd2) == ref2 + 1, "IDirectDraw2 refcount was increased by %ld\n", getref((IUnknown *) dd2) - ref2);
784 ok(getref((IUnknown *) dd4) == ref4 + 0, "IDirectDraw4 refcount was increased by %ld\n", getref((IUnknown *) dd4) - ref4);
785 ok(getref((IUnknown *) dd7) == ref7 + 0, "IDirectDraw7 refcount was increased by %ld\n", getref((IUnknown *) dd7) - ref7);
787 ok(dd == dd2, "Returned interface pointer is not equal to the creation interface\n");
788 IUnknown_Release((IUnknown *) dd);
790 IDirectDraw_Release(dd2);
791 IDirectDraw_Release(dd4);
792 IDirectDraw_Release(dd7);
793 IDirectDrawSurface2_Release(dsurface2);
794 IDirectDrawSurface_Release(dsurface);
797 static void GetDDInterface_4(void)
799 LPDIRECTDRAWSURFACE2 dsurface2;
800 LPDIRECTDRAWSURFACE4 dsurface4;
801 DDSURFACEDESC2 surface;
802 HRESULT ret;
803 IDirectDraw2 *dd2;
804 IDirectDraw4 *dd4;
805 IDirectDraw7 *dd7;
806 unsigned long ref1, ref2, ref4, ref7;
807 void *dd;
809 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw2, (void **) &dd2);
810 ok(ret == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", ret);
811 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw4, (void **) &dd4);
812 ok(ret == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", ret);
813 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
814 ok(ret == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", ret);
816 /* Create a surface */
817 ZeroMemory(&surface, sizeof(surface));
818 surface.dwSize = sizeof(surface);
819 surface.dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
820 surface.dwHeight = 10;
821 surface.dwWidth = 10;
822 ret = IDirectDraw4_CreateSurface(dd4, &surface, &dsurface4, NULL);
823 if(ret != DD_OK)
825 ok(FALSE, "IDirectDraw::CreateSurface failed with error %x\n", ret);
826 return;
828 ret = IDirectDrawSurface4_QueryInterface(dsurface4, &IID_IDirectDrawSurface2, (void **) &dsurface2);
829 ok(ret == DD_OK, "IDirectDrawSurface_QueryInterface returned %08x\n", ret);
831 ref1 = getref((IUnknown *) lpDD);
832 ok(ref1 == 1, "IDirectDraw refcount is %ld\n", ref1);
833 ref2 = getref((IUnknown *) dd2);
834 ok(ref2 == 1, "IDirectDraw2 refcount is %ld\n", ref2);
835 ref4 = getref((IUnknown *) dd4);
836 ok(ref4 == 2, "IDirectDraw4 refcount is %ld\n", ref4);
837 ref7 = getref((IUnknown *) dd7);
838 ok(ref7 == 1, "IDirectDraw7 refcount is %ld\n", ref7);
840 ret = IDirectDrawSurface4_GetDDInterface(dsurface4, &dd);
841 ok(ret == DD_OK, "IDirectDrawSurface7_GetDDInterface returned %08x\n", ret);
842 ok(getref((IUnknown *) lpDD) == ref1 + 0, "IDirectDraw refcount was increased by %ld\n", getref((IUnknown *) lpDD) - ref1);
843 ok(getref((IUnknown *) dd2) == ref2 + 0, "IDirectDraw2 refcount was increased by %ld\n", getref((IUnknown *) dd2) - ref2);
844 ok(getref((IUnknown *) dd4) == ref4 + 1, "IDirectDraw4 refcount was increased by %ld\n", getref((IUnknown *) dd4) - ref4);
845 ok(getref((IUnknown *) dd7) == ref7 + 0, "IDirectDraw7 refcount was increased by %ld\n", getref((IUnknown *) dd7) - ref7);
847 ok(dd == dd4, "Returned interface pointer is not equal to the creation interface\n");
848 IUnknown_Release((IUnknown *) dd);
850 /* Now test what happens if we QI the surface for some other version - It should still return the creation interface */
851 ret = IDirectDrawSurface2_GetDDInterface(dsurface2, &dd);
852 ok(ret == DD_OK, "IDirectDrawSurface7_GetDDInterface returned %08x\n", ret);
853 ok(getref((IUnknown *) lpDD) == ref1 + 0, "IDirectDraw refcount was increased by %ld\n", getref((IUnknown *) lpDD) - ref1);
854 ok(getref((IUnknown *) dd2) == ref2 + 0, "IDirectDraw2 refcount was increased by %ld\n", getref((IUnknown *) dd2) - ref2);
855 ok(getref((IUnknown *) dd4) == ref4 + 1, "IDirectDraw4 refcount was increased by %ld\n", getref((IUnknown *) dd4) - ref4);
856 ok(getref((IUnknown *) dd7) == ref7 + 0, "IDirectDraw7 refcount was increased by %ld\n", getref((IUnknown *) dd7) - ref7);
858 ok(dd == dd4, "Returned interface pointer is not equal to the creation interface\n");
859 IUnknown_Release((IUnknown *) dd);
861 IDirectDraw_Release(dd2);
862 IDirectDraw_Release(dd4);
863 IDirectDraw_Release(dd7);
864 IDirectDrawSurface4_Release(dsurface4);
865 IDirectDrawSurface2_Release(dsurface2);
868 static void GetDDInterface_7(void)
870 LPDIRECTDRAWSURFACE4 dsurface4;
871 LPDIRECTDRAWSURFACE7 dsurface7;
872 DDSURFACEDESC2 surface;
873 HRESULT ret;
874 IDirectDraw2 *dd2;
875 IDirectDraw4 *dd4;
876 IDirectDraw7 *dd7;
877 unsigned long ref1, ref2, ref4, ref7;
878 void *dd;
880 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw2, (void **) &dd2);
881 ok(ret == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", ret);
882 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw4, (void **) &dd4);
883 ok(ret == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", ret);
884 ret = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
885 ok(ret == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", ret);
887 /* Create a surface */
888 ZeroMemory(&surface, sizeof(surface));
889 surface.dwSize = sizeof(surface);
890 surface.dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
891 surface.dwHeight = 10;
892 surface.dwWidth = 10;
893 ret = IDirectDraw7_CreateSurface(dd7, &surface, &dsurface7, NULL);
894 if(ret != DD_OK)
896 ok(FALSE, "IDirectDraw::CreateSurface failed with error %x\n", ret);
897 return;
899 ret = IDirectDrawSurface7_QueryInterface(dsurface7, &IID_IDirectDrawSurface4, (void **) &dsurface4);
900 ok(ret == DD_OK, "IDirectDrawSurface_QueryInterface returned %08x\n", ret);
902 ref1 = getref((IUnknown *) lpDD);
903 ok(ref1 == 1, "IDirectDraw refcount is %ld\n", ref1);
904 ref2 = getref((IUnknown *) dd2);
905 ok(ref2 == 1, "IDirectDraw2 refcount is %ld\n", ref2);
906 ref4 = getref((IUnknown *) dd4);
907 ok(ref4 == 1, "IDirectDraw4 refcount is %ld\n", ref4);
908 ref7 = getref((IUnknown *) dd7);
909 ok(ref7 == 2, "IDirectDraw7 refcount is %ld\n", ref7);
911 ret = IDirectDrawSurface7_GetDDInterface(dsurface7, &dd);
912 ok(ret == DD_OK, "IDirectDrawSurface7_GetDDInterface returned %08x\n", ret);
913 ok(getref((IUnknown *) lpDD) == ref1 + 0, "IDirectDraw refcount was increased by %ld\n", getref((IUnknown *) lpDD) - ref1);
914 ok(getref((IUnknown *) dd2) == ref2 + 0, "IDirectDraw2 refcount was increased by %ld\n", getref((IUnknown *) dd2) - ref2);
915 ok(getref((IUnknown *) dd4) == ref4 + 0, "IDirectDraw4 refcount was increased by %ld\n", getref((IUnknown *) dd4) - ref4);
916 ok(getref((IUnknown *) dd7) == ref7 + 1, "IDirectDraw7 refcount was increased by %ld\n", getref((IUnknown *) dd7) - ref7);
918 ok(dd == dd7, "Returned interface pointer is not equal to the creation interface\n");
919 IUnknown_Release((IUnknown *) dd);
921 /* Now test what happens if we QI the surface for some other version - It should still return the creation interface */
922 ret = IDirectDrawSurface4_GetDDInterface(dsurface4, &dd);
923 ok(ret == DD_OK, "IDirectDrawSurface7_GetDDInterface returned %08x\n", ret);
924 ok(getref((IUnknown *) lpDD) == ref1 + 0, "IDirectDraw refcount was increased by %ld\n", getref((IUnknown *) lpDD) - ref1);
925 ok(getref((IUnknown *) dd2) == ref2 + 0, "IDirectDraw2 refcount was increased by %ld\n", getref((IUnknown *) dd2) - ref2);
926 ok(getref((IUnknown *) dd4) == ref4 + 0, "IDirectDraw4 refcount was increased by %ld\n", getref((IUnknown *) dd4) - ref4);
927 ok(getref((IUnknown *) dd7) == ref7 + 1, "IDirectDraw7 refcount was increased by %ld\n", getref((IUnknown *) dd7) - ref7);
929 ok(dd == dd7, "Returned interface pointer is not equal to the creation interface\n");
930 IUnknown_Release((IUnknown *) dd);
932 IDirectDraw_Release(dd2);
933 IDirectDraw_Release(dd4);
934 IDirectDraw_Release(dd7);
935 IDirectDrawSurface4_Release(dsurface4);
936 IDirectDrawSurface7_Release(dsurface7);
939 #define MAXEXPECTED 8 /* Can match up to 8 expected surfaces */
940 struct enumstruct
942 IDirectDrawSurface *expected[MAXEXPECTED];
943 UINT count;
946 static HRESULT WINAPI enumCB(IDirectDrawSurface *surf, DDSURFACEDESC *desc, void *ctx)
948 int i;
949 BOOL found = FALSE;
951 for(i = 0; i < MAXEXPECTED; i++)
953 if(((struct enumstruct *)ctx)->expected[i] == surf) found = TRUE;
956 ok(found, "Unexpected surface %p enumerated\n", surf);
957 ((struct enumstruct *)ctx)->count++;
958 IDirectDrawSurface_Release(surf);
959 return DDENUMRET_OK;
962 static void EnumTest(void)
964 HRESULT rc;
965 DDSURFACEDESC ddsd;
966 IDirectDrawSurface *surface;
967 struct enumstruct ctx;
969 ddsd.dwSize = sizeof(ddsd);
970 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_MIPMAPCOUNT;
971 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
972 U2(ddsd).dwMipMapCount = 3;
973 ddsd.dwWidth = 32;
974 ddsd.dwHeight = 32;
975 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface, NULL);
976 ok(rc==DD_OK,"CreateSurface returned: %x\n",rc);
978 memset(&ctx, 0, sizeof(ctx));
979 ctx.expected[0] = surface;
980 rc = IDirectDrawSurface_GetAttachedSurface(ctx.expected[0], &ddsd.ddsCaps, &ctx.expected[1]);
981 ok(rc == DD_OK, "GetAttachedSurface returned %08x\n", rc);
982 rc = IDirectDrawSurface_GetAttachedSurface(ctx.expected[1], &ddsd.ddsCaps, &ctx.expected[2]);
983 ok(rc == DD_OK, "GetAttachedSurface returned %08x\n", rc);
984 rc = IDirectDrawSurface_GetAttachedSurface(ctx.expected[2], &ddsd.ddsCaps, &ctx.expected[3]);
985 ok(rc == DDERR_NOTFOUND, "GetAttachedSurface returned %08x\n", rc);
986 ctx.count = 0;
988 rc = IDirectDraw_EnumSurfaces(lpDD, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_ALL, &ddsd, (void *) &ctx, enumCB);
989 ok(rc == DD_OK, "IDirectDraw_EnumSurfaces returned %08x\n", rc);
990 ok(ctx.count == 3, "%d surfaces enumerated, expected 3\n", ctx.count);
992 IDirectDrawSurface_Release(ctx.expected[2]);
993 IDirectDrawSurface_Release(ctx.expected[1]);
994 IDirectDrawSurface_Release(surface);
997 HRESULT WINAPI SurfaceCounter(IDirectDrawSurface7 *surface, DDSURFACEDESC2 *desc, void *context)
999 UINT *num = context;
1000 (*num)++;
1001 IDirectDrawSurface_Release(surface);
1002 return DDENUMRET_OK;
1005 static void AttachmentTest7(void)
1007 HRESULT hr;
1008 IDirectDraw7 *dd7;
1009 IDirectDrawSurface7 *surface1, *surface2, *surface3, *surface4;
1010 DDSURFACEDESC2 ddsd;
1011 UINT num;
1012 DDSCAPS2 caps = {DDSCAPS_TEXTURE, 0, 0, 0};
1013 HWND window = CreateWindow( "static", "ddraw_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
1015 hr = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
1016 ok(hr == DD_OK, "IDirectDraw_QueryInterface returned %08x\n", hr);
1018 memset(&ddsd, 0, sizeof(ddsd));
1019 ddsd.dwSize = sizeof(ddsd);
1020 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_MIPMAPCOUNT;
1021 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
1022 U2(ddsd).dwMipMapCount = 3; /* Will create 128x128, 64x64, 32x32 */
1023 ddsd.dwWidth = 128;
1024 ddsd.dwHeight = 128;
1025 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface1, NULL);
1026 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1028 /* ROOT */
1029 num = 0;
1030 IDirectDrawSurface7_EnumAttachedSurfaces(surface1, &num, SurfaceCounter);
1031 ok(num == 1, "Mipmap root has %d surfaces attached, expected 1\n", num);
1032 /* DONE ROOT */
1034 /* LEVEL 1 */
1035 hr = IDirectDrawSurface7_GetAttachedSurface(surface1, &caps, &surface2);
1036 ok(hr == DD_OK, "GetAttachedSurface returned %08x\n", hr);
1037 num = 0;
1038 IDirectDrawSurface7_EnumAttachedSurfaces(surface2, &num, SurfaceCounter);
1039 ok(num == 1, "First mip level has %d surfaces attached, expected 1\n", num);
1040 /* DONE LEVEL 1 */
1042 /* LEVEL 2 */
1043 hr = IDirectDrawSurface7_GetAttachedSurface(surface2, &caps, &surface3);
1044 ok(hr == DD_OK, "GetAttachedSurface returned %08x\n", hr);
1045 IDirectDrawSurface7_Release(surface2);
1046 num = 0;
1047 IDirectDrawSurface7_EnumAttachedSurfaces(surface3, &num, SurfaceCounter);
1048 ok(num == 0, "Second mip level has %d surfaces attached, expected 1\n", num);
1049 /* Done level 2 */
1050 /* Mip level 3 is still needed */
1052 /* Try to attach a 16x16 miplevel - Should not work as far I can see */
1053 memset(&ddsd, 0, sizeof(ddsd));
1054 ddsd.dwSize = sizeof(ddsd);
1055 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1056 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1057 ddsd.dwWidth = 16;
1058 ddsd.dwHeight = 16;
1059 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface2, NULL);
1060 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1062 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface2);
1063 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 16x16 surface to a 128x128 texture root returned %08x\n", hr);
1064 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface1);
1065 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 128x128 texture root to a 16x16 texture returned %08x\n", hr);
1066 hr = IDirectDrawSurface7_AddAttachedSurface(surface3, surface2);
1067 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 16x16 surface to a 32x32 texture mip level returned %08x\n", hr);
1068 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface3);
1069 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 32x32 texture mip level to a 16x16 surface returned %08x\n", hr);
1071 IDirectDrawSurface7_Release(surface2);
1073 memset(&ddsd, 0, sizeof(ddsd));
1074 ddsd.dwSize = sizeof(ddsd);
1075 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1076 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
1077 ddsd.dwWidth = 16;
1078 ddsd.dwHeight = 16;
1079 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface2, NULL);
1080 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1082 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface2);
1083 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 16x16 offscreen plain surface to a 128x128 texture root returned %08x\n", hr);
1084 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface1);
1085 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 128x128 texture root to a 16x16 offscreen plain surface returned %08x\n", hr);
1086 hr = IDirectDrawSurface7_AddAttachedSurface(surface3, surface2);
1087 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 16x16 offscreen plain surface to a 32x32 texture mip level returned %08x\n", hr);
1088 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface3);
1089 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 32x32 texture mip level to a 16x16 offscreen plain surface returned %08x\n", hr);
1091 IDirectDrawSurface7_Release(surface3);
1092 IDirectDrawSurface7_Release(surface2);
1093 IDirectDrawSurface7_Release(surface1);
1095 hr = IDirectDraw7_SetCooperativeLevel(dd7, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
1096 ok(hr == DD_OK, "SetCooperativeLevel returned %08x\n", hr);
1098 memset(&ddsd, 0, sizeof(ddsd));
1099 ddsd.dwSize = sizeof(ddsd);
1100 ddsd.dwFlags = DDSD_BACKBUFFERCOUNT | DDSD_CAPS;
1101 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
1102 ddsd.dwBackBufferCount = 2;
1103 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface1, NULL);
1104 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1106 num = 0;
1107 IDirectDrawSurface7_EnumAttachedSurfaces(surface1, &num, SurfaceCounter);
1108 ok(num == 1, "Primary surface has %d surfaces attached, expected 1\n", num);
1109 IDirectDrawSurface7_Release(surface1);
1111 /* Those are some invalid descriptions, no need to test attachments with them */
1112 memset(&ddsd, 0, sizeof(ddsd));
1113 ddsd.dwSize = sizeof(ddsd);
1114 ddsd.dwFlags = DDSD_CAPS;
1115 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FRONTBUFFER;
1116 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface1, NULL);
1117 ok(hr==DDERR_INVALIDCAPS,"CreateSurface returned: %x\n",hr);
1118 memset(&ddsd, 0, sizeof(ddsd));
1119 ddsd.dwSize = sizeof(ddsd);
1120 ddsd.dwFlags = DDSD_CAPS;
1121 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_BACKBUFFER;
1122 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface2, NULL);
1123 ok(hr==DDERR_INVALIDCAPS,"CreateSurface returned: %x\n",hr);
1125 /* Try a single primary and two offscreen plain surfaces */
1126 memset(&ddsd, 0, sizeof(ddsd));
1127 ddsd.dwSize = sizeof(ddsd);
1128 ddsd.dwFlags = DDSD_CAPS;
1129 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
1130 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface1, NULL);
1131 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1133 memset(&ddsd, 0, sizeof(ddsd));
1134 ddsd.dwSize = sizeof(ddsd);
1135 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1136 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
1137 ddsd.dwWidth = GetSystemMetrics(SM_CXSCREEN);
1138 ddsd.dwHeight = GetSystemMetrics(SM_CYSCREEN);
1139 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface2, NULL);
1140 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1142 memset(&ddsd, 0, sizeof(ddsd));
1143 ddsd.dwSize = sizeof(ddsd);
1144 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1145 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
1146 ddsd.dwWidth = GetSystemMetrics(SM_CXSCREEN);
1147 ddsd.dwHeight = GetSystemMetrics(SM_CYSCREEN);
1148 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface3, NULL);
1149 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1151 /* This one has a different size */
1152 memset(&ddsd, 0, sizeof(ddsd));
1153 ddsd.dwSize = sizeof(ddsd);
1154 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1155 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
1156 ddsd.dwWidth = 128;
1157 ddsd.dwHeight = 128;
1158 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface4, NULL);
1159 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1161 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface2);
1162 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching an offscreen plain surface to a front buffer returned %08x\n", hr);
1163 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface1);
1164 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a front buffer to an offscreen plain surface returned %08x\n", hr);
1165 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface3);
1166 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching an offscreen plain surface to another offscreen plain surface returned %08x\n", hr);
1167 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface4);
1168 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching an offscreen plain surface to a front buffer of different size returned %08x\n", hr);
1169 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface1);
1170 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a front buffer to an offscreen plain surface of different size returned %08x\n", hr);
1172 IDirectDrawSurface7_Release(surface4);
1173 IDirectDrawSurface7_Release(surface3);
1174 IDirectDrawSurface7_Release(surface2);
1175 IDirectDrawSurface7_Release(surface1);
1177 hr =IDirectDraw7_SetCooperativeLevel(dd7, NULL, DDSCL_NORMAL);
1178 ok(hr == DD_OK, "SetCooperativeLevel returned %08x\n", hr);
1179 IDirectDraw7_Release(dd7);
1182 static void AttachmentTest(void)
1184 HRESULT hr;
1185 IDirectDrawSurface *surface1, *surface2, *surface3, *surface4;
1186 DDSURFACEDESC ddsd;
1187 DDSCAPS caps = {DDSCAPS_TEXTURE};
1188 HWND window = CreateWindow( "static", "ddraw_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
1190 memset(&ddsd, 0, sizeof(ddsd));
1191 ddsd.dwSize = sizeof(ddsd);
1192 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_MIPMAPCOUNT;
1193 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
1194 U2(ddsd).dwMipMapCount = 3; /* Will create 128x128, 64x64, 32x32 */
1195 ddsd.dwWidth = 128;
1196 ddsd.dwHeight = 128;
1197 hr = IDirectDraw7_CreateSurface(lpDD, &ddsd, &surface1, NULL);
1198 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1200 hr = IDirectDrawSurface7_GetAttachedSurface(surface1, &caps, &surface2);
1201 ok(hr == DD_OK, "GetAttachedSurface returned %08x\n", hr);
1202 hr = IDirectDrawSurface7_GetAttachedSurface(surface2, &caps, &surface3);
1203 ok(hr == DD_OK, "GetAttachedSurface returned %08x\n", hr);
1205 /* Try to attach a 16x16 miplevel - Should not work as far I can see */
1206 memset(&ddsd, 0, sizeof(ddsd));
1207 ddsd.dwSize = sizeof(ddsd);
1208 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1209 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1210 ddsd.dwWidth = 16;
1211 ddsd.dwHeight = 16;
1212 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface4, NULL);
1213 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1215 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface4);
1216 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 16x16 surface to a 128x128 texture root returned %08x\n", hr);
1217 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface1);
1218 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 128x128 texture root to a 16x16 texture returned %08x\n", hr);
1219 hr = IDirectDrawSurface7_AddAttachedSurface(surface3, surface4);
1220 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 16x16 surface to a 32x32 texture mip level returned %08x\n", hr);
1221 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface3);
1222 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 32x32 texture mip level to a 16x16 surface returned %08x\n", hr);
1223 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface4);
1224 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 16x16 surface to a 64x64 texture sublevel returned %08x\n", hr);
1225 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface2);
1226 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 64x64 texture sublevel to a 16x16 texture returned %08x\n", hr);
1228 IDirectDrawSurface7_Release(surface4);
1230 memset(&ddsd, 0, sizeof(ddsd));
1231 ddsd.dwSize = sizeof(ddsd);
1232 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1233 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
1234 ddsd.dwWidth = 16;
1235 ddsd.dwHeight = 16;
1236 hr = IDirectDraw7_CreateSurface(lpDD, &ddsd, &surface4, NULL);
1237 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1239 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface4); /* Succeeds on refrast */
1240 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 16x16 offscreen plain surface to a 128x128 texture root returned %08x\n", hr);
1241 if(SUCCEEDED(hr)) IDirectDrawSurface7_DeleteAttachedSurface(surface1, 0, surface4);
1242 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface1); /* Succeeds on refrast */
1243 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 128x128 texture root to a 16x16 offscreen plain surface returned %08x\n", hr);
1244 if(SUCCEEDED(hr)) IDirectDrawSurface7_DeleteAttachedSurface(surface1, 0, surface1);
1245 hr = IDirectDrawSurface7_AddAttachedSurface(surface3, surface4); /* Succeeds on refrast */
1246 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 16x16 offscreen plain surface to a 32x32 texture mip level returned %08x\n", hr);
1247 if(SUCCEEDED(hr)) IDirectDrawSurface7_DeleteAttachedSurface(surface3, 0, surface4);
1248 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface3);
1249 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 32x32 texture mip level to a 16x16 offscreen plain surface returned %08x\n", hr);
1250 if(SUCCEEDED(hr)) IDirectDrawSurface7_DeleteAttachedSurface(surface4, 0, surface3);
1251 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface4); /* Succeeds on refrast */
1252 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 16x16 offscreen plain surface to a 64x64 texture sublevel returned %08x\n", hr);
1253 if(SUCCEEDED(hr)) IDirectDrawSurface7_DeleteAttachedSurface(surface2, 0, surface4);
1254 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface2);
1255 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a 64x64 texture sublevel to a 16x16 offscreen plain surface returned %08x\n", hr);
1256 if(SUCCEEDED(hr)) IDirectDrawSurface7_DeleteAttachedSurface(surface4, 0, surface2);
1258 IDirectDrawSurface7_Release(surface4);
1259 IDirectDrawSurface7_Release(surface3);
1260 IDirectDrawSurface7_Release(surface2);
1261 IDirectDrawSurface7_Release(surface1);
1263 hr = IDirectDraw_SetCooperativeLevel(lpDD, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
1264 ok(hr == DD_OK, "SetCooperativeLevel returned %08x\n", hr);
1266 /* Creating a back buffer as-is, is not allowed. No need to perform attachment tests */
1267 memset(&ddsd, 0, sizeof(ddsd));
1268 ddsd.dwSize = sizeof(ddsd);
1269 ddsd.dwFlags = DDSD_CAPS;
1270 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_BACKBUFFER;
1271 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface2, NULL);
1272 ok(hr==DDERR_INVALIDCAPS,"CreateSurface returned: %x\n",hr);
1273 /* This old ddraw version happily creates explicit front buffers */
1274 memset(&ddsd, 0, sizeof(ddsd));
1275 ddsd.dwSize = sizeof(ddsd);
1276 ddsd.dwFlags = DDSD_CAPS;
1277 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FRONTBUFFER;
1278 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface1, NULL);
1279 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1280 IDirectDrawSurface_Release(surface1);
1282 /* Try a single primary and two offscreen plain surfaces */
1283 memset(&ddsd, 0, sizeof(ddsd));
1284 ddsd.dwSize = sizeof(ddsd);
1285 ddsd.dwFlags = DDSD_CAPS;
1286 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
1287 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface1, NULL);
1288 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1290 memset(&ddsd, 0, sizeof(ddsd));
1291 ddsd.dwSize = sizeof(ddsd);
1292 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1293 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
1294 ddsd.dwWidth = GetSystemMetrics(SM_CXSCREEN);
1295 ddsd.dwHeight = GetSystemMetrics(SM_CYSCREEN);
1296 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface2, NULL);
1297 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1299 memset(&ddsd, 0, sizeof(ddsd));
1300 ddsd.dwSize = sizeof(ddsd);
1301 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1302 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
1303 ddsd.dwWidth = GetSystemMetrics(SM_CXSCREEN);
1304 ddsd.dwHeight = GetSystemMetrics(SM_CYSCREEN);
1305 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface3, NULL);
1306 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1308 /* This one has a different size */
1309 memset(&ddsd, 0, sizeof(ddsd));
1310 ddsd.dwSize = sizeof(ddsd);
1311 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1312 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
1313 ddsd.dwWidth = 128;
1314 ddsd.dwHeight = 128;
1315 hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface4, NULL);
1316 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
1318 hr = IDirectDrawSurface_AddAttachedSurface(surface1, surface2);
1319 ok(hr == DD_OK, "Attaching an offscreen plain surface to a front buffer returned %08x\n", hr);
1320 /* Try the reverse without detaching first */
1321 hr = IDirectDrawSurface_AddAttachedSurface(surface2, surface1);
1322 ok(hr == DDERR_SURFACEALREADYATTACHED, "Attaching an attached surface to its attachee returned %08x\n", hr);
1323 hr = IDirectDrawSurface_DeleteAttachedSurface(surface1, 0, surface2);
1324 ok(hr == DD_OK, "DeleteAttachedSurface failed with %08x\n", hr);
1325 hr = IDirectDrawSurface_AddAttachedSurface(surface2, surface1);
1326 ok(hr == DD_OK, "Attaching a front buffer to an offscreen plain surface returned %08x\n", hr);
1327 /* Try to detach reversed */
1328 hr = IDirectDrawSurface_DeleteAttachedSurface(surface1, 0, surface2);
1329 ok(hr == DDERR_CANNOTDETACHSURFACE, "DeleteAttachedSurface returned %08x\n", hr);
1330 /* Now the proper detach */
1331 hr = IDirectDrawSurface_DeleteAttachedSurface(surface2, 0, surface1);
1332 ok(hr == DD_OK, "DeleteAttachedSurface failed with %08x\n", hr);
1333 hr = IDirectDrawSurface_AddAttachedSurface(surface2, surface3); /* Fails on refrast */
1334 ok(hr == DD_OK, "Attaching an offscreen plain surface to another offscreen plain surface returned %08x\n", hr);
1335 if(SUCCEEDED(hr))
1337 hr = IDirectDrawSurface_DeleteAttachedSurface(surface2, 0, surface3);
1338 ok(hr == DD_OK, "DeleteAttachedSurface failed with %08x\n", hr);
1340 hr = IDirectDrawSurface_AddAttachedSurface(surface1, surface4);
1341 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching an offscreen plain surface to a front buffer of different size returned %08x\n", hr);
1342 hr = IDirectDrawSurface_AddAttachedSurface(surface4, surface1);
1343 ok(hr == DDERR_CANNOTATTACHSURFACE, "Attaching a front buffer to an offscreen plain surface of different size returned %08x\n", hr);
1345 IDirectDrawSurface_Release(surface4);
1346 IDirectDrawSurface_Release(surface3);
1347 IDirectDrawSurface_Release(surface2);
1348 IDirectDrawSurface_Release(surface1);
1350 hr =IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_NORMAL);
1351 ok(hr == DD_OK, "SetCooperativeLevel returned %08x\n", hr);
1353 DestroyWindow(window);
1356 struct compare
1358 DWORD width, height;
1359 DWORD caps, caps2;
1360 UINT mips;
1363 HRESULT WINAPI CubeTestLvl2Enum(IDirectDrawSurface7 *surface, DDSURFACEDESC2 *desc, void *context)
1365 UINT *mips = context;
1367 (*mips)++;
1368 IDirectDrawSurface7_EnumAttachedSurfaces(surface,
1369 context,
1370 CubeTestLvl2Enum);
1372 return DDENUMRET_OK;
1375 HRESULT WINAPI CubeTestLvl1Enum(IDirectDrawSurface7 *surface, DDSURFACEDESC2 *desc, void *context)
1377 UINT mips = 0;
1378 UINT *num = (UINT *) context;
1379 static const struct compare expected[] =
1382 128, 128,
1383 DDSCAPS_MIPMAP | DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_COMPLEX,
1384 DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEZ,
1388 128, 128,
1389 DDSCAPS_MIPMAP | DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_COMPLEX,
1390 DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEZ,
1394 128, 128,
1395 DDSCAPS_MIPMAP | DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_COMPLEX,
1396 DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEY,
1400 128, 128,
1401 DDSCAPS_MIPMAP | DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_COMPLEX,
1402 DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEY,
1406 128, 128,
1407 DDSCAPS_MIPMAP | DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_COMPLEX,
1408 DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEX,
1412 64, 64, /* This is the first mipmap */
1413 DDSCAPS_MIPMAP | DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_COMPLEX,
1414 DDSCAPS2_MIPMAPSUBLEVEL | DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEX,
1419 mips = 0;
1420 IDirectDrawSurface7_EnumAttachedSurfaces(surface,
1421 &mips,
1422 CubeTestLvl2Enum);
1424 ok(desc->dwWidth == expected[*num].width, "Surface width is %d expected %d\n", desc->dwWidth, expected[*num].width);
1425 ok(desc->dwHeight == expected[*num].height, "Surface height is %d expected %d\n", desc->dwHeight, expected[*num].height);
1426 ok(desc->ddsCaps.dwCaps == expected[*num].caps, "Surface caps are %08x expected %08x\n", desc->ddsCaps.dwCaps, expected[*num].caps);
1427 ok(desc->ddsCaps.dwCaps2 == expected[*num].caps2, "Surface caps2 are %08x expected %08x\n", desc->ddsCaps.dwCaps2, expected[*num].caps2);
1428 ok(mips == expected[*num].mips, "Surface has %d mipmaps, expected %d\n", mips, expected[*num].mips);
1430 (*num)++;
1432 IDirectDrawSurface7_Release(surface);
1434 return DDENUMRET_OK;
1437 static void CubeMapTest(void)
1439 IDirectDraw7 *dd7 = NULL;
1440 IDirectDrawSurface7 *cubemap;
1441 DDSURFACEDESC2 ddsd;
1442 HRESULT hr;
1443 UINT num = 0;
1444 struct enumstruct ctx;
1446 hr = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
1447 ok(hr == DD_OK, "IDirectDraw::QueryInterface returned %08x\n", hr);
1449 memset(&ddsd, 0, sizeof(ddsd));
1450 ddsd.dwSize = sizeof(ddsd);
1451 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
1452 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS;
1453 ddsd.dwWidth = 128;
1454 ddsd.dwHeight = 128;
1455 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP | DDSCAPS_SYSTEMMEMORY;
1456 ddsd.ddsCaps.dwCaps2 = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES;
1458 /* D3DFMT_R5G6B5 */
1459 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
1460 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 16;
1461 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0xF800;
1462 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x07E0;
1463 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x001F;
1465 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &cubemap, NULL);
1466 ok(hr == DD_OK, "IDirectDraw7::CreateSurface returned %08x\n", hr);
1468 hr = IDirectDrawSurface7_GetSurfaceDesc(cubemap, &ddsd);
1469 ok(hr == DD_OK, "IDirectDrawSurface7_GetSurfaceDesc returned %08x\n", hr);
1470 ok(ddsd.ddsCaps.dwCaps == (DDSCAPS_MIPMAP | DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_COMPLEX),
1471 "Root Caps are %08x\n", ddsd.ddsCaps.dwCaps);
1472 ok(ddsd.ddsCaps.dwCaps2 == (DDSCAPS2_CUBEMAP_POSITIVEX | DDSCAPS2_CUBEMAP),
1473 "Root Caps2 are %08x\n", ddsd.ddsCaps.dwCaps2);
1475 IDirectDrawSurface7_EnumAttachedSurfaces(cubemap,
1476 &num,
1477 CubeTestLvl1Enum);
1478 trace("Enumerated %d surfaces in total\n", num);
1479 ok(num == 6, "Surface has %d attachments\n", num);
1480 IDirectDrawSurface7_Release(cubemap);
1482 /* What happens if I do not specify any faces? */
1483 memset(&ddsd, 0, sizeof(ddsd));
1484 ddsd.dwSize = sizeof(ddsd);
1485 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
1486 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS;
1487 ddsd.dwWidth = 128;
1488 ddsd.dwHeight = 128;
1489 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP | DDSCAPS_SYSTEMMEMORY;
1490 ddsd.ddsCaps.dwCaps2 = DDSCAPS2_CUBEMAP;
1492 /* D3DFMT_R5G6B5 */
1493 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
1494 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 16;
1495 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0xF800;
1496 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x07E0;
1497 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x001F;
1499 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &cubemap, NULL);
1500 ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw7::CreateSurface asking for a cube map without faces returned %08x\n", hr);
1502 /* Cube map faces without a cube map? */
1503 memset(&ddsd, 0, sizeof(ddsd));
1504 ddsd.dwSize = sizeof(ddsd);
1505 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
1506 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS;
1507 ddsd.dwWidth = 128;
1508 ddsd.dwHeight = 128;
1509 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP | DDSCAPS_SYSTEMMEMORY;
1510 ddsd.ddsCaps.dwCaps2 = DDSCAPS2_CUBEMAP_ALLFACES;
1512 /* D3DFMT_R5G6B5 */
1513 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
1514 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 16;
1515 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0xF800;
1516 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x07E0;
1517 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x001F;
1519 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &cubemap, NULL);
1520 ok(hr == DDERR_INVALIDCAPS, "IDirectDraw7::CreateSurface returned %08x\n", hr);
1522 memset(&ddsd, 0, sizeof(ddsd));
1523 ddsd.dwSize = sizeof(ddsd);
1524 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
1525 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS;
1526 ddsd.dwWidth = 128;
1527 ddsd.dwHeight = 128;
1528 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP | DDSCAPS_SYSTEMMEMORY;
1529 ddsd.ddsCaps.dwCaps2 = DDSCAPS2_CUBEMAP_POSITIVEX;
1531 /* D3DFMT_R5G6B5 */
1532 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
1533 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 16;
1534 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0xF800;
1535 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x07E0;
1536 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x001F;
1538 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &cubemap, NULL);
1539 ok(hr == DDERR_INVALIDCAPS, "IDirectDraw7::CreateSurface returned %08x\n", hr);
1541 /* Make sure everything is cleaned up properly. Use the enumSurfaces test infrastructure */
1542 memset(&ctx, 0, sizeof(ctx));
1543 memset(&ddsd, 0, sizeof(ddsd));
1544 ddsd.dwSize = sizeof(DDSURFACEDESC);
1545 hr = IDirectDraw_EnumSurfaces(lpDD, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_ALL, (DDSURFACEDESC *) &ddsd, (void *) &ctx, enumCB);
1546 ok(hr == DD_OK, "IDirectDraw_EnumSurfaces returned %08x\n", hr);
1547 ok(ctx.count == 0, "%d surfaces enumerated, expected 0\n", ctx.count);
1549 IDirectDraw7_Release(dd7);
1552 static void test_lockrect_invalid(void)
1554 unsigned int i, j;
1556 RECT valid[] = {
1557 {60, 60, 68, 68},
1558 {60, 60, 60, 68},
1559 {60, 60, 68, 60},
1560 {120, 60, 128, 68},
1561 {60, 120, 68, 128},
1564 RECT invalid[] = {
1565 {68, 60, 60, 68}, /* left > right */
1566 {60, 68, 68, 60}, /* top > bottom */
1567 {-8, 60, 0, 68}, /* left < surface */
1568 {60, -8, 68, 0}, /* top < surface */
1569 {-16, 60, -8, 68}, /* right < surface */
1570 {60, -16, 68, -8}, /* bottom < surface */
1571 {60, 60, 136, 68}, /* right > surface */
1572 {60, 60, 68, 136}, /* bottom > surface */
1573 {136, 60, 144, 68}, /* left > surface */
1574 {60, 136, 68, 144}, /* top > surface */
1577 const DWORD dds_caps[] = {
1578 DDSCAPS_OFFSCREENPLAIN,
1579 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE,
1582 for (j = 0; j < (sizeof(dds_caps) / sizeof(*dds_caps)); ++j)
1584 IDirectDrawSurface *surface = 0;
1585 DDSURFACEDESC surface_desc = {0};
1586 DDSURFACEDESC locked_desc = {0};
1587 HRESULT hr;
1589 surface_desc.dwSize = sizeof(surface_desc);
1590 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
1591 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
1592 surface_desc.ddsCaps.dwCaps = dds_caps[j];
1593 surface_desc.dwWidth = 128;
1594 surface_desc.dwHeight = 128;
1595 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB;
1596 U1(surface_desc.ddpfPixelFormat).dwRGBBitCount = 32;
1597 U2(surface_desc.ddpfPixelFormat).dwRBitMask = 0xFF0000;
1598 U3(surface_desc.ddpfPixelFormat).dwGBitMask = 0x00FF00;
1599 U4(surface_desc.ddpfPixelFormat).dwBBitMask = 0x0000FF;
1601 hr = IDirectDraw_CreateSurface(lpDD, &surface_desc, &surface, NULL);
1602 ok(SUCCEEDED(hr), "CreateSurface failed (0x%08x)\n", hr);
1603 if (FAILED(hr)) {
1604 skip("failed to create surface\n");
1605 continue;
1608 for (i = 0; i < (sizeof(valid) / sizeof(*valid)); ++i)
1610 RECT *rect = &valid[i];
1612 memset(&locked_desc, 0, sizeof(locked_desc));
1613 locked_desc.dwSize = sizeof(locked_desc);
1615 hr = IDirectDrawSurface_Lock(surface, rect, &locked_desc, DDLOCK_WAIT, NULL);
1616 ok(SUCCEEDED(hr), "Lock failed (0x%08x) for rect [%d, %d]->[%d, %d]\n",
1617 hr, rect->left, rect->top, rect->right, rect->bottom);
1619 hr = IDirectDrawSurface_Unlock(surface, NULL);
1620 ok(SUCCEEDED(hr), "Unlock failed (0x%08x)\n", hr);
1623 for (i = 0; i < (sizeof(invalid) / sizeof(*invalid)); ++i)
1625 RECT *rect = &invalid[i];
1627 hr = IDirectDrawSurface_Lock(surface, rect, &locked_desc, DDLOCK_WAIT, NULL);
1628 ok(hr == DDERR_INVALIDPARAMS, "Lock returned 0x%08x for rect [%d, %d]->[%d, %d]"
1629 ", expected DDERR_INVALIDPARAMS (0x%08x)\n", hr, rect->left, rect->top,
1630 rect->right, rect->bottom, DDERR_INVALIDPARAMS);
1633 hr = IDirectDrawSurface_Lock(surface, NULL, &locked_desc, DDLOCK_WAIT, NULL);
1634 ok(hr == DD_OK, "IDirectDrawSurface_Lock(rect = NULL) failed (0x%08x)\n", hr);
1635 hr = IDirectDrawSurface_Lock(surface, NULL, &locked_desc, DDLOCK_WAIT, NULL);
1636 ok(hr == DDERR_SURFACEBUSY, "Double lock(rect = NULL) returned 0x%08x\n", hr);
1637 if(SUCCEEDED(hr)) {
1638 hr = IDirectDrawSurface_Unlock(surface, NULL);
1639 ok(SUCCEEDED(hr), "Unlock failed (0x%08x)\n", hr);
1641 hr = IDirectDrawSurface_Unlock(surface, NULL);
1642 ok(SUCCEEDED(hr), "Unlock failed (0x%08x)\n", hr);
1644 memset(&locked_desc, 0, sizeof(locked_desc));
1645 locked_desc.dwSize = sizeof(locked_desc);
1646 hr = IDirectDrawSurface_Lock(surface, &valid[0], &locked_desc, DDLOCK_WAIT, NULL);
1647 ok(hr == DD_OK, "IDirectDrawSurface_Lock(rect = [%d, %d]->[%d, %d]) failed (0x%08x)\n",
1648 valid[0].left, valid[0].top, valid[0].right, valid[0].bottom, hr);
1649 hr = IDirectDrawSurface_Lock(surface, &valid[0], &locked_desc, DDLOCK_WAIT, NULL);
1650 ok(hr == DDERR_SURFACEBUSY, "Double lock(rect = [%d, %d]->[%d, %d]) failed (0x%08x)\n",
1651 valid[0].left, valid[0].top, valid[0].right, valid[0].bottom, hr);
1653 /* Locking a different rectangle returns DD_OK, but it seems to break the surface.
1654 * Afterwards unlocking the surface fails(NULL rectangle, and both locked rectangles
1657 hr = IDirectDrawSurface_Unlock(surface, NULL);
1658 ok(hr == DD_OK, "Unlock returned (0x%08x)\n", hr);
1660 IDirectDrawSurface_Release(surface);
1664 static void CompressedTest(void)
1666 HRESULT hr;
1667 IDirectDrawSurface7 *surface;
1668 DDSURFACEDESC2 ddsd, ddsd2;
1669 IDirectDraw7 *dd7 = NULL;
1670 RECT r = { 0, 0, 128, 128 };
1671 RECT r2 = { 32, 32, 64, 64 };
1673 hr = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
1674 ok(hr == DD_OK, "IDirectDraw::QueryInterface returned %08x\n", hr);
1676 memset(&ddsd, 0, sizeof(ddsd));
1677 ddsd.dwSize = sizeof(ddsd);
1678 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
1679 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS;
1680 ddsd.dwWidth = 128;
1681 ddsd.dwHeight = 128;
1682 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY;
1683 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_FOURCC;
1684 U4(ddsd).ddpfPixelFormat.dwFourCC = MAKEFOURCC('D','X','T','1');
1686 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface, NULL);
1687 ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
1688 if (FAILED(hr)) {
1689 skip("failed to create surface\n");
1690 return;
1693 memset(&ddsd2, 0, sizeof(ddsd2));
1694 ddsd2.dwSize = sizeof(ddsd2);
1695 U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
1696 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd2);
1697 ok(hr == DD_OK, "GetSurfaceDesc returned %08x\n", hr);
1699 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
1700 "Surface desc flags: %08x\n", ddsd2.dwFlags);
1701 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
1702 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
1703 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
1704 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
1705 ok(U1(ddsd2).dwLinearSize == 8192, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
1706 ok(ddsd2.ddsCaps.dwCaps2 == 0, "Caps2: %08x\n", ddsd2.ddsCaps.dwCaps2);
1707 IDirectDrawSurface7_Release(surface);
1709 U4(ddsd).ddpfPixelFormat.dwFourCC = MAKEFOURCC('D','X','T','3');
1710 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface, NULL);
1711 ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
1712 if (FAILED(hr)) {
1713 skip("failed to create surface\n");
1714 return;
1717 memset(&ddsd2, 0, sizeof(ddsd2));
1718 ddsd2.dwSize = sizeof(ddsd2);
1719 U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
1720 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd2);
1721 ok(hr == DD_OK, "GetSurfaceDesc returned %08x\n", hr);
1723 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
1724 "Surface desc flags: %08x\n", ddsd2.dwFlags);
1725 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
1726 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
1727 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
1728 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
1729 ok(U1(ddsd2).dwLinearSize == 16384, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
1730 IDirectDrawSurface7_Release(surface);
1732 U4(ddsd).ddpfPixelFormat.dwFourCC = MAKEFOURCC('D','X','T','5');
1733 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface, NULL);
1734 ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
1735 if (FAILED(hr)) {
1736 skip("failed to create surface\n");
1737 return;
1740 memset(&ddsd2, 0, sizeof(ddsd2));
1741 ddsd2.dwSize = sizeof(ddsd2);
1742 U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
1743 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd2);
1744 ok(hr == DD_OK, "GetSurfaceDesc returned %08x\n", hr);
1746 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
1747 "Surface desc flags: %08x\n", ddsd2.dwFlags);
1748 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
1749 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
1750 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
1751 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
1752 ok(U1(ddsd2).dwLinearSize == 16384, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
1753 ok(ddsd2.lpSurface == 0, "Surface memory is at %p, expected NULL\n", ddsd2.lpSurface);
1755 memset(&ddsd2, 0, sizeof(ddsd2));
1756 ddsd2.dwSize = sizeof(ddsd2);
1757 U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
1759 /* Show that the description is not changed when locking the surface. What is really interesting
1760 * about this is that DDSD_LPSURFACE isn't set.
1762 hr = IDirectDrawSurface7_Lock(surface, NULL, &ddsd2, DDLOCK_READONLY, 0);
1763 ok(hr == DD_OK, "Lock 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 == 16384, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
1772 ok(ddsd2.lpSurface != 0, "Surface memory is at NULL\n");
1774 hr = IDirectDrawSurface7_Unlock(surface, NULL);
1775 ok(hr == DD_OK, "Unlock returned %08x\n", hr);
1777 /* Now what about a locking rect? */
1778 hr = IDirectDrawSurface7_Lock(surface, &r, &ddsd2, DDLOCK_READONLY, 0);
1779 ok(hr == DD_OK, "Lock returned %08x\n", hr);
1781 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
1782 "Surface desc flags: %08x\n", ddsd2.dwFlags);
1783 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
1784 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
1785 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
1786 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
1787 ok(U1(ddsd2).dwLinearSize == 16384, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
1788 ok(ddsd2.lpSurface != 0, "Surface memory is at NULL\n");
1790 hr = IDirectDrawSurface7_Unlock(surface, &r);
1791 ok(hr == DD_OK, "Unlock returned %08x\n", hr);
1793 /* Now what about a different locking offset? */
1794 hr = IDirectDrawSurface7_Lock(surface, &r2, &ddsd2, DDLOCK_READONLY, 0);
1795 ok(hr == DD_OK, "Lock returned %08x\n", hr);
1797 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
1798 "Surface desc flags: %08x\n", ddsd2.dwFlags);
1799 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
1800 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
1801 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
1802 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
1803 ok(U1(ddsd2).dwLinearSize == 16384, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
1804 ok(ddsd2.lpSurface != 0, "Surface memory is at NULL\n");
1806 hr = IDirectDrawSurface7_Unlock(surface, &r2);
1807 ok(hr == DD_OK, "Unlock returned %08x\n", hr);
1808 IDirectDrawSurface7_Release(surface);
1810 /* Try this with video memory. A kind of surprise. It still has the LINEARSIZE flag set,
1811 * but seems to have a pitch instead.
1813 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY;
1814 U4(ddsd).ddpfPixelFormat.dwFourCC = MAKEFOURCC('D','X','T','1');
1816 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface, NULL);
1817 ok(hr == DD_OK || hr == DDERR_NOTEXTUREHW || hr == DDERR_INVALIDPARAMS,
1818 "CreateSurface returned %08x\n", hr);
1820 /* Not supported everywhere */
1821 if(SUCCEEDED(hr))
1823 memset(&ddsd2, 0, sizeof(ddsd2));
1824 ddsd2.dwSize = sizeof(ddsd2);
1825 U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
1826 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd2);
1827 ok(hr == DD_OK, "GetSurfaceDesc returned %08x\n", hr);
1829 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
1830 "Surface desc flags: %08x\n", ddsd2.dwFlags);
1831 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
1832 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
1833 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM),
1834 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
1835 /* ATI drivers report a broken linear size, thus no need to clone the exact behaviour. nvidia reports the correct size */
1836 ok(ddsd2.ddsCaps.dwCaps2 == 0, "Caps2: %08x\n", ddsd2.ddsCaps.dwCaps2);
1837 IDirectDrawSurface7_Release(surface);
1839 U4(ddsd).ddpfPixelFormat.dwFourCC = MAKEFOURCC('D','X','T','3');
1840 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface, NULL);
1841 ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
1843 memset(&ddsd2, 0, sizeof(ddsd2));
1844 ddsd2.dwSize = sizeof(ddsd2);
1845 U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
1846 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd2);
1847 ok(hr == DD_OK, "GetSurfaceDesc returned %08x\n", hr);
1849 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
1850 "Surface desc flags: %08x\n", ddsd2.dwFlags);
1851 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
1852 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
1853 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM),
1854 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
1855 /* ATI drivers report a broken linear size, thus no need to clone the exact behaviour. nvidia reports the correct size */
1856 IDirectDrawSurface7_Release(surface);
1858 U4(ddsd).ddpfPixelFormat.dwFourCC = MAKEFOURCC('D','X','T','5');
1859 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface, NULL);
1860 ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
1862 memset(&ddsd2, 0, sizeof(ddsd2));
1863 ddsd2.dwSize = sizeof(ddsd2);
1864 U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
1865 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd2);
1866 ok(hr == DD_OK, "GetSurfaceDesc returned %08x\n", hr);
1868 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
1869 "Surface desc flags: %08x\n", ddsd2.dwFlags);
1870 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
1871 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
1872 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM),
1873 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
1874 /* ATI drivers report a broken linear size, thus no need to clone the exact behaviour. nvidia reports the correct size */
1875 ok(ddsd2.lpSurface == 0, "Surface memory is at %p, expected NULL\n", ddsd2.lpSurface);
1877 memset(&ddsd2, 0, sizeof(ddsd2));
1878 ddsd2.dwSize = sizeof(ddsd2);
1879 U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
1881 /* Show that the description is not changed when locking the surface. What is really interesting
1882 * about this is that DDSD_LPSURFACE isn't set.
1884 hr = IDirectDrawSurface7_Lock(surface, NULL, &ddsd2, DDLOCK_READONLY, 0);
1885 ok(hr == DD_OK, "Lock returned %08x\n", hr);
1887 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
1888 "Surface desc flags: %08x\n", ddsd2.dwFlags);
1889 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
1890 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
1891 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM),
1892 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
1893 /* ATI drivers report a broken linear size, thus no need to clone the exact behaviour. nvidia reports the correct size */
1894 ok(ddsd2.lpSurface != 0, "Surface memory is at NULL\n");
1896 hr = IDirectDrawSurface7_Unlock(surface, NULL);
1897 ok(hr == DD_OK, "Unlock returned %08x\n", hr);
1899 /* Now what about a locking rect? */
1900 hr = IDirectDrawSurface7_Lock(surface, &r, &ddsd2, DDLOCK_READONLY, 0);
1901 ok(hr == DD_OK, "Lock returned %08x\n", hr);
1903 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
1904 "Surface desc flags: %08x\n", ddsd2.dwFlags);
1905 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
1906 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
1907 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM),
1908 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
1909 /* ATI drivers report a broken linear size, thus no need to clone the exact behaviour. nvidia reports the correct size */
1910 ok(ddsd2.lpSurface != 0, "Surface memory is at NULL\n");
1912 hr = IDirectDrawSurface7_Unlock(surface, &r);
1913 ok(hr == DD_OK, "Unlock returned %08x\n", hr);
1915 /* Now what about a different locking offset? */
1916 hr = IDirectDrawSurface7_Lock(surface, &r2, &ddsd2, DDLOCK_READONLY, 0);
1917 ok(hr == DD_OK, "Lock returned %08x\n", hr);
1919 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
1920 "Surface desc flags: %08x\n", ddsd2.dwFlags);
1921 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
1922 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
1923 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM),
1924 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
1925 /* ATI drivers report a broken linear size, thus no need to clone the exact behaviour. nvidia reports the correct size */
1926 ok(ddsd2.lpSurface != 0, "Surface memory is at NULL\n");
1928 hr = IDirectDrawSurface7_Unlock(surface, &r2);
1929 ok(hr == DD_OK, "Unlock returned %08x\n", hr);
1931 IDirectDrawSurface7_Release(surface);
1933 else
1935 skip("Hardware DXTN textures not supported\n");
1938 /* What happens to managed textures? Interestingly, Windows reports them as being in system
1939 * memory. The linear size fits again.
1941 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1942 ddsd.ddsCaps.dwCaps2 = DDSCAPS2_TEXTUREMANAGE;
1943 U4(ddsd).ddpfPixelFormat.dwFourCC = MAKEFOURCC('D','X','T','1');
1945 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface, NULL);
1946 ok(hr == DD_OK || hr == DDERR_NOTEXTUREHW, "CreateSurface returned %08x\n", hr);
1948 /* Not supported everywhere */
1949 if(SUCCEEDED(hr))
1951 memset(&ddsd2, 0, sizeof(ddsd2));
1952 ddsd2.dwSize = sizeof(ddsd2);
1953 U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
1954 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd2);
1955 ok(hr == DD_OK, "GetSurfaceDesc returned %08x\n", hr);
1957 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
1958 "Surface desc flags: %08x\n", ddsd2.dwFlags);
1959 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
1960 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
1961 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
1962 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
1963 ok(U1(ddsd2).dwLinearSize == 8192, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
1964 ok(ddsd2.ddsCaps.dwCaps2 == DDSCAPS2_TEXTUREMANAGE, "Caps2: %08x\n", ddsd2.ddsCaps.dwCaps2);
1965 IDirectDrawSurface7_Release(surface);
1967 U4(ddsd).ddpfPixelFormat.dwFourCC = MAKEFOURCC('D','X','T','3');
1968 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface, NULL);
1969 ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
1971 memset(&ddsd2, 0, sizeof(ddsd2));
1972 ddsd2.dwSize = sizeof(ddsd2);
1973 U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
1974 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd2);
1975 ok(hr == DD_OK, "GetSurfaceDesc returned %08x\n", hr);
1977 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
1978 "Surface desc flags: %08x\n", ddsd2.dwFlags);
1979 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
1980 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
1981 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
1982 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
1983 ok(U1(ddsd2).dwLinearSize == 16384, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
1984 IDirectDrawSurface7_Release(surface);
1986 U4(ddsd).ddpfPixelFormat.dwFourCC = MAKEFOURCC('D','X','T','5');
1987 hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface, NULL);
1988 ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
1990 memset(&ddsd2, 0, sizeof(ddsd2));
1991 ddsd2.dwSize = sizeof(ddsd2);
1992 U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
1993 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd2);
1994 ok(hr == DD_OK, "GetSurfaceDesc returned %08x\n", hr);
1996 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
1997 "Surface desc flags: %08x\n", ddsd2.dwFlags);
1998 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
1999 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
2000 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
2001 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
2002 ok(U1(ddsd2).dwLinearSize == 16384, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
2003 ok(ddsd2.lpSurface == 0, "Surface memory is at %p, expected NULL\n", ddsd2.lpSurface);
2005 memset(&ddsd2, 0, sizeof(ddsd2));
2006 ddsd2.dwSize = sizeof(ddsd2);
2007 U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
2009 /* Show that the description is not changed when locking the surface. What is really interesting
2010 * about this is that DDSD_LPSURFACE isn't set.
2012 hr = IDirectDrawSurface7_Lock(surface, NULL, &ddsd2, DDLOCK_READONLY, 0);
2013 ok(hr == DD_OK, "Lock returned %08x\n", hr);
2015 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
2016 "Surface desc flags: %08x\n", ddsd2.dwFlags);
2017 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
2018 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
2019 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
2020 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
2021 ok(U1(ddsd2).dwLinearSize == 16384, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
2022 ok(ddsd2.lpSurface != 0, "Surface memory is at NULL\n");
2024 hr = IDirectDrawSurface7_Unlock(surface, NULL);
2025 ok(hr == DD_OK, "Unlock returned %08x\n", hr);
2027 /* Now what about a locking rect? */
2028 hr = IDirectDrawSurface7_Lock(surface, &r, &ddsd2, DDLOCK_READONLY, 0);
2029 ok(hr == DD_OK, "Lock returned %08x\n", hr);
2031 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
2032 "Surface desc flags: %08x\n", ddsd2.dwFlags);
2033 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
2034 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
2035 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
2036 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
2037 ok(U1(ddsd2).dwLinearSize == 16384, "\"Linear\" size is %d\n", U1(ddsd2).dwLinearSize);
2038 ok(ddsd2.lpSurface != 0, "Surface memory is at NULL\n");
2040 hr = IDirectDrawSurface7_Unlock(surface, &r);
2041 ok(hr == DD_OK, "Unlock returned %08x\n", hr);
2043 /* Now what about a different locking offset? */
2044 hr = IDirectDrawSurface7_Lock(surface, &r2, &ddsd2, DDLOCK_READONLY, 0);
2045 ok(hr == DD_OK, "Lock returned %08x\n", hr);
2047 ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
2048 "Surface desc flags: %08x\n", ddsd2.dwFlags);
2049 ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
2050 ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
2051 ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
2052 "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
2053 ok(U1(ddsd2).dwLinearSize == 16384, "\"Linear\" size is %d\n", U1(ddsd2).dwLinearSize);
2054 ok(ddsd2.lpSurface != 0, "Surface memory is at NULL\n");
2056 hr = IDirectDrawSurface7_Unlock(surface, &r2);
2057 ok(hr == DD_OK, "Unlock returned %08x\n", hr);
2059 IDirectDrawSurface7_Release(surface);
2061 else
2063 skip("Hardware DXTN textures not supported\n");
2066 IDirectDraw7_Release(dd7);
2069 static void SizeTest(void)
2071 LPDIRECTDRAWSURFACE dsurface = NULL;
2072 DDSURFACEDESC desc;
2073 HRESULT ret;
2074 HWND window = CreateWindow( "static", "ddraw_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
2076 /* Create an offscreen surface surface without a size */
2077 ZeroMemory(&desc, sizeof(desc));
2078 desc.dwSize = sizeof(desc);
2079 desc.dwFlags = DDSD_CAPS;
2080 desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
2081 trace("before offscreenplain create dsurface = %p\n", dsurface);
2082 ret = IDirectDraw_CreateSurface(lpDD, &desc, &dsurface, NULL);
2083 ok(ret == DDERR_INVALIDPARAMS, "Creating an offscreen plain surface without a size info returned %08x (dsurface=%p)\n", ret, dsurface);
2084 if(dsurface)
2086 trace("Surface at %p\n", dsurface);
2087 IDirectDrawSurface_Release(dsurface);
2088 dsurface = NULL;
2091 /* Create an offscreen surface surface with only a width parameter */
2092 ZeroMemory(&desc, sizeof(desc));
2093 desc.dwSize = sizeof(desc);
2094 desc.dwFlags = DDSD_CAPS | DDSD_WIDTH;
2095 desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
2096 desc.dwWidth = 128;
2097 ret = IDirectDraw_CreateSurface(lpDD, &desc, &dsurface, NULL);
2098 ok(ret == DDERR_INVALIDPARAMS, "Creating an offscreen plain surface without hight info returned %08x\n", ret);
2099 if(dsurface)
2101 IDirectDrawSurface_Release(dsurface);
2102 dsurface = NULL;
2105 /* Create an offscreen surface surface with only a height parameter */
2106 ZeroMemory(&desc, sizeof(desc));
2107 desc.dwSize = sizeof(desc);
2108 desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT;
2109 desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
2110 desc.dwHeight = 128;
2111 ret = IDirectDraw_CreateSurface(lpDD, &desc, &dsurface, NULL);
2112 ok(ret == DDERR_INVALIDPARAMS, "Creating an offscreen plain surface without width info returned %08x\n", ret);
2113 if(dsurface)
2115 IDirectDrawSurface_Release(dsurface);
2116 dsurface = NULL;
2119 /* Sanity check */
2120 ZeroMemory(&desc, sizeof(desc));
2121 desc.dwSize = sizeof(desc);
2122 desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
2123 desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
2124 desc.dwHeight = 128;
2125 desc.dwWidth = 128;
2126 ret = IDirectDraw_CreateSurface(lpDD, &desc, &dsurface, NULL);
2127 ok(ret == DD_OK, "Creating an offscreen plain surface with width and height info returned %08x\n", ret);
2128 if(dsurface)
2130 IDirectDrawSurface_Release(dsurface);
2131 dsurface = NULL;
2134 /* Test a primary surface size */
2135 ret = IDirectDraw_SetCooperativeLevel(lpDD, window, DDSCL_NORMAL);
2136 ok(ret == DD_OK, "SetCooperativeLevel failed with %08x\n", ret);
2138 ZeroMemory(&desc, sizeof(desc));
2139 desc.dwSize = sizeof(desc);
2140 desc.dwFlags = DDSD_CAPS;
2141 desc.ddsCaps.dwCaps |= DDSCAPS_PRIMARYSURFACE;
2142 desc.dwHeight = 128; /* Keep them set to check what happens */
2143 desc.dwWidth = 128; /* Keep them set to check what happens */
2144 ret = IDirectDraw_CreateSurface(lpDD, &desc, &dsurface, NULL);
2145 ok(ret == DD_OK, "Creating a primary surface without width and height info returned %08x\n", ret);
2146 if(dsurface)
2148 ret = IDirectDrawSurface_GetSurfaceDesc(dsurface, &desc);
2149 ok(ret == DD_OK, "GetSurfaceDesc returned %x\n", ret);
2151 IDirectDrawSurface_Release(dsurface);
2152 dsurface = NULL;
2154 ok(desc.dwFlags & DDSD_WIDTH, "Primary surface doesn't have width set\n");
2155 ok(desc.dwFlags & DDSD_HEIGHT, "Primary surface doesn't have height set\n");
2156 ok(desc.dwWidth == GetSystemMetrics(SM_CXSCREEN), "Surface width differs from screen width\n");
2157 ok(desc.dwHeight == GetSystemMetrics(SM_CYSCREEN), "Surface height differs from screen height\n");
2159 ret = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_NORMAL);
2160 ok(ret == DD_OK, "SetCooperativeLevel failed with %08x\n", ret);
2163 static void PrivateDataTest(void)
2165 HRESULT hr;
2166 IDirectDrawSurface7 *surface7 = NULL;
2167 IDirectDrawSurface *surface = NULL;
2168 DDSURFACEDESC desc;
2169 ULONG ref, ref2;
2170 IUnknown *ptr;
2171 DWORD size = sizeof(IUnknown *);
2173 ZeroMemory(&desc, sizeof(desc));
2174 desc.dwSize = sizeof(desc);
2175 desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
2176 desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
2177 desc.dwHeight = 128;
2178 desc.dwWidth = 128;
2179 hr = IDirectDraw_CreateSurface(lpDD, &desc, &surface, NULL);
2180 ok(hr == DD_OK, "Creating an offscreen plain surface failed with %08x\n", hr);
2181 if(!surface)
2183 return;
2185 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirectDrawSurface7, (void **) &surface7);
2186 ok(hr == DD_OK, "IDirectDrawSurface_QueryInterface failed with %08x\n", hr);
2187 if(!surface)
2189 IDirectDrawSurface_Release(surface);
2190 return;
2193 /* This fails */
2194 hr = IDirectDrawSurface7_SetPrivateData(surface7, &IID_IDirectDrawSurface7 /* Abuse this tag */, lpDD, 0, DDSPD_IUNKNOWNPOINTER);
2195 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr);
2196 hr = IDirectDrawSurface7_SetPrivateData(surface7, &IID_IDirectDrawSurface7 /* Abuse this tag */, lpDD, 5, DDSPD_IUNKNOWNPOINTER);
2197 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr);
2198 hr = IDirectDrawSurface7_SetPrivateData(surface7, &IID_IDirectDrawSurface7 /* Abuse this tag */, lpDD, sizeof(IUnknown *) * 2, DDSPD_IUNKNOWNPOINTER);
2199 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr);
2201 ref = getref((IUnknown *) lpDD);
2202 hr = IDirectDrawSurface7_SetPrivateData(surface7, &IID_IDirectDrawSurface7 /* Abuse this tag */, lpDD, sizeof(IUnknown *), DDSPD_IUNKNOWNPOINTER);
2203 ok(hr == DD_OK, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr);
2204 ref2 = getref((IUnknown *) lpDD);
2205 ok(ref2 == ref + 1, "Object reference is %d, expected %d\n", ref2, ref + 1);
2206 hr = IDirectDrawSurface7_FreePrivateData(surface7, &IID_IDirectDrawSurface7);
2207 ref2 = getref((IUnknown *) lpDD);
2208 ok(ref2 == ref, "Object reference is %d, expected %d\n", ref2, ref);
2210 hr = IDirectDrawSurface7_SetPrivateData(surface7, &IID_IDirectDrawSurface7, lpDD, sizeof(IUnknown *), DDSPD_IUNKNOWNPOINTER);
2211 ok(hr == DD_OK, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr);
2212 hr = IDirectDrawSurface7_SetPrivateData(surface7, &IID_IDirectDrawSurface7, surface7, sizeof(IUnknown *), DDSPD_IUNKNOWNPOINTER);
2213 ok(hr == DD_OK, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr);
2214 ref2 = getref((IUnknown *) lpDD);
2215 ok(ref2 == ref, "Object reference is %d, expected %d\n", ref2, ref);
2217 hr = IDirectDrawSurface7_SetPrivateData(surface7, &IID_IDirectDrawSurface7, lpDD, sizeof(IUnknown *), DDSPD_IUNKNOWNPOINTER);
2218 ok(hr == DD_OK, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr);
2219 hr = IDirectDrawSurface7_GetPrivateData(surface7, &IID_IDirectDrawSurface7, &ptr, &size);
2220 ok(hr == DD_OK, "IDirectDrawSurface7_GetPrivateData failed with %08x\n", hr);
2221 ref2 = getref((IUnknown *) lpDD);
2222 /* Object is NOT beein addrefed */
2223 ok(ptr == (IUnknown *) lpDD, "Returned interface pointer is %p, expected %p\n", ptr, lpDD);
2224 ok(ref2 == ref + 1, "Object reference is %d, expected %d. ptr at %p, orig at %p\n", ref2, ref + 1, ptr, lpDD);
2226 IDirectDrawSurface_Release(surface);
2227 IDirectDrawSurface7_Release(surface7);
2229 /* Destroying the surface frees the held reference */
2230 ref2 = getref((IUnknown *) lpDD);
2231 ok(ref2 == ref, "Object reference is %d, expected %d\n", ref2, ref);
2234 static void BltParamTest(void)
2236 IDirectDrawSurface *surface1 = NULL, *surface2 = NULL;
2237 DDSURFACEDESC desc;
2238 HRESULT hr;
2239 DDBLTFX BltFx;
2240 RECT valid = {10, 10, 20, 20};
2241 RECT invalid1 = {20, 10, 10, 20};
2242 RECT invalid2 = {20, 20, 20, 20};
2243 RECT invalid3 = {-1, -1, 20, 20};
2244 RECT invalid4 = {60, 60, 70, 70};
2246 memset(&desc, 0, sizeof(desc));
2247 desc.dwSize = sizeof(desc);
2248 desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
2249 desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
2250 desc.dwHeight = 128;
2251 desc.dwWidth = 128;
2252 hr = IDirectDraw_CreateSurface(lpDD, &desc, &surface1, NULL);
2253 ok(hr == DD_OK, "Creating an offscreen plain surface failed with %08x\n", hr);
2255 desc.dwHeight = 64;
2256 desc.dwWidth = 64;
2257 hr = IDirectDraw_CreateSurface(lpDD, &desc, &surface2, NULL);
2258 ok(hr == DD_OK, "Creating an offscreen plain surface failed with %08x\n", hr);
2260 if(0)
2262 /* This crashes */
2263 hr = IDirectDrawSurface_BltFast(surface1, 0, 0, NULL, NULL, 0);
2264 ok(hr == DD_OK, "BltFast from NULL surface returned %08x\n", hr);
2266 hr = IDirectDrawSurface_BltFast(surface1, 0, 0, surface2, NULL, 0);
2267 ok(hr == DD_OK, "BltFast from smaller to bigger surface returned %08x\n", hr);
2268 hr = IDirectDrawSurface_BltFast(surface2, 0, 0, surface1, NULL, 0);
2269 ok(hr == DDERR_INVALIDRECT, "BltFast from bigger to smaller surface returned %08x\n", hr);
2270 hr = IDirectDrawSurface_BltFast(surface2, 0, 0, surface1, &valid, 0);
2271 ok(hr == DD_OK, "BltFast from bigger to smaller surface using a valid rectangle returned %08x\n", hr);
2272 hr = IDirectDrawSurface_BltFast(surface2, 60, 60, surface1, &valid, 0);
2273 ok(hr == DDERR_INVALIDRECT, "BltFast with a rectangle resulting in an off-surface write returned %08x\n", hr);
2274 hr = IDirectDrawSurface_BltFast(surface1, 90, 90, surface2, NULL, 0);
2275 ok(hr == DDERR_INVALIDRECT, "BltFast with a rectangle resulting in an off-surface write returned %08x\n", hr);
2276 hr = IDirectDrawSurface_BltFast(surface2, 0, 0, surface1, &invalid1, 0);
2277 ok(hr == DDERR_INVALIDRECT, "BltFast with invalid rectangle 1 returned %08x\n", hr);
2278 hr = IDirectDrawSurface_BltFast(surface2, 0, 0, surface1, &invalid2, 0);
2279 ok(hr == DDERR_INVALIDRECT, "BltFast with invalid rectangle 2 returned %08x\n", hr);
2280 hr = IDirectDrawSurface_BltFast(surface2, 0, 0, surface1, &invalid3, 0);
2281 ok(hr == DDERR_INVALIDRECT, "BltFast with invalid rectangle 3 returned %08x\n", hr);
2282 hr = IDirectDrawSurface_BltFast(surface1, 0, 0, surface2, &invalid4, 0);
2283 ok(hr == DDERR_INVALIDRECT, "BltFast with invalid rectangle 3 returned %08x\n", hr);
2284 hr = IDirectDrawSurface_BltFast(surface1, 0, 0, surface1, NULL, 0);
2285 ok(hr == DD_OK, "BltFast blitting a surface onto itself returned %08x\n", hr);
2287 /* Blt(non-fast) tests */
2288 memset(&BltFx, 0, sizeof(BltFx));
2289 BltFx.dwSize = sizeof(BltFx);
2290 U5(BltFx).dwFillColor = 0xaabbccdd;
2292 hr = IDirectDrawSurface_Blt(surface1, &valid, NULL, NULL, DDBLT_COLORFILL, &BltFx);
2293 ok(hr == DD_OK, "IDirectDrawSurface_Blt with a valid rectangle for color fill returned %08x\n", hr);
2294 hr = IDirectDrawSurface_Blt(surface1, &valid, NULL, &invalid3, DDBLT_COLORFILL, &BltFx);
2295 ok(hr == DD_OK, "IDirectDrawSurface_Blt with a invalid, unused rectangle returned %08x\n", hr);
2296 hr = IDirectDrawSurface_Blt(surface2, &invalid1, NULL, NULL, DDBLT_COLORFILL, &BltFx);
2297 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 1 returned %08x\n", hr);
2298 hr = IDirectDrawSurface_Blt(surface2, &invalid2, NULL, NULL, DDBLT_COLORFILL, &BltFx);
2299 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 2 returned %08x\n", hr);
2300 hr = IDirectDrawSurface_Blt(surface2, &invalid3, NULL, NULL, DDBLT_COLORFILL, &BltFx);
2301 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 3 returned %08x\n", hr);
2302 hr = IDirectDrawSurface_Blt(surface2, &invalid4, NULL, NULL, DDBLT_COLORFILL, &BltFx);
2303 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 4 returned %08x\n", hr);
2305 /* Valid on surface 1 */
2306 hr = IDirectDrawSurface_Blt(surface1, &invalid4, NULL, NULL, DDBLT_COLORFILL, &BltFx);
2307 ok(hr == DD_OK, "IDirectDrawSurface_Blt with a subrectangle fill returned %08x\n", hr);
2309 /* Works - stretched blit */
2310 hr = IDirectDrawSurface_Blt(surface1, NULL, surface2, NULL, 0, NULL);
2311 ok(hr == DD_OK, "IDirectDrawSurface_Blt from a smaller to a bigger surface returned %08x\n", hr);
2312 hr = IDirectDrawSurface_Blt(surface2, NULL, surface1, NULL, 0, NULL);
2313 ok(hr == DD_OK, "IDirectDrawSurface_Blt from a bigger to a smaller surface %08x\n", hr);
2315 /* Invalid dest rects in sourced blits */
2316 hr = IDirectDrawSurface_Blt(surface2, &invalid1, surface1, NULL, 0, NULL);
2317 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 1 returned %08x\n", hr);
2318 hr = IDirectDrawSurface_Blt(surface2, &invalid2, surface1, NULL, 0, NULL);
2319 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 2 returned %08x\n", hr);
2320 hr = IDirectDrawSurface_Blt(surface2, &invalid3, surface1, NULL, 0, NULL);
2321 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 3 returned %08x\n", hr);
2322 hr = IDirectDrawSurface_Blt(surface2, &invalid4, surface1, NULL, 0, NULL);
2323 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 4 returned %08x\n", hr);
2325 /* Invalid src rects */
2326 hr = IDirectDrawSurface_Blt(surface2, NULL, surface1, &invalid1, 0, NULL);
2327 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 1 returned %08x\n", hr);
2328 hr = IDirectDrawSurface_Blt(surface2, NULL, surface1, &invalid2, 0, NULL);
2329 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 2 returned %08x\n", hr);
2330 hr = IDirectDrawSurface_Blt(surface2, NULL, surface1, &invalid3, 0, NULL);
2331 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 3 returned %08x\n", hr);
2332 hr = IDirectDrawSurface_Blt(surface1, NULL, surface2, &invalid4, 0, NULL);
2333 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 4 returned %08x\n", hr);
2335 IDirectDrawSurface_Release(surface1);
2336 IDirectDrawSurface_Release(surface2);
2339 static void StructSizeTest(void)
2341 IDirectDrawSurface *surface1;
2342 IDirectDrawSurface7 *surface7;
2343 union {
2344 DDSURFACEDESC desc1;
2345 DDSURFACEDESC2 desc2;
2346 char blob[1024]; /* To get a bunch of writable memory */
2347 } desc;
2348 DDSURFACEDESC create;
2349 HRESULT hr;
2351 memset(&desc, 0, sizeof(desc));
2352 memset(&create, 0, sizeof(create));
2354 memset(&create, 0, sizeof(create));
2355 create.dwSize = sizeof(create);
2356 create.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
2357 create.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
2358 create.dwHeight = 128;
2359 create.dwWidth = 128;
2360 hr = IDirectDraw_CreateSurface(lpDD, &create, &surface1, NULL);
2361 ok(hr == DD_OK, "Creating an offscreen plain surface failed with %08x\n", hr);
2362 hr = IDirectDrawSurface_QueryInterface(surface1, &IID_IDirectDrawSurface7, (void **) &surface7);
2363 ok(hr == DD_OK, "IDirectDrawSurface_QueryInterface failed with %08x\n", hr);
2365 desc.desc1.dwSize = sizeof(DDSURFACEDESC);
2366 hr = IDirectDrawSurface_GetSurfaceDesc(surface1, &desc.desc1);
2367 ok(hr == DD_OK, "IDirectDrawSurface_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC) returned %08x\n", hr);
2368 hr = IDirectDrawSurface7_GetSurfaceDesc(surface7, &desc.desc2);
2369 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC) returned %08x\n", hr);
2371 desc.desc2.dwSize = sizeof(DDSURFACEDESC2);
2372 hr = IDirectDrawSurface_GetSurfaceDesc(surface1, &desc.desc1);
2373 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC2) returned %08x\n", hr);
2374 hr = IDirectDrawSurface7_GetSurfaceDesc(surface7, &desc.desc2);
2375 ok(hr == DD_OK, "IDirectDrawSurface7_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC2) returned %08x\n", hr);
2377 desc.desc2.dwSize = 0;
2378 hr = IDirectDrawSurface_GetSurfaceDesc(surface1, &desc.desc1);
2379 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface_GetSurfaceDesc with desc size 0 returned %08x\n", hr);
2380 hr = IDirectDrawSurface7_GetSurfaceDesc(surface7, &desc.desc2);
2381 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_GetSurfaceDesc with desc size 0 returned %08x\n", hr);
2383 desc.desc1.dwSize = sizeof(DDSURFACEDESC) + 1;
2384 hr = IDirectDrawSurface_GetSurfaceDesc(surface1, &desc.desc1);
2385 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC) + 1 returned %08x\n", hr);
2386 hr = IDirectDrawSurface7_GetSurfaceDesc(surface7, &desc.desc2);
2387 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC) + 1 returned %08x\n", hr);
2389 desc.desc2.dwSize = sizeof(DDSURFACEDESC2) + 1;
2390 hr = IDirectDrawSurface_GetSurfaceDesc(surface1, &desc.desc1);
2391 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC2) + 1returned %08x\n", hr);
2392 hr = IDirectDrawSurface7_GetSurfaceDesc(surface7, &desc.desc2);
2393 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC2) + 1returned %08x\n", hr);
2395 /* Tests for Lock() */
2397 desc.desc1.dwSize = sizeof(DDSURFACEDESC);
2398 hr = IDirectDrawSurface_Lock(surface1, NULL, &desc.desc1, 0, 0);
2399 ok(hr == DD_OK, "IDirectDrawSurface_Lock with desc size sizeof(DDSURFACEDESC) returned %08x\n", hr);
2400 if(SUCCEEDED(hr)) IDirectDrawSurface_Unlock(surface1, NULL);
2401 ok(desc.desc1.dwSize == sizeof(DDSURFACEDESC), "Destination size was changed to %d\n", desc.desc1.dwSize);
2402 hr = IDirectDrawSurface7_Lock(surface7, NULL, &desc.desc2, 0, 0);
2403 ok(hr == DD_OK, "IDirectDrawSurface7_Lock with desc size sizeof(DDSURFACEDESC) returned %08x\n", hr);
2404 if(SUCCEEDED(hr)) IDirectDrawSurface7_Unlock(surface7, NULL);
2405 ok(desc.desc2.dwSize == sizeof(DDSURFACEDESC), "Destination size was changed to %d\n", desc.desc1.dwSize);
2407 desc.desc2.dwSize = sizeof(DDSURFACEDESC2);
2408 hr = IDirectDrawSurface_Lock(surface1, NULL, &desc.desc1, 0, 0);
2409 ok(hr == DD_OK, "IDirectDrawSurface_Lock with desc size sizeof(DDSURFACEDESC2) returned %08x\n", hr);
2410 ok(desc.desc1.dwSize == sizeof(DDSURFACEDESC2), "Destination size was changed to %d\n", desc.desc1.dwSize);
2411 if(SUCCEEDED(hr)) IDirectDrawSurface_Unlock(surface1, NULL);
2412 hr = IDirectDrawSurface7_Lock(surface7, NULL, &desc.desc2, 0, 0);
2413 ok(hr == DD_OK, "IDirectDrawSurface7_Lock with desc size sizeof(DDSURFACEDESC2) returned %08x\n", hr);
2414 if(SUCCEEDED(hr)) IDirectDrawSurface7_Unlock(surface7, NULL);
2415 ok(desc.desc2.dwSize == sizeof(DDSURFACEDESC2), "Destination size was changed to %d\n", desc.desc1.dwSize);
2417 desc.desc2.dwSize = 0;
2418 hr = IDirectDrawSurface_Lock(surface1, NULL, &desc.desc1, 0, 0);
2419 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface_Lock with desc size 0 returned %08x\n", hr);
2420 if(SUCCEEDED(hr)) IDirectDrawSurface_Unlock(surface1, NULL);
2421 hr = IDirectDrawSurface7_Lock(surface7, NULL, &desc.desc2, 0, 0);
2422 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_Lock with desc size 0 returned %08x\n", hr);
2423 if(SUCCEEDED(hr)) IDirectDrawSurface7_Unlock(surface7, NULL);
2425 desc.desc1.dwSize = sizeof(DDSURFACEDESC) + 1;
2426 hr = IDirectDrawSurface_Lock(surface1, NULL, &desc.desc1, 0, 0);
2427 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface_Lock with desc size sizeof(DDSURFACEDESC) + 1 returned %08x\n", hr);
2428 if(SUCCEEDED(hr)) IDirectDrawSurface_Unlock(surface1, NULL);
2429 hr = IDirectDrawSurface7_Lock(surface7, NULL, &desc.desc2, 0, 0);
2430 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_Lock with desc size sizeof(DDSURFACEDESC) + 1 returned %08x\n", hr);
2431 if(SUCCEEDED(hr)) IDirectDrawSurface7_Unlock(surface7, NULL);
2433 desc.desc2.dwSize = sizeof(DDSURFACEDESC2) + 1;
2434 hr = IDirectDrawSurface_Lock(surface1, NULL, &desc.desc1, 0, 0);
2435 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface_Lock with desc size sizeof(DDSURFACEDESC2) + 1returned %08x\n", hr);
2436 if(SUCCEEDED(hr)) IDirectDrawSurface_Unlock(surface1, NULL);
2437 hr = IDirectDrawSurface7_Lock(surface7, NULL, &desc.desc2, 0, 0);
2438 ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_Lock with desc size sizeof(DDSURFACEDESC2) + 1returned %08x\n", hr);
2439 if(SUCCEEDED(hr)) IDirectDrawSurface7_Unlock(surface7, NULL);
2441 IDirectDrawSurface7_Release(surface7);
2442 IDirectDrawSurface_Release(surface1);
2445 START_TEST(dsurface)
2447 if (!CreateDirectDraw())
2448 return;
2449 MipMapCreationTest();
2450 SrcColorKey32BlitTest();
2451 QueryInterface();
2452 GetDDInterface_1();
2453 GetDDInterface_2();
2454 GetDDInterface_4();
2455 GetDDInterface_7();
2456 EnumTest();
2457 AttachmentTest();
2458 AttachmentTest7();
2459 CubeMapTest();
2460 test_lockrect_invalid();
2461 CompressedTest();
2462 SizeTest();
2463 PrivateDataTest();
2464 BltParamTest();
2465 StructSizeTest();
2466 ReleaseDirectDraw();