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