utils.c 49.4 KB
Newer Older
1 2 3 4 5 6
/*
 * DirectDraw helper functions
 *
 * Copyright (c) 1997-2000 Marcus Meissner
 * Copyright (c) 1998 Lionel Ulmer
 * Copyright (c) 2000 TransGaming Technologies Inc.
7
 * Copyright (c) 2006 Stefan Dösinger
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

#include "ddraw_private.h"

WINE_DEFAULT_DEBUG_CHANNEL(ddraw);

28
static void DDRAW_dump_pixelformat(const DDPIXELFORMAT *pf);
29

30
void ddrawformat_from_wined3dformat(DDPIXELFORMAT *DDPixelFormat, enum wined3d_format_id wined3d_format)
31 32 33 34 35 36 37
{
    DWORD Size = DDPixelFormat->dwSize;

    if(Size==0) return;

    memset(DDPixelFormat, 0x00, Size);
    DDPixelFormat->dwSize = Size;
38
    switch (wined3d_format)
39
    {
40
        case WINED3DFMT_B8G8R8_UNORM:
41 42 43 44 45 46 47 48 49
            DDPixelFormat->dwFlags = DDPF_RGB;
            DDPixelFormat->dwFourCC = 0;
            DDPixelFormat->u1.dwRGBBitCount = 24;
            DDPixelFormat->u2.dwRBitMask = 0x00ff0000;
            DDPixelFormat->u3.dwGBitMask = 0x0000ff00;
            DDPixelFormat->u4.dwBBitMask = 0x000000ff;
            DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
            break;

50
        case WINED3DFMT_B8G8R8A8_UNORM:
51 52 53 54 55 56 57 58 59
            DDPixelFormat->dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
            DDPixelFormat->dwFourCC = 0;
            DDPixelFormat->u1.dwRGBBitCount = 32;
            DDPixelFormat->u2.dwRBitMask = 0x00ff0000;
            DDPixelFormat->u3.dwGBitMask = 0x0000ff00;
            DDPixelFormat->u4.dwBBitMask = 0x000000ff;
            DDPixelFormat->u5.dwRGBAlphaBitMask = 0xff000000;
            break;

60
        case WINED3DFMT_B8G8R8X8_UNORM:
61 62 63 64 65 66 67 68 69
            DDPixelFormat->dwFlags = DDPF_RGB;
            DDPixelFormat->dwFourCC = 0;
            DDPixelFormat->u1.dwRGBBitCount = 32;
            DDPixelFormat->u2.dwRBitMask = 0x00ff0000;
            DDPixelFormat->u3.dwGBitMask = 0x0000ff00;
            DDPixelFormat->u4.dwBBitMask = 0x000000ff;
            DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
            break;

70
        case WINED3DFMT_R8G8B8X8_UNORM:
71 72 73 74 75 76 77 78 79
            DDPixelFormat->dwFlags = DDPF_RGB;
            DDPixelFormat->dwFourCC = 0;
            DDPixelFormat->u1.dwRGBBitCount = 32;
            DDPixelFormat->u2.dwRBitMask = 0x000000ff;
            DDPixelFormat->u3.dwGBitMask = 0x0000ff00;
            DDPixelFormat->u4.dwBBitMask = 0x00ff0000;
            DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
            break;

80
        case WINED3DFMT_B5G6R5_UNORM:
81 82 83 84 85 86 87 88 89
            DDPixelFormat->dwFlags = DDPF_RGB;
            DDPixelFormat->dwFourCC = 0;
            DDPixelFormat->u1.dwRGBBitCount = 16;
            DDPixelFormat->u2.dwRBitMask = 0xF800;
            DDPixelFormat->u3.dwGBitMask = 0x07E0;
            DDPixelFormat->u4.dwBBitMask = 0x001F;
            DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
            break;

90
        case WINED3DFMT_B5G5R5X1_UNORM:
91 92 93 94 95 96 97 98 99
            DDPixelFormat->dwFlags = DDPF_RGB;
            DDPixelFormat->dwFourCC = 0;
            DDPixelFormat->u1.dwRGBBitCount = 16;
            DDPixelFormat->u2.dwRBitMask = 0x7C00;
            DDPixelFormat->u3.dwGBitMask = 0x03E0;
            DDPixelFormat->u4.dwBBitMask = 0x001F;
            DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
            break;

100
        case WINED3DFMT_B5G5R5A1_UNORM:
101 102 103 104 105 106 107 108 109
            DDPixelFormat->dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
            DDPixelFormat->dwFourCC = 0;
            DDPixelFormat->u1.dwRGBBitCount = 16;
            DDPixelFormat->u2.dwRBitMask = 0x7C00;
            DDPixelFormat->u3.dwGBitMask = 0x03E0;
            DDPixelFormat->u4.dwBBitMask = 0x001F;
            DDPixelFormat->u5.dwRGBAlphaBitMask = 0x8000;
            break;

110
        case WINED3DFMT_B4G4R4A4_UNORM:
111 112 113 114 115 116 117 118 119
            DDPixelFormat->dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
            DDPixelFormat->dwFourCC = 0;
            DDPixelFormat->u1.dwRGBBitCount = 16;
            DDPixelFormat->u2.dwRBitMask = 0x0F00;
            DDPixelFormat->u3.dwGBitMask = 0x00F0;
            DDPixelFormat->u4.dwBBitMask = 0x000F;
            DDPixelFormat->u5.dwRGBAlphaBitMask = 0xF000;
            break;

120
        case WINED3DFMT_B2G3R3_UNORM:
121 122 123 124 125 126 127 128 129
            DDPixelFormat->dwFlags = DDPF_RGB;
            DDPixelFormat->dwFourCC = 0;
            DDPixelFormat->u1.dwRGBBitCount = 8;
            DDPixelFormat->u2.dwRBitMask = 0xE0;
            DDPixelFormat->u3.dwGBitMask = 0x1C;
            DDPixelFormat->u4.dwBBitMask = 0x03;
            DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0x0;
            break;

130
        case WINED3DFMT_P8_UINT:
131 132 133 134 135 136 137 138
            DDPixelFormat->dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
            DDPixelFormat->dwFourCC = 0;
            DDPixelFormat->u1.dwRGBBitCount = 8;
            DDPixelFormat->u2.dwRBitMask = 0x00;
            DDPixelFormat->u3.dwGBitMask = 0x00;
            DDPixelFormat->u4.dwBBitMask = 0x00;
            break;

139
        case WINED3DFMT_A8_UNORM:
140 141 142 143 144 145 146 147 148
            DDPixelFormat->dwFlags = DDPF_ALPHA;
            DDPixelFormat->dwFourCC = 0;
            DDPixelFormat->u1.dwAlphaBitDepth = 8;
            DDPixelFormat->u2.dwRBitMask = 0x0;
            DDPixelFormat->u3.dwZBitMask = 0x0;
            DDPixelFormat->u4.dwStencilBitMask = 0x0;
            DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0x0;
            break;

149
        case WINED3DFMT_B2G3R3A8_UNORM:
150 151 152 153 154 155
            DDPixelFormat->dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
            DDPixelFormat->dwFourCC = 0;
            DDPixelFormat->u1.dwRGBBitCount = 16;
            DDPixelFormat->u2.dwRBitMask = 0x00E0;
            DDPixelFormat->u3.dwGBitMask = 0x001C;
            DDPixelFormat->u4.dwBBitMask = 0x0003;
156
            DDPixelFormat->u5.dwRGBAlphaBitMask = 0xFF00;
157 158
            break;

159
        case WINED3DFMT_B4G4R4X4_UNORM:
160 161 162 163 164 165 166
            DDPixelFormat->dwFlags = DDPF_RGB;
            DDPixelFormat->dwFourCC = 0;
            DDPixelFormat->u1.dwRGBBitCount = 16;
            DDPixelFormat->u2.dwRBitMask = 0x0F00;
            DDPixelFormat->u3.dwGBitMask = 0x00F0;
            DDPixelFormat->u4.dwBBitMask = 0x000F;
            DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
167
            break;
168 169 170

        /* How are Z buffer bit depth and Stencil buffer bit depth related?
         */
171
        case WINED3DFMT_D16_UNORM:
172 173 174 175 176 177
            DDPixelFormat->dwFlags = DDPF_ZBUFFER;
            DDPixelFormat->dwFourCC = 0;
            DDPixelFormat->u1.dwZBufferBitDepth = 16;
            DDPixelFormat->u2.dwStencilBitDepth = 0;
            DDPixelFormat->u3.dwZBitMask = 0x0000FFFF;
            DDPixelFormat->u4.dwStencilBitMask = 0x0;
178
            DDPixelFormat->u5.dwRGBZBitMask = 0x00000000;
179 180
            break;

181
        case WINED3DFMT_D32_UNORM:
182 183 184 185 186 187
            DDPixelFormat->dwFlags = DDPF_ZBUFFER;
            DDPixelFormat->dwFourCC = 0;
            DDPixelFormat->u1.dwZBufferBitDepth = 32;
            DDPixelFormat->u2.dwStencilBitDepth = 0;
            DDPixelFormat->u3.dwZBitMask = 0xFFFFFFFF;
            DDPixelFormat->u4.dwStencilBitMask = 0x0;
188
            DDPixelFormat->u5.dwRGBZBitMask = 0x00000000;
189 190
            break;

191
        case WINED3DFMT_S4X4_UINT_D24_UNORM:
192 193 194
            DDPixelFormat->dwFlags = DDPF_ZBUFFER | DDPF_STENCILBUFFER;
            DDPixelFormat->dwFourCC = 0;
            /* Should I set dwZBufferBitDepth to 32 here? */
195
            DDPixelFormat->u1.dwZBufferBitDepth = 32;
196
            DDPixelFormat->u2.dwStencilBitDepth = 4;
197 198
            DDPixelFormat->u3.dwZBitMask = 0x00FFFFFF;
            DDPixelFormat->u4.dwStencilBitMask = 0x0F000000;
199 200 201
            DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
            break;

202
        case WINED3DFMT_D24_UNORM_S8_UINT:
203 204
            DDPixelFormat->dwFlags = DDPF_ZBUFFER | DDPF_STENCILBUFFER;
            DDPixelFormat->dwFourCC = 0;
205
            DDPixelFormat->u1.dwZBufferBitDepth = 32;
206
            DDPixelFormat->u2.dwStencilBitDepth = 8;
207
            DDPixelFormat->u3.dwZBitMask = 0x00FFFFFF;
208
            DDPixelFormat->u4.dwStencilBitMask = 0xFF000000;
209 210 211
            DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
            break;

212
        case WINED3DFMT_X8D24_UNORM:
213 214
            DDPixelFormat->dwFlags = DDPF_ZBUFFER;
            DDPixelFormat->dwFourCC = 0;
215 216
            DDPixelFormat->u1.dwZBufferBitDepth = 32;
            DDPixelFormat->u2.dwStencilBitDepth = 0;
217
            DDPixelFormat->u3.dwZBitMask = 0x00FFFFFF;
218
            DDPixelFormat->u4.dwStencilBitMask = 0x00000000;
219 220
            DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
            break;
221

222
        case WINED3DFMT_S1_UINT_D15_UNORM:
223 224
            DDPixelFormat->dwFlags = DDPF_ZBUFFER | DDPF_STENCILBUFFER;
            DDPixelFormat->dwFourCC = 0;
225
            DDPixelFormat->u1.dwZBufferBitDepth = 16;
226
            DDPixelFormat->u2.dwStencilBitDepth = 1;
227 228
            DDPixelFormat->u3.dwZBitMask = 0x7fff;
            DDPixelFormat->u4.dwStencilBitMask = 0x8000;
229 230 231 232 233
            DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
            break;

        case WINED3DFMT_UYVY:
        case WINED3DFMT_YUY2:
234 235
            DDPixelFormat->u1.dwYUVBitCount = 16;
            DDPixelFormat->dwFlags = DDPF_FOURCC;
236
            DDPixelFormat->dwFourCC = wined3d_format;
237 238
            break;

239
        case WINED3DFMT_YV12:
240 241
            DDPixelFormat->u1.dwYUVBitCount = 12;
            DDPixelFormat->dwFlags = DDPF_FOURCC;
242
            DDPixelFormat->dwFourCC = wined3d_format;
243 244
            break;

245 246 247 248 249
        case WINED3DFMT_DXT1:
        case WINED3DFMT_DXT2:
        case WINED3DFMT_DXT3:
        case WINED3DFMT_DXT4:
        case WINED3DFMT_DXT5:
250
        case WINED3DFMT_MULTI2_ARGB8:
251 252 253
        case WINED3DFMT_G8R8_G8B8:
        case WINED3DFMT_R8G8_B8G8:
            DDPixelFormat->dwFlags = DDPF_FOURCC;
254
            DDPixelFormat->dwFourCC = wined3d_format;
255 256 257
            break;

        /* Luminance */
258
        case WINED3DFMT_L8_UNORM:
259 260 261 262 263 264 265 266 267
            DDPixelFormat->dwFlags = DDPF_LUMINANCE;
            DDPixelFormat->dwFourCC = 0;
            DDPixelFormat->u1.dwLuminanceBitCount = 8;
            DDPixelFormat->u2.dwLuminanceBitMask = 0xff;
            DDPixelFormat->u3.dwBumpDvBitMask = 0x0;
            DDPixelFormat->u4.dwBumpLuminanceBitMask = 0x0;
            DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0x0;
            break;

268
        case WINED3DFMT_L4A4_UNORM:
269 270 271 272 273 274 275 276 277
            DDPixelFormat->dwFlags = DDPF_ALPHAPIXELS | DDPF_LUMINANCE;
            DDPixelFormat->dwFourCC = 0;
            DDPixelFormat->u1.dwLuminanceBitCount = 4;
            DDPixelFormat->u2.dwLuminanceBitMask = 0x0f;
            DDPixelFormat->u3.dwBumpDvBitMask = 0x0;
            DDPixelFormat->u4.dwBumpLuminanceBitMask = 0x0;
            DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0xf0;
            break;

278
        case WINED3DFMT_L8A8_UNORM:
279 280 281 282 283 284 285 286 287 288
            DDPixelFormat->dwFlags = DDPF_ALPHAPIXELS | DDPF_LUMINANCE;
            DDPixelFormat->dwFourCC = 0;
            DDPixelFormat->u1.dwLuminanceBitCount = 16;
            DDPixelFormat->u2.dwLuminanceBitMask = 0x00ff;
            DDPixelFormat->u3.dwBumpDvBitMask = 0x0;
            DDPixelFormat->u4.dwBumpLuminanceBitMask = 0x0;
            DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0xff00;
            break;

        /* Bump mapping */
289
        case WINED3DFMT_R8G8_SNORM:
290 291 292 293 294 295 296 297 298
            DDPixelFormat->dwFlags = DDPF_BUMPDUDV;
            DDPixelFormat->dwFourCC = 0;
            DDPixelFormat->u1.dwBumpBitCount = 16;
            DDPixelFormat->u2.dwBumpDuBitMask =         0x000000ff;
            DDPixelFormat->u3.dwBumpDvBitMask =         0x0000ff00;
            DDPixelFormat->u4.dwBumpLuminanceBitMask =  0x00000000;
            DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0x00000000;
            break;

299
        case WINED3DFMT_R5G5_SNORM_L6_UNORM:
300
            DDPixelFormat->dwFlags = DDPF_BUMPDUDV | DDPF_BUMPLUMINANCE;
301 302 303 304 305 306 307 308
            DDPixelFormat->dwFourCC = 0;
            DDPixelFormat->u1.dwBumpBitCount = 16;
            DDPixelFormat->u2.dwBumpDuBitMask =         0x0000001f;
            DDPixelFormat->u3.dwBumpDvBitMask =         0x000003e0;
            DDPixelFormat->u4.dwBumpLuminanceBitMask =  0x0000fc00;
            DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0x00000000;
            break;

309
        case WINED3DFMT_R8G8_SNORM_L8X8_UNORM:
310
            DDPixelFormat->dwFlags = DDPF_BUMPDUDV | DDPF_BUMPLUMINANCE;
311 312 313 314 315 316 317 318
            DDPixelFormat->dwFourCC = 0;
            DDPixelFormat->u1.dwBumpBitCount = 32;
            DDPixelFormat->u2.dwBumpDuBitMask =         0x000000ff;
            DDPixelFormat->u3.dwBumpDvBitMask =         0x0000ff00;
            DDPixelFormat->u4.dwBumpLuminanceBitMask =  0x00ff0000;
            DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0x00000000;
            break;

319
        default:
320 321
            FIXME("Unhandled wined3d format %#x.\n", wined3d_format);
            break;
322 323 324 325 326 327 328
    }

    if(TRACE_ON(ddraw)) {
        TRACE("Returning: ");
        DDRAW_dump_pixelformat(DDPixelFormat);
    }
}
329 330

enum wined3d_format_id wined3dformat_from_ddrawformat(const DDPIXELFORMAT *DDPixelFormat)
331
{
332
    TRACE("Convert a DirectDraw Pixelformat to a WineD3D Pixelformat\n");
333 334 335 336 337 338 339
    if(TRACE_ON(ddraw))
    {
        DDRAW_dump_pixelformat(DDPixelFormat);
    }

    if(DDPixelFormat->dwFlags & DDPF_PALETTEINDEXED8)
    {
340
        return WINED3DFMT_P8_UINT;
341 342 343 344
    }
    else if(DDPixelFormat->dwFlags & (DDPF_PALETTEINDEXED1 | DDPF_PALETTEINDEXED2 | DDPF_PALETTEINDEXED4) )
    {
        FIXME("DDPF_PALETTEINDEXED1 to DDPF_PALETTEINDEXED4 are not supported by WineD3D (yet). Returning WINED3DFMT_P8\n");
345
        return WINED3DFMT_P8_UINT;
346 347 348 349 350 351 352
    }
    else if(DDPixelFormat->dwFlags & DDPF_RGB)
    {
        switch(DDPixelFormat->u1.dwRGBBitCount)
        {
            case 8:
                /* This is the only format that can match here */
353
                return WINED3DFMT_B2G3R3_UNORM;
354 355 356 357 358 359 360

            case 16:
                /* Read the Color masks */
                if( (DDPixelFormat->u2.dwRBitMask == 0xF800) &&
                    (DDPixelFormat->u3.dwGBitMask == 0x07E0) &&
                    (DDPixelFormat->u4.dwBBitMask == 0x001F) )
                {
361
                    return WINED3DFMT_B5G6R5_UNORM;
362 363 364 365 366 367 368 369
                }

                if( (DDPixelFormat->u2.dwRBitMask == 0x7C00) &&
                    (DDPixelFormat->u3.dwGBitMask == 0x03E0) &&
                    (DDPixelFormat->u4.dwBBitMask == 0x001F) )
                {
                    if( (DDPixelFormat->dwFlags & DDPF_ALPHAPIXELS) &&
                        (DDPixelFormat->u5.dwRGBAlphaBitMask == 0x8000))
370
                        return WINED3DFMT_B5G5R5A1_UNORM;
371
                    else
372
                        return WINED3DFMT_B5G5R5X1_UNORM;
373 374 375 376 377 378 379 380
                }

                if( (DDPixelFormat->u2.dwRBitMask == 0x0F00) &&
                    (DDPixelFormat->u3.dwGBitMask == 0x00F0) &&
                    (DDPixelFormat->u4.dwBBitMask == 0x000F) )
                {
                    if( (DDPixelFormat->dwFlags & DDPF_ALPHAPIXELS) &&
                        (DDPixelFormat->u5.dwRGBAlphaBitMask == 0xF000))
381
                        return WINED3DFMT_B4G4R4A4_UNORM;
382
                    else
383
                        return WINED3DFMT_B4G4R4X4_UNORM;
384 385 386 387 388 389 390 391
                }

                if( (DDPixelFormat->dwFlags & DDPF_ALPHAPIXELS) &&
                    (DDPixelFormat->u5.dwRGBAlphaBitMask == 0xFF00) &&
                    (DDPixelFormat->u2.dwRBitMask == 0x00E0) &&
                    (DDPixelFormat->u3.dwGBitMask == 0x001C) &&
                    (DDPixelFormat->u4.dwBBitMask == 0x0003) )
                {
392
                    return WINED3DFMT_B2G3R3A8_UNORM;
393
                }
394
                WARN("16 bit RGB Pixel format does not match.\n");
395 396 397
                return WINED3DFMT_UNKNOWN;

            case 24:
398
                return WINED3DFMT_B8G8R8_UNORM;
399 400 401 402 403 404 405 406 407

            case 32:
                /* Read the Color masks */
                if( (DDPixelFormat->u2.dwRBitMask == 0x00FF0000) &&
                    (DDPixelFormat->u3.dwGBitMask == 0x0000FF00) &&
                    (DDPixelFormat->u4.dwBBitMask == 0x000000FF) )
                {
                    if( (DDPixelFormat->dwFlags & DDPF_ALPHAPIXELS) &&
                        (DDPixelFormat->u5.dwRGBAlphaBitMask == 0xFF000000))
408
                        return WINED3DFMT_B8G8R8A8_UNORM;
409
                    else
410
                        return WINED3DFMT_B8G8R8X8_UNORM;
411 412

                }
413
                WARN("32 bit RGB pixel format does not match.\n");
414
                return WINED3DFMT_UNKNOWN;
415 416

            default:
417
                WARN("Invalid dwRGBBitCount in Pixelformat structure.\n");
418 419 420 421 422 423 424 425 426
                return WINED3DFMT_UNKNOWN;
        }
    }
    else if( (DDPixelFormat->dwFlags & DDPF_ALPHA) )
    {
        /* Alpha only Pixelformat */
        switch(DDPixelFormat->u1.dwAlphaBitDepth)
        {
            case 8:
427
                return WINED3DFMT_A8_UNORM;
428 429

            default:
430
                WARN("Invalid AlphaBitDepth in Alpha-Only Pixelformat.\n");
431 432 433 434 435 436 437 438 439 440 441 442 443
                return WINED3DFMT_UNKNOWN;
        }
    }
    else if(DDPixelFormat->dwFlags & DDPF_LUMINANCE)
    {
        /* Luminance-only or luminance-alpha */
        if(DDPixelFormat->dwFlags & DDPF_ALPHAPIXELS)
        {
            /* Luminance with Alpha */
            switch(DDPixelFormat->u1.dwLuminanceBitCount)
            {
                case 4:
                    if(DDPixelFormat->u1.dwAlphaBitDepth == 4)
444
                        return WINED3DFMT_L4A4_UNORM;
445
                    WARN("Unknown Alpha / Luminance bit depth combination.\n");
446 447 448
                    return WINED3DFMT_UNKNOWN;

                case 6:
449
                    FIXME("A luminance Pixelformat shouldn't have 6 luminance bits. Returning D3DFMT_L6V5U5 for now.\n");
450
                    return WINED3DFMT_R5G5_SNORM_L6_UNORM;
451 452 453

                case 8:
                    if(DDPixelFormat->u1.dwAlphaBitDepth == 8)
454
                        return WINED3DFMT_L8A8_UNORM;
455
                    WARN("Unknown Alpha / Lumincase bit depth combination.\n");
456 457 458 459 460 461 462 463 464
                    return WINED3DFMT_UNKNOWN;
            }
        }
        else
        {
            /* Luminance-only */
            switch(DDPixelFormat->u1.dwLuminanceBitCount)
            {
                case 6:
465
                    FIXME("A luminance Pixelformat shouldn't have 6 luminance bits. Returning D3DFMT_L6V5U5 for now.\n");
466
                    return WINED3DFMT_R5G5_SNORM_L6_UNORM;
467 468

                case 8:
469
                    return WINED3DFMT_L8_UNORM;
470 471

                default:
472
                    WARN("Unknown luminance-only bit depth 0x%x.\n", DDPixelFormat->u1.dwLuminanceBitCount);
473 474 475 476 477 478 479 480 481 482 483 484
                    return WINED3DFMT_UNKNOWN;
             }
        }
    }
    else if(DDPixelFormat->dwFlags & DDPF_ZBUFFER)
    {
        /* Z buffer */
        if(DDPixelFormat->dwFlags & DDPF_STENCILBUFFER)
        {
            switch(DDPixelFormat->u1.dwZBufferBitDepth)
            {
                case 16:
485
                    if (DDPixelFormat->u2.dwStencilBitDepth == 1) return WINED3DFMT_S1_UINT_D15_UNORM;
486
                    WARN("Unknown depth stencil format: 16 z bits, %u stencil bits.\n",
487
                            DDPixelFormat->u2.dwStencilBitDepth);
488 489 490
                    return WINED3DFMT_UNKNOWN;

                case 32:
491 492
                    if (DDPixelFormat->u2.dwStencilBitDepth == 8) return WINED3DFMT_D24_UNORM_S8_UINT;
                    else if (DDPixelFormat->u2.dwStencilBitDepth == 4) return WINED3DFMT_S4X4_UINT_D24_UNORM;
493
                    WARN("Unknown depth stencil format: 32 z bits, %u stencil bits.\n",
494 495
                            DDPixelFormat->u2.dwStencilBitDepth);
                    return WINED3DFMT_UNKNOWN;
496 497

                default:
498
                    WARN("Unknown depth stencil format: %u z bits, %u stencil bits.\n",
499
                            DDPixelFormat->u1.dwZBufferBitDepth, DDPixelFormat->u2.dwStencilBitDepth);
500 501 502 503 504 505 506 507
                    return WINED3DFMT_UNKNOWN;
            }
        }
        else
        {
            switch(DDPixelFormat->u1.dwZBufferBitDepth)
            {
                case 16:
508
                    return WINED3DFMT_D16_UNORM;
509 510

                case 24:
511 512
                    return WINED3DFMT_X8D24_UNORM;

513
                case 32:
514 515 516 517 518 519
                    if (DDPixelFormat->u3.dwZBitMask == 0x00FFFFFF) return WINED3DFMT_X8D24_UNORM;
                    else if (DDPixelFormat->u3.dwZBitMask == 0xFFFFFF00) return WINED3DFMT_X8D24_UNORM;
                    else if (DDPixelFormat->u3.dwZBitMask == 0xFFFFFFFF) return WINED3DFMT_D32_UNORM;
                    WARN("Unknown depth-only format: 32 z bits, mask 0x%08x\n",
                            DDPixelFormat->u3.dwZBitMask);
                    return WINED3DFMT_UNKNOWN;
520 521

                default:
522 523
                    WARN("Unknown depth-only format: %u z bits, mask 0x%08x\n",
                            DDPixelFormat->u1.dwZBufferBitDepth, DDPixelFormat->u3.dwZBitMask);
524 525 526 527 528 529
                    return WINED3DFMT_UNKNOWN;
            }
        }
    }
    else if(DDPixelFormat->dwFlags & DDPF_FOURCC)
    {
530
        return DDPixelFormat->dwFourCC;
531 532 533 534 535 536 537 538
    }
    else if(DDPixelFormat->dwFlags & DDPF_BUMPDUDV)
    {
        if( (DDPixelFormat->u1.dwBumpBitCount         == 16        ) &&
            (DDPixelFormat->u2.dwBumpDuBitMask        == 0x000000ff) &&
            (DDPixelFormat->u3.dwBumpDvBitMask        == 0x0000ff00) &&
            (DDPixelFormat->u4.dwBumpLuminanceBitMask == 0x00000000) )
        {
539
            return WINED3DFMT_R8G8_SNORM;
540 541 542 543 544 545
        }
        else if ( (DDPixelFormat->u1.dwBumpBitCount         == 16        ) &&
                  (DDPixelFormat->u2.dwBumpDuBitMask        == 0x0000001f) &&
                  (DDPixelFormat->u3.dwBumpDvBitMask        == 0x000003e0) &&
                  (DDPixelFormat->u4.dwBumpLuminanceBitMask == 0x0000fc00) )
        {
546
            return WINED3DFMT_R5G5_SNORM_L6_UNORM;
547
        }
548 549 550 551 552
        else if ( (DDPixelFormat->u1.dwBumpBitCount         == 32        ) &&
                  (DDPixelFormat->u2.dwBumpDuBitMask        == 0x000000ff) &&
                  (DDPixelFormat->u3.dwBumpDvBitMask        == 0x0000ff00) &&
                  (DDPixelFormat->u4.dwBumpLuminanceBitMask == 0x00ff0000) )
        {
553
            return WINED3DFMT_R8G8_SNORM_L8X8_UNORM;
554
        }
555 556
    }

557
    WARN("Unknown Pixelformat.\n");
558 559 560
    return WINED3DFMT_UNKNOWN;
}

561 562
unsigned int wined3dmapflags_from_ddrawmapflags(unsigned int flags)
{
563
    static const unsigned int handled = DDLOCK_NOSYSLOCK
564 565 566 567 568 569
            | DDLOCK_NOOVERWRITE
            | DDLOCK_DISCARDCONTENTS
            | DDLOCK_DONOTWAIT;
    unsigned int wined3d_flags;

    wined3d_flags = flags & handled;
570
    if (!(flags & (DDLOCK_NOOVERWRITE | DDLOCK_DISCARDCONTENTS | DDLOCK_WRITEONLY)))
571 572 573 574 575
        wined3d_flags |= WINED3D_MAP_READ;
    if (!(flags & DDLOCK_READONLY))
        wined3d_flags |= WINED3D_MAP_WRITE;
    if (!(wined3d_flags & (WINED3D_MAP_READ | WINED3D_MAP_WRITE)))
        wined3d_flags |= WINED3D_MAP_READ | WINED3D_MAP_WRITE;
576 577
    if (flags & DDLOCK_NODIRTYUPDATE)
        wined3d_flags |= WINED3D_MAP_NO_DIRTY_UPDATE;
578
    flags &= ~(handled | DDLOCK_WAIT | DDLOCK_READONLY | DDLOCK_WRITEONLY | DDLOCK_NODIRTYUPDATE);
579 580 581 582 583 584 585

    if (flags)
        FIXME("Unhandled flags %#x.\n", flags);

    return wined3d_flags;
}

586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671
static float colour_to_float(DWORD colour, DWORD mask)
{
    if (!mask)
        return 0.0f;
    return (float)(colour & mask) / (float)mask;
}

BOOL wined3d_colour_from_ddraw_colour(const DDPIXELFORMAT *pf, const struct ddraw_palette *palette,
        DWORD colour, struct wined3d_color *wined3d_colour)
{
    if (pf->dwFlags & DDPF_ALPHA)
    {
        DWORD size, mask;

        size = pf->u1.dwAlphaBitDepth;
        mask = size < 32 ? (1u << size) - 1 : ~0u;
        wined3d_colour->r = 0.0f;
        wined3d_colour->g = 0.0f;
        wined3d_colour->b = 0.0f;
        wined3d_colour->a = colour_to_float(colour, mask);
        return TRUE;
    }

    if (pf->dwFlags & DDPF_FOURCC)
    {
        WARN("FourCC formats not supported.\n");
        goto fail;
    }

    if (pf->dwFlags & DDPF_PALETTEINDEXED8)
    {
        PALETTEENTRY entry;

        colour &= 0xff;
        if (!palette || FAILED(wined3d_palette_get_entries(palette->wined3d_palette, 0, colour, 1, &entry)))
        {
            wined3d_colour->r = 0.0f;
            wined3d_colour->g = 0.0f;
            wined3d_colour->b = 0.0f;
        }
        else
        {
            wined3d_colour->r = entry.peRed / 255.0f;
            wined3d_colour->g = entry.peGreen / 255.0f;
            wined3d_colour->b = entry.peBlue / 255.0f;
        }
        wined3d_colour->a = colour / 255.0f;
        return TRUE;
    }

    if (pf->dwFlags & DDPF_RGB)
    {
        wined3d_colour->r = colour_to_float(colour, pf->u2.dwRBitMask);
        wined3d_colour->g = colour_to_float(colour, pf->u3.dwGBitMask);
        wined3d_colour->b = colour_to_float(colour, pf->u4.dwBBitMask);
        if (pf->dwFlags & DDPF_ALPHAPIXELS)
            wined3d_colour->a = colour_to_float(colour, pf->u5.dwRGBAlphaBitMask);
        else
            wined3d_colour->a = 0.0f;
        return TRUE;
    }

    if (pf->dwFlags & DDPF_ZBUFFER)
    {
        wined3d_colour->r = colour_to_float(colour, pf->u3.dwZBitMask);
        if (pf->dwFlags & DDPF_STENCILBUFFER)
            wined3d_colour->g = colour_to_float(colour, pf->u4.dwStencilBitMask);
        else
            wined3d_colour->g = 0.0f;
        wined3d_colour->b = 0.0f;
        wined3d_colour->a = 0.0f;
        return TRUE;
    }

    FIXME("Unhandled pixel format.\n");
    DDRAW_dump_pixelformat(pf);

fail:
    wined3d_colour->r = 0.0f;
    wined3d_colour->g = 0.0f;
    wined3d_colour->b = 0.0f;
    wined3d_colour->a = 0.0f;

    return FALSE;
}

672 673 674
/*****************************************************************************
 * Various dumping functions.
 *
Andrew Riedi's avatar
Andrew Riedi committed
675
 * They write the contents of a specific function to a TRACE.
676 677 678 679 680
 *
 *****************************************************************************/
static void
DDRAW_dump_DWORD(const void *in)
{
681
    TRACE("%d\n", *((const DWORD *) in));
682 683 684 685
}
static void
DDRAW_dump_PTR(const void *in)
{
686
    TRACE("%p\n", *((const void * const*) in));
687
}
688
static void
689 690
DDRAW_dump_DDCOLORKEY(const DDCOLORKEY *ddck)
{
691
    TRACE("Low : 0x%08x  - High : 0x%08x\n", ddck->dwColorSpaceLowValue, ddck->dwColorSpaceHighValue);
692
}
693

694
static void DDRAW_dump_flags_nolf(DWORD flags, const struct flag_info *names, size_t num_names)
695
{
696
    unsigned int i;
697 698 699 700

    for (i=0; i < num_names; i++)
        if ((flags & names[i].val) ||      /* standard flag value */
            ((!flags) && (!names[i].val))) /* zero value only */
701
            TRACE("%s ", names[i].name);
702
}
703

704
static void DDRAW_dump_flags(DWORD flags, const struct flag_info *names, size_t num_names)
705 706 707
{
    DDRAW_dump_flags_nolf(flags, names, num_names);
    TRACE("\n");
708 709
}

710 711
void DDRAW_dump_DDSCAPS2(const DDSCAPS2 *in)
{
712 713
    static const struct flag_info flags[] =
    {
714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744
        FE(DDSCAPS_RESERVED1),
        FE(DDSCAPS_ALPHA),
        FE(DDSCAPS_BACKBUFFER),
        FE(DDSCAPS_COMPLEX),
        FE(DDSCAPS_FLIP),
        FE(DDSCAPS_FRONTBUFFER),
        FE(DDSCAPS_OFFSCREENPLAIN),
        FE(DDSCAPS_OVERLAY),
        FE(DDSCAPS_PALETTE),
        FE(DDSCAPS_PRIMARYSURFACE),
        FE(DDSCAPS_PRIMARYSURFACELEFT),
        FE(DDSCAPS_SYSTEMMEMORY),
        FE(DDSCAPS_TEXTURE),
        FE(DDSCAPS_3DDEVICE),
        FE(DDSCAPS_VIDEOMEMORY),
        FE(DDSCAPS_VISIBLE),
        FE(DDSCAPS_WRITEONLY),
        FE(DDSCAPS_ZBUFFER),
        FE(DDSCAPS_OWNDC),
        FE(DDSCAPS_LIVEVIDEO),
        FE(DDSCAPS_HWCODEC),
        FE(DDSCAPS_MODEX),
        FE(DDSCAPS_MIPMAP),
        FE(DDSCAPS_RESERVED2),
        FE(DDSCAPS_ALLOCONLOAD),
        FE(DDSCAPS_VIDEOPORT),
        FE(DDSCAPS_LOCALVIDMEM),
        FE(DDSCAPS_NONLOCALVIDMEM),
        FE(DDSCAPS_STANDARDVGAMODE),
        FE(DDSCAPS_OPTIMIZED)
    };
745 746
    static const struct flag_info flags2[] =
    {
747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767
        FE(DDSCAPS2_HARDWAREDEINTERLACE),
        FE(DDSCAPS2_HINTDYNAMIC),
        FE(DDSCAPS2_HINTSTATIC),
        FE(DDSCAPS2_TEXTUREMANAGE),
        FE(DDSCAPS2_RESERVED1),
        FE(DDSCAPS2_RESERVED2),
        FE(DDSCAPS2_OPAQUE),
        FE(DDSCAPS2_HINTANTIALIASING),
        FE(DDSCAPS2_CUBEMAP),
        FE(DDSCAPS2_CUBEMAP_POSITIVEX),
        FE(DDSCAPS2_CUBEMAP_NEGATIVEX),
        FE(DDSCAPS2_CUBEMAP_POSITIVEY),
        FE(DDSCAPS2_CUBEMAP_NEGATIVEY),
        FE(DDSCAPS2_CUBEMAP_POSITIVEZ),
        FE(DDSCAPS2_CUBEMAP_NEGATIVEZ),
        FE(DDSCAPS2_MIPMAPSUBLEVEL),
        FE(DDSCAPS2_D3DTEXTUREMANAGE),
        FE(DDSCAPS2_DONOTPERSIST),
        FE(DDSCAPS2_STEREOSURFACELEFT)
    };

768 769
    DDRAW_dump_flags_nolf(in->dwCaps, flags, ARRAY_SIZE(flags));
    DDRAW_dump_flags(in->dwCaps2, flags2, ARRAY_SIZE(flags2));
770 771
}

772
static void
773 774 775 776 777 778 779
DDRAW_dump_DDSCAPS(const DDSCAPS *in)
{
    DDSCAPS2 in_bis;

    in_bis.dwCaps = in->dwCaps;
    in_bis.dwCaps2 = 0;
    in_bis.dwCaps3 = 0;
780
    in_bis.u1.dwCaps4 = 0;
781 782 783 784

    DDRAW_dump_DDSCAPS2(&in_bis);
}

785
static void
786 787
DDRAW_dump_pixelformat_flag(DWORD flagmask)
{
788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803
    static const struct flag_info flags[] =
    {
        FE(DDPF_ALPHAPIXELS),
        FE(DDPF_ALPHA),
        FE(DDPF_FOURCC),
        FE(DDPF_PALETTEINDEXED4),
        FE(DDPF_PALETTEINDEXEDTO8),
        FE(DDPF_PALETTEINDEXED8),
        FE(DDPF_RGB),
        FE(DDPF_COMPRESSED),
        FE(DDPF_RGBTOYUV),
        FE(DDPF_YUV),
        FE(DDPF_ZBUFFER),
        FE(DDPF_PALETTEINDEXED1),
        FE(DDPF_PALETTEINDEXED2),
        FE(DDPF_ZPIXELS)
804 805
    };

806
    DDRAW_dump_flags_nolf(flagmask, flags, ARRAY_SIZE(flags));
807 808
}

809
static void DDRAW_dump_members(DWORD flags, const void *data, const struct member_info *mems, size_t num_mems)
810 811 812 813 814 815 816
{
    unsigned int i;

    for (i=0; i < num_mems; i++)
    {
        if (mems[i].val & flags)
        {
Andrew Riedi's avatar
Andrew Riedi committed
817
            TRACE(" - %s : ", mems[i].name);
818 819 820 821 822
            mems[i].func((const char *)data + mems[i].offset);
        }
    }
}

823
static void
824 825
DDRAW_dump_pixelformat(const DDPIXELFORMAT *pf)
{
Andrew Riedi's avatar
Andrew Riedi committed
826
    TRACE("( ");
827 828
    DDRAW_dump_pixelformat_flag(pf->dwFlags);
    if (pf->dwFlags & DDPF_FOURCC)
829
        TRACE(", dwFourCC code '%c%c%c%c' (0x%08x) - %u bits per pixel",
830 831 832 833 834
                (unsigned char)( pf->dwFourCC     &0xff),
                (unsigned char)((pf->dwFourCC>> 8)&0xff),
                (unsigned char)((pf->dwFourCC>>16)&0xff),
                (unsigned char)((pf->dwFourCC>>24)&0xff),
                pf->dwFourCC,
835
                pf->u1.dwYUVBitCount);
836 837
    if (pf->dwFlags & DDPF_RGB)
    {
838 839 840 841 842
        TRACE(", RGB bits: %u, R 0x%08x G 0x%08x B 0x%08x",
                pf->u1.dwRGBBitCount,
                pf->u2.dwRBitMask,
                pf->u3.dwGBitMask,
                pf->u4.dwBBitMask);
843
        if (pf->dwFlags & DDPF_ALPHAPIXELS)
844
            TRACE(" A 0x%08x", pf->u5.dwRGBAlphaBitMask);
845
        if (pf->dwFlags & DDPF_ZPIXELS)
846
            TRACE(" Z 0x%08x", pf->u5.dwRGBZBitMask);
847 848
    }
    if (pf->dwFlags & DDPF_ZBUFFER)
849
        TRACE(", Z bits: %u", pf->u1.dwZBufferBitDepth);
850
    if (pf->dwFlags & DDPF_ALPHA)
851
        TRACE(", Alpha bits: %u", pf->u1.dwAlphaBitDepth);
852
    if (pf->dwFlags & DDPF_BUMPDUDV)
853 854 855 856 857
        TRACE(", Bump bits: %u, U 0x%08x V 0x%08x L 0x%08x",
                pf->u1.dwBumpBitCount,
                pf->u2.dwBumpDuBitMask,
                pf->u3.dwBumpDvBitMask,
                pf->u4.dwBumpLuminanceBitMask);
858
    TRACE(")\n");
859 860 861 862 863
}

void DDRAW_dump_surface_desc(const DDSURFACEDESC2 *lpddsd)
{
#define STRUCT DDSURFACEDESC2
864 865 866 867 868 869
    static const struct member_info members[] =
    {
        ME(DDSD_HEIGHT, DDRAW_dump_DWORD, dwHeight),
        ME(DDSD_WIDTH, DDRAW_dump_DWORD, dwWidth),
        ME(DDSD_PITCH, DDRAW_dump_DWORD, u1 /* lPitch */),
        ME(DDSD_LINEARSIZE, DDRAW_dump_DWORD, u1 /* dwLinearSize */),
870
        ME(DDSD_BACKBUFFERCOUNT, DDRAW_dump_DWORD, u5.dwBackBufferCount),
871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889
        ME(DDSD_MIPMAPCOUNT, DDRAW_dump_DWORD, u2 /* dwMipMapCount */),
        ME(DDSD_ZBUFFERBITDEPTH, DDRAW_dump_DWORD, u2 /* dwZBufferBitDepth */), /* This is for 'old-style' D3D */
        ME(DDSD_REFRESHRATE, DDRAW_dump_DWORD, u2 /* dwRefreshRate */),
        ME(DDSD_ALPHABITDEPTH, DDRAW_dump_DWORD, dwAlphaBitDepth),
        ME(DDSD_LPSURFACE, DDRAW_dump_PTR, lpSurface),
        ME(DDSD_CKDESTOVERLAY, DDRAW_dump_DDCOLORKEY, u3 /* ddckCKDestOverlay */),
        ME(DDSD_CKDESTBLT, DDRAW_dump_DDCOLORKEY, ddckCKDestBlt),
        ME(DDSD_CKSRCOVERLAY, DDRAW_dump_DDCOLORKEY, ddckCKSrcOverlay),
        ME(DDSD_CKSRCBLT, DDRAW_dump_DDCOLORKEY, ddckCKSrcBlt),
        ME(DDSD_PIXELFORMAT, DDRAW_dump_pixelformat, u4 /* ddpfPixelFormat */)
    };
    static const struct member_info members_caps[] =
    {
        ME(DDSD_CAPS, DDRAW_dump_DDSCAPS, ddsCaps)
    };
    static const struct member_info members_caps2[] =
    {
        ME(DDSD_CAPS, DDRAW_dump_DDSCAPS2, ddsCaps)
    };
890 891 892 893
#undef STRUCT

    if (NULL == lpddsd)
    {
Andrew Riedi's avatar
Andrew Riedi committed
894
        TRACE("(null)\n");
895 896 897 898 899 900 901 902 903 904 905
    }
    else
    {
      if (lpddsd->dwSize >= sizeof(DDSURFACEDESC2))
      {
          DDRAW_dump_members(lpddsd->dwFlags, lpddsd, members_caps2, 1);
      }
      else
      {
          DDRAW_dump_members(lpddsd->dwFlags, lpddsd, members_caps, 1);
      }
906
      DDRAW_dump_members(lpddsd->dwFlags, lpddsd, members, ARRAY_SIZE(members));
907 908 909 910
    }
}

void
911
dump_D3DMATRIX(const D3DMATRIX *mat)
912
{
Andrew Riedi's avatar
Andrew Riedi committed
913 914 915 916
    TRACE("  %f %f %f %f\n", mat->_11, mat->_12, mat->_13, mat->_14);
    TRACE("  %f %f %f %f\n", mat->_21, mat->_22, mat->_23, mat->_24);
    TRACE("  %f %f %f %f\n", mat->_31, mat->_32, mat->_33, mat->_34);
    TRACE("  %f %f %f %f\n", mat->_41, mat->_42, mat->_43, mat->_44);
917 918 919 920 921 922
}

DWORD
get_flexible_vertex_size(DWORD d3dvtVertexType)
{
    DWORD size = 0;
923
    DWORD i;
924 925 926 927 928 929 930

    if (d3dvtVertexType & D3DFVF_NORMAL) size += 3 * sizeof(D3DVALUE);
    if (d3dvtVertexType & D3DFVF_DIFFUSE) size += sizeof(DWORD);
    if (d3dvtVertexType & D3DFVF_SPECULAR) size += sizeof(DWORD);
    if (d3dvtVertexType & D3DFVF_RESERVED1) size += sizeof(DWORD);
    switch (d3dvtVertexType & D3DFVF_POSITION_MASK)
    {
931
        case D3DFVF_XYZ:    size += 3 * sizeof(D3DVALUE); break;
932
        case D3DFVF_XYZRHW: size += 4 * sizeof(D3DVALUE); break;
933 934 935 936 937 938
        case D3DFVF_XYZB1:  size += 4 * sizeof(D3DVALUE); break;
        case D3DFVF_XYZB2:  size += 5 * sizeof(D3DVALUE); break;
        case D3DFVF_XYZB3:  size += 6 * sizeof(D3DVALUE); break;
        case D3DFVF_XYZB4:  size += 7 * sizeof(D3DVALUE); break;
        case D3DFVF_XYZB5:  size += 8 * sizeof(D3DVALUE); break;
        default: ERR("Unexpected position mask\n");
939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954
    }
    for (i = 0; i < GET_TEXCOUNT_FROM_FVF(d3dvtVertexType); i++)
    {
        size += GET_TEXCOORD_SIZE_FROM_FVF(d3dvtVertexType, i) * sizeof(D3DVALUE);
    }

    return size;
}

void DDRAW_Convert_DDSCAPS_1_To_2(const DDSCAPS* pIn, DDSCAPS2* pOut)
{
    /* 2 adds three additional caps fields to the end. Both versions
     * are unversioned. */
    pOut->dwCaps = pIn->dwCaps;
    pOut->dwCaps2 = 0;
    pOut->dwCaps3 = 0;
955
    pOut->u1.dwCaps4 = 0;
956 957 958 959 960 961 962 963 964 965 966
}

void DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(const DDDEVICEIDENTIFIER2* pIn, DDDEVICEIDENTIFIER* pOut)
{
    /* 2 adds a dwWHQLLevel field to the end. Both structures are
     * unversioned. */
    memcpy(pOut, pIn, sizeof(*pOut));
}

void DDRAW_dump_cooperativelevel(DWORD cooplevel)
{
967 968 969 970 971 972 973 974 975 976 977
    static const struct flag_info flags[] =
    {
        FE(DDSCL_FULLSCREEN),
        FE(DDSCL_ALLOWREBOOT),
        FE(DDSCL_NOWINDOWCHANGES),
        FE(DDSCL_NORMAL),
        FE(DDSCL_ALLOWMODEX),
        FE(DDSCL_EXCLUSIVE),
        FE(DDSCL_SETFOCUSWINDOW),
        FE(DDSCL_SETDEVICEWINDOW),
        FE(DDSCL_CREATEDEVICEWINDOW)
978 979 980 981
    };

    if (TRACE_ON(ddraw))
    {
Andrew Riedi's avatar
Andrew Riedi committed
982
        TRACE(" - ");
983
        DDRAW_dump_flags(cooplevel, flags, ARRAY_SIZE(flags));
984 985 986 987 988
    }
}

void DDRAW_dump_DDCAPS(const DDCAPS *lpcaps)
{
989
    static const struct flag_info flags1[] =
990
    {
991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022
        FE(DDCAPS_3D),
        FE(DDCAPS_ALIGNBOUNDARYDEST),
        FE(DDCAPS_ALIGNSIZEDEST),
        FE(DDCAPS_ALIGNBOUNDARYSRC),
        FE(DDCAPS_ALIGNSIZESRC),
        FE(DDCAPS_ALIGNSTRIDE),
        FE(DDCAPS_BLT),
        FE(DDCAPS_BLTQUEUE),
        FE(DDCAPS_BLTFOURCC),
        FE(DDCAPS_BLTSTRETCH),
        FE(DDCAPS_GDI),
        FE(DDCAPS_OVERLAY),
        FE(DDCAPS_OVERLAYCANTCLIP),
        FE(DDCAPS_OVERLAYFOURCC),
        FE(DDCAPS_OVERLAYSTRETCH),
        FE(DDCAPS_PALETTE),
        FE(DDCAPS_PALETTEVSYNC),
        FE(DDCAPS_READSCANLINE),
        FE(DDCAPS_STEREOVIEW),
        FE(DDCAPS_VBI),
        FE(DDCAPS_ZBLTS),
        FE(DDCAPS_ZOVERLAYS),
        FE(DDCAPS_COLORKEY),
        FE(DDCAPS_ALPHA),
        FE(DDCAPS_COLORKEYHWASSIST),
        FE(DDCAPS_NOHARDWARE),
        FE(DDCAPS_BLTCOLORFILL),
        FE(DDCAPS_BANKSWITCHED),
        FE(DDCAPS_BLTDEPTHFILL),
        FE(DDCAPS_CANCLIP),
        FE(DDCAPS_CANCLIPSTRETCHED),
        FE(DDCAPS_CANBLTSYSMEM)
1023
    };
1024
    static const struct flag_info flags2[] =
1025
    {
1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050
        FE(DDCAPS2_CERTIFIED),
        FE(DDCAPS2_NO2DDURING3DSCENE),
        FE(DDCAPS2_VIDEOPORT),
        FE(DDCAPS2_AUTOFLIPOVERLAY),
        FE(DDCAPS2_CANBOBINTERLEAVED),
        FE(DDCAPS2_CANBOBNONINTERLEAVED),
        FE(DDCAPS2_COLORCONTROLOVERLAY),
        FE(DDCAPS2_COLORCONTROLPRIMARY),
        FE(DDCAPS2_CANDROPZ16BIT),
        FE(DDCAPS2_NONLOCALVIDMEM),
        FE(DDCAPS2_NONLOCALVIDMEMCAPS),
        FE(DDCAPS2_NOPAGELOCKREQUIRED),
        FE(DDCAPS2_WIDESURFACES),
        FE(DDCAPS2_CANFLIPODDEVEN),
        FE(DDCAPS2_CANBOBHARDWARE),
        FE(DDCAPS2_COPYFOURCC),
        FE(DDCAPS2_PRIMARYGAMMA),
        FE(DDCAPS2_CANRENDERWINDOWED),
        FE(DDCAPS2_CANCALIBRATEGAMMA),
        FE(DDCAPS2_FLIPINTERVAL),
        FE(DDCAPS2_FLIPNOVSYNC),
        FE(DDCAPS2_CANMANAGETEXTURE),
        FE(DDCAPS2_TEXMANINNONLOCALVIDMEM),
        FE(DDCAPS2_STEREO),
        FE(DDCAPS2_SYSTONONLOCAL_AS_SYSTOLOCAL)
1051
    };
1052
    static const struct flag_info flags3[] =
1053
    {
1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072
        FE(DDCKEYCAPS_DESTBLT),
        FE(DDCKEYCAPS_DESTBLTCLRSPACE),
        FE(DDCKEYCAPS_DESTBLTCLRSPACEYUV),
        FE(DDCKEYCAPS_DESTBLTYUV),
        FE(DDCKEYCAPS_DESTOVERLAY),
        FE(DDCKEYCAPS_DESTOVERLAYCLRSPACE),
        FE(DDCKEYCAPS_DESTOVERLAYCLRSPACEYUV),
        FE(DDCKEYCAPS_DESTOVERLAYONEACTIVE),
        FE(DDCKEYCAPS_DESTOVERLAYYUV),
        FE(DDCKEYCAPS_SRCBLT),
        FE(DDCKEYCAPS_SRCBLTCLRSPACE),
        FE(DDCKEYCAPS_SRCBLTCLRSPACEYUV),
        FE(DDCKEYCAPS_SRCBLTYUV),
        FE(DDCKEYCAPS_SRCOVERLAY),
        FE(DDCKEYCAPS_SRCOVERLAYCLRSPACE),
        FE(DDCKEYCAPS_SRCOVERLAYCLRSPACEYUV),
        FE(DDCKEYCAPS_SRCOVERLAYONEACTIVE),
        FE(DDCKEYCAPS_SRCOVERLAYYUV),
        FE(DDCKEYCAPS_NOCOSTOVERLAY)
1073
    };
1074
    static const struct flag_info flags4[] =
1075
    {
1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103
        FE(DDFXCAPS_BLTALPHA),
        FE(DDFXCAPS_OVERLAYALPHA),
        FE(DDFXCAPS_BLTARITHSTRETCHYN),
        FE(DDFXCAPS_BLTARITHSTRETCHY),
        FE(DDFXCAPS_BLTMIRRORLEFTRIGHT),
        FE(DDFXCAPS_BLTMIRRORUPDOWN),
        FE(DDFXCAPS_BLTROTATION),
        FE(DDFXCAPS_BLTROTATION90),
        FE(DDFXCAPS_BLTSHRINKX),
        FE(DDFXCAPS_BLTSHRINKXN),
        FE(DDFXCAPS_BLTSHRINKY),
        FE(DDFXCAPS_BLTSHRINKYN),
        FE(DDFXCAPS_BLTSTRETCHX),
        FE(DDFXCAPS_BLTSTRETCHXN),
        FE(DDFXCAPS_BLTSTRETCHY),
        FE(DDFXCAPS_BLTSTRETCHYN),
        FE(DDFXCAPS_OVERLAYARITHSTRETCHY),
        FE(DDFXCAPS_OVERLAYARITHSTRETCHYN),
        FE(DDFXCAPS_OVERLAYSHRINKX),
        FE(DDFXCAPS_OVERLAYSHRINKXN),
        FE(DDFXCAPS_OVERLAYSHRINKY),
        FE(DDFXCAPS_OVERLAYSHRINKYN),
        FE(DDFXCAPS_OVERLAYSTRETCHX),
        FE(DDFXCAPS_OVERLAYSTRETCHXN),
        FE(DDFXCAPS_OVERLAYSTRETCHY),
        FE(DDFXCAPS_OVERLAYSTRETCHYN),
        FE(DDFXCAPS_OVERLAYMIRRORLEFTRIGHT),
        FE(DDFXCAPS_OVERLAYMIRRORUPDOWN)
1104
    };
1105
    static const struct flag_info flags5[] =
1106
    {
1107 1108 1109 1110 1111 1112 1113 1114 1115 1116
        FE(DDFXALPHACAPS_BLTALPHAEDGEBLEND),
        FE(DDFXALPHACAPS_BLTALPHAPIXELS),
        FE(DDFXALPHACAPS_BLTALPHAPIXELSNEG),
        FE(DDFXALPHACAPS_BLTALPHASURFACES),
        FE(DDFXALPHACAPS_BLTALPHASURFACESNEG),
        FE(DDFXALPHACAPS_OVERLAYALPHAEDGEBLEND),
        FE(DDFXALPHACAPS_OVERLAYALPHAPIXELS),
        FE(DDFXALPHACAPS_OVERLAYALPHAPIXELSNEG),
        FE(DDFXALPHACAPS_OVERLAYALPHASURFACES),
        FE(DDFXALPHACAPS_OVERLAYALPHASURFACESNEG)
1117
    };
1118
    static const struct flag_info flags6[] =
1119
    {
1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130
        FE(DDPCAPS_4BIT),
        FE(DDPCAPS_8BITENTRIES),
        FE(DDPCAPS_8BIT),
        FE(DDPCAPS_INITIALIZE),
        FE(DDPCAPS_PRIMARYSURFACE),
        FE(DDPCAPS_PRIMARYSURFACELEFT),
        FE(DDPCAPS_ALLOW256),
        FE(DDPCAPS_VSYNC),
        FE(DDPCAPS_1BIT),
        FE(DDPCAPS_2BIT),
        FE(DDPCAPS_ALPHA),
1131
    };
1132
    static const struct flag_info flags7[] =
1133
    {
1134 1135 1136 1137 1138
        FE(DDSVCAPS_RESERVED1),
        FE(DDSVCAPS_RESERVED2),
        FE(DDSVCAPS_RESERVED3),
        FE(DDSVCAPS_RESERVED4),
        FE(DDSVCAPS_STEREOSEQUENTIAL),
1139 1140
    };

Andrew Riedi's avatar
Andrew Riedi committed
1141
    TRACE(" - dwSize : %d\n", lpcaps->dwSize);
1142 1143 1144 1145 1146 1147 1148
    TRACE(" - dwCaps : "); DDRAW_dump_flags(lpcaps->dwCaps, flags1, ARRAY_SIZE(flags1));
    TRACE(" - dwCaps2 : "); DDRAW_dump_flags(lpcaps->dwCaps2, flags2, ARRAY_SIZE(flags2));
    TRACE(" - dwCKeyCaps : "); DDRAW_dump_flags(lpcaps->dwCKeyCaps, flags3, ARRAY_SIZE(flags3));
    TRACE(" - dwFXCaps : "); DDRAW_dump_flags(lpcaps->dwFXCaps, flags4, ARRAY_SIZE(flags4));
    TRACE(" - dwFXAlphaCaps : "); DDRAW_dump_flags(lpcaps->dwFXAlphaCaps, flags5, ARRAY_SIZE(flags5));
    TRACE(" - dwPalCaps : "); DDRAW_dump_flags(lpcaps->dwPalCaps, flags6, ARRAY_SIZE(flags6));
    TRACE(" - dwSVCaps : "); DDRAW_dump_flags(lpcaps->dwSVCaps, flags7, ARRAY_SIZE(flags7));
Andrew Riedi's avatar
Andrew Riedi committed
1149 1150 1151 1152 1153 1154
    TRACE("...\n");
    TRACE(" - dwNumFourCCCodes : %d\n", lpcaps->dwNumFourCCCodes);
    TRACE(" - dwCurrVisibleOverlays : %d\n", lpcaps->dwCurrVisibleOverlays);
    TRACE(" - dwMinOverlayStretch : %d\n", lpcaps->dwMinOverlayStretch);
    TRACE(" - dwMaxOverlayStretch : %d\n", lpcaps->dwMaxOverlayStretch);
    TRACE("...\n");
1155
    TRACE(" - ddsCaps : "); DDRAW_dump_DDSCAPS2(&lpcaps->ddsCaps);
1156 1157 1158 1159 1160 1161 1162 1163 1164 1165
}

/*****************************************************************************
 * multiply_matrix
 *
 * Multiplies 2 4x4 matrices src1 and src2, and stores the result in dest.
 *
 * Params:
 *  dest: Pointer to the destination matrix
 *  src1: Pointer to the first source matrix
1166
 *  src2: Pointer to the second source matrix
1167 1168 1169 1170
 *
 *****************************************************************************/
void
multiply_matrix(D3DMATRIX *dest,
1171 1172
                const D3DMATRIX *src1,
                const D3DMATRIX *src2)
1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210
{
    D3DMATRIX temp;

    /* Now do the multiplication 'by hand'.
       I know that all this could be optimised, but this will be done later :-) */
    temp._11 = (src1->_11 * src2->_11) + (src1->_21 * src2->_12) + (src1->_31 * src2->_13) + (src1->_41 * src2->_14);
    temp._21 = (src1->_11 * src2->_21) + (src1->_21 * src2->_22) + (src1->_31 * src2->_23) + (src1->_41 * src2->_24);
    temp._31 = (src1->_11 * src2->_31) + (src1->_21 * src2->_32) + (src1->_31 * src2->_33) + (src1->_41 * src2->_34);
    temp._41 = (src1->_11 * src2->_41) + (src1->_21 * src2->_42) + (src1->_31 * src2->_43) + (src1->_41 * src2->_44);

    temp._12 = (src1->_12 * src2->_11) + (src1->_22 * src2->_12) + (src1->_32 * src2->_13) + (src1->_42 * src2->_14);
    temp._22 = (src1->_12 * src2->_21) + (src1->_22 * src2->_22) + (src1->_32 * src2->_23) + (src1->_42 * src2->_24);
    temp._32 = (src1->_12 * src2->_31) + (src1->_22 * src2->_32) + (src1->_32 * src2->_33) + (src1->_42 * src2->_34);
    temp._42 = (src1->_12 * src2->_41) + (src1->_22 * src2->_42) + (src1->_32 * src2->_43) + (src1->_42 * src2->_44);

    temp._13 = (src1->_13 * src2->_11) + (src1->_23 * src2->_12) + (src1->_33 * src2->_13) + (src1->_43 * src2->_14);
    temp._23 = (src1->_13 * src2->_21) + (src1->_23 * src2->_22) + (src1->_33 * src2->_23) + (src1->_43 * src2->_24);
    temp._33 = (src1->_13 * src2->_31) + (src1->_23 * src2->_32) + (src1->_33 * src2->_33) + (src1->_43 * src2->_34);
    temp._43 = (src1->_13 * src2->_41) + (src1->_23 * src2->_42) + (src1->_33 * src2->_43) + (src1->_43 * src2->_44);

    temp._14 = (src1->_14 * src2->_11) + (src1->_24 * src2->_12) + (src1->_34 * src2->_13) + (src1->_44 * src2->_14);
    temp._24 = (src1->_14 * src2->_21) + (src1->_24 * src2->_22) + (src1->_34 * src2->_23) + (src1->_44 * src2->_24);
    temp._34 = (src1->_14 * src2->_31) + (src1->_24 * src2->_32) + (src1->_34 * src2->_33) + (src1->_44 * src2->_34);
    temp._44 = (src1->_14 * src2->_41) + (src1->_24 * src2->_42) + (src1->_34 * src2->_43) + (src1->_44 * src2->_44);

    /* And copy the new matrix in the good storage.. */
    memcpy(dest, &temp, 16 * sizeof(D3DVALUE));
}

HRESULT
hr_ddraw_from_wined3d(HRESULT hr)
{
    switch(hr)
    {
        case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS;
        default: return hr;
    }
}
1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221

/* Note that this function writes the full sizeof(DDSURFACEDESC2) size, don't use it
 * for writing into application-provided DDSURFACEDESC2 structures if the size may
 * be different */
void DDSD_to_DDSD2(const DDSURFACEDESC *in, DDSURFACEDESC2 *out)
{
    /* The output of this function is never passed to the application directly, so
     * the memset is not strictly needed. CreateSurface still has problems with this
     * though. Don't forget to set ddsCaps.dwCaps2/3/4 to 0 when removing this */
    memset(out, 0x00, sizeof(*out));
    out->dwSize = sizeof(*out);
1222
    out->dwFlags = in->dwFlags & ~DDSD_ZBUFFERBITDEPTH;
1223 1224 1225
    if (in->dwFlags & DDSD_WIDTH) out->dwWidth = in->dwWidth;
    if (in->dwFlags & DDSD_HEIGHT) out->dwHeight = in->dwHeight;
    if (in->dwFlags & DDSD_PIXELFORMAT) out->u4.ddpfPixelFormat = in->ddpfPixelFormat;
1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236
    else if(in->dwFlags & DDSD_ZBUFFERBITDEPTH)
    {
        out->dwFlags |= DDSD_PIXELFORMAT;
        memset(&out->u4.ddpfPixelFormat, 0, sizeof(out->u4.ddpfPixelFormat));
        out->u4.ddpfPixelFormat.dwSize = sizeof(out->u4.ddpfPixelFormat);
        out->u4.ddpfPixelFormat.dwFlags = DDPF_ZBUFFER;
        out->u4.ddpfPixelFormat.u1.dwZBufferBitDepth = in->u2.dwZBufferBitDepth;
        /* 0 is not a valid DDSURFACEDESC / DDPIXELFORMAT on either side of the
         * conversion */
        out->u4.ddpfPixelFormat.u3.dwZBitMask = ~0U >> (32 - in->u2.dwZBufferBitDepth);
    }
1237 1238 1239
    /* ddsCaps is read even without DDSD_CAPS set. See dsurface:no_ddsd_caps_test */
    out->ddsCaps.dwCaps = in->ddsCaps.dwCaps;
    if (in->dwFlags & DDSD_PITCH) out->u1.lPitch = in->u1.lPitch;
1240
    if (in->dwFlags & DDSD_BACKBUFFERCOUNT) out->u5.dwBackBufferCount = in->dwBackBufferCount;
1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254
    if (in->dwFlags & DDSD_ALPHABITDEPTH) out->dwAlphaBitDepth = in->dwAlphaBitDepth;
    /* DDraw(native, and wine) does not set the DDSD_LPSURFACE, so always copy */
    out->lpSurface = in->lpSurface;
    if (in->dwFlags & DDSD_CKDESTOVERLAY) out->u3.ddckCKDestOverlay = in->ddckCKDestOverlay;
    if (in->dwFlags & DDSD_CKDESTBLT) out->ddckCKDestBlt = in->ddckCKDestBlt;
    if (in->dwFlags & DDSD_CKSRCOVERLAY) out->ddckCKSrcOverlay = in->ddckCKSrcOverlay;
    if (in->dwFlags & DDSD_CKSRCBLT) out->ddckCKSrcBlt = in->ddckCKSrcBlt;
    if (in->dwFlags & DDSD_MIPMAPCOUNT) out->u2.dwMipMapCount = in->u2.dwMipMapCount;
    if (in->dwFlags & DDSD_REFRESHRATE) out->u2.dwRefreshRate = in->u2.dwRefreshRate;
    if (in->dwFlags & DDSD_LINEARSIZE) out->u1.dwLinearSize = in->u1.dwLinearSize;
    /* Does not exist in DDSURFACEDESC:
     * DDSD_TEXTURESTAGE, DDSD_FVF, DDSD_SRCVBHANDLE,
     */
}
1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265

/* Note that this function writes the full sizeof(DDSURFACEDESC) size, don't use it
 * for writing into application-provided DDSURFACEDESC structures if the size may
 * be different */
void DDSD2_to_DDSD(const DDSURFACEDESC2 *in, DDSURFACEDESC *out)
{
    memset(out, 0, sizeof(*out));
    out->dwSize = sizeof(*out);
    out->dwFlags = in->dwFlags;
    if (in->dwFlags & DDSD_WIDTH) out->dwWidth = in->dwWidth;
    if (in->dwFlags & DDSD_HEIGHT) out->dwHeight = in->dwHeight;
1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277
    if (in->dwFlags & DDSD_PIXELFORMAT)
    {
        out->ddpfPixelFormat = in->u4.ddpfPixelFormat;
        if ((in->dwFlags & DDSD_CAPS) && (in->ddsCaps.dwCaps & DDSCAPS_ZBUFFER))
        {
            /* Z buffers have DDSD_ZBUFFERBITDEPTH set, but not DDSD_PIXELFORMAT. They do
             * have valid data in ddpfPixelFormat though */
            out->dwFlags &= ~DDSD_PIXELFORMAT;
            out->dwFlags |= DDSD_ZBUFFERBITDEPTH;
            out->u2.dwZBufferBitDepth = in->u4.ddpfPixelFormat.u1.dwZBufferBitDepth;
        }
    }
1278 1279 1280
    /* ddsCaps is read even without DDSD_CAPS set. See dsurface:no_ddsd_caps_test */
    out->ddsCaps.dwCaps = in->ddsCaps.dwCaps;
    if (in->dwFlags & DDSD_PITCH) out->u1.lPitch = in->u1.lPitch;
1281
    if (in->dwFlags & DDSD_BACKBUFFERCOUNT) out->dwBackBufferCount = in->u5.dwBackBufferCount;
1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300
    if (in->dwFlags & DDSD_ZBUFFERBITDEPTH) out->u2.dwZBufferBitDepth = in->u2.dwMipMapCount; /* same union */
    if (in->dwFlags & DDSD_ALPHABITDEPTH) out->dwAlphaBitDepth = in->dwAlphaBitDepth;
    /* DDraw(native, and wine) does not set the DDSD_LPSURFACE, so always copy */
    out->lpSurface = in->lpSurface;
    if (in->dwFlags & DDSD_CKDESTOVERLAY) out->ddckCKDestOverlay = in->u3.ddckCKDestOverlay;
    if (in->dwFlags & DDSD_CKDESTBLT) out->ddckCKDestBlt = in->ddckCKDestBlt;
    if (in->dwFlags & DDSD_CKSRCOVERLAY) out->ddckCKSrcOverlay = in->ddckCKSrcOverlay;
    if (in->dwFlags & DDSD_CKSRCBLT) out->ddckCKSrcBlt = in->ddckCKSrcBlt;
    if (in->dwFlags & DDSD_MIPMAPCOUNT) out->u2.dwMipMapCount = in->u2.dwMipMapCount;
    if (in->dwFlags & DDSD_REFRESHRATE) out->u2.dwRefreshRate = in->u2.dwRefreshRate;
    if (in->dwFlags & DDSD_LINEARSIZE) out->u1.dwLinearSize = in->u1.dwLinearSize;
    /* Does not exist in DDSURFACEDESC:
     * DDSD_TEXTURESTAGE, DDSD_FVF, DDSD_SRCVBHANDLE,
     */
    if (in->dwFlags & DDSD_TEXTURESTAGE) WARN("Does not exist in DDSURFACEDESC: DDSD_TEXTURESTAGE\n");
    if (in->dwFlags & DDSD_FVF) WARN("Does not exist in DDSURFACEDESC: DDSD_FVF\n");
    if (in->dwFlags & DDSD_SRCVBHANDLE) WARN("Does not exist in DDSURFACEDESC: DDSD_SRCVBHANDLE\n");
    out->dwFlags &= ~(DDSD_TEXTURESTAGE | DDSD_FVF | DDSD_SRCVBHANDLE);
}