ddraw: Some drivers return DDERR_INVALIDPARAMS if DXTn surfaces aren't supported.
[wine] / dlls / ddraw / tests / dsurface.c
1 /*
2  * Unit tests for (a few) ddraw surface functions
3  *
4  * Copyright (C) 2005 Antoine Chavasse (a.chavasse@gmail.com)
5  * Copyright (C) 2005 Christian Costa
6  * Copyright 2005 Ivan Leo Puoti
7  * Copyright (C) 2007 Stefan Dösinger
8  *
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.
13  *
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.
18  *
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
22  */
23 #define COBJMACROS
24
25 #include <assert.h>
26 #include "wine/test.h"
27 #include "ddraw.h"
28 #include "unknwn.h"
29
30 static LPDIRECTDRAW lpDD = NULL;
31
32 static BOOL CreateDirectDraw(void)
33 {
34     HRESULT rc;
35
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;
41     }
42
43     rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_NORMAL);
44     ok(rc==DD_OK,"SetCooperativeLevel returned: %x\n",rc);
45
46     return TRUE;
47 }
48
49
50 static void ReleaseDirectDraw(void)
51 {
52     if( lpDD != NULL )
53     {
54         IDirectDraw_Release(lpDD);
55         lpDD = NULL;
56     }
57 }
58
59 static void MipMapCreationTest(void)
60 {
61     LPDIRECTDRAWSURFACE lpDDSMipMapTest;
62     DDSURFACEDESC ddsd;
63     HRESULT rc;
64
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;
79     }
80
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);
90
91     /* Destroy the surface. */
92     IDirectDrawSurface_Release(lpDDSMipMapTest);
93
94
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;
109     }
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);
119
120     /* Destroy the surface. */
121     IDirectDrawSurface_Release(lpDDSMipMapTest);
122
123
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;
141     }
142
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);
152
153     /* Destroy the surface. */
154     IDirectDrawSurface_Release(lpDDSMipMapTest);
155
156
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;
172     }
173
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);
183
184     /* Destroy the surface. */
185     IDirectDrawSurface_Release(lpDDSMipMapTest);
186 }
187
188 static void SrcColorKey32BlitTest(void)
189 {
190     LPDIRECTDRAWSURFACE lpSrc;
191     LPDIRECTDRAWSURFACE lpDst;
192     DDSURFACEDESC ddsd, ddsd2, ddsd3;
193     DDCOLORKEY DDColorKey;
194     LPDWORD lpData;
195     HRESULT rc;
196     DDBLTFX fx;
197
198     ddsd2.dwSize = sizeof(ddsd2);
199     ddsd2.ddpfPixelFormat.dwSize = sizeof(ddsd2.ddpfPixelFormat);
200
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;
217     }
218
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;
227     }
228
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;
236
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);
243
244     rc = IDirectDrawSurface_Unlock(lpDst, NULL);
245     ok(rc==DD_OK,"Unlock returned: %x\n",rc);
246
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);
253
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);
264
265     IDirectDrawSurface_Blt(lpDst, NULL, lpSrc, NULL, DDBLT_KEYSRC, NULL);
266
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);
275
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");
280
281     DDColorKey.dwColorSpaceLowValue = 0x00FF00;
282     DDColorKey.dwColorSpaceHighValue = 0x00FF00;
283     IDirectDrawSurface_SetColorKey(lpSrc, DDCKEY_SRCBLT, &DDColorKey);
284
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");
290
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");
296
297     IDirectDrawSurface_Release(lpSrc);
298     IDirectDrawSurface_Release(lpDst);
299
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))
320     {
321         skip("Failed to create surface\n");
322         return;
323     }
324
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))
345     {
346         skip("Failed to create surface\n");
347         IDirectDrawSurface_Release(lpDst);
348         return;
349     }
350
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;
357
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);
370
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);
383
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);
387
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");
399
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);
408
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);
412
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;
417
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");
424
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);
433
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);
437
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;
442
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");
450
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);
459
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);
463
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;
469
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");
477
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);
486
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);
490
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;
495
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");
504
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);
513
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);
517
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;
522
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");
530
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);
539
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);
543
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;
549
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");
557
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);
566
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);
575
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);
579
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;
584
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");
592
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);
601
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);
607
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);
613
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);
617
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);
621
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
624      */
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);
629
630     IDirectDrawSurface_Release(lpSrc);
631     IDirectDrawSurface_Release(lpDst);
632 }
633
634 static void QueryInterface(void)
635 {
636     LPDIRECTDRAWSURFACE dsurface;
637     DDSURFACEDESC surface;
638     LPVOID object;
639     HRESULT ret;
640
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)
649     {
650         ok(FALSE, "IDirectDraw::CreateSurface failed with error %x\n", ret);
651         return;
652     }
653
654     /* Call IUnknown::QueryInterface */
655     ret = IDirectDrawSurface_QueryInterface(dsurface, 0, &object);
656     ok(ret == DDERR_INVALIDPARAMS, "IDirectDrawSurface::QueryInterface returned %x\n", ret);
657
658     IDirectDrawSurface_Release(dsurface);
659 }
660
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
664  */
665
666 static unsigned long getref(IUnknown *iface)
667 {
668     IUnknown_AddRef(iface);
669     return IUnknown_Release(iface);
670 }
671
672 static void GetDDInterface_1(void)
673 {
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;
683
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)
692     {
693         ok(FALSE, "IDirectDraw::CreateSurface failed with error %x\n", ret);
694         return;
695     }
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);
704
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);
713
714
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);
721
722     ok(dd == lpDD, "Returned interface pointer is not equal to the creation interface\n");
723     IUnknown_Release((IUnknown *) dd);
724
725     /* try a NULL pointer */
726     ret = IDirectDrawSurface2_GetDDInterface(dsurface2, NULL);
727     ok(ret == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_GetDDInterface returned %08x\n", ret);
728
729     IDirectDraw_Release(dd2);
730     IDirectDraw_Release(dd4);
731     IDirectDraw_Release(dd7);
732     IDirectDrawSurface2_Release(dsurface2);
733     IDirectDrawSurface_Release(dsurface);
734 }
735
736 static void GetDDInterface_2(void)
737 {
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;
747
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);
754
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)
763     {
764         ok(FALSE, "IDirectDraw::CreateSurface failed with error %x\n", ret);
765         return;
766     }
767     ret = IDirectDrawSurface_QueryInterface(dsurface, &IID_IDirectDrawSurface2, (void **) &dsurface2);
768     ok(ret == DD_OK, "IDirectDrawSurface_QueryInterface returned %08x\n", ret);
769
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);
778
779
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);
786
787     ok(dd == dd2, "Returned interface pointer is not equal to the creation interface\n");
788     IUnknown_Release((IUnknown *) dd);
789
790     IDirectDraw_Release(dd2);
791     IDirectDraw_Release(dd4);
792     IDirectDraw_Release(dd7);
793     IDirectDrawSurface2_Release(dsurface2);
794     IDirectDrawSurface_Release(dsurface);
795 }
796
797 static void GetDDInterface_4(void)
798 {
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;
808
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);
815
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)
824     {
825         ok(FALSE, "IDirectDraw::CreateSurface failed with error %x\n", ret);
826         return;
827     }
828     ret = IDirectDrawSurface4_QueryInterface(dsurface4, &IID_IDirectDrawSurface2, (void **) &dsurface2);
829     ok(ret == DD_OK, "IDirectDrawSurface_QueryInterface returned %08x\n", ret);
830
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);
839
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);
846
847     ok(dd == dd4, "Returned interface pointer is not equal to the creation interface\n");
848     IUnknown_Release((IUnknown *) dd);
849
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);
857
858     ok(dd == dd4, "Returned interface pointer is not equal to the creation interface\n");
859     IUnknown_Release((IUnknown *) dd);
860
861     IDirectDraw_Release(dd2);
862     IDirectDraw_Release(dd4);
863     IDirectDraw_Release(dd7);
864     IDirectDrawSurface4_Release(dsurface4);
865     IDirectDrawSurface2_Release(dsurface2);
866 }
867
868 static void GetDDInterface_7(void)
869 {
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;
879
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);
886
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)
895     {
896         ok(FALSE, "IDirectDraw::CreateSurface failed with error %x\n", ret);
897         return;
898     }
899     ret = IDirectDrawSurface7_QueryInterface(dsurface7, &IID_IDirectDrawSurface4, (void **) &dsurface4);
900     ok(ret == DD_OK, "IDirectDrawSurface_QueryInterface returned %08x\n", ret);
901
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);
910
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);
917
918     ok(dd == dd7, "Returned interface pointer is not equal to the creation interface\n");
919     IUnknown_Release((IUnknown *) dd);
920
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);
928
929     ok(dd == dd7, "Returned interface pointer is not equal to the creation interface\n");
930     IUnknown_Release((IUnknown *) dd);
931
932     IDirectDraw_Release(dd2);
933     IDirectDraw_Release(dd4);
934     IDirectDraw_Release(dd7);
935     IDirectDrawSurface4_Release(dsurface4);
936     IDirectDrawSurface7_Release(dsurface7);
937 }
938
939 #define MAXEXPECTED 8  /* Can match up to 8 expected surfaces */
940 struct enumstruct
941 {
942     IDirectDrawSurface *expected[MAXEXPECTED];
943     UINT count;
944 };
945
946 static HRESULT WINAPI enumCB(IDirectDrawSurface *surf, DDSURFACEDESC *desc, void *ctx)
947 {
948     int i;
949     BOOL found = FALSE;
950
951     for(i = 0; i < MAXEXPECTED; i++)
952     {
953         if(((struct enumstruct *)ctx)->expected[i] == surf) found = TRUE;
954     }
955
956     ok(found, "Unexpected surface %p enumerated\n", surf);
957     ((struct enumstruct *)ctx)->count++;
958     IDirectDrawSurface_Release(surf);
959     return DDENUMRET_OK;
960 }
961
962 static void EnumTest(void)
963 {
964     HRESULT rc;
965     DDSURFACEDESC ddsd;
966     IDirectDrawSurface *surface;
967     struct enumstruct ctx;
968
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);
977
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;
987
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);
991
992     IDirectDrawSurface_Release(ctx.expected[2]);
993     IDirectDrawSurface_Release(ctx.expected[1]);
994     IDirectDrawSurface_Release(surface);
995 }
996
997 HRESULT WINAPI SurfaceCounter(IDirectDrawSurface7 *surface, DDSURFACEDESC2 *desc, void *context)
998 {
999     UINT *num = context;
1000     (*num)++;
1001     IDirectDrawSurface_Release(surface);
1002     return DDENUMRET_OK;
1003 }
1004
1005 static void AttachmentTest7(void)
1006 {
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 );
1014
1015     hr = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
1016     ok(hr == DD_OK, "IDirectDraw_QueryInterface returned %08x\n", hr);
1017
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);
1027
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 */
1033
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 */
1041
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 */
1051
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);
1061
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);
1070
1071     IDirectDrawSurface7_Release(surface2);
1072
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);
1081
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);
1090
1091     IDirectDrawSurface7_Release(surface3);
1092     IDirectDrawSurface7_Release(surface2);
1093     IDirectDrawSurface7_Release(surface1);
1094
1095     hr = IDirectDraw7_SetCooperativeLevel(dd7, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
1096     ok(hr == DD_OK, "SetCooperativeLevel returned %08x\n", hr);
1097
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);
1105
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);
1110
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);
1124
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);
1132
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);
1141
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);
1150
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);
1160
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);
1171
1172     IDirectDrawSurface7_Release(surface4);
1173     IDirectDrawSurface7_Release(surface3);
1174     IDirectDrawSurface7_Release(surface2);
1175     IDirectDrawSurface7_Release(surface1);
1176
1177     hr =IDirectDraw7_SetCooperativeLevel(dd7, NULL, DDSCL_NORMAL);
1178     ok(hr == DD_OK, "SetCooperativeLevel returned %08x\n", hr);
1179     IDirectDraw7_Release(dd7);
1180 }
1181
1182 static void AttachmentTest(void)
1183 {
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 );
1189
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);
1199
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);
1204
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);
1214
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);
1227
1228     IDirectDrawSurface7_Release(surface4);
1229
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);
1238
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);
1257
1258     IDirectDrawSurface7_Release(surface4);
1259     IDirectDrawSurface7_Release(surface3);
1260     IDirectDrawSurface7_Release(surface2);
1261     IDirectDrawSurface7_Release(surface1);
1262
1263     hr = IDirectDraw_SetCooperativeLevel(lpDD, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
1264     ok(hr == DD_OK, "SetCooperativeLevel returned %08x\n", hr);
1265
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);
1281
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);
1289
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);
1298
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);
1307
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);
1317
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))
1336     {
1337         hr = IDirectDrawSurface_DeleteAttachedSurface(surface2, 0, surface3);
1338         ok(hr == DD_OK, "DeleteAttachedSurface failed with %08x\n", hr);
1339     }
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);
1344
1345     IDirectDrawSurface_Release(surface4);
1346     IDirectDrawSurface_Release(surface3);
1347     IDirectDrawSurface_Release(surface2);
1348     IDirectDrawSurface_Release(surface1);
1349
1350     hr =IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_NORMAL);
1351     ok(hr == DD_OK, "SetCooperativeLevel returned %08x\n", hr);
1352
1353     DestroyWindow(window);
1354 }
1355
1356 struct compare
1357 {
1358     DWORD width, height;
1359     DWORD caps, caps2;
1360     UINT mips;
1361 };
1362
1363 HRESULT WINAPI CubeTestLvl2Enum(IDirectDrawSurface7 *surface, DDSURFACEDESC2 *desc, void *context)
1364 {
1365     UINT *mips = context;
1366
1367     (*mips)++;
1368     IDirectDrawSurface7_EnumAttachedSurfaces(surface,
1369                                              context,
1370                                              CubeTestLvl2Enum);
1371
1372     return DDENUMRET_OK;
1373 }
1374
1375 HRESULT WINAPI CubeTestLvl1Enum(IDirectDrawSurface7 *surface, DDSURFACEDESC2 *desc, void *context)
1376 {
1377     UINT mips = 0;
1378     UINT *num = (UINT *) context;
1379     static const struct compare expected[] =
1380     {
1381         {
1382             128, 128,
1383             DDSCAPS_MIPMAP | DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_COMPLEX,
1384             DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEZ,
1385             7
1386         },
1387         {
1388             128, 128,
1389             DDSCAPS_MIPMAP | DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_COMPLEX,
1390             DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEZ,
1391             7
1392         },
1393         {
1394             128, 128,
1395             DDSCAPS_MIPMAP | DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_COMPLEX,
1396             DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEY,
1397             7
1398         },
1399         {
1400             128, 128,
1401             DDSCAPS_MIPMAP | DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_COMPLEX,
1402             DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEY,
1403             7
1404         },
1405         {
1406             128, 128,
1407             DDSCAPS_MIPMAP | DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_COMPLEX,
1408             DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEX,
1409             7
1410         },
1411         {
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,
1415             6
1416         },
1417     };
1418
1419     mips = 0;
1420     IDirectDrawSurface7_EnumAttachedSurfaces(surface,
1421                                              &mips,
1422                                              CubeTestLvl2Enum);
1423
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);
1429
1430     (*num)++;
1431
1432     IDirectDrawSurface7_Release(surface);
1433
1434     return DDENUMRET_OK;
1435 }
1436
1437 static void CubeMapTest(void)
1438 {
1439     IDirectDraw7 *dd7 = NULL;
1440     IDirectDrawSurface7 *cubemap;
1441     DDSURFACEDESC2 ddsd;
1442     HRESULT hr;
1443     UINT num = 0;
1444     struct enumstruct ctx;
1445
1446     hr = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
1447     ok(hr == DD_OK, "IDirectDraw::QueryInterface returned %08x\n", hr);
1448
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;
1457
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;
1464
1465     hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &cubemap, NULL);
1466     ok(hr == DD_OK, "IDirectDraw7::CreateSurface returned %08x\n", hr);
1467
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);
1474
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);
1481
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;
1491
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;
1498
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);
1501
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;
1511
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;
1518
1519     hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &cubemap, NULL);
1520     ok(hr == DDERR_INVALIDCAPS, "IDirectDraw7::CreateSurface returned %08x\n", hr);
1521
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;
1530
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;
1537
1538     hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &cubemap, NULL);
1539     ok(hr == DDERR_INVALIDCAPS, "IDirectDraw7::CreateSurface returned %08x\n", hr);
1540
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);
1548
1549     IDirectDraw7_Release(dd7);
1550 }
1551
1552 static void test_lockrect_invalid(void)
1553 {
1554     unsigned int i, j;
1555
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},
1562     };
1563
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 */
1575     };
1576
1577     const DWORD dds_caps[] = {
1578         DDSCAPS_OFFSCREENPLAIN,
1579         DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE,
1580     };
1581
1582     for (j = 0; j < (sizeof(dds_caps) / sizeof(*dds_caps)); ++j)
1583     {
1584         IDirectDrawSurface *surface = 0;
1585         DDSURFACEDESC surface_desc = {0};
1586         DDSURFACEDESC locked_desc = {0};
1587         HRESULT hr;
1588
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;
1600
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;
1606         }
1607
1608         for (i = 0; i < (sizeof(valid) / sizeof(*valid)); ++i)
1609         {
1610             RECT *rect = &valid[i];
1611
1612             memset(&locked_desc, 0, sizeof(locked_desc));
1613             locked_desc.dwSize = sizeof(locked_desc);
1614
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);
1618
1619             hr = IDirectDrawSurface_Unlock(surface, NULL);
1620             ok(SUCCEEDED(hr), "Unlock failed (0x%08x)\n", hr);
1621         }
1622
1623         for (i = 0; i < (sizeof(invalid) / sizeof(*invalid)); ++i)
1624         {
1625             RECT *rect = &invalid[i];
1626
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);
1631         }
1632
1633         IDirectDrawSurface_Release(surface);
1634     }
1635 }
1636
1637 static void CompressedTest(void)
1638 {
1639     HRESULT hr;
1640     IDirectDrawSurface7 *surface;
1641     DDSURFACEDESC2 ddsd, ddsd2;
1642     IDirectDraw7 *dd7 = NULL;
1643     RECT r = { 0, 0, 128, 128 };
1644     RECT r2 = { 32, 32, 64, 64 };
1645
1646     hr = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
1647     ok(hr == DD_OK, "IDirectDraw::QueryInterface returned %08x\n", hr);
1648
1649     memset(&ddsd, 0, sizeof(ddsd));
1650     ddsd.dwSize = sizeof(ddsd);
1651     U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
1652     ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS;
1653     ddsd.dwWidth = 128;
1654     ddsd.dwHeight = 128;
1655     ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY;
1656     U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_FOURCC;
1657     U4(ddsd).ddpfPixelFormat.dwFourCC = MAKEFOURCC('D','X','T','1');
1658
1659     hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface, NULL);
1660     ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
1661     if (FAILED(hr)) {
1662         skip("failed to create surface\n");
1663         return;
1664     }
1665
1666     memset(&ddsd2, 0, sizeof(ddsd2));
1667     ddsd2.dwSize = sizeof(ddsd2);
1668     U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
1669     hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd2);
1670     ok(hr == DD_OK, "GetSurfaceDesc returned %08x\n", hr);
1671
1672     ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
1673        "Surface desc flags: %08x\n", ddsd2.dwFlags);
1674     ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
1675     ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
1676     ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
1677        "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
1678     ok(U1(ddsd2).dwLinearSize == 8192, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
1679     ok(ddsd2.ddsCaps.dwCaps2 == 0, "Caps2: %08x\n", ddsd2.ddsCaps.dwCaps2);
1680     IDirectDrawSurface7_Release(surface);
1681
1682     U4(ddsd).ddpfPixelFormat.dwFourCC = MAKEFOURCC('D','X','T','3');
1683     hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface, NULL);
1684     ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
1685     if (FAILED(hr)) {
1686         skip("failed to create surface\n");
1687         return;
1688     }
1689
1690     memset(&ddsd2, 0, sizeof(ddsd2));
1691     ddsd2.dwSize = sizeof(ddsd2);
1692     U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
1693     hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd2);
1694     ok(hr == DD_OK, "GetSurfaceDesc returned %08x\n", hr);
1695
1696     ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
1697        "Surface desc flags: %08x\n", ddsd2.dwFlags);
1698     ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
1699     ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
1700     ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
1701        "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
1702     ok(U1(ddsd2).dwLinearSize == 16384, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
1703     IDirectDrawSurface7_Release(surface);
1704
1705     U4(ddsd).ddpfPixelFormat.dwFourCC = MAKEFOURCC('D','X','T','5');
1706     hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface, NULL);
1707     ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
1708     if (FAILED(hr)) {
1709         skip("failed to create surface\n");
1710         return;
1711     }
1712
1713     memset(&ddsd2, 0, sizeof(ddsd2));
1714     ddsd2.dwSize = sizeof(ddsd2);
1715     U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
1716     hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd2);
1717     ok(hr == DD_OK, "GetSurfaceDesc returned %08x\n", hr);
1718
1719     ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
1720        "Surface desc flags: %08x\n", ddsd2.dwFlags);
1721     ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
1722     ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
1723     ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
1724        "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
1725     ok(U1(ddsd2).dwLinearSize == 16384, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
1726     ok(ddsd2.lpSurface == 0, "Surface memory is at %p, expected NULL\n", ddsd2.lpSurface);
1727
1728     memset(&ddsd2, 0, sizeof(ddsd2));
1729     ddsd2.dwSize = sizeof(ddsd2);
1730     U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
1731
1732     /* Show that the description is not changed when locking the surface. What is really interesting
1733      * about this is that DDSD_LPSURFACE isn't set.
1734      */
1735     hr = IDirectDrawSurface7_Lock(surface, NULL, &ddsd2, DDLOCK_READONLY, 0);
1736     ok(hr == DD_OK, "Lock returned %08x\n", hr);
1737
1738     ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
1739        "Surface desc flags: %08x\n", ddsd2.dwFlags);
1740     ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
1741     ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
1742     ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
1743        "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
1744     ok(U1(ddsd2).dwLinearSize == 16384, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
1745     ok(ddsd2.lpSurface != 0, "Surface memory is at NULL\n");
1746
1747     hr = IDirectDrawSurface7_Unlock(surface, NULL);
1748     ok(hr == DD_OK, "Unlock returned %08x\n", hr);
1749
1750     /* Now what about a locking rect?  */
1751     hr = IDirectDrawSurface7_Lock(surface, &r, &ddsd2, DDLOCK_READONLY, 0);
1752     ok(hr == DD_OK, "Lock returned %08x\n", hr);
1753
1754     ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
1755        "Surface desc flags: %08x\n", ddsd2.dwFlags);
1756     ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
1757     ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
1758     ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
1759        "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
1760     ok(U1(ddsd2).dwLinearSize == 16384, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
1761     ok(ddsd2.lpSurface != 0, "Surface memory is at NULL\n");
1762
1763     hr = IDirectDrawSurface7_Unlock(surface, &r);
1764     ok(hr == DD_OK, "Unlock returned %08x\n", hr);
1765
1766     /* Now what about a different locking offset? */
1767     hr = IDirectDrawSurface7_Lock(surface, &r2, &ddsd2, DDLOCK_READONLY, 0);
1768     ok(hr == DD_OK, "Lock returned %08x\n", hr);
1769
1770     ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
1771        "Surface desc flags: %08x\n", ddsd2.dwFlags);
1772     ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
1773     ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
1774     ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
1775        "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
1776     ok(U1(ddsd2).dwLinearSize == 16384, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
1777     ok(ddsd2.lpSurface != 0, "Surface memory is at NULL\n");
1778
1779     hr = IDirectDrawSurface7_Unlock(surface, &r2);
1780     ok(hr == DD_OK, "Unlock returned %08x\n", hr);
1781     IDirectDrawSurface7_Release(surface);
1782
1783     /* Try this with video memory. A kind of surprise. It still has the LINEARSIZE flag set,
1784      * but seems to have a pitch instead.
1785      */
1786     ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY;
1787     U4(ddsd).ddpfPixelFormat.dwFourCC = MAKEFOURCC('D','X','T','1');
1788
1789     hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface, NULL);
1790     ok(hr == DD_OK || hr == DDERR_NOTEXTUREHW || hr == DDERR_INVALIDPARAMS,
1791        "CreateSurface returned %08x\n", hr);
1792
1793     /* Not supported everywhere */
1794     if(SUCCEEDED(hr))
1795     {
1796         memset(&ddsd2, 0, sizeof(ddsd2));
1797         ddsd2.dwSize = sizeof(ddsd2);
1798         U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
1799         hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd2);
1800         ok(hr == DD_OK, "GetSurfaceDesc returned %08x\n", hr);
1801
1802         ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
1803         "Surface desc flags: %08x\n", ddsd2.dwFlags);
1804         ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
1805         ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
1806         ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM),
1807         "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
1808         /* ATI drivers report a broken linear size, thus no need to clone the exact behaviour. nvidia reports the correct size */
1809         ok(ddsd2.ddsCaps.dwCaps2 == 0, "Caps2: %08x\n", ddsd2.ddsCaps.dwCaps2);
1810         IDirectDrawSurface7_Release(surface);
1811
1812         U4(ddsd).ddpfPixelFormat.dwFourCC = MAKEFOURCC('D','X','T','3');
1813         hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface, NULL);
1814         ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
1815
1816         memset(&ddsd2, 0, sizeof(ddsd2));
1817         ddsd2.dwSize = sizeof(ddsd2);
1818         U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
1819         hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd2);
1820         ok(hr == DD_OK, "GetSurfaceDesc returned %08x\n", hr);
1821
1822         ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
1823         "Surface desc flags: %08x\n", ddsd2.dwFlags);
1824         ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
1825         ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
1826         ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM),
1827         "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
1828         /* ATI drivers report a broken linear size, thus no need to clone the exact behaviour. nvidia reports the correct size */
1829         IDirectDrawSurface7_Release(surface);
1830
1831         U4(ddsd).ddpfPixelFormat.dwFourCC = MAKEFOURCC('D','X','T','5');
1832         hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface, NULL);
1833         ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
1834
1835         memset(&ddsd2, 0, sizeof(ddsd2));
1836         ddsd2.dwSize = sizeof(ddsd2);
1837         U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
1838         hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd2);
1839         ok(hr == DD_OK, "GetSurfaceDesc returned %08x\n", hr);
1840
1841         ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
1842         "Surface desc flags: %08x\n", ddsd2.dwFlags);
1843         ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
1844         ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
1845         ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM),
1846         "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
1847         /* ATI drivers report a broken linear size, thus no need to clone the exact behaviour. nvidia reports the correct size */
1848         ok(ddsd2.lpSurface == 0, "Surface memory is at %p, expected NULL\n", ddsd2.lpSurface);
1849
1850         memset(&ddsd2, 0, sizeof(ddsd2));
1851         ddsd2.dwSize = sizeof(ddsd2);
1852         U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
1853
1854         /* Show that the description is not changed when locking the surface. What is really interesting
1855         * about this is that DDSD_LPSURFACE isn't set.
1856         */
1857         hr = IDirectDrawSurface7_Lock(surface, NULL, &ddsd2, DDLOCK_READONLY, 0);
1858         ok(hr == DD_OK, "Lock returned %08x\n", hr);
1859
1860         ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
1861         "Surface desc flags: %08x\n", ddsd2.dwFlags);
1862         ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
1863         ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
1864         ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM),
1865         "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
1866         /* ATI drivers report a broken linear size, thus no need to clone the exact behaviour. nvidia reports the correct size */
1867         ok(ddsd2.lpSurface != 0, "Surface memory is at NULL\n");
1868
1869         hr = IDirectDrawSurface7_Unlock(surface, NULL);
1870         ok(hr == DD_OK, "Unlock returned %08x\n", hr);
1871
1872         /* Now what about a locking rect?  */
1873         hr = IDirectDrawSurface7_Lock(surface, &r, &ddsd2, DDLOCK_READONLY, 0);
1874         ok(hr == DD_OK, "Lock returned %08x\n", hr);
1875
1876         ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
1877         "Surface desc flags: %08x\n", ddsd2.dwFlags);
1878         ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
1879         ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
1880         ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM),
1881         "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
1882         /* ATI drivers report a broken linear size, thus no need to clone the exact behaviour. nvidia reports the correct size */
1883         ok(ddsd2.lpSurface != 0, "Surface memory is at NULL\n");
1884
1885         hr = IDirectDrawSurface7_Unlock(surface, &r);
1886         ok(hr == DD_OK, "Unlock returned %08x\n", hr);
1887
1888         /* Now what about a different locking offset? */
1889         hr = IDirectDrawSurface7_Lock(surface, &r2, &ddsd2, DDLOCK_READONLY, 0);
1890         ok(hr == DD_OK, "Lock returned %08x\n", hr);
1891
1892         ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
1893         "Surface desc flags: %08x\n", ddsd2.dwFlags);
1894         ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
1895         ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
1896         ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM),
1897         "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
1898         /* ATI drivers report a broken linear size, thus no need to clone the exact behaviour. nvidia reports the correct size */
1899         ok(ddsd2.lpSurface != 0, "Surface memory is at NULL\n");
1900
1901         hr = IDirectDrawSurface7_Unlock(surface, &r2);
1902         ok(hr == DD_OK, "Unlock returned %08x\n", hr);
1903
1904         IDirectDrawSurface7_Release(surface);
1905     }
1906     else
1907     {
1908         skip("Hardware DXTN textures not supported\n");
1909     }
1910
1911     /* What happens to managed textures? Interestingly, Windows reports them as being in system
1912      * memory. The linear size fits again.
1913      */
1914     ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1915     ddsd.ddsCaps.dwCaps2 = DDSCAPS2_TEXTUREMANAGE;
1916     U4(ddsd).ddpfPixelFormat.dwFourCC = MAKEFOURCC('D','X','T','1');
1917
1918     hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface, NULL);
1919     ok(hr == DD_OK || hr == DDERR_NOTEXTUREHW, "CreateSurface returned %08x\n", hr);
1920
1921     /* Not supported everywhere */
1922     if(SUCCEEDED(hr))
1923     {
1924         memset(&ddsd2, 0, sizeof(ddsd2));
1925         ddsd2.dwSize = sizeof(ddsd2);
1926         U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
1927         hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd2);
1928         ok(hr == DD_OK, "GetSurfaceDesc returned %08x\n", hr);
1929
1930         ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
1931         "Surface desc flags: %08x\n", ddsd2.dwFlags);
1932         ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
1933         ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
1934         ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
1935         "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
1936         ok(U1(ddsd2).dwLinearSize == 8192, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
1937         ok(ddsd2.ddsCaps.dwCaps2 == DDSCAPS2_TEXTUREMANAGE, "Caps2: %08x\n", ddsd2.ddsCaps.dwCaps2);
1938         IDirectDrawSurface7_Release(surface);
1939
1940         U4(ddsd).ddpfPixelFormat.dwFourCC = MAKEFOURCC('D','X','T','3');
1941         hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface, NULL);
1942         ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
1943
1944         memset(&ddsd2, 0, sizeof(ddsd2));
1945         ddsd2.dwSize = sizeof(ddsd2);
1946         U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
1947         hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd2);
1948         ok(hr == DD_OK, "GetSurfaceDesc returned %08x\n", hr);
1949
1950         ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
1951         "Surface desc flags: %08x\n", ddsd2.dwFlags);
1952         ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
1953         ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
1954         ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
1955         "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
1956         ok(U1(ddsd2).dwLinearSize == 16384, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
1957         IDirectDrawSurface7_Release(surface);
1958
1959         U4(ddsd).ddpfPixelFormat.dwFourCC = MAKEFOURCC('D','X','T','5');
1960         hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface, NULL);
1961         ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
1962
1963         memset(&ddsd2, 0, sizeof(ddsd2));
1964         ddsd2.dwSize = sizeof(ddsd2);
1965         U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
1966         hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd2);
1967         ok(hr == DD_OK, "GetSurfaceDesc returned %08x\n", hr);
1968
1969         ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
1970         "Surface desc flags: %08x\n", ddsd2.dwFlags);
1971         ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
1972         ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
1973         ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
1974         "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
1975         ok(U1(ddsd2).dwLinearSize == 16384, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
1976         ok(ddsd2.lpSurface == 0, "Surface memory is at %p, expected NULL\n", ddsd2.lpSurface);
1977
1978         memset(&ddsd2, 0, sizeof(ddsd2));
1979         ddsd2.dwSize = sizeof(ddsd2);
1980         U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
1981
1982         /* Show that the description is not changed when locking the surface. What is really interesting
1983         * about this is that DDSD_LPSURFACE isn't set.
1984         */
1985         hr = IDirectDrawSurface7_Lock(surface, NULL, &ddsd2, DDLOCK_READONLY, 0);
1986         ok(hr == DD_OK, "Lock returned %08x\n", hr);
1987
1988         ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
1989         "Surface desc flags: %08x\n", ddsd2.dwFlags);
1990         ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
1991         ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
1992         ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
1993         "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
1994         ok(U1(ddsd2).dwLinearSize == 16384, "Linear size is %d\n", U1(ddsd2).dwLinearSize);
1995         ok(ddsd2.lpSurface != 0, "Surface memory is at NULL\n");
1996
1997         hr = IDirectDrawSurface7_Unlock(surface, NULL);
1998         ok(hr == DD_OK, "Unlock returned %08x\n", hr);
1999
2000         /* Now what about a locking rect?  */
2001         hr = IDirectDrawSurface7_Lock(surface, &r, &ddsd2, DDLOCK_READONLY, 0);
2002         ok(hr == DD_OK, "Lock returned %08x\n", hr);
2003
2004         ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
2005         "Surface desc flags: %08x\n", ddsd2.dwFlags);
2006         ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
2007         ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
2008         ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
2009         "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
2010         ok(U1(ddsd2).dwLinearSize == 16384, "\"Linear\" size is %d\n", U1(ddsd2).dwLinearSize);
2011         ok(ddsd2.lpSurface != 0, "Surface memory is at NULL\n");
2012
2013         hr = IDirectDrawSurface7_Unlock(surface, &r);
2014         ok(hr == DD_OK, "Unlock returned %08x\n", hr);
2015
2016         /* Now what about a different locking offset? */
2017         hr = IDirectDrawSurface7_Lock(surface, &r2, &ddsd2, DDLOCK_READONLY, 0);
2018         ok(hr == DD_OK, "Lock returned %08x\n", hr);
2019
2020         ok(ddsd2.dwFlags == (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_LINEARSIZE),
2021         "Surface desc flags: %08x\n", ddsd2.dwFlags);
2022         ok(U4(ddsd2).ddpfPixelFormat.dwFlags == DDPF_FOURCC, "Pixel format flags: %08x\n", U4(ddsd2).ddpfPixelFormat.dwFlags);
2023         ok(U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount == 0, "RGB bitcount: %08x\n", U1(U4(ddsd2).ddpfPixelFormat).dwRGBBitCount);
2024         ok(ddsd2.ddsCaps.dwCaps == (DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY),
2025         "Surface caps flags: %08x\n", ddsd2.ddsCaps.dwCaps);
2026         ok(U1(ddsd2).dwLinearSize == 16384, "\"Linear\" size is %d\n", U1(ddsd2).dwLinearSize);
2027         ok(ddsd2.lpSurface != 0, "Surface memory is at NULL\n");
2028
2029         hr = IDirectDrawSurface7_Unlock(surface, &r2);
2030         ok(hr == DD_OK, "Unlock returned %08x\n", hr);
2031
2032         IDirectDrawSurface7_Release(surface);
2033     }
2034     else
2035     {
2036         skip("Hardware DXTN textures not supported\n");
2037     }
2038
2039     IDirectDraw7_Release(dd7);
2040 }
2041
2042 static void SizeTest(void)
2043 {
2044     LPDIRECTDRAWSURFACE dsurface = NULL;
2045     DDSURFACEDESC desc;
2046     HRESULT ret;
2047     HWND window = CreateWindow( "static", "ddraw_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
2048
2049     /* Create an offscreen surface surface without a size */
2050     ZeroMemory(&desc, sizeof(desc));
2051     desc.dwSize = sizeof(desc);
2052     desc.dwFlags = DDSD_CAPS;
2053     desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
2054     trace("before offscreenplain create dsurface = %p\n", dsurface);
2055     ret = IDirectDraw_CreateSurface(lpDD, &desc, &dsurface, NULL);
2056     ok(ret == DDERR_INVALIDPARAMS, "Creating an offscreen plain surface without a size info returned %08x (dsurface=%p)\n", ret, dsurface);
2057     if(dsurface)
2058     {
2059         trace("Surface at %p\n", dsurface);
2060         IDirectDrawSurface_Release(dsurface);
2061         dsurface = NULL;
2062     }
2063
2064     /* Create an offscreen surface surface with only a width parameter */
2065     ZeroMemory(&desc, sizeof(desc));
2066     desc.dwSize = sizeof(desc);
2067     desc.dwFlags = DDSD_CAPS | DDSD_WIDTH;
2068     desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
2069     desc.dwWidth = 128;
2070     ret = IDirectDraw_CreateSurface(lpDD, &desc, &dsurface, NULL);
2071     ok(ret == DDERR_INVALIDPARAMS, "Creating an offscreen plain surface without hight info returned %08x\n", ret);
2072     if(dsurface)
2073     {
2074         IDirectDrawSurface_Release(dsurface);
2075         dsurface = NULL;
2076     }
2077
2078     /* Create an offscreen surface surface with only a height parameter */
2079     ZeroMemory(&desc, sizeof(desc));
2080     desc.dwSize = sizeof(desc);
2081     desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT;
2082     desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
2083     desc.dwHeight = 128;
2084     ret = IDirectDraw_CreateSurface(lpDD, &desc, &dsurface, NULL);
2085     ok(ret == DDERR_INVALIDPARAMS, "Creating an offscreen plain surface without width info returned %08x\n", ret);
2086     if(dsurface)
2087     {
2088         IDirectDrawSurface_Release(dsurface);
2089         dsurface = NULL;
2090     }
2091
2092     /* Sanity check */
2093     ZeroMemory(&desc, sizeof(desc));
2094     desc.dwSize = sizeof(desc);
2095     desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
2096     desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
2097     desc.dwHeight = 128;
2098     desc.dwWidth = 128;
2099     ret = IDirectDraw_CreateSurface(lpDD, &desc, &dsurface, NULL);
2100     ok(ret == DD_OK, "Creating an offscreen plain surface with width and height info returned %08x\n", ret);
2101     if(dsurface)
2102     {
2103         IDirectDrawSurface_Release(dsurface);
2104         dsurface = NULL;
2105     }
2106
2107     /* Test a primary surface size */
2108     ret = IDirectDraw_SetCooperativeLevel(lpDD, window, DDSCL_NORMAL);
2109     ok(ret == DD_OK, "SetCooperativeLevel failed with %08x\n", ret);
2110
2111     ZeroMemory(&desc, sizeof(desc));
2112     desc.dwSize = sizeof(desc);
2113     desc.dwFlags = DDSD_CAPS;
2114     desc.ddsCaps.dwCaps |= DDSCAPS_PRIMARYSURFACE;
2115     desc.dwHeight = 128; /* Keep them set to  check what happens */
2116     desc.dwWidth = 128; /* Keep them set to  check what happens */
2117     ret = IDirectDraw_CreateSurface(lpDD, &desc, &dsurface, NULL);
2118     ok(ret == DD_OK, "Creating a primary surface without width and height info returned %08x\n", ret);
2119     if(dsurface)
2120     {
2121         ret = IDirectDrawSurface_GetSurfaceDesc(dsurface, &desc);
2122         ok(ret == DD_OK, "GetSurfaceDesc returned %x\n", ret);
2123
2124         IDirectDrawSurface_Release(dsurface);
2125         dsurface = NULL;
2126
2127         ok(desc.dwFlags & DDSD_WIDTH, "Primary surface doesn't have width set\n");
2128         ok(desc.dwFlags & DDSD_HEIGHT, "Primary surface doesn't have height set\n");
2129         ok(desc.dwWidth == GetSystemMetrics(SM_CXSCREEN), "Surface width differs from screen width\n");
2130         ok(desc.dwHeight == GetSystemMetrics(SM_CYSCREEN), "Surface height differs from screen height\n");
2131     }
2132     ret = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_NORMAL);
2133     ok(ret == DD_OK, "SetCooperativeLevel failed with %08x\n", ret);
2134 }
2135
2136 static void PrivateDataTest(void)
2137 {
2138     HRESULT hr;
2139     IDirectDrawSurface7 *surface7 = NULL;
2140     IDirectDrawSurface *surface = NULL;
2141     DDSURFACEDESC desc;
2142     ULONG ref, ref2;
2143     IUnknown *ptr;
2144     DWORD size = sizeof(IUnknown *);
2145
2146     ZeroMemory(&desc, sizeof(desc));
2147     desc.dwSize = sizeof(desc);
2148     desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
2149     desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
2150     desc.dwHeight = 128;
2151     desc.dwWidth = 128;
2152     hr = IDirectDraw_CreateSurface(lpDD, &desc, &surface, NULL);
2153     ok(hr == DD_OK, "Creating an offscreen plain surface failed with %08x\n", hr);
2154     if(!surface)
2155     {
2156         return;
2157     }
2158     hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirectDrawSurface7, (void **) &surface7);
2159     ok(hr == DD_OK, "IDirectDrawSurface_QueryInterface failed with %08x\n", hr);
2160     if(!surface)
2161     {
2162         IDirectDrawSurface_Release(surface);
2163         return;
2164     }
2165
2166     /* This fails */
2167     hr = IDirectDrawSurface7_SetPrivateData(surface7, &IID_IDirectDrawSurface7 /* Abuse this tag */, lpDD, 0, DDSPD_IUNKNOWNPOINTER);
2168     ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr);
2169     hr = IDirectDrawSurface7_SetPrivateData(surface7, &IID_IDirectDrawSurface7 /* Abuse this tag */, lpDD, 5, DDSPD_IUNKNOWNPOINTER);
2170     ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr);
2171     hr = IDirectDrawSurface7_SetPrivateData(surface7, &IID_IDirectDrawSurface7 /* Abuse this tag */, lpDD, sizeof(IUnknown *) * 2, DDSPD_IUNKNOWNPOINTER);
2172     ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr);
2173
2174     ref = getref((IUnknown *) lpDD);
2175     hr = IDirectDrawSurface7_SetPrivateData(surface7, &IID_IDirectDrawSurface7 /* Abuse this tag */, lpDD, sizeof(IUnknown *), DDSPD_IUNKNOWNPOINTER);
2176     ok(hr == DD_OK, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr);
2177     ref2 = getref((IUnknown *) lpDD);
2178     ok(ref2 == ref + 1, "Object reference is %d, expected %d\n", ref2, ref + 1);
2179     hr = IDirectDrawSurface7_FreePrivateData(surface7, &IID_IDirectDrawSurface7);
2180     ref2 = getref((IUnknown *) lpDD);
2181     ok(ref2 == ref, "Object reference is %d, expected %d\n", ref2, ref);
2182
2183     hr = IDirectDrawSurface7_SetPrivateData(surface7, &IID_IDirectDrawSurface7, lpDD, sizeof(IUnknown *), DDSPD_IUNKNOWNPOINTER);
2184     ok(hr == DD_OK, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr);
2185     hr = IDirectDrawSurface7_SetPrivateData(surface7, &IID_IDirectDrawSurface7, surface7, sizeof(IUnknown *), DDSPD_IUNKNOWNPOINTER);
2186     ok(hr == DD_OK, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr);
2187     ref2 = getref((IUnknown *) lpDD);
2188     ok(ref2 == ref, "Object reference is %d, expected %d\n", ref2, ref);
2189
2190     hr = IDirectDrawSurface7_SetPrivateData(surface7, &IID_IDirectDrawSurface7, lpDD, sizeof(IUnknown *), DDSPD_IUNKNOWNPOINTER);
2191     ok(hr == DD_OK, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr);
2192     hr = IDirectDrawSurface7_GetPrivateData(surface7, &IID_IDirectDrawSurface7, &ptr, &size);
2193     ok(hr == DD_OK, "IDirectDrawSurface7_GetPrivateData failed with %08x\n", hr);
2194     ref2 = getref((IUnknown *) lpDD);
2195     /* Object is NOT beein addrefed */
2196     ok(ptr == (IUnknown *) lpDD, "Returned interface pointer is %p, expected %p\n", ptr, lpDD);
2197     ok(ref2 == ref + 1, "Object reference is %d, expected %d. ptr at %p, orig at %p\n", ref2, ref + 1, ptr, lpDD);
2198
2199     IDirectDrawSurface_Release(surface);
2200     IDirectDrawSurface7_Release(surface7);
2201
2202     /* Destroying the surface frees the held reference */
2203     ref2 = getref((IUnknown *) lpDD);
2204     ok(ref2 == ref, "Object reference is %d, expected %d\n", ref2, ref);
2205 }
2206
2207 static void BltParamTest(void)
2208 {
2209     IDirectDrawSurface *surface1 = NULL, *surface2 = NULL;
2210     DDSURFACEDESC desc;
2211     HRESULT hr;
2212     DDBLTFX BltFx;
2213     RECT valid = {10, 10, 20, 20};
2214     RECT invalid1 = {20, 10, 10, 20};
2215     RECT invalid2 = {20, 20, 20, 20};
2216     RECT invalid3 = {-1, -1, 20, 20};
2217     RECT invalid4 = {60, 60, 70, 70};
2218
2219     memset(&desc, 0, sizeof(desc));
2220     desc.dwSize = sizeof(desc);
2221     desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
2222     desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
2223     desc.dwHeight = 128;
2224     desc.dwWidth = 128;
2225     hr = IDirectDraw_CreateSurface(lpDD, &desc, &surface1, NULL);
2226     ok(hr == DD_OK, "Creating an offscreen plain surface failed with %08x\n", hr);
2227
2228     desc.dwHeight = 64;
2229     desc.dwWidth = 64;
2230     hr = IDirectDraw_CreateSurface(lpDD, &desc, &surface2, NULL);
2231     ok(hr == DD_OK, "Creating an offscreen plain surface failed with %08x\n", hr);
2232
2233     if(0)
2234     {
2235         /* This crashes */
2236         hr = IDirectDrawSurface_BltFast(surface1, 0, 0, NULL, NULL, 0);
2237         ok(hr == DD_OK, "BltFast from NULL surface returned %08x\n", hr);
2238     }
2239     hr = IDirectDrawSurface_BltFast(surface1, 0, 0, surface2, NULL, 0);
2240     ok(hr == DD_OK, "BltFast from smaller to bigger surface returned %08x\n", hr);
2241     hr = IDirectDrawSurface_BltFast(surface2, 0, 0, surface1, NULL, 0);
2242     ok(hr == DDERR_INVALIDRECT, "BltFast from bigger to smaller surface returned %08x\n", hr);
2243     hr = IDirectDrawSurface_BltFast(surface2, 0, 0, surface1, &valid, 0);
2244     ok(hr == DD_OK, "BltFast from bigger to smaller surface using a valid rectangle returned %08x\n", hr);
2245     hr = IDirectDrawSurface_BltFast(surface2, 60, 60, surface1, &valid, 0);
2246     ok(hr == DDERR_INVALIDRECT, "BltFast with a rectangle resulting in an off-surface write returned %08x\n", hr);
2247     hr = IDirectDrawSurface_BltFast(surface1, 90, 90, surface2, NULL, 0);
2248     ok(hr == DDERR_INVALIDRECT, "BltFast with a rectangle resulting in an off-surface write returned %08x\n", hr);
2249     hr = IDirectDrawSurface_BltFast(surface2, 0, 0, surface1, &invalid1, 0);
2250     ok(hr == DDERR_INVALIDRECT, "BltFast with invalid rectangle 1 returned %08x\n", hr);
2251     hr = IDirectDrawSurface_BltFast(surface2, 0, 0, surface1, &invalid2, 0);
2252     ok(hr == DDERR_INVALIDRECT, "BltFast with invalid rectangle 2 returned %08x\n", hr);
2253     hr = IDirectDrawSurface_BltFast(surface2, 0, 0, surface1, &invalid3, 0);
2254     ok(hr == DDERR_INVALIDRECT, "BltFast with invalid rectangle 3 returned %08x\n", hr);
2255     hr = IDirectDrawSurface_BltFast(surface1, 0, 0, surface2, &invalid4, 0);
2256     ok(hr == DDERR_INVALIDRECT, "BltFast with invalid rectangle 3 returned %08x\n", hr);
2257     hr = IDirectDrawSurface_BltFast(surface1, 0, 0, surface1, NULL, 0);
2258     ok(hr == DD_OK, "BltFast blitting a surface onto itself returned %08x\n", hr);
2259
2260     /* Blt(non-fast) tests */
2261     memset(&BltFx, 0, sizeof(BltFx));
2262     BltFx.dwSize = sizeof(BltFx);
2263     U5(BltFx).dwFillColor = 0xaabbccdd;
2264
2265     hr = IDirectDrawSurface_Blt(surface1, &valid, NULL, NULL, DDBLT_COLORFILL, &BltFx);
2266     ok(hr == DD_OK, "IDirectDrawSurface_Blt with a valid rectangle for color fill returned %08x\n", hr);
2267     hr = IDirectDrawSurface_Blt(surface1, &valid, NULL, &invalid3, DDBLT_COLORFILL, &BltFx);
2268     ok(hr == DD_OK, "IDirectDrawSurface_Blt with a invalid, unused rectangle returned %08x\n", hr);
2269     hr = IDirectDrawSurface_Blt(surface2, &invalid1, NULL, NULL, DDBLT_COLORFILL, &BltFx);
2270     ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 1 returned %08x\n", hr);
2271     hr = IDirectDrawSurface_Blt(surface2, &invalid2, NULL, NULL, DDBLT_COLORFILL, &BltFx);
2272     ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 2 returned %08x\n", hr);
2273     hr = IDirectDrawSurface_Blt(surface2, &invalid3, NULL, NULL, DDBLT_COLORFILL, &BltFx);
2274     ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 3 returned %08x\n", hr);
2275     hr = IDirectDrawSurface_Blt(surface2, &invalid4, NULL, NULL, DDBLT_COLORFILL, &BltFx);
2276     ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 4 returned %08x\n", hr);
2277
2278     /* Valid on surface 1 */
2279     hr = IDirectDrawSurface_Blt(surface1, &invalid4, NULL, NULL, DDBLT_COLORFILL, &BltFx);
2280     ok(hr == DD_OK, "IDirectDrawSurface_Blt with a subrectangle fill returned %08x\n", hr);
2281
2282     /* Works - stretched blit */
2283     hr = IDirectDrawSurface_Blt(surface1, NULL, surface2, NULL, 0, NULL);
2284     ok(hr == DD_OK, "IDirectDrawSurface_Blt from a smaller to a bigger surface returned %08x\n", hr);
2285     hr = IDirectDrawSurface_Blt(surface2, NULL, surface1, NULL, 0, NULL);
2286     ok(hr == DD_OK, "IDirectDrawSurface_Blt from a bigger to a smaller surface %08x\n", hr);
2287
2288     /* Invalid dest rects in sourced blits */
2289     hr = IDirectDrawSurface_Blt(surface2, &invalid1, surface1, NULL, 0, NULL);
2290     ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 1 returned %08x\n", hr);
2291     hr = IDirectDrawSurface_Blt(surface2, &invalid2, surface1, NULL, 0, NULL);
2292     ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 2 returned %08x\n", hr);
2293     hr = IDirectDrawSurface_Blt(surface2, &invalid3, surface1, NULL, 0, NULL);
2294     ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 3 returned %08x\n", hr);
2295     hr = IDirectDrawSurface_Blt(surface2, &invalid4, surface1, NULL, 0, NULL);
2296     ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 4 returned %08x\n", hr);
2297
2298     /* Invalid src rects */
2299     hr = IDirectDrawSurface_Blt(surface2, NULL, surface1, &invalid1, 0, NULL);
2300     ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 1 returned %08x\n", hr);
2301     hr = IDirectDrawSurface_Blt(surface2, NULL, surface1, &invalid2, 0, NULL);
2302     ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 2 returned %08x\n", hr);
2303     hr = IDirectDrawSurface_Blt(surface2, NULL, surface1, &invalid3, 0, NULL);
2304     ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 3 returned %08x\n", hr);
2305     hr = IDirectDrawSurface_Blt(surface1, NULL, surface2, &invalid4, 0, NULL);
2306     ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface_Blt with a with invalid rectangle 4 returned %08x\n", hr);
2307
2308     IDirectDrawSurface_Release(surface1);
2309     IDirectDrawSurface_Release(surface2);
2310 }
2311
2312 static void StructSizeTest(void)
2313 {
2314     IDirectDrawSurface *surface1;
2315     IDirectDrawSurface7 *surface7;
2316     union {
2317         DDSURFACEDESC desc1;
2318         DDSURFACEDESC2 desc2;
2319         char blob[1024]; /* To get a bunch of writable memory */
2320     } desc;
2321     DDSURFACEDESC create;
2322     HRESULT hr;
2323
2324     memset(&desc, 0, sizeof(desc));
2325     memset(&create, 0, sizeof(create));
2326
2327     memset(&create, 0, sizeof(create));
2328     create.dwSize = sizeof(create);
2329     create.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
2330     create.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
2331     create.dwHeight = 128;
2332     create.dwWidth = 128;
2333     hr = IDirectDraw_CreateSurface(lpDD, &create, &surface1, NULL);
2334     ok(hr == DD_OK, "Creating an offscreen plain surface failed with %08x\n", hr);
2335     hr = IDirectDrawSurface_QueryInterface(surface1, &IID_IDirectDrawSurface7, (void **) &surface7);
2336     ok(hr == DD_OK, "IDirectDrawSurface_QueryInterface failed with %08x\n", hr);
2337
2338     desc.desc1.dwSize = sizeof(DDSURFACEDESC);
2339     hr = IDirectDrawSurface_GetSurfaceDesc(surface1, &desc.desc1);
2340     ok(hr == DD_OK, "IDirectDrawSurface_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC) returned %08x\n", hr);
2341     hr = IDirectDrawSurface7_GetSurfaceDesc(surface7, &desc.desc2);
2342     ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC) returned %08x\n", hr);
2343
2344     desc.desc2.dwSize = sizeof(DDSURFACEDESC2);
2345     hr = IDirectDrawSurface_GetSurfaceDesc(surface1, &desc.desc1);
2346     ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC2) returned %08x\n", hr);
2347     hr = IDirectDrawSurface7_GetSurfaceDesc(surface7, &desc.desc2);
2348     ok(hr == DD_OK, "IDirectDrawSurface7_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC2) returned %08x\n", hr);
2349
2350     desc.desc2.dwSize = 0;
2351     hr = IDirectDrawSurface_GetSurfaceDesc(surface1, &desc.desc1);
2352     ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface_GetSurfaceDesc with desc size 0 returned %08x\n", hr);
2353     hr = IDirectDrawSurface7_GetSurfaceDesc(surface7, &desc.desc2);
2354     ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_GetSurfaceDesc with desc size 0 returned %08x\n", hr);
2355
2356     desc.desc1.dwSize = sizeof(DDSURFACEDESC) + 1;
2357     hr = IDirectDrawSurface_GetSurfaceDesc(surface1, &desc.desc1);
2358     ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC) + 1 returned %08x\n", hr);
2359     hr = IDirectDrawSurface7_GetSurfaceDesc(surface7, &desc.desc2);
2360     ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC) + 1 returned %08x\n", hr);
2361
2362     desc.desc2.dwSize = sizeof(DDSURFACEDESC2) + 1;
2363     hr = IDirectDrawSurface_GetSurfaceDesc(surface1, &desc.desc1);
2364     ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC2) + 1returned %08x\n", hr);
2365     hr = IDirectDrawSurface7_GetSurfaceDesc(surface7, &desc.desc2);
2366     ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_GetSurfaceDesc with desc size sizeof(DDSURFACEDESC2) + 1returned %08x\n", hr);
2367
2368     /* Tests for Lock() */
2369
2370     desc.desc1.dwSize = sizeof(DDSURFACEDESC);
2371     hr = IDirectDrawSurface_Lock(surface1, NULL, &desc.desc1, 0, 0);
2372     ok(hr == DD_OK, "IDirectDrawSurface_Lock with desc size sizeof(DDSURFACEDESC) returned %08x\n", hr);
2373     if(SUCCEEDED(hr)) IDirectDrawSurface_Unlock(surface1, NULL);
2374     ok(desc.desc1.dwSize == sizeof(DDSURFACEDESC), "Destination size was changed to %d\n", desc.desc1.dwSize);
2375     hr = IDirectDrawSurface7_Lock(surface7, NULL, &desc.desc2, 0, 0);
2376     ok(hr == DD_OK, "IDirectDrawSurface7_Lock with desc size sizeof(DDSURFACEDESC) returned %08x\n", hr);
2377     if(SUCCEEDED(hr)) IDirectDrawSurface7_Unlock(surface7, NULL);
2378     ok(desc.desc2.dwSize == sizeof(DDSURFACEDESC), "Destination size was changed to %d\n", desc.desc1.dwSize);
2379
2380     desc.desc2.dwSize = sizeof(DDSURFACEDESC2);
2381     hr = IDirectDrawSurface_Lock(surface1, NULL, &desc.desc1, 0, 0);
2382     ok(hr == DD_OK, "IDirectDrawSurface_Lock with desc size sizeof(DDSURFACEDESC2) returned %08x\n", hr);
2383     ok(desc.desc1.dwSize == sizeof(DDSURFACEDESC2), "Destination size was changed to %d\n", desc.desc1.dwSize);
2384     if(SUCCEEDED(hr)) IDirectDrawSurface_Unlock(surface1, NULL);
2385     hr = IDirectDrawSurface7_Lock(surface7, NULL, &desc.desc2, 0, 0);
2386     ok(hr == DD_OK, "IDirectDrawSurface7_Lock with desc size sizeof(DDSURFACEDESC2) returned %08x\n", hr);
2387     if(SUCCEEDED(hr)) IDirectDrawSurface7_Unlock(surface7, NULL);
2388     ok(desc.desc2.dwSize == sizeof(DDSURFACEDESC2), "Destination size was changed to %d\n", desc.desc1.dwSize);
2389
2390     desc.desc2.dwSize = 0;
2391     hr = IDirectDrawSurface_Lock(surface1, NULL, &desc.desc1, 0, 0);
2392     ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface_Lock with desc size 0 returned %08x\n", hr);
2393     if(SUCCEEDED(hr)) IDirectDrawSurface_Unlock(surface1, NULL);
2394     hr = IDirectDrawSurface7_Lock(surface7, NULL, &desc.desc2, 0, 0);
2395     ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_Lock with desc size 0 returned %08x\n", hr);
2396     if(SUCCEEDED(hr)) IDirectDrawSurface7_Unlock(surface7, NULL);
2397
2398     desc.desc1.dwSize = sizeof(DDSURFACEDESC) + 1;
2399     hr = IDirectDrawSurface_Lock(surface1, NULL, &desc.desc1, 0, 0);
2400     ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface_Lock with desc size sizeof(DDSURFACEDESC) + 1 returned %08x\n", hr);
2401     if(SUCCEEDED(hr)) IDirectDrawSurface_Unlock(surface1, NULL);
2402     hr = IDirectDrawSurface7_Lock(surface7, NULL, &desc.desc2, 0, 0);
2403     ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_Lock with desc size sizeof(DDSURFACEDESC) + 1 returned %08x\n", hr);
2404     if(SUCCEEDED(hr)) IDirectDrawSurface7_Unlock(surface7, NULL);
2405
2406     desc.desc2.dwSize = sizeof(DDSURFACEDESC2) + 1;
2407     hr = IDirectDrawSurface_Lock(surface1, NULL, &desc.desc1, 0, 0);
2408     ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface_Lock with desc size sizeof(DDSURFACEDESC2) + 1returned %08x\n", hr);
2409     if(SUCCEEDED(hr)) IDirectDrawSurface_Unlock(surface1, NULL);
2410     hr = IDirectDrawSurface7_Lock(surface7, NULL, &desc.desc2, 0, 0);
2411     ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_Lock with desc size sizeof(DDSURFACEDESC2) + 1returned %08x\n", hr);
2412     if(SUCCEEDED(hr)) IDirectDrawSurface7_Unlock(surface7, NULL);
2413
2414     IDirectDrawSurface7_Release(surface7);
2415     IDirectDrawSurface_Release(surface1);
2416 }
2417
2418 START_TEST(dsurface)
2419 {
2420     if (!CreateDirectDraw())
2421         return;
2422     MipMapCreationTest();
2423     SrcColorKey32BlitTest();
2424     QueryInterface();
2425     GetDDInterface_1();
2426     GetDDInterface_2();
2427     GetDDInterface_4();
2428     GetDDInterface_7();
2429     EnumTest();
2430     AttachmentTest();
2431     AttachmentTest7();
2432     CubeMapTest();
2433     test_lockrect_invalid();
2434     CompressedTest();
2435     SizeTest();
2436     PrivateDataTest();
2437     BltParamTest();
2438     StructSizeTest();
2439     ReleaseDirectDraw();
2440 }