src/video/directfb/SDL_DirectFB_video.c
author Sam Lantinga
Sat, 11 Aug 2007 21:51:19 +0000
changeset 2226 0e70b4b8cf84
parent 2113 6264c973814a
child 2227 b252359547ed
permissions -rw-r--r--
Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST)
From: couriersud arcor.de
To: slouken@libsdl.org
Subject: Directfb driver for SDL1.3

Hi,

the attachment contains a patch for a SDL1.3 directfb driver. It supports:

- Renderer "directfb":

Hardware acceleration as supported by the underlying directfb driver. With a
radeon X850, testsprite2 runs at 50% to 70% of OpenGL (X11, dri) performance.

Also supports hardware accelerated yuv overlays. This must be enabled by sett
ing:

export SDL_DIRECTFB_YUV_DIRECT=1

- Renderer "opengl"

Supports software opengl using mesa opengl (make linux-directfb).

Some more information may be found in README.DirectFB

There will certainly still be some bugs, and there is some debug code around.
When I find some time, I will compile against directfb-0.9.25 as distributed
with ubuntu 7.04.

The diff also contains a fix for SDL_LockYUVOverlay fixing a bug in *pixels
and pitches initialization.

Kind regards,

couriersud
slouken@167
     1
/*
slouken@1312
     2
    SDL - Simple DirectMedia Layer
slouken@1312
     3
    Copyright (C) 1997-2006 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@2226
    22
    SDL1.3 implementation by couriersud@arcor.de
slouken@2226
    23
	
slouken@167
    24
*/
slouken@2226
    25
slouken@2226
    26
/* TODO: Various
slouken@2226
    27
 * Add Mouse support from 1.2 directfb driver
slouken@2226
    28
 * - Interface is defined in SDL_Mouse.c.h
slouken@2226
    29
 * - Default Cursor automatically created
slouken@2226
    30
 */
slouken@2226
    31
slouken@1402
    32
#include "SDL_config.h"
slouken@167
    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>
slouken@167
    43
slouken@167
    44
#include "SDL_video.h"
slouken@167
    45
#include "SDL_mouse.h"
slouken@1361
    46
#include "../SDL_sysvideo.h"
slouken@1361
    47
#include "../SDL_pixels_c.h"
slouken@1361
    48
#include "../../events/SDL_events_c.h"
slouken@167
    49
#include "SDL_DirectFB_video.h"
slouken@167
    50
#include "SDL_DirectFB_events.h"
slouken@167
    51
slouken@167
    52
/* This is the rect EnumModes2 uses */
slouken@1895
    53
struct DirectFBEnumRect
slouken@1895
    54
{
slouken@1895
    55
    SDL_Rect r;
slouken@1895
    56
    struct DirectFBEnumRect *next;
slouken@167
    57
};
slouken@167
    58
slouken@2226
    59
struct DirectFB_GLContext
slouken@2226
    60
{
slouken@2226
    61
    IDirectFBGL *context;
slouken@2226
    62
};
slouken@2226
    63
slouken@2226
    64
/* Initialization/Query functions */
slouken@2226
    65
static int DirectFB_VideoInit(_THIS);
slouken@2226
    66
static void DirectFB_VideoQuit(_THIS);
slouken@167
    67
slouken@2226
    68
static int DirectFB_CreateWindow(_THIS, SDL_Window * window);
slouken@2226
    69
static int DirectFB_CreateWindowFrom(_THIS, SDL_Window * window,
slouken@2226
    70
                                     const void *data);
slouken@2226
    71
static void DirectFB_SetWindowTitle(_THIS, SDL_Window * window);
slouken@2226
    72
static void DirectFB_SetWindowPosition(_THIS, SDL_Window * window);
slouken@2226
    73
static void DirectFB_SetWindowSize(_THIS, SDL_Window * window);
slouken@2226
    74
static void DirectFB_ShowWindow(_THIS, SDL_Window * window);
slouken@2226
    75
static void DirectFB_HideWindow(_THIS, SDL_Window * window);
slouken@2226
    76
static void DirectFB_RaiseWindow(_THIS, SDL_Window * window);
slouken@2226
    77
static void DirectFB_MaximizeWindow(_THIS, SDL_Window * window);
slouken@2226
    78
static void DirectFB_MinimizeWindow(_THIS, SDL_Window * window);
slouken@2226
    79
static void DirectFB_RestoreWindow(_THIS, SDL_Window * window);
slouken@2226
    80
static void DirectFB_SetWindowGrab(_THIS, SDL_Window * window);
slouken@2226
    81
static void DirectFB_DestroyWindow(_THIS, SDL_Window * window);
slouken@2226
    82
static SDL_bool DirectFB_GetWindowWMInfo(_THIS, SDL_Window * window,
slouken@2226
    83
                                         struct SDL_SysWMinfo *info);
slouken@2226
    84
slouken@2226
    85
static void DirectFB_GetDisplayModes(_THIS);
slouken@2226
    86
static int DirectFB_SetDisplayMode(_THIS, SDL_DisplayMode * mode);
slouken@2226
    87
slouken@2226
    88
static int DirectFB_SetDisplayGammaRamp(_THIS, Uint16 * ramp);
slouken@2226
    89
static int DirectFB_GetDisplayGammaRamp(_THIS, Uint16 * ramp);
slouken@2226
    90
slouken@2226
    91
#if SDL_DIRECTFB_OPENGL
slouken@2226
    92
static int DirectFB_GL_LoadLibrary(_THIS, const char *path);
slouken@2226
    93
static void DirectFB_GL_UnloadLibrary(_THIS);
slouken@2226
    94
static void *DirectFB_GL_GetProcAddress(_THIS, const char *proc);
slouken@2226
    95
static SDL_GLContext DirectFB_GL_CreateContext(_THIS, SDL_Window * window);
slouken@2226
    96
static int DirectFB_GL_MakeCurrent(_THIS, SDL_Window * window,
slouken@2226
    97
                                   SDL_GLContext context);
slouken@2226
    98
static int DirectFB_GL_SetSwapInterval(_THIS, int interval);
slouken@2226
    99
static int DirectFB_GL_GetSwapInterval(_THIS);
slouken@2226
   100
static void DirectFB_GL_SwapWindow(_THIS, SDL_Window * window);
slouken@2226
   101
static void DirectFB_GL_DeleteContext(_THIS, SDL_GLContext context);
slouken@2226
   102
slouken@2226
   103
#endif
slouken@167
   104
slouken@167
   105
/* DirectFB driver bootstrap functions */
slouken@167
   106
slouken@1895
   107
static int
slouken@1895
   108
DirectFB_Available(void)
slouken@167
   109
{
slouken@1895
   110
    return 1;
slouken@167
   111
}
slouken@167
   112
slouken@1895
   113
static void
slouken@1895
   114
DirectFB_DeleteDevice(SDL_VideoDevice * device)
slouken@167
   115
{
slouken@2226
   116
    SDL_free(device->driverdata);
slouken@1895
   117
    SDL_free(device);
slouken@167
   118
}
slouken@167
   119
slouken@1895
   120
static SDL_VideoDevice *
slouken@1895
   121
DirectFB_CreateDevice(int devindex)
slouken@167
   122
{
slouken@1895
   123
    SDL_VideoDevice *device;
slouken@167
   124
slouken@1895
   125
    /* Initialize all variables that we clean on shutdown */
slouken@2226
   126
    SDL_DFB_CALLOC(device, 1, sizeof(SDL_VideoDevice));
slouken@2226
   127
    SDL_DFB_CALLOC(device->gl_data, 1, sizeof(*device->gl_data));
slouken@2226
   128
slouken@2226
   129
    /* Set the function pointers */
slouken@167
   130
slouken@1895
   131
    /* Set the function pointers */
slouken@1895
   132
    device->VideoInit = DirectFB_VideoInit;
slouken@1895
   133
    device->VideoQuit = DirectFB_VideoQuit;
slouken@2226
   134
    device->GetDisplayModes = DirectFB_GetDisplayModes;
slouken@2226
   135
    device->SetDisplayMode = DirectFB_SetDisplayMode;
slouken@2226
   136
#if 0
slouken@2226
   137
    device->SetDisplayGammaRamp = DirectFB_SetDisplayGammaRamp;
slouken@2226
   138
    device->GetDisplayGammaRamp = DirectFB_GetDisplayGammaRamp;
slouken@2226
   139
#else
slouken@2226
   140
    device->SetDisplayGammaRamp = NULL;
slouken@2226
   141
    device->GetDisplayGammaRamp = NULL;
slouken@2226
   142
#endif
slouken@2226
   143
    device->PumpEvents = DirectFB_PumpEventsWindow;
slouken@2226
   144
slouken@2226
   145
    device->CreateWindow = DirectFB_CreateWindow;
slouken@2226
   146
    device->CreateWindowFrom = DirectFB_CreateWindowFrom;
slouken@2226
   147
    device->SetWindowTitle = DirectFB_SetWindowTitle;
slouken@2226
   148
    device->SetWindowPosition = DirectFB_SetWindowPosition;
slouken@2226
   149
    device->SetWindowSize = DirectFB_SetWindowSize;
slouken@2226
   150
    device->ShowWindow = DirectFB_ShowWindow;
slouken@2226
   151
    device->HideWindow = DirectFB_HideWindow;
slouken@2226
   152
    device->RaiseWindow = DirectFB_RaiseWindow;
slouken@2226
   153
    device->MaximizeWindow = DirectFB_MaximizeWindow;
slouken@2226
   154
    device->MinimizeWindow = DirectFB_MinimizeWindow;
slouken@2226
   155
    device->RestoreWindow = DirectFB_RestoreWindow;
slouken@2226
   156
    device->SetWindowGrab = DirectFB_SetWindowGrab;
slouken@2226
   157
    device->DestroyWindow = DirectFB_DestroyWindow;
slouken@2226
   158
    device->GetWindowWMInfo = DirectFB_GetWindowWMInfo;
slouken@2226
   159
slouken@2226
   160
#if SDL_DIRECTFB_OPENGL
slouken@2226
   161
    device->GL_LoadLibrary = DirectFB_GL_LoadLibrary;
slouken@2226
   162
    device->GL_GetProcAddress = DirectFB_GL_GetProcAddress;
slouken@2226
   163
    device->GL_MakeCurrent = DirectFB_GL_MakeCurrent;
slouken@2226
   164
slouken@2226
   165
    device->GL_CreateContext = DirectFB_GL_CreateContext;
slouken@2226
   166
    device->GL_SetSwapInterval = DirectFB_GL_SetSwapInterval;
slouken@2226
   167
    device->GL_GetSwapInterval = DirectFB_GL_GetSwapInterval;
slouken@2226
   168
    device->GL_SwapWindow = DirectFB_GL_SwapWindow;
slouken@2226
   169
    device->GL_DeleteContext = DirectFB_GL_DeleteContext;
slouken@2226
   170
slouken@2226
   171
#endif
slouken@167
   172
slouken@1895
   173
    device->free = DirectFB_DeleteDevice;
slouken@167
   174
slouken@1895
   175
    return device;
slouken@2226
   176
  error:
slouken@2226
   177
    if (device)
slouken@2226
   178
        free(device);
slouken@2226
   179
    return (0);
slouken@167
   180
}
slouken@167
   181
slouken@167
   182
VideoBootStrap DirectFB_bootstrap = {
slouken@1895
   183
    "directfb", "DirectFB",
slouken@1895
   184
    DirectFB_Available, DirectFB_CreateDevice
slouken@167
   185
};
slouken@167
   186
slouken@1895
   187
static DFBEnumerationResult
slouken@1895
   188
EnumModesCallback(int width, int height, int bpp, void *data)
slouken@167
   189
{
slouken@2226
   190
    SDL_VideoDisplay *this = (SDL_VideoDisplay *) data;
slouken@2226
   191
    DFB_DisplayData *dispdata = (DFB_DisplayData *) this->driverdata;
slouken@2226
   192
    SDL_DisplayMode mode;
slouken@167
   193
slouken@2226
   194
    mode.w = width;
slouken@2226
   195
    mode.h = height;
slouken@2226
   196
    mode.refresh_rate = 0;
slouken@2226
   197
    mode.driverdata = NULL;
slouken@2226
   198
    mode.format = 0;
slouken@1777
   199
slouken@2226
   200
    if (dispdata->nummodes < DFB_MAX_MODES) {
slouken@2226
   201
        dispdata->modelist[dispdata->nummodes++] = mode;
slouken@167
   202
    }
slouken@167
   203
slouken@2226
   204
    SDL_DFB_DEBUG("w %d h %d bpp %d\n", width, height, bpp);
slouken@1895
   205
    return DFENUM_OK;
slouken@167
   206
}
slouken@167
   207
slouken@2226
   208
static int
slouken@2226
   209
DFBToSDLPixelFormat(DFBSurfacePixelFormat pixelformat, Uint32 * fmt)
slouken@1895
   210
{
slouken@2226
   211
    switch (pixelformat) {
slouken@2226
   212
    case DSPF_ALUT44:
slouken@2226
   213
        *fmt = SDL_PIXELFORMAT_INDEX4LSB;
slouken@2226
   214
        break;
slouken@2226
   215
    case DSPF_LUT8:
slouken@2226
   216
        *fmt = SDL_PIXELFORMAT_INDEX8;
slouken@2226
   217
        break;
slouken@2226
   218
    case DSPF_RGB332:
slouken@2226
   219
        *fmt = SDL_PIXELFORMAT_RGB332;
slouken@2226
   220
        break;
slouken@2226
   221
    case DSPF_ARGB4444:
slouken@2226
   222
        *fmt = SDL_PIXELFORMAT_ARGB4444;
slouken@2226
   223
        break;
slouken@2226
   224
    case SDL_PIXELFORMAT_ARGB1555:
slouken@2226
   225
        *fmt = SDL_PIXELFORMAT_ARGB1555;
slouken@2226
   226
        break;
slouken@2226
   227
    case DSPF_RGB16:
slouken@2226
   228
        *fmt = SDL_PIXELFORMAT_RGB565;
slouken@2226
   229
        break;
slouken@2226
   230
    case DSPF_RGB24:
slouken@2226
   231
        *fmt = SDL_PIXELFORMAT_RGB24;
slouken@2226
   232
        break;
slouken@2226
   233
    case DSPF_RGB32:
slouken@2226
   234
        *fmt = SDL_PIXELFORMAT_RGB888;
slouken@2226
   235
        break;
slouken@2226
   236
    case DSPF_ARGB:
slouken@2226
   237
        *fmt = SDL_PIXELFORMAT_ARGB8888;
slouken@2226
   238
        break;
slouken@2226
   239
    case DSPF_YV12:
slouken@2226
   240
        *fmt = SDL_PIXELFORMAT_YV12;
slouken@2226
   241
        break;                  /* Planar mode: Y + V + U  (3 planes) */
slouken@2226
   242
    case DSPF_I420:
slouken@2226
   243
        *fmt = SDL_PIXELFORMAT_IYUV;
slouken@2226
   244
        break;                  /* Planar mode: Y + U + V  (3 planes) */
slouken@2226
   245
    case DSPF_YUY2:
slouken@2226
   246
        *fmt = SDL_PIXELFORMAT_YUY2;
slouken@2226
   247
        break;                  /* Packed mode: Y0+U0+Y1+V0 (1 plane) */
slouken@2226
   248
    case DSPF_UYVY:
slouken@2226
   249
        *fmt = SDL_PIXELFORMAT_UYVY;
slouken@2226
   250
        break;                  /* Packed mode: U0+Y0+V0+Y1 (1 plane) */
slouken@2226
   251
    default:
slouken@2226
   252
        return -1;
slouken@2226
   253
    }
slouken@2226
   254
    return 0;
slouken@167
   255
}
slouken@167
   256
slouken@2226
   257
static DFBEnumerationResult
slouken@2226
   258
cbScreens(DFBScreenID screen_id, DFBScreenDescription desc,
slouken@2226
   259
          void *callbackdata)
slouken@167
   260
{
slouken@2226
   261
    DFB_DeviceData *devdata = (DFB_DeviceData *) callbackdata;
slouken@1895
   262
slouken@2226
   263
    devdata->screenid[devdata->numscreens++] = screen_id;
slouken@2226
   264
    return DFENUM_OK;
slouken@2226
   265
}
slouken@1895
   266
slouken@2226
   267
DFBEnumerationResult
slouken@2226
   268
cbLayers(DFBDisplayLayerID layer_id, DFBDisplayLayerDescription desc,
slouken@2226
   269
         void *callbackdata)
slouken@2226
   270
{
slouken@2226
   271
    DFB_DeviceData *devdata = (DFB_DeviceData *) callbackdata;
slouken@464
   272
slouken@2226
   273
    if (desc.caps & DLCAPS_SURFACE) {
slouken@2226
   274
        if ((desc.type & DLTF_GRAPHICS) && (desc.type & DLTF_VIDEO)) {
slouken@2226
   275
            if (devdata->vidlayer[devdata->aux] == -1)
slouken@2226
   276
                devdata->vidlayer[devdata->aux] = layer_id;
slouken@2226
   277
        } else if (desc.type & DLTF_GRAPHICS) {
slouken@2226
   278
            if (devdata->gralayer[devdata->aux] == -1)
slouken@2226
   279
                devdata->gralayer[devdata->aux] = layer_id;
slouken@167
   280
        }
slouken@167
   281
    }
slouken@2226
   282
    return DFENUM_OK;
slouken@464
   283
}
slouken@464
   284
slouken@1895
   285
static int
slouken@2226
   286
DirectFB_VideoInit(_THIS)
slouken@167
   287
{
icculus@1165
   288
#if (DIRECTFB_MAJOR_VERSION == 0) && (DIRECTFB_MINOR_VERSION == 9) && (DIRECTFB_MICRO_VERSION < 23)
slouken@1895
   289
    DFBCardCapabilities caps;
icculus@1165
   290
#else
slouken@1895
   291
    DFBGraphicsDeviceDescription caps;
icculus@1165
   292
#endif
slouken@1895
   293
    DFBDisplayLayerConfig dlc;
slouken@1895
   294
    struct DirectFBEnumRect *rect;
slouken@1895
   295
    IDirectFB *dfb = NULL;
slouken@1895
   296
    IDirectFBDisplayLayer *layer = NULL;
slouken@167
   297
slouken@2226
   298
    SDL_VideoDisplay display;
slouken@2226
   299
    DFB_DisplayData *dispdata;
slouken@2226
   300
    DFB_DeviceData *devdata;
slouken@2226
   301
    SDL_DisplayMode mode;
slouken@2226
   302
    SDL_Keyboard keyboard;
slouken@2226
   303
    int i;
slouken@2226
   304
    DFBResult ret;
slouken@2226
   305
    int tcw[DFB_MAX_SCREENS];
slouken@2226
   306
    int tch[DFB_MAX_SCREENS];
slouken@2226
   307
slouken@2226
   308
    SDL_zero(keyboard);
slouken@2226
   309
slouken@2226
   310
    SDL_DFB_CHECKERR(DirectFBInit(NULL, NULL));
slouken@2226
   311
    SDL_DFB_CHECKERR(DirectFBCreate(&dfb));
slouken@167
   312
slouken@2226
   313
    SDL_DFB_CALLOC(devdata, 1, sizeof(*devdata));
slouken@2226
   314
    devdata->numscreens = 0;
slouken@2226
   315
    for (i = 0; i < DFB_MAX_SCREENS; i++) {
slouken@2226
   316
        devdata->gralayer[i] = -1;
slouken@2226
   317
        devdata->vidlayer[i] = -1;
slouken@1895
   318
    }
slouken@2226
   319
    SDL_DFB_CHECKERR(dfb->EnumScreens(dfb, &cbScreens, devdata));
slouken@2226
   320
    for (i = 0; i < devdata->numscreens; i++) {
slouken@2226
   321
        IDirectFBScreen *screen;
slouken@1895
   322
slouken@2226
   323
        SDL_DFB_CHECKERR(dfb->GetScreen(dfb, devdata->screenid[i], &screen));
slouken@167
   324
slouken@2226
   325
        devdata->aux = i;
slouken@2226
   326
        SDL_DFB_CHECKERR(screen->
slouken@2226
   327
                         EnumDisplayLayers(screen, &cbLayers, devdata));
slouken@2226
   328
        screen->GetSize(screen, &tcw[i], &tch[i]);
slouken@2226
   329
        screen->Release(screen);
slouken@1895
   330
    }
slouken@1895
   331
slouken@2226
   332
    /* Query card capabilities */
slouken@2226
   333
slouken@2226
   334
    dfb->GetDeviceDescription(dfb, &caps);
slouken@2226
   335
slouken@2226
   336
    SDL_DFB_DEBUG("SDL directfb video driver - %s %s\n", __DATE__, __TIME__);
slouken@2226
   337
    SDL_DFB_DEBUG("Using %s (%s) driver.\n", caps.name, caps.vendor);
slouken@2226
   338
    SDL_DFB_DEBUG("Found %d screens\n", devdata->numscreens);
slouken@1895
   339
slouken@2226
   340
    for (i = 0; i < devdata->numscreens; i++) {
slouken@2226
   341
        //SDL_DFB_CHECKERR( dfb->GetDisplayLayer (dfb, DLID_PRIMARY, &layer) );
slouken@2226
   342
        SDL_DFB_CHECKERR(dfb->
slouken@2226
   343
                         GetDisplayLayer(dfb, devdata->gralayer[i], &layer));
slouken@2226
   344
        //SDL_DFB_CHECKERR( dfb->CreateInputEventBuffer (dfb, DICAPS_ALL, DFB_FALSE, &events) );
slouken@2226
   345
slouken@2226
   346
        SDL_DFB_CHECKERR(layer->
slouken@2226
   347
                         SetCooperativeLevel(layer, DLSCL_ADMINISTRATIVE));
slouken@2226
   348
        layer->EnableCursor(layer, 1);
slouken@2226
   349
        SDL_DFB_CHECKERR(layer->SetCursorOpacity(layer, 0xC0));
slouken@2226
   350
        SDL_DFB_CHECKERR(layer->SetCooperativeLevel(layer, DLSCL_SHARED));
slouken@2226
   351
slouken@2226
   352
        /* Query layer configuration to determine the current mode and pixelformat */
slouken@2226
   353
        layer->GetConfiguration(layer, &dlc);
slouken@2226
   354
slouken@2226
   355
        DFBToSDLPixelFormat(dlc.pixelformat, &mode.format);
slouken@1895
   356
slouken@2226
   357
        mode.w = dlc.width;
slouken@2226
   358
        mode.h = dlc.height;
slouken@2226
   359
        mode.refresh_rate = 0;
slouken@2226
   360
        mode.driverdata = NULL;
slouken@2226
   361
slouken@2226
   362
        SDL_DFB_CALLOC(dispdata, 1, sizeof(*dispdata));
slouken@2226
   363
slouken@2226
   364
        dispdata->layer = layer;
slouken@2226
   365
        dispdata->pixelformat = dlc.pixelformat;
slouken@2226
   366
        dispdata->cw = tcw[i];
slouken@2226
   367
        dispdata->ch = tch[i];
slouken@2226
   368
slouken@2226
   369
        /* YUV - Video layer */
slouken@1895
   370
slouken@2226
   371
        dispdata->vidID = devdata->vidlayer[i];
slouken@2226
   372
slouken@2226
   373
        SDL_zero(display);
slouken@2226
   374
slouken@2226
   375
        display.desktop_mode = mode;
slouken@2226
   376
        display.current_mode = mode;
slouken@2226
   377
        display.driverdata = dispdata;
slouken@2226
   378
slouken@2226
   379
        /* Enumerate the available fullscreen modes */
slouken@2226
   380
        SDL_DFB_CALLOC(dispdata->modelist, DFB_MAX_MODES,
slouken@2226
   381
                       sizeof(SDL_DisplayMode));
slouken@2226
   382
        SDL_DFB_CHECKERR(dfb->
slouken@2226
   383
                         EnumVideoModes(dfb, EnumModesCallback, &display));
slouken@2226
   384
slouken@2226
   385
        SDL_AddVideoDisplay(&display);
slouken@167
   386
    }
slouken@167
   387
slouken@2226
   388
    devdata->initialized = 1;
slouken@2226
   389
    devdata->dfb = dfb;
slouken@2226
   390
    devdata->firstwin = NULL;
slouken@464
   391
slouken@2226
   392
    _this->driverdata = devdata;
slouken@464
   393
slouken@464
   394
slouken@2226
   395
#if SDL_DIRECTFB_OPENGL
slouken@2226
   396
    /* Opengl */
slouken@2226
   397
    _this->gl_data->gl_active = 0;
slouken@2226
   398
    _this->gl_data->gl_context = NULL;
icculus@1165
   399
#endif
slouken@167
   400
slouken@2226
   401
    DirectFB_AddRenderDriver(_this);
slouken@2226
   402
    DirectFB_InitMouse(_this);
slouken@2226
   403
    //devdata->mouse = SDL_AddMouse(&mouse, -1);
slouken@2226
   404
    devdata->keyboard = SDL_AddKeyboard(&keyboard, -1);
slouken@2226
   405
    DirectFB_InitOSKeymap(_this);
slouken@2226
   406
slouken@2226
   407
    return 0;
slouken@2226
   408
slouken@167
   409
slouken@2226
   410
  error:
slouken@2226
   411
    //FIXME: Cleanup not complete, Free existing displays
slouken@2226
   412
    SDL_DFB_FREE(dispdata);
slouken@2226
   413
    SDL_DFB_FREE(dispdata->modelist);
slouken@2226
   414
    SDL_DFB_RELEASE(layer);
slouken@2226
   415
    SDL_DFB_RELEASE(dfb);
slouken@2226
   416
    return -1;
slouken@2226
   417
}
slouken@1895
   418
slouken@2226
   419
static void
slouken@2226
   420
DirectFB_VideoQuit(_THIS)
slouken@2226
   421
{
slouken@2226
   422
    DFB_DeviceData *devdata = (DFB_DeviceData *) _this->driverdata;
slouken@2226
   423
    SDL_DisplayMode tmode;
slouken@2226
   424
    DFBResult ret;
slouken@2226
   425
    int i;
slouken@1018
   426
slouken@2226
   427
    tmode = _this->displays[0].desktop_mode;
slouken@2226
   428
    tmode.format = SDL_PIXELFORMAT_UNKNOWN;
slouken@2226
   429
    DirectFB_SetDisplayMode(_this, &tmode);
slouken@2226
   430
    tmode = _this->displays[0].desktop_mode;
slouken@2226
   431
    DirectFB_SetDisplayMode(_this, &tmode);
slouken@1895
   432
slouken@2226
   433
    for (i = 0; i < devdata->numscreens; i++) {
slouken@2226
   434
        DFB_DisplayData *dispdata =
slouken@2226
   435
            (DFB_DisplayData *) _this->displays[i].driverdata;
slouken@2226
   436
        if (dispdata->layer) {
slouken@2226
   437
            SDL_DFB_CHECK(dispdata->layer->
slouken@2226
   438
                          SetCooperativeLevel(dispdata->layer,
slouken@2226
   439
                                              DLSCL_ADMINISTRATIVE));
slouken@2226
   440
            SDL_DFB_CHECK(dispdata->layer->
slouken@2226
   441
                          SetCursorOpacity(dispdata->layer, 0x00));
slouken@2226
   442
            SDL_DFB_CHECK(dispdata->layer->
slouken@2226
   443
                          SetCooperativeLevel(dispdata->layer, DLSCL_SHARED));
icculus@728
   444
        }
slouken@2226
   445
        SDL_DFB_RELEASE(dispdata->layer);
icculus@728
   446
slouken@2226
   447
        /* Free video mode list */
slouken@2226
   448
        if (dispdata->modelist) {
slouken@2226
   449
            SDL_free(dispdata->modelist);
slouken@2226
   450
            dispdata->modelist = NULL;
icculus@728
   451
        }
slouken@2226
   452
        // Done by core
slouken@2226
   453
        //SDL_free(dispdata);
slouken@2226
   454
    }
slouken@2226
   455
slouken@2226
   456
    //SDL_DFB_RELEASE(devdata->eventbuffer);
slouken@1895
   457
slouken@2226
   458
    SDL_DFB_RELEASE(devdata->dfb);
slouken@2226
   459
slouken@2226
   460
    SDL_DelMouse(devdata->mouse);
slouken@2226
   461
    SDL_DelKeyboard(devdata->keyboard);
icculus@728
   462
slouken@2226
   463
#if SDL_DIRECTFB_OPENGL
slouken@2226
   464
    DirectFB_GL_UnloadLibrary(_this);
slouken@2226
   465
#endif
slouken@2226
   466
slouken@2226
   467
    devdata->initialized = 0;
slouken@2226
   468
}
slouken@2226
   469
slouken@1895
   470
slouken@2226
   471
static DFBSurfacePixelFormat
slouken@2226
   472
SDLToDFBPixelFormat(Uint32 format)
slouken@2226
   473
{
slouken@2226
   474
    switch (format) {
slouken@2226
   475
    case SDL_PIXELFORMAT_INDEX4LSB:
slouken@2226
   476
        return DSPF_ALUT44;
slouken@2226
   477
    case SDL_PIXELFORMAT_INDEX8:
slouken@2226
   478
        return DSPF_LUT8;
slouken@2226
   479
    case SDL_PIXELFORMAT_RGB332:
slouken@2226
   480
        return DSPF_RGB332;
slouken@2226
   481
    case SDL_PIXELFORMAT_RGB555:
slouken@2226
   482
        return DSPF_ARGB1555;
slouken@2226
   483
    case SDL_PIXELFORMAT_ARGB4444:
slouken@2226
   484
        return DSPF_ARGB4444;
slouken@2226
   485
    case SDL_PIXELFORMAT_ARGB1555:
slouken@2226
   486
        return DSPF_ARGB1555;
slouken@2226
   487
    case SDL_PIXELFORMAT_RGB565:
slouken@2226
   488
        return DSPF_RGB16;
slouken@2226
   489
    case SDL_PIXELFORMAT_RGB24:
slouken@2226
   490
        return DSPF_RGB24;
slouken@2226
   491
    case SDL_PIXELFORMAT_RGB888:
slouken@2226
   492
        return DSPF_RGB32;
slouken@2226
   493
    case SDL_PIXELFORMAT_ARGB8888:
slouken@2226
   494
        return DSPF_ARGB;
slouken@2226
   495
    case SDL_PIXELFORMAT_YV12:
slouken@2226
   496
        return DSPF_YV12;       /* Planar mode: Y + V + U  (3 planes) */
slouken@2226
   497
    case SDL_PIXELFORMAT_IYUV:
slouken@2226
   498
        return DSPF_I420;       /* Planar mode: Y + U + V  (3 planes) */
slouken@2226
   499
    case SDL_PIXELFORMAT_YUY2:
slouken@2226
   500
        return DSPF_YUY2;       /* Packed mode: Y0+U0+Y1+V0 (1 plane) */
slouken@2226
   501
    case SDL_PIXELFORMAT_UYVY:
slouken@2226
   502
        return DSPF_UYVY;       /* Packed mode: U0+Y0+V0+Y1 (1 plane) */
slouken@2226
   503
    case SDL_PIXELFORMAT_YVYU:
slouken@2226
   504
        return DSPF_UNKNOWN;    /* Packed mode: Y0+V0+Y1+U0 (1 plane) */
slouken@2226
   505
    case SDL_PIXELFORMAT_INDEX1LSB:
slouken@2226
   506
        return DSPF_UNKNOWN;
slouken@2226
   507
    case SDL_PIXELFORMAT_INDEX1MSB:
slouken@2226
   508
        return DSPF_UNKNOWN;
slouken@2226
   509
    case SDL_PIXELFORMAT_INDEX4MSB:
slouken@2226
   510
        return DSPF_UNKNOWN;
slouken@2226
   511
    case SDL_PIXELFORMAT_RGB444:
slouken@2226
   512
        return DSPF_UNKNOWN;
slouken@2226
   513
    case SDL_PIXELFORMAT_BGR24:
slouken@2226
   514
        return DSPF_UNKNOWN;
slouken@2226
   515
    case SDL_PIXELFORMAT_BGR888:
slouken@2226
   516
        return DSPF_UNKNOWN;
slouken@2226
   517
    case SDL_PIXELFORMAT_RGBA8888:
slouken@2226
   518
        return DSPF_UNKNOWN;
slouken@2226
   519
    case SDL_PIXELFORMAT_ABGR8888:
slouken@2226
   520
        return DSPF_UNKNOWN;
slouken@2226
   521
    case SDL_PIXELFORMAT_BGRA8888:
slouken@2226
   522
        return DSPF_UNKNOWN;
slouken@2226
   523
    case SDL_PIXELFORMAT_ARGB2101010:
slouken@2226
   524
        return DSPF_UNKNOWN;
slouken@2226
   525
    default:
slouken@2226
   526
        return DSPF_UNKNOWN;
slouken@2226
   527
    }
slouken@2226
   528
}
icculus@728
   529
slouken@2226
   530
static void
slouken@2226
   531
CheckSetDisplayMode(_THIS, DFB_DisplayData * data, SDL_DisplayMode * mode)
slouken@2226
   532
{
slouken@2226
   533
    DFBDisplayLayerConfig config;
slouken@2226
   534
    DFBDisplayLayerConfigFlags failed;
slouken@1895
   535
slouken@2226
   536
    config.width = mode->w;
slouken@2226
   537
    config.height = mode->h;
slouken@2226
   538
    config.pixelformat = SDLToDFBPixelFormat(mode->format);
slouken@2226
   539
    config.flags = DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT;
slouken@2226
   540
    failed = 0;
slouken@2226
   541
    data->layer->TestConfiguration(data->layer, &config, &failed);
slouken@2226
   542
    if (failed == 0)
slouken@2226
   543
        SDL_AddDisplayMode(_this->current_display, mode);
icculus@728
   544
slouken@2226
   545
}
slouken@2226
   546
slouken@2226
   547
static void
slouken@2226
   548
DirectFB_GetDisplayModes(_THIS)
slouken@2226
   549
{
slouken@2226
   550
    //SDL_DisplayData *data = (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
slouken@2226
   551
    //SDL_DisplayMode mode;
slouken@2226
   552
    //SDL_AddDisplayMode(_this->current_display, &mode);
slouken@2226
   553
slouken@2226
   554
    SDL_DFB_DEVICEDATA(_this);
slouken@2226
   555
    DFB_DisplayData *data = (DFB_DisplayData *) SDL_CurrentDisplay.driverdata;
slouken@2226
   556
    int i;
slouken@2226
   557
    SDL_DisplayMode mode;
slouken@2226
   558
slouken@2226
   559
    for (i = 0; i < data->nummodes; ++i) {
slouken@2226
   560
        mode = data->modelist[i];
slouken@2226
   561
        //mode.format = SDL_PIXELFORMAT_UNKNOWN;
icculus@728
   562
slouken@2226
   563
        mode.format = SDL_PIXELFORMAT_INDEX8;
slouken@2226
   564
        CheckSetDisplayMode(_this, data, &mode);
slouken@2226
   565
        mode.format = SDL_PIXELFORMAT_RGB565;
slouken@2226
   566
        CheckSetDisplayMode(_this, data, &mode);
slouken@2226
   567
        mode.format = SDL_PIXELFORMAT_RGB24;
slouken@2226
   568
        CheckSetDisplayMode(_this, data, &mode);
slouken@2226
   569
        mode.format = SDL_PIXELFORMAT_RGB888;
slouken@2226
   570
        CheckSetDisplayMode(_this, data, &mode);
slouken@2226
   571
    }
slouken@2226
   572
}
slouken@1895
   573
slouken@2226
   574
int
slouken@2226
   575
DirectFB_SetDisplayMode(_THIS, SDL_DisplayMode * mode)
slouken@2226
   576
{
slouken@2226
   577
    SDL_DFB_DEVICEDATA(_this);
slouken@2226
   578
    DFB_DisplayData *data = (DFB_DisplayData *) SDL_CurrentDisplay.driverdata;
slouken@2226
   579
    DFBDisplayLayerConfig config, rconfig;
slouken@2226
   580
    DFBDisplayLayerConfigFlags fail = 0;
slouken@2226
   581
    DFBResult ret;
icculus@728
   582
slouken@2226
   583
    SDL_DFB_CHECKERR(data->layer->
slouken@2226
   584
                     SetCooperativeLevel(data->layer, DLSCL_ADMINISTRATIVE));
slouken@2226
   585
slouken@2226
   586
    SDL_DFB_CHECKERR(data->layer->GetConfiguration(data->layer, &config));
slouken@2226
   587
    config.flags = DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_BUFFERMODE;
slouken@2226
   588
    if (mode->format != SDL_PIXELFORMAT_UNKNOWN) {
slouken@2226
   589
        config.flags |= DLCONF_PIXELFORMAT;
slouken@2226
   590
        config.pixelformat = SDLToDFBPixelFormat(mode->format);
slouken@2226
   591
        data->pixelformat = config.pixelformat;
slouken@2226
   592
    }
slouken@2226
   593
    config.width = mode->w;
slouken@2226
   594
    config.height = mode->h;
slouken@2226
   595
slouken@2226
   596
    config.buffermode = DLBM_BACKVIDEO;
slouken@2226
   597
slouken@2226
   598
    //config.pixelformat = GetFormatForBpp (bpp, HIDDEN->layer);
icculus@732
   599
slouken@2226
   600
    data->layer->TestConfiguration(data->layer, &config, &fail);
slouken@2226
   601
    if (fail & (DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT)) {
slouken@2226
   602
        SDL_DFB_DEBUG("Error setting mode %dx%d-%x\n", mode->w, mode->h,
slouken@2226
   603
                      mode->format);
slouken@2226
   604
        return -1;
slouken@2226
   605
    }
slouken@2226
   606
    SDL_DFB_DEBUG("Trace\n");
slouken@2226
   607
    config.flags &= ~fail;
slouken@2226
   608
    SDL_DFB_CHECKERR(data->layer->SetConfiguration(data->layer, &config));
slouken@2226
   609
    SDL_DFB_CHECKERR(data->layer->
slouken@2226
   610
                     SetCooperativeLevel(data->layer, DLSCL_ADMINISTRATIVE));
slouken@2226
   611
slouken@2226
   612
    /* Double check */
slouken@2226
   613
    SDL_DFB_CHECKERR(data->layer->GetConfiguration(data->layer, &rconfig));
slouken@2226
   614
slouken@2226
   615
    if ((config.width != rconfig.width) ||
slouken@2226
   616
        (config.height != rconfig.height) ||
slouken@2226
   617
        (config.pixelformat != rconfig.pixelformat)) {
slouken@2226
   618
        SDL_DFB_DEBUG("Error setting mode %dx%d-%x\n", mode->w, mode->h,
slouken@2226
   619
                      mode->format);
slouken@2226
   620
        return -1;
icculus@728
   621
    }
icculus@728
   622
slouken@1895
   623
    return 0;
slouken@1895
   624
  error:
slouken@2226
   625
    return -1;
slouken@2226
   626
}
icculus@728
   627
slouken@2226
   628
static int
slouken@2226
   629
DirectFB_SetDisplayGammaRamp(_THIS, Uint16 * ramp)
slouken@2226
   630
{
slouken@1895
   631
    return -1;
slouken@167
   632
}
slouken@167
   633
slouken@2226
   634
static int
slouken@2226
   635
DirectFB_GetDisplayGammaRamp(_THIS, Uint16 * ramp)
slouken@2226
   636
{
slouken@2226
   637
    return -1;
slouken@2226
   638
}
slouken@2226
   639
slouken@2226
   640
static int
slouken@2226
   641
DirectFB_CreateWindow(_THIS, SDL_Window * window)
slouken@167
   642
{
slouken@2226
   643
    SDL_DFB_DEVICEDATA(_this);
slouken@2226
   644
    SDL_DFB_DISPLAYDATA(_this, window);
slouken@2226
   645
    DFB_WindowData *windata;
slouken@2226
   646
    DFBWindowOptions wopts;
slouken@2226
   647
    DFBWindowDescription desc;
slouken@2226
   648
    int ret, x, y;
slouken@2226
   649
slouken@2226
   650
    SDL_DFB_DEBUG("Trace x %d y %d w %d h %d\n", window->x, window->y,
slouken@2226
   651
                  window->w, window->h);
slouken@2226
   652
    window->driverdata = NULL;
slouken@2226
   653
    SDL_DFB_CALLOC(window->driverdata, 1, sizeof(DFB_WindowData));
slouken@2226
   654
    windata = (DFB_WindowData *) window->driverdata;
slouken@2226
   655
slouken@2226
   656
    SDL_DFB_CHECKERR(devdata->dfb->
slouken@2226
   657
                     SetCooperativeLevel(devdata->dfb, DFSCL_NORMAL));
slouken@2226
   658
    SDL_DFB_CHECKERR(dispdata->layer->
slouken@2226
   659
                     SetCooperativeLevel(dispdata->layer,
slouken@2226
   660
                                         DLSCL_ADMINISTRATIVE));
slouken@2226
   661
slouken@2226
   662
    /* Fill the window description. */
slouken@2226
   663
    if (window->x == SDL_WINDOWPOS_CENTERED) {
slouken@2226
   664
        x = (dispdata->cw - window->w) / 2;
slouken@2226
   665
    } else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
slouken@2226
   666
        x = 0;
slouken@2226
   667
    } else {
slouken@2226
   668
        x = window->x;
slouken@2226
   669
    }
slouken@2226
   670
    if (window->y == SDL_WINDOWPOS_CENTERED) {
slouken@2226
   671
        y = (dispdata->ch - window->h) / 2;
slouken@2226
   672
    } else if (window->y == SDL_WINDOWPOS_UNDEFINED) {
slouken@2226
   673
        y = 0;
slouken@2226
   674
    } else {
slouken@2226
   675
        y = window->y;
slouken@2226
   676
    }
slouken@2226
   677
slouken@2226
   678
    desc.flags =
slouken@2226
   679
        DWDESC_WIDTH | DWDESC_HEIGHT | DWDESC_CAPS | DWDESC_PIXELFORMAT;
slouken@2226
   680
    desc.flags |= DWDESC_POSX | DWDESC_POSY | DWDESC_SURFACE_CAPS;
slouken@2226
   681
    desc.posx = x;
slouken@2226
   682
    desc.posy = y;
slouken@2226
   683
    desc.width = window->w;
slouken@2226
   684
    desc.height = window->h;
slouken@2226
   685
slouken@2226
   686
    desc.pixelformat = dispdata->pixelformat;
slouken@2226
   687
slouken@2226
   688
    desc.caps = 0;              //DWCAPS_DOUBLEBUFFER;
slouken@2226
   689
    desc.surface_caps = DSCAPS_DOUBLE | DSCAPS_TRIPLE;  //| DSCAPS_PREMULTIPLIED;
slouken@2226
   690
slouken@2226
   691
    /* Create the window. */
slouken@2226
   692
    SDL_DFB_CHECKERR(dispdata->layer->
slouken@2226
   693
                     CreateWindow(dispdata->layer, &desc, &windata->window));
slouken@2226
   694
slouken@2226
   695
    windata->window->GetOptions(windata->window, &wopts);
slouken@2226
   696
#if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 0)
slouken@2226
   697
slouken@2226
   698
    if (window->flags & SDL_WINDOW_RESIZABLE)
slouken@2226
   699
        wopts |= DWOP_SCALE;
slouken@2226
   700
    else
slouken@2226
   701
        wopts |= DWOP_KEEP_SIZE;
slouken@2226
   702
#else
slouken@2226
   703
    wopts |= DWOP_KEEP_SIZE;    // if not we will crash ...
slouken@2226
   704
#endif
slouken@2226
   705
slouken@2226
   706
    if (window->flags & SDL_WINDOW_FULLSCREEN)
slouken@2226
   707
        wopts |= DWOP_KEEP_POSITION | DWOP_KEEP_STACKING | DWOP_KEEP_SIZE;
slouken@167
   708
slouken@2226
   709
    windata->window->SetOptions(windata->window, wopts);
slouken@2226
   710
    /* Get the window's surface. */
slouken@2226
   711
    SDL_DFB_CHECKERR(windata->window->
slouken@2226
   712
                     GetSurface(windata->window, &windata->surface));
slouken@2226
   713
    windata->window->SetOpacity(windata->window, 0xFF);
slouken@2226
   714
    SDL_DFB_CHECKERR(windata->window->
slouken@2226
   715
                     CreateEventBuffer(windata->window,
slouken@2226
   716
                                       &(windata->eventbuffer)));
slouken@2226
   717
    SDL_DFB_CHECKERR(windata->window->
slouken@2226
   718
                     EnableEvents(windata->window,
slouken@2226
   719
                                  DWET_POSITION | DWET_SIZE | DWET_CLOSE |
slouken@2226
   720
                                  DWET_ALL));
slouken@2226
   721
slouken@2226
   722
    if (window->flags & SDL_WINDOW_FULLSCREEN)
slouken@2226
   723
        windata->window->SetStackingClass(windata->window, DWSC_UPPER);
slouken@2226
   724
    /* Make it the top most window. */
slouken@2226
   725
    windata->window->RaiseToTop(windata->window);
slouken@2226
   726
slouken@2226
   727
    windata->window->GetID(windata->window, &windata->windowID);
slouken@2226
   728
    windata->id = window->id;
slouken@2226
   729
slouken@2226
   730
#if SDL_DIRECTFB_OPENGL
slouken@2226
   731
    if (window->flags & SDL_WINDOW_OPENGL) {
slouken@2226
   732
        if (!_this->gl_config.driver_loaded) {
slouken@2226
   733
            /* no driver has been loaded, use default (ourselves) */
slouken@2226
   734
            if (DirectFB_GL_LoadLibrary(_this, NULL) < 0) {
slouken@2226
   735
                goto error;
slouken@2226
   736
            }
slouken@2226
   737
        }
slouken@2226
   738
        _this->gl_data->gl_active = 1;
slouken@2226
   739
    }
slouken@2226
   740
#endif
slouken@2226
   741
slouken@2226
   742
    /* Add to list ... */
slouken@2226
   743
slouken@2226
   744
    windata->next = devdata->firstwin;
slouken@2226
   745
    windata->opacity = 0xFF;
slouken@2226
   746
    devdata->firstwin = windata;
slouken@2226
   747
slouken@2226
   748
    //SDL_DFB_CHECKERR( windata->surface->GetPalette(windata->surface, &windata->palette) );
slouken@2226
   749
slouken@2226
   750
    return 0;
slouken@2226
   751
  error:
slouken@2226
   752
    SDL_DFB_RELEASE(windata->window);
slouken@2226
   753
    SDL_DFB_RELEASE(windata->surface);
slouken@2226
   754
    return -1;
slouken@2226
   755
}
slouken@2226
   756
slouken@2226
   757
static int
slouken@2226
   758
DirectFB_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
slouken@2226
   759
{
slouken@2226
   760
    SDL_DFB_DEVICEDATA(_this);
slouken@2226
   761
    SDL_DFB_WINDOWDATA(window);
slouken@2226
   762
    SDL_DFB_DISPLAYDATA(_this, window);
slouken@2226
   763
slouken@2226
   764
    SDL_Unsupported();
slouken@2226
   765
    return -1;
slouken@2226
   766
}
slouken@2226
   767
slouken@2226
   768
static void
slouken@2226
   769
DirectFB_SetWindowTitle(_THIS, SDL_Window * window)
slouken@2226
   770
{
slouken@2226
   771
    SDL_DFB_DEVICEDATA(_this);
slouken@2226
   772
    SDL_DFB_WINDOWDATA(window);
slouken@2226
   773
    SDL_DFB_DISPLAYDATA(_this, window);
slouken@2226
   774
slouken@2226
   775
    SDL_Unsupported();
slouken@2226
   776
    //return -1;
slouken@2226
   777
slouken@2226
   778
}
slouken@2226
   779
static void
slouken@2226
   780
DirectFB_SetWindowPosition(_THIS, SDL_Window * window)
slouken@2226
   781
{
slouken@2226
   782
    SDL_DFB_DEVICEDATA(_this);
slouken@2226
   783
    SDL_DFB_WINDOWDATA(window);
slouken@2226
   784
    SDL_DFB_DISPLAYDATA(_this, window);
slouken@2226
   785
slouken@2226
   786
    windata->window->MoveTo(windata->window, window->x, window->y);
slouken@167
   787
}
slouken@167
   788
slouken@2226
   789
static void
slouken@2226
   790
DirectFB_SetWindowSize(_THIS, SDL_Window * window)
slouken@2226
   791
{
slouken@2226
   792
    SDL_DFB_DEVICEDATA(_this);
slouken@2226
   793
    SDL_DFB_WINDOWDATA(window);
slouken@2226
   794
    SDL_DFB_DISPLAYDATA(_this, window);
slouken@2226
   795
slouken@2226
   796
    windata->window->Resize(windata->window, window->w, window->h);
slouken@2226
   797
slouken@2226
   798
}
slouken@2226
   799
static void
slouken@2226
   800
DirectFB_ShowWindow(_THIS, SDL_Window * window)
slouken@2226
   801
{
slouken@2226
   802
    SDL_DFB_DEVICEDATA(_this);
slouken@2226
   803
    SDL_DFB_WINDOWDATA(window);
slouken@2226
   804
    SDL_DFB_DISPLAYDATA(_this, window);
slouken@2226
   805
slouken@2226
   806
    windata->window->SetOpacity(windata->window, windata->opacity);
slouken@2226
   807
slouken@2226
   808
}
slouken@2226
   809
slouken@2226
   810
static void
slouken@2226
   811
DirectFB_HideWindow(_THIS, SDL_Window * window)
slouken@2226
   812
{
slouken@2226
   813
    SDL_DFB_DEVICEDATA(_this);
slouken@2226
   814
    SDL_DFB_WINDOWDATA(window);
slouken@2226
   815
    SDL_DFB_DISPLAYDATA(_this, window);
slouken@2226
   816
slouken@2226
   817
    windata->window->GetOpacity(windata->window, &windata->opacity);
slouken@2226
   818
    windata->window->SetOpacity(windata->window, 0);
slouken@2226
   819
slouken@2226
   820
}
slouken@2226
   821
static void
slouken@2226
   822
DirectFB_RaiseWindow(_THIS, SDL_Window * window)
slouken@167
   823
{
slouken@2226
   824
    SDL_DFB_DEVICEDATA(_this);
slouken@2226
   825
    SDL_DFB_WINDOWDATA(window);
slouken@2226
   826
    SDL_DFB_DISPLAYDATA(_this, window);
slouken@2226
   827
slouken@2226
   828
    windata->window->Raise(windata->window);
slouken@2226
   829
slouken@2226
   830
}
slouken@2226
   831
slouken@2226
   832
static void
slouken@2226
   833
DirectFB_MaximizeWindow(_THIS, SDL_Window * window)
slouken@2226
   834
{
slouken@2226
   835
    SDL_DFB_DEVICEDATA(_this);
slouken@2226
   836
    SDL_DFB_WINDOWDATA(window);
slouken@2226
   837
    SDL_DFB_DISPLAYDATA(_this, window);
slouken@2226
   838
slouken@2226
   839
    SDL_Unsupported();
slouken@167
   840
slouken@2226
   841
}
slouken@2226
   842
static void
slouken@2226
   843
DirectFB_MinimizeWindow(_THIS, SDL_Window * window)
slouken@2226
   844
{
slouken@2226
   845
    SDL_DFB_DEVICEDATA(_this);
slouken@2226
   846
    SDL_DFB_WINDOWDATA(window);
slouken@2226
   847
    SDL_DFB_DISPLAYDATA(_this, window);
slouken@2226
   848
slouken@2226
   849
    SDL_Unsupported();
slouken@167
   850
slouken@2226
   851
}
slouken@2226
   852
slouken@2226
   853
static void
slouken@2226
   854
DirectFB_RestoreWindow(_THIS, SDL_Window * window)
slouken@2226
   855
{
slouken@2226
   856
    SDL_DFB_DEVICEDATA(_this);
slouken@2226
   857
    SDL_DFB_WINDOWDATA(window);
slouken@2226
   858
    SDL_DFB_DISPLAYDATA(_this, window);
slouken@2226
   859
slouken@2226
   860
    SDL_Unsupported();
slouken@167
   861
slouken@2226
   862
}
slouken@2226
   863
static void
slouken@2226
   864
DirectFB_SetWindowGrab(_THIS, SDL_Window * window)
slouken@2226
   865
{
slouken@2226
   866
    SDL_DFB_DEVICEDATA(_this);
slouken@2226
   867
    SDL_DFB_WINDOWDATA(window);
slouken@2226
   868
    SDL_DFB_DISPLAYDATA(_this, window);
slouken@2226
   869
slouken@2226
   870
    SDL_Unsupported();
slouken@2226
   871
slouken@2226
   872
}
slouken@2226
   873
slouken@2226
   874
static void
slouken@2226
   875
DirectFB_DestroyWindow(_THIS, SDL_Window * window)
slouken@2226
   876
{
slouken@2226
   877
    SDL_DFB_DEVICEDATA(_this);
slouken@2226
   878
    SDL_DFB_WINDOWDATA(window);
slouken@2226
   879
    SDL_DFB_DISPLAYDATA(_this, window);
slouken@2226
   880
    DFB_WindowData *p;
slouken@2226
   881
slouken@2226
   882
    SDL_DFB_DEBUG("Trace\n");
slouken@2226
   883
slouken@2226
   884
    SDL_DFB_RELEASE(windata->palette);
slouken@2226
   885
    SDL_DFB_RELEASE(windata->eventbuffer);
slouken@2226
   886
    SDL_DFB_RELEASE(windata->surface);
slouken@2226
   887
    SDL_DFB_RELEASE(windata->window);
slouken@2226
   888
slouken@2226
   889
    /* Remove from list ... */
slouken@477
   890
slouken@2226
   891
    p = devdata->firstwin;
slouken@2226
   892
    while (p && p->next != windata)
slouken@2226
   893
        p = p->next;
slouken@2226
   894
    if (p)
slouken@2226
   895
        p->next = windata->next;
slouken@2226
   896
    else
slouken@2226
   897
        devdata->firstwin = windata->next;
slouken@2226
   898
    SDL_free(windata);
slouken@2226
   899
}
slouken@2226
   900
static SDL_bool
slouken@2226
   901
DirectFB_GetWindowWMInfo(_THIS, SDL_Window * window,
slouken@2226
   902
                         struct SDL_SysWMinfo *info)
slouken@2226
   903
{
slouken@2226
   904
    SDL_DFB_DEVICEDATA(_this);
slouken@2226
   905
    SDL_DFB_WINDOWDATA(window);
slouken@2226
   906
    SDL_DFB_DISPLAYDATA(_this, window);
slouken@2226
   907
slouken@2226
   908
    SDL_Unsupported();
slouken@2226
   909
    return SDL_FALSE;
slouken@2226
   910
}
slouken@2226
   911
slouken@2226
   912
#if SDL_DIRECTFB_OPENGL
slouken@2226
   913
slouken@2226
   914
#define OPENGL_REQUIRS_DLOPEN
slouken@2226
   915
#if defined(OPENGL_REQUIRS_DLOPEN) && defined(SDL_LOADSO_DLOPEN)
slouken@2226
   916
#include <dlfcn.h>
slouken@2226
   917
#define GL_LoadObject(X)	dlopen(X, (RTLD_NOW|RTLD_GLOBAL))
slouken@2226
   918
#define GL_LoadFunction		dlsym
slouken@2226
   919
#define GL_UnloadObject		dlclose
slouken@2226
   920
#else
slouken@2226
   921
#define GL_LoadObject	SDL_LoadObject
slouken@2226
   922
#define GL_LoadFunction	SDL_LoadFunction
slouken@2226
   923
#define GL_UnloadObject	SDL_UnloadObject
slouken@2226
   924
#endif
slouken@2226
   925
slouken@2226
   926
static int
slouken@2226
   927
DirectFB_GL_LoadLibrary(_THIS, const char *path)
slouken@2226
   928
{
slouken@2226
   929
    SDL_DFB_DEVICEDATA(_this);
slouken@2226
   930
#
slouken@2226
   931
    void *handle = NULL;
slouken@2226
   932
slouken@2226
   933
    SDL_DFB_DEBUG("Loadlibrary : %s\n", path);
slouken@2226
   934
slouken@2226
   935
    if (_this->gl_data->gl_active) {
slouken@2226
   936
        SDL_SetError("OpenGL context already created");
slouken@2226
   937
        return -1;
slouken@167
   938
    }
slouken@167
   939
slouken@167
   940
slouken@2226
   941
    if (path == NULL) {
slouken@2226
   942
        path = SDL_getenv("SDL_VIDEO_GL_DRIVER");
slouken@2226
   943
        if (path == NULL) {
slouken@2226
   944
            path = "libGL.so";
slouken@167
   945
        }
slouken@167
   946
    }
slouken@167
   947
slouken@2226
   948
    handle = GL_LoadObject(path);
slouken@2226
   949
    if (handle == NULL) {
slouken@2226
   950
        SDL_DFB_ERR("Library not found: %s\n", path);
slouken@2226
   951
        /* SDL_LoadObject() will call SDL_SetError() for us. */
slouken@1895
   952
        return -1;
slouken@167
   953
    }
slouken@167
   954
slouken@2226
   955
    SDL_DFB_DEBUG("Loaded library: %s\n", path);
slouken@2226
   956
slouken@2226
   957
    /* Unload the old driver and reset the pointers */
slouken@2226
   958
    DirectFB_GL_UnloadLibrary(_this);
slouken@2226
   959
slouken@2226
   960
    _this->gl_config.dll_handle = handle;
slouken@2226
   961
    _this->gl_config.driver_loaded = 1;
slouken@2226
   962
    if (path) {
slouken@2226
   963
        SDL_strlcpy(_this->gl_config.driver_path, path,
slouken@2226
   964
                    SDL_arraysize(_this->gl_config.driver_path));
slouken@2226
   965
    } else {
slouken@2226
   966
        *_this->gl_config.driver_path = '\0';
slouken@167
   967
    }
slouken@167
   968
slouken@2226
   969
    devdata->glFinish = DirectFB_GL_GetProcAddress(_this, "glFinish");
slouken@2226
   970
    devdata->glFlush = DirectFB_GL_GetProcAddress(_this, "glFlush");
slouken@1895
   971
    return 0;
slouken@167
   972
}
slouken@167
   973
slouken@1895
   974
static void
slouken@2226
   975
DirectFB_GL_UnloadLibrary(_THIS)
slouken@167
   976
{
slouken@2226
   977
    SDL_DFB_DEVICEDATA(_this);
slouken@2226
   978
slouken@2226
   979
    int ret;
slouken@2226
   980
slouken@2226
   981
    if (_this->gl_config.driver_loaded) {
slouken@2226
   982
slouken@2226
   983
        ret = GL_UnloadObject(_this->gl_config.dll_handle);
slouken@2226
   984
        if (ret)
slouken@2226
   985
            SDL_DFB_ERR("Error #%d trying to unload library.\n", ret);
slouken@2226
   986
        _this->gl_config.dll_handle = NULL;
slouken@2226
   987
        _this->gl_config.driver_loaded = 0;
slouken@167
   988
    }
slouken@167
   989
}
slouken@167
   990
slouken@2226
   991
static void *
slouken@2226
   992
DirectFB_GL_GetProcAddress(_THIS, const char *proc)
slouken@167
   993
{
slouken@2226
   994
    SDL_DFB_DEVICEDATA(_this);
slouken@2226
   995
    int ret;
slouken@2226
   996
    void *handle;
slouken@167
   997
slouken@2226
   998
    SDL_DFB_DEBUG("Trace %s\n", proc);
slouken@2226
   999
    handle = _this->gl_config.dll_handle;
slouken@2226
  1000
    return GL_LoadFunction(handle, proc);
slouken@167
  1001
}
slouken@167
  1002
slouken@2226
  1003
static SDL_GLContext
slouken@2226
  1004
DirectFB_GL_CreateContext(_THIS, SDL_Window * window)
slouken@167
  1005
{
slouken@2226
  1006
    SDL_DFB_DEVICEDATA(_this);
slouken@2226
  1007
    SDL_DFB_WINDOWDATA(window);
slouken@2226
  1008
    SDL_DFB_DISPLAYDATA(_this, window);
slouken@2226
  1009
    int ret;
slouken@2226
  1010
    IDirectFBGL *context = NULL;
slouken@167
  1011
slouken@2226
  1012
    SDL_DFB_DEBUG("Trace\n");
slouken@2226
  1013
    SDL_DFB_CHECKERR(windata->surface->GetGL(windata->surface, &context));
slouken@2226
  1014
    SDL_DFB_CHECKERR(context->Unlock(context));
slouken@167
  1015
slouken@2226
  1016
    if (DirectFB_GL_MakeCurrent(_this, window, context) < 0) {
slouken@2226
  1017
        DirectFB_GL_DeleteContext(_this, context);
slouken@2226
  1018
        return NULL;
slouken@167
  1019
    }
slouken@167
  1020
slouken@2226
  1021
    return context;
slouken@167
  1022
slouken@2226
  1023
  error:
slouken@2226
  1024
    return NULL;
slouken@167
  1025
}
slouken@167
  1026
slouken@1895
  1027
static int
slouken@2226
  1028
DirectFB_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
slouken@167
  1029
{
slouken@2226
  1030
    SDL_DFB_DEVICEDATA(_this);
slouken@2226
  1031
    SDL_DFB_WINDOWDATA(window);
slouken@2226
  1032
    SDL_DFB_DISPLAYDATA(_this, window);
slouken@2226
  1033
    IDirectFBGL *dfb_context = (IDirectFBGL *) context;
slouken@2226
  1034
    int ret;
slouken@219
  1035
slouken@2226
  1036
    if (dfb_context) {
slouken@2226
  1037
        dfb_context->Unlock(dfb_context);
slouken@2226
  1038
        SDL_DFB_CHECKERR(dfb_context->Lock(dfb_context));
slouken@2226
  1039
    }
slouken@2226
  1040
    if (windata)
slouken@2226
  1041
        windata->gl_context = dfb_context;
slouken@219
  1042
slouken@1895
  1043
    return 0;
slouken@2226
  1044
  error:
slouken@2226
  1045
    return -1;
slouken@167
  1046
}
slouken@167
  1047
slouken@1895
  1048
static int
slouken@2226
  1049
DirectFB_GL_SetSwapInterval(_THIS, int interval)
slouken@167
  1050
{
slouken@2226
  1051
    SDL_DFB_DEVICEDATA(_this);
slouken@1895
  1052
slouken@2226
  1053
    SDL_Unsupported();
slouken@2226
  1054
    return -1;
slouken@2226
  1055
slouken@167
  1056
}
slouken@167
  1057
slouken@1895
  1058
static int
slouken@2226
  1059
DirectFB_GL_GetSwapInterval(_THIS)
slouken@167
  1060
{
slouken@2226
  1061
    SDL_DFB_DEVICEDATA(_this);
slouken@167
  1062
slouken@2226
  1063
    SDL_Unsupported();
slouken@2226
  1064
    return -1;
slouken@167
  1065
slouken@167
  1066
}
slouken@167
  1067
slouken@1895
  1068
static void
slouken@2226
  1069
DirectFB_GL_SwapWindow(_THIS, SDL_Window * window)
slouken@167
  1070
{
slouken@2226
  1071
    SDL_DFB_DEVICEDATA(_this);
slouken@2226
  1072
    SDL_DFB_WINDOWDATA(window);
slouken@2226
  1073
    SDL_DFB_DISPLAYDATA(_this, window);
slouken@2226
  1074
    int ret;
slouken@2226
  1075
    void *p;
slouken@2226
  1076
    int pitch;
slouken@2226
  1077
    DFBRegion region;
slouken@2226
  1078
slouken@2226
  1079
    region.x1 = 0;
slouken@2226
  1080
    region.y1 = 0;
slouken@2226
  1081
    region.x2 = window->w;
slouken@2226
  1082
    region.y2 = window->h;
icculus@728
  1083
slouken@2226
  1084
    if (devdata->glFinish)
slouken@2226
  1085
        devdata->glFinish();
slouken@2226
  1086
    else if (devdata->glFlush)
slouken@2226
  1087
        devdata->glFlush();
slouken@2226
  1088
slouken@2226
  1089
    SDL_DFB_CHECKERR(windata->gl_context->Unlock(windata->gl_context));
slouken@2226
  1090
    SDL_DFB_CHECKERR(windata->surface->
slouken@2226
  1091
                     Flip(windata->surface, &region, DSFLIP_ONSYNC));
slouken@2226
  1092
    SDL_DFB_CHECKERR(windata->gl_context->Lock(windata->gl_context));
slouken@2226
  1093
slouken@2226
  1094
    return;
slouken@2226
  1095
  error:
slouken@2226
  1096
    return;
slouken@167
  1097
}
slouken@167
  1098
slouken@1895
  1099
static void
slouken@2226
  1100
DirectFB_GL_DeleteContext(_THIS, SDL_GLContext context)
slouken@167
  1101
{
slouken@2226
  1102
    IDirectFBGL *dfb_context = (IDirectFBGL *) context;
slouken@2226
  1103
    SDL_DFB_DEVICEDATA(_this);
slouken@1895
  1104
slouken@2226
  1105
    dfb_context->Unlock(dfb_context);
slouken@2226
  1106
    dfb_context->Release(dfb_context);
slouken@167
  1107
}
slouken@167
  1108
slouken@2226
  1109
#endif