msxml3/tests: Step to the next item on failure as well.
[wine] / dlls / ddraw / utils.c
1 /*
2  * DirectDraw helper functions
3  *
4  * Copyright (c) 1997-2000 Marcus Meissner
5  * Copyright (c) 1998 Lionel Ulmer
6  * Copyright (c) 2000 TransGaming Technologies Inc.
7  * Copyright (c) 2006 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
24 #include "config.h"
25 #include "wine/port.h"
26
27 #include "ddraw_private.h"
28
29 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
30
31 static void DDRAW_dump_pixelformat(const DDPIXELFORMAT *pf);
32
33 /*****************************************************************************
34  * PixelFormat_WineD3DtoDD
35  *
36  * Converts an wined3d format ID into a DDPIXELFORMAT structure
37  *
38  * Params:
39  *  DDPixelFormat: Address of the structure to write the pixel format to
40  *  WineD3DFormat: Source format
41  *
42  *****************************************************************************/
43 void PixelFormat_WineD3DtoDD(DDPIXELFORMAT *DDPixelFormat, enum wined3d_format_id WineD3DFormat)
44 {
45     DWORD Size = DDPixelFormat->dwSize;
46     TRACE("Converting wined3d format %#x to DDRAW.\n", WineD3DFormat);
47
48     if(Size==0) return;
49
50     memset(DDPixelFormat, 0x00, Size);
51     DDPixelFormat->dwSize = Size;
52     switch(WineD3DFormat)
53     {
54         case WINED3DFMT_B8G8R8_UNORM:
55             DDPixelFormat->dwFlags = DDPF_RGB;
56             DDPixelFormat->dwFourCC = 0;
57             DDPixelFormat->u1.dwRGBBitCount = 24;
58             DDPixelFormat->u2.dwRBitMask = 0x00ff0000;
59             DDPixelFormat->u3.dwGBitMask = 0x0000ff00;
60             DDPixelFormat->u4.dwBBitMask = 0x000000ff;
61             DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
62             break;
63
64         case WINED3DFMT_B8G8R8A8_UNORM:
65             DDPixelFormat->dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
66             DDPixelFormat->dwFourCC = 0;
67             DDPixelFormat->u1.dwRGBBitCount = 32;
68             DDPixelFormat->u2.dwRBitMask = 0x00ff0000;
69             DDPixelFormat->u3.dwGBitMask = 0x0000ff00;
70             DDPixelFormat->u4.dwBBitMask = 0x000000ff;
71             DDPixelFormat->u5.dwRGBAlphaBitMask = 0xff000000;
72             break;
73
74         case WINED3DFMT_B8G8R8X8_UNORM:
75             DDPixelFormat->dwFlags = DDPF_RGB;
76             DDPixelFormat->dwFourCC = 0;
77             DDPixelFormat->u1.dwRGBBitCount = 32;
78             DDPixelFormat->u2.dwRBitMask = 0x00ff0000;
79             DDPixelFormat->u3.dwGBitMask = 0x0000ff00;
80             DDPixelFormat->u4.dwBBitMask = 0x000000ff;
81             DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
82             break;
83
84         case WINED3DFMT_R8G8B8X8_UNORM:
85             DDPixelFormat->dwFlags = DDPF_RGB;
86             DDPixelFormat->dwFourCC = 0;
87             DDPixelFormat->u1.dwRGBBitCount = 32;
88             DDPixelFormat->u2.dwRBitMask = 0x000000ff;
89             DDPixelFormat->u3.dwGBitMask = 0x0000ff00;
90             DDPixelFormat->u4.dwBBitMask = 0x00ff0000;
91             DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
92             break;
93
94         case WINED3DFMT_B5G6R5_UNORM:
95             DDPixelFormat->dwFlags = DDPF_RGB;
96             DDPixelFormat->dwFourCC = 0;
97             DDPixelFormat->u1.dwRGBBitCount = 16;
98             DDPixelFormat->u2.dwRBitMask = 0xF800;
99             DDPixelFormat->u3.dwGBitMask = 0x07E0;
100             DDPixelFormat->u4.dwBBitMask = 0x001F;
101             DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
102             break;
103
104         case WINED3DFMT_B5G5R5X1_UNORM:
105             DDPixelFormat->dwFlags = DDPF_RGB;
106             DDPixelFormat->dwFourCC = 0;
107             DDPixelFormat->u1.dwRGBBitCount = 16;
108             DDPixelFormat->u2.dwRBitMask = 0x7C00;
109             DDPixelFormat->u3.dwGBitMask = 0x03E0;
110             DDPixelFormat->u4.dwBBitMask = 0x001F;
111             DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
112             break;
113
114         case WINED3DFMT_B5G5R5A1_UNORM:
115             DDPixelFormat->dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
116             DDPixelFormat->dwFourCC = 0;
117             DDPixelFormat->u1.dwRGBBitCount = 16;
118             DDPixelFormat->u2.dwRBitMask = 0x7C00;
119             DDPixelFormat->u3.dwGBitMask = 0x03E0;
120             DDPixelFormat->u4.dwBBitMask = 0x001F;
121             DDPixelFormat->u5.dwRGBAlphaBitMask = 0x8000;
122             break;
123
124         case WINED3DFMT_B4G4R4A4_UNORM:
125             DDPixelFormat->dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
126             DDPixelFormat->dwFourCC = 0;
127             DDPixelFormat->u1.dwRGBBitCount = 16;
128             DDPixelFormat->u2.dwRBitMask = 0x0F00;
129             DDPixelFormat->u3.dwGBitMask = 0x00F0;
130             DDPixelFormat->u4.dwBBitMask = 0x000F;
131             DDPixelFormat->u5.dwRGBAlphaBitMask = 0xF000;
132             break;
133
134         case WINED3DFMT_B2G3R3_UNORM:
135             DDPixelFormat->dwFlags = DDPF_RGB;
136             DDPixelFormat->dwFourCC = 0;
137             DDPixelFormat->u1.dwRGBBitCount = 8;
138             DDPixelFormat->u2.dwRBitMask = 0xE0;
139             DDPixelFormat->u3.dwGBitMask = 0x1C;
140             DDPixelFormat->u4.dwBBitMask = 0x03;
141             DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0x0;
142             break;
143
144         case WINED3DFMT_P8_UINT:
145             DDPixelFormat->dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
146             DDPixelFormat->dwFourCC = 0;
147             DDPixelFormat->u1.dwRGBBitCount = 8;
148             DDPixelFormat->u2.dwRBitMask = 0x00;
149             DDPixelFormat->u3.dwGBitMask = 0x00;
150             DDPixelFormat->u4.dwBBitMask = 0x00;
151             break;
152
153         case WINED3DFMT_A8_UNORM:
154             DDPixelFormat->dwFlags = DDPF_ALPHA;
155             DDPixelFormat->dwFourCC = 0;
156             DDPixelFormat->u1.dwAlphaBitDepth = 8;
157             DDPixelFormat->u2.dwRBitMask = 0x0;
158             DDPixelFormat->u3.dwZBitMask = 0x0;
159             DDPixelFormat->u4.dwStencilBitMask = 0x0;
160             DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0x0;
161             break;
162
163         case WINED3DFMT_B2G3R3A8_UNORM:
164             DDPixelFormat->dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
165             DDPixelFormat->dwFourCC = 0;
166             DDPixelFormat->u1.dwRGBBitCount = 16;
167             DDPixelFormat->u2.dwRBitMask = 0x00E0;
168             DDPixelFormat->u3.dwGBitMask = 0x001C;
169             DDPixelFormat->u4.dwBBitMask = 0x0003;
170             DDPixelFormat->u5.dwRGBAlphaBitMask = 0xFF00;
171             break;
172
173         case WINED3DFMT_B4G4R4X4_UNORM:
174             DDPixelFormat->dwFlags = DDPF_RGB;
175             DDPixelFormat->dwFourCC = 0;
176             DDPixelFormat->u1.dwRGBBitCount = 16;
177             DDPixelFormat->u2.dwRBitMask = 0x0F00;
178             DDPixelFormat->u3.dwGBitMask = 0x00F0;
179             DDPixelFormat->u4.dwBBitMask = 0x000F;
180             DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
181             break;
182
183         /* How are Z buffer bit depth and Stencil buffer bit depth related?
184          */
185         case WINED3DFMT_D16_UNORM:
186             DDPixelFormat->dwFlags = DDPF_ZBUFFER;
187             DDPixelFormat->dwFourCC = 0;
188             DDPixelFormat->u1.dwZBufferBitDepth = 16;
189             DDPixelFormat->u2.dwStencilBitDepth = 0;
190             DDPixelFormat->u3.dwZBitMask = 0x0000FFFF;
191             DDPixelFormat->u4.dwStencilBitMask = 0x0;
192             DDPixelFormat->u5.dwRGBZBitMask = 0x00000000;
193             break;
194
195         case WINED3DFMT_D32_UNORM:
196             DDPixelFormat->dwFlags = DDPF_ZBUFFER;
197             DDPixelFormat->dwFourCC = 0;
198             DDPixelFormat->u1.dwZBufferBitDepth = 32;
199             DDPixelFormat->u2.dwStencilBitDepth = 0;
200             DDPixelFormat->u3.dwZBitMask = 0xFFFFFFFF;
201             DDPixelFormat->u4.dwStencilBitMask = 0x0;
202             DDPixelFormat->u5.dwRGBZBitMask = 0x00000000;
203             break;
204
205         case WINED3DFMT_S4X4_UINT_D24_UNORM:
206             DDPixelFormat->dwFlags = DDPF_ZBUFFER | DDPF_STENCILBUFFER;
207             DDPixelFormat->dwFourCC = 0;
208             /* Should I set dwZBufferBitDepth to 32 here? */
209             DDPixelFormat->u1.dwZBufferBitDepth = 32;
210             DDPixelFormat->u2.dwStencilBitDepth = 4;
211             DDPixelFormat->u3.dwZBitMask = 0x00FFFFFF;
212             DDPixelFormat->u4.dwStencilBitMask = 0x0F000000;
213             DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
214             break;
215
216         case WINED3DFMT_D24_UNORM_S8_UINT:
217             DDPixelFormat->dwFlags = DDPF_ZBUFFER | DDPF_STENCILBUFFER;
218             DDPixelFormat->dwFourCC = 0;
219             /* Should I set dwZBufferBitDepth to 32 here? */
220             DDPixelFormat->u1.dwZBufferBitDepth = 32;
221             DDPixelFormat->u2.dwStencilBitDepth = 8;
222             DDPixelFormat->u3.dwZBitMask = 0x00FFFFFFFF;
223             DDPixelFormat->u4.dwStencilBitMask = 0xFF000000;
224             DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
225             break;
226
227         case WINED3DFMT_X8D24_UNORM:
228             DDPixelFormat->dwFlags = DDPF_ZBUFFER;
229             DDPixelFormat->dwFourCC = 0;
230             DDPixelFormat->u1.dwZBufferBitDepth = 32;
231             DDPixelFormat->u2.dwStencilBitDepth = 0;
232             DDPixelFormat->u3.dwZBitMask = 0x00FFFFFFFF;
233             DDPixelFormat->u4.dwStencilBitMask = 0x00000000;
234             DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
235             break;
236
237         case WINED3DFMT_S1_UINT_D15_UNORM:
238             DDPixelFormat->dwFlags = DDPF_ZBUFFER | DDPF_STENCILBUFFER;
239             DDPixelFormat->dwFourCC = 0;
240             DDPixelFormat->u1.dwZBufferBitDepth = 16;
241             DDPixelFormat->u2.dwStencilBitDepth = 1;
242             DDPixelFormat->u3.dwZBitMask = 0x7fff;
243             DDPixelFormat->u4.dwStencilBitMask = 0x8000;
244             DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
245             break;
246
247         case WINED3DFMT_UYVY:
248         case WINED3DFMT_YUY2:
249             DDPixelFormat->u1.dwYUVBitCount = 16;
250             DDPixelFormat->dwFlags = DDPF_FOURCC;
251             DDPixelFormat->dwFourCC = WineD3DFormat;
252             break;
253
254         case WINED3DFMT_YV12:
255             DDPixelFormat->u1.dwYUVBitCount = 12;
256             DDPixelFormat->dwFlags = DDPF_FOURCC;
257             DDPixelFormat->dwFourCC = WineD3DFormat;
258             break;
259
260         case WINED3DFMT_DXT1:
261         case WINED3DFMT_DXT2:
262         case WINED3DFMT_DXT3:
263         case WINED3DFMT_DXT4:
264         case WINED3DFMT_DXT5:
265         case WINED3DFMT_MULTI2_ARGB8:
266         case WINED3DFMT_G8R8_G8B8:
267         case WINED3DFMT_R8G8_B8G8:
268             DDPixelFormat->dwFlags = DDPF_FOURCC;
269             DDPixelFormat->dwFourCC = WineD3DFormat;
270             break;
271
272         /* Luminance */
273         case WINED3DFMT_L8_UNORM:
274             DDPixelFormat->dwFlags = DDPF_LUMINANCE;
275             DDPixelFormat->dwFourCC = 0;
276             DDPixelFormat->u1.dwLuminanceBitCount = 8;
277             DDPixelFormat->u2.dwLuminanceBitMask = 0xff;
278             DDPixelFormat->u3.dwBumpDvBitMask = 0x0;
279             DDPixelFormat->u4.dwBumpLuminanceBitMask = 0x0;
280             DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0x0;
281             break;
282
283         case WINED3DFMT_L4A4_UNORM:
284             DDPixelFormat->dwFlags = DDPF_ALPHAPIXELS | DDPF_LUMINANCE;
285             DDPixelFormat->dwFourCC = 0;
286             DDPixelFormat->u1.dwLuminanceBitCount = 4;
287             DDPixelFormat->u2.dwLuminanceBitMask = 0x0f;
288             DDPixelFormat->u3.dwBumpDvBitMask = 0x0;
289             DDPixelFormat->u4.dwBumpLuminanceBitMask = 0x0;
290             DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0xf0;
291             break;
292
293         case WINED3DFMT_L8A8_UNORM:
294             DDPixelFormat->dwFlags = DDPF_ALPHAPIXELS | DDPF_LUMINANCE;
295             DDPixelFormat->dwFourCC = 0;
296             DDPixelFormat->u1.dwLuminanceBitCount = 16;
297             DDPixelFormat->u2.dwLuminanceBitMask = 0x00ff;
298             DDPixelFormat->u3.dwBumpDvBitMask = 0x0;
299             DDPixelFormat->u4.dwBumpLuminanceBitMask = 0x0;
300             DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0xff00;
301             break;
302
303         /* Bump mapping */
304         case WINED3DFMT_R8G8_SNORM:
305             DDPixelFormat->dwFlags = DDPF_BUMPDUDV;
306             DDPixelFormat->dwFourCC = 0;
307             DDPixelFormat->u1.dwBumpBitCount = 16;
308             DDPixelFormat->u2.dwBumpDuBitMask =         0x000000ff;
309             DDPixelFormat->u3.dwBumpDvBitMask =         0x0000ff00;
310             DDPixelFormat->u4.dwBumpLuminanceBitMask =  0x00000000;
311             DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0x00000000;
312             break;
313
314         case WINED3DFMT_R5G5_SNORM_L6_UNORM:
315             DDPixelFormat->dwFlags = DDPF_BUMPDUDV;
316             DDPixelFormat->dwFourCC = 0;
317             DDPixelFormat->u1.dwBumpBitCount = 16;
318             DDPixelFormat->u2.dwBumpDuBitMask =         0x0000001f;
319             DDPixelFormat->u3.dwBumpDvBitMask =         0x000003e0;
320             DDPixelFormat->u4.dwBumpLuminanceBitMask =  0x0000fc00;
321             DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0x00000000;
322             break;
323
324         case WINED3DFMT_R8G8_SNORM_L8X8_UNORM:
325             DDPixelFormat->dwFlags = DDPF_BUMPDUDV;
326             DDPixelFormat->dwFourCC = 0;
327             DDPixelFormat->u1.dwBumpBitCount = 32;
328             DDPixelFormat->u2.dwBumpDuBitMask =         0x000000ff;
329             DDPixelFormat->u3.dwBumpDvBitMask =         0x0000ff00;
330             DDPixelFormat->u4.dwBumpLuminanceBitMask =  0x00ff0000;
331             DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0x00000000;
332             break;
333
334         default:
335             ERR("Can't translate this Pixelformat %d\n", WineD3DFormat);
336     }
337
338     if(TRACE_ON(ddraw)) {
339         TRACE("Returning: ");
340         DDRAW_dump_pixelformat(DDPixelFormat);
341     }
342 }
343 /*****************************************************************************
344  * PixelFormat_DD2WineD3D
345  *
346  * Reads a DDPIXELFORMAT structure and returns the equivalent wined3d
347  * format ID.
348  *
349  * Params:
350  *  DDPixelFormat: The source format
351  *
352  * Returns:
353  *  The wined3d format ID equivalent to the DDraw format
354  *  WINED3DFMT_UNKNOWN if a matching format wasn't found
355  *****************************************************************************/
356 enum wined3d_format_id PixelFormat_DD2WineD3D(const DDPIXELFORMAT *DDPixelFormat)
357 {
358     TRACE("Convert a DirectDraw Pixelformat to a WineD3D Pixelformat\n");
359     if(TRACE_ON(ddraw))
360     {
361         DDRAW_dump_pixelformat(DDPixelFormat);
362     }
363
364     if(DDPixelFormat->dwFlags & DDPF_PALETTEINDEXED8)
365     {
366         return WINED3DFMT_P8_UINT;
367     }
368     else if(DDPixelFormat->dwFlags & (DDPF_PALETTEINDEXED1 | DDPF_PALETTEINDEXED2 | DDPF_PALETTEINDEXED4) )
369     {
370         FIXME("DDPF_PALETTEINDEXED1 to DDPF_PALETTEINDEXED4 are not supported by WineD3D (yet). Returning WINED3DFMT_P8\n");
371         return WINED3DFMT_P8_UINT;
372     }
373     else if(DDPixelFormat->dwFlags & DDPF_RGB)
374     {
375         switch(DDPixelFormat->u1.dwRGBBitCount)
376         {
377             case 8:
378                 /* This is the only format that can match here */
379                 return WINED3DFMT_B2G3R3_UNORM;
380
381             case 16:
382                 /* Read the Color masks */
383                 if( (DDPixelFormat->u2.dwRBitMask == 0xF800) &&
384                     (DDPixelFormat->u3.dwGBitMask == 0x07E0) &&
385                     (DDPixelFormat->u4.dwBBitMask == 0x001F) )
386                 {
387                     return WINED3DFMT_B5G6R5_UNORM;
388                 }
389
390                 if( (DDPixelFormat->u2.dwRBitMask == 0x7C00) &&
391                     (DDPixelFormat->u3.dwGBitMask == 0x03E0) &&
392                     (DDPixelFormat->u4.dwBBitMask == 0x001F) )
393                 {
394                     if( (DDPixelFormat->dwFlags & DDPF_ALPHAPIXELS) &&
395                         (DDPixelFormat->u5.dwRGBAlphaBitMask == 0x8000))
396                         return WINED3DFMT_B5G5R5A1_UNORM;
397                     else
398                         return WINED3DFMT_B5G5R5X1_UNORM;
399                 }
400
401                 if( (DDPixelFormat->u2.dwRBitMask == 0x0F00) &&
402                     (DDPixelFormat->u3.dwGBitMask == 0x00F0) &&
403                     (DDPixelFormat->u4.dwBBitMask == 0x000F) )
404                 {
405                     if( (DDPixelFormat->dwFlags & DDPF_ALPHAPIXELS) &&
406                         (DDPixelFormat->u5.dwRGBAlphaBitMask == 0xF000))
407                         return WINED3DFMT_B4G4R4A4_UNORM;
408                     else
409                         return WINED3DFMT_B4G4R4X4_UNORM;
410                 }
411
412                 if( (DDPixelFormat->dwFlags & DDPF_ALPHAPIXELS) &&
413                     (DDPixelFormat->u5.dwRGBAlphaBitMask == 0xFF00) &&
414                     (DDPixelFormat->u2.dwRBitMask == 0x00E0) &&
415                     (DDPixelFormat->u3.dwGBitMask == 0x001C) &&
416                     (DDPixelFormat->u4.dwBBitMask == 0x0003) )
417                 {
418                     return WINED3DFMT_B2G3R3A8_UNORM;
419                 }
420                 ERR("16 bit RGB Pixel format does not match\n");
421                 return WINED3DFMT_UNKNOWN;
422
423             case 24:
424                 return WINED3DFMT_B8G8R8_UNORM;
425
426             case 32:
427                 /* Read the Color masks */
428                 if( (DDPixelFormat->u2.dwRBitMask == 0x00FF0000) &&
429                     (DDPixelFormat->u3.dwGBitMask == 0x0000FF00) &&
430                     (DDPixelFormat->u4.dwBBitMask == 0x000000FF) )
431                 {
432                     if( (DDPixelFormat->dwFlags & DDPF_ALPHAPIXELS) &&
433                         (DDPixelFormat->u5.dwRGBAlphaBitMask == 0xFF000000))
434                         return WINED3DFMT_B8G8R8A8_UNORM;
435                     else
436                         return WINED3DFMT_B8G8R8X8_UNORM;
437
438                 }
439                 ERR("32 bit RGB pixel format does not match\n");
440
441             default:
442                 ERR("Invalid dwRGBBitCount in Pixelformat structure\n");
443                 return WINED3DFMT_UNKNOWN;
444         }
445     }
446     else if( (DDPixelFormat->dwFlags & DDPF_ALPHA) )
447     {
448         /* Alpha only Pixelformat */
449         switch(DDPixelFormat->u1.dwAlphaBitDepth)
450         {
451             case 1:
452             case 2:
453             case 4:
454                 ERR("Unsupported Alpha-Only bit depth 0x%x\n", DDPixelFormat->u1.dwAlphaBitDepth);
455             case 8:
456                 return WINED3DFMT_A8_UNORM;
457
458             default:
459                 ERR("Invalid AlphaBitDepth in Alpha-Only Pixelformat\n");
460                 return WINED3DFMT_UNKNOWN;
461         }
462     }
463     else if(DDPixelFormat->dwFlags & DDPF_LUMINANCE)
464     {
465         /* Luminance-only or luminance-alpha */
466         if(DDPixelFormat->dwFlags & DDPF_ALPHAPIXELS)
467         {
468             /* Luminance with Alpha */
469             switch(DDPixelFormat->u1.dwLuminanceBitCount)
470             {
471                 case 4:
472                     if(DDPixelFormat->u1.dwAlphaBitDepth == 4)
473                         return WINED3DFMT_L4A4_UNORM;
474                     ERR("Unknown Alpha / Luminance bit depth combination\n");
475                     return WINED3DFMT_UNKNOWN;
476
477                 case 6:
478                     ERR("A luminance Pixelformat shouldn't have 6 luminance bits. Returning D3DFMT_L6V5U5 for now!!\n");
479                     return WINED3DFMT_R5G5_SNORM_L6_UNORM;
480
481                 case 8:
482                     if(DDPixelFormat->u1.dwAlphaBitDepth == 8)
483                         return WINED3DFMT_L8A8_UNORM;
484                     ERR("Unknown Alpha / Lumincase bit depth combination\n");
485                     return WINED3DFMT_UNKNOWN;
486             }
487         }
488         else
489         {
490             /* Luminance-only */
491             switch(DDPixelFormat->u1.dwLuminanceBitCount)
492             {
493                 case 6:
494                     ERR("A luminance Pixelformat shouldn't have 6 luminance bits. Returning D3DFMT_L6V5U5 for now!!\n");
495                     return WINED3DFMT_R5G5_SNORM_L6_UNORM;
496
497                 case 8:
498                     return WINED3DFMT_L8_UNORM;
499
500                 default:
501                     ERR("Unknown luminance-only bit depth 0x%x\n", DDPixelFormat->u1.dwLuminanceBitCount);
502                     return WINED3DFMT_UNKNOWN;
503              }
504         }
505     }
506     else if(DDPixelFormat->dwFlags & DDPF_ZBUFFER)
507     {
508         /* Z buffer */
509         if(DDPixelFormat->dwFlags & DDPF_STENCILBUFFER)
510         {
511             switch(DDPixelFormat->u1.dwZBufferBitDepth)
512             {
513                 case 8:
514                     FIXME("8 Bits Z+Stencil buffer pixelformat is not supported. Returning WINED3DFMT_UNKNOWN\n");
515                     return WINED3DFMT_UNKNOWN;
516
517                 case 15:
518                     FIXME("15 bit depth buffer not handled yet, assuming 16 bit\n");
519                 case 16:
520                     if(DDPixelFormat->u2.dwStencilBitDepth == 1)
521                         return WINED3DFMT_S1_UINT_D15_UNORM;
522
523                     FIXME("Don't know how to handle a 16 bit Z buffer with %d bit stencil buffer pixelformat\n", DDPixelFormat->u2.dwStencilBitDepth);
524                     return WINED3DFMT_UNKNOWN;
525
526                 case 24:
527                     FIXME("Don't know how to handle a 24 bit depth buffer with stencil bits\n");
528                     return WINED3DFMT_D24_UNORM_S8_UINT;
529
530                 case 32:
531                     if(DDPixelFormat->u2.dwStencilBitDepth == 8)
532                         return WINED3DFMT_D24_UNORM_S8_UINT;
533                     else
534                         return WINED3DFMT_S4X4_UINT_D24_UNORM;
535
536                 default:
537                     ERR("Unknown Z buffer depth %d\n", DDPixelFormat->u1.dwZBufferBitDepth);
538                     return WINED3DFMT_UNKNOWN;
539             }
540         }
541         else
542         {
543             switch(DDPixelFormat->u1.dwZBufferBitDepth)
544             {
545                 case 8:
546                     ERR("8 Bit Z buffers are not supported. Trying a 16 Bit one\n");
547                     return WINED3DFMT_D16_UNORM;
548
549                 case 16:
550                     return WINED3DFMT_D16_UNORM;
551
552                 case 24:
553                     FIXME("24 Bit depth buffer, treating like a 32 bit one\n");
554                 case 32:
555                     if(DDPixelFormat->u3.dwZBitMask == 0x00FFFFFF) {
556                         return WINED3DFMT_X8D24_UNORM;
557                     } else if(DDPixelFormat->u3.dwZBitMask == 0xFFFFFFFF) {
558                         return WINED3DFMT_D32_UNORM;
559                     }
560                     FIXME("Unhandled 32 bit depth buffer bitmasks, returning WINED3DFMT_D24X8\n");
561                     return WINED3DFMT_X8D24_UNORM; /* That's most likely to make games happy */
562
563                 default:
564                     ERR("Unsupported Z buffer depth %d\n", DDPixelFormat->u1.dwZBufferBitDepth);
565                     return WINED3DFMT_UNKNOWN;
566             }
567         }
568     }
569     else if(DDPixelFormat->dwFlags & DDPF_FOURCC)
570     {
571         return DDPixelFormat->dwFourCC;
572     }
573     else if(DDPixelFormat->dwFlags & DDPF_BUMPDUDV)
574     {
575         if( (DDPixelFormat->u1.dwBumpBitCount         == 16        ) &&
576             (DDPixelFormat->u2.dwBumpDuBitMask        == 0x000000ff) &&
577             (DDPixelFormat->u3.dwBumpDvBitMask        == 0x0000ff00) &&
578             (DDPixelFormat->u4.dwBumpLuminanceBitMask == 0x00000000) )
579         {
580             return WINED3DFMT_R8G8_SNORM;
581         }
582         else if ( (DDPixelFormat->u1.dwBumpBitCount         == 16        ) &&
583                   (DDPixelFormat->u2.dwBumpDuBitMask        == 0x0000001f) &&
584                   (DDPixelFormat->u3.dwBumpDvBitMask        == 0x000003e0) &&
585                   (DDPixelFormat->u4.dwBumpLuminanceBitMask == 0x0000fc00) )
586         {
587             return WINED3DFMT_R5G5_SNORM_L6_UNORM;
588         }
589         else if ( (DDPixelFormat->u1.dwBumpBitCount         == 32        ) &&
590                   (DDPixelFormat->u2.dwBumpDuBitMask        == 0x000000ff) &&
591                   (DDPixelFormat->u3.dwBumpDvBitMask        == 0x0000ff00) &&
592                   (DDPixelFormat->u4.dwBumpLuminanceBitMask == 0x00ff0000) )
593         {
594             return WINED3DFMT_R8G8_SNORM_L8X8_UNORM;
595         }
596     }
597
598     ERR("Unknown Pixelformat!\n");
599     return WINED3DFMT_UNKNOWN;
600 }
601
602 /*****************************************************************************
603  * Various dumping functions.
604  *
605  * They write the contents of a specific function to a TRACE.
606  *
607  *****************************************************************************/
608 static void
609 DDRAW_dump_DWORD(const void *in)
610 {
611     TRACE("%d\n", *((const DWORD *) in));
612 }
613 static void
614 DDRAW_dump_PTR(const void *in)
615 {
616     TRACE("%p\n", *((const void * const*) in));
617 }
618 static void
619 DDRAW_dump_DDCOLORKEY(const DDCOLORKEY *ddck)
620 {
621     TRACE("Low : %d  - High : %d\n", ddck->dwColorSpaceLowValue, ddck->dwColorSpaceHighValue);
622 }
623
624 static void DDRAW_dump_flags_nolf(DWORD flags, const flag_info* names,
625                                   size_t num_names)
626 {
627     unsigned int i;
628
629     for (i=0; i < num_names; i++)
630         if ((flags & names[i].val) ||      /* standard flag value */
631             ((!flags) && (!names[i].val))) /* zero value only */
632             TRACE("%s ", names[i].name);
633 }
634
635 static void DDRAW_dump_flags(DWORD flags, const flag_info* names, size_t num_names)
636 {
637     DDRAW_dump_flags_nolf(flags, names, num_names);
638     TRACE("\n");
639 }
640
641 void DDRAW_dump_DDSCAPS2(const DDSCAPS2 *in)
642 {
643     static const flag_info flags[] = {
644         FE(DDSCAPS_RESERVED1),
645         FE(DDSCAPS_ALPHA),
646         FE(DDSCAPS_BACKBUFFER),
647         FE(DDSCAPS_COMPLEX),
648         FE(DDSCAPS_FLIP),
649         FE(DDSCAPS_FRONTBUFFER),
650         FE(DDSCAPS_OFFSCREENPLAIN),
651         FE(DDSCAPS_OVERLAY),
652         FE(DDSCAPS_PALETTE),
653         FE(DDSCAPS_PRIMARYSURFACE),
654         FE(DDSCAPS_PRIMARYSURFACELEFT),
655         FE(DDSCAPS_SYSTEMMEMORY),
656         FE(DDSCAPS_TEXTURE),
657         FE(DDSCAPS_3DDEVICE),
658         FE(DDSCAPS_VIDEOMEMORY),
659         FE(DDSCAPS_VISIBLE),
660         FE(DDSCAPS_WRITEONLY),
661         FE(DDSCAPS_ZBUFFER),
662         FE(DDSCAPS_OWNDC),
663         FE(DDSCAPS_LIVEVIDEO),
664         FE(DDSCAPS_HWCODEC),
665         FE(DDSCAPS_MODEX),
666         FE(DDSCAPS_MIPMAP),
667         FE(DDSCAPS_RESERVED2),
668         FE(DDSCAPS_ALLOCONLOAD),
669         FE(DDSCAPS_VIDEOPORT),
670         FE(DDSCAPS_LOCALVIDMEM),
671         FE(DDSCAPS_NONLOCALVIDMEM),
672         FE(DDSCAPS_STANDARDVGAMODE),
673         FE(DDSCAPS_OPTIMIZED)
674     };
675     static const flag_info flags2[] = {
676         FE(DDSCAPS2_HARDWAREDEINTERLACE),
677         FE(DDSCAPS2_HINTDYNAMIC),
678         FE(DDSCAPS2_HINTSTATIC),
679         FE(DDSCAPS2_TEXTUREMANAGE),
680         FE(DDSCAPS2_RESERVED1),
681         FE(DDSCAPS2_RESERVED2),
682         FE(DDSCAPS2_OPAQUE),
683         FE(DDSCAPS2_HINTANTIALIASING),
684         FE(DDSCAPS2_CUBEMAP),
685         FE(DDSCAPS2_CUBEMAP_POSITIVEX),
686         FE(DDSCAPS2_CUBEMAP_NEGATIVEX),
687         FE(DDSCAPS2_CUBEMAP_POSITIVEY),
688         FE(DDSCAPS2_CUBEMAP_NEGATIVEY),
689         FE(DDSCAPS2_CUBEMAP_POSITIVEZ),
690         FE(DDSCAPS2_CUBEMAP_NEGATIVEZ),
691         FE(DDSCAPS2_MIPMAPSUBLEVEL),
692         FE(DDSCAPS2_D3DTEXTUREMANAGE),
693         FE(DDSCAPS2_DONOTPERSIST),
694         FE(DDSCAPS2_STEREOSURFACELEFT)
695     };
696
697     DDRAW_dump_flags_nolf(in->dwCaps, flags, sizeof(flags)/sizeof(flags[0]));
698     DDRAW_dump_flags(in->dwCaps2, flags2, sizeof(flags2)/sizeof(flags2[0]));
699 }
700
701 static void
702 DDRAW_dump_DDSCAPS(const DDSCAPS *in)
703 {
704     DDSCAPS2 in_bis;
705
706     in_bis.dwCaps = in->dwCaps;
707     in_bis.dwCaps2 = 0;
708     in_bis.dwCaps3 = 0;
709     in_bis.dwCaps4 = 0;
710
711     DDRAW_dump_DDSCAPS2(&in_bis);
712 }
713
714 static void
715 DDRAW_dump_pixelformat_flag(DWORD flagmask)
716 {
717     static const flag_info flags[] =
718         {
719             FE(DDPF_ALPHAPIXELS),
720             FE(DDPF_ALPHA),
721             FE(DDPF_FOURCC),
722             FE(DDPF_PALETTEINDEXED4),
723             FE(DDPF_PALETTEINDEXEDTO8),
724             FE(DDPF_PALETTEINDEXED8),
725             FE(DDPF_RGB),
726             FE(DDPF_COMPRESSED),
727             FE(DDPF_RGBTOYUV),
728             FE(DDPF_YUV),
729             FE(DDPF_ZBUFFER),
730             FE(DDPF_PALETTEINDEXED1),
731             FE(DDPF_PALETTEINDEXED2),
732             FE(DDPF_ZPIXELS)
733     };
734
735     DDRAW_dump_flags_nolf(flagmask, flags, sizeof(flags)/sizeof(flags[0]));
736 }
737
738 static void
739 DDRAW_dump_members(DWORD flags,
740                    const void* data,
741                    const member_info* mems,
742                    size_t num_mems)
743 {
744     unsigned int i;
745
746     for (i=0; i < num_mems; i++)
747     {
748         if (mems[i].val & flags)
749         {
750             TRACE(" - %s : ", mems[i].name);
751             mems[i].func((const char *)data + mems[i].offset);
752         }
753     }
754 }
755
756 static void
757 DDRAW_dump_pixelformat(const DDPIXELFORMAT *pf)
758 {
759     TRACE("( ");
760     DDRAW_dump_pixelformat_flag(pf->dwFlags);
761     if (pf->dwFlags & DDPF_FOURCC)
762     {
763         TRACE(", dwFourCC code '%c%c%c%c' (0x%08x) - %d bits per pixel",
764                 (unsigned char)( pf->dwFourCC     &0xff),
765                 (unsigned char)((pf->dwFourCC>> 8)&0xff),
766                 (unsigned char)((pf->dwFourCC>>16)&0xff),
767                 (unsigned char)((pf->dwFourCC>>24)&0xff),
768                 pf->dwFourCC,
769                 pf->u1.dwYUVBitCount
770         );
771     }
772     if (pf->dwFlags & DDPF_RGB)
773     {
774         const char *cmd;
775         TRACE(", RGB bits: %d, ", pf->u1.dwRGBBitCount);
776         switch (pf->u1.dwRGBBitCount)
777         {
778         case 4: cmd = "%1lx"; break;
779         case 8: cmd = "%02lx"; break;
780         case 16: cmd = "%04lx"; break;
781         case 24: cmd = "%06lx"; break;
782         case 32: cmd = "%08lx"; break;
783         default: ERR("Unexpected bit depth !\n"); cmd = "%d"; break;
784         }
785         TRACE(" R "); TRACE(cmd, pf->u2.dwRBitMask);
786         TRACE(" G "); TRACE(cmd, pf->u3.dwGBitMask);
787         TRACE(" B "); TRACE(cmd, pf->u4.dwBBitMask);
788         if (pf->dwFlags & DDPF_ALPHAPIXELS)
789         {
790             TRACE(" A "); TRACE(cmd, pf->u5.dwRGBAlphaBitMask);
791         }
792         if (pf->dwFlags & DDPF_ZPIXELS)
793         {
794             TRACE(" Z "); TRACE(cmd, pf->u5.dwRGBZBitMask);
795         }
796     }
797     if (pf->dwFlags & DDPF_ZBUFFER)
798     {
799         TRACE(", Z bits : %d", pf->u1.dwZBufferBitDepth);
800     }
801     if (pf->dwFlags & DDPF_ALPHA)
802     {
803         TRACE(", Alpha bits : %d", pf->u1.dwAlphaBitDepth);
804     }
805     if (pf->dwFlags & DDPF_BUMPDUDV)
806     {
807         const char *cmd = "%08lx";
808         TRACE(", Bump bits: %d, ", pf->u1.dwBumpBitCount);
809         TRACE(" U "); TRACE(cmd, pf->u2.dwBumpDuBitMask);
810         TRACE(" V "); TRACE(cmd, pf->u3.dwBumpDvBitMask);
811         TRACE(" L "); TRACE(cmd, pf->u4.dwBumpLuminanceBitMask);
812     }
813     TRACE(")\n");
814 }
815
816 void DDRAW_dump_surface_desc(const DDSURFACEDESC2 *lpddsd)
817 {
818 #define STRUCT DDSURFACEDESC2
819     static const member_info members[] =
820         {
821             ME(DDSD_HEIGHT, DDRAW_dump_DWORD, dwHeight),
822             ME(DDSD_WIDTH, DDRAW_dump_DWORD, dwWidth),
823             ME(DDSD_PITCH, DDRAW_dump_DWORD, u1 /* lPitch */),
824             ME(DDSD_LINEARSIZE, DDRAW_dump_DWORD, u1 /* dwLinearSize */),
825             ME(DDSD_BACKBUFFERCOUNT, DDRAW_dump_DWORD, dwBackBufferCount),
826             ME(DDSD_MIPMAPCOUNT, DDRAW_dump_DWORD, u2 /* dwMipMapCount */),
827             ME(DDSD_ZBUFFERBITDEPTH, DDRAW_dump_DWORD, u2 /* dwZBufferBitDepth */), /* This is for 'old-style' D3D */
828             ME(DDSD_REFRESHRATE, DDRAW_dump_DWORD, u2 /* dwRefreshRate */),
829             ME(DDSD_ALPHABITDEPTH, DDRAW_dump_DWORD, dwAlphaBitDepth),
830             ME(DDSD_LPSURFACE, DDRAW_dump_PTR, lpSurface),
831             ME(DDSD_CKDESTOVERLAY, DDRAW_dump_DDCOLORKEY, u3 /* ddckCKDestOverlay */),
832             ME(DDSD_CKDESTBLT, DDRAW_dump_DDCOLORKEY, ddckCKDestBlt),
833             ME(DDSD_CKSRCOVERLAY, DDRAW_dump_DDCOLORKEY, ddckCKSrcOverlay),
834             ME(DDSD_CKSRCBLT, DDRAW_dump_DDCOLORKEY, ddckCKSrcBlt),
835             ME(DDSD_PIXELFORMAT, DDRAW_dump_pixelformat, u4 /* ddpfPixelFormat */)
836         };
837     static const member_info members_caps[] =
838         {
839             ME(DDSD_CAPS, DDRAW_dump_DDSCAPS, ddsCaps)
840         };
841     static const member_info members_caps2[] =
842         {
843             ME(DDSD_CAPS, DDRAW_dump_DDSCAPS2, ddsCaps)
844         };
845 #undef STRUCT
846
847     if (NULL == lpddsd)
848     {
849         TRACE("(null)\n");
850     }
851     else
852     {
853       if (lpddsd->dwSize >= sizeof(DDSURFACEDESC2))
854       {
855           DDRAW_dump_members(lpddsd->dwFlags, lpddsd, members_caps2, 1);
856       }
857       else
858       {
859           DDRAW_dump_members(lpddsd->dwFlags, lpddsd, members_caps, 1);
860       }
861       DDRAW_dump_members(lpddsd->dwFlags, lpddsd, members,
862                           sizeof(members)/sizeof(members[0]));
863     }
864 }
865
866 void
867 dump_D3DMATRIX(const D3DMATRIX *mat)
868 {
869     TRACE("  %f %f %f %f\n", mat->_11, mat->_12, mat->_13, mat->_14);
870     TRACE("  %f %f %f %f\n", mat->_21, mat->_22, mat->_23, mat->_24);
871     TRACE("  %f %f %f %f\n", mat->_31, mat->_32, mat->_33, mat->_34);
872     TRACE("  %f %f %f %f\n", mat->_41, mat->_42, mat->_43, mat->_44);
873 }
874
875 DWORD
876 get_flexible_vertex_size(DWORD d3dvtVertexType)
877 {
878     DWORD size = 0;
879     DWORD i;
880
881     if (d3dvtVertexType & D3DFVF_NORMAL) size += 3 * sizeof(D3DVALUE);
882     if (d3dvtVertexType & D3DFVF_DIFFUSE) size += sizeof(DWORD);
883     if (d3dvtVertexType & D3DFVF_SPECULAR) size += sizeof(DWORD);
884     if (d3dvtVertexType & D3DFVF_RESERVED1) size += sizeof(DWORD);
885     switch (d3dvtVertexType & D3DFVF_POSITION_MASK)
886     {
887         case D3DFVF_XYZ:    size += 3 * sizeof(D3DVALUE); break;
888         case D3DFVF_XYZRHW: size += 4 * sizeof(D3DVALUE); break;
889         case D3DFVF_XYZB1:  size += 4 * sizeof(D3DVALUE); break;
890         case D3DFVF_XYZB2:  size += 5 * sizeof(D3DVALUE); break;
891         case D3DFVF_XYZB3:  size += 6 * sizeof(D3DVALUE); break;
892         case D3DFVF_XYZB4:  size += 7 * sizeof(D3DVALUE); break;
893         case D3DFVF_XYZB5:  size += 8 * sizeof(D3DVALUE); break;
894         default: ERR("Unexpected position mask\n");
895     }
896     for (i = 0; i < GET_TEXCOUNT_FROM_FVF(d3dvtVertexType); i++)
897     {
898         size += GET_TEXCOORD_SIZE_FROM_FVF(d3dvtVertexType, i) * sizeof(D3DVALUE);
899     }
900
901     return size;
902 }
903
904 void DDRAW_Convert_DDSCAPS_1_To_2(const DDSCAPS* pIn, DDSCAPS2* pOut)
905 {
906     /* 2 adds three additional caps fields to the end. Both versions
907      * are unversioned. */
908     pOut->dwCaps = pIn->dwCaps;
909     pOut->dwCaps2 = 0;
910     pOut->dwCaps3 = 0;
911     pOut->dwCaps4 = 0;
912 }
913
914 void DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(const DDDEVICEIDENTIFIER2* pIn, DDDEVICEIDENTIFIER* pOut)
915 {
916     /* 2 adds a dwWHQLLevel field to the end. Both structures are
917      * unversioned. */
918     memcpy(pOut, pIn, sizeof(*pOut));
919 }
920
921 void DDRAW_dump_cooperativelevel(DWORD cooplevel)
922 {
923     static const flag_info flags[] =
924         {
925             FE(DDSCL_FULLSCREEN),
926             FE(DDSCL_ALLOWREBOOT),
927             FE(DDSCL_NOWINDOWCHANGES),
928             FE(DDSCL_NORMAL),
929             FE(DDSCL_ALLOWMODEX),
930             FE(DDSCL_EXCLUSIVE),
931             FE(DDSCL_SETFOCUSWINDOW),
932             FE(DDSCL_SETDEVICEWINDOW),
933             FE(DDSCL_CREATEDEVICEWINDOW)
934     };
935
936     if (TRACE_ON(ddraw))
937     {
938         TRACE(" - ");
939         DDRAW_dump_flags(cooplevel, flags, sizeof(flags)/sizeof(flags[0]));
940     }
941 }
942
943 void DDRAW_dump_DDCAPS(const DDCAPS *lpcaps)
944 {
945     static const flag_info flags1[] =
946     {
947       FE(DDCAPS_3D),
948       FE(DDCAPS_ALIGNBOUNDARYDEST),
949       FE(DDCAPS_ALIGNSIZEDEST),
950       FE(DDCAPS_ALIGNBOUNDARYSRC),
951       FE(DDCAPS_ALIGNSIZESRC),
952       FE(DDCAPS_ALIGNSTRIDE),
953       FE(DDCAPS_BLT),
954       FE(DDCAPS_BLTQUEUE),
955       FE(DDCAPS_BLTFOURCC),
956       FE(DDCAPS_BLTSTRETCH),
957       FE(DDCAPS_GDI),
958       FE(DDCAPS_OVERLAY),
959       FE(DDCAPS_OVERLAYCANTCLIP),
960       FE(DDCAPS_OVERLAYFOURCC),
961       FE(DDCAPS_OVERLAYSTRETCH),
962       FE(DDCAPS_PALETTE),
963       FE(DDCAPS_PALETTEVSYNC),
964       FE(DDCAPS_READSCANLINE),
965       FE(DDCAPS_STEREOVIEW),
966       FE(DDCAPS_VBI),
967       FE(DDCAPS_ZBLTS),
968       FE(DDCAPS_ZOVERLAYS),
969       FE(DDCAPS_COLORKEY),
970       FE(DDCAPS_ALPHA),
971       FE(DDCAPS_COLORKEYHWASSIST),
972       FE(DDCAPS_NOHARDWARE),
973       FE(DDCAPS_BLTCOLORFILL),
974       FE(DDCAPS_BANKSWITCHED),
975       FE(DDCAPS_BLTDEPTHFILL),
976       FE(DDCAPS_CANCLIP),
977       FE(DDCAPS_CANCLIPSTRETCHED),
978       FE(DDCAPS_CANBLTSYSMEM)
979     };
980     static const flag_info flags2[] =
981     {
982       FE(DDCAPS2_CERTIFIED),
983       FE(DDCAPS2_NO2DDURING3DSCENE),
984       FE(DDCAPS2_VIDEOPORT),
985       FE(DDCAPS2_AUTOFLIPOVERLAY),
986       FE(DDCAPS2_CANBOBINTERLEAVED),
987       FE(DDCAPS2_CANBOBNONINTERLEAVED),
988       FE(DDCAPS2_COLORCONTROLOVERLAY),
989       FE(DDCAPS2_COLORCONTROLPRIMARY),
990       FE(DDCAPS2_CANDROPZ16BIT),
991       FE(DDCAPS2_NONLOCALVIDMEM),
992       FE(DDCAPS2_NONLOCALVIDMEMCAPS),
993       FE(DDCAPS2_NOPAGELOCKREQUIRED),
994       FE(DDCAPS2_WIDESURFACES),
995       FE(DDCAPS2_CANFLIPODDEVEN),
996       FE(DDCAPS2_CANBOBHARDWARE),
997       FE(DDCAPS2_COPYFOURCC),
998       FE(DDCAPS2_PRIMARYGAMMA),
999       FE(DDCAPS2_CANRENDERWINDOWED),
1000       FE(DDCAPS2_CANCALIBRATEGAMMA),
1001       FE(DDCAPS2_FLIPINTERVAL),
1002       FE(DDCAPS2_FLIPNOVSYNC),
1003       FE(DDCAPS2_CANMANAGETEXTURE),
1004       FE(DDCAPS2_TEXMANINNONLOCALVIDMEM),
1005       FE(DDCAPS2_STEREO),
1006       FE(DDCAPS2_SYSTONONLOCAL_AS_SYSTOLOCAL)
1007     };
1008     static const flag_info flags3[] =
1009     {
1010       FE(DDCKEYCAPS_DESTBLT),
1011       FE(DDCKEYCAPS_DESTBLTCLRSPACE),
1012       FE(DDCKEYCAPS_DESTBLTCLRSPACEYUV),
1013       FE(DDCKEYCAPS_DESTBLTYUV),
1014       FE(DDCKEYCAPS_DESTOVERLAY),
1015       FE(DDCKEYCAPS_DESTOVERLAYCLRSPACE),
1016       FE(DDCKEYCAPS_DESTOVERLAYCLRSPACEYUV),
1017       FE(DDCKEYCAPS_DESTOVERLAYONEACTIVE),
1018       FE(DDCKEYCAPS_DESTOVERLAYYUV),
1019       FE(DDCKEYCAPS_SRCBLT),
1020       FE(DDCKEYCAPS_SRCBLTCLRSPACE),
1021       FE(DDCKEYCAPS_SRCBLTCLRSPACEYUV),
1022       FE(DDCKEYCAPS_SRCBLTYUV),
1023       FE(DDCKEYCAPS_SRCOVERLAY),
1024       FE(DDCKEYCAPS_SRCOVERLAYCLRSPACE),
1025       FE(DDCKEYCAPS_SRCOVERLAYCLRSPACEYUV),
1026       FE(DDCKEYCAPS_SRCOVERLAYONEACTIVE),
1027       FE(DDCKEYCAPS_SRCOVERLAYYUV),
1028       FE(DDCKEYCAPS_NOCOSTOVERLAY)
1029     };
1030     static const flag_info flags4[] =
1031     {
1032       FE(DDFXCAPS_BLTALPHA),
1033       FE(DDFXCAPS_OVERLAYALPHA),
1034       FE(DDFXCAPS_BLTARITHSTRETCHYN),
1035       FE(DDFXCAPS_BLTARITHSTRETCHY),
1036       FE(DDFXCAPS_BLTMIRRORLEFTRIGHT),
1037       FE(DDFXCAPS_BLTMIRRORUPDOWN),
1038       FE(DDFXCAPS_BLTROTATION),
1039       FE(DDFXCAPS_BLTROTATION90),
1040       FE(DDFXCAPS_BLTSHRINKX),
1041       FE(DDFXCAPS_BLTSHRINKXN),
1042       FE(DDFXCAPS_BLTSHRINKY),
1043       FE(DDFXCAPS_BLTSHRINKYN),
1044       FE(DDFXCAPS_BLTSTRETCHX),
1045       FE(DDFXCAPS_BLTSTRETCHXN),
1046       FE(DDFXCAPS_BLTSTRETCHY),
1047       FE(DDFXCAPS_BLTSTRETCHYN),
1048       FE(DDFXCAPS_OVERLAYARITHSTRETCHY),
1049       FE(DDFXCAPS_OVERLAYARITHSTRETCHYN),
1050       FE(DDFXCAPS_OVERLAYSHRINKX),
1051       FE(DDFXCAPS_OVERLAYSHRINKXN),
1052       FE(DDFXCAPS_OVERLAYSHRINKY),
1053       FE(DDFXCAPS_OVERLAYSHRINKYN),
1054       FE(DDFXCAPS_OVERLAYSTRETCHX),
1055       FE(DDFXCAPS_OVERLAYSTRETCHXN),
1056       FE(DDFXCAPS_OVERLAYSTRETCHY),
1057       FE(DDFXCAPS_OVERLAYSTRETCHYN),
1058       FE(DDFXCAPS_OVERLAYMIRRORLEFTRIGHT),
1059       FE(DDFXCAPS_OVERLAYMIRRORUPDOWN)
1060     };
1061     static const flag_info flags5[] =
1062     {
1063       FE(DDFXALPHACAPS_BLTALPHAEDGEBLEND),
1064       FE(DDFXALPHACAPS_BLTALPHAPIXELS),
1065       FE(DDFXALPHACAPS_BLTALPHAPIXELSNEG),
1066       FE(DDFXALPHACAPS_BLTALPHASURFACES),
1067       FE(DDFXALPHACAPS_BLTALPHASURFACESNEG),
1068       FE(DDFXALPHACAPS_OVERLAYALPHAEDGEBLEND),
1069       FE(DDFXALPHACAPS_OVERLAYALPHAPIXELS),
1070       FE(DDFXALPHACAPS_OVERLAYALPHAPIXELSNEG),
1071       FE(DDFXALPHACAPS_OVERLAYALPHASURFACES),
1072       FE(DDFXALPHACAPS_OVERLAYALPHASURFACESNEG)
1073     };
1074     static const flag_info flags6[] =
1075     {
1076       FE(DDPCAPS_4BIT),
1077       FE(DDPCAPS_8BITENTRIES),
1078       FE(DDPCAPS_8BIT),
1079       FE(DDPCAPS_INITIALIZE),
1080       FE(DDPCAPS_PRIMARYSURFACE),
1081       FE(DDPCAPS_PRIMARYSURFACELEFT),
1082       FE(DDPCAPS_ALLOW256),
1083       FE(DDPCAPS_VSYNC),
1084       FE(DDPCAPS_1BIT),
1085       FE(DDPCAPS_2BIT),
1086       FE(DDPCAPS_ALPHA),
1087     };
1088     static const flag_info flags7[] =
1089     {
1090       FE(DDSVCAPS_RESERVED1),
1091       FE(DDSVCAPS_RESERVED2),
1092       FE(DDSVCAPS_RESERVED3),
1093       FE(DDSVCAPS_RESERVED4),
1094       FE(DDSVCAPS_STEREOSEQUENTIAL),
1095     };
1096
1097     TRACE(" - dwSize : %d\n", lpcaps->dwSize);
1098     TRACE(" - dwCaps : "); DDRAW_dump_flags(lpcaps->dwCaps, flags1, sizeof(flags1)/sizeof(flags1[0]));
1099     TRACE(" - dwCaps2 : "); DDRAW_dump_flags(lpcaps->dwCaps2, flags2, sizeof(flags2)/sizeof(flags2[0]));
1100     TRACE(" - dwCKeyCaps : "); DDRAW_dump_flags(lpcaps->dwCKeyCaps, flags3, sizeof(flags3)/sizeof(flags3[0]));
1101     TRACE(" - dwFXCaps : "); DDRAW_dump_flags(lpcaps->dwFXCaps, flags4, sizeof(flags4)/sizeof(flags4[0]));
1102     TRACE(" - dwFXAlphaCaps : "); DDRAW_dump_flags(lpcaps->dwFXAlphaCaps, flags5, sizeof(flags5)/sizeof(flags5[0]));
1103     TRACE(" - dwPalCaps : "); DDRAW_dump_flags(lpcaps->dwPalCaps, flags6, sizeof(flags6)/sizeof(flags6[0]));
1104     TRACE(" - dwSVCaps : "); DDRAW_dump_flags(lpcaps->dwSVCaps, flags7, sizeof(flags7)/sizeof(flags7[0]));
1105     TRACE("...\n");
1106     TRACE(" - dwNumFourCCCodes : %d\n", lpcaps->dwNumFourCCCodes);
1107     TRACE(" - dwCurrVisibleOverlays : %d\n", lpcaps->dwCurrVisibleOverlays);
1108     TRACE(" - dwMinOverlayStretch : %d\n", lpcaps->dwMinOverlayStretch);
1109     TRACE(" - dwMaxOverlayStretch : %d\n", lpcaps->dwMaxOverlayStretch);
1110     TRACE("...\n");
1111     TRACE(" - ddsCaps : "); DDRAW_dump_DDSCAPS2(&lpcaps->ddsCaps);
1112 }
1113
1114 /*****************************************************************************
1115  * multiply_matrix
1116  *
1117  * Multiplies 2 4x4 matrices src1 and src2, and stores the result in dest.
1118  *
1119  * Params:
1120  *  dest: Pointer to the destination matrix
1121  *  src1: Pointer to the first source matrix
1122  *  src2: Pointer to the second source matrix
1123  *
1124  *****************************************************************************/
1125 void
1126 multiply_matrix(D3DMATRIX *dest,
1127                 const D3DMATRIX *src1,
1128                 const D3DMATRIX *src2)
1129 {
1130     D3DMATRIX temp;
1131
1132     /* Now do the multiplication 'by hand'.
1133        I know that all this could be optimised, but this will be done later :-) */
1134     temp._11 = (src1->_11 * src2->_11) + (src1->_21 * src2->_12) + (src1->_31 * src2->_13) + (src1->_41 * src2->_14);
1135     temp._21 = (src1->_11 * src2->_21) + (src1->_21 * src2->_22) + (src1->_31 * src2->_23) + (src1->_41 * src2->_24);
1136     temp._31 = (src1->_11 * src2->_31) + (src1->_21 * src2->_32) + (src1->_31 * src2->_33) + (src1->_41 * src2->_34);
1137     temp._41 = (src1->_11 * src2->_41) + (src1->_21 * src2->_42) + (src1->_31 * src2->_43) + (src1->_41 * src2->_44);
1138
1139     temp._12 = (src1->_12 * src2->_11) + (src1->_22 * src2->_12) + (src1->_32 * src2->_13) + (src1->_42 * src2->_14);
1140     temp._22 = (src1->_12 * src2->_21) + (src1->_22 * src2->_22) + (src1->_32 * src2->_23) + (src1->_42 * src2->_24);
1141     temp._32 = (src1->_12 * src2->_31) + (src1->_22 * src2->_32) + (src1->_32 * src2->_33) + (src1->_42 * src2->_34);
1142     temp._42 = (src1->_12 * src2->_41) + (src1->_22 * src2->_42) + (src1->_32 * src2->_43) + (src1->_42 * src2->_44);
1143
1144     temp._13 = (src1->_13 * src2->_11) + (src1->_23 * src2->_12) + (src1->_33 * src2->_13) + (src1->_43 * src2->_14);
1145     temp._23 = (src1->_13 * src2->_21) + (src1->_23 * src2->_22) + (src1->_33 * src2->_23) + (src1->_43 * src2->_24);
1146     temp._33 = (src1->_13 * src2->_31) + (src1->_23 * src2->_32) + (src1->_33 * src2->_33) + (src1->_43 * src2->_34);
1147     temp._43 = (src1->_13 * src2->_41) + (src1->_23 * src2->_42) + (src1->_33 * src2->_43) + (src1->_43 * src2->_44);
1148
1149     temp._14 = (src1->_14 * src2->_11) + (src1->_24 * src2->_12) + (src1->_34 * src2->_13) + (src1->_44 * src2->_14);
1150     temp._24 = (src1->_14 * src2->_21) + (src1->_24 * src2->_22) + (src1->_34 * src2->_23) + (src1->_44 * src2->_24);
1151     temp._34 = (src1->_14 * src2->_31) + (src1->_24 * src2->_32) + (src1->_34 * src2->_33) + (src1->_44 * src2->_34);
1152     temp._44 = (src1->_14 * src2->_41) + (src1->_24 * src2->_42) + (src1->_34 * src2->_43) + (src1->_44 * src2->_44);
1153
1154     /* And copy the new matrix in the good storage.. */
1155     memcpy(dest, &temp, 16 * sizeof(D3DVALUE));
1156 }
1157
1158 void multiply_matrix_D3D_way(D3DMATRIX* result, const D3DMATRIX *m1, const D3DMATRIX *m2)
1159 {
1160     D3DMATRIX temp;
1161
1162     temp._11 = m1->_11 * m2->_11 + m1->_12 * m2->_21 + m1->_13 * m2->_31 + m1->_14 * m2->_41;
1163     temp._12 = m1->_11 * m2->_12 + m1->_12 * m2->_22 + m1->_13 * m2->_32 + m1->_14 * m2->_42;
1164     temp._13 = m1->_11 * m2->_13 + m1->_12 * m2->_23 + m1->_13 * m2->_33 + m1->_14 * m2->_43;
1165     temp._14 = m1->_11 * m2->_14 + m1->_12 * m2->_24 + m1->_13 * m2->_34 + m1->_14 * m2->_44;
1166     temp._21 = m1->_21 * m2->_11 + m1->_22 * m2->_21 + m1->_23 * m2->_31 + m1->_24 * m2->_41;
1167     temp._22 = m1->_21 * m2->_12 + m1->_22 * m2->_22 + m1->_23 * m2->_32 + m1->_24 * m2->_42;
1168     temp._23 = m1->_21 * m2->_13 + m1->_22 * m2->_23 + m1->_23 * m2->_33 + m1->_24 * m2->_43;
1169     temp._24 = m1->_21 * m2->_14 + m1->_22 * m2->_24 + m1->_23 * m2->_34 + m1->_24 * m2->_44;
1170     temp._31 = m1->_31 * m2->_11 + m1->_32 * m2->_21 + m1->_33 * m2->_31 + m1->_34 * m2->_41;
1171     temp._32 = m1->_31 * m2->_12 + m1->_32 * m2->_22 + m1->_33 * m2->_32 + m1->_34 * m2->_42;
1172     temp._33 = m1->_31 * m2->_13 + m1->_32 * m2->_23 + m1->_33 * m2->_33 + m1->_34 * m2->_43;
1173     temp._34 = m1->_31 * m2->_14 + m1->_32 * m2->_24 + m1->_33 * m2->_34 + m1->_34 * m2->_44;
1174     temp._41 = m1->_41 * m2->_11 + m1->_42 * m2->_21 + m1->_43 * m2->_31 + m1->_44 * m2->_41;
1175     temp._42 = m1->_41 * m2->_12 + m1->_42 * m2->_22 + m1->_43 * m2->_32 + m1->_44 * m2->_42;
1176     temp._43 = m1->_41 * m2->_13 + m1->_42 * m2->_23 + m1->_43 * m2->_33 + m1->_44 * m2->_43;
1177     temp._44 = m1->_41 * m2->_14 + m1->_42 * m2->_24 + m1->_43 * m2->_34 + m1->_44 * m2->_44;
1178
1179     *result = temp;
1180 }
1181
1182 HRESULT
1183 hr_ddraw_from_wined3d(HRESULT hr)
1184 {
1185     switch(hr)
1186     {
1187         case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS;
1188         default: return hr;
1189     }
1190 }