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