src/video/directfb/SDL_DirectFB_video.c
author Sam Lantinga
Mon, 14 Mar 2011 23:13:33 -0700
changeset 5488 c20436fd5627
parent 5262 b530ef003506
child 5489 e0c63a55b67d
permissions -rw-r--r--
DirectFB driver update

Couriersud to Sam

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