src/video/directfb/SDL_DirectFB_video.c
author Sam Lantinga
Fri, 08 Apr 2011 13:03:26 -0700
changeset 5535 96594ac5fd1a
parent 5489 e0c63a55b67d
child 6044 35448a5ea044
permissions -rw-r--r--
SDL 1.3 is now under the zlib license.
slouken@167
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@5535
     3
  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
slouken@167
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@167
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@167
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@167
    20
*/
slouken@2226
    21
slouken@5199
    22
#include "SDL_DirectFB_video.h"
slouken@5199
    23
slouken@5199
    24
#include "SDL_DirectFB_events.h"
slouken@5199
    25
/*
slouken@5199
    26
 * #include "SDL_DirectFB_keyboard.h"
slouken@5199
    27
 */
slouken@5199
    28
#include "SDL_DirectFB_modes.h"
slouken@5199
    29
#include "SDL_DirectFB_mouse.h"
slouken@5199
    30
#include "SDL_DirectFB_opengl.h"
slouken@5199
    31
#include "SDL_DirectFB_window.h"
slouken@5199
    32
#include "SDL_DirectFB_WM.h"
slouken@5199
    33
slouken@2226
    34
slouken@1402
    35
#include "SDL_config.h"
slouken@167
    36
slouken@167
    37
/* DirectFB video driver implementation.
slouken@167
    38
*/
slouken@167
    39
slouken@167
    40
#include <fcntl.h>
slouken@167
    41
#include <unistd.h>
slouken@167
    42
#include <sys/mman.h>
slouken@167
    43
slouken@167
    44
#include <directfb.h>
icculus@1165
    45
#include <directfb_version.h>
couriersud@3023
    46
#include <directfb_strings.h>
slouken@167
    47
slouken@167
    48
#include "SDL_video.h"
slouken@167
    49
#include "SDL_mouse.h"
slouken@1361
    50
#include "../SDL_sysvideo.h"
slouken@1361
    51
#include "../SDL_pixels_c.h"
slouken@1361
    52
#include "../../events/SDL_events_c.h"
slouken@167
    53
#include "SDL_DirectFB_video.h"
slouken@167
    54
#include "SDL_DirectFB_events.h"
slouken@2737
    55
#include "SDL_DirectFB_render.h"
slouken@2737
    56
#include "SDL_DirectFB_mouse.h"
slouken@5199
    57
#include "SDL_DirectFB_shape.h"
slouken@5199
    58
slouken@2226
    59
slouken@2998
    60
#include "SDL_DirectFB_dyn.h"
slouken@2998
    61
slouken@2226
    62
/* Initialization/Query functions */
slouken@2226
    63
static int DirectFB_VideoInit(_THIS);
slouken@2226
    64
static void DirectFB_VideoQuit(_THIS);
slouken@167
    65
slouken@2737
    66
static int DirectFB_Available(void);
slouken@2737
    67
static SDL_VideoDevice *DirectFB_CreateDevice(int devindex);
slouken@2226
    68
slouken@2737
    69
VideoBootStrap DirectFB_bootstrap = {
slouken@2737
    70
    "directfb", "DirectFB",
slouken@2737
    71
    DirectFB_Available, DirectFB_CreateDevice
slouken@2737
    72
};
slouken@167
    73
slouken@5199
    74
static const DirectFBSurfaceDrawingFlagsNames(drawing_flags);
slouken@5199
    75
static const DirectFBSurfaceBlittingFlagsNames(blitting_flags);
slouken@5199
    76
static const DirectFBAccelerationMaskNames(acceleration_mask);
slouken@5199
    77
slouken@167
    78
/* DirectFB driver bootstrap functions */
slouken@167
    79
slouken@1895
    80
static int
slouken@1895
    81
DirectFB_Available(void)
slouken@167
    82
{
slouken@2998
    83
    if (!SDL_DirectFB_LoadLibrary())
slouken@2998
    84
        return 0;
slouken@2998
    85
    SDL_DirectFB_UnLoadLibrary();
slouken@1895
    86
    return 1;
slouken@167
    87
}
slouken@167
    88
slouken@1895
    89
static void
slouken@1895
    90
DirectFB_DeleteDevice(SDL_VideoDevice * device)
slouken@167
    91
{
slouken@2998
    92
    SDL_DirectFB_UnLoadLibrary();
slouken@2998
    93
    SDL_DFB_FREE(device->driverdata);
slouken@2998
    94
    SDL_DFB_FREE(device);
slouken@167
    95
}
slouken@167
    96
slouken@1895
    97
static SDL_VideoDevice *
slouken@1895
    98
DirectFB_CreateDevice(int devindex)
slouken@167
    99
{
slouken@1895
   100
    SDL_VideoDevice *device;
slouken@167
   101
slouken@2998
   102
    if (!SDL_DirectFB_LoadLibrary())
slouken@2998
   103
        return NULL;
slouken@2998
   104
slouken@1895
   105
    /* Initialize all variables that we clean on shutdown */
slouken@5199
   106
    SDL_DFB_ALLOC_CLEAR(device, sizeof(SDL_VideoDevice));
slouken@2226
   107
slouken@2226
   108
    /* Set the function pointers */
slouken@167
   109
slouken@1895
   110
    /* Set the function pointers */
slouken@1895
   111
    device->VideoInit = DirectFB_VideoInit;
slouken@1895
   112
    device->VideoQuit = DirectFB_VideoQuit;
slouken@2226
   113
    device->GetDisplayModes = DirectFB_GetDisplayModes;
slouken@2226
   114
    device->SetDisplayMode = DirectFB_SetDisplayMode;
slouken@2226
   115
    device->PumpEvents = DirectFB_PumpEventsWindow;
slouken@2226
   116
    device->CreateWindow = DirectFB_CreateWindow;
slouken@2226
   117
    device->CreateWindowFrom = DirectFB_CreateWindowFrom;
slouken@2226
   118
    device->SetWindowTitle = DirectFB_SetWindowTitle;
couriersud@3023
   119
    device->SetWindowIcon = DirectFB_SetWindowIcon;
slouken@2226
   120
    device->SetWindowPosition = DirectFB_SetWindowPosition;
slouken@2226
   121
    device->SetWindowSize = DirectFB_SetWindowSize;
slouken@2226
   122
    device->ShowWindow = DirectFB_ShowWindow;
slouken@2226
   123
    device->HideWindow = DirectFB_HideWindow;
slouken@2226
   124
    device->RaiseWindow = DirectFB_RaiseWindow;
slouken@2226
   125
    device->MaximizeWindow = DirectFB_MaximizeWindow;
slouken@2226
   126
    device->MinimizeWindow = DirectFB_MinimizeWindow;
slouken@2226
   127
    device->RestoreWindow = DirectFB_RestoreWindow;
slouken@2226
   128
    device->SetWindowGrab = DirectFB_SetWindowGrab;
slouken@2226
   129
    device->DestroyWindow = DirectFB_DestroyWindow;
slouken@2226
   130
    device->GetWindowWMInfo = DirectFB_GetWindowWMInfo;
slouken@2226
   131
slouken@2226
   132
#if SDL_DIRECTFB_OPENGL
slouken@2226
   133
    device->GL_LoadLibrary = DirectFB_GL_LoadLibrary;
slouken@2226
   134
    device->GL_GetProcAddress = DirectFB_GL_GetProcAddress;
slouken@2226
   135
    device->GL_MakeCurrent = DirectFB_GL_MakeCurrent;
slouken@2226
   136
slouken@2226
   137
    device->GL_CreateContext = DirectFB_GL_CreateContext;
slouken@2226
   138
    device->GL_SetSwapInterval = DirectFB_GL_SetSwapInterval;
slouken@2226
   139
    device->GL_GetSwapInterval = DirectFB_GL_GetSwapInterval;
slouken@2226
   140
    device->GL_SwapWindow = DirectFB_GL_SwapWindow;
slouken@2226
   141
    device->GL_DeleteContext = DirectFB_GL_DeleteContext;
slouken@2226
   142
slouken@2226
   143
#endif
slouken@167
   144
slouken@5199
   145
	/* Shaped window support */
slouken@5199
   146
	device->shape_driver.CreateShaper = DirectFB_CreateShaper;
slouken@5199
   147
	device->shape_driver.SetWindowShape = DirectFB_SetWindowShape;
slouken@5199
   148
	device->shape_driver.ResizeWindowShape = DirectFB_ResizeWindowShape;
slouken@5199
   149
	
slouken@1895
   150
    device->free = DirectFB_DeleteDevice;
slouken@5199
   151
    
slouken@1895
   152
    return device;
slouken@2226
   153
  error:
slouken@2226
   154
    if (device)
slouken@2226
   155
        free(device);
slouken@2226
   156
    return (0);
slouken@167
   157
}
slouken@167
   158
couriersud@3023
   159
static void
couriersud@3023
   160
DirectFB_DeviceInformation(IDirectFB * dfb)
couriersud@3023
   161
{
couriersud@3023
   162
    DFBGraphicsDeviceDescription desc;
couriersud@3023
   163
    int n;
couriersud@3023
   164
couriersud@3023
   165
    dfb->GetDeviceDescription(dfb, &desc);
couriersud@3023
   166
slouken@5488
   167
    SDL_DFB_LOG( "DirectFB Device Information");
slouken@5488
   168
    SDL_DFB_LOG( "===========================");
slouken@5488
   169
    SDL_DFB_LOG( "Name:           %s", desc.name);
slouken@5488
   170
    SDL_DFB_LOG( "Vendor:         %s", desc.vendor);
slouken@5488
   171
    SDL_DFB_LOG( "Driver Name:    %s", desc.driver.name);
slouken@5488
   172
    SDL_DFB_LOG( "Driver Vendor:  %s", desc.driver.vendor);
slouken@5488
   173
    SDL_DFB_LOG( "Driver Version: %d.%d", desc.driver.major,
couriersud@3023
   174
            desc.driver.minor);
couriersud@3023
   175
slouken@5488
   176
    SDL_DFB_LOG( "Video memoory:  %d", desc.video_memory);
couriersud@3023
   177
slouken@5488
   178
    SDL_DFB_LOG( "Blitting flags:");
couriersud@3023
   179
    for (n = 0; blitting_flags[n].flag; n++) {
couriersud@3023
   180
        if (desc.blitting_flags & blitting_flags[n].flag)
slouken@5488
   181
            SDL_DFB_LOG( "    %s", blitting_flags[n].name);
couriersud@3023
   182
    }
couriersud@3023
   183
slouken@5488
   184
    SDL_DFB_LOG( "Drawing flags:");
couriersud@3023
   185
    for (n = 0; drawing_flags[n].flag; n++) {
couriersud@3023
   186
        if (desc.drawing_flags & drawing_flags[n].flag)
slouken@5488
   187
            SDL_DFB_LOG( "    %s", drawing_flags[n].name);
couriersud@3023
   188
    }
couriersud@3023
   189
slouken@4568
   190
slouken@5488
   191
    SDL_DFB_LOG( "Acceleration flags:");
couriersud@3023
   192
    for (n = 0; acceleration_mask[n].mask; n++) {
couriersud@3023
   193
        if (desc.acceleration_mask & acceleration_mask[n].mask)
slouken@5488
   194
            SDL_DFB_LOG( "    %s", acceleration_mask[n].name);
couriersud@3023
   195
    }
couriersud@3023
   196
couriersud@3023
   197
couriersud@3023
   198
}
couriersud@3023
   199
slouken@5199
   200
static int readBoolEnv(const char *env_name, int def_val)
slouken@5199
   201
{
slouken@5199
   202
    char *stemp;
slouken@5199
   203
slouken@5199
   204
    stemp = SDL_getenv(env_name);
slouken@5199
   205
    if (stemp)
slouken@5199
   206
        return atoi(stemp);
slouken@5199
   207
    else
slouken@5199
   208
        return def_val;
slouken@5199
   209
}
slouken@5199
   210
slouken@1895
   211
static int
slouken@2226
   212
DirectFB_VideoInit(_THIS)
slouken@167
   213
{
slouken@1895
   214
    IDirectFB *dfb = NULL;
slouken@2998
   215
    DFB_DeviceData *devdata = NULL;
slouken@2226
   216
    DFBResult ret;
slouken@2226
   217
slouken@5199
   218
    SDL_DFB_ALLOC_CLEAR(devdata, sizeof(*devdata));
slouken@2998
   219
slouken@2226
   220
    SDL_DFB_CHECKERR(DirectFBInit(NULL, NULL));
slouken@2998
   221
slouken@2998
   222
    /* avoid switching to the framebuffer when we
slouken@2998
   223
     * are running X11 */
slouken@5199
   224
    ret = readBoolEnv(DFBENV_USE_X11_CHECK , 1);
slouken@2998
   225
    if (ret) {
couriersud@3023
   226
        if (SDL_getenv("DISPLAY"))
slouken@2998
   227
            DirectFBSetOption("system", "x11");
slouken@2998
   228
        else
slouken@2998
   229
            DirectFBSetOption("disable-module", "x11input");
slouken@2998
   230
    }
slouken@2998
   231
slouken@4636
   232
	/* FIXME: Reenable as default once multi kbd/mouse interface is sorted out */
slouken@5199
   233
	devdata->use_linux_input = readBoolEnv(DFBENV_USE_LINUX_INPUT, 0);       /* default: on */
slouken@2998
   234
slouken@2998
   235
    if (!devdata->use_linux_input)
slouken@5199
   236
    {
slouken@5199
   237
		SDL_DFB_LOG("Disabling linxu input\n");    
slouken@2998
   238
        DirectFBSetOption("disable-module", "linux_input");
slouken@5199
   239
    }
slouken@5199
   240
    
slouken@2226
   241
    SDL_DFB_CHECKERR(DirectFBCreate(&dfb));
slouken@167
   242
couriersud@3023
   243
    DirectFB_DeviceInformation(dfb);
slouken@5199
   244
    
slouken@5199
   245
    devdata->use_yuv_underlays = readBoolEnv(DFBENV_USE_YUV_UNDERLAY, 0);     /* default: off */
slouken@5199
   246
    devdata->use_yuv_direct = readBoolEnv(DFBENV_USE_YUV_DIRECT, 0);      /* default is off! */
slouken@2998
   247
slouken@2737
   248
    /* Create global Eventbuffer for axis events */
slouken@2998
   249
    if (devdata->use_linux_input) {
couriersud@3023
   250
        SDL_DFB_CHECKERR(dfb->CreateInputEventBuffer(dfb, DICAPS_ALL,
couriersud@3023
   251
                                                     DFB_TRUE,
couriersud@3023
   252
                                                     &devdata->events));
slouken@2860
   253
    } else {
couriersud@3023
   254
        SDL_DFB_CHECKERR(dfb->CreateInputEventBuffer(dfb, DICAPS_AXES
couriersud@3023
   255
                                                     /*DICAPS_ALL */ ,
couriersud@3023
   256
                                                     DFB_TRUE,
couriersud@3023
   257
                                                     &devdata->events));
slouken@2860
   258
    }
slouken@167
   259
slouken@5199
   260
    /* simple window manager support */
slouken@5199
   261
    devdata->has_own_wm = readBoolEnv(DFBENV_USE_WM, 0);
couriersud@3023
   262
slouken@5199
   263
    devdata->initialized = 1;
couriersud@3023
   264
slouken@2226
   265
    devdata->dfb = dfb;
slouken@2226
   266
    devdata->firstwin = NULL;
slouken@4636
   267
    devdata->grabbed_window = NULL;
slouken@464
   268
slouken@2226
   269
    _this->driverdata = devdata;
slouken@464
   270
slouken@2737
   271
    DirectFB_InitModes(_this);
slouken@464
   272
slouken@2226
   273
#if SDL_DIRECTFB_OPENGL
slouken@2737
   274
    DirectFB_GL_Initialize(_this);
icculus@1165
   275
#endif
slouken@167
   276
slouken@2226
   277
    DirectFB_InitMouse(_this);
slouken@2721
   278
    DirectFB_InitKeyboard(_this);
slouken@2737
   279
slouken@2226
   280
    return 0;
slouken@2226
   281
slouken@167
   282
slouken@2226
   283
  error:
slouken@2998
   284
    SDL_DFB_FREE(devdata);
slouken@2226
   285
    SDL_DFB_RELEASE(dfb);
slouken@2226
   286
    return -1;
slouken@2226
   287
}
slouken@1895
   288
slouken@2226
   289
static void
slouken@2226
   290
DirectFB_VideoQuit(_THIS)
slouken@2226
   291
{
slouken@2226
   292
    DFB_DeviceData *devdata = (DFB_DeviceData *) _this->driverdata;
slouken@1895
   293
slouken@2737
   294
    DirectFB_QuitModes(_this);
slouken@2737
   295
    DirectFB_QuitKeyboard(_this);
slouken@2737
   296
    DirectFB_QuitMouse(_this);
icculus@728
   297
slouken@5199
   298
    devdata->events->Reset(devdata->events);
slouken@2737
   299
    SDL_DFB_RELEASE(devdata->events);
slouken@2226
   300
    SDL_DFB_RELEASE(devdata->dfb);
icculus@728
   301
slouken@2226
   302
#if SDL_DIRECTFB_OPENGL
slouken@2737
   303
    DirectFB_GL_Shutdown(_this);
slouken@2226
   304
#endif
slouken@2226
   305
slouken@2226
   306
    devdata->initialized = 0;
slouken@2226
   307
}
slouken@5199
   308
slouken@5199
   309
/* DirectFB driver general support functions */
slouken@5199
   310
slouken@5199
   311
static const struct {
slouken@5199
   312
    DFBSurfacePixelFormat dfb;
slouken@5199
   313
    Uint32 sdl;
slouken@5199
   314
} pixelformat_tab[] = 
slouken@5199
   315
{
slouken@5199
   316
    { DSPF_RGB32, SDL_PIXELFORMAT_RGB888 },             /* 24 bit RGB (4 byte, nothing@24, red 8@16, green 8@8, blue 8@0) */
slouken@5199
   317
    { DSPF_ARGB, SDL_PIXELFORMAT_ARGB8888 },            /* 32 bit ARGB (4 byte, alpha 8@24, red 8@16, green 8@8, blue 8@0) */
slouken@5199
   318
    { DSPF_RGB16, SDL_PIXELFORMAT_RGB565 },             /* 16 bit RGB (2 byte, red 5@11, green 6@5, blue 5@0) */
slouken@5199
   319
    { DSPF_RGB332, SDL_PIXELFORMAT_RGB332 },            /* 8 bit RGB (1 byte, red 3@5, green 3@2, blue 2@0) */
slouken@5199
   320
    { DSPF_ARGB4444, SDL_PIXELFORMAT_ARGB4444 },        /* 16 bit ARGB (2 byte, alpha 4@12, red 4@8, green 4@4, blue 4@0) */
slouken@5199
   321
    { DSPF_ARGB1555, SDL_PIXELFORMAT_ARGB1555 },        /* 16 bit ARGB (2 byte, alpha 1@15, red 5@10, green 5@5, blue 5@0) */
slouken@5199
   322
    { DSPF_RGB24, SDL_PIXELFORMAT_RGB24 },              /* 24 bit RGB (3 byte, red 8@16, green 8@8, blue 8@0) */
slouken@5199
   323
    { DSPF_RGB444, SDL_PIXELFORMAT_RGB444 },            /* 16 bit RGB (2 byte, nothing @12, red 4@8, green 4@4, blue 4@0) */
slouken@5199
   324
    { DSPF_YV12, SDL_PIXELFORMAT_YV12 },                /* 12 bit YUV (8 bit Y plane followed by 8 bit quarter size V/U planes) */
slouken@5199
   325
    { DSPF_I420,SDL_PIXELFORMAT_IYUV },                 /* 12 bit YUV (8 bit Y plane followed by 8 bit quarter size U/V planes) */
slouken@5199
   326
    { DSPF_YUY2, SDL_PIXELFORMAT_YUY2 },                /* 16 bit YUV (4 byte/ 2 pixel, macropixel contains CbYCrY [31:0]) */
slouken@5199
   327
    { DSPF_UYVY, SDL_PIXELFORMAT_UYVY },                /* 16 bit YUV (4 byte/ 2 pixel, macropixel contains YCbYCr [31:0]) */
slouken@5199
   328
    { DSPF_RGB555, SDL_PIXELFORMAT_RGB555 },            /* 16 bit RGB (2 byte, nothing @15, red 5@10, green 5@5, blue 5@0) */
slouken@5199
   329
#if (ENABLE_LUT8)
slouken@5199
   330
    { DSPF_LUT8, SDL_PIXELFORMAT_INDEX8 },              /* 8 bit LUT (8 bit color and alpha lookup from palette) */
slouken@5199
   331
#endif
slouken@5199
   332
slouken@5199
   333
#if (DFB_VERSION_ATLEAST(1,2,0))
slouken@5199
   334
    { DSPF_BGR555, SDL_PIXELFORMAT_BGR555 },            /* 16 bit BGR (2 byte, nothing @15, blue 5@10, green 5@5, red 5@0) */
slouken@5199
   335
#else
slouken@5199
   336
    { DSPF_UNKNOWN, SDL_PIXELFORMAT_BGR555 },
slouken@5199
   337
#endif
slouken@5199
   338
slouken@5199
   339
    /* Pfff ... nonmatching formats follow */    
slouken@5199
   340
    
slouken@5199
   341
    { DSPF_ALUT44, SDL_PIXELFORMAT_UNKNOWN },           /* 8 bit ALUT (1 byte, alpha 4@4, color lookup 4@0) */
slouken@5199
   342
 	{ DSPF_A8, SDL_PIXELFORMAT_UNKNOWN },               /* 	8 bit alpha (1 byte, alpha 8@0), e.g. anti-aliased glyphs */
slouken@5199
   343
 	{ DSPF_AiRGB, SDL_PIXELFORMAT_UNKNOWN },            /* 	32 bit ARGB (4 byte, inv. alpha 8@24, red 8@16, green 8@8, blue 8@0) */
slouken@5199
   344
 	{ DSPF_A1, SDL_PIXELFORMAT_UNKNOWN },               /* 	1 bit alpha (1 byte/ 8 pixel, most significant bit used first) */
slouken@5199
   345
 	{ DSPF_NV12, SDL_PIXELFORMAT_UNKNOWN },             /* 	12 bit YUV (8 bit Y plane followed by one 16 bit quarter size CbCr [15:0] plane) */
slouken@5199
   346
 	{ DSPF_NV16, SDL_PIXELFORMAT_UNKNOWN },             /* 	16 bit YUV (8 bit Y plane followed by one 16 bit half width CbCr [15:0] plane) */
slouken@5199
   347
 	{ DSPF_ARGB2554, SDL_PIXELFORMAT_UNKNOWN },         /* 	16 bit ARGB (2 byte, alpha 2@14, red 5@9, green 5@4, blue 4@0) */
slouken@5199
   348
 	{ DSPF_NV21, SDL_PIXELFORMAT_UNKNOWN },             /* 	12 bit YUV (8 bit Y plane followed by one 16 bit quarter size CrCb [15:0] plane) */
slouken@5199
   349
 	{ DSPF_AYUV, SDL_PIXELFORMAT_UNKNOWN },             /* 	32 bit AYUV (4 byte, alpha 8@24, Y 8@16, Cb 8@8, Cr 8@0) */
slouken@5199
   350
 	{ DSPF_A4, SDL_PIXELFORMAT_UNKNOWN },               /* 	4 bit alpha (1 byte/ 2 pixel, more significant nibble used first) */
slouken@5199
   351
 	{ DSPF_ARGB1666, SDL_PIXELFORMAT_UNKNOWN },         /* 	1 bit alpha (3 byte/ alpha 1@18, red 6@16, green 6@6, blue 6@0) */
slouken@5199
   352
 	{ DSPF_ARGB6666, SDL_PIXELFORMAT_UNKNOWN },         /* 	6 bit alpha (3 byte/ alpha 6@18, red 6@16, green 6@6, blue 6@0) */
slouken@5199
   353
 	{ DSPF_RGB18, SDL_PIXELFORMAT_UNKNOWN },            /* 	6 bit RGB (3 byte/ red 6@16, green 6@6, blue 6@0) */
slouken@5199
   354
 	{ DSPF_LUT2, SDL_PIXELFORMAT_UNKNOWN },             /* 	2 bit LUT (1 byte/ 4 pixel, 2 bit color and alpha lookup from palette) */
slouken@5199
   355
slouken@5199
   356
#if (DFB_VERSION_ATLEAST(1,3,0))
slouken@5199
   357
 	{ DSPF_RGBA4444, SDL_PIXELFORMAT_UNKNOWN },         /* 16 bit RGBA (2 byte, red 4@12, green 4@8, blue 4@4, alpha 4@0) */
slouken@5199
   358
#endif
slouken@5199
   359
slouken@5199
   360
#if (DFB_VERSION_ATLEAST(1,4,3))
slouken@5199
   361
 	{ DSPF_RGBA5551, SDL_PIXELFORMAT_UNKNOWN },         /* 	16 bit RGBA (2 byte, red 5@11, green 5@6, blue 5@1, alpha 1@0) */
slouken@5199
   362
 	{ DSPF_YUV444P, SDL_PIXELFORMAT_UNKNOWN },          /* 	24 bit full YUV planar (8 bit Y plane followed by an 8 bit Cb and an 8 bit Cr plane) */
slouken@5199
   363
 	{ DSPF_ARGB8565, SDL_PIXELFORMAT_UNKNOWN },         /* 	24 bit ARGB (3 byte, alpha 8@16, red 5@11, green 6@5, blue 5@0) */
slouken@5199
   364
 	{ DSPF_AVYU, SDL_PIXELFORMAT_UNKNOWN },             /* 	32 bit AVYU 4:4:4 (4 byte, alpha 8@24, Cr 8@16, Y 8@8, Cb 8@0) */
slouken@5199
   365
 	{ DSPF_VYU, SDL_PIXELFORMAT_UNKNOWN },              /* 	24 bit VYU 4:4:4 (3 byte, Cr 8@16, Y 8@8, Cb 8@0)  */
slouken@5199
   366
#endif
slouken@5199
   367
 	
slouken@5199
   368
    { DSPF_UNKNOWN, SDL_PIXELFORMAT_INDEX1LSB },
slouken@5199
   369
    { DSPF_UNKNOWN, SDL_PIXELFORMAT_INDEX1MSB },
slouken@5199
   370
    { DSPF_UNKNOWN, SDL_PIXELFORMAT_INDEX4LSB }, 
slouken@5199
   371
    { DSPF_UNKNOWN, SDL_PIXELFORMAT_INDEX4MSB },
slouken@5199
   372
    { DSPF_UNKNOWN, SDL_PIXELFORMAT_BGR24 },
slouken@5199
   373
    { DSPF_UNKNOWN, SDL_PIXELFORMAT_BGR888 },
slouken@5199
   374
    { DSPF_UNKNOWN, SDL_PIXELFORMAT_RGBA8888 },
slouken@5199
   375
    { DSPF_UNKNOWN, SDL_PIXELFORMAT_ABGR8888 },
slouken@5199
   376
    { DSPF_UNKNOWN, SDL_PIXELFORMAT_BGRA8888 },
slouken@5199
   377
    { DSPF_UNKNOWN, SDL_PIXELFORMAT_ARGB2101010 },
slouken@5199
   378
    { DSPF_UNKNOWN, SDL_PIXELFORMAT_ABGR4444 },
slouken@5199
   379
    { DSPF_UNKNOWN, SDL_PIXELFORMAT_ABGR1555 },
slouken@5199
   380
    { DSPF_UNKNOWN, SDL_PIXELFORMAT_BGR565 },
slouken@5199
   381
    { DSPF_UNKNOWN, SDL_PIXELFORMAT_YVYU },                        /**< Packed mode: Y0+V0+Y1+U0 (1 pla	*/
slouken@5199
   382
};
slouken@5199
   383
slouken@5199
   384
Uint32
slouken@5199
   385
DirectFB_DFBToSDLPixelFormat(DFBSurfacePixelFormat pixelformat)
slouken@5199
   386
{
slouken@5199
   387
    int i;
slouken@5199
   388
    
slouken@5199
   389
    for (i=0; pixelformat_tab[i].dfb != DSPF_UNKNOWN; i++)
slouken@5199
   390
        if (pixelformat_tab[i].dfb == pixelformat)
slouken@5199
   391
        {
slouken@5199
   392
            return pixelformat_tab[i].sdl;
slouken@5199
   393
        }
slouken@5199
   394
    return SDL_PIXELFORMAT_UNKNOWN;
slouken@5199
   395
}
slouken@5199
   396
slouken@5199
   397
DFBSurfacePixelFormat
slouken@5199
   398
DirectFB_SDLToDFBPixelFormat(Uint32 format)
slouken@5199
   399
{
slouken@5199
   400
    int i;
slouken@5199
   401
    
slouken@5199
   402
    for (i=0; pixelformat_tab[i].dfb != DSPF_UNKNOWN; i++)
slouken@5199
   403
        if (pixelformat_tab[i].sdl == format)
slouken@5199
   404
        {
slouken@5199
   405
            return pixelformat_tab[i].dfb;
slouken@5199
   406
        }
slouken@5199
   407
    return DSPF_UNKNOWN;
slouken@5199
   408
}
slouken@5199
   409
slouken@5199
   410
void DirectFB_SetSupportedPixelFormats(SDL_RendererInfo* ri)
slouken@5199
   411
{
slouken@5199
   412
	int i, j;
slouken@5199
   413
slouken@5199
   414
    for (i=0, j=0; pixelformat_tab[i].dfb != DSPF_UNKNOWN; i++)
slouken@5199
   415
    	if (pixelformat_tab[i].sdl != SDL_PIXELFORMAT_UNKNOWN)
slouken@5199
   416
    		ri->texture_formats[j++] = pixelformat_tab[i].sdl;
slouken@5199
   417
    ri->num_texture_formats = j;
slouken@5199
   418
}