src/video/directfb/SDL_DirectFB_video.c
author Sam Lantinga <slouken@libsdl.org>
Tue, 28 Aug 2018 13:37:11 -0700
changeset 12158 ee7f3955c9fb
parent 11811 5d94cb6b24d3
child 12201 8bdc4d340419
permissions -rw-r--r--
Fixed bug 4229 - Add support for ABGR format in DirectFB renderer

Alexandre

DirectFB supports 32-bit ABGR pixel format via DSPF_ABGR, but SDL doesn't map SDL_PIXELFORMAT_ABGR8888 to DSPF_ABGR.

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