src/video/directfb/SDL_DirectFB_video.c
author Couriersud
Sun, 11 Jan 2009 23:49:23 +0000
changeset 3023 d72a0dd80e8b
parent 3013 8cc00819c8d6
child 3040 62d4992e5a92
permissions -rw-r--r--
DirectFB cleanups & simple window manager

- use SDL_getenv, not getenv ...
- no more support for 0.9.25 - not even mentioned any longer on directfb.org
- fix fullscreen issues
- add a simple window manager unless the directfb team comes up with a working wm.

The driver has support for a very, very basic window manager you may
want to use when runnning with "wm=default". Use

export SDL_DIRECTFB_WM=1

to enable basic window borders including icon support. In order to have the window title rendered,
you need to have the following font installed:

/usr/share/fonts/truetype/freefont/FreeSans.ttf
slouken@167
     1
/*
slouken@1312
     2
    SDL - Simple DirectMedia Layer
slouken@2859
     3
    Copyright (C) 1997-2009 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
slouken@1402
    27
#include "SDL_config.h"
slouken@167
    28
slouken@167
    29
/* DirectFB video driver implementation.
slouken@167
    30
*/
slouken@167
    31
slouken@167
    32
#include <fcntl.h>
slouken@167
    33
#include <unistd.h>
slouken@167
    34
#include <sys/mman.h>
slouken@167
    35
slouken@167
    36
#include <directfb.h>
icculus@1165
    37
#include <directfb_version.h>
couriersud@3023
    38
#include <directfb_strings.h>
slouken@167
    39
slouken@167
    40
#include "SDL_video.h"
slouken@167
    41
#include "SDL_mouse.h"
slouken@1361
    42
#include "../SDL_sysvideo.h"
slouken@1361
    43
#include "../SDL_pixels_c.h"
slouken@1361
    44
#include "../../events/SDL_events_c.h"
slouken@167
    45
#include "SDL_DirectFB_video.h"
slouken@167
    46
#include "SDL_DirectFB_events.h"
slouken@2737
    47
#include "SDL_DirectFB_render.h"
slouken@2737
    48
#include "SDL_DirectFB_mouse.h"
slouken@2226
    49
slouken@2998
    50
#include "SDL_DirectFB_dyn.h"
slouken@2998
    51
slouken@2226
    52
/* Initialization/Query functions */
slouken@2226
    53
static int DirectFB_VideoInit(_THIS);
slouken@2226
    54
static void DirectFB_VideoQuit(_THIS);
slouken@167
    55
slouken@2737
    56
static int DirectFB_Available(void);
slouken@2737
    57
static SDL_VideoDevice *DirectFB_CreateDevice(int devindex);
slouken@2226
    58
couriersud@3023
    59
#if 0
slouken@2226
    60
static int DirectFB_SetDisplayGammaRamp(_THIS, Uint16 * ramp);
slouken@2226
    61
static int DirectFB_GetDisplayGammaRamp(_THIS, Uint16 * ramp);
couriersud@3023
    62
#endif
slouken@2226
    63
slouken@2737
    64
VideoBootStrap DirectFB_bootstrap = {
slouken@2737
    65
    "directfb", "DirectFB",
slouken@2737
    66
    DirectFB_Available, DirectFB_CreateDevice
slouken@2737
    67
};
slouken@167
    68
slouken@167
    69
/* DirectFB driver bootstrap functions */
slouken@167
    70
slouken@1895
    71
static int
slouken@1895
    72
DirectFB_Available(void)
slouken@167
    73
{
slouken@2998
    74
    if (!SDL_DirectFB_LoadLibrary())
slouken@2998
    75
        return 0;
slouken@2998
    76
    SDL_DirectFB_UnLoadLibrary();
slouken@1895
    77
    return 1;
slouken@167
    78
}
slouken@167
    79
slouken@1895
    80
static void
slouken@1895
    81
DirectFB_DeleteDevice(SDL_VideoDevice * device)
slouken@167
    82
{
slouken@2998
    83
    SDL_DirectFB_UnLoadLibrary();
slouken@2998
    84
    SDL_DFB_FREE(device->driverdata);
slouken@2998
    85
    SDL_DFB_FREE(device);
slouken@167
    86
}
slouken@167
    87
slouken@1895
    88
static SDL_VideoDevice *
slouken@1895
    89
DirectFB_CreateDevice(int devindex)
slouken@167
    90
{
slouken@1895
    91
    SDL_VideoDevice *device;
slouken@167
    92
slouken@2998
    93
    if (!SDL_DirectFB_LoadLibrary())
slouken@2998
    94
        return NULL;
slouken@2998
    95
slouken@1895
    96
    /* Initialize all variables that we clean on shutdown */
slouken@2226
    97
    SDL_DFB_CALLOC(device, 1, sizeof(SDL_VideoDevice));
slouken@2226
    98
slouken@2226
    99
    /* Set the function pointers */
slouken@167
   100
slouken@1895
   101
    /* Set the function pointers */
slouken@1895
   102
    device->VideoInit = DirectFB_VideoInit;
slouken@1895
   103
    device->VideoQuit = DirectFB_VideoQuit;
slouken@2226
   104
    device->GetDisplayModes = DirectFB_GetDisplayModes;
slouken@2226
   105
    device->SetDisplayMode = DirectFB_SetDisplayMode;
slouken@2226
   106
#if 0
slouken@2226
   107
    device->SetDisplayGammaRamp = DirectFB_SetDisplayGammaRamp;
slouken@2226
   108
    device->GetDisplayGammaRamp = DirectFB_GetDisplayGammaRamp;
slouken@2226
   109
#else
slouken@2226
   110
    device->SetDisplayGammaRamp = NULL;
slouken@2226
   111
    device->GetDisplayGammaRamp = NULL;
slouken@2226
   112
#endif
slouken@2226
   113
    device->PumpEvents = DirectFB_PumpEventsWindow;
slouken@2226
   114
    device->CreateWindow = DirectFB_CreateWindow;
slouken@2226
   115
    device->CreateWindowFrom = DirectFB_CreateWindowFrom;
slouken@2226
   116
    device->SetWindowTitle = DirectFB_SetWindowTitle;
couriersud@3023
   117
    device->SetWindowIcon = DirectFB_SetWindowIcon;
slouken@2226
   118
    device->SetWindowPosition = DirectFB_SetWindowPosition;
slouken@2226
   119
    device->SetWindowSize = DirectFB_SetWindowSize;
slouken@2226
   120
    device->ShowWindow = DirectFB_ShowWindow;
slouken@2226
   121
    device->HideWindow = DirectFB_HideWindow;
slouken@2226
   122
    device->RaiseWindow = DirectFB_RaiseWindow;
slouken@2226
   123
    device->MaximizeWindow = DirectFB_MaximizeWindow;
slouken@2226
   124
    device->MinimizeWindow = DirectFB_MinimizeWindow;
slouken@2226
   125
    device->RestoreWindow = DirectFB_RestoreWindow;
slouken@2226
   126
    device->SetWindowGrab = DirectFB_SetWindowGrab;
slouken@2226
   127
    device->DestroyWindow = DirectFB_DestroyWindow;
slouken@2226
   128
    device->GetWindowWMInfo = DirectFB_GetWindowWMInfo;
slouken@2226
   129
slouken@2226
   130
#if SDL_DIRECTFB_OPENGL
slouken@2226
   131
    device->GL_LoadLibrary = DirectFB_GL_LoadLibrary;
slouken@2226
   132
    device->GL_GetProcAddress = DirectFB_GL_GetProcAddress;
slouken@2226
   133
    device->GL_MakeCurrent = DirectFB_GL_MakeCurrent;
slouken@2226
   134
slouken@2226
   135
    device->GL_CreateContext = DirectFB_GL_CreateContext;
slouken@2226
   136
    device->GL_SetSwapInterval = DirectFB_GL_SetSwapInterval;
slouken@2226
   137
    device->GL_GetSwapInterval = DirectFB_GL_GetSwapInterval;
slouken@2226
   138
    device->GL_SwapWindow = DirectFB_GL_SwapWindow;
slouken@2226
   139
    device->GL_DeleteContext = DirectFB_GL_DeleteContext;
slouken@2226
   140
slouken@2226
   141
#endif
slouken@167
   142
slouken@1895
   143
    device->free = DirectFB_DeleteDevice;
slouken@167
   144
slouken@1895
   145
    return device;
slouken@2226
   146
  error:
slouken@2226
   147
    if (device)
slouken@2226
   148
        free(device);
slouken@2226
   149
    return (0);
slouken@167
   150
}
slouken@167
   151
couriersud@3023
   152
static const DirectFBSurfaceDrawingFlagsNames(drawing_flags);
couriersud@3023
   153
static const DirectFBSurfaceBlittingFlagsNames(blitting_flags);
couriersud@3023
   154
static const DirectFBAccelerationMaskNames(acceleration_mask);
couriersud@3023
   155
couriersud@3023
   156
static void
couriersud@3023
   157
DirectFB_DeviceInformation(IDirectFB * dfb)
couriersud@3023
   158
{
couriersud@3023
   159
    DFBGraphicsDeviceDescription desc;
couriersud@3023
   160
    int n;
couriersud@3023
   161
couriersud@3023
   162
    dfb->GetDeviceDescription(dfb, &desc);
couriersud@3023
   163
couriersud@3023
   164
    fprintf(LOG_CHANNEL, "DirectFB Device Information\n");
couriersud@3023
   165
    fprintf(LOG_CHANNEL, "===========================\n");
couriersud@3023
   166
    fprintf(LOG_CHANNEL, "Name:           %s\n", desc.name);
couriersud@3023
   167
    fprintf(LOG_CHANNEL, "Vendor:         %s\n", desc.vendor);
couriersud@3023
   168
    fprintf(LOG_CHANNEL, "Driver Name:    %s\n", desc.driver.name);
couriersud@3023
   169
    fprintf(LOG_CHANNEL, "Driver Vendor:  %s\n", desc.driver.vendor);
couriersud@3023
   170
    fprintf(LOG_CHANNEL, "Driver Version: %d.%d\n", desc.driver.major,
couriersud@3023
   171
            desc.driver.minor);
couriersud@3023
   172
couriersud@3023
   173
    fprintf(LOG_CHANNEL, "\nVideo memoory:  %d\n", desc.video_memory);
couriersud@3023
   174
couriersud@3023
   175
    fprintf(LOG_CHANNEL, "\nBlitting flags:\n");
couriersud@3023
   176
    for (n = 0; blitting_flags[n].flag; n++) {
couriersud@3023
   177
        if (desc.blitting_flags & blitting_flags[n].flag)
couriersud@3023
   178
            printf("    %s\n", blitting_flags[n].name);
couriersud@3023
   179
    }
couriersud@3023
   180
couriersud@3023
   181
    fprintf(LOG_CHANNEL, "\nDrawing flags:\n");
couriersud@3023
   182
    for (n = 0; drawing_flags[n].flag; n++) {
couriersud@3023
   183
        if (desc.drawing_flags & drawing_flags[n].flag)
couriersud@3023
   184
            printf("    %s\n", drawing_flags[n].name);
couriersud@3023
   185
    }
couriersud@3023
   186
couriersud@3023
   187
    fprintf(LOG_CHANNEL, "\nAcceleration flags:\n");
couriersud@3023
   188
    for (n = 0; acceleration_mask[n].mask; n++) {
couriersud@3023
   189
        if (desc.acceleration_mask & acceleration_mask[n].mask)
couriersud@3023
   190
            printf("    %s\n", acceleration_mask[n].name);
couriersud@3023
   191
    }
couriersud@3023
   192
couriersud@3023
   193
couriersud@3023
   194
}
couriersud@3023
   195
slouken@1895
   196
static int
slouken@2226
   197
DirectFB_VideoInit(_THIS)
slouken@167
   198
{
slouken@1895
   199
    IDirectFB *dfb = NULL;
slouken@2998
   200
    DFB_DeviceData *devdata = NULL;
slouken@2737
   201
    char *stemp;
slouken@2226
   202
    DFBResult ret;
slouken@2226
   203
slouken@2998
   204
    SDL_DFB_CALLOC(devdata, 1, sizeof(*devdata));
slouken@2998
   205
slouken@2226
   206
    SDL_DFB_CHECKERR(DirectFBInit(NULL, NULL));
slouken@2998
   207
slouken@2998
   208
    /* avoid switching to the framebuffer when we
slouken@2998
   209
     * are running X11 */
couriersud@3023
   210
    stemp = SDL_getenv(DFBENV_USE_X11_CHECK);
slouken@2998
   211
    if (stemp)
slouken@2998
   212
        ret = atoi(stemp);
slouken@2998
   213
    else
slouken@2998
   214
        ret = 1;
slouken@2998
   215
slouken@2998
   216
    if (ret) {
couriersud@3023
   217
        if (SDL_getenv("DISPLAY"))
slouken@2998
   218
            DirectFBSetOption("system", "x11");
slouken@2998
   219
        else
slouken@2998
   220
            DirectFBSetOption("disable-module", "x11input");
slouken@2998
   221
    }
slouken@2998
   222
slouken@2998
   223
    devdata->use_linux_input = 1;       /* default: on */
couriersud@3023
   224
    stemp = SDL_getenv(DFBENV_USE_LINUX_INPUT);
slouken@2998
   225
    if (stemp)
slouken@2998
   226
        devdata->use_linux_input = atoi(stemp);
slouken@2998
   227
slouken@2998
   228
    if (!devdata->use_linux_input)
slouken@2998
   229
        DirectFBSetOption("disable-module", "linux_input");
slouken@2998
   230
slouken@2226
   231
    SDL_DFB_CHECKERR(DirectFBCreate(&dfb));
slouken@167
   232
couriersud@3023
   233
    DirectFB_DeviceInformation(dfb);
slouken@2737
   234
    devdata->use_yuv_underlays = 0;     /* default: off */
couriersud@3023
   235
    stemp = SDL_getenv(DFBENV_USE_YUV_UNDERLAY);
slouken@2737
   236
    if (stemp)
slouken@2737
   237
        devdata->use_yuv_underlays = atoi(stemp);
slouken@2226
   238
slouken@2998
   239
slouken@2737
   240
    /* Create global Eventbuffer for axis events */
slouken@2998
   241
    if (devdata->use_linux_input) {
couriersud@3023
   242
        SDL_DFB_CHECKERR(dfb->CreateInputEventBuffer(dfb, DICAPS_ALL,
couriersud@3023
   243
                                                     DFB_TRUE,
couriersud@3023
   244
                                                     &devdata->events));
slouken@2860
   245
    } else {
couriersud@3023
   246
        SDL_DFB_CHECKERR(dfb->CreateInputEventBuffer(dfb, DICAPS_AXES
couriersud@3023
   247
                                                     /*DICAPS_ALL */ ,
couriersud@3023
   248
                                                     DFB_TRUE,
couriersud@3023
   249
                                                     &devdata->events));
slouken@2860
   250
    }
slouken@167
   251
slouken@2226
   252
    devdata->initialized = 1;
couriersud@3023
   253
couriersud@3023
   254
    /* simple window manager support */
couriersud@3023
   255
    stemp = SDL_getenv(DFBENV_USE_WM);
couriersud@3023
   256
    if (stemp)
couriersud@3023
   257
    	devdata->has_own_wm = atoi(stemp);
couriersud@3023
   258
    else
couriersud@3023
   259
    	devdata->has_own_wm = 0;
couriersud@3023
   260
slouken@2226
   261
    devdata->dfb = dfb;
slouken@2226
   262
    devdata->firstwin = NULL;
slouken@464
   263
slouken@2226
   264
    _this->driverdata = devdata;
slouken@464
   265
slouken@2737
   266
    DirectFB_InitModes(_this);
slouken@464
   267
slouken@2226
   268
#if SDL_DIRECTFB_OPENGL
slouken@2737
   269
    DirectFB_GL_Initialize(_this);
icculus@1165
   270
#endif
slouken@167
   271
slouken@2226
   272
    DirectFB_AddRenderDriver(_this);
slouken@2226
   273
    DirectFB_InitMouse(_this);
slouken@2721
   274
    DirectFB_InitKeyboard(_this);
slouken@2737
   275
slouken@2226
   276
    return 0;
slouken@2226
   277
slouken@167
   278
slouken@2226
   279
  error:
slouken@2998
   280
    SDL_DFB_FREE(devdata);
slouken@2226
   281
    SDL_DFB_RELEASE(dfb);
slouken@2226
   282
    return -1;
slouken@2226
   283
}
slouken@1895
   284
slouken@2226
   285
static void
slouken@2226
   286
DirectFB_VideoQuit(_THIS)
slouken@2226
   287
{
slouken@2226
   288
    DFB_DeviceData *devdata = (DFB_DeviceData *) _this->driverdata;
slouken@1895
   289
slouken@2737
   290
    DirectFB_QuitModes(_this);
slouken@2737
   291
    DirectFB_QuitKeyboard(_this);
slouken@2737
   292
    DirectFB_QuitMouse(_this);
icculus@728
   293
slouken@2737
   294
    SDL_DFB_RELEASE(devdata->events);
slouken@2226
   295
    SDL_DFB_RELEASE(devdata->dfb);
icculus@728
   296
slouken@2226
   297
#if SDL_DIRECTFB_OPENGL
slouken@2737
   298
    DirectFB_GL_Shutdown(_this);
slouken@2226
   299
#endif
slouken@2226
   300
slouken@2226
   301
    devdata->initialized = 0;
slouken@2226
   302
}
slouken@2226
   303
couriersud@3023
   304
#if 0
slouken@2226
   305
static int
slouken@2226
   306
DirectFB_SetDisplayGammaRamp(_THIS, Uint16 * ramp)
slouken@2226
   307
{
slouken@1895
   308
    return -1;
slouken@167
   309
}
slouken@167
   310
slouken@2226
   311
static int
slouken@2226
   312
DirectFB_GetDisplayGammaRamp(_THIS, Uint16 * ramp)
slouken@2226
   313
{
slouken@2226
   314
    return -1;
slouken@2226
   315
}
couriersud@3023
   316
#endif