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