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