src/video/directfb/SDL_DirectFB_video.c
author Sam Lantinga <slouken@libsdl.org>
Sat, 05 Feb 2011 16:07:10 -0800
changeset 5199 164f20ba08eb
parent 4636 b196d2758026
child 5243 3a8a452b49f0
permissions -rw-r--r--
Updated the DirectFB support, from Couriersud

attached is a working directfb driver diff which works with the current
changes. There are a number of changes around it as well, e.g.
configure.in.

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